sampleNos = new ArrayList<>();
+ for (ApplySampleVO sampleVO : applyVO.getSampleVO()) {
+ if(sampleVO.getStatus()==1){
+ str=str+sampleVO.getSampleNo()+"\n";
+ }
+ }
+
+ dm.put("sampleNo",str);
+
+ //-----------------------------
+ // 生成 word 版本的 鉴定委托书
+
+ String applyFileName = "";
+
+ if (applyVO.getApplyType() == 1) {//外带申请
+ applyFileName = "携带毒品外出申请表-" + applyVO.getId();
+ } else {
+ applyFileName = "待销毁检材样本报批表-" + applyVO.getId();
+ }
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ if (applyVO.getApplyType() == 1) {//外带申请
+ ossFile.fileGet("template" + "/" + "携带毒品外出申请表模板.docx", bos);
+ } else {
+ ossFile.fileGet("template" + "/" + "待销毁检材报批申请表模板.docx", bos);
+ }
+ byte[] templateArray = bos.toByteArray();
+ ByteArrayInputStream bis = new ByteArrayInputStream(templateArray);
+ bos.close();
+ // 现在 bis 是模板的 InputStream
+ ConfigureBuilder builder = Configure.builder().buildGramer("${", "}").useSpringEL(false);
+ XWPFTemplate template = XWPFTemplate.compile(bis, builder.build()).render(dm);
+ bis.close();
+
+ ByteArrayOutputStream fosWord = new ByteArrayOutputStream();
+ template.write(fosWord);
+ template.close();
+
+ //------------
+ ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
+ fosWord.close();
+
+ //MockMultipartFile mockMultipartFile = new MockMultipartFile("file", entrustmentLetterFileName + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fisWord);
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file", applyFileName + ".docx", "image/jpg", fisWord);
+ Response response = remoteWord2PDFService.word2pdf(mockMultipartFile);
+ fisWord.close();
+
+
+ ByteArrayOutputStream outPDF = new ByteArrayOutputStream();
+ IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE);
+ ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray());
+ outPDF.close();
+
+
+ ossFile.fileSave("document" + "/" + "application" + "/" + applyVO.getId() + "/" + applyFileName + ".pdf", isPDF);
+ isPDF.close();
+
+ System.out.println("转换为 PDF 结束");
+
+ }
+}
+
diff --git a/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseApplyController.java b/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseApplyController.java
new file mode 100644
index 0000000..4c285c8
--- /dev/null
+++ b/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseApplyController.java
@@ -0,0 +1,472 @@
+package digital.laboratory.platform.imr.controller;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+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.imr.dto.CombinationOut;
+import digital.laboratory.platform.imr.dto.OutWarehouseApplyDTO;
+import digital.laboratory.platform.imr.dto.QueryDTO;
+import digital.laboratory.platform.imr.entity.SampleOutWarehouseApply;
+import digital.laboratory.platform.imr.entity.SampleStorage;
+import digital.laboratory.platform.imr.mapper.SampleStorageMapper;
+import digital.laboratory.platform.imr.service.SampleOutWarehouseApplyService;
+import digital.laboratory.platform.imr.vo.OutSampleVO;
+import digital.laboratory.platform.imr.vo.RepositorySampleVO;
+import digital.laboratory.platform.imr.vo.SampleOutWarehouseApplyVO;
+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 javax.servlet.http.HttpServletRequest;
+import java.security.Principal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 样本出库申请实体类
+ *
+ * @author Zhang Xiaolong created at 2023-03-17
+ * @describe 样本出库申请实体类 前端控制器
+ *
+ * 这是与表示层的接口, 不应该接业务逻辑写在这里, 业务逻辑应该写在 service 中
+ * 这里写什么:
+ * 为前端提供数据, 接受前端的数据
+ * 为前端提供的数据, 从 service 取得后, 可以做一些适当的加工, 这种加工不是业务层面的, 只能是数据格式上, 为方便前端处理
+ * 接受前端的数据, 每一个函数的参数可以先做一些整理后, 再调用 service 中的函数。这里对参数的整理, 应该只是格式上的, 而不能是业务上的
+ * 数据层在 mapper 中, 数据层不涉及业务, 只管技术上的 对象<->表 之间的转换
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/sample_out_warehouse_apply")
+@Api(value = "sample_out_warehouse_apply", tags = "领用出库申请管理")
+public class SampleOutWarehouseApplyController {
+
+ private final SampleOutWarehouseApplyService sampleOutWarehouseApplyService;
+
+ private final SampleStorageMapper storageMapper;
+
+ /**
+ * 通过id查询样本出库申请实体类
+ *
+ * @param id id
+ * @return R
+ */
+ @ApiOperation(value = "通过id查询", notes = "通过id查询")
+ @GetMapping("/{id}")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_get')")
+ public R getById(@PathVariable("id") String id, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ SampleOutWarehouseApplyVO outWarehouseApplyVO = sampleOutWarehouseApplyService.getOutWarehouseDetailedById(id);
+ if (outWarehouseApplyVO != null) {
+ return R.ok(outWarehouseApplyVO, "查询成功");
+ } else {
+ return R.failed("查询失败");
+ }
+ }
+
+ /**
+ * 分页查询
+ *
+ * @param dto 查询参数
+ * @return
+ */
+ @ApiOperation(value = "分页查询", notes = "分页查询")
+ @GetMapping("/page")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_get')")
+ public R> getSampleOutWarehouseApplyPage(QueryDTO dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ QueryWrapper query = Wrappers.query();
+ query.eq("applicant_id", dlpUser.getId());
+ query.between(dto.getBeginDate() != null && dto.getFinishDate() != null, "application_date", dto.getBeginDate(), dto.getFinishDate());
+ query.orderByDesc("create_time");
+
+ if (dto.getStatus() == 0) {//返回待审核和待使用的数据
+ ArrayList integers = new ArrayList<>();
+ integers.add(1);
+ integers.add(2);
+ query.in("status", integers);
+ } else if (dto.getStatus() == 1) {
+ query.eq("status", 1);
+ } else if (dto.getStatus() == 2) {
+ query.eq("status", 2);
+ } else if (dto.getStatus() == 3) {
+ query.eq("status", 3);
+ }
+
+ if (dto.getStatus() == 4) {//全部数据--出库模块备用
+ ArrayList integers = new ArrayList<>();
+ integers.add(1);
+ integers.add(2);
+ integers.add(3);
+ query.in("status", integers);
+ }
+
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+
+ IPage thisPage = sampleOutWarehouseApplyService.getSampleOutWarehouseApplyVOPage(page, query);
+ return R.ok(thisPage, "查询出库申请成功");
+ }
+
+ @ApiOperation(value = "列表查询", notes = "列表查询")
+ @GetMapping("/list")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_list')")
+ public R> getSampleOutWarehouseApplyList(Page page, SampleOutWarehouseApply sampleOutWarehouseApply, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ IPage thisList = sampleOutWarehouseApplyService.getSampleOutWarehouseApplyVOList(Wrappers.query()
+ .eq("applicant_id", dlpUser.getId())
+ .eq(sampleOutWarehouseApply.getStatus() != null, "status", sampleOutWarehouseApply.getStatus())
+ .orderByDesc("create_time")
+ );
+ return R.ok(thisList, "查询出库申请成功");
+ }
+
+
+ /**
+ * 查询当前已经存入仓库的样本信息(全部查询)
+ */
+
+ @ApiOperation(value = "创建领用申请时的查询样本接口--分页", notes = "创建领用申请时的查询样本接口--分页")
+ @GetMapping("/getSampleInfo")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_list')")
+ public R getSampleInfo(QueryDTO dto) {
+
+ List sampleIds = Arrays.asList(dto.getSampleIds().split(","));
+
+ if (dto.getType() == 1) {//任务
+ IPage sampleVOIPage2 = new Page<>();
+ List records1 = new ArrayList<>();
+
+ if (dto.getType() == 1) {
+ Integer begin = (dto.getCurrent() - 1) * dto.getSize();
+ CombinationOut combinationOut = new CombinationOut(sampleIds, begin, dto.getSize(), dto.getName());
+ //获取仓库现有样本;并进行事件分类
+ //1.委托
+ List vo1 = storageMapper.getWTSample(combinationOut);
+ if (!vo1.isEmpty()) {
+ records1.addAll(vo1);
+ }
+
+ List vo2 = storageMapper.getWSSample(combinationOut);
+ if (!vo2.isEmpty()) {
+ records1.addAll(vo2);
+ }
+ List vo3 = storageMapper.getMFSample(combinationOut);
+ if (!vo3.isEmpty()) {
+ records1.addAll(vo3);
+ }
+ List vo4 = storageMapper.getSJSample(combinationOut);
+ if (!vo4.isEmpty()) {
+ records1.addAll(vo4);
+ }
+ List vo5 = storageMapper.getTZSample(combinationOut);
+ if (!vo5.isEmpty()) {
+ records1.addAll(vo5);
+ }
+ }
+
+ if (records1.size() == 0) {
+ return R.ok(sampleVOIPage2, "暂无数据");
+ }
+ Collections.sort(records1, new Comparator() {
+ @Override
+ public int compare(OutSampleVO o1, OutSampleVO o2) {
+ return o1.getRoomNo().compareTo(o2.getSampleNo());
+ }
+ });
+ List records2 = new ArrayList<>();
+ sampleVOIPage2.setSize(dto.getSize());
+ int pageCurrent = (dto.getCurrent() - 1) * dto.getSize();
+ int pageTotal = 0;
+ if (records1.size() % dto.getSize() == 0) {
+ pageTotal = records1.size() / dto.getSize();
+ } else {
+ pageTotal = records1.size() / dto.getSize() + 1;
+ }
+ if (pageCurrent + dto.getSize() <= records1.size()) {
+ records2 = records1.subList(pageCurrent, pageCurrent + dto.getSize());
+ } else if (records1.size() % dto.getSize() > sampleIds.size() - 1) {
+ records2 = records1.subList(pageCurrent, records1.size());
+ } else if (dto.getCurrent() > pageTotal) {
+ records2 = records1.subList(pageCurrent - dto.getSize(), records1.size());
+ } else {
+ records2 = records1.subList(pageCurrent, records1.size());
+ }
+ sampleVOIPage2.setTotal(records1.size());//不分页总数
+ sampleVOIPage2.setRecords(records2);
+ return R.ok(sampleVOIPage2, "查询成功");
+
+ } else {
+// int size = sampleIds.size();
+// if ("".equals(dto.getSampleIds())) {
+// size = sampleIds.size() - 1;
+// }
+// if (dto.getTotal() != 0) {
+// int num = 0;//去重后目前能分的页数
+//
+// if ((dto.getTotal() - size) % 8 == 0) {
+// num = (dto.getTotal() - size) / 8;
+// } else {
+// num = (dto.getTotal() - size) / 8 + 1;
+// }
+//
+//
+// if (dto.getCurrent() > num) {
+// //求余数
+// int a = dto.getTotal() % 8;//求最后一页的剩余条数
+// if (a == 0) {
+// a = 8;
+// }
+// if (sampleIds.size() >= a) {
+// dto.setCurrent(num);
+// }
+// }
+// }
+// Page page = new Page<>(dto.getCurrent(), dto.getSize());
+
+ List sampleVOList = storageMapper.getSampleInfoList(Wrappers.query()
+ .and(StringUtils.isNotBlank(dto.getName()), qw -> qw
+ .like("storage.name", dto.getName())
+ .or()
+ .like("sample_no", dto.getName()))
+ .notIn(!sampleIds.isEmpty(), "storage.sample_id", sampleIds)//去重数组sampleIds
+ .eq("storage.status", 2) //只能查找存入仓库的样本数据
+ .eq("s.status", 2)//并且sample实际状态为2
+ .like(StringUtils.isNotBlank(dto.getRoomNo()), "storage.room_no", dto.getRoomNo())
+ .orderByDesc("sample_no")
+ );
+ for (OutSampleVO vo : sampleVOList) {
+ vo.setSampleId(vo.getId());
+ String eventName = "";
+ //entrustment/hairJob/sewageJob
+ if (vo.getSource().equals("entrustment")) {
+ //委托
+ eventName = storageMapper.getEntrustmentName(vo.getSampleId());
+ } else if (vo.getSource().equals("hairJob")) {
+ //毛发
+ eventName = storageMapper.getHairJobName(vo.getSampleId());
+ } else if (vo.getSource().equals("sewageJob")) {
+ //污水
+ eventName = storageMapper.getSewageJobName(vo.getSampleId());
+ } else if (vo.getSource().contains("Event")) {//通用事件
+ //内部录入
+ eventName = storageMapper.getEventName(vo.getSampleId());
+ } else {
+ //特征分析
+ eventName = storageMapper.getFeatureName(vo.getSampleId());
+ }
+ vo.setEventName(eventName);
+ }
+ Map> map = sampleVOList.stream().collect(Collectors.groupingBy(item -> item.getSource()));
+ List entrustmentSampleList = map.get("entrustment");
+ List outSampleVOS = new ArrayList<>();
+ if (entrustmentSampleList != null && entrustmentSampleList.size() > 0) {
+ sampleVOList.removeAll(entrustmentSampleList);
+ Collections.sort(entrustmentSampleList, new Comparator() {
+ @Override
+ public int compare(OutSampleVO o1, OutSampleVO o2) {
+ String[] split1 = o1.getSampleNo().split("-");
+ String[] split2 = o2.getSampleNo().split("-");
+ // 先比较年份
+ int yearComparison = split2[0].compareTo(split1[0]);
+ if (yearComparison != 0) {
+ return yearComparison;
+ }
+ // 再比较序号
+ int num1 = Integer.parseInt(split2[1]);
+ int num2 = Integer.parseInt(split1[1]);
+ if (num1 - num2 != 0) {
+ return num1 - num2;
+ }
+
+ // 再比较尾号
+ int num3 = Integer.parseInt(split1[2]);
+ int num4 = Integer.parseInt(split2[2]);
+ return num3 - num4;
+
+ }
+ });
+ outSampleVOS.addAll(entrustmentSampleList);
+ }
+ outSampleVOS.addAll(sampleVOList);
+ return R.ok(outSampleVOS, "查询成功");
+ }
+ }
+
+
+ /**
+ * 查询当前已经存入仓库的样本信息(根据当前登录人查询对应部门的sample信息)
+ */
+
+
+ /**
+ * 新增样本出库申请实体类
+ *
+ * @param dto 样本出库申请实体类
+ * @return R
+ */
+ @ApiOperation(value = "新增样本出库申请实体类", notes = "新增样本出库申请实体类")
+ @SysLog("新增样本出库申请实体类")
+ @PostMapping("/addOutApply")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_add')")
+ public R postAddOutApply(@RequestBody OutWarehouseApplyDTO dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ //数据校验
+ if (dto.getSampleIds() == null || dto.getSampleIds().size() == 0) {
+ throw new RuntimeException("申请出库检材不能为空");
+ }
+ if (dto.getReturnDate() == null) {
+ throw new RuntimeException("归还时间不能为空");
+ }
+ if ("".equals(dto.getAppraiserId()) || dto.getAppraiserId().isEmpty()) {
+ throw new RuntimeException("鉴定人不能为空");
+ }
+
+ SampleOutWarehouseApplyVO vo = sampleOutWarehouseApplyService.createOutApply(dto, dlpUser);
+ if (vo != null) {
+ return R.ok(vo, "创建出库申请成功");
+ } else {
+ return R.failed("创建出库申请失败");
+ }
+ }
+
+
+ /**
+ * 创建样本出库申请(接口2)
+ *
+ * @param dto
+ * @param theHttpServletRequest
+ * @return
+ */
+ @ApiOperation(value = "创建样本出库申请(老版本)", notes = "创建样本出库申请(老版本)")
+ @SysLog("创建样本出库申请")
+ @PostMapping("/createOutRepositoryApply")
+ @PreAuthorize("@pms.hasPermission('imr_sample_out_warehouse_apply_add')")
+ public R createOutRepositoryApply(@RequestBody OutWarehouseApplyDTO dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ //数据校验
+ if (dto.getSampleIds().isEmpty()) {
+ throw new RuntimeException("申请检材不能为空");
+ }
+ if (dto.getReturnDate() == null) {
+ throw new RuntimeException("归还时间不能为空");
+ }
+ if ("".equals(dto.getAppraiserId()) || dto.getAppraiserId().isEmpty()) {
+ throw new RuntimeException("鉴定人不能为空");
+ }
+
+ SampleOutWarehouseApplyVO vo = sampleOutWarehouseApplyService.createOutRepositoryApply(dto, dlpUser);
+ if (vo != null) {
+ return R.ok(vo, "创建出库申请成功");
+ } else {
+ return R.failed("创建出库申请失败");
+ }
+ }
+
+
+ @ApiOperation(value = "取检条码打印",
+ notes = "取检条码打印")
+ @SysLog("检材条码打印")
+ @GetMapping("/print_QR_code")
+ public String printgetSampleQRCode(String code) {
+
+ return sampleOutWarehouseApplyService.buildEventImLabelContent(code);
+ }
+
+
+ /**
+ * 以下为新创建接口----------------------------------------------------------------------
+ */
+
+ @GetMapping("/testQuery")
+ public R testQuery(QueryDTO dto) {
+
+ List sampleIds = Arrays.asList(dto.getSampleIds().split(","));
+ IPage sampleVOIPage2 = new Page<>();
+ List records1 = new ArrayList<>();
+ int total = 0;
+
+ if (dto.getType() == 1) {
+ Integer begin = (dto.getCurrent() - 1) * dto.getSize();
+ CombinationOut combinationOut = new CombinationOut(sampleIds, begin, dto.getSize(), dto.getName());
+ //获取仓库现有样本;并进行事件分类
+ //1.委托
+ List vo1 = storageMapper.getWTSample(combinationOut);
+ if (!vo1.isEmpty()) {
+ total = total + vo1.size();
+ records1.addAll(vo1);
+ }
+
+ //2.污水
+ List vo2 = storageMapper.getWSSample(combinationOut);
+ if (!vo2.isEmpty()) {
+ total = total + vo2.size();
+ records1.addAll(vo2);
+ }
+ //3.毛发
+ List vo3 = storageMapper.getMFSample(combinationOut);
+ if (!vo3.isEmpty()) {
+ total = total + vo3.size();
+ records1.addAll(vo3);
+ }
+ //4.事件
+ List vo4 = storageMapper.getSJSample(combinationOut);
+ if (!vo4.isEmpty()) {
+ total = total + vo4.size();
+ records1.addAll(vo4);
+ }
+ }
+
+ sampleVOIPage2.setTotal(total);
+ sampleVOIPage2.setRecords(records1);
+ return R.ok(sampleVOIPage2, "查询成功");
+ }
+
+
+
+ /*if(pageCurrentsampleIds.size()-1){
+ records2 = records1.subList(pageCurrent,records1.size());
+ }else {
+ if(dto.getCurrent()>=2){
+ records2 = records1.subList(pageCurrent-dto.getSize(),records1.size());
+ }else {
+ records2 = records1.subList(0,records1.size());
+ }
+ }
+ }
+ }*/
+
+ /*if(records1.size()%dto.getSize()>sampleIds.size()-1){
+ records2 = records1.subList(pageCurrent,records1.size());
+ }else {
+ if (dto.getCurrent() > Math.ceil((float)records1.size()/dto.getSize())) {
+ records2 = records1.subList(pageCurrent - dto.getSize(), records1.size());
+ } else {
+ records2 = records1.subList(pageCurrent, records1.size());
+ }
+ }*/
+
+
+}
diff --git a/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseController.java b/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseController.java
new file mode 100644
index 0000000..3de459f
--- /dev/null
+++ b/src/main/java/digital/laboratory/platform/imr/controller/SampleOutWarehouseController.java
@@ -0,0 +1,594 @@
+package digital.laboratory.platform.imr.controller;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
+import digital.laboratory.platform.common.core.util.R;
+import digital.laboratory.platform.common.feign.RemoteWord2PDFService;
+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.imr.dto.*;
+import digital.laboratory.platform.imr.entity.*;
+import digital.laboratory.platform.imr.entity.enums.OutboundType;
+import digital.laboratory.platform.imr.mapper.DestructionDetailMapper;
+import digital.laboratory.platform.imr.mapper.SampleOutWarehouseApplyMapper;
+import digital.laboratory.platform.imr.mapper.SampleOutboundRecordMapper;
+import digital.laboratory.platform.imr.mapper.SampleStorageMapper;
+import digital.laboratory.platform.imr.service.DestructionPublicityService;
+import digital.laboratory.platform.imr.service.SampleOutWarehouseApplyService;
+import digital.laboratory.platform.imr.service.SampleOutWarehouseService;
+import digital.laboratory.platform.imr.vo.*;
+import feign.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.Principal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 自定义出库controller
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/sample_out_Warehouse" )
+@Api(value = "sample_out_Warehouse", tags = "样本出库管理")
+public class SampleOutWarehouseController {
+
+
+
+ private final SampleOutWarehouseApplyService sampleOutWarehouseApplyService;
+
+ private final DestructionPublicityService destructionPublicityService;
+
+ private final DestructionDetailMapper destructionDetailMapper;
+
+
+ private final SampleOutWarehouseApplyMapper outWarehouseApplyMapper;
+
+
+ private final SampleOutWarehouseService warehouseService;
+
+
+ private final SampleStorageMapper storageMapper;
+
+
+ private final SampleOutboundRecordMapper outboundRecordMapper;
+
+
+ private final RemoteWord2PDFService remoteWord2PDFService;
+
+ private final OssFile ossFile;
+
+
+
+
+ /**
+ * 分页查询
+ * @param dto 查询参数管理员可以看见所有数据
+ * @return
+ */
+ @ApiOperation(value = "出库模块领用出库申请--分页查询", notes = "出库模块领用出库申请--分页查询")
+ @GetMapping("/page" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')" )
+ public R> getSampleOutWarehouseApplyPage(QueryDTO dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ QueryWrapper query = Wrappers.query();
+ query.between(dto.getBeginDate()!=null && dto.getFinishDate()!=null,"application_date",dto.getBeginDate(),dto.getFinishDate());
+ query.orderByDesc("create_time");
+
+ if (dto.getStatus()==0){//返回待审核和待使用的数据
+ ArrayList integers = new ArrayList<>();
+ integers.add(1);
+ integers.add(2);
+ integers.add(3);
+ query.in("status",integers);
+ }else if (dto.getStatus()==1){
+ query.eq("status",1);
+ }
+ else if (dto.getStatus()==2){
+ query.eq("status",2);
+ }
+ else if (dto.getStatus()==3){
+ query.eq("status",3);
+ }
+
+ Page page = new Page<>(dto.getCurrent(),dto.getSize());
+
+ IPage thisPage = sampleOutWarehouseApplyService.getSampleOutWarehouseApplyVOPage(page,query);
+ return R.ok(thisPage,"查询出库申请成功");
+ }
+
+
+
+
+
+
+
+
+ /**
+ * 检材管理员看见领用出库申请然后点击同意出库
+ */
+
+ @ApiOperation(value = "检材管理员--确认同意领用申请", notes = "检材管理员--确认同意领用申请")
+ @PutMapping("/reconfirmApply" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R reconfirmApply(String id, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ if (id.isEmpty()){
+ throw new RuntimeException(String.format("id不能为空"));
+ }
+
+ SampleOutWarehouseApplyVO applyVO = sampleOutWarehouseApplyService.reconfirmApply(id,dlpUser.getId());
+
+
+ return R.ok(applyVO,"确认成功");
+ }
+
+
+ /**
+ * 根据"取检码"查询相关信息
+ */
+ @ApiOperation(value = "根据取检码查询相关信息", notes = "根据取检码查询相关信息")
+ @SysLog("根据取检码查询相关信息" )
+ @GetMapping("/code/{code}" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R getInfoByCode(@PathVariable("code" ) String code, HttpServletRequest theHttpServletRequest) {
+
+ if ("".equals(code)||code.isEmpty()) {
+ throw new RuntimeException(String.format("取检码不能为空"));
+ }
+ SampleOutWarehouseApplyVO vo = sampleOutWarehouseApplyService.getInfoByCode(code);
+ if (vo!=null) {
+ return R.ok(vo,"查询成功");
+ }else {
+ return R.failed("查询失败");
+ }
+ }
+
+
+ /**
+ * 根据"取检码"验证出库信息(确认出库)
+ * Confirm Outbound
+ */
+
+ @ApiOperation(value = "根据取检码验证出库信息(确认出库)", notes = "根据取检码验证出库信息(确认出库)")
+ @SysLog("根据取检码验证出库信息(确认出库)" )
+ @PutMapping("/confirmOutbound" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')")
+ public R confirmOutbound(@RequestBody VerificationCode dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ if(dto.getSampleIds().isEmpty()){
+ throw new RuntimeException("领用申请样本id不能为空");
+ }
+ if(StrUtil.isEmpty(dto.getCode())){
+ throw new RuntimeException("'取检码不能为空'");
+ }
+
+ SampleOutWarehouseApplyVO vo = sampleOutWarehouseApplyService.confirmOutbound(dto,dlpUser);
+ return R.ok(vo,"确认出库成功");
+
+ }
+
+
+ /**
+ * 退还/销毁出库---待销毁样本列表查询
+ */
+ @ApiOperation(value = "待销毁或退还出库的样本查询接口", notes = "待销毁或退还出库的样本查询接口--分页")
+ @GetMapping("/toBeDestroyed/page" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R getToBeDestroyedSample(QueryDTO dto) {
+
+ List sampleIds = Arrays.asList(dto.getSampleIds().split(","));
+ int size = sampleIds.size();
+ if ("".equals(dto.getSampleIds())){
+ size = sampleIds.size()-1;
+ }
+
+
+ if(dto.getTotal()!=0){
+ int num = 0;//去重后目前能分的页数
+
+ if((dto.getTotal()-size)%8==0){
+ num = (dto.getTotal()-size)/8;
+ }else {
+ num = (dto.getTotal()-size)/8+1;
+ }
+
+ System.out.println(num);
+
+ if(dto.getCurrent()>num){
+ //求余数
+ int a = dto.getTotal()%8;//求最后一页的剩余条数
+ if(a==0){
+ a=8;
+ if(sampleIds.size()>=a){
+ dto.setCurrent(num);
+ }
+ }else {
+ if(sampleIds.size()>=a){
+ dto.setCurrent(num);
+ }
+ }
+ }
+ }
+ Page page = new Page<>(dto.getCurrent(),dto.getSize());
+ /*
+ * 两个条件
+ * 审核通过待销毁状态-->=2
+ * 销毁申请通过的不能再退还中出现
+ *
+ * 还在仓库--status==2
+ */
+
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.notIn(!sampleIds.isEmpty(),"storage.sample_id",sampleIds);//去重数组sampleIds
+ queryWrapper.like(!dto.getName().isEmpty(),"storage.name",dto.getName());
+ queryWrapper.eq("storage.status",2); //只能查找存入仓库的样本数据
+ if(dto.getStatus()==null){
+ queryWrapper.ne("storage.early_warning",2); //如果是退还出库不需要去查询销毁申请通过的检材
+ }else {
+ queryWrapper.eq("storage.early_warning",dto.getStatus());//销毁出库就只查询销毁申请通过的
+ }
+ //queryWrapper.eq(dto.getStatus()!=null,"storage.early_warning",dto.getStatus());
+ IPage sampleVOIPage = storageMapper.getSampleInfoTwo(page,queryWrapper);
+ return R.ok(sampleVOIPage,"查询成功");
+ }
+
+ /**
+ * 退还出库自动查询退还单位
+ */
+ @ApiOperation(value = "退还出库查询委托方", notes = "退还出库查询委托方")
+ @GetMapping("/returnOutboundQuery" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R returnOutboundQuery(String sampleId) {
+
+
+ String orgName = storageMapper.returnOutboundQuery(sampleId);
+
+ return R.ok(orgName,"查询成功");
+ }
+
+ /**
+ * 退还出库
+ */
+ @ApiOperation(value = "退还出库", notes = "退还出库")
+ @PutMapping("/returnOutbound" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+
+ public R returnOutbound(@RequestBody ReturnOutboundDTO dto, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ if(dto.getSampleIds().isEmpty()){
+ throw new RuntimeException("样本信息不能为空");
+ }
+ if(dto.getReturnInstitution().isEmpty()){
+ throw new RuntimeException("退还单位不能为空");
+ }
+
+ warehouseService.returnOutbound(dto,dlpUser);
+
+ return R.ok("退还出库成功");
+
+ }
+
+ /**
+ * 销毁出库
+ */
+
+ @ApiOperation(value = "销毁出库", notes = "销毁出库")
+ @PutMapping("/destroyOutbound" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R destroyOutbound(@RequestBody DestroyOutboundDTO dto, HttpServletRequest theHttpServletRequest) {
+
+
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ /*
+ *这里销毁出库可能要先判断是否公示了
+ */
+// LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+// queryWrapper.in(DestructionDetail::getSampleId, dto.getSampleIds());
+// queryWrapper.orderByDesc(DestructionDetail::getUpdateTime);
+// List destructionDetails = destructionDetailMapper.selectList(queryWrapper); // 查询该dto中的样本id 是否已经公示
+// // 根据公示id 进行分类
+// Map> collect = destructionDetails.stream().collect(Collectors.groupingBy(item -> item.getDestructionId()));
+// collect.forEach((k, v) -> {
+// // 根据公示详情中关联的公示id 查公示
+// DestructionPublicity oneById = destructionPublicityService.getOneById(k);
+// if (oneById == null || oneById.getStatus() != 1) {
+// // 公示如果查不到或者状态不为1 则提示需要公示
+// throw new RuntimeException("请先进行销毁公示在出口!");
+// }
+// });
+
+
+ if(dto.getSampleIds().isEmpty()){
+ throw new RuntimeException("样本信息不能为空");
+ }
+
+ warehouseService.destroyOutbound(dto,dlpUser);
+
+ return R.ok("销毁出库成功");
+ }
+
+
+
+ /**
+ * 入库样本记录分页
+ */
+ @ApiOperation(value = "出库记录分页", notes = "出库记录分页")
+ @GetMapping("/outboundRecord/page" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')" )
+ public R> outboundRecord(QuerySampleDTO dto) {
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+ IPage sampleVOIPage = outboundRecordMapper.outboundRecord(page, Wrappers.query()
+ .like(!dto.getName().isEmpty(), "outbound.name", dto.getName())
+ .orderByDesc("create_time")
+ );
+
+ List records = sampleVOIPage.getRecords();
+ for (OutboundRecordVO record : records) {
+ record.setStatusCode(record.getOutboundType().getStatus());
+ if(record.getOutboundType() == OutboundType.RETURN){
+ record.setRecipientName(record.getRecipientId());//退还的比较特殊
+ }
+ //销毁出库
+ }
+ return R.ok(sampleVOIPage, "查询成功");
+
+
+ }
+
+
+ /**
+ * 待归还样本toBeReturned
+ */
+ @ApiOperation(value = "待归还样本--分页", notes = "待归还样本--分页")
+ @GetMapping("/toBeReturned/page" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')" )
+ public R> toBeReturned(QuerySampleDTO dto) {
+
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+
+ IPage sampleVOIPage = storageMapper.toBeReturned(page, Wrappers.query()
+ .like(!dto.getName().isEmpty(), "storage.name", dto.getName())
+ .eq("is_return",1)//只查询需要归还的
+ .eq("storage.status",3)
+ .orderByAsc("storage.update_time")
+ );
+ List records = sampleVOIPage.getRecords();
+ for (ToBeReturnVO toBeReturnVO : records) {
+ String eventName = "";
+ //entrustment/hairJob/sewageJob
+ switch (toBeReturnVO.getSource()) {
+ case "entrustment":
+ //委托
+ eventName = storageMapper.getEntrustmentName(toBeReturnVO.getSampleId());
+ break;
+ case "hairJob":
+ //毛发
+ eventName = storageMapper.getHairJobName(toBeReturnVO.getSampleId());
+ break;
+ case "sewageJob":
+ //污水
+ eventName = storageMapper.getSewageJobName(toBeReturnVO.getSampleId());
+ break;
+ case "Event污水":
+ case "Event毛发":
+ //内部录入
+ eventName = storageMapper.getEventName(toBeReturnVO.getSampleId());
+ break;
+ default:
+ //特征分析
+ eventName = storageMapper.getFeatureName(toBeReturnVO.getSampleId());
+ break;
+ }
+ toBeReturnVO.setEventName(eventName);
+ }
+
+
+ return R.ok(sampleVOIPage, "查询成功");
+
+
+ }
+
+ /**
+ * 查询单个待归还样本
+ */
+
+ @ApiOperation(value = "待归还样本--详情", notes = "待归还样本--详情")
+ @GetMapping("/toBeReturned/detail" )
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')" )
+ public R toBeReturnedDetail(String sampleId) {
+
+
+
+ RecipientDTO sampleVOIPage = storageMapper.toBeReturnedDetail(sampleId);
+
+ return R.ok(sampleVOIPage, "查询成功");
+
+
+ }
+
+ /**
+ * 出库模块对应角标
+ */
+
+ @ApiOperation(value = "出库模块对应角标0.待确认出库申请;2.出库待归还", notes = "出库模块对应角标0.待确认出库申请;2.出库待归还")
+ @GetMapping("/inboundIcon/count" )
+ //@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R> getIconCount() {
+
+
+ //出库申请
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+
+ queryWrapper.eq("status",1);//待确认(出库申请带确认)
+
+ Long count = outWarehouseApplyMapper.selectCount(queryWrapper);
+
+ IconDTO destroyed = new IconDTO(count, 0, "destroyed");
+
+ //出库待归还
+
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.eq("is_return",1);//需要归还
+ wrapper.eq("status",3);//领用出库了
+
+ Long selectCount = storageMapper.selectCount(wrapper);
+
+ IconDTO aReturn = new IconDTO(selectCount, 2, "return");
+
+
+ ArrayList iconDTOS = new ArrayList<>();
+ iconDTOS.add(destroyed);
+ iconDTOS.add(aReturn);
+ return R.ok(iconDTOS,"查询成功");
+
+ }
+
+
+
+ /**-------出库清单*/
+ /**
+ * 出库清单
+ *
+ * @param ids
+ *
+ * @return
+ */
+ @ApiOperation(value = "出库清单", notes = "出库清单")
+ @SysLog("出库清单")
+ @PostMapping("/print/inventory")
+// @PreAuthorize("@pms.hasPermission('EntrustmentEdit')")
+ public void bizGetPDFInventory(@RequestBody List ids, HttpServletRequest theHttpServletRequest, HttpServletResponse httpServletResponse) {
+ System.out.println("bizApplyWord.................");
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+
+ //查询数据
+ List voList = storageMapper.getSampleInventory(new QueryWrapper()
+ .in("storage.id", ids)//查询该集合中相关样本数据
+ );
+
+ if (voList.isEmpty()) {
+ throw new RuntimeException("未查询到相关信息");
+ }
+
+ String id = IdWorker.get32UUID().toUpperCase();
+
+ String applyFileName = "检材出库清单-"+id;
+
+ String pdfFilePath = "document" + "/"+"inventory" + "/" + id + "/" + applyFileName + ".pdf";
+ try {
+ //直接调用pdf方法
+ GenerateSampleApplyTablePDF(voList,id,theHttpServletRequest,httpServletResponse);
+ ossFile.fileGet(pdfFilePath, httpServletResponse.getOutputStream());
+ httpServletResponse.setContentType(applyFileName);
+ } catch (Exception e) {
+ System.out.printf("minioFile objectExist() Exception. %s%n", e.getLocalizedMessage());
+ e.printStackTrace();
+ }
+ }
+
+
+ private void GenerateSampleApplyTablePDF(List voList,String id, HttpServletRequest theHttpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
+ System.out.println("GenerateSampleApplyTablePDF.................");
+
+ //-----------------------------
+ // 生成 word 版本的 鉴定委托书
+
+ String applyFileName = "检材出库清单-"+id;
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ossFile.fileGet("template" + "/" + "检材出库清单模板.docx", bos);
+
+ byte[] templateArray = bos.toByteArray();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(templateArray);
+ bos.close();
+
+ for (int i = 0;i() {{
+ put("voList", voList);
+ }}
+ );
+ bis.close();
+
+ ByteArrayOutputStream fosWord = new ByteArrayOutputStream();
+ template.write(fosWord);
+ template.close();
+
+ //------------
+ ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray());
+ fosWord.close();
+
+ //MockMultipartFile mockMultipartFile = new MockMultipartFile("file", entrustmentLetterFileName + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fisWord);
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file", applyFileName + ".docx", "image/jpg", fisWord);
+ Response response = remoteWord2PDFService.word2pdf(mockMultipartFile);
+ fisWord.close();
+
+
+ ByteArrayOutputStream outPDF = new ByteArrayOutputStream();
+ IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE);
+ ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray());
+ outPDF.close();
+
+
+ ossFile.fileSave("document" + "/" + "inventory" + "/" + id + "/" + applyFileName + ".pdf", isPDF);
+ isPDF.close();
+
+
+ System.out.println("转换为 PDF 结束");
+
+ }
+
+
+
+
+ /**
+ * 催还
+ */
+
+}
diff --git a/src/main/java/digital/laboratory/platform/imr/controller/SamplePutInStorageController.java b/src/main/java/digital/laboratory/platform/imr/controller/SamplePutInStorageController.java
new file mode 100644
index 0000000..3cedd3f
--- /dev/null
+++ b/src/main/java/digital/laboratory/platform/imr/controller/SamplePutInStorageController.java
@@ -0,0 +1,947 @@
+package digital.laboratory.platform.imr.controller;
+
+
+import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
+import digital.laboratory.platform.common.core.util.R;
+import digital.laboratory.platform.common.feign.RemoteWord2PDFService;
+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.common.security.annotation.Inner;
+import digital.laboratory.platform.common.security.util.SecurityUtils;
+import digital.laboratory.platform.imr.dto.*;
+import digital.laboratory.platform.imr.entity.*;
+import digital.laboratory.platform.imr.mapper.*;
+import digital.laboratory.platform.imr.service.SamplePutInStorageService;
+import digital.laboratory.platform.imr.vo.*;
+import feign.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.Principal;
+import java.time.LocalDate;
+import java.util.*;
+
+
+/**
+ * @author Zhang Xiaolong created at 2023-03-21
+ * @describe 前端控制器
+ *
+ * 这是与表示层的接口, 不应该接业务逻辑写在这里, 业务逻辑应该写在 service 中
+ * 这里写什么:
+ * 为前端提供数据, 接受前端的数据
+ * 为前端提供的数据, 从 service 取得后, 可以做一些适当的加工, 这种加工不是业务层面的, 只能是数据格式上, 为方便前端处理
+ * 接受前端的数据, 每一个函数的参数可以先做一些整理后, 再调用 service 中的函数。这里对参数的整理, 应该只是格式上的, 而不能是业务上的
+ * 数据层在 mapper 中, 数据层不涉及业务, 只管技术上的 对象<->表 之间的转换
+ */
+
+
+/**
+ * 样本入库controller
+ * 入库相关接口
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/sample_put_in_storage")
+@Api(value = "sample_inbound_or_outbound", tags = "样本入库管理")
+public class SamplePutInStorageController {
+
+ private final SamplePutInStorageService samplePutInStorageService;
+
+ private final SampleStorageMapper storageMapper;
+
+ private final RemoteWord2PDFService remoteWord2PDFService;
+
+ private final SampleApplyMapper asMapper;
+
+ private final OssFile ossFile;
+
+ private final SampleOutWarehouseApplyMapper outWarehouseApplyMapper;
+
+ private final SampleInboundAndOutboundTableMapper tableMapper;
+
+ /**
+ * 获取已录入仓库样本(分页)
+ */
+ @ApiOperation(value = "获取已录入仓库样本(分页)", notes = "获取已录入仓库样本(分页)")
+ @GetMapping("/repositorySample/page")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R> getSampleVOList(QuerySampleDTO dto) {
+
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+ IPage sampleVOIPage = samplePutInStorageService.getSampleVOList(page, Wrappers.query()
+ .like(StrUtil.isNotEmpty(dto.getName()), "storage.name", dto.getName())
+ .eq(StrUtil.isNotEmpty(dto.getSampleType()), "storage.sample_type", dto.getSampleType())
+ .eq("storage.status", dto.getStatus())
+ .between(dto.getBeginDate() != null && dto.getFinishDate() != null, "in_repository_date", dto.getBeginDate(), dto.getFinishDate())
+ .orderByDesc("create_time")
+ );
+ return R.ok(sampleVOIPage, "查询成功");
+ }
+
+ /**
+ * 入库样本记录分页
+ */
+ @ApiOperation(value = "入库样本记录分页", notes = "入库样本记录分页")
+ @GetMapping("/inboundRecord/page")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R> inboundRecord(QuerySampleDTO dto) {
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+ IPage sampleVOIPage = samplePutInStorageService.inboundRecord(page, Wrappers.query()
+ .like(StrUtil.isNotEmpty(dto.getName()), "inbound.name", dto.getName())
+ .orderByDesc("create_time")
+ );
+ return R.ok(sampleVOIPage, "查询成功");
+ }
+
+
+ /**
+ * 待销毁样本预警
+ */
+ @ApiOperation(value = "待销毁样本预警", notes = "待销毁样本预警")
+ @GetMapping("/destructionWarning/page")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R destructionWarning(QuerySampleDTO dto) {
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+ IPage sampleVOIPage = samplePutInStorageService.getDestructionVO(page, Wrappers.query()
+ .like(StrUtil.isNotEmpty(dto.getName()), "storage.name", dto.getName())
+ .eq("early_warning", 1)
+ .eq("storage.status", 2)//只能查看当前入库的
+ .orderByDesc("create_time")
+ );
+ return R.ok(sampleVOIPage, "查询成功");
+ }
+
+
+ /**
+ * 查询单个存放样本信息
+ * sample信息+详情(出入库登记表)
+ */
+ @ApiOperation(value = "查询单个存放样本信息--这个id不是样本id", notes = "查询单个存放样本信息")
+ @GetMapping("/detailed")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R getSampleDetailed(String id) {
+
+ if (StrUtil.isEmpty(id)) {
+ throw new RuntimeException("查询id不能为空");
+ }
+
+ RepositorySampleVO sampleVO = samplePutInStorageService.getSampleDetailed(id);
+
+ return R.ok(sampleVO, "查询成功");
+ }
+
+
+ /**
+ * 根据样本编号获取主要信息
+ * (扫码枪扫描)
+ */
+ @ApiOperation(value = "根据样本编号获取主要信息(入库)", notes = "根据样本编号获取主要信息(入库)")
+ @GetMapping("/getSampleInfoByNo")
+ @Inner(value = false)
+ //@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')" )
+ public R> getSampleInfoByNo(String sampleNo) {
+
+ if (sampleNo == null || "".equals(sampleNo)) {
+ return R.failed(null);
+ }
+
+ List vo = samplePutInStorageService.getSampleListByNo(sampleNo);
+
+ if (!vo.isEmpty()) {
+ return R.ok(vo, "查询成功");
+ } else {
+ return R.failed(vo, String.format("编号为" + sampleNo + "的样本不存在请重试"));
+ }
+ }
+
+
+ @ApiOperation(value = "修改sample质量", notes = "修改sample质量")
+ @PostMapping("/updateSampleQuality")
+ public R updateSampleQuality(String sampleId, double sampleQuality) {
+
+ if (StrUtil.isEmpty(sampleId)) {
+ throw new RuntimeException("id不能为空");
+ }
+
+ //查询并修改
+ samplePutInStorageService.updateSampleQuality(sampleId, sampleQuality);
+
+ return R.ok(null, "修改质量成功");
+ }
+
+
+ /**
+ * 扫码入库查看详情信息
+ */
+ @ApiOperation(value = "获取sample主要的详情信息", notes = "获取sample主要的详情信息")
+ @GetMapping("/getSampleDetailInfo")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R getSampleDetailInfo(String id) {
+
+ if (id == null || "".equals(id)) {
+ return R.failed(null);
+ }
+
+ BaseSampleDetail sampleDetail = storageMapper.getSampleDetailInfo(id);
+
+ if (sampleDetail != null) {
+ if (sampleDetail.getSource().equals("entrustment") && sampleDetail.getQuantity() == 0) {
+ sampleDetail.setQuantity(storageMapper.getQuality(sampleDetail.getId()));
+ }
+ return R.ok(sampleDetail, "查询成功");
+ } else {
+ return R.failed("查询失败");
+ }
+ }
+
+
+ /**
+ * 默认没有仓库样本表
+ * 外部关联一张样本存储表格
+ * (接口2)(不考虑样本入库质量)
+ * 根据检材样本编号录入仓库(入库)
+ * 确认入库按钮
+ */
+ @ApiOperation(value = "根据编号录入仓库(入库)--不考虑质量", notes = "根据编号录入仓库(入库)--不考虑质量")
+ @PostMapping("/sampleEntryRepository")
+ //@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound')" )
+ public R sampleEntryRepository(@RequestBody List sampleNos, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ if (sampleNos != null) {
+ throw new RuntimeException("入库样本编号不能为空");
+ }
+
+ List vo = samplePutInStorageService.sampleEntryRepository(sampleNos, dlpUser);
+ if (vo != null) {
+ return R.ok(vo, "样本入库成功,本次入库样本数为" + sampleNos.size() + "份");
+ } else {
+ return R.failed("入库失败");
+ }
+ }
+
+
+ /**
+ * 默认没有仓库样本表
+ * 外部关联一张样本存储表格
+ * (接口3)
+ * 根据检材样本编号录入仓库(入库)
+ *
+ * 这里需要手动填写入库时的质量和计量单位(流转)
+ *
+ * 确认入库按钮
+ */
+ @ApiOperation(value = "根据样本编号录入仓库(入库)--考虑质量", notes = "根据样本编号录入仓库(入库)--考虑质量")
+ @PostMapping("/sampleInRepository")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_add')")
+ public R sampleInRepository(@RequestBody List sample, HttpServletRequest theHttpServletRequest) {
+ Principal principal = theHttpServletRequest.getUserPrincipal();
+ DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal();
+
+ if (sample == null) {
+ throw new RuntimeException("入库样本编号不能为空");
+ }
+
+ List vo = samplePutInStorageService.sampleInRepository(sample, dlpUser);
+ if (vo != null) {
+ return R.ok(vo, "样本入库成功,本次入库样本数为" + sample.size() + "份");
+ } else {
+ return R.failed("入库失败");
+ }
+ }
+
+
+ /**
+ * 待存放样本查询
+ */
+ @ApiOperation(value = "待存放样本查询", notes = "待存放样本查询")
+ @GetMapping("/getToBeStoredSample")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R> getToBeStoredSample(QueryDTO dto) {
+
+
+ Page page = new Page<>(dto.getCurrent(), dto.getSize());
+
+ IPage sampleVOS = storageMapper.getToBeStoredSample(page, Wrappers.query()
+ .like(StrUtil.isNotEmpty(dto.getName()), "storage.name", dto.getName())
+ .eq("storage.status", 1)
+ );
+
+
+ return R.ok(sampleVOS, "查询成功");
+ }
+
+
+ /**
+ * 检材存放
+ */
+ @ApiOperation(value = "选择样本存放到格子(存放)", notes = "选择样本存放到格子(存放)")
+ @PostMapping("/sampleDepositRepository")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')")
+ public R sampleDepositRepository(@RequestBody DepositDTO dto) {
+ if (dto.getIds() == null) {
+ throw new RuntimeException("样本不能为空");
+ }
+ if (StrUtil.isEmpty(dto.getCellId())) {
+ throw new RuntimeException("存放位置不能为空");
+ }
+
+ List vo = samplePutInStorageService.sampleDepositRepository(dto);
+
+ return R.ok(vo, "已成功存入" + vo.get(0).getStorageLocation());
+ }
+
+
+ /**
+ * 点击存放格子时展示对应内部的存放样本信息
+ */
+
+ @ApiOperation(value = "通过样本id获取格子中存放的样本信息", notes = "通过样本id获取格子中存放的样本信息")
+ @GetMapping("/getStoredSample")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_get')")
+ public R> getStoredSample(String cellId) {
+
+
+ if (cellId == null || "".equals(cellId)) {
+ throw new RuntimeException("格子id不能为空");
+ }
+
+ ArrayList outSampleVOS = new ArrayList<>();
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("storage_cell_id", cellId);
+ queryWrapper.eq("status", 2);//已经入库的
+ List storages = storageMapper.selectList(queryWrapper);
+ for (SampleStorage storage : storages) {
+ OutSampleVO sampleVO = storageMapper.getSampleById(storage.getSampleId());
+ if (sampleVO != null) {
+ outSampleVOS.add(sampleVO);
+ }
+ }
+ Collections.sort(outSampleVOS, new Comparator() {
+ @Override
+ public int compare(OutSampleVO o1, OutSampleVO o2) {
+ String[] split1 = o1.getSampleNo().split("-");
+ String[] split2 = o2.getSampleNo().split("-");
+ // 先比较年份
+ int yearComparison = split2[0].compareTo(split1[0]);
+ if (yearComparison != 0) {
+ return yearComparison;
+ }
+ // 再比较序号
+ int num1 = Integer.parseInt(split2[1]);
+ int num2 = Integer.parseInt(split1[1]);
+ if (num1 - num2 != 0) {
+ return num1 - num2;
+ }
+
+ // 再比较尾号
+ int num3 = Integer.parseInt(split1[2]);
+ int num4 = Integer.parseInt(split2[2]);
+ return num3 - num4;
+ }
+ });
+ if (!outSampleVOS.isEmpty()) {
+ return R.ok(outSampleVOS, "查询成功");
+ } else {
+ return R.failed("当前格子未存放样本");
+ }
+ }
+
+
+ /**
+ * 修改存储期限
+ */
+
+ @ApiOperation(value = "修改存储期限", notes = "修改存储期限")
+ @PutMapping("/updateStorageDate")
+ @PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')")
+ public R updateStorageLocation(@RequestBody UpdateStorageDateDTO dto) {
+
+ if (dto.getStorageDate().isBefore(LocalDate.now())) {
+ throw new RuntimeException("请选择正确的时间");
+ }
+
+ UpdateWrapper wrapper = new UpdateWrapper<>();
+ wrapper.eq("id", dto.getId());
+ wrapper.set("storage_date", dto.getStorageDate());
+ wrapper.set("early_warning", 0);//销毁预警为0
+ storageMapper.update(null, wrapper);
+ return R.ok("修改成功");
+ }
+
+
+ /**
+ * 销毁预警角标
+ */
+
+ @ApiOperation(value = "销毁预警角标", notes = "销毁预警角标")
+ @GetMapping("/destroyed/count")
+ //@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R> getIconCount() {
+ //查询当前待销毁检材数量
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("early_warning", 1);
+ queryWrapper.eq("status", 2);//只能查看当前入库的
+ Long count = storageMapper.selectCount(queryWrapper);
+
+ IconDTO destroyed = new IconDTO(count, 1, "destroyed");
+
+ ArrayList iconDTOS = new ArrayList<>();
+ iconDTOS.add(destroyed);
+ return R.ok(iconDTOS, "查询成功");
+
+ }
+
+
+ //待存放检材角标(--检材存放提示角标)
+ /*@ApiOperation(value = "待存放检材角标", notes = "待存放检材角标")
+ @GetMapping("/getToBeStoredIcon/count" )
+ //@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')" )
+ public R> getToBeStoredIcon() {
+ //查询当前待存放检材的数量
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("status",1);//只能查看当前入库的
+ Long count = storageMapper.selectCount(queryWrapper);
+
+ IconDTO toBeStored = new IconDTO(count, 1, "toBeStored");
+
+ ArrayList iconDTOS = new ArrayList<>();
+ iconDTOS.add(toBeStored);
+ return R.ok(iconDTOS,"查询成功");
+
+ }*/
+
+ //----------------------------------------------------------
+
+
+ /*
+
+ */
+ @ApiOperation(value = "一个检材入库时的可选检材列表", notes = "一个检材入库时的可选检材列表")
+ @GetMapping("/choseSampleList")
+ public R