zss
2024-12-09 4bc7776bc6c063a9bfb9806e4bf6db5bf22985b1
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -27,6 +27,9 @@
import com.yuanchu.mom.service.*;
import com.yuanchu.mom.utils.*;
import com.yuanchu.mom.vo.*;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
@@ -126,6 +129,9 @@
    @Resource
    FuSheUtils fuSheUtils;
    @Resource
    DianLuUtils dianLuUtils;
    @Override
    public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
        Map<String, Object> map = new HashMap<>();
@@ -182,6 +188,12 @@
        if (BeanUtil.isEmpty(order.getInsTime())) {
            insOrder.setInsTime(LocalDateTime.now());//订单的检验时间
            insOrderMapper.updateById(insOrder);
        }
        InsOrderState orderState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery()
                .eq(InsOrderState::getInsOrderId, insSample.getInsOrderId())
                .eq(InsOrderState::getInsSampleId, sampleId)
                .eq(InsOrderState::getLaboratory, laboratory));
        if (ObjectUtils.isEmpty(orderState.getInsTime())) {
            //更新检验任务表的检验时间
            insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate()
                    .eq(InsOrderState::getInsOrderId, insSample.getInsOrderId())
@@ -295,13 +307,13 @@
            sampleId = insOrderFile.getInsSampleId();
            insOrderFile.setInsSampleId(null);
        }
        IPage<InsOrderFile> insOrderFileIPage = insOrderFileMapper.getFileList(page, QueryWrappers.queryWrappers(insOrderFile), insOrderId, sonLaboratory,sampleId);
        IPage<InsOrderFile> insOrderFileIPage = insOrderFileMapper.getFileList(page, QueryWrappers.queryWrappers(insOrderFile), insOrderId, sonLaboratory, sampleId);
        map.put("body", insOrderFileIPage);
        return map;
    }
    @Override
    public int uploadFile(Integer orderId, MultipartFile file, String sonLaboratory, Integer sampleId) {
    public Object uploadFile(Integer orderId, MultipartFile file, String sonLaboratory, Integer sampleId) {
        String urlString;
        String pathName;
        String path;
@@ -330,21 +342,19 @@
            if (!realpath.exists()) {
                realpath.mkdirs();
            }
            pathName = UUID.randomUUID() + "_"+file.getOriginalFilename().replace("#", "&");
            pathName = UUID.randomUUID() + "_" + file.getOriginalFilename().replace("#", "&");
            urlString = realpath + "/" + pathName;
            file.transferTo(new File(urlString));
            insOrderFile.setFileUrl(pathName);
            insOrderFileMapper.insert(insOrderFile);
            //如果是辐射试验(近场/远程上传的csv文件)
            String[] split = filename.split("\\.");
            if (ObjectUtils.isNotEmpty(sonLaboratory) && (sonLaboratory.equals("近场") || sonLaboratory.equals("远场")) &&
                    split[split.length - 1].equals("csv")) {
                //判断是哪种csv文件,是否有——
                if (sonLaboratory.equals("近场")) {
                    fuSheUtils.getFuSheWord1(sonLaboratory, insOrderFile);
                } else {
                    fuSheUtils.getFuSheWord2(sonLaboratory, insOrderFile);
                }
            if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("近场") && split[split.length - 1].equals("csv")) {
                fuSheUtils.getFuSheWord1(sonLaboratory, insOrderFile);
            } else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("远场") && split[split.length - 1].equals("xlsx")) {
                fuSheUtils.getFuSheWord2(sonLaboratory, insOrderFile);
            }else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验") && split[split.length - 1].equals("xlsx") && filename.contains("交调")) {
               dianLuUtils.readDianLuFile1(sampleId,insOrderFile);
            }
        } catch (Exception e) {
            System.err.println("附件上传错误");
@@ -371,12 +381,15 @@
    //扫码报检
    @Override
    public int scanInsOrderState(String sonLaboratory, String sampleCode, String trees) {
    public int scanInsOrderState(String sonLaboratory, String sampleCode, String trees, String entrustCode) {
        /*样品入库*/
        warehouseService.inWarehouse(trees, sampleCode);
        warehouseService.inWarehouse(trees, sampleCode, entrustCode);
        /*新增检验任务*/
        //先判断该样品是否有这个站点的项目
        InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getSampleCode, sampleCode));
        List<InsOrder> insOrders = insOrderMapper.selectList(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getEntrustCode, entrustCode));
        InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery()
                .eq(InsSample::getSampleCode, sampleCode)
                .eq(InsSample::getInsOrderId, insOrders.get(0).getId()));
        List<String> collect = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                .eq(InsProduct::getState, 1)
                .eq(InsProduct::getInsSampleId, insSample.getId())).stream().map(InsProduct::getSonLaboratory).collect(Collectors.toList());
