zss
2023-09-24 7930d685829d7cc1e743e9a4cd9bd3924ad953fb
inspect-server/src/main/java/com/yuanchu/mom/service/impl/FinishedInspectServiceImpl.java
@@ -16,6 +16,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -36,19 +37,10 @@
    FinishedInspectMapper finishedInspectMapper;
    @Resource
    MaterialMapper materialMapper;
    @Resource
    StandardService standardService;
    @Resource
    SpecificationsService specificationsService;
    @Resource
    ManualTechnologyMapper manualTechnologyMapper;
    @Resource
    ProductService productService;
    ManualProductService manualProductService;
    @Resource
    InspectionItemService inspectionItemService;
@@ -72,6 +64,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer addProcessInspectionSheet(String userId, FinishedInspectVo finishedInspectVo) {
        //根据生产订单id查询编制工序的最后一道工艺
        List<ManualTechnology> manualTechnologyList = manualTechnologyMapper.selAllByMoId(finishedInspectVo.getId());
        //获取编制工艺最后一道工艺的id
        Integer mtId = manualTechnologyList.get(0).getId();
        /*新增成品检验单*/
        FinishedInspect finishedInspect = new FinishedInspect();
        finishedInspect.setUserId(Integer.parseInt(userId));
@@ -84,20 +80,16 @@
        finishedInspect.setSpecificationsModel(finishedInspectVo.getSpecificationsModel());
        finishedInspect.setMaterial(finishedInspectVo.getMaterial());
        finishedInspect.setMaterialCode(finishedInspectVo.getMcode());
        //finishedInspect.setTechId(technologyId);
        finishedInspectMapper.insert(finishedInspect);
        /*批量新增成品检验项目单*/
        //获取型号id
        Integer specificationId = getSpecificationId(finishedInspectVo.getMaterial(), finishedInspectVo.getMcode(), finishedInspectVo.getSpecificationsModel());
        //根据生产订单id查询编制工序的最后一道工艺
        List<ManualTechnology> manualTechnologyList = manualTechnologyMapper.selAllByMoId(finishedInspectVo.getId());
        //获取最后一道工艺关联的工艺路线id
        Integer technologyId = manualTechnologyList.get(0).getTechnologyId();
        //查询标准BOM技术指标中该型号工艺下最新版本的检验项目
        Integer ver = productService.selectVerByPro(specificationId).get(0);//该型号下技术指标最新版本
        List<Product> productList = productService.selProByVerSpe(technologyId, ver);
        List<InspectionItem> inspectionItemList = productList.stream().map(product -> {
        List<ManualProduct> manualProductList = manualProductService.selByMtid(mtId);
        List<InspectionItem> inspectionItemList = manualProductList.stream().map(manualProduct -> {
            InspectionItem inspectionItem = new InspectionItem();
            BeanUtils.copyProperties(product, inspectionItem);
            BeanUtils.copyProperties(manualProductList, inspectionItem);
            inspectionItem.setId(null);
            inspectionItem.setCreateTime(new Date());
            inspectionItem.setUpdateTime(new Date());
            inspectionItem.setInspectId(finishedInspect.getId());
            inspectionItem.setType(2);//成品
            return inspectionItem;
@@ -106,13 +98,14 @@
        return finishedInspect.getId();
    }
    //上报(更新检验状态)
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String updateFinishInspectsById(String username,Integer id) {
    public String updateFinishInspectsById(String username, Integer id) {
        /*更新检验单里面的检验结论*/
        //先判断检验结果
        List<Integer> results = inspectionItemMapper.getResult(id,1);
        List<Integer> results = inspectionItemMapper.getResult(id, 2);
        int count = 0;
        for (Integer result : results) {
            if (result != null && result == 1) {
@@ -149,7 +142,7 @@
                    .eq(Repertory::getUnit, finishedInspect.getUnit())
                    .eq(Repertory::getType, 1);
            Repertory rep = repertoryMapper.selectOne(queryWrapper);
            if (rep != null ) {
            if (rep != null) {
                rep.setNumber(rep.getNumber() + finishedInspect.getQuantity());
                rep.setUserName(username);
                repertoryMapper.updateById(rep);
@@ -174,7 +167,7 @@
    //分页查询成品检验单列表
    @Override
    public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer result, String material) {
        return finishedInspectMapper.selectFinishedInspectPage(page, result,material);
        return finishedInspectMapper.selectFinishedInspectPage(page, result, material);
    }
    //根据检验单id查询成品检验单详情
@@ -183,76 +176,5 @@
        return finishedInspectMapper.selectFinishInspectsListById(id);
    }
    /*根据样品名称,样品编号,型号规格获取型号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();
    }
    /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/
    private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) {
        boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr);
        boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr);
        if (isStandardValueSatisfied && isControlValueSatisfied) {
            return 1;
        } else {
            return 0;
        }
    }
    private boolean isValueSatisfied(String valueStr, String detectionValueStr) {
        String substring = valueStr.substring(1, 2);
        if (substring.equals("=")) {
            String operator = valueStr.substring(0, 2);
            Double standardValue = Double.parseDouble(valueStr.substring(2));
            Double detectionValue = Double.parseDouble(detectionValueStr);
            switch (operator) {
                case ">=":
                    return detectionValue >= standardValue;
                case "<=":
                    return detectionValue <= standardValue;
                default:
                    return false;
            }
        } else {
            String operator = valueStr.substring(0, 1);
            Double standardValue = Double.parseDouble(valueStr.substring(1));
            Double detectionValue = Double.parseDouble(detectionValueStr);
            switch (operator) {
                case ">":
                    return detectionValue > standardValue;
                case "≥":
                    return detectionValue >= standardValue;
                case "≤":
                    return detectionValue <= standardValue;
                case "<":
                    return detectionValue < standardValue;
                case "=":
                    return detectionValue.equals(standardValue);
                default:
                    return false;
            }
        }
    }
}