zss
2024-11-19 e8d0a2f9375da4d04da4a06a0f9fa8ef448512c4
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -21,6 +21,7 @@
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.*;
import com.yuanchu.mom.pojo.*;
import com.yuanchu.mom.service.InformationNotificationService;
import com.yuanchu.mom.service.InsOrderPlanService;
import com.yuanchu.mom.service.InsOrderService;
import com.yuanchu.mom.service.InsProductService;
@@ -40,6 +41,8 @@
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -74,6 +77,10 @@
    @Resource
    private InsSampleMapper insSampleMapper;
    @Resource
    InsProductResult2Mapper insProductResult2Mapper;
    @Resource
    InsProductResultMapper insProductResultMapper;
    @Resource
    private WarehouseHistoryMapper warehouseHistoryMapper;
    @Resource
    private InsProductMapper insProductMapper;
@@ -89,6 +96,9 @@
    private InsOrderStateMapper insOrderStateMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    InformationNotificationService informationNotificationService;
    @Resource
    PowerMapper powerMapper;
    @Resource
@@ -240,14 +250,80 @@
            }
        });
        List<User> users1 = userMapper.getUserByRole("检测中心主任");
        List<User> users2 = userMapper.getUserByRole("研发部经理");
        List<User> users3 = userMapper.getUserByRole("技术负责人");
        //通信:如果是C类订单无需审核直接通过
        if (insOrder.getOrderType().equals("C")) {
            insOrder.setState(1);
            upInsOrderOfState(insOrder);
        }else if (insOrder.getOrderType().equals("A")){
            //常规外部单需消息提醒检验中心主任和研发部经理
            //todo 企业微信推送
            users1.addAll(users2);
            String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|"));
            HashMap<String, Object> map = new HashMap<>();
            map.put("touser", account);//接收消息成员的账号'ZT-031292'这种类型(如果有多个用'|'分隔)
            map.put("msgtype", "text");//消息类型 text:文本
            map.put("agentid", 1000517);//应用id
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("content", "您有一条检验订单需要审核,请前往LIMS系统查看。外部订单号是:"+insOrder.getOutEntrustCode()+",请前往LIMS系统查看。<a href=\"https://ztwxlims.ztt.cn:7443/enter\">中天通信LIMS系统 </a>");
            map.put("text", hashMap);//消息内容
            map.put("safe", 0);//是否保密消息.0否
            map.put("enable_id_trans", 0);//是否开启id转译.0否
            map.put("enable_duplicate_check", 0);//是否开启重复消息检查.0否
            qywxApi.send(map);
            //lims消息提醒
            ArrayList<InformationNotification> notificationArrayList = new ArrayList<>();
            for (User user : users1) {
                InformationNotification info = new InformationNotification();
                info.setCreateUser(userMapper.selectById(userId).getName());
                info.setMessageType("2");
                info.setTheme("审核通知");
                info.setContent("您有一条检验订单待审核消息,订单的外部编号是:"+insOrder.getOutEntrustCode());
                info.setSenderId(userId);
                info.setViewStatus(false);
                info.setJumpPath("b1-inspect-order");
                info.setConsigneeId(user.getId());
                notificationArrayList.add(info);
            }
            informationNotificationService.saveBatch(notificationArrayList);
        }else if (insOrder.getOrderType().equals("B")){
            //非常规外部单需消息提醒检验中心主任,研发部经理和技术负责人
            //todo 企业微信推送
            users1.addAll(users2);
            users1.addAll(users3);
            String account = users1.stream().map(User::getAccount).collect(Collectors.joining("|"));
            HashMap<String, Object> map = new HashMap<>();
            map.put("touser", account);//接收消息成员的账号'ZT-031292'这种类型(如果有多个用'|'分隔)
            map.put("msgtype", "text");//消息类型 text:文本
            map.put("agentid", 1000517);//应用id
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("content", "您有一条检验订单需要审核,请前往LIMS系统查看。外部订单号是:"+insOrder.getOutEntrustCode()+",请前往LIMS系统查看。<a href=\"https://ztwxlims.ztt.cn:7443/enter\">中天通信LIMS系统 </a>");
            map.put("text", hashMap);//消息内容
            map.put("safe", 0);//是否保密消息.0否
            map.put("enable_id_trans", 0);//是否开启id转译.0否
            map.put("enable_duplicate_check", 0);//是否开启重复消息检查.0否
            qywxApi.send(map);
            //lims消息提醒
            ArrayList<InformationNotification> notificationArrayList = new ArrayList<>();
            for (User user : users1) {
                InformationNotification info = new InformationNotification();
                info.setCreateUser(userMapper.selectById(userId).getName());
                info.setMessageType("2");
                info.setTheme("审核通知");
                info.setContent("您有一条检验订单待审核消息,订单的外部编号是:"+insOrder.getOutEntrustCode());
                info.setSenderId(userId);
                info.setViewStatus(false);
                info.setJumpPath("b1-inspect-order");
                info.setConsigneeId(user.getId());
                notificationArrayList.add(info);
            }
            informationNotificationService.saveBatch(notificationArrayList);
        }
        //如果有上传的附件
        if (CollectionUtils.isNotEmpty(files)) {
            for (MultipartFile file : files ) {
            for (MultipartFile file : files) {
                String urlString;
                String pathName;
                String path;
@@ -280,6 +356,33 @@
                    System.err.println("附件上传错误");
                }
            }
        }
        //todo 根据订单类型判断是否需要推送企业微信 @zss
        if (!insOrder.getFormType().equals("其他成品")) {
            String account = userMapper.selectById(insOrder.getIssueUser()).getAccount();
            HashMap<String, Object> map = new HashMap<>();
            map.put("touser", account);//接收消息成员的账号'ZT-031292'这种类型(如果有多个用'|'分隔)
            map.put("msgtype", "text");//消息类型 text:文本
            map.put("agentid", 1000517);//应用id
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("content", "您有一条订单需要完成,请前往LIMS系统查看。外部订单号是:"+insOrder.getOutEntrustCode()+",请前往LIMS系统查看。<a href=\"https://ztwxlims.ztt.cn:7443/enter\">中天通信LIMS系统 </a>");
            map.put("text", hashMap);//消息内容
            map.put("safe", 0);//是否保密消息.0否
            map.put("enable_id_trans", 0);//是否开启id转译.0否
            map.put("enable_duplicate_check", 0);//是否开启重复消息检查.0否
            qywxApi.send(map);
            //LIMS系统消息推送
            InformationNotification info = new InformationNotification();
            info.setCreateUser(insProductMapper.selectUserById(userId).get("name"));
            info.setMessageType("1");
            info.setTheme("样机员通知");
            info.setContent("您有一条检验订单的样机待完成消息,外部订单号是:"+insOrder.getOutEntrustCode()+",请前往LIMS系统查看。");
            info.setSenderId(userId);
            info.setConsigneeId(insOrder.getIssueUser());
            info.setViewStatus(false);
            info.setJumpPath("b1-inspect-order");
            informationNotificationService.addInformationNotification(info);
        }
        return insOrder.getId();
    }
