From 0debf5b7bb0246eaef1397975cdb16f4adb9e8d9 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 29 十月 2026 14:36:31 +0800
Subject: [PATCH] refactor(inspection-order): 1.检验委托单绑定机制支持多次下单 2.合格率统计口径调整 3.外购铜导体推送入库MES增加米重 4.报告英文字段调整
---
cnas-process/src/main/java/com/ruoyi/process/service/impl/InspectionOrderServiceImpl.java | 655 +++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 436 insertions(+), 219 deletions(-)
diff --git a/cnas-process/src/main/java/com/ruoyi/process/service/impl/InspectionOrderServiceImpl.java b/cnas-process/src/main/java/com/ruoyi/process/service/impl/InspectionOrderServiceImpl.java
index ae6b0b4..ac756a0 100644
--- a/cnas-process/src/main/java/com/ruoyi/process/service/impl/InspectionOrderServiceImpl.java
+++ b/cnas-process/src/main/java/com/ruoyi/process/service/impl/InspectionOrderServiceImpl.java
@@ -2,7 +2,6 @@
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -10,24 +9,33 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
+import com.ruoyi.common.numgen.NumberGenerator;
+import com.ruoyi.common.core.domain.entity.Custom;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.exception.ErrorException;
-import com.ruoyi.inspect.dto.InsOrderDeviceRecordDto;
-import com.ruoyi.inspect.mapper.InsProductResultMapper;
-import com.ruoyi.inspect.mapper.InsSampleMapper;
-import com.ruoyi.inspect.pojo.*;
+import com.ruoyi.inspect.dto.InsPlaceOrderDto;
+import com.ruoyi.inspect.pojo.InsOrder;
+import com.ruoyi.inspect.pojo.InsReport;
import com.ruoyi.inspect.service.InsOrderService;
import com.ruoyi.inspect.service.InsReportService;
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.process.dto.InspectionOrderDto;
+import com.ruoyi.process.dto.InspectionOrderBindingDto;
import com.ruoyi.process.dto.InspectionOrderExportDto;
+import com.ruoyi.process.mapper.InspectionOrderBindLogMapper;
import com.ruoyi.process.mapper.InspectionOrderMapper;
-import com.ruoyi.process.mapper.ProcessOrderDeviceMapper;
-import com.ruoyi.process.mapper.ProcessSampleMapper;
-import com.ruoyi.process.pojo.*;
+import com.ruoyi.process.mapper.InspectionOrderAttachmentMapper;
+import com.ruoyi.process.mapper.InspectionOrderBindingMapper;
+import com.ruoyi.process.pojo.InspectionOrder;
+import com.ruoyi.process.pojo.InspectionOrderAttachment;
+import com.ruoyi.process.pojo.InspectionOrderBinding;
+import com.ruoyi.process.pojo.InspectionOrderBindLog;
+import com.ruoyi.process.pojo.InspectionOrderDetail;
import com.ruoyi.process.service.*;
import com.ruoyi.system.mapper.UserMapper;
+import com.ruoyi.system.mapper.CustomMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -44,11 +52,16 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-import java.time.LocalDate;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
import java.time.LocalDateTime;
+import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.HashMap;
+import java.util.List;
+import java.util.LinkedHashMap;
+import java.util.Objects;
+import java.util.UUID;
/**
* <p>
@@ -62,35 +75,30 @@
@Transactional(rollbackFor = Exception.class)
public class InspectionOrderServiceImpl extends ServiceImpl<InspectionOrderMapper, InspectionOrder> implements InspectionOrderService {
@Resource
+ private InspectionOrderBindLogMapper inspectionOrderBindLogMapper;
+ @Resource
+ private InspectionOrderBindingMapper inspectionOrderBindingMapper;
+ @Resource
+ private InspectionOrderAttachmentMapper inspectionOrderAttachmentMapper;
+ @Resource
private InspectionOrderDetailService inspectionOrderDetailService;
@Resource
private InsOrderService insOrderService;
- @Resource
- private InsSampleMapper insSampleMapper;
@Resource
private InsReportService insReportService;
@Value("${wordUrl}")
private String wordUrl;
@Resource
- private ProcessReportService processReportService;
- @Resource
- private ProcessOrderDeviceMapper processOrderDeviceMapper;
- @Resource
- private InsProductResultMapper insProductResultMapper;
- @Resource
- private ProcessOrderDeviceService processOrderDeviceService;
- @Resource
private UserMapper userMapper;
@Resource
- private ProcessSampleService processSampleService;
+ private CustomMapper customMapper;
@Resource
- private ProcessSampleMapper processSampleMapper;
- @Resource
- private ProcessDealService processDealService;
+ private NumberGenerator<InspectionOrder> numberGenerator;
/**
* 妫�楠屽鎵樺崟鍒嗛〉鏌ヨ
+ *
* @param page
* @param InspectionOrder
* @return
@@ -102,39 +110,23 @@
/**
* 妫�楠屽鎵樺崟鏂板
+ *
* @param inspectionOrder
* @return
*/
@Override
- public boolean addInspectionOrder(InspectionOrderDto inspectionOrder) {
- if (inspectionOrder.getInsOrderId() == null) {
- throw new ErrorException("缂哄皯璁㈠崟id");
+ public InspectionOrderDto addInspectionOrder(InspectionOrderDto inspectionOrder) {
+ if (inspectionOrder.getInsOrderId() != null) {
+ throw new ErrorException("鏂板妫�楠屽鎵樺崟涓嶅厑璁哥洿鎺ョ粦瀹氭垚鍝佷笅鍗曪紝璇峰湪鎴愬搧涓嬪崟椤甸潰閫夋嫨濮旀墭鍗�");
}
+ normalizeCommissionParty(inspectionOrder);
- // 澶嶅埗鎶ュ憡
- // 鏌ヨ璁㈠崟鎶ュ憡
- InsReport insReport = insReportService.getOne(Wrappers.<InsReport>lambdaQuery()
- .eq(InsReport::getInsOrderId, inspectionOrder.getInsOrderId()));
-
- String path = wordUrl + insReport.getUrl().replaceFirst("/word", "");
-
- String fileName =LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + "濮旀墭鍗曟姤鍛�.docx";
-
- // 婧愭枃浠惰矾寰�
- Path sourcePath = Paths.get(path);
- // 鐩爣鏂囦欢璺緞
- Path targetPath = Paths.get(wordUrl + "/" + fileName);
-
- try {
- // 澶嶅埗鏂囦欢锛屽鏋滅洰鏍囨枃浠跺凡瀛樺湪锛屽垯瑕嗙洊
- Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
- // 娣诲姞鏂囦欢鍦板潃
- inspectionOrder.setFileUrl("/word/" + fileName);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
+ inspectionOrder.setInspectionOrderCode(numberGenerator.generateNumberWithPrefix(4,
+ "WTD" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")),
+ InspectionOrder::getInspectionOrderCode));
+ // 濮旀墭缂栧彿鐢辨垚鍝佷笅鍗曟祦绋嬬敓鎴愶紝濮旀墭鍗曟柊澧為樁娈典笉寰楁墜宸ュ~鍐欍��
+ inspectionOrder.setEntrustCode(null);
+ inspectionOrder.setFileUrl(null);
baseMapper.insert(inspectionOrder);
// 鏂板璇︽儏
if (CollectionUtils.isNotEmpty(inspectionOrder.getOrderDetailList())) {
@@ -143,97 +135,34 @@
}
inspectionOrderDetailService.saveBatch(inspectionOrder.getOrderDetailList());
}
- /*鏂板7.8鎶ュ憡缁撴灉*/
- ProcessReport processReport = new ProcessReport();
- processReport.setInspectionOrderId(inspectionOrder.getInsOrderId());
- processReport.setInsReportCode(inspectionOrder.getEntrustCode());//鎶ュ憡缂栧彿=濮旀墭缂栧彿
- //椤垫暟
- try {
- com.aspose.words.Document doc = new com.aspose.words.Document(path);
- processReport.setPages(doc.getPageCount()+"");
- } catch (Exception e) {
- }
- processReport.setNumber("1");//鍙戦�佷唤鏁伴粯璁�1
- processReport.setSend(inspectionOrder.getCommissionUnit());//鍙戝線浣曞=濮旀墭鍗曚綅
- processReport.setMethod(inspectionOrder.getSend()==1?"鑷彇":"鍏朵粬");//鍙戦�佹柟寮�
- processReport.setSendTime(insReport.getRatifyTime().toLocalDate());//鍙戦�佹棩鏈�
- processReport.setSendUser(64);//鍙戦�佷汉鍥哄畾
- processReport.setSignatory(inspectionOrder.getCommissionUser());//绛炬敹浜�=濮旀墭浜�
- processReportService.save(processReport);
- /*鏂板7.1濮旀墭鍗曞搴旂殑璁惧浣跨敤璁板綍*/
- addDeviceRecord(inspectionOrder,insReport.getWriteUserId());
- /*鏂板7.4鏍峰搧鎺ユ敹*/
- List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery()
- .eq(InsSample::getInsOrderId, inspectionOrder.getInsOrderId()));
- if (insSamples.size()>0){
- List<ProcessSample> processSamples = new ArrayList<>();
- for (InsSample insSample : insSamples) {
- ProcessSample processSample = new ProcessSample();
- processSample.setReceiveDate(inspectionOrder.getSampleData());//鏀舵牱鏃ユ湡=棰嗘牱鏃ユ湡
- processSample.setSampleCode(insSample.getSampleCode());//鏍峰搧缂栧彿
- processSample.setSampleName(insSample.getSample());//鏍峰搧鍚嶇О
- processSample.setNum(1);//鏍峰搧鏁伴噺=1
- processSample.setSampleSupplier(inspectionOrder.getCommissionUnit());//鏉ユ牱鍗曚綅
- LocalDate plusMonths = inspectionOrder.getSampleData() == null ? null : inspectionOrder.getSampleData().plusMonths(1);
- processSample.setLeaveDate(plusMonths);//鐣欐牱鏃ユ湡=鏀舵牱鏃ユ湡寰�鍚庡欢涓�涓湀
- processSample.setSampleState(inspectionOrder.getSampleStatus());//鏍峰搧鐘舵��
- processSample.setDealTime(plusMonths);//閫�鏍锋棩鏈�=鐣欐牱鏃ユ湡
- processSample.setInspectionOrderId(inspectionOrder.getInspectionOrderId());//濮旀墭鍗昳d
- processSamples.add(processSample);
- }
- processSampleService.saveBatch(processSamples);
- }
- return true;
- }
-
- private synchronized void addDeviceRecord(InspectionOrder inspectionOrder,Integer userId) {
- // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍
- Set<String> recordCodeset = processOrderDeviceMapper.selectDeviceNumber(inspectionOrder.getInspectionOrderId());
- // 鑾峰彇璁㈠崟璁惧缂栧彿
- List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(inspectionOrder.getInsOrderId());
- Set<String> deviceCodeSet = new HashSet<>();
- for (InsProductResult result : resultList) {
- // 娣诲姞璁惧缂栧彿
- List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class);
- for (JSONObject jsonObject : jsonObjects) {
- if (!"".equals(jsonObject.get("v") + "")) {
- List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�");
- deviceCodeSet.addAll(v);
- }
- }
- }
- // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍
- Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset);
- // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id
- if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) {
- List<Integer> orderDeviceIds = processOrderDeviceMapper.selectDeviceIdsByNumbers(orderDeviceNumbers);
- List<ProcessOrderDevice> collect = orderDeviceIds.stream().map(deviceId -> {
- ProcessOrderDevice processOrderDevice = new ProcessOrderDevice();
- processOrderDevice.setInspectionOrderId(inspectionOrder.getInspectionOrderId());
- processOrderDevice.setDeviceId(deviceId);
- processOrderDevice.setSampleCode(inspectionOrder.getEntrustCode());
- processOrderDevice.setUseBefore(1);
- processOrderDevice.setUseAfter(1);
- processOrderDevice.setUsePerson(userMapper.selectById(userId).getName());//浣跨敤浜�
- processOrderDevice.setUsePersonId(userId);//浣跨敤浜篿d
- return processOrderDevice;
- }).collect(Collectors.toList());
- processOrderDeviceService.saveBatch(collect);
- }
- }
-
- private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) {
- return number1.stream().filter(s1 -> number2.stream().noneMatch(s2 -> s1.equals(s2)))
- .collect(Collectors.toSet());
+ return inspectionOrder;
}
/**
* 妫�楠屽鎵樺崟淇敼
+ *
* @param InspectionOrder
* @return
*/
@Override
public boolean updateInspectionOrder(InspectionOrderDto InspectionOrder) {
+ InspectionOrder oldInspectionOrder = baseMapper.selectByIdForUpdate(InspectionOrder.getInspectionOrderId());
+ if (oldInspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ Long bindingHistoryCount = inspectionOrderBindingMapper.selectCount(Wrappers.<InspectionOrderBinding>lambdaQuery()
+ .eq(InspectionOrderBinding::getInspectionOrderId, InspectionOrder.getInspectionOrderId()));
+ if (bindingHistoryCount > 0 && !Objects.equals(oldInspectionOrder.getCommissionUnitId(), InspectionOrder.getCommissionUnitId())) {
+ throw new ErrorException("宸叉湁涓嬪崟璁板綍锛屼笉鍏佽淇敼濮旀墭鍗曚綅");
+ }
+ normalizeCommissionParty(InspectionOrder);
+ // 缂栧彿銆佸叧鑱斿叧绯汇�佹寮忓鎵樼紪鍙峰拰鎶ュ憡鍦板潃鍙兘鐢变笓鐢ㄦ祦绋嬬淮鎶ゃ��
+ InspectionOrder.setInspectionOrderCode(null);
+ InspectionOrder.setInsOrderId(null);
+ InspectionOrder.setEntrustCode(null);
+ InspectionOrder.setFileUrl(null);
+ InspectionOrder.setSampleTakerUserId(null);
+ InspectionOrder.setSampleTakerUser(null);
baseMapper.updateById(InspectionOrder);
// 鍒犻櫎涔嬪墠鐨勮鎯�
@@ -241,57 +170,57 @@
.eq(InspectionOrderDetail::getInspectionOrderId, InspectionOrder.getInspectionOrderId()));
// 鏂板璇︽儏
- for (InspectionOrderDetail InspectionOrderDetail : InspectionOrder.getOrderDetailList()) {
- InspectionOrderDetail.setInspectionOrderId(InspectionOrder.getInspectionOrderId());
+ if (CollectionUtils.isNotEmpty(InspectionOrder.getOrderDetailList())) {
+ for (InspectionOrderDetail InspectionOrderDetail : InspectionOrder.getOrderDetailList()) {
+ InspectionOrderDetail.setInspectionOrderId(InspectionOrder.getInspectionOrderId());
+ }
+ inspectionOrderDetailService.saveBatch(InspectionOrder.getOrderDetailList());
}
- inspectionOrderDetailService.saveBatch(InspectionOrder.getOrderDetailList());
-
- //淇敼7.9鎶ュ憡缁撴灉
- ProcessReport processReport = processReportService.getOne(Wrappers.<ProcessReport>lambdaQuery().eq(ProcessReport::getInspectionOrderId, InspectionOrder.getInspectionOrderId()));
- processReport.setInsReportCode(InspectionOrder.getEntrustCode());//鎶ュ憡缂栧彿=濮旀墭缂栧彿
- processReportService.updateById(processReport);
return true;
}
/**
* 妫�楠屽鎵樺崟鍒犻櫎
+ *
* @param inspectionOrderId
* @return
*/
@Override
public boolean delInspectionOrder(Integer inspectionOrderId) {
+ InspectionOrder inspectionOrder = baseMapper.selectByIdForUpdate(inspectionOrderId);
+ if (inspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ Long bindingHistoryCount = inspectionOrderBindingMapper.selectCount(Wrappers.<InspectionOrderBinding>lambdaQuery()
+ .eq(InspectionOrderBinding::getInspectionOrderId, inspectionOrderId));
+ Long bindLogCount = inspectionOrderBindLogMapper.selectCount(Wrappers.<InspectionOrderBindLog>lambdaQuery()
+ .and(wrapper -> wrapper.eq(InspectionOrderBindLog::getOldInspectionOrderId, inspectionOrderId)
+ .or().eq(InspectionOrderBindLog::getNewInspectionOrderId, inspectionOrderId)));
+ Long attachmentCount = inspectionOrderAttachmentMapper.selectCount(Wrappers.<InspectionOrderAttachment>lambdaQuery()
+ .eq(InspectionOrderAttachment::getInspectionOrderId, inspectionOrderId));
+ if (bindingHistoryCount > 0 || bindLogCount > 0 || attachmentCount > 0) {
+ throw new ErrorException("璇ユ楠屽鎵樺崟宸叉湁涓嬪崟鎴栭檮浠跺巻鍙诧紝涓嶅厑璁稿垹闄�");
+ }
+
inspectionOrderDetailService.remove(Wrappers.<InspectionOrderDetail>lambdaQuery()
.eq(InspectionOrderDetail::getInspectionOrderId, inspectionOrderId));
baseMapper.deleteById(inspectionOrderId);
- //鍒犻櫎7.8鎶ュ憡
- processReportService.remove(Wrappers.<ProcessReport>lambdaQuery()
- .eq(ProcessReport::getInspectionOrderId, inspectionOrderId));
- //鍒犻櫎瀵瑰簲鐨勮澶囦娇鐢ㄨ褰�
- processOrderDeviceService.remove(Wrappers.<ProcessOrderDevice>lambdaQuery()
- .eq(ProcessOrderDevice::getInspectionOrderId, inspectionOrderId));
- //鍒犻櫎瀵瑰簲鐨�7.4鐨勬牱鍝佺敵璇�
- List<ProcessSample> processSamples = processSampleMapper.selectList(Wrappers.<ProcessSample>lambdaQuery()
- .eq(ProcessSample::getInspectionOrderId, inspectionOrderId));
- if (processSamples.size()>0){
- List<Integer> list = processSamples.stream().map(ProcessSample::getId).collect(Collectors.toList());
- processDealService.remove(Wrappers.<ProcessDeal>lambdaQuery()
- .in(ProcessDeal::getProcessSampleId,list));
- }
- //鍒犻櫎瀵瑰簲7.4鐨勬牱鍝佹帴鏀�
- processSampleService.remove(Wrappers.<ProcessSample>lambdaQuery()
- .eq(ProcessSample::getInspectionOrderId,inspectionOrderId));
return true;
}
/**
* 妫�楠屽鎵樺崟鏌ョ湅璇︽儏
+ *
* @param inspectionOrderId
* @return
*/
@Override
public InspectionOrderDto getInspectionOrderOne(Integer inspectionOrderId) {
InspectionOrder inspectionOrder = baseMapper.selectById(inspectionOrderId);
+ if (inspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
InspectionOrderDto inspectionOrderDto = new InspectionOrderDto();
BeanUtils.copyProperties(inspectionOrder, inspectionOrderDto);
@@ -301,77 +230,364 @@
return inspectionOrderDto;
}
- /**
- * 鏍规嵁鎴愬搧璁㈠崟id鏌ヨ濮旀墭鍗曡鎯�
- * @param insOrderId
- * @return
- */
@Override
- public InspectionOrderDto getInspectionOrderByInsOderId(Integer insOrderId) {
- InsOrder order = insOrderService.getById(insOrderId);
- InspectionOrderDto inspectionOrderDto = new InspectionOrderDto();
- inspectionOrderDto.setInsOrderId(order.getId());//鎴愬搧璁㈠崟id
- inspectionOrderDto.setEntrustCode(order.getEntrustCode());//濮旀墭缂栧彿
- inspectionOrderDto.setSampleName(order.getSample());//璇曟牱鍚嶇О
- inspectionOrderDto.setProduction(order.getProduction());//鐢熶骇鍗曚綅
- inspectionOrderDto.setCommissionUnit(order.getCompany());//濮旀墭鍗曚綅
- inspectionOrderDto.setCommissionUser(order.getPrepareUser());//濮旀墭浜�
- inspectionOrderDto.setSampleStatus("瀹屽ソ");//鏍峰搧鐘舵��
- inspectionOrderDto.setIsLeave(order.getIsLeave());//鏄惁鐣欐牱
- inspectionOrderDto.setProcessing(order.getProcessing());//鏍峰搧澶勭悊鏂瑰紡
- inspectionOrderDto.setAppointed(order.getAppointed());//绾﹀畾鏃堕棿
- inspectionOrderDto.setSend(order.getSend());//鎶ュ憡鍙戦�佹柟寮�
- inspectionOrderDto.setCommissionPhone(order.getPhone());//鎶ュ憡鍙戦�佹柟寮�
-
- return inspectionOrderDto;
+ public IPage<InspectionOrder> pageUnboundInspectionOrder(Page page, InspectionOrder inspectionOrder) {
+ return baseMapper.pageUnboundInspectionOrder(page, QueryWrappers.queryWrappers(inspectionOrder));
}
-
- /**
- * 濮旀墭鍗曟煡璇㈡垚鍝佽鍗�
- * @return
- */
@Override
- public IPage<InsOrder> getInsOrderOnInspection(Page page, InsOrder insOrder) {
- return baseMapper.getInsOrderOnInspection(page, QueryWrappers.queryWrappers(insOrder));
+ public IPage<InspectionOrderBindingDto> pageInspectionOrderBindings(Page page, Integer inspectionOrderId,
+ Boolean includeDeleted) {
+ if (inspectionOrderId == null || baseMapper.selectById(inspectionOrderId) == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ return inspectionOrderBindingMapper.pageBindings(page, inspectionOrderId, includeDeleted);
+ }
+
+ @Override
+ public List<InspectionOrderAttachment> listInspectionOrderAttachments(Integer inspectionOrderId, Long bindingId) {
+ if (inspectionOrderId == null || baseMapper.selectById(inspectionOrderId) == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ if (bindingId != null) {
+ InspectionOrderBinding binding = inspectionOrderBindingMapper.selectById(bindingId);
+ if (binding == null || !Objects.equals(binding.getInspectionOrderId(), inspectionOrderId)) {
+ throw new ErrorException("涓嬪崟璁板綍涓嶅睘浜庤妫�楠屽鎵樺崟");
+ }
+ }
+ return inspectionOrderAttachmentMapper.selectVisibleAttachments(inspectionOrderId, bindingId);
+ }
+
+ @Override
+ public InspectionOrderDto getInspectionOrderForPlaceOrder(Integer inspectionOrderId) {
+ InspectionOrder inspectionOrder = baseMapper.selectById(inspectionOrderId);
+ if (inspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ return getInspectionOrderOne(inspectionOrderId);
+ }
+
+ @Override
+ public Integer addInsOrderWithInspectionOrder(InsPlaceOrderDto insPlaceOrderDto) {
+ if (insPlaceOrderDto == null || insPlaceOrderDto.getInspectionOrderId() == null) {
+ throw new ErrorException("璇烽�夋嫨妫�楠屽鎵樺崟");
+ }
+ if (insPlaceOrderDto.getInsOrder() == null) {
+ throw new ErrorException("缂哄皯鎴愬搧涓嬪崟淇℃伅");
+ }
+ if (CollectionUtils.isEmpty(insPlaceOrderDto.getSampleList())) {
+ throw new ErrorException("璇峰~鍐欐湰娆℃牱鍝�");
+ }
+ String requestId = normalizeRequestId(insPlaceOrderDto.getRequestId());
+ Integer requestUserId = SecurityUtils.getUserId().intValue();
+ String requestHash = calculateRequestHash(insPlaceOrderDto);
+ if (inspectionOrderBindingMapper.lockRequestUser(requestUserId) == null) {
+ throw new ErrorException("褰撳墠鎿嶄綔浜轰笉瀛樺湪");
+ }
+ InspectionOrderBinding existing = inspectionOrderBindingMapper.selectByRequest(requestUserId, requestId);
+ if (existing != null) {
+ return resolveIdempotentRequest(existing, requestHash);
+ }
+ InspectionOrder inspectionOrder = baseMapper.selectByIdForUpdate(insPlaceOrderDto.getInspectionOrderId());
+ if (inspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ existing = inspectionOrderBindingMapper.selectByRequest(requestUserId, requestId);
+ if (existing != null) {
+ return resolveIdempotentRequest(existing, requestHash);
+ }
+ if (inspectionOrder.getCommissionUnitId() == null) {
+ throw new ErrorException("璇峰厛瀹屽杽濮旀墭鍗曚綅");
+ }
+ if (inspectionOrder.getCommissionUserId() == null) {
+ throw new ErrorException("璇峰厛瀹屽杽濮旀墭浜�");
+ }
+
+ fillInsOrderFromInspectionOrder(inspectionOrder, insPlaceOrderDto.getInsOrder());
+ Integer insOrderId = insOrderService.addInsOrder(insPlaceOrderDto.getSampleList(), insPlaceOrderDto.getInsOrder());
+ Long sampleTakerUserId = SecurityUtils.getUserId();
+ User sampleTaker = sampleTakerUserId == null ? null : userMapper.selectById(sampleTakerUserId);
+ InspectionOrderBinding binding = new InspectionOrderBinding();
+ binding.setInspectionOrderId(inspectionOrder.getInspectionOrderId());
+ binding.setInsOrderId(insOrderId);
+ binding.setSourceType("NEW");
+ binding.setRequestId(requestId);
+ binding.setRequestHash(requestHash);
+ binding.setRequestUserId(requestUserId);
+ binding.setSampleTakerUserId(sampleTakerUserId == null ? null : sampleTakerUserId.intValue());
+ binding.setSampleTakerUser(sampleTaker == null ? null : sampleTaker.getName());
+ binding.setSampleData(LocalDate.now());
+ binding.setOrderDeleted(0);
+ binding.setCreateUser(requestUserId);
+ binding.setCreateTime(LocalDateTime.now());
+ inspectionOrderBindingMapper.insert(binding);
+ return insOrderId;
+ }
+
+ private String normalizeRequestId(String requestId) {
+ if (StrUtil.isBlank(requestId)) {
+ throw new ErrorException("缂哄皯涓嬪崟璇锋眰鍙凤紝璇峰埛鏂伴〉闈㈠悗閲嶈瘯");
+ }
+ try {
+ return UUID.fromString(requestId.trim()).toString();
+ } catch (IllegalArgumentException e) {
+ throw new ErrorException("涓嬪崟璇锋眰鍙锋牸寮忛敊璇紝璇峰埛鏂伴〉闈㈠悗閲嶈瘯");
+ }
+ }
+
+ private Integer resolveIdempotentRequest(InspectionOrderBinding existing, String requestHash) {
+ if (!Objects.equals(existing.getRequestHash(), requestHash)) {
+ throw new ErrorException("璇锋眰鍙峰凡琚叾浠栦笅鍗曞唴瀹逛娇鐢紝璇烽噸鏂板彂璧蜂笅鍗�");
+ }
+ if (Integer.valueOf(1).equals(existing.getOrderDeleted())) {
+ throw new ErrorException("鍘熻鍗曞凡鍒犻櫎锛岃閲嶆柊鍙戣捣涓嬪崟");
+ }
+ return existing.getInsOrderId();
+ }
+
+ private String calculateRequestHash(InsPlaceOrderDto dto) {
+ LinkedHashMap<String, Object> content = new LinkedHashMap<>();
+ content.put("inspectionOrderId", dto.getInspectionOrderId());
+ content.put("insOrder", dto.getInsOrder());
+ content.put("sampleList", dto.getSampleList());
+ try {
+ byte[] digest = MessageDigest.getInstance("SHA-256")
+ .digest(JSON.toJSONString(content).getBytes(StandardCharsets.UTF_8));
+ StringBuilder result = new StringBuilder(64);
+ for (byte value : digest) {
+ result.append(String.format("%02x", value & 0xff));
+ }
+ return result.toString();
+ } catch (Exception e) {
+ throw new ErrorException("涓嬪崟璇锋眰鏍¢獙澶辫触");
+ }
+ }
+
+ private void fillInsOrderFromInspectionOrder(InspectionOrder inspectionOrder, InsOrder insOrder) {
+ insOrder.setEntrustCode(null);
+ insOrder.setSample(inspectionOrder.getSampleName());
+ insOrder.setCompany(inspectionOrder.getCommissionUnit());
+ insOrder.setCompanyId(inspectionOrder.getCommissionUnitId());
+ insOrder.setProduction(inspectionOrder.getProduction());
+ insOrder.setPrepareUser(inspectionOrder.getCommissionUser());
+ insOrder.setPhone(inspectionOrder.getCommissionPhone());
+ insOrder.setSampleStatus(inspectionOrder.getSampleStatus());
+ insOrder.setIsLeave(inspectionOrder.getIsLeave());
+ insOrder.setProcessing(inspectionOrder.getProcessing());
+ insOrder.setAppointed(inspectionOrder.getAppointed());
+ insOrder.setSend(inspectionOrder.getSend());
+ }
+
+ /** 浠呬俊浠诲鎴峰拰浜哄憳涓绘暟鎹紝鍚嶇О涓庣數璇濆潎浠ヤ富鏁版嵁蹇収涓哄噯銆� */
+ private void normalizeCommissionParty(InspectionOrder inspectionOrder) {
+ if (inspectionOrder.getCommissionUnitId() == null) {
+ throw new ErrorException("璇烽�夋嫨濮旀墭鍗曚綅");
+ }
+ Custom custom = customMapper.selectById(inspectionOrder.getCommissionUnitId());
+ if (custom == null) {
+ throw new ErrorException("濮旀墭鍗曚綅涓嶅瓨鍦ㄦ垨宸插仠鐢�");
+ }
+ inspectionOrder.setCommissionUnit(custom.getCompany());
+
+ if (inspectionOrder.getCommissionUserId() == null) {
+ throw new ErrorException("璇烽�夋嫨濮旀墭浜�");
+ }
+ User commissionUser = userMapper.selectById(inspectionOrder.getCommissionUserId());
+ if (commissionUser == null) {
+ throw new ErrorException("濮旀墭浜轰笉瀛樺湪鎴栧凡鍋滅敤");
+ }
+ inspectionOrder.setCommissionUser(commissionUser.getName());
+ inspectionOrder.setCommissionPhone(commissionUser.getPhone());
+ }
+
+ @Override
+ public void syncEntrustCode(Integer insOrderId) {
+ // 濮旀墭缂栧彿灞炰簬鍏蜂綋鎴愬搧璁㈠崟锛岄〉闈㈤�氳繃缁戝畾鍏崇郴瀹炴椂璇诲彇锛屼笉鍐嶅洖鍐欏鎵樺崟涓昏〃銆�
+ }
+
+ @Override
+ public void syncReportFile(Integer insReportId) {
+ if (insReportId == null) {
+ return;
+ }
+ InsReport insReport = insReportService.getById(insReportId);
+ if (insReport == null || !Integer.valueOf(1).equals(insReport.getIsRatify())) {
+ return;
+ }
+ InspectionOrderBinding binding = inspectionOrderBindingMapper.selectOne(Wrappers.<InspectionOrderBinding>lambdaQuery()
+ .eq(InspectionOrderBinding::getInsOrderId, insReport.getInsOrderId())
+ .eq(InspectionOrderBinding::getOrderDeleted, 0)
+ .last("limit 1"));
+ if (binding == null) {
+ return;
+ }
+ InspectionOrder inspectionOrder = baseMapper.selectById(binding.getInspectionOrderId());
+ if (inspectionOrder == null) return;
+
+ String sourceUrl = StrUtil.isBlank(insReport.getUrlS()) ? insReport.getUrl() : insReport.getUrlS();
+ if (StrUtil.isBlank(sourceUrl)) {
+ throw new ErrorException("姝e紡鎶ュ憡鏂囦欢涓嶅瓨鍦紝鏃犳硶鍚屾鍒版楠屽鎵樺崟");
+ }
+ String sourceFileName = sourceUrl.substring(sourceUrl.lastIndexOf('/') + 1);
+ String extension = sourceFileName.lastIndexOf('.') >= 0
+ ? sourceFileName.substring(sourceFileName.lastIndexOf('.')) : ".docx";
+ String fileName = inspectionOrder.getInspectionOrderCode() + "_order_" + insReport.getInsOrderId()
+ + "_report_" + insReportId + "_" + UUID.randomUUID() + extension;
+ Path sourcePath = Paths.get(wordUrl + sourceUrl.replaceFirst("/word", ""));
+ Path targetPath = Paths.get(wordUrl, fileName);
+ try {
+ if (!Files.exists(sourcePath)) {
+ throw new ErrorException("姝e紡鎶ュ憡鏂囦欢涓嶅瓨鍦紝鏃犳硶鍚屾鍒版楠屽鎵樺崟");
+ }
+ Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
+ InspectionOrderAttachment attachment = inspectionOrderAttachmentMapper.selectOne(
+ Wrappers.<InspectionOrderAttachment>lambdaQuery()
+ .eq(InspectionOrderAttachment::getInsReportId, insReportId).last("limit 1"));
+ if (attachment == null) {
+ attachment = new InspectionOrderAttachment();
+ attachment.setInsReportId(insReportId);
+ attachment.setSourceType("REPORT");
+ attachment.setCreateUser(SecurityUtils.getUserId().intValue());
+ attachment.setCreateTime(LocalDateTime.now());
+ }
+ attachment.setInspectionOrderId(binding.getInspectionOrderId());
+ attachment.setBindingId(binding.getId());
+ attachment.setFileName(fileName);
+ attachment.setFileUrl("/word/" + fileName);
+ attachment.setUpdateTime(LocalDateTime.now());
+ if (attachment.getId() == null) {
+ inspectionOrderAttachmentMapper.insert(attachment);
+ } else {
+ inspectionOrderAttachmentMapper.updateById(attachment);
+ }
+ } catch (ErrorException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ErrorException("鎶ュ憡鍚屾澶辫触");
+ }
+ }
+
+ @Override
+ public boolean changeBinding(Integer insOrderId, Integer inspectionOrderId, String reason) {
+ if (insOrderId == null || inspectionOrderId == null || StrUtil.isBlank(reason)) {
+ throw new ErrorException("缂哄皯鍙樻洿鍏宠仈鎵�闇�鍙傛暟");
+ }
+ InsOrder insOrder = insOrderService.getById(insOrderId);
+ if (insOrder == null) {
+ throw new ErrorException("鎴愬搧涓嬪崟涓嶅瓨鍦�");
+ }
+ if (!(Integer.valueOf(0).equals(insOrder.getState()) || Integer.valueOf(2).equals(insOrder.getState()))
+ || StrUtil.isNotBlank(insOrder.getEntrustCode())) {
+ throw new ErrorException("褰撳墠涓嬪崟宸茶繘鍏ユ楠屾祦绋嬫垨宸茬敓鎴愬鎵樼紪鍙凤紝涓嶅厑璁稿彉鏇村叧鑱�");
+ }
+ InspectionOrderBinding binding = inspectionOrderBindingMapper.selectByOrderIdForUpdate(insOrderId);
+ if (binding == null || Integer.valueOf(1).equals(binding.getOrderDeleted())) {
+ throw new ErrorException("鎴愬搧涓嬪崟鏈粦瀹氭湁鏁堟楠屽鎵樺崟");
+ }
+ InspectionOrder target = baseMapper.selectByIdForUpdate(inspectionOrderId);
+ if (target == null) {
+ throw new ErrorException("鐩爣妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
+ if (Objects.equals(binding.getInspectionOrderId(), inspectionOrderId)) {
+ throw new ErrorException("鐩爣妫�楠屽鎵樺崟涓庡綋鍓嶅鎵樺崟鐩稿悓");
+ }
+ if (!Objects.equals(target.getCommissionUnitId(), insOrder.getCompanyId())) {
+ throw new ErrorException("鐩爣妫�楠屽鎵樺崟涓庢垚鍝佽鍗曠殑濮旀墭鍗曚綅涓嶄竴鑷�");
+ }
+ Integer oldInspectionOrderId = binding.getInspectionOrderId();
+ binding.setInspectionOrderId(inspectionOrderId);
+ binding.setUpdateUser(SecurityUtils.getUserId().intValue());
+ binding.setUpdateTime(LocalDateTime.now());
+ inspectionOrderBindingMapper.updateById(binding);
+ inspectionOrderAttachmentMapper.update(null, Wrappers.<InspectionOrderAttachment>lambdaUpdate()
+ .eq(InspectionOrderAttachment::getBindingId, binding.getId())
+ .set(InspectionOrderAttachment::getInspectionOrderId, inspectionOrderId)
+ .set(InspectionOrderAttachment::getUpdateTime, LocalDateTime.now()));
+ InspectionOrderBindLog bindLog = new InspectionOrderBindLog();
+ bindLog.setInsOrderId(insOrderId);
+ bindLog.setOldInspectionOrderId(oldInspectionOrderId);
+ bindLog.setNewInspectionOrderId(inspectionOrderId);
+ bindLog.setChangeReason(reason.trim());
+ bindLog.setCreateUser(SecurityUtils.getUserId().intValue());
+ bindLog.setCreateTime(LocalDateTime.now());
+ inspectionOrderBindLogMapper.insert(bindLog);
+ return true;
}
/**
* 濮旀墭鍗曟垚鍝佹姤鍛婁笂浼�
+ *
* @param file
* @param inspectionOrderId
* @return
*/
@Override
public boolean uploadInspectionOrderFile(MultipartFile file, Integer inspectionOrderId) {
- String urlString;
- String pathName;
- try {
- String path = wordUrl;
- File realpath = new File(path);
- if (!realpath.exists()) {
- realpath.mkdirs();
- }
- pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + file.getOriginalFilename();
- urlString = realpath + "/" + pathName;
- file.transferTo(new File(urlString));
-
- baseMapper.update(null, Wrappers.<InspectionOrder>lambdaUpdate()
- .eq(InspectionOrder::getInspectionOrderId, inspectionOrderId)
- .set(InspectionOrder::getFileUrl, "/word/" + pathName));
-
-
-
- } catch (Exception e) {
- throw new ErrorException("鏂囦欢涓婁紶澶辫触");
- }
- return true;
+ throw new ErrorException("璇峰湪涓嬪崟璁板綍涓�夋嫨鍏蜂綋璁㈠崟鍚庝笂浼犻檮浠�");
}
@Override
- public void exportInspectionOrder(Integer inspectionOrderId, HttpServletResponse response) {
+ public boolean uploadInspectionOrderBindingFile(MultipartFile file, Long bindingId) {
+ if (file == null || file.isEmpty() || bindingId == null) {
+ throw new ErrorException("璇烽�夋嫨涓嬪崟璁板綍鍜屼笂浼犳枃浠�");
+ }
+ InspectionOrderBinding binding = inspectionOrderBindingMapper.selectById(bindingId);
+ if (binding == null || Integer.valueOf(1).equals(binding.getOrderDeleted())) {
+ throw new ErrorException("涓嬪崟璁板綍涓嶅瓨鍦ㄦ垨璁㈠崟宸插垹闄�");
+ }
+ try {
+ File realpath = new File(wordUrl);
+ if (!realpath.exists() && !realpath.mkdirs()) {
+ throw new ErrorException("鏂囦欢鐩綍鍒涘缓澶辫触");
+ }
+ String originalName = new File(file.getOriginalFilename() == null ? "attachment" : file.getOriginalFilename()).getName();
+ String pathName = "binding_" + bindingId + "_" + UUID.randomUUID() + "_" + originalName;
+ file.transferTo(new File(realpath, pathName));
+ InspectionOrderAttachment attachment = new InspectionOrderAttachment();
+ attachment.setInspectionOrderId(binding.getInspectionOrderId());
+ attachment.setBindingId(bindingId);
+ attachment.setSourceType("MANUAL");
+ attachment.setFileName(originalName);
+ attachment.setFileUrl("/word/" + pathName);
+ attachment.setCreateUser(SecurityUtils.getUserId().intValue());
+ attachment.setCreateTime(LocalDateTime.now());
+ inspectionOrderAttachmentMapper.insert(attachment);
+ return true;
+ } catch (ErrorException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ErrorException("鏂囦欢涓婁紶澶辫触");
+ }
+ }
+
+ @Override
+ public void exportInspectionOrder(Integer inspectionOrderId, Long bindingId, HttpServletResponse response) {
InspectionOrder inspectionOrder = baseMapper.selectById(inspectionOrderId);
+ if (inspectionOrder == null) {
+ throw new ErrorException("妫�楠屽鎵樺崟涓嶅瓨鍦�");
+ }
InspectionOrderExportDto inspectionOrderExportDto = extracted(inspectionOrder);
+ if (bindingId == null) {
+ inspectionOrderExportDto.setEntrustCode(null);
+ inspectionOrderExportDto.setSampleTakerUser(null);
+ inspectionOrderExportDto.setSampleTakerUserId(null);
+ inspectionOrderExportDto.setSampleData(null);
+ inspectionOrderExportDto.setSampleDataString(null);
+ } else {
+ InspectionOrderBinding binding = inspectionOrderBindingMapper.selectById(bindingId);
+ if (binding == null || !Objects.equals(binding.getInspectionOrderId(), inspectionOrderId)) {
+ throw new ErrorException("涓嬪崟璁板綍涓嶅睘浜庤妫�楠屽鎵樺崟");
+ }
+ InsOrder insOrder = insOrderService.getById(binding.getInsOrderId());
+ inspectionOrderExportDto.setEntrustCode(insOrder == null ? null : insOrder.getEntrustCode());
+ inspectionOrderExportDto.setSampleTakerUser(binding.getSampleTakerUser());
+ inspectionOrderExportDto.setSampleTakerUserId(binding.getSampleTakerUserId());
+ inspectionOrderExportDto.setSampleData(binding.getSampleData());
+ if (binding.getSampleData() != null) {
+ inspectionOrderExportDto.setSampleDataString(binding.getSampleData()
+ .format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�")));
+ }
+ }
List<InspectionOrderDetail> list = inspectionOrderDetailService.list(Wrappers.<InspectionOrderDetail>lambdaQuery()
.eq(InspectionOrderDetail::getInspectionOrderId, inspectionOrderId));
int index = 1;
@@ -401,6 +617,7 @@
template.write(os);
os.flush();
os.close();
+ inputStream.close();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("瀵煎嚭澶辫触");
@@ -425,14 +642,14 @@
inspectionOrderExportDto.setAppointedString(inspectionOrder.getAppointed().format(formatter));
}
- inspectionOrderExportDto.setIsLeave1(inspectionOrder.getIsLeave() != null && inspectionOrder.getIsLeave() == 1? "鈽�" : "鈻�");
- inspectionOrderExportDto.setIsLeave2(inspectionOrder.getIsLeave() != null && inspectionOrder.getIsLeave() == 0? "鈽�" : "鈻�");
- inspectionOrderExportDto.setSend0(inspectionOrder.getSend() != null && inspectionOrder.getSend() == 1? "鈽�" : "鈻�");
- inspectionOrderExportDto.setSend1(inspectionOrder.getSend() != null && inspectionOrder.getSend() == 0? "鈽�" : "鈻�");
- inspectionOrderExportDto.setProcessing0(inspectionOrder.getProcessing() != null && inspectionOrder.getProcessing() == 0? "鈽�" : "鈻�");
- inspectionOrderExportDto.setProcessing1(inspectionOrder.getProcessing() != null && inspectionOrder.getProcessing() == 1? "鈽�" : "鈻�");
- inspectionOrderExportDto.setCriterionRule0(inspectionOrder.getCriterionRule() != null && inspectionOrder.getCriterionRule() == 0? "鈽�" : "鈻�");
- inspectionOrderExportDto.setCriterionRule1(inspectionOrder.getCriterionRule() != null && inspectionOrder.getCriterionRule() == 1? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setIsLeave1(inspectionOrder.getIsLeave() != null && inspectionOrder.getIsLeave() == 1 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setIsLeave2(inspectionOrder.getIsLeave() != null && inspectionOrder.getIsLeave() == 0 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setSend0(inspectionOrder.getSend() != null && inspectionOrder.getSend() == 1 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setSend1(inspectionOrder.getSend() != null && inspectionOrder.getSend() == 0 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setProcessing0(inspectionOrder.getProcessing() != null && inspectionOrder.getProcessing() == 0 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setProcessing1(inspectionOrder.getProcessing() != null && inspectionOrder.getProcessing() == 1 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setCriterionRule0(inspectionOrder.getCriterionRule() != null && inspectionOrder.getCriterionRule() == 0 ? "鈽�" : "鈻�");
+ inspectionOrderExportDto.setCriterionRule1(inspectionOrder.getCriterionRule() != null && inspectionOrder.getCriterionRule() == 1 ? "鈽�" : "鈻�");
return inspectionOrderExportDto;
}
}
--
Gitblit v1.9.3