提交 83cc0a73 authored 作者: zjm's avatar zjm

修改附件接口

上级 c360fe55
流水线 #46 已取消 于阶段
......@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static org.springframework.http.ResponseEntity.ok;
/**
......@@ -32,12 +34,19 @@ public class AttachmentController {
}
@PostMapping("/{workId}")
@ApiOperation(value = "新增附件并将其添加到所属工作中.", notes = "新增不可在数据中附带id.需要在路径中指定所属工作的id.成功时返回新增数据保存的id.")
public ResponseEntity<JobResponse> add(@RequestBody Attachment attachment, @PathVariable String workId) {
@ApiOperation(value = "新增附件结合并将其添加到所属工作中.", notes = "新增不可在数据中附带id.需要在路径中指定所属工作的id.成功时返回新增数据保存的id.")
public ResponseEntity<JobResponse> add(@RequestBody List<Attachment> attachment, @PathVariable String workId) {
String saveId = attachmentService.add(attachment, workId);
return ok(new JobResponse(saveId));
}
@PostMapping("/one/{workId}")
@ApiOperation(value = "新增附件并将其添加到所属工作中.", notes = "新增不可在数据中附带id.需要在路径中指定所属工作的id.成功时返回新增数据保存的id.")
public ResponseEntity<JobResponse> add(@RequestBody Attachment attachment) {
String saveId = attachmentService.add(attachment);
return ok(new JobResponse(saveId));
}
@PutMapping()
@ApiOperation(value = "修改附件.", notes = "修改必须在数据中附带id.")
public ResponseEntity<JobResponse> modify(@RequestBody Attachment attachment) {
......
......@@ -48,7 +48,7 @@ public class WorkController {
@ApiOperation(value = "根据id查询工作.", notes = "在路径中指定要查询的工作id.")
public ResponseEntity<WorkVo> findById(@PathVariable String workId) {
return ok( conversionService.workToVo(workService.findById(workId)));
return ok(conversionService.workToVo(workService.findById(workId)));
}
......
......@@ -36,6 +36,16 @@ public interface AttachmentService {
*/
String add(Attachment attachment, String workId);
/**
* 根据workId新增Attachment并与所属Work建立关系
* 不可附带id
*
* @param attachments Attachment集合对象
* @param workId 所属工作id
* @return Attachment对象的id
*/
String add(List<Attachment> attachments, String workId);
/**
* 修改Attachment
* 必须附带id
......
......@@ -90,6 +90,39 @@ public class AttachmentServiceImpl implements AttachmentService {
}
}
@Override
public String add(List<Attachment> attachments, String workId) {
if (attachments.size() == 0) {
String msg = "[Attachment] 没有附件";
log.error(msg);
throw new BadRequestException(msg);
}
for (Attachment attachment : attachments){
Boolean idMustNull = isNull(attachment.getId());
if (idMustNull) {
Boolean workMustExist = workService.idExists(workId);
if (workMustExist) {
String saveId = attachmentRepository.save(attachment).getId();
Work work = workService.findById(workId);
if (isNull(work.getAttachment())) {
work.setAttachment(Lists.newArrayList());
}
work.getAttachment().add(saveId);
workService.modify(work);
} else {
String msg = "[job] 指定id的所属工作不存在.";
log.error(msg);
throw new NotFoundException(msg);
}
} else {
String msg = "[job] 新增数据不可附带id.";
log.error(msg);
throw new BadRequestException(msg);
}
}
return "添加附件成功";
}
@Override
public String modify(Attachment attachment) {
Boolean idExist = nonNull(attachment.getId());
......
......@@ -7,6 +7,7 @@ import com.zjty.tynotes.job.basic.service.AttachmentService;
import com.zjty.tynotes.job.basic.service.ConversionService;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -14,6 +15,7 @@ import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class ConversionServiceImpl implements ConversionService {
@Autowired
IUserService iUserService;
......@@ -23,6 +25,7 @@ public class ConversionServiceImpl implements ConversionService {
@Override
public WorkVo workToVo(Work work) {
log.info("开始转换对象");
User pUser=iUserService.findUserById(work.getPublisher());
User eUser=iUserService.findUserById(work.getExecutor());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论