diff --git a/src/main/java/digital/laboratory/platform/entrustment/controller/PushDataToLabsCareController.java b/src/main/java/digital/laboratory/platform/entrustment/controller/PushDataToLabsCareController.java new file mode 100644 index 0000000..01ea83e --- /dev/null +++ b/src/main/java/digital/laboratory/platform/entrustment/controller/PushDataToLabsCareController.java @@ -0,0 +1,51 @@ +package digital.laboratory.platform.entrustment.controller; + +import cn.hutool.json.JSONObject; +import digital.laboratory.platform.common.core.util.R; +import digital.laboratory.platform.entrustment.service.PushDataToLabsCareService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author ChenJiangBao + * @version 1.0 + * @description: 推送数据到LabsCare平台接口管理 + * @date 2025/4/3 10:48 + */ +@RestController +@RequestMapping("/pushDataToLabsCare") +@Api(tags = "19-推送数据到LabsCare平台接口管理", description = "推送数据到LabsCare平台接口管理") +public class PushDataToLabsCareController { + + + + @Resource + private PushDataToLabsCareService pushDataToLabsCareService; + + @ApiOperation("获取推送鉴定委托书的数据") + @PostMapping("/entrustLetter") + public R entrustLetter(@RequestParam("entrustId") String entrustId) { + try { + return R.ok(pushDataToLabsCareService.fetchEntrustLetterData(entrustId)); + } catch (Exception e) { + return R.failed(e.getMessage()); + } + } + + @ApiOperation("获取推送鉴定事项确认书的数据") + @PostMapping("/itemConfirmLetter") + public R itemConfirmLetter(@RequestParam("entrustId") String entrustId) { + try { + return R.ok(pushDataToLabsCareService.fetchItemConfirmLetterData(entrustId)); + } catch (Exception e) { + return R.failed(e.getMessage()); + } + } + +} diff --git a/src/main/java/digital/laboratory/platform/entrustment/service/EntrustmentIdentificationMaterialService.java b/src/main/java/digital/laboratory/platform/entrustment/service/EntrustmentIdentificationMaterialService.java index 995d5fe..055cd4f 100644 --- a/src/main/java/digital/laboratory/platform/entrustment/service/EntrustmentIdentificationMaterialService.java +++ b/src/main/java/digital/laboratory/platform/entrustment/service/EntrustmentIdentificationMaterialService.java @@ -93,7 +93,6 @@ public interface EntrustmentIdentificationMaterialService extends IService createNewIm(List identificationMaterial, DLPUser dlpUser); - public List printLabel(List printDTOList); + List printLabel(List printDTOList); List printManyLabel(List printDTOList); @@ -114,7 +113,13 @@ public interface EntrustmentIdentificationMaterialService extends IService list); - List sortByAcceptNo(List materials); + /** + * 处理检材重量四舍五入 + * 设置检材列表, 对检材的重量进行处理 小于100的保留两位小数,100以上保留一位小数 + * @param entrustId 委托ID + * @return 处理后的检材列表 + */ + List handleMaterialWeightRounding(String entrustId); List sortVoByAcceptNo(List materials); } diff --git a/src/main/java/digital/laboratory/platform/entrustment/service/PushDataToLabsCareService.java b/src/main/java/digital/laboratory/platform/entrustment/service/PushDataToLabsCareService.java index 4b16ba0..8ffeabd 100644 --- a/src/main/java/digital/laboratory/platform/entrustment/service/PushDataToLabsCareService.java +++ b/src/main/java/digital/laboratory/platform/entrustment/service/PushDataToLabsCareService.java @@ -1,5 +1,6 @@ package digital.laboratory.platform.entrustment.service; +import cn.hutool.json.JSONObject; import digital.laboratory.platform.entrustment.vo.EntrustmentVO; @@ -24,4 +25,18 @@ public interface PushDataToLabsCareService { * @param entrustVO */ void pushEntrustLetterData(EntrustmentVO entrustVO) throws IllegalAccessException; + + /** + * 获取推送鉴定委托书的数据 + * @param entrustId 委托id + * @return + */ + JSONObject fetchEntrustLetterData(String entrustId); + + /** + * 获取推送鉴定事项确认书的数据 + * @param entrustId 委托id + * @return + */ + JSONObject fetchItemConfirmLetterData(String entrustId); } diff --git a/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentIdentificationMaterialServiceImpl.java b/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentIdentificationMaterialServiceImpl.java index 1d142b5..44e524c 100644 --- a/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentIdentificationMaterialServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentIdentificationMaterialServiceImpl.java @@ -52,6 +52,7 @@ import javax.annotation.Resource; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; @@ -1532,7 +1533,11 @@ public class EntrustmentIdentificationMaterialServiceImpl extends ServiceImpl list) { if (list != null && list.size() > 0) { @@ -1628,15 +1633,31 @@ public class EntrustmentIdentificationMaterialServiceImpl extends ServiceImpl sortByAcceptNo(List materials){ - materials.sort(Comparator.comparing((EntrustmentIdentificationMaterial m) -> { - String[] parts = m.getAcceptNo().split("-"); - return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])}; - }, Comparator.comparingInt((int[] arr) -> arr[0]) // 按年份排序 - .thenComparingInt(arr -> arr[1]) // 按流水号排序 - .thenComparingInt(arr -> arr[2]))); // 按子流水号排序 - return materials; + public List handleMaterialWeightRounding(String entrustId) { + List materialList = super.list( + Wrappers.lambdaQuery() + .eq(EntrustmentIdentificationMaterial::getEntrustmentId, entrustId) + .orderByAsc(EntrustmentIdentificationMaterial::getOrderNo) + ); + conformityDrugs(materialList); + //设置检材列表, 对检材的重量进行处理 小于100的保留两位小数,100以上保留一位小数 + BigDecimal compareNumber = new BigDecimal(100); + for (EntrustmentIdentificationMaterial entrustmentIdentificationMaterial : materialList) { + BigDecimal quantity = entrustmentIdentificationMaterial.getQuantity(); + if (quantity.compareTo(compareNumber) >= 0) { + entrustmentIdentificationMaterial.setQuantity(quantity.setScale(1, RoundingMode.HALF_UP)); + } else { + entrustmentIdentificationMaterial.setQuantity(quantity.setScale(2, RoundingMode.HALF_UP)); + } + } + return materialList; } @Override diff --git a/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentServiceImpl.java b/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentServiceImpl.java index e050c17..55dae86 100644 --- a/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustmentServiceImpl.java @@ -2176,27 +2176,13 @@ public class EntrustmentServiceImpl extends ServiceImpl materialList = entrustmentIdentificationMaterialService.list( - Wrappers.query() - .eq("entrustment_id", ev.getId()) - .orderByAsc("order_no") - ); - entrustmentIdentificationMaterialService.conformityDrugs(materialList); + List materialList = entrustmentIdentificationMaterialService.handleMaterialWeightRounding(ev.getId()); //设置检材描述 dm.put("materialDes", this.buildMaterialDes(materialList)); //设置鉴定要求 //dm.put("identifyReq",entrustmentService.buildIdentfyReq(materialList)); dm.put("identifyReq", ev.getEntrustRequirement()); - //设置检材列表, 对检材的重量进行处理 小于100的保留两位小数,100以上保留一位小数 - BigDecimal compareNumber = new BigDecimal(100); - for (EntrustmentIdentificationMaterial entrustmentIdentificationMaterial : materialList) { - BigDecimal quantity = entrustmentIdentificationMaterial.getQuantity(); - if (quantity.compareTo(compareNumber) >= 0) { - entrustmentIdentificationMaterial.setQuantity(quantity.setScale(1, RoundingMode.HALF_UP)); - } else { - entrustmentIdentificationMaterial.setQuantity(quantity.setScale(2, RoundingMode.HALF_UP)); - } - } + dm.put("materialList", materialList); // QR Code // BufferedImage bufferedImage = QRCodeUtils.genQRCode(ev.getEntrustmentNo(), 100, 100); diff --git a/src/main/java/digital/laboratory/platform/entrustment/service/impl/PushDataToLabsCareServiceImpl.java b/src/main/java/digital/laboratory/platform/entrustment/service/impl/PushDataToLabsCareServiceImpl.java index 7bc9b5c..4677c19 100644 --- a/src/main/java/digital/laboratory/platform/entrustment/service/impl/PushDataToLabsCareServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/entrustment/service/impl/PushDataToLabsCareServiceImpl.java @@ -3,6 +3,7 @@ package digital.laboratory.platform.entrustment.service.impl; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import digital.laboratory.platform.common.core.exception.CheckedException; import digital.laboratory.platform.entrustment.config.properties.ApiPathProperties; import digital.laboratory.platform.entrustment.entity.Entrustment; import digital.laboratory.platform.entrustment.entity.EntrustmentIdentificationMaterial; @@ -140,8 +141,7 @@ public class PushDataToLabsCareServiceImpl implements PushDataToLabsCareService */ @Override public void pushEntrustLetterData(EntrustmentVO entrustVO) throws IllegalAccessException { - Map dataMap = entrustmentService.buildEntrustLetterDataMap(entrustVO); - JSONObject jsonObject = buildEntrustLetterJsonPayload(entrustVO, dataMap); + JSONObject jsonObject = buildEntrustLetterJsonPayload(entrustVO); String successFlag = ENTRUST_LETTER + ":true"; String failureFlag = ENTRUST_LETTER + ":false"; @@ -161,15 +161,38 @@ public class PushDataToLabsCareServiceImpl implements PushDataToLabsCareService } } + /** + * 获取推送鉴定委托书的数据 + * @param entrustId 委托id + * @return + */ + @Override + public JSONObject fetchEntrustLetterData(String entrustId) { + // 获取委托信息 + EntrustmentVO entrustVO = validFetchParam(entrustId); + return buildEntrustLetterJsonPayload(entrustVO); + } + + /** + * 获取推送鉴定事项确认书的数据 + * @param entrustId 委托id + * @return + */ + @Override + public JSONObject fetchItemConfirmLetterData(String entrustId) { + // 获取委托信息 + EntrustmentVO entrustVO = validFetchParam(entrustId); + return buildItemConfirmLetterJsonPayload(entrustVO); + } + /** * 构建委托函的JSON负载 * * @param entrustVO 委托VO对象 - * @param dataMap 数据映射 * @return 构建好的JSON对象 */ - private JSONObject buildEntrustLetterJsonPayload(EntrustmentVO entrustVO, Map dataMap) { + private JSONObject buildEntrustLetterJsonPayload(EntrustmentVO entrustVO) { JSONObject jsonObject = new JSONObject(); jsonObject.set("afsj", entrustVO.getHappenTime()); // 案发时间 jsonObject.set("ajmc", entrustVO.getCaseName()); // 案事件名称 @@ -186,7 +209,7 @@ public class PushDataToLabsCareServiceImpl implements PushDataToLabsCareService jsonObject.set("yjdqk", entrustVO.getOldIdentificationResult()); // 组装材料信息 - List materialList = (List) dataMap.get("materialList"); + List materialList = entrustmentIdentificationMaterialService.handleMaterialWeightRounding(entrustVO.getId()); AtomicInteger index = new AtomicInteger(1); List table = materialList.stream().map(material -> { JSONObject materialJson = new JSONObject(); @@ -305,5 +328,19 @@ public class PushDataToLabsCareServiceImpl implements PushDataToLabsCareService .set(Entrustment::getPushFlag, String.join(",", flagList))); } - + /** + * 根据委托ID验证并获取委托信息 + * + * @param entrustId 委托ID + * @return 委托信息对象 EntrustmentVO + * @throws CheckedException 当未找到对应的委托信息时抛出此异常 + */ + private EntrustmentVO validFetchParam(String entrustId) { + EntrustmentVO entrustVO = entrustmentService.getEntrustmentVOById(entrustId); + if (entrustVO == null) { + log.error("未找到委托信息, entrustId={}", entrustId); + throw new CheckedException(String.format("未找到委托信息, entrustId=%s", entrustId)); + } + return entrustVO; + } }