Skip to content

Commit

Permalink
附件管理,上传照片或文件以供记录,包括附件名称、附件地址、附件类型。
Browse files Browse the repository at this point in the history
  • Loading branch information
charging-kuafuai committed Oct 23, 2023
1 parent 7ef61a6 commit 746a185
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 9 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/aiassistant/controller/AttachmentController.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/aiassistant/mapper/AssetAssignMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/aiassistant/mapper/AttachmentMapper.java
Original file line number Diff line number Diff line change
@@ -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);
}
8 changes: 0 additions & 8 deletions src/main/java/com/aiassistant/mapper/EmployeeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 31 additions & 0 deletions src/main/java/com/aiassistant/model/Attachment.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/aiassistant/service/AttachmentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.aiassistant.service;

import com.aiassistant.model.Attachment;
import com.aiassistant.utils.ResultModel;

public interface AttachmentService {
ResultModel<Attachment> addAttachment(Attachment attachment);

ResultModel<Attachment> getAttachmentById(Integer id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ResultModel<Asset> 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Attachment> addAttachment(Attachment attachment) {
attachmentMapper.insertAttachment(attachment);
return new ResultModel<>(attachment);
}

@Override
public ResultModel<Attachment> getAttachmentById(Integer id) {
Attachment attachment = attachmentMapper.selectById(id);
if (attachment != null) {
return new ResultModel<>(attachment);
} else {
return new ResultModel<>(ResultModel.FAIL, "Attachment not found");
}
}
}

0 comments on commit 746a185

Please sign in to comment.