diff --git a/src/main/java/com/aiassistant/controller/AttachmentController.java b/src/main/java/com/aiassistant/controller/AttachmentController.java new file mode 100644 index 0000000..6bf2864 --- /dev/null +++ b/src/main/java/com/aiassistant/controller/AttachmentController.java @@ -0,0 +1,28 @@ +package com.aiassistant.controller; + +import com.aiassistant.model.Attachment; +import com.aiassistant.service.AttachmentService; +import com.aiassistant.utils.ResultModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/attachment") +public class AttachmentController { + private final AttachmentService attachmentService; + + @Autowired + public AttachmentController(AttachmentService attachmentService) { + this.attachmentService = attachmentService; + } + + @PostMapping("/add") + public ResultModel addAttachment(@RequestBody Attachment attachment) { + return attachmentService.addAttachment(attachment); + } + + @GetMapping("/{id}") + public ResultModel getAttachmentById(@PathVariable Integer id) { + return attachmentService.getAttachmentById(id); + } +} diff --git a/src/main/java/com/aiassistant/mapper/AssetAssignMapper.java b/src/main/java/com/aiassistant/mapper/AssetAssignMapper.java index b38fd76..7cb0c16 100644 --- a/src/main/java/com/aiassistant/mapper/AssetAssignMapper.java +++ b/src/main/java/com/aiassistant/mapper/AssetAssignMapper.java @@ -2,7 +2,9 @@ import com.aiassistant.model.AssetAssign; import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +@Mapper public interface AssetAssignMapper { @Insert("INSERT INTO asset_assign (asset_id, employee_id, assign_date) VALUES (#{assetId}, #{employeeId}, #{assignDate})") void insertAssetAssign(AssetAssign assetAssign); diff --git a/src/main/java/com/aiassistant/mapper/AttachmentMapper.java b/src/main/java/com/aiassistant/mapper/AttachmentMapper.java new file mode 100644 index 0000000..6fe3508 --- /dev/null +++ b/src/main/java/com/aiassistant/mapper/AttachmentMapper.java @@ -0,0 +1,17 @@ +package com.aiassistant.mapper; + +import com.aiassistant.model.Attachment; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.Select; + +@Mapper +public interface AttachmentMapper { + @Insert("INSERT INTO attachment(name, type, url) VALUES(#{name}, #{type}, #{url})") + @Options(useGeneratedKeys = true, keyProperty = "id") + void insertAttachment(Attachment attachment); + + @Select("SELECT * FROM attachment WHERE id = #{id}") + Attachment selectById(Integer id); +} diff --git a/src/main/java/com/aiassistant/mapper/EmployeeMapper.java b/src/main/java/com/aiassistant/mapper/EmployeeMapper.java index e24ee77..ab49012 100644 --- a/src/main/java/com/aiassistant/mapper/EmployeeMapper.java +++ b/src/main/java/com/aiassistant/mapper/EmployeeMapper.java @@ -24,12 +24,4 @@ public interface EmployeeMapper { @Delete("DELETE FROM employee WHERE employee_id = #{employeeId}") void deleteById(String employeeId); - /** - * 根据员工工号查询员工信息 - * - * @param employeeId - * @return - */ - @Select("SELECT * FROM employee WHERE employee_id = #{employeeId}") - Employee selectById(String employeeId); } diff --git a/src/main/java/com/aiassistant/model/Attachment.java b/src/main/java/com/aiassistant/model/Attachment.java new file mode 100644 index 0000000..e70506f --- /dev/null +++ b/src/main/java/com/aiassistant/model/Attachment.java @@ -0,0 +1,31 @@ +package com.aiassistant.model; + +public class Attachment { + private String name; + private String type; + private String url; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/src/main/java/com/aiassistant/service/AttachmentService.java b/src/main/java/com/aiassistant/service/AttachmentService.java new file mode 100644 index 0000000..0cf977e --- /dev/null +++ b/src/main/java/com/aiassistant/service/AttachmentService.java @@ -0,0 +1,10 @@ +package com.aiassistant.service; + +import com.aiassistant.model.Attachment; +import com.aiassistant.utils.ResultModel; + +public interface AttachmentService { + ResultModel addAttachment(Attachment attachment); + + ResultModel getAttachmentById(Integer id); +} diff --git a/src/main/java/com/aiassistant/service/impl/AssetServiceImpl.java b/src/main/java/com/aiassistant/service/impl/AssetServiceImpl.java index 5dce63a..193f9a7 100644 --- a/src/main/java/com/aiassistant/service/impl/AssetServiceImpl.java +++ b/src/main/java/com/aiassistant/service/impl/AssetServiceImpl.java @@ -83,7 +83,7 @@ public ResultModel assignAsset(String assignDate, String employeeId, Stri AssetAssign assetAssign = new AssetAssign(); assetAssign.setAssignDate(assignDate); assetAssign.setEmployeeId(employeeId); - assetAssign.setAssetId(assetId); + assetAssign.setAssetNumber(assetId); assetAssignMapper.insertAssetAssign(assetAssign); return ResultModel.ofSuccess("Asset assigned successfully"); diff --git a/src/main/java/com/aiassistant/service/impl/AttachmentServiceImpl.java b/src/main/java/com/aiassistant/service/impl/AttachmentServiceImpl.java new file mode 100644 index 0000000..7921269 --- /dev/null +++ b/src/main/java/com/aiassistant/service/impl/AttachmentServiceImpl.java @@ -0,0 +1,35 @@ +package com.aiassistant.service.impl; + +import com.aiassistant.mapper.AttachmentMapper; +import com.aiassistant.model.Attachment; +import com.aiassistant.service.AttachmentService; +import com.aiassistant.utils.ResultModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AttachmentServiceImpl implements AttachmentService { + + private final AttachmentMapper attachmentMapper; + + @Autowired + public AttachmentServiceImpl(AttachmentMapper attachmentMapper) { + this.attachmentMapper = attachmentMapper; + } + + @Override + public ResultModel addAttachment(Attachment attachment) { + attachmentMapper.insertAttachment(attachment); + return new ResultModel<>(attachment); + } + + @Override + public ResultModel getAttachmentById(Integer id) { + Attachment attachment = attachmentMapper.selectById(id); + if (attachment != null) { + return new ResultModel<>(attachment); + } else { + return new ResultModel<>(ResultModel.FAIL, "Attachment not found"); + } + } +} \ No newline at end of file