| | |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.service.InsOrderPlanService; |
| | | import com.yuanchu.mom.service.InformationNotificationService; |
| | | import com.yuanchu.mom.service.InsOrderService; |
| | | import com.yuanchu.mom.service.InsProductService; |
| | | import com.yuanchu.mom.utils.GiveCode; |
| | | import com.yuanchu.mom.utils.QYWXApi; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.SampleDefectsFatherVo; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | 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; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | @Resource |
| | | InsProductResultMapper insProductResultMapper; |
| | | @Resource |
| | | private WarehouseHistoryMapper warehouseHistoryMapper; |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | | @Resource |
| | | private InsProductService insProductService; |
| | | @Resource |
| | | private InsProductUserMapper insProductUserMapper; |
| | | @Resource |
| | | private GiveCode giveCode; |
| | | @Resource |
| | | private InsSampleUserMapper insSampleUserMapper; |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | @Resource |
| | | UserMapper userMapper; |
| | | @Resource |
| | | InformationNotificationService informationNotificationService; |
| | | @Resource |
| | | PowerMapper powerMapper; |
| | | @Resource |
| | | CustomMapper customMapper; |
| | | @Resource |
| | | QYWXApi qywxApi; |
| | | @Autowired |
| | | ProcessOrder1Mapper processOrderMapper; |
| | | |
| | | |
| | | //获取检验下单数据 |
| | |
| | | }); |
| | | map.put("body", sampleOrderDtoIPage); |
| | | return map; |
| | | } |
| | | |
| | | //分配站点 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId, String sonLaboratory) { |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(orderId); |
| | | //insOrder.setAppointed(LocalDate.parse(appointed)); |
| | | insOrder.setSendTime(LocalDateTime.now()); |
| | | insOrderMapper.updateById(insOrder); |
| | | //修改成只给当前选择的试验室下发单子 |
| | | InsOrderState insOrderState = new InsOrderState(); |
| | | insOrderState.setInsOrderId(orderId); |
| | | insOrderState.setLaboratory(sonLaboratory); |
| | | insOrderState.setInsState(0); |
| | | insOrderState.setNum(1);//初始是第一次 |
| | | insOrderStateMapper.insert(insOrderState); |
| | | //这里是在给分配的指定的人和试验室下发检验人 |
| | | if (userId != null) { |
| | | InsSampleUser insSampleUser = new InsSampleUser(); |
| | | insSampleUser.setState(0); |
| | | insSampleUser.setUserId(userId); |
| | | insSampleUser.setInsSampleId(orderId); |
| | | insSampleUser.setSonLaboratory(sonLaboratory); |
| | | insSampleUserMapper.insert(insSampleUser); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | }); |
| | | 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() + |
| | | ",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))+ |
| | | ",请前往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()+",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))); |
| | | info.setSenderId(userId); |
| | | info.setViewStatus(false); |
| | | info.setJumpPath("b1-inspection-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() + |
| | | ",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(",")) + |
| | | ",请前往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()+",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))); |
| | | info.setSenderId(userId); |
| | | info.setViewStatus(false); |
| | | info.setJumpPath("b1-inspection-order"); |
| | | info.setConsigneeId(user.getId()); |
| | | notificationArrayList.add(info); |
| | | } |
| | | informationNotificationService.saveBatch(notificationArrayList); |
| | | } |
| | | //如果有上传的附件 |
| | | if (CollectionUtils.isNotEmpty(files)) { |
| | |
| | | if (!realpath.exists()) { |
| | | realpath.mkdirs(); |
| | | } |
| | | pathName = UUID.randomUUID() + "_" + file.getOriginalFilename(); |
| | | pathName = UUID.randomUUID() + "_" + file.getOriginalFilename().replace("#", "&"); |
| | | urlString = realpath + "/" + pathName; |
| | | file.transferTo(new File(urlString)); |
| | | insOrderFile.setFileUrl(pathName); |
| | |
| | | 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() + |
| | | ",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))+ |
| | | ",请前往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() + ",样品名称是:"+list.stream().map(SampleProductDto::getSample).collect(Collectors.joining(","))); |
| | | info.setSenderId(userId); |
| | | info.setConsigneeId(insOrder.getIssueUser()); |
| | | info.setViewStatus(false); |
| | | info.setJumpPath("b1-inspection-order"); |
| | | informationNotificationService.addInformationNotification(info); |
| | | } |
| | | return insOrder.getId(); |
| | | } |
| | |
| | | //审核通过才会生成委托编号 |
| | | insOrder.setEntrustCode(giveCode.giveCode2("WT-", "ins_order", "-", "yyMMdd")); |
| | | insOrder.setSendTime(LocalDateTime.now()); |
| | | /*todo 根据订单类型判断是否需要推送企业微信 @zss*/ |
| | | /*if (!order.getFormType().equals("其他成品")) { |
| | | String account = userMapper.selectById(order.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系统查看。订单号是:"+order.getEntrustCode()+",请前往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); |
| | | }*/ |
| | | /*审核通过还需要新增一条cnas要求、标书和合同评审*/ |
| | | ProcessOrder processOrder = new ProcessOrder(); |
| | | processOrder.setInsOrderId(insOrder.getId()); |
| | | processOrder.setRule(insOrder.getRule()); |
| | | processOrderMapper.insert(processOrder); |
| | | } |
| | | return insOrderMapper.updateById(insOrder); |
| | | } |
| | |
| | | } |
| | | 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); |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) { |
| | | public Map<String, Object> getInsOrderAndSample(Integer sampleId, String laboratory) { |
| | | InsSample insSample = insSampleMapper.selectById(sampleId); |
| | | 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); |
| | | InsOrder insOrder = insOrderMapper.selectById2(insSample.getInsOrderId()); |
| | | SampleProductDto sampleProductDto = insSampleMapper.getInsOrderAndSample(sampleId, 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); |
| | | if (ObjectUtils.isEmpty(sampleProductDto)) { |
| | | 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); |
| | | } |
| | | |
| | | SampleProductDto dto = new SampleProductDto(); |
| | | dto.setInsProduct(insProducts); |
| | | BeanUtils.copyProperties(insSample,dto); |
| | | sampleProductDto=dto; |
| | | } |
| | | for (SampleProductDto sampleProductDto : list) { |
| | | List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList()); |
| | | List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery() |
| | | .in(InsProductUser::getInsProductId, ids)); |
| | | if (CollectionUtils.isNotEmpty(insProductUsers)) { |
| | | List<Integer> userIds = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList()); |
| | | String collect = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(",")); |
| | | sampleProductDto.setCheckName(collect); |
| | | } |
| | | List<Integer> ids = sampleProductDto.getInsProduct().stream().map(InsProduct::getId).collect(Collectors.toList()); |
| | | List<InsProductUser> insProductUsers = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery() |
| | | .in(InsProductUser::getInsProductId, ids)); |
| | | if (CollectionUtils.isNotEmpty(insProductUsers)) { |
| | | List<Integer> userIds = insProductUsers.stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList()); |
| | | String collect = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(",")); |
| | | sampleProductDto.setCheckName(collect); |
| | | } |
| | | map.put("insOrder", insOrder); |
| | | map.put("sampleProduct", list); |
| | | map.put("sampleProduct", sampleProductDto); |
| | | //查询所有记录模版去重 |
| | | List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory); |
| | | List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(insSample.getInsOrderId(), laboratory); |
| | | map.put("reportModel", list2); |
| | | return map; |
| | | } |
| | |
| | | .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; |
| | | } |
| | | |
| | |
| | | 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 sampleProductDtos; |
| | | } |
| | | |