value
2023-08-31 0afd6c073589d5221774dab5cf4a9d21415ec0e8
inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java
@@ -1,7 +1,9 @@
package com.yuanchu.limslaboratory.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -132,6 +134,7 @@
            RawMaterial rawMaterial = new RawMaterial();
            rawMaterial.setId(inspectionVo.getId());
            rawMaterial.setType(1);
            rawMaterial.setInspectionDate(DateUtil.date());
            rawMaterial.setSurveyor(userMapper.selectById(id).getName());
            rawMaterialMapper.updateById(rawMaterial);
        }
@@ -156,7 +159,12 @@
        inspectionMaterialMapper.insert(inspectionMaterial);
        /*新增检验项目表*/
        //根据样品名称编号以及型号规格获取型号id
        Integer specificationId = getSpecificationId(inspectionVo.getName(), inspectionVo.getMcode(), inspectionVo.getSpecifications());
        Integer specificationId = null;
        if(ObjectUtils.isNotEmpty(inspectionVo.getSpecificationId())){
            specificationId =Integer.parseInt(inspectionVo.getSpecificationId());
        }else{
            specificationId=getSpecificationId(inspectionVo.getName(), inspectionVo.getMcode(), inspectionVo.getSpecifications());
        }
        //如果试验项目字段不为空则按该字段的项目进行匹配
        if (ObjectUtils.isNotEmpty(inspectionVo.getExperiment())) {
            //获取试验项目信息(结构,导线外径)
@@ -194,7 +202,10 @@
            return inspection.getId();
        }
        //如果试验项目为空则按照型号id在标准库里面全部匹配
        List<Product> productList = productMapper.selectList(Wrappers.<Product>query().eq("specifications_id", specificationId));
        List<Product> productList =
                productMapper.selectList(Wrappers.<Product>query()
                        .eq("specifications_id", specificationId)
                .eq("version",inspectionVo.getVersion()));
        //将查询的项目信息构建成检验项目
        ArrayList<InspectionProduct> list = new ArrayList<>();
        for (Product product : productList) {
@@ -233,7 +244,8 @@
        BeanUtils.copyProperties(inspectionMaterial, inspectDetailVo);
        /*查询检验单里面的检验项目,并封装到RawInspectVo对象中*/
        LambdaQueryWrapper<InspectionProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId());
        queryWrapper
                .eq(InspectionProduct::getInspectionMaterialId, inspectionMaterial.getId());
        List<InspectionProduct> inspectionProducts = inspectionProductMapper.selectList(queryWrapper);
        //这里查到的设备id和检验员id要查询名称
        List<InsProductVo> insProductVos = inspectionProducts.stream().map(insProduct -> {
@@ -242,16 +254,15 @@
            BeanUtils.copyProperties(insProduct, insProductVo);
            //获取设备名(前提是如果存在)
            if (insProduct.getInstrumentId() != null) {
                String equipmentName = instrumentService.getById(insProduct.getInstrumentId()).getEquipmentName();
                insProductVo.setInstrumentName(equipmentName);
                insProductVo.setInstrumentId(insProduct.getInstrumentId());
            }
            //获取用户名(前提是如果存在)
            if (insProduct.getUserId() != null) {
                String userName = userMapper.selectById(insProduct.getUserId()).getName();
                insProductVo.setUserName(userName);
            if (insProduct.getUserProId() != null) {
                insProductVo.setUserId(insProduct.getUserProId());
            }
            //项目关联物料id
            insProductVo.setInspectionMaterialId(inspectionMaterial.getId());
            insProductVo.setId(insProduct.getId());
            return insProductVo;
        }).collect(Collectors.toList());
        inspectDetailVo.setInsProducts(insProductVos);
@@ -286,12 +297,23 @@
        return "保存成功!";
    }
    @Override
    public boolean chooseEquipment(Integer id, Integer equipmentId) {
        UpdateWrapper<InspectionProduct>inspectionProductUpdateWrapper=new UpdateWrapper<>();
        inspectionProductUpdateWrapper.lambda().set(InspectionProduct::getInstrumentId,equipmentId)
                .eq(InspectionProduct::getId,id);
        return inspectionProductMapper.update(null,inspectionProductUpdateWrapper)>0;
    }
    /*根据样品名称,样品编号,型号规格获取型号id*/
    private Integer getSpecificationId(String name, String mcode, String specification) {
        //获取物料id
        Material material = materialMapper.selectOne(Wrappers.<Material>query()
                .eq("name", name)
                .eq("code", mcode));
        if (Objects.isNull(material)){
            return null;
        }
        //获取规格名称和型号名称
        String[] split = specification.split("-");
        String stName = split[0];