| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import cn.hutool.core.date.DateUtil; |
| | | 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; |
| | | import com.yuanchu.mom.Task.BatchInfo; |
| | | import com.yuanchu.mom.Task.SyncOrder; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.pojo.vo.RawInsProductVo; |
| | | import com.yuanchu.mom.pojo.vo.RawInspectVo; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.yuanchu.mom.utils.MyUtil; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | //新增原材料检验单-->根据原材料编码得到ifs中的报检数据 |
| | | @Override |
| | | public List<RawInspectVo> chooseIFS(String code) { |
| | | List<RawInspectVo> rawInspectVos = new ArrayList<>(); |
| | | List<Map<String, Object>> mapList = SyncOrder.ifsInterfaces(); |
| | | for (Map<String, Object> map : mapList) { |
| | | // todo: 后续需要将状态改成待检验 |
| | | if (map.get("STATE").equals("已接收")) { |
| | | if (map.get("PART_NO").toString().equals(code)) { |
| | | RawInspectVo rawInspectVo = new RawInspectVo(); |
| | | rawInspectVo.setCode(map.get("PART_NO").toString()); //原材料编码 |
| | | String[] split = map.get("PART_DESC").toString().split(","); |
| | | rawInspectVo.setName(split[0]); //原材料名称 |
| | | rawInspectVo.setSpecifications(split[1]); //型号规格 |
| | | rawInspectVo.setUnit(map.get("BUY_UNIT_MEAS").toString()); //单位 |
| | | rawInspectVo.setNumber(Integer.parseInt(String.valueOf(map.get("QTY_TO_INSPECT")))); //数量 |
| | | rawInspectVo.setFormTime(DateUtil.parse(map.get("APPROVED_DATE").toString())); //来料日期 |
| | | rawInspectVo.setSupplier(map.get("SUPPLIER_NAME").toString()); //供应商 |
| | | String orderNo = map.get("ORDER_NO").toString();//订单号 |
| | | String releaseNo = map.get("RELEASE_NO").toString();//下达号 |
| | | String lineNo = map.get("LINE_NO").toString();//行号 |
| | | String lotBatchNo = map.get("LOT_BATCH_NO").toString();//批号 |
| | | String locationNo = map.get("LOCATION_NO").toString();//库位号 |
| | | rawInspectVo.setMessage(orderNo+","+releaseNo+","+lineNo+","+lotBatchNo+","+locationNo); |
| | | rawInspectVos.add(rawInspectVo); |
| | | |
| | | //查询该原材料是否有检验项目记录 |
| | | RawInspect rawInspect = rawInspectMapper.selOneByCode(code); |
| | | if (ObjectUtils.isNotEmpty(rawInspect)) { |
| | | List<RawInsProduct> rawInsProductList = rawInsProductMapper.selectList(Wrappers.<RawInsProduct>query().eq("raw_inspect_id", rawInspect.getId())); |
| | | List<RawInsProductVo> rawInsProductVos = rawInsProductList.stream().map(rawInsProduct -> { |
| | | RawInsProductVo rawInsProductVo = new RawInsProductVo(); |
| | | rawInsProductVo.setName(rawInsProduct.getName()); |
| | | rawInsProductVo.setUnit(rawInsProduct.getUnit()); |
| | | rawInsProductVo.setRequired(rawInsProduct.getRequired()); |
| | | rawInsProductVo.setInternal(rawInsProduct.getInternal()); |
| | | return rawInsProductVo; |
| | | }).collect(Collectors.toList()); |
| | | rawInspectVo.setRawInsProducts(rawInsProductVos); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return rawInspectVos; |
| | | } |
| | | |
| | | //新增原材料检验单 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | rawInspectVo.setUserName(userMapper.selectById(userId).getName()); |
| | | //校验标准值,内控值格式 |
| | | List<RawInsProductVo> rawInsProductVos = rawInspectVo.getRawInsProducts(); |
| | | for (RawInsProductVo rawInsProductVo : rawInsProductVos) { |
| | | char internal = rawInsProductVo.getInternal().charAt(0); |
| | | char required = rawInsProductVo.getRequired().charAt(0); |
| | | if (internal != '>' && internal != '<' && internal != '=') { |
| | | return "内控值输入格式有问题!"; |
| | | } |
| | | if (required != '>' && required != '<' && required != '=') { |
| | | return "标准值输入格式有问题!"; |
| | | } |
| | | } |
| | | /*新增原材料检验单*/ |
| | | RawInspect rawInspect = new RawInspect(); |
| | | BeanUtils.copyProperties(rawInspectVo, rawInspect); |
| | |
| | | RawInsProduct rawInsProduct = new RawInsProduct(); |
| | | BeanUtils.copyProperties(rawInsProVo, rawInsProduct); |
| | | if (ObjectUtils.isNotEmpty(rawInsProduct.getTestValue())) { |
| | | //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 |
| | | String required = rawInsProduct.getRequired();//标准值 |
| | | String internal = rawInsProduct.getInternal();//内控值 |
| | | String testValue = rawInsProduct.getTestValue();//检测值 |
| | | List<Integer> list = Arrays.stream(testValue.split(",")).map(s -> { |
| | | int values = checkValues(required, internal, s); |
| | | return values; |
| | | }).collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | //如果其中一个检验值不合格则该项目检验不合格 |
| | | if (rawInsProduct.getTestValue().equals("过")) { |
| | | rawInsProduct.setTestState(1); |
| | | } else if (rawInsProduct.getTestValue().equals("不过")) { |
| | | rawInsProduct.setTestState(0); |
| | | } else { |
| | | rawInsProduct.setTestState(1); |
| | | //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 |
| | | String required = rawInsProduct.getRequired();//标准值 |
| | | String internal = rawInsProduct.getInternal();//内控值 |
| | | String testValue = rawInsProduct.getTestValue();//检测值 |
| | | char req = required.charAt(0); |
| | | List<Integer> list = Arrays.stream(testValue.split(",")).map(s -> { |
| | | int values = 2; |
| | | if (req == '>' || req == '<' || req == '=') { |
| | | values = checkValues(required, internal, s); |
| | | } else { |
| | | values = conValues(required, internal, s); |
| | | } |
| | | return values; |
| | | }).collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | //如果其中一个检验值不合格则该项目检验不合格 |
| | | rawInsProduct.setTestState(0); |
| | | } else { |
| | | rawInsProduct.setTestState(1); |
| | | } |
| | | } |
| | | rawInsProduct.setUserId(Integer.parseInt(userId)); |
| | | } |
| | |
| | | //更新检验状态(上报) |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String updateRawInspectsById(Integer id) { |
| | | public String updateRawInspectsById(Integer id, Integer number) { |
| | | /*更新检验单里面的检验结论*/ |
| | | //先判断检验结果 |
| | | List<Integer> results = rawInsProductMapper.getresult(id); |
| | |
| | | } else return "项目未检验完!"; |
| | | /*如果检验结论为不合格,则需要新增不合格检验单*/ |
| | | if (rawInspect.getJudgeState() == 0) { |
| | | //查询该检验单哪些检验项目不合格 |
| | | List<RawInsProduct> rawInsProductList = rawInsProductMapper.selectList(Wrappers.<RawInsProduct>query() |
| | | .eq("raw_inspect_id", id) |
| | | .eq("test_state", 0)); |
| | | String msg =""; |
| | | for (RawInsProduct rawInsProduct : rawInsProductList) { |
| | | msg=msg+rawInsProduct.getName()+"-"; |
| | | } |
| | | InspectUnaccepted rawUnaccepted = InspectUnaccepted.builder() |
| | | .reason(rawInspectMapper.selectById(id).getName() + "不合格") //暂且定义为原材料不合格 |
| | | .reason(msg + "不合格") //定义为不合格的项目+不合格 |
| | | .number(number) |
| | | .rawInspectId(id) |
| | | .type(0) //类型为原材料 |
| | | .build(); |
| | | inspectUnacceptedMapper.insert(rawUnaccepted); |
| | | } |
| | | return "上报成功!"; |
| | | /*检验完成后,无论合格与否,将IFS报检状态更改为已接收*/ |
| | | //根据检验单id查询原材料检验单 |
| | | RawInspect rawIns = rawInspectMapper.selectById(id); |
| | | String[] split = rawIns.getMessage().split(","); |
| | | BatchInfo batchInfo = new BatchInfo(); |
| | | batchInfo.setOrderNo(split[0]); |
| | | batchInfo.setReleaseNo(split[1]); |
| | | batchInfo.setLineNo(split[2]); |
| | | batchInfo.setPartNo(rawIns.getCode()); |
| | | batchInfo.setLotBatchNo(split[3]); |
| | | batchInfo.setLocationNo(split[4]); |
| | | if (ObjectUtils.isEmpty(number)) { |
| | | //如果不合格的数量为空null |
| | | number=0; |
| | | } |
| | | batchInfo.setQtyToReceive(rawIns.getNumber()-number); //要接收的数量 |
| | | batchInfo.setQtyToInspect(rawIns.getNumber()); //要检验的数量 |
| | | batchInfo.setReceiveCase("接收到来料区"); |
| | | List<BatchInfo> batchInfos = Arrays.asList(batchInfo); |
| | | //发送IFS请求 |
| | | String s = SyncOrder.importPolReceive(batchInfos); |
| | | System.out.println(s); |
| | | System.out.println("'''''''''''''''''''''''"); |
| | | return rawInspect.getJudgeState().toString(); |
| | | } |
| | | |
| | | |
| | | /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ |
| | | //如果是±的操作 |
| | | private int conValues(String standardValueStr, String controlValueStr, String detectionValueStr) { |
| | | double standVar = Double.parseDouble(standardValueStr); |
| | | double controlVar = Double.parseDouble(controlValueStr); |
| | | double detecVar = Double.parseDouble(detectionValueStr); |
| | | double a = standVar + controlVar; |
| | | double b = standVar - controlVar; |
| | | if (detecVar >= b && detecVar <= a) { |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | //如果是> , < ,=的操作 |
| | | private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) { |
| | | boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr); |
| | | boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr); |