@@ -322,27 +425,7 @@
        if (insOrder.getState() == 1) {
            //审核通过才会生成委托编号
            insOrder.setEntrustCode(giveCode.giveCode2("WT-", "ins_order", "-", "yyMMdd"));
            //确定订单的下发时间和约定时间
            //int day = insProductService.selectOrderManDay(insOrder.getId());//预计完成时间
            //insOrder.setAppointed(LocalDate.parse(LocalDateTime.now().plusHours(day).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
            insOrder.setSendTime(LocalDateTime.now());
            /*todo 根据订单类型判断是否需要推送企业微信 @zss*/
            if (!order.getFormType().equals("其他成品")) {
               /* HashMap<String, Object> map = new HashMap<>();
                String account = userMapper.selectById(order.getIssueUser()).getAccount();
                map.put("touser", account);//接收消息成员的账号'ZT-031292'这种类型(如果有多个用'|'分隔)
                map.put("toparty", "");//接收部门id
                map.put("totag", "");//消息标签id
                map.put("msgtype", "text");//消息类型 text:文本
                map.put("agentid", 1000513);//应用id
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("content", "您有一条订单需生成检验,请前往LIMS系统查看。<a href=\"http://10.1.13.77/enter\"> </a>");
                map.put("text", JSONArray.toJSONString(hashMap));//消息内容
                map.put("safe", 0);//是否保密消息.0否
                map.put("enable_id_trans", 0);//是否开启id转译.0否
                map.put("enable_duplicate_check", 0);//是否开启重复消息检查.0否
                qywxApi.send(map);*/
            }
        }
        return insOrderMapper.updateById(insOrder);
    }
