|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
package digital.laboratory.platform.reagent.controller; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.file.FileNameUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
@ -7,26 +9,34 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import digital.laboratory.platform.common.core.util.R; |
|
|
|
|
import digital.laboratory.platform.common.log.annotation.SysLog; |
|
|
|
|
import digital.laboratory.platform.common.mybatis.security.service.DLPUser; |
|
|
|
|
import digital.laboratory.platform.common.oss.service.OssFile; |
|
|
|
|
import digital.laboratory.platform.reagent.entity.InstructionBook; |
|
|
|
|
import digital.laboratory.platform.reagent.entity.ReagentConsumables; |
|
|
|
|
import digital.laboratory.platform.reagent.service.InstructionBookService; |
|
|
|
|
import digital.laboratory.platform.reagent.service.ReagentConsumablesService; |
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.security.Principal; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* (标准物质期间核查指导书) |
|
|
|
|
* |
|
|
|
|
* @author Zhang Xiaolong created at 2023-03-10 |
|
|
|
|
* @describe (标准物质期间核查指导书) 前端控制器 |
|
|
|
|
* |
|
|
|
|
* <p> |
|
|
|
|
* 这是与表示层的接口, 不应该接业务逻辑写在这里, 业务逻辑应该写在 service 中 |
|
|
|
|
* 这里写什么: |
|
|
|
|
* 为前端提供数据, 接受前端的数据 |
|
|
|
@ -40,112 +50,93 @@ import java.security.Principal; |
|
|
|
|
@Api(value = "instruction_book", tags = "(标准物质期间核查指导书)管理") |
|
|
|
|
public class InstructionBookController { |
|
|
|
|
|
|
|
|
|
private final ReagentConsumablesService reagentConsumablesService; |
|
|
|
|
private final InstructionBookService instructionBookService; |
|
|
|
|
|
|
|
|
|
private final OssFile ossFile; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通过id查询(标准物质期间核查指导书) |
|
|
|
|
* @param instructionBookId id |
|
|
|
|
* 新增(标准物质期间核查指导书) |
|
|
|
|
* |
|
|
|
|
* @param id (标准物质期间核查指导书) |
|
|
|
|
* @return R |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "通过id查询", notes = "通过id查询") |
|
|
|
|
@GetMapping("/{instructionBookId}" ) |
|
|
|
|
@PreAuthorize("@pms.hasPermission('reagent_instruction_book_get')" ) |
|
|
|
|
public R<InstructionBook> getById(@PathVariable("instructionBookId" ) String instructionBookId, HttpServletRequest theHttpServletRequest) { |
|
|
|
|
@ApiOperation(value = "上传(标准物质期间核查指导书)", notes = "上传(标准物质期间核查指导书)") |
|
|
|
|
@SysLog("上传(标准物质期间核查指导书)") |
|
|
|
|
@PostMapping |
|
|
|
|
// @PreAuthorize("@pms.hasPermission('reagent_instruction_book_add')" )
|
|
|
|
|
public R<InstructionBook> upload(String id, @RequestPart(value = "file", required = false) MultipartFile file, HttpServletRequest theHttpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
|
|
|
|
Principal principal = theHttpServletRequest.getUserPrincipal(); |
|
|
|
|
DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); |
|
|
|
|
|
|
|
|
|
InstructionBook instructionBook = instructionBookService.getById(instructionBookId); |
|
|
|
|
return R.ok(instructionBook); |
|
|
|
|
//return R.ok(instructionBookService.getById(instructionBookId));
|
|
|
|
|
} |
|
|
|
|
ReagentConsumables byId = reagentConsumablesService.getById(id); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分页查询 |
|
|
|
|
* @param page 分页对象 |
|
|
|
|
* @param instructionBook (标准物质期间核查指导书) |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "分页查询", notes = "分页查询") |
|
|
|
|
@GetMapping("/page" ) |
|
|
|
|
@PreAuthorize("@pms.hasPermission('reagent_instruction_book_get')" ) |
|
|
|
|
public R<IPage<InstructionBook>> getInstructionBookPage(Page<InstructionBook> page, InstructionBook instructionBook, HttpServletRequest theHttpServletRequest) { |
|
|
|
|
Principal principal = theHttpServletRequest.getUserPrincipal(); |
|
|
|
|
DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); |
|
|
|
|
String path = "reagen_managment" + "/" + "instructionBook" + "/" + byId.getReagentConsumableId(); |
|
|
|
|
String fileName = FileNameUtil.getName(file.getOriginalFilename()); |
|
|
|
|
boolean b = ossFile.fileUpload(file, path); |
|
|
|
|
Map<String, String> ResultData = new HashMap<>(); |
|
|
|
|
ResultData.put("fileName", fileName); |
|
|
|
|
ResultData.put("path", path); |
|
|
|
|
InstructionBook instructionBook = new InstructionBook(); |
|
|
|
|
|
|
|
|
|
IPage<InstructionBook> instructionBookSList = instructionBookService.page(page, Wrappers.<InstructionBook>query() |
|
|
|
|
.eq("create_by", dlpUser.getId()) |
|
|
|
|
.orderByDesc("create_time") |
|
|
|
|
); |
|
|
|
|
return R.ok(instructionBookSList); |
|
|
|
|
// return R.ok(instructionBookService.page(page, Wrappers.query(instructionBook)));
|
|
|
|
|
} |
|
|
|
|
if (b) { |
|
|
|
|
instructionBook.setId(IdWorker.get32UUID().toUpperCase()); |
|
|
|
|
instructionBook.setSetTime(LocalDateTime.now()); |
|
|
|
|
instructionBook.setMakerId(dlpUser.getId()); |
|
|
|
|
instructionBook.setReferenceMaterialTypeId(byId.getReagentConsumableId()); |
|
|
|
|
instructionBook.setInstructionBook(fileName); |
|
|
|
|
|
|
|
|
|
String fileNames = path + "/" + fileName; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增(标准物质期间核查指导书) |
|
|
|
|
* @param instructionBook (标准物质期间核查指导书) |
|
|
|
|
* @return R |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "新增(标准物质期间核查指导书)", notes = "新增(标准物质期间核查指导书)") |
|
|
|
|
@SysLog("新增(标准物质期间核查指导书)" ) |
|
|
|
|
@PostMapping |
|
|
|
|
@PreAuthorize("@pms.hasPermission('reagent_instruction_book_add')" ) |
|
|
|
|
public R<InstructionBook> postAddObject(@RequestBody InstructionBook instructionBook, HttpServletRequest theHttpServletRequest) { |
|
|
|
|
Principal principal = theHttpServletRequest.getUserPrincipal(); |
|
|
|
|
DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); |
|
|
|
|
ossFile.fileGet(fileNames, httpServletResponse.getOutputStream()); |
|
|
|
|
|
|
|
|
|
instructionBook.setId(IdWorker.get32UUID().toUpperCase()); |
|
|
|
|
if (instructionBookService.save(instructionBook)) { |
|
|
|
|
return R.ok(instructionBook, "对象创建成功"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return R.failed(instructionBook, "对象创建失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
instructionBookService.save(instructionBook); |
|
|
|
|
|
|
|
|
|
return R.ok(instructionBook, "上传成功"); |
|
|
|
|
} else return R.failed("上传失败"); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改(标准物质期间核查指导书) |
|
|
|
|
* @param instructionBook (标准物质期间核查指导书) |
|
|
|
|
* @return R |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "修改(标准物质期间核查指导书)", notes = "修改(标准物质期间核查指导书)") |
|
|
|
|
@SysLog("修改(标准物质期间核查指导书)" ) |
|
|
|
|
@PutMapping |
|
|
|
|
@PreAuthorize("@pms.hasPermission('reagent_instruction_book_edit')" ) |
|
|
|
|
public R<InstructionBook> putUpdateById(@RequestBody InstructionBook instructionBook, HttpServletRequest theHttpServletRequest) { |
|
|
|
|
Principal principal = theHttpServletRequest.getUserPrincipal(); |
|
|
|
|
DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); |
|
|
|
|
|
|
|
|
|
if (instructionBookService.updateById(instructionBook)) { |
|
|
|
|
return R.ok(instructionBook, "保存对象成功"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return R.failed(instructionBook, "保存对象失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通过id删除(标准物质期间核查指导书) |
|
|
|
|
* @param instructionBookId id |
|
|
|
|
* 新增(标准物质期间核查指导书) |
|
|
|
|
* |
|
|
|
|
* @param id (标准物质期间核查指导书) |
|
|
|
|
* @return R |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "通过id删除(标准物质期间核查指导书)", notes = "通过id删除(标准物质期间核查指导书)") |
|
|
|
|
@SysLog("通过id删除(标准物质期间核查指导书)" ) |
|
|
|
|
@DeleteMapping("/{instructionBookId}" ) |
|
|
|
|
@PreAuthorize("@pms.hasPermission('reagent_instruction_book_del')" ) |
|
|
|
|
public R<InstructionBook> deleteById(@PathVariable String instructionBookId, HttpServletRequest theHttpServletRequest) { |
|
|
|
|
@ApiOperation(value = "预览(标准物质期间核查指导书)", notes = "预览(标准物质期间核查指导书)(标准物质期间核查指导书)") |
|
|
|
|
@SysLog("预览(标准物质期间核查指导书)(标准物质期间核查指导书)") |
|
|
|
|
@GetMapping("/download") |
|
|
|
|
// @PreAuthorize("@pms.hasPermission('reagent_instruction_book_add')" )
|
|
|
|
|
public R<InstructionBook> download(String id, HttpServletRequest theHttpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
|
|
|
|
Principal principal = theHttpServletRequest.getUserPrincipal(); |
|
|
|
|
DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); |
|
|
|
|
|
|
|
|
|
InstructionBook oldInstructionBook = instructionBookService.getById(instructionBookId); |
|
|
|
|
ReagentConsumables byId = reagentConsumablesService.getById(id); |
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<InstructionBook> instructionBookLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
|
|
instructionBookLambdaQueryWrapper.eq(InstructionBook::getReferenceMaterialTypeId, byId.getReagentConsumableId()); |
|
|
|
|
|
|
|
|
|
if (instructionBookService.removeById(instructionBookId)) { |
|
|
|
|
return R.ok(oldInstructionBook, "对象删除成功"); |
|
|
|
|
InstructionBook one = instructionBookService.getOne(instructionBookLambdaQueryWrapper); |
|
|
|
|
|
|
|
|
|
if (one != null) { |
|
|
|
|
|
|
|
|
|
String fileName = one.getInstructionBook(); |
|
|
|
|
|
|
|
|
|
String path = "reagen_managment" + "/" + "instructionBook" + "/" + byId.getReagentConsumableId(); |
|
|
|
|
|
|
|
|
|
String fileNames = path + "/" + fileName; |
|
|
|
|
|
|
|
|
|
ossFile.fileGet(fileNames, httpServletResponse.getOutputStream()); |
|
|
|
|
|
|
|
|
|
return R.ok(one); |
|
|
|
|
} else |
|
|
|
|
return R.ok(null); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return R.failed(oldInstructionBook, "对象删除失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|