@@ -415,10 +428,13 @@
    //扫码出库
    @Override
    public int outInsOrderState(String sonLaboratory, String sampleCode) {
    public int outInsOrderState(String sonLaboratory, String sampleCode, String entrustCode) {
        //判断该样品的检验任务是否已经结束(继续试验或者是结束试验)
        //先判断该样品是否有这个站点的项目
        InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getSampleCode, sampleCode));
        List<InsOrder> insOrders = insOrderMapper.selectList(Wrappers.<InsOrder>lambdaQuery().eq(InsOrder::getEntrustCode, entrustCode));
        InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery()
                .eq(InsSample::getSampleCode, sampleCode)
                .eq(InsSample::getInsOrderId, insOrders.get(0).getId()));
        List<String> collect = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                .eq(InsProduct::getState, 1)
                .eq(InsProduct::getInsSampleId, insSample.getId())).stream().map(InsProduct::getSonLaboratory).collect(Collectors.toList());
@@ -440,7 +456,7 @@
            }
        }
        boolean a = true;
        warehouseService.outWarehouse(sampleCode, a);
        warehouseService.outWarehouse(sampleCode, a, entrustCode);
        return 0;
    }
@@ -483,11 +499,60 @@
                //获取最后一行的num,即总行数。此处从0开始
                int maxRow = sheet.getLastRowNum();
                for (int row = 0; row <= maxRow; row++) {
                    XSSFRow xssfRow = sheet.getRow(row);
                    //获取最后单元格num,即总单元格数 ***注意:此处从1开始计数***
                    int maxRol = sheet.getRow(row).getLastCellNum();
                    StringBuilder aLine = new StringBuilder();
                    for (int rol = 0; rol < maxRol; rol++) {
                    /*for (int rol = 0; rol < maxRol; rol++) {
                        aLine.append(sheet.getRow(row).getCell(rol)).append(",");
                    }*/
                    for (int rol = 0; rol < maxRol; rol++) {
                        XSSFCell cell = xssfRow.getCell(rol);
                        if (cell == null) {
                            aLine.append(",");
                        } else {
                            switch (cell.getCellType()) {
                                case FORMULA:
                                    // 计算公式并获取结果
                                    CellValue cellValue = xssfWorkbook.getCreationHelper().createFormulaEvaluator().evaluate(cell);
                                    switch (cellValue.getCellType()) {
                                        case NUMERIC:
                                            String formattedValue = String.format("%.4f", cellValue.getNumberValue());
                                            aLine.append(formattedValue);
                                            break;
                                        case STRING:
                                            aLine.append(cellValue.getStringValue());
                                            break;
                                        case BOOLEAN:
                                            aLine.append(cellValue.getBooleanValue());
                                            break;
                                        case ERROR:
                                            aLine.append("#ERR!");
                                            break;
                                        default:
                                            aLine.append("");
                                            break;
                                    }
                                    break;
                                case NUMERIC:
                                    String formattedValue = String.format("%.4f", cell.getNumericCellValue());
                                    aLine.append(formattedValue);
                                    break;
                                case STRING:
                                    aLine.append(cell.getStringCellValue());
                                    break;
                                case BOOLEAN:
                                    aLine.append(cell.getBooleanCellValue());
                                    break;
                                case ERROR:
                                    aLine.append("#ERR!");
                                    break;
                                default:
                                    aLine.append("");
                                    break;
                            }
                            aLine.append(",");
                        }
                    }
                    String substring = aLine.substring(0, aLine.length() - 1);
                    result.append(substring).append("\n");
@@ -737,7 +802,7 @@
                //结论
                int ressult = 1;
                String valueStr = insProductResult2.getValue();
                String regex ="[\u4e00-\u9fa5]";
                String regex = "[\u4e00-\u9fa5]";
                if (!insProduct.getAsk().contains(",")) {
                    if (insProduct.getAsk().equals("/") || Pattern.compile(regex).matcher(insProduct.getAsk()).find()) {
                        ressult = 3; //不判定
@@ -982,7 +1047,10 @@
                    if (insOrder.getFormType().equals("原理样机")) {
                        //出库
                        try {
                            outInsOrderState(laboratory, insSample.getSampleCode());
                            List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insSample.getInsOrderId()));
                            for (InsSample sample : insSamples) {
                                outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode());
                            }
                        } catch (Exception e) {
                        }
@@ -1091,7 +1159,7 @@
        info.setCreateUser(insProductMapper.selectUserById(userId).get("name"));
        info.setMessageType("2");
        info.setTheme("复核通知");
        info.setContent("您有一条检验任务待复核消息");
        info.setContent("您有一条检验任务待复核消息,订单号是:" + insOrder.getEntrustCode() + ",样品名称为:" + insSample.getSample());
        info.setSenderId(userId);
        info.setConsigneeId(submitPlanDto.getVerifyUser());
        info.setViewStatus(false);
@@ -1106,12 +1174,13 @@
        map.put("msgtype", "text");//消息类型 text:文本
        map.put("agentid", 1000517);//应用id
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("content", "您有一条检验任务待复核消息,订单号是:" + insOrder.getEntrustCode() + ",请前往LIMS系统查看。<a href=\"https://ztwxlims.ztt.cn:7443/enter\">中天通信LIMS系统 </a>");
        hashMap.put("content", "您有一条检验任务待复核消息,订单号是:" + insOrder.getEntrustCode() + ",样品名称为:" + insSample.getSample() +
                ",请前往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);
        qywxApi.send(map);
        //复核人--检验单相关负责人
        InsSampleUser insSampleUser = new InsSampleUser();
        insSampleUser.setUserId(submitPlanDto.getVerifyUser());
@@ -1129,9 +1198,6 @@
                throw new ErrorException("电路试验的站点报告生成有误,请联系开发人员调整!");
            }
        }
        /*// 删除数采采集次数
        String key = "frequency" + ":" + submitPlanDto.getEntrustCode() + ":*";
        RedisUtil.delsLike(key);*/
        /*生成产量工时*/
        //校验如果这个人这个检测项目已经添加过了则不需要再新增
@@ -1158,26 +1224,26 @@
                }
                for (AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours : submitPlanDto.getAuxiliaryOutputWorkingHoursList()) {
                    InsProduct insProduct = insProductMapper.selectById(auxiliaryOutputWorkingHours.getInsProductId());
                        if (isWithinRange) {
                            //在时间内就是正常上班
                            auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//非加班委托单号
                            auxiliaryOutputWorkingHours.setWorkTime(auxiliaryOutputWorkingHours.getOutputWorkTime());//非加班工时
                            auxiliaryOutputWorkingHours.setAmount(1);//非加班数量
                        } else {
                            //加班
                            auxiliaryOutputWorkingHours.setOvertimeOrderNo(insOrder.getEntrustCode());//加班委托单号
                            auxiliaryOutputWorkingHours.setOvertimeWorkTime(auxiliaryOutputWorkingHours.getOutputWorkTime());//加班工时
                            auxiliaryOutputWorkingHours.setOvertimeAmount(1);//加班数量
                        }
                        auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//工时分组
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                        DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                        auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//日期
                        LocalDateTime localDateTime = LocalDateTime.now();
                        DateTime parse = DateUtil.parse(localDateTime.format(formatter));
                        auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//星期
                        auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//周次
                        auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
                    if (isWithinRange) {
                        //在时间内就是正常上班
                        auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//非加班委托单号
                        auxiliaryOutputWorkingHours.setWorkTime(auxiliaryOutputWorkingHours.getOutputWorkTime());//非加班工时
                        auxiliaryOutputWorkingHours.setAmount(1);//非加班数量
                    } else {
                        //加班
                        auxiliaryOutputWorkingHours.setOvertimeOrderNo(insOrder.getEntrustCode());//加班委托单号
                        auxiliaryOutputWorkingHours.setOvertimeWorkTime(auxiliaryOutputWorkingHours.getOutputWorkTime());//加班工时
                        auxiliaryOutputWorkingHours.setOvertimeAmount(1);//加班数量
                    }
                    auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//工时分组
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                    DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//日期
                    LocalDateTime localDateTime = LocalDateTime.now();
                    DateTime parse = DateUtil.parse(localDateTime.format(formatter));
                    auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//星期
                    auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//周次
                    auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
                }
            }
        }