@@ -373,8 +456,8 @@
        }
        insOrderMapper.updateById(order);
        //查询该订单是A类还是B类
        if (order.getOrderType().equals("A")) {
            //如果是A类,1和2和3都审核通过这个单子就审核通过
        if (order.getOrderType().equals("B")) {
            //如果是B类,1和2和3都审核通过这个单子就审核通过
            if (order.getCheckState1() == 1 && order.getCheckState2() == 1 && order.getCheckState3() == 1) {
                order.setState(1);
                upInsOrderOfState(order);
@@ -382,8 +465,8 @@
                order.setState(2);
                upInsOrderOfState(order);
            }
        } else if (order.getOrderType().equals("B")) {
            //如果是B类,1和2审核通过后这个单子就审核通过
        } else if (order.getOrderType().equals("A")) {
            //如果是A类,1和2审核通过后这个单子就审核通过
            if (order.getCheckState1() == 1 && order.getCheckState2() == 1) {
                order.setState(1);
                upInsOrderOfState(order);
@@ -399,9 +482,31 @@
    public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) {
        Map<String, Object> map = new HashMap<>();
        InsOrder insOrder = insOrderMapper.selectById2(id);
        List<SampleProductDto> insSamples = insSampleMapper.selectList1(insOrder.getId());
        List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory);
        if (list.size() == 0) {
            list = insSampleMapper.getInsOrderAndSample2(id, laboratory);
        //再次试验会出现为空的情况
        if (list.size() != insSamples.size()) {
            List<Integer> ids = list.stream().map(sampleProductDto -> sampleProductDto.getId()).distinct().collect(Collectors.toList());
            List<SampleProductDto> samples = insSamples.stream().filter(insSample ->
                    !ids.contains(insSample.getId())
            ).collect(Collectors.toList());
            for (SampleProductDto insSample : samples) {
                List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                        .eq(InsProduct::getInsSampleId, insSample.getId())
                        .eq(InsProduct::getState, 1)
                        .eq(InsProduct::getSonLaboratory, laboratory));
                for (InsProduct insProduct : insProducts) {
                    List<InsProductResult2> insProductResult2List = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery()
                            .eq(InsProductResult2::getInsProductId, insProduct.getId()).isNull(InsProductResult2::getNum));
                    insProduct.setInsProductResult2(insProductResult2List);
                    InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
                            .eq(InsProductResult::getInsProductId, insProduct.getId()).isNull(InsProductResult::getNum));
                    insProduct.setInsProductResult(insProductResult);
                }
                insSample.setInsProduct(insProducts);
                list.add(insSample);
            }
        }
        for (SampleProductDto sampleProductDto : list) {
            List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList());
@@ -479,7 +584,9 @@
                .filter(dto -> dto.getPrice() != null) // 过滤掉价格为 null 的对象
                .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum())
                .sum();
        map.put("total", totalPrice);
        BigDecimal bd = new BigDecimal(totalPrice).setScale(2, RoundingMode.HALF_UP);
        double roundedTotalPrice = bd.doubleValue();
        map.put("total", roundedTotalPrice);
        return map;
    }
@@ -503,16 +610,7 @@
    public List<SampleProductDto3> labelPrinting(String ids) {
        List<Integer> list = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        List<SampleProductDto3> sampleProductDtos = insSampleMapper.selectSampleProductListByOrderId3(list);
        Set<String> processedCodes = new HashSet<>();
        List<SampleProductDto3> sampleProductDto3s = sampleProductDtos.stream().filter(sampleProductDto3 -> {
            if (processedCodes.contains(sampleProductDto3.getCode())) {
                return false;
            } else {
                processedCodes.add(sampleProductDto3.getCode());
                return true;
            }
        }).collect(Collectors.toList());
        return sampleProductDto3s;
        return sampleProductDtos;
    }
    //校验电机编号