value
2023-08-31 34abd07d1567dd0757113c822e9a7dfc4a4cc1d1
inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/InspectionServiceImpl.java
@@ -1,8 +1,11 @@
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;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -59,6 +62,12 @@
    @Resource
    UserMapper userMapper;
    @Resource
    RawMaterialMapper rawMaterialMapper;
    @Resource
    LinkDetectionMapper linkDetectionMapper;
    /**
     * 查询检验申请单列表
@@ -71,10 +80,40 @@
        return inspectionMapper.selectInspectsList(page, message);
    }
    //新增检验单-->选择检验项目版本
    @Override
    public List<Integer> chooseVer(String name, String mcode, String specifications) {
        Integer specificationId = getSpecificationId(name, mcode, specifications);
        return productMapper.chooseVersion(specificationId);
    }
    //新增检验单-->选择检验项目版本-->查看该版本下我们要做的项目要求
    @Override
    public List<Map<String, Object>> lookProByVer(String name, String mcode, String specifications, Integer version, String experiment) {
        Integer specificationId = getSpecificationId(name, mcode, specifications);
        /*如果试验项目为空则是成品检验或者原材料检验则是展示该版本的所有项目检验要求参数*/
        if (ObjectUtils.isEmpty(experiment)) {
            return productMapper.pageProductInformation(specificationId, version);
        }
        /*如果不为空则是委托检验,只展示我们要检验的项目要求参数*/
        //获取试验项目信息(结构,导线外径)
        List<String> experiments = Arrays.stream(experiment.split(",")).collect(Collectors.toList());
        //根据型号id和项目信息查询项目信息
        List<Map<String, Object>> products = new ArrayList<>();
        for (String exper : experiments) {
            List<Map<String, Object>> list = productMapper.selFath(specificationId, exper, version);
            if (ObjectUtils.isEmpty(list)) {
                Map<String, Object> project = productMapper.selNam(specificationId, exper, version);
                products.add(project);
            }
            products.addAll(list);
        }
        return products;
    }
    /**
     * 新增检验申请表
     *
     * @param id
     * @param id 用户id
     * @param
     * @return
     */
@@ -90,6 +129,22 @@
                .userId(id)
                .build();
        inspectionMapper.insert(inspection);
        /*如果是原材料检验,新增之后要更改原材料报检的状态和检验人,检验日期*/
        if (inspectionVo.getType()==0) {
            RawMaterial rawMaterial = new RawMaterial();
            rawMaterial.setId(inspectionVo.getId());
            rawMaterial.setType(1);
            rawMaterial.setInspectionDate(DateUtil.date());
            rawMaterial.setSurveyor(userMapper.selectById(id).getName());
            rawMaterialMapper.updateById(rawMaterial);
        }
        /*如果是委托检验,新增之后要更改委托报检的状态*/
        else if (inspectionVo.getType()==2){
            LinkDetection linkDetection = new LinkDetection();
            linkDetection.setId(inspectionVo.getId());
            linkDetection.setInspectionStatus(2);
            linkDetectionMapper.updateById(linkDetection);
        }
        /*新增检验样品表*/
        InspectionMaterial inspectionMaterial = InspectionMaterial.builder()
                .code(inspectionVo.getMcode())
@@ -103,25 +158,55 @@
                .build();
        inspectionMaterialMapper.insert(inspectionMaterial);
        /*新增检验项目表*/
        //获取物料id
        Material material = materialMapper.selectOne(Wrappers.<Material>query()
                .eq("name", inspectionVo.getName())
                .eq("code", inspectionVo.getMcode()));
        //获取规格名称和型号名称
        String specification = inspectionVo.getSpecifications();
        String[] split = specification.split("-");
        String stName = split[0];
        String spName = split[1];
        //获取规格id
        Standard standard = standardService.getOne(Wrappers.<Standard>query()
                .eq("name", stName)
                .eq("material_id", material.getId()));
        //获取型号id
        Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query()
                .eq("name", spName)
                .eq("standard_id", standard.getId()));
        //根据型号id查询项目信息
        List<Product> productList = productMapper.selectList(Wrappers.<Product>query().eq("specifications_id", specifications.getId()));
        //根据样品名称编号以及型号规格获取型号id
        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())) {
            //获取试验项目信息(结构,导线外径)
            List<String> experiments = Arrays.stream(inspectionVo.getExperiment().split(",")).collect(Collectors.toList());
            //根据型号id和项目信息查询项目信息
            List<Product> products = new ArrayList<>();
            for (String experiment : experiments) {
                List<Product> productList1 = productMapper.selectList(Wrappers.<Product>query()
                        .eq("specifications_id", specificationId)
                        .eq("father", experiment)
                        .eq("version", inspectionVo.getVersion()));
                if (ObjectUtils.isEmpty(productList1)) {
                    Product product = productMapper.selectOne(Wrappers.<Product>query()
                            .eq("specifications_id", specificationId)
                            .isNull("father")
                            .eq("name", experiment)
                            .eq("version", inspectionVo.getVersion()));
                    products.add(product);
                } else products.addAll(productList1);
            }
            //将查询的项目信息构建成检验项目
            ArrayList<InspectionProduct> list = new ArrayList<>();
            for (Product product : products) {
                InspectionProduct rawInsProduct = InspectionProduct.builder()
                        .name(product.getName())
                        .unit(product.getUnit())
                        .required(product.getRequired())
                        .internal(product.getInternal())
                        .inspectionMaterialId(inspectionMaterial.getId())
                        .build();
                list.add(rawInsProduct);
            }
            //检验项目批量添加
            inspectionProductService.saveBatch(list);
            return inspection.getId();
        }
        //如果试验项目为空则按照型号id在标准库里面全部匹配
        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) {
            InspectionProduct rawInsProduct = InspectionProduct.builder()
@@ -129,7 +214,7 @@
                    .unit(product.getUnit())
                    .required(product.getRequired())
                    .internal(product.getInternal())
                    .inspectionMaterialId(material.getId())
                    .inspectionMaterialId(inspectionMaterial.getId())
                    .build();
            list.add(rawInsProduct);
        }
@@ -159,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 -> {
@@ -172,12 +258,13 @@
                insProductVo.setInstrumentName(equipmentName);
            }
            //获取用户名(前提是如果存在)
            if (insProduct.getUserId() != null) {
                String userName = userMapper.selectById(insProduct.getUserId()).getName();
            if (insProduct.getUserProId() != null) {
                String userName = userMapper.selectById(insProduct.getUserProId()).getName();
                insProductVo.setUserName(userName);
            }
            //项目关联物料id
            insProductVo.setInspectionMaterialId(inspectionMaterial.getId());
            insProductVo.setId(insProduct.getId());
            return insProductVo;
        }).collect(Collectors.toList());
        inspectDetailVo.setInsProducts(insProductVos);
@@ -212,6 +299,37 @@
        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];
        String spName = split[1];
        //获取规格id
        Standard standard = standardService.getOne(Wrappers.<Standard>query()
                .eq("name", stName)
                .eq("material_id", material.getId()));
        //获取型号id
        Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query()
                .eq("name", spName)
                .eq("standard_id", standard.getId()));
        return specifications.getId();
    }
}