package com.chinaztt.mes.quality.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils; 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.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.chinaztt.ifs.api.feign.IfsFeignClient; import com.chinaztt.mes.basic.entity.WorkstationLocation; import com.chinaztt.mes.basic.mapper.WorkstationLocationMapper; import com.chinaztt.mes.basic.util.AesUtils; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.quality.dto.*; import com.chinaztt.mes.quality.entity.*; import com.chinaztt.mes.quality.mapper.*; import com.chinaztt.mes.quality.service.ApplyPartService; import com.chinaztt.mes.quality.service.ApplyService; import com.chinaztt.mes.quality.service.ReportSampleService; import com.chinaztt.mes.quality.service.ReportService; import com.chinaztt.mes.quality.state.result.constant.ResultStateStringValues; import com.chinaztt.mes.quality.state.unqualifiedprocess.constant.UnqualifiedprocessStateStringValues; import com.chinaztt.mes.quality.utils.ReportUtils; import com.chinaztt.mes.quality.utils.TestApplyRuleUtils; import com.chinaztt.mes.warehouse.entity.Stock; import com.chinaztt.mes.warehouse.mapper.StockMapper; import com.chinaztt.mes.warehouse.service.StockService; import com.chinaztt.mes.warehouse.util.StockUtils; import com.chinaztt.mes.warehouse.util.TransactionType; import com.chinaztt.ztt.admin.api.feign.RemoteParamService; import com.chinaztt.ztt.common.core.constant.SecurityConstants; import com.chinaztt.ztt.common.core.util.R; import com.chinaztt.ztt.common.security.util.SecurityUtils; import com.google.gson.Gson; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; /** * 检测申请材料表 * * @author cxf * @date 2021-04-01 13:34:51 */ @Service @AllArgsConstructor @Component @Transactional(rollbackFor = Exception.class) public class ApplyPartServiceImpl extends ServiceImpl implements ApplyPartService { private static final long ONE = 1L; private static final long TWO = 2L; public static final String MOVELIBRARY = "mv";//移库码 public static final String UNMOVELIBRARY = "unmv";//取消移库码 private static final String SYSTEM = "L-MES"; private static final String SYSTEM_NAME = "采购检验后移库"; private static final String NEW_SYSTEM_NAME = "登记检验结果"; @Resource private ResultMapper resultMapper; @Resource private RemoteParamService remoteParamService; @Autowired private StockBean stockBean; @Autowired private StockUtils stockUtils; @Resource private WorkstationLocationMapper workstationLocationMapper; private ReportService reportService; @Autowired private ApplyService applyService; @Resource private ReportMapper reportMapper; @Resource private ApplyPartMapper applyPartMapper; @Resource private IfsFeignClient ifsFeignClient; @Resource private ReportUtils reportUtils; @Resource private ReportSampleService reportSampleService; @Resource private ReportSampleMapper reportSampleMapper; @Resource private TestApplyRuleUtils testApplyRuleUtils; @Resource private StockMapper stockMapper; @Resource private ApplyPartFileMapper applyPartFileMapper; @Resource private UnqualifiedProcessMapper unqualifiedProcessMapper; @Autowired public ApplyPartServiceImpl(@Lazy ReportService reportService) { this.reportService = reportService; } @Override public IPage getApplyPartPage(Page page, QueryWrapper gen) { return baseMapper.getApplyPartPage(page, gen); } @Override public IPage getApplyPartPageForReport(Page page, QueryWrapper gen) { return baseMapper.getApplyPartPageForReport(page, gen); } @Override public IPage getApplyPartPageForUnqualified(Page page, QueryWrapper gen, Long unqualifiedProcessId) { IPage applyPartPageForUnqualifiedList = baseMapper.getApplyPartPageForUnqualified(page, gen, unqualifiedProcessId); List records = applyPartPageForUnqualifiedList.getRecords(); for (ApplyPartDTO applyPartDTO:records) { if(applyPartDTO.getReplacePartId()!=null){ applyPartDTO.setPartId(applyPartDTO.getReplacePartId()); applyPartDTO.setPartNo(applyPartDTO.getReplacePartNo()); applyPartDTO.setPartName(applyPartDTO.getReplacePartName()); applyPartDTO.setPartDesc(applyPartDTO.getReplacePartName()); } } return applyPartPageForUnqualifiedList; } @Override public boolean removeByIdForReport(Long id) { // 删除零件时,对检测报告状态进行判断,如果是未检测,删除后全部检测完毕,则将状态改为已检测 ApplyPart applyPart = baseMapper.selectById(id);//传的是检测汇报明细id if(isApplyReportIsSubmit(applyPart.getReportId())){ throw new RuntimeException("检测汇报已提交,冻结删除操作!"); } Report report = reportMapper.selectById(applyPart.getReportId()); applyPart.setIsQualified(null);//复位检测结果 applyPart.setQtyArrived((new BigDecimal(applyPart.getQtyArrived()).add(new BigDecimal(applyPart.getUnqualifiedArrived()))).toString()); applyPart.setUnqualifiedArrived("0"); baseMapper.updateById(applyPart); boolean result = SqlHelper.retBool(baseMapper.deleteByIdForReport(id)); changeCheckState(applyPart); //更新检测结果为待检测 changeStatus(applyPart.getSystemNo(), ResultStateStringValues.UNTESTED, applyPart.getIsQualified(), report.getReportType()); return result; } /** * 根据检测汇报id判断检测汇报是否已提交 * @param reportId 检测汇报id * @return true:已提交;false:未提交 */ private boolean isApplyReportIsSubmit(Long reportId){ Report report = reportMapper.selectById(reportId); if(report == null){ throw new RuntimeException("检测汇报状态获取失败!"); }else{ if(report.getIsSubmit() == null || !report.getIsSubmit()){ return false;//检测汇报未提交 }else{ return true;//检测汇报已提交 } } } @Override public boolean isApplyReportIsSubmitByApplyPartId(Long id){ ApplyPart applyPart = baseMapper.selectById(id); Report report = reportMapper.selectById(applyPart.getReportId()); if(report == null){ return false;//没有检测汇报 }else{ if(report.getIsSubmit() == null || !report.getIsSubmit()){ return false;//检测汇报未提交 }else{ return true;//检测汇报已提交 } } } @Override public ApplyPartDTO getApplyPartDtoById(Long id) { ApplyPartDTO applyPartDTO = baseMapper.getApplyPartDtoById(id); applyPartDTO.setTestStandardList(baseMapper.findTestStandardNoBySystemNo(applyPartDTO.getSystemNo())); List applyPartFiles = this.applyPartFileMapper.selectList(Wrappers.lambdaQuery().eq(ApplyPartFile::getApplyPartId, id)); applyPartDTO.setApplyPartFileList(applyPartFiles); List reportSamples = reportSampleMapper.selectList(Wrappers.lambdaQuery().eq(ReportSample::getReportId, applyPartDTO.getReportId())); applyPartDTO.setReportSampleList(reportSamples); if (applyPartDTO.getProduceTime() == null) { applyPartDTO.setIsNotOutCheck(true); } return applyPartDTO; } @Override public List findTestStandardNoBySystemNo(String systemNo) { return baseMapper.findTestStandardNoBySystemNo(systemNo); } @Override public boolean synchronizationErpStock(List applyPartList) { List stockList = new ArrayList<>(); if (CollectionUtil.isNotEmpty(applyPartList)) { Set idList = applyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() == null && Double.parseDouble(o.getQtyArrived()) > 0).map(o -> o.getId()).collect(Collectors.toSet()); //合格数量大于0 if (CollectionUtil.isNotEmpty(idList)) { stockList = baseMapper.selectApplyPart(idList, remoteParamService.getByKey("QUALIFIED_LIBRARY", SecurityConstants.FROM_IN).getData()); //erp移库 synchronizationErp(stockList); } //不合格数量大于0 Set list = applyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() == null && Double.parseDouble(o.getUnqualifiedArrived()) > 0).map(o -> o.getId()).collect(Collectors.toSet()); if (CollectionUtil.isNotEmpty(list)) { stockList = baseMapper.selectUnApplyPart(list, remoteParamService.getByKey("UNQUALIFIED_LIBRARY", SecurityConstants.FROM_IN).getData()); synchronizationErp(stockList); } } return true; } @Override public boolean saveApply(List applyPartList) { applyPartList.stream().forEach(applyPart -> { // 添加申请零件 applyPart.setIsErp(true); applyPart.setSystemNo(applyPart.getOrderNo() + "-" + applyPart.getLineNo() + "-" + applyPart.getReleaseNo() + "-" + applyPart.getReceiptNo()); baseMapper.insert(applyPart); }); return true; } /** * 校验是否首检、是否合格 * * @param systemNo 改造(22-09-13)-交班产出在工作台那边,不会创建首检,但是会创建尾检,导致尾检与首检的系统编号不一致,统一改成通过批次号去判断 * @param batchNo 产出批次号 * @return */ private boolean isFirstApplyGood(String batchNo) { // 获取产出首检结果 Result result = resultMapper.selectOne(Wrappers.lambdaQuery().eq(Result::getApplyType, Apply.FIRST_APPLY).eq(Result::getPartBatchNo, batchNo)); if (null == result) { return Boolean.FALSE; } if (BooleanUtil.isTrue(result.getIsQualified())) { return Boolean.TRUE; } // 产出首检为不合格,查询不合格处理,如果是让步放行,返回true,否则返回false List unqualifiedProcessList = unqualifiedProcessMapper.selectByQualityResultId(result.getId()); if (CollectionUtil.isEmpty(unqualifiedProcessList)) { return Boolean.FALSE; } return (org.apache.commons.lang3.StringUtils.equals(UnqualifiedprocessStateStringValues.PROCESS_MODE_ALLOW, unqualifiedProcessList.get(0).getProcessMode()) && org.apache.commons.lang3.StringUtils.equals(unqualifiedProcessList.get(0).getState(), UnqualifiedprocessStateStringValues.EXECUTED)); } @Override public R batchUpdateApplyPart(List applyPartList, Long type) { StringBuffer tipMsg = new StringBuffer(); List arrayList = new ArrayList(); if (CollectionUtil.isNotEmpty(applyPartList)) { Report report = reportMapper.selectById(applyPartList.get(0).getReportId()); if(null != report){ if(null != report.getIsSubmit() && report.getIsSubmit()){ throw new RuntimeException("检测汇报已提交 -> 冻结该操作"); } } Set idList = applyPartList.stream().map(o -> o.getId()).collect(Collectors.toSet());//获取检测汇报零件行id if (CollectionUtil.isNotEmpty(idList)) { List newApplyPartList = baseMapper.selectList(Wrappers.lambdaQuery().in(ApplyPart::getId, idList));//通过行id查quality_apply_part if (CollectionUtil.isNotEmpty(newApplyPartList)) { //遍历newApplyPartList,判断检测结果都为null是否成立,不成立则中断修改检测结果业务(不支持反复修改检测结果) // for(int i = 0;i < newApplyPartList.size();i++){ // if(newApplyPartList.get(i).getIsQualified() != null){ // return R.failed("提交列表中存在已检测数据"); // } // } arrayList = newApplyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() == null).collect(Collectors.toList());//过滤:是erp库存,且检测结果值为null } //同步erp if (type == ONE) { //更新检测汇报明细时不进行ifs移库(统一在检测汇报提交时进行) //moveStock(newApplyPartList); } } // 成品检list List finishApplyPartList = new ArrayList<>(); applyPartList.stream().forEach(applyPart -> { if (type == ONE) { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); //若是判定为合格,则合格数量为合格数量+不合格数量,不合格数量为0 if (applyPart.getIsQualified()) { //这里根据检测结果强制更新了合格数据,如果判定结果为合格,则不合格数量必定为0 applyPart.setQtyArrived((new BigDecimal(oldApplyPart.getQtyArrived()).add(new BigDecimal(oldApplyPart.getUnqualifiedArrived()))).toString()); applyPart.setUnqualifiedArrived("0"); } applyPart.setCheckLength(new BigDecimal(applyPart.getQtyArrived()).add(new BigDecimal(applyPart.getUnqualifiedArrived()))); baseMapper.updateById(applyPart); String applyType = baseMapper.selectApplyTypeByApplyPartId(applyPart.getId()); //如果所有材料都进行了检测,将检测汇报状态改为已检测 changeCheckState(oldApplyPart);//这个方法更新的只是检测字段check_state的状态值 //1.如果是标记结果合格不合格,把检测结果状态打成已检测 changeStatus(applyPart.getSystemNo(), ResultStateStringValues.TESTED, applyPart.getIsQualified(), applyType); //1.1如果是产出报检,需要进行移库操作 //if (StringUtils.isNotBlank(applyType) && Apply.OUTPUT_APPLY.equals(applyType)) { //01output:产出尾检 if (false) { //更新检测汇报明细时不进行移库(统一在检测汇报提交时进行) // 判断一下,第一次质检才自动移库,后面修改检测结果,不进行移库 if (oldApplyPart.getIsQualified() == null) { //校验是否首检、是否合格 if (!isFirstApplyGood(applyPart.getLotBatchNo())) { tipMsg.append("系统编号:" + applyPart.getSystemNo() + " SN号:" + applyPart.getLotBatchNo() + " 首检未做或首检不合格,请确认!\r\n"); return; } // 存在工序且为最后一道工序,并且合格时,仅生成成品检验,不移库 if (null != oldApplyPart.getOperationId() && applyPart.getIsQualified() && baseMapper .isLastOperationBySystemNo(applyPart.getSystemNo())) { ApplyPartDTO partDTO = new ApplyPartDTO(); partDTO.setOutBatchNo(oldApplyPart.getLotBatchNo()); partDTO.setPartId(oldApplyPart.getPartId()); partDTO.setSystemNo(oldApplyPart.getSystemNo()); partDTO.setPartName(oldApplyPart.getPartDesc()); partDTO.setPartNo(oldApplyPart.getPartNo()); finishApplyPartList.add(partDTO); // 移库 } else { autoMoveStock(applyPart,"抛异常", false); } } // 成品检移库 //} else if (StringUtils.isNotBlank(applyType) && Apply.PRODUCT_APPLY.equals(applyType)) { } else if (false) {//更新检测汇报明细时不进行移库(统一在检测汇报提交时进行) // 判断一下,第一次质检才自动移库,后面修改检测结果,不进行移库 if (oldApplyPart.getIsQualified() == null) { autoMoveStock(applyPart,"抛异常", false); } } //1.2如果是库存报检,不需要进行移库操作 } else if (type == TWO) { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); baseMapper.updateById(applyPart); String applyType = baseMapper.selectApplyTypeByApplyPartId(applyPart.getId()); //2.如果是绑定汇报,把检测结果状态打成检测中 changeStatus(applyPart.getSystemNo(), ResultStateStringValues.TESTING, null, applyType); //新增报检后,需要将检测汇报状态改为未检测 changeCheckState(applyPart); //如果不存在汇报样品则自动创建一条汇报样品 List reportSampleList = reportSampleMapper.selectList(Wrappers.lambdaQuery().eq(ReportSample::getReportId,applyPart.getReportId())); if(CollectionUtils.isEmpty(reportSampleList)){ ReportSample reportSample = new ReportSample(); reportSample.setReportId(applyPart.getReportId()); reportSample.setSystemNo(applyPart.getSystemNo()); reportSample.setTestStandardNo(applyPart.getTestStandardNo()); reportSample.setTestStandardId(applyPart.getMoTestStandardId()); reportSample.setIsMoTestStandard(true); reportSampleList.add(reportSample); reportSampleService.saveBatchList(reportSampleList); } } else { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); baseMapper.updateById(applyPart); String applyType = baseMapper.selectApplyTypeByApplyPartId(applyPart.getId()); } }); // 生成成品检 (成品检测自动创建统一在检测汇报提交时创建) // if (!finishApplyPartList.isEmpty()) { // ApplyDTO applyDTO = new ApplyDTO(); // applyDTO.setApplyPartList(finishApplyPartList); // applyDTO.setApplyType(Apply.PRODUCT_APPLY); // applyService.saveDto(applyDTO); // } } return R.ok(arrayList, tipMsg.toString()); } @Override public R batchUpdateApplyPartV2(List applyPartList, Long type) { StringBuffer tipMsg = new StringBuffer(); List arrayList = new ArrayList(); if (CollectionUtil.isNotEmpty(applyPartList)) { Report report = reportMapper.selectById(applyPartList.get(0).getReportId()); if(null != report){ if(null != report.getIsSubmit() && report.getIsSubmit()){ throw new RuntimeException("检测汇报已提交 -> 冻结该操作"); } } Set idList = applyPartList.stream().map(o -> o.getId()).collect(Collectors.toSet());//获取检测汇报零件行id if (CollectionUtil.isNotEmpty(idList)) { List newApplyPartList = baseMapper.selectList(Wrappers.lambdaQuery().in(ApplyPart::getId, idList));//通过行id查quality_apply_part if (CollectionUtil.isNotEmpty(newApplyPartList)) { //遍历newApplyPartList,判断检测结果都为null是否成立,不成立则中断修改检测结果业务(不支持反复修改检测结果) // for(int i = 0;i < newApplyPartList.size();i++){ // if(newApplyPartList.get(i).getIsQualified() != null){ // return R.failed("提交列表中存在已检测数据"); // } // } arrayList = newApplyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() == null).collect(Collectors.toList());//过滤:是erp库存,且检测结果值为null } //同步erp if (type == ONE) { //更新检测汇报明细时不进行ifs移库(统一在检测汇报提交时进行) //moveStock(newApplyPartList); } } // 成品检list List finishApplyPartList = new ArrayList<>(); applyPartList.stream().forEach(applyPart -> { if (type == ONE) { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); //若是判定为合格,则合格数量为合格数量+不合格数量,不合格数量为0 if (oldApplyPart.getCheckLength() == null) { throw new RuntimeException("检测长度不能为空,请先保存检测数据"); } if ((applyPart.getTargetQualifiedLocationId() != null && applyPart.getTargetQualifiedLocationId().equals(oldApplyPart.getSourceLocationId())) || (applyPart.getTargetUnqualifiedLocationId() != null && applyPart.getTargetUnqualifiedLocationId().equals(oldApplyPart.getSourceLocationId()))) { throw new RuntimeException("目标库位不能与源库位相同"); } if (applyPart.getIsQualified()) { //这里根据检测结果强制更新了合格数据,如果判定结果为合格,则不合格数量必定为0 applyPart.setQtyArrived(oldApplyPart.getCheckLength().stripTrailingZeros().toPlainString()); applyPart.setUnqualifiedArrived("0"); } else { //这里根据检测结果强制更新了不合格数据,如果判定结果为不合格,则合格数量必定为0 applyPart.setQtyArrived("0"); applyPart.setUnqualifiedArrived(oldApplyPart.getCheckLength().stripTrailingZeros().toPlainString()); } baseMapper.updateById(applyPart); String applyType = baseMapper.selectApplyTypeByApplyPartId(applyPart.getId()); //如果所有材料都进行了检测,将检测汇报状态改为已检测 changeCheckState(oldApplyPart);//这个方法更新的只是检测字段check_state的状态值 //1.如果是标记结果合格不合格,把检测结果状态打成已检测 changeStatus(applyPart.getSystemNo(), ResultStateStringValues.TESTED, applyPart.getIsQualified(), applyType); //1.1如果是产出报检,需要进行移库操作 //if (StringUtils.isNotBlank(applyType) && Apply.OUTPUT_APPLY.equals(applyType)) { //01output:产出尾检 if (false) { //更新检测汇报明细时不进行移库(统一在检测汇报提交时进行) // 判断一下,第一次质检才自动移库,后面修改检测结果,不进行移库 if (oldApplyPart.getIsQualified() == null) { //校验是否首检、是否合格 if (!isFirstApplyGood(applyPart.getLotBatchNo())) { tipMsg.append("系统编号:" + applyPart.getSystemNo() + " SN号:" + applyPart.getLotBatchNo() + " 首检未做或首检不合格,请确认!\r\n"); return; } // 存在工序且为最后一道工序,并且合格时,仅生成成品检验,不移库 if (null != oldApplyPart.getOperationId() && applyPart.getIsQualified() && baseMapper .isLastOperationBySystemNo(applyPart.getSystemNo())) { ApplyPartDTO partDTO = new ApplyPartDTO(); partDTO.setOutBatchNo(oldApplyPart.getLotBatchNo()); partDTO.setPartId(oldApplyPart.getPartId()); partDTO.setSystemNo(oldApplyPart.getSystemNo()); partDTO.setPartName(oldApplyPart.getPartDesc()); partDTO.setPartNo(oldApplyPart.getPartNo()); finishApplyPartList.add(partDTO); // 移库 } else { autoMoveStock(applyPart,"抛异常", false); } } // 成品检移库 //} else if (StringUtils.isNotBlank(applyType) && Apply.PRODUCT_APPLY.equals(applyType)) { } else if (false) {//更新检测汇报明细时不进行移库(统一在检测汇报提交时进行) // 判断一下,第一次质检才自动移库,后面修改检测结果,不进行移库 if (oldApplyPart.getIsQualified() == null) { autoMoveStock(applyPart,"抛异常", false); } } //1.2如果是库存报检,不需要进行移库操作 } else if (type == TWO) { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); baseMapper.updateById(applyPart); String applyType = baseMapper.selectApplyTypeByApplyPartId(applyPart.getId()); //2.如果是绑定汇报,把检测结果状态打成检测中 changeStatus(applyPart.getSystemNo(), ResultStateStringValues.TESTING, null, applyType); //新增报检后,需要将检测汇报状态改为未检测 changeCheckState(applyPart); //如果不存在汇报样品则自动创建一条汇报样品 List reportSampleList = reportSampleMapper.selectList(Wrappers.lambdaQuery().eq(ReportSample::getReportId,applyPart.getReportId())); if(CollectionUtils.isEmpty(reportSampleList)){ ReportSample reportSample = new ReportSample(); reportSample.setReportId(applyPart.getReportId()); reportSample.setSystemNo(applyPart.getSystemNo()); reportSample.setTestStandardNo(applyPart.getTestStandardNo()); reportSample.setTestStandardId(applyPart.getMoTestStandardId()); reportSample.setIsMoTestStandard(true); reportSampleList.add(reportSample); reportSampleService.saveBatchList(reportSampleList); } } else { ApplyPart oldApplyPart = baseMapper.selectById(applyPart.getId()); if (oldApplyPart.getTotalLength() == null) { JSONObject showInfo = applyPartMapper.selectShowInfoBySystemNo(oldApplyPart.getSystemNo()); oldApplyPart.setTotalLength(showInfo.getBigDecimal("product_qty")); applyPart.setTotalLength(showInfo.getBigDecimal("product_qty")); } if (applyPart.getCheckLength() == null) { throw new RuntimeException("系统编号:" + applyPart.getSystemNo() + " SN号:" + applyPart.getLotBatchNo() + " 入库长度不能为空,请确认!"); } if (applyPart.getCheckLength().compareTo(oldApplyPart.getTotalLength()) > 0 || applyPart.getCheckLength().compareTo(BigDecimal.ZERO) < 0) { throw new RuntimeException("系统编号:" + applyPart.getSystemNo() + " SN号:" + applyPart.getLotBatchNo() + " 入库长度不能大于总长度或小于等于0,请确认!"); } if ((applyPart.getTargetQualifiedLocationId() != null && applyPart.getTargetQualifiedLocationId().equals(oldApplyPart.getSourceLocationId())) || (applyPart.getTargetUnqualifiedLocationId() != null && applyPart.getTargetUnqualifiedLocationId().equals(oldApplyPart.getSourceLocationId()))) { throw new RuntimeException("目标库位不能与源库位相同"); } applyPart.setScrapArrived(oldApplyPart.getTotalLength().subtract(applyPart.getCheckLength())); if (applyPart.getReplacePartId() == null) { baseMapper.removeReplacePart(applyPart.getId()); } else { if (StringUtils.isBlank(applyPart.getReplacePartNo()) || StringUtils.isBlank(applyPart.getReplacePartName())) { throw new RuntimeException("系统编号:" + applyPart.getSystemNo() + " SN号:" + applyPart.getLotBatchNo() + " 替换零件信息不能为空,请确认!"); } } if (oldApplyPart.getIsQualified() != null) { if (oldApplyPart.getIsQualified()) { applyPart.setQtyArrived(applyPart.getCheckLength().stripTrailingZeros().toPlainString()); applyPart.setUnqualifiedArrived("0"); } else { applyPart.setQtyArrived("0"); applyPart.setUnqualifiedArrived(applyPart.getCheckLength().stripTrailingZeros().toPlainString()); } } baseMapper.updateById(applyPart); } }); } return R.ok(arrayList, tipMsg.toString()); } /** * 根据产出系统唯一编号移库 * * @param systemNo 系统编号 * @param lotBatchNo 零件批号 * @param qtyArrived 合格数量 * @param unqualifiedArrived 不合格数量 */ private void autoMoveStock(ApplyPart applyPart,String dir,Boolean isNeedFinishApply) { //根据系统唯一编号查出零件id Long partId = baseMapper.selectPartIdBySystemNo(applyPart.getSystemNo()); if (partId == null) { //return;//这里不应该return throw new RuntimeException("移库对象零件查无零件基础数据!"); } //根据产出系统唯一编号查出对应工作站的库位 Long inspectionLocationId = workstationLocationMapper.selectBySystemNo(applyPart.getSystemNo(), WorkstationLocation.INSPECTION_LOCATION);//产出待检库位 Long disqualifiedLocationId = workstationLocationMapper.selectBySystemNo(applyPart.getSystemNo(), WorkstationLocation.DISQUALIFIED_LOCATION);//产出不合格品库位 // Long qualifiedLocationId = workstationLocationMapper.selectBySystemNo(systemNo, WorkstationLocation.QUALIFIED_LOCATION); // 如果配置了成品待检库位,则移入成品待检库 Long qualifiedLocationId = workstationLocationMapper.selectFinishToQualifiedLocationIdBySystemNo(applyPart.getSystemNo()); // 存在源库位,则取源库位 if (applyPart.getSourceLocationId() != null) { inspectionLocationId = applyPart.getSourceLocationId(); disqualifiedLocationId = applyPart.getTargetUnqualifiedLocationId() == null ? -1 : applyPart.getTargetUnqualifiedLocationId(); qualifiedLocationId = applyPart.getTargetQualifiedLocationId() == null ? -1 : applyPart.getTargetQualifiedLocationId(); } else { if (!isNeedFinishApply) { // 合格库位取工单中库位 qualifiedLocationId = workstationLocationMapper.selectQualifiedLocationIdBySystemNo(applyPart.getSystemNo());//合格品库位 } else { if (qualifiedLocationId == null) { throw new RuntimeException("成品待检库位未配置!"); } } } if (inspectionLocationId != null && disqualifiedLocationId != null && qualifiedLocationId != null) { if(dir.equals(MOVELIBRARY)){ // 待检移合格 if (new BigDecimal(applyPart.getQtyArrived()).compareTo(BigDecimal.ZERO) == 1) { // 如果有替代件,则替代件移库 if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), inspectionLocationId, qualifiedLocationId, applyPart.getReplacePartId()); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), inspectionLocationId, qualifiedLocationId); } } // 待检移不合格 if (new BigDecimal(applyPart.getUnqualifiedArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), inspectionLocationId, disqualifiedLocationId, applyPart.getReplacePartId()); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), inspectionLocationId, disqualifiedLocationId); } } // 报废库存发放 if (applyPart.getScrapArrived() != null && applyPart.getScrapArrived().compareTo(BigDecimal.ZERO) > 0) { Stock stock = stockMapper.selectOne(Wrappers.lambdaQuery().eq(Stock::getPartId, partId) .eq(Stock::getLocationId,inspectionLocationId) .eq(Stock::getPartBatchNo,applyPart.getLotBatchNo()) .eq(Stock::getSystemNo,applyPart.getSystemNo())); stockUtils.updateById(stock.getId(), applyPart.getScrapArrived().negate(), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, null, TransactionType.SCRAP.getValue()); } }else if(dir.equals(UNMOVELIBRARY)){ // 合格移待检 if (new BigDecimal(applyPart.getQtyArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(applyPart.getReplacePartId(), applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), qualifiedLocationId, inspectionLocationId, partId); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), qualifiedLocationId, inspectionLocationId); } } // 不合格移待检 if (new BigDecimal(applyPart.getUnqualifiedArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(applyPart.getReplacePartId(), applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), disqualifiedLocationId, inspectionLocationId, partId); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), disqualifiedLocationId, inspectionLocationId); } } // 报废库存撤回 if (applyPart.getScrapArrived() != null && applyPart.getScrapArrived().compareTo(BigDecimal.ZERO) > 0) { Stock stock = stockMapper.selectOne(Wrappers.lambdaQuery().eq(Stock::getPartId, partId) .eq(Stock::getLocationId,inspectionLocationId) .eq(Stock::getPartBatchNo,applyPart.getLotBatchNo()) .eq(Stock::getSystemNo,applyPart.getSystemNo())); stockUtils.updateById(stock.getId(), applyPart.getScrapArrived() , BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, null, TransactionType.CANCEL_SCRAP.getValue()); } }else{ throw new RuntimeException("移库方向码异常!异常码--" + dir); } }else{ throw new RuntimeException("移库库位信息获取不全->产出待检库位id=" + inspectionLocationId + "->产出不合格品库位id=" + disqualifiedLocationId + "->产出合格库位id=" + qualifiedLocationId); } } private void autoMoveStockV2(ApplyPart applyPart,String dir,Boolean isNeedFinishApply) { //根据系统唯一编号查出零件id Long partId = applyPart.getPartId(); if (partId == null) { //return;//这里不应该return throw new RuntimeException("移库对象零件查无零件基础数据!"); } //根据产出系统唯一编号查出对应工作站的库位 Long inspectionLocationId = workstationLocationMapper.selectBySystemNo(applyPart.getSystemNo(), WorkstationLocation.INSPECTION_LOCATION);//产出待检库位 Long disqualifiedLocationId = workstationLocationMapper.selectBySystemNo(applyPart.getSystemNo(), WorkstationLocation.DISQUALIFIED_LOCATION);//产出不合格品库位 // Long qualifiedLocationId = workstationLocationMapper.selectBySystemNo(systemNo, WorkstationLocation.QUALIFIED_LOCATION); // 如果配置了成品待检库位,则移入成品待检库 Long qualifiedLocationId = workstationLocationMapper.selectFinishToQualifiedLocationIdBySystemNo(applyPart.getSystemNo()); // 存在源库位,则取源库位 if (applyPart.getSourceLocationId() != null) { inspectionLocationId = applyPart.getSourceLocationId(); disqualifiedLocationId = applyPart.getTargetUnqualifiedLocationId() == null ? -1 : applyPart.getTargetUnqualifiedLocationId(); qualifiedLocationId = applyPart.getTargetQualifiedLocationId() == null ? -1 : applyPart.getTargetQualifiedLocationId(); } else { if (!isNeedFinishApply) { // 合格库位取工单中库位 qualifiedLocationId = workstationLocationMapper.selectQualifiedLocationIdBySystemNo(applyPart.getSystemNo());//合格品库位 } else { if (qualifiedLocationId == null) { throw new RuntimeException("成品待检库位未配置!"); } } } if (inspectionLocationId != null && disqualifiedLocationId != null && qualifiedLocationId != null) { if(dir.equals(MOVELIBRARY)){ // 待检移合格 if (new BigDecimal(applyPart.getQtyArrived()).compareTo(BigDecimal.ZERO) == 1) { // 如果有替代件,则替代件移库 if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), inspectionLocationId, qualifiedLocationId, applyPart.getReplacePartId()); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), inspectionLocationId, qualifiedLocationId); } } // 待检移不合格 if (new BigDecimal(applyPart.getUnqualifiedArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), inspectionLocationId, disqualifiedLocationId, applyPart.getReplacePartId()); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), inspectionLocationId, disqualifiedLocationId); } } // 报废库存发放 if (applyPart.getScrapArrived() != null && applyPart.getScrapArrived().compareTo(BigDecimal.ZERO) > 0) { Stock stock = stockMapper.selectOne(Wrappers.lambdaQuery().eq(Stock::getPartId, partId) .eq(Stock::getLocationId,inspectionLocationId) .eq(Stock::getPartBatchNo,applyPart.getLotBatchNo()) .eq(Stock::getSystemNo,applyPart.getSystemNo())); stockUtils.updateById(stock.getId(), applyPart.getScrapArrived().negate(), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, null, TransactionType.SCRAP.getValue()); } }else if(dir.equals(UNMOVELIBRARY)){ // 合格移待检 if (new BigDecimal(applyPart.getQtyArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(applyPart.getReplacePartId(), applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), qualifiedLocationId, inspectionLocationId, partId); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getQtyArrived()), qualifiedLocationId, inspectionLocationId); } } // 不合格移待检 if (new BigDecimal(applyPart.getUnqualifiedArrived()).compareTo(BigDecimal.ZERO) == 1) { if (applyPart.getReplacePartId() != null) { stockUtils.replaceMove(applyPart.getReplacePartId(), applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), disqualifiedLocationId, inspectionLocationId, partId); } else { stockUtils.localMove(partId, applyPart.getSystemNo(), applyPart.getLotBatchNo(), new BigDecimal(applyPart.getUnqualifiedArrived()), disqualifiedLocationId, inspectionLocationId); } } // 报废库存撤回 if (applyPart.getScrapArrived() != null && applyPart.getScrapArrived().compareTo(BigDecimal.ZERO) > 0) { Stock stock = stockMapper.selectOne(Wrappers.lambdaQuery().eq(Stock::getPartId, partId) .eq(Stock::getLocationId,inspectionLocationId) .eq(Stock::getPartBatchNo,applyPart.getLotBatchNo()) .eq(Stock::getSystemNo,applyPart.getSystemNo())); stockUtils.updateById(stock.getId(), applyPart.getScrapArrived() , BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, null, TransactionType.CANCEL_SCRAP.getValue()); } }else{ throw new RuntimeException("移库方向码异常!异常码--" + dir); } }else{ throw new RuntimeException("移库库位信息获取不全->产出待检库位id=" + inspectionLocationId + "->产出不合格品库位id=" + disqualifiedLocationId + "->产出合格库位id=" + qualifiedLocationId); } } public void moveStock(List applyPartList) { List newStockList = new ArrayList<>(); if (CollectionUtil.isNotEmpty(applyPartList)) { //这里再过滤一遍,把是ifs的且没有检测的筛选出来 Set newIdList = applyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() == null).map(o -> o.getId()).collect(Collectors.toSet()); if (CollectionUtil.isNotEmpty(newIdList)) { newStockList = baseMapper.selectRegistrationApplyPart(newIdList, remoteParamService.getByKey("QUALIFIED_LIBRARY", SecurityConstants.FROM_IN).getData()); //登记检验结果 registrationResult(newStockList);//这个是原材料检测,暂时不做 } } } /** * erp登记检验结果 */ public void registrationResult(List stockList) { String one = "1"; String data = "data"; String type = "operationType"; JSONObject inAttr = new JSONObject(); String s = UUID.randomUUID().toString(); inAttr.put("recordId", s); inAttr.put("syscode", SYSTEM); inAttr.put("sysmodel", NEW_SYSTEM_NAME); inAttr.put("batchInfo", stockList); JSONObject stockMap = new JSONObject(); stockMap.put("contract", stockBean.getRegion()); try { System.out.println(stockBean.getSecretKey()); System.out.println(stockBean.getCleartextSecretKey()); if (StringUtils.isNotBlank(stockBean.getSecretKey())) { stockMap.put("contractKey", stockBean.getSecretKey()); } else if (StringUtils.isNotBlank(stockBean.getCleartextSecretKey())) { stockMap.put("contractKey", AesUtils.encrypt(stockBean.getCleartextSecretKey())); } } catch (Exception e) { throw new RuntimeException("明文密钥加密失败"); } stockMap.put("userId", SecurityUtils.getUser().getUsername()); stockMap.put("inAttr", inAttr); String result = HttpRequest.post(stockBean.getRegistrationResultIp()).body(JSONObject.toJSONString(stockMap)).execute().body(); JSONObject jsonObject = JSONObject.parseObject(result); if (!one.equals(jsonObject.getJSONObject(data).getString(type))) { throw new RuntimeException(jsonObject.getString("msg")); } } /** * 同步erp库存 */ public void synchronizationErp(List stockList) { String one = "1"; String data = "data"; String type = "operationType"; JSONObject inAttr = new JSONObject(); String s = UUID.randomUUID().toString(); inAttr.put("recordId", s); inAttr.put("syscode", SYSTEM); inAttr.put("sysmodel", SYSTEM_NAME); inAttr.put("batchInfo", stockList); JSONObject stockMap = new JSONObject(); stockMap.put("contract", stockBean.getRegion()); try { System.out.println(stockBean.getSecretKey()); System.out.println(stockBean.getCleartextSecretKey()); if (StringUtils.isNotBlank(stockBean.getSecretKey())) { stockMap.put("contractKey", stockBean.getSecretKey()); } else if (StringUtils.isNotBlank(stockBean.getCleartextSecretKey())) { stockMap.put("contractKey", AesUtils.encrypt(stockBean.getCleartextSecretKey())); } } catch (Exception e) { throw new RuntimeException("明文密钥加密失败"); } stockMap.put("userId", SecurityUtils.getUser().getUsername()); stockMap.put("inAttr", inAttr); System.out.println(stockMap); String result = HttpRequest.post(stockBean.getMoveStockIp()).body(JSONObject.toJSONString(stockMap)).execute().body(); JSONObject jsonObject = JSONObject.parseObject(result); if (!one.equals(jsonObject.getJSONObject(data).getString(type))) { throw new RuntimeException(jsonObject.getString("msg")); } } @Override public void changeStatus(String systemNo, String checkStatus, Boolean isQualified, String applyType) { Result result = resultMapper.selectOne(Wrappers.query().lambda().eq(Result::getSystemNo, systemNo) .eq(Result::getApplyType, applyType).eq(Result::getIsErp, false)); if (result != null) { //if (isQualified != null) { result.setIsQualified(isQualified); result.setIsUsed(isQualified); //} result.setCheckStatus(checkStatus); resultMapper.updateById(result); } } /** * 如果所有材料都进行了检测,将检测汇报状态改为已检测,否则为未检测 * * @param applyPart */ @Override public void changeCheckState(ApplyPart applyPart) { Report report = reportService.getById(applyPart.getReportId()); List applyParts = baseMapper.selectList(Wrappers.lambdaQuery().eq(ApplyPart::getReportId , applyPart.getReportId())); Report update = new Report(); update.setId(report.getId()); update.setReportNo(report.getReportNo()); update.setCheckTime(LocalDateTime.now()); if (!applyParts.isEmpty() && applyParts.stream().allMatch(p -> p.getIsQualified() != null)) { if (report.getCheckState() == null || report.getCheckState().equals(Report.CHECK_STATE_UNCHECK)) { update.setCheckState(Report.CHECK_STATE_CHECKED); reportService.updateById(update); } } else { if (report.getCheckState() != null && report.getCheckState().equals(Report.CHECK_STATE_CHECKED)) { update.setCheckState(Report.CHECK_STATE_UNCHECK); reportService.updateById(update); } } } /** * 移库 * @param reportId 检测汇报id * @param dir 操作方向,mv移库;unmv:取消移库 */ @Override public boolean moveLibrary(Long reportId,String dir){ // 是否需要成品检处理 boolean isNeedFinishApply = false; Report report = reportMapper.selectById(reportId); List applyPartList = applyPartMapper.selectListByReportId(reportId);//通过检测汇报id获取检测汇报材料明细 List applyPartList_ifs = new ArrayList<>();//ifs库存件报检 List applyPartList_mes = new ArrayList<>();//mes产出报检 if(CollectionUtil.isNotEmpty(applyPartList)){ //将集合进行数据源的分离:mes的产出报检、ifs的库存件报检 applyPartList_ifs = applyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() != null).collect(Collectors.toList());//ifs库存件报检数据(这里的is_erp字段代表的应该是ifs的原材料报检,原材料报检暂时不上) applyPartList_mes = applyPartList.stream().filter(o -> !o.getIsErp() && o.getIsQualified() != null).collect(Collectors.toList());//mes产出报检数据 } if(CollectionUtil.isNotEmpty(applyPartList_ifs)){ //对接ifs移库 if(false){//暂时不开放ifs原材料在mes中报检 moveLibrary_ifs(applyPartList_ifs,report.getReportNo(),report.getReportType(),dir); } } if(CollectionUtil.isNotEmpty(applyPartList_mes)){ //mes移库 isNeedFinishApply = moveLibrary_mes(applyPartList_mes, report.getReportType(), dir); } return isNeedFinishApply; } @Override public boolean moveLibraryV2(Long reportId, String dir) { // 是否需要成品检处理 boolean isNeedFinishApply = false; Report report = reportMapper.selectById(reportId); List applyPartList = applyPartMapper.selectListByReportId(reportId);//通过检测汇报id获取检测汇报材料明细 List applyPartList_ifs = new ArrayList<>();//ifs库存件报检 List applyPartList_mes = new ArrayList<>();//mes产出报检 if(CollectionUtil.isNotEmpty(applyPartList)){ //将集合进行数据源的分离:mes的产出报检、ifs的库存件报检 applyPartList_ifs = applyPartList.stream().filter(o -> o.getIsErp() && o.getIsQualified() != null).collect(Collectors.toList());//ifs库存件报检数据(这里的is_erp字段代表的应该是ifs的原材料报检,原材料报检暂时不上) applyPartList_mes = applyPartList.stream().filter(o -> !o.getIsErp() && o.getIsQualified() != null).collect(Collectors.toList());//mes产出报检数据 } if(CollectionUtil.isNotEmpty(applyPartList_ifs)){ //对接ifs移库 if(false){//暂时不开放ifs原材料在mes中报检 moveLibrary_ifs(applyPartList_ifs,report.getReportNo(),report.getReportType(),dir); } } if(CollectionUtil.isNotEmpty(applyPartList_mes)){ //mes移库 isNeedFinishApply = moveLibrary_mes_v2(applyPartList_mes, report.getReportType(), dir); } return isNeedFinishApply; } /** * ifs移库 * @param applyPartList * @param reportNo 检测汇报编号 */ public void moveLibrary_ifs(List applyPartList,String reportNo,String reportType,String dir){ if(StringUtils.isBlank(reportType)){ throw new RuntimeException("检测汇报类型为空!操作已中断!"); } //拼接inAttr //对接库存件移库 IfsMoveLibraryDTO ifsMoveLibraryDTO = new IfsMoveLibraryDTO(); ifsMoveLibraryDTO.setRECORD_ID(reportNo); List dataBeanList = new ArrayList<>();//批量标识 for(int i = 0;i < applyPartList.size();i++){ if(baseMapper.isLastOperationBySystemNo(applyPartList.get(i).getSystemNo()) && !reportType.equals(Apply.PRODUCT_APPLY)){ continue;//是最后一道工序,且不是成品检,则跳过 } List operationStockStatus = applyPartMapper.selectStockOperationStatus(applyPartList.get(0).getSystemNo()); // 如果是工序库存,不进行IFS移库 if (CollectionUtil.isNotEmpty(operationStockStatus) && BooleanUtil.isTrue(operationStockStatus.get(0))) { continue; } SubmitReportDTO submitReportDTO = reportMapper.getManufacturingOrderInfo(applyPartList.get(i).getId()); double qty_qualified = Double.parseDouble(applyPartList.get(i).getQtyArrived());//合格数量 double qty_unqualified = Double.parseDouble(applyPartList.get(i).getUnqualifiedArrived());//不合格数量 BigDecimal big_qualified = BigDecimal.valueOf(qty_qualified);//合格数量转换数据类型 BigDecimal big_unqualified = BigDecimal.valueOf(qty_unqualified);//不合格数量转换数据类型 if(big_qualified.compareTo(BigDecimal.ZERO) == 1){ //合格数量大于0 IfsMoveLibraryDTO.DataBean batchInfo = new IfsMoveLibraryDTO.DataBean(); batchInfo.setPART_NO(applyPartList.get(i).getPartNo());//零件号 batchInfo.setLOT_BATCH_NO(applyPartList.get(i).getLotBatchNo());//批次号 batchInfo.setMOVE_QTY(Double.parseDouble(applyPartList.get(i).getQtyArrived()));//合格数量 //------------------------------------------------------------------------------------------------------序列号、版本号、wdr号、ifs原库位号,从ifs库存件获取数据时存储在quality_apply_part表中 batchInfo.setSERIAL_NO(applyPartList.get(i).getSerialNo());//序列号 batchInfo.setENG_CHG_LEVEL(applyPartList.get(i).getEngChgLevel());//版本号 batchInfo.setWAIV_DEV_REJ_NO(applyPartList.get(i).getWaivDevRejNo());//wdr号 if(dir.equals(MOVELIBRARY)){ //移库 batchInfo.setLOCATION_NO(applyPartList.get(i).getLocationNo());//ifs原库位号 batchInfo.setTO_LOCATION_NO(reportMapper.getIfsLocationArrivedByWorkstationId(submitReportDTO.getWorkstationId(),WorkstationLocation.QUALIFIED_LOCATION));//获取IFS产出合格库位 }else if(dir.equals(UNMOVELIBRARY)){ //取消移库 batchInfo.setTO_LOCATION_NO(applyPartList.get(i).getLocationNo());//ifs原库位号 batchInfo.setLOCATION_NO(reportMapper.getIfsLocationArrivedByWorkstationId(submitReportDTO.getWorkstationId(),WorkstationLocation.QUALIFIED_LOCATION));//获取IFS产出合格库位 }else{ throw new RuntimeException("移库方向码异常!"); } batchInfo.setTO_CONTRACT(stockBean.getRegion());//目标域 // 因为现在多个 mes库位可能对应一个 ifs库位 所以 执行移库操作之前需要判断一下库位是否相同 // xcg 20230413 if (!StrUtil.equals(batchInfo.getLOCATION_NO(), batchInfo.getTO_LOCATION_NO())) { dataBeanList.add(batchInfo); } } if(big_unqualified.compareTo(BigDecimal.ZERO) == 1){ //不合格数量大于0 IfsMoveLibraryDTO.DataBean batchInfo = new IfsMoveLibraryDTO.DataBean(); batchInfo.setPART_NO(applyPartList.get(i).getPartNo());//零件号 batchInfo.setLOT_BATCH_NO(applyPartList.get(i).getLotBatchNo());//批次号 batchInfo.setMOVE_QTY(Double.parseDouble(applyPartList.get(i).getUnqualifiedArrived()));//不合格数量 //------------------------------------------------------------------------------------------------------序列号、版本号、wdr号、ifs原库位号,从ifs库存件获取数据时存储在quality_apply_part表中 batchInfo.setSERIAL_NO(applyPartList.get(i).getSerialNo());//序列号 batchInfo.setENG_CHG_LEVEL(applyPartList.get(i).getEngChgLevel());//版本号 batchInfo.setWAIV_DEV_REJ_NO(applyPartList.get(i).getWaivDevRejNo());//wdr号 if(dir.equals(MOVELIBRARY)){ batchInfo.setLOCATION_NO(applyPartList.get(i).getLocationNo());//ifs原库位号 batchInfo.setTO_LOCATION_NO(reportMapper.getIfsLocationArrivedByWorkstationId(submitReportDTO.getWorkstationId(),WorkstationLocation.DISQUALIFIED_LOCATION));//获取IFS产出不合格库位 }else if(dir.equals(UNMOVELIBRARY)){ batchInfo.setTO_LOCATION_NO(applyPartList.get(i).getLocationNo());//ifs原库位号 batchInfo.setLOCATION_NO(reportMapper.getIfsLocationArrivedByWorkstationId(submitReportDTO.getWorkstationId(),WorkstationLocation.DISQUALIFIED_LOCATION));//获取IFS产出不合格库位 }else{ throw new RuntimeException("移库方向码异常!异常码--" + dir); } batchInfo.setTO_CONTRACT(stockBean.getRegion());//目标域 // 因为现在多个 mes库位可能对应一个 ifs库位 所以 执行移库操作之前需要判断一下库位是否相同 // xcg 20230413 if (!StrUtil.equals(batchInfo.getLOCATION_NO(), batchInfo.getTO_LOCATION_NO())) { dataBeanList.add(batchInfo); } } } if (CollectionUtil.isEmpty(dataBeanList)) { return; } ifsMoveLibraryDTO.setBATCH_INFO(dataBeanList); Gson gson = new Gson(); String jsonstr = gson.toJson(ifsMoveLibraryDTO); JSONObject jsonObject = JSONObject.parseObject(jsonstr);//解决序列化时自动将大写转小写问题 R res = ifsFeignClient.importMovePartStd(jsonObject,true); if(res.getCode() != 0){ throw new RuntimeException("ifs库存件移库失败;erromsg:" + res.getMsg()); } } /** * mes移库 * @param applyPartList */ public boolean moveLibrary_mes(List applyPartList,String reportType,String dir){ //检测汇报类型为空则中断程序 if(StringUtils.isBlank(reportType)){ throw new RuntimeException("检测汇报类型为空!操作已中断!"); } List finishApplyPartList = new ArrayList<>();//成品检list // 是否需要成品检处理 boolean isNeedFinishApply = false; //不满足已首检&&首检状态为合格,则中断程序 for(ApplyPart applyPart_cursor:applyPartList){ //存在首检,且首检结果为合格(整改优化:汇报类型为尾检时才去判断是否存在首检) if(reportType.equals(Apply.OUTPUT_APPLY)){ if(!isFirstApplyGood(applyPart_cursor.getLotBatchNo())){ throw new RuntimeException("系统编号--" + applyPart_cursor.getSystemNo() + "|SN号--" + applyPart_cursor.getLotBatchNo() + "--首检未做或首检不合格!操作已中断!"); } } //批次首检不参与移库&&自动创建成品检 // if(!reportType.equals(Apply.BATCHFIRST_APPLY)){ //若工序为最后一道工序&&检测结果为合格&&汇报类型不是成品检,则自动生成成品检(该规则作废) //若工序为最后一道工序&&检测结果为合格&&汇报类型是非批次首检,则自动生成成品检(该规则作废) //(若工序为尾检或者工序检)&&检测结果为合格 //if((reportType.equals(Apply.OUTPUT_APPLY) || reportType.equals(Apply.PROCESS_APPLY)) && applyPart_cursor.getOperationId() != null && applyPart_cursor.getIsQualified() && baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ if((reportType.equals(Apply.OUTPUT_APPLY) || reportType.equals(Apply.PROCESS_APPLY)) && applyPart_cursor.getOperationId() != null && applyPart_cursor.getIsQualified()){ if(dir.equals(MOVELIBRARY)){ //判断检测申请规则是否配置了成品检 String ruleApply = remoteParamService.getByKey(Apply.RULE_APPLY, SecurityConstants.FROM_IN).getData(); ApplyPartDTO applyPartDTO = new ApplyPartDTO(); applyPartDTO.setOutBatchNo(applyPart_cursor.getLotBatchNo()); applyPartDTO.setPartId(applyPart_cursor.getPartId()); applyPartDTO.setSystemNo(applyPart_cursor.getSystemNo()); applyPartDTO.setPartName(applyPart_cursor.getPartDesc()); applyPartDTO.setPartNo(applyPart_cursor.getPartNo()); if(ruleApply.equals("true") && baseMapper.isExistTestApplyConfigBySystemNo(applyPart_cursor.getSystemNo())){ //存在成品检检测申请配置 if(baseMapper.isConfigFinishedProdTest(applyPart_cursor.getSystemNo())){ //校验一下配置规则 (2023-02-24 配置规则不再使用,从车间订单配置中获取) // String operationNo = baseMapper.selectOperationNoBySystemNo(applyPart_cursor.getSystemNo());//根据产出系统编号获取工序编号 testApplyRuleUtils.applyRulesCheckBySystemNo(applyPart_cursor.getSystemNo()); finishApplyPartList.add(applyPartDTO); isNeedFinishApply = true; } } // 2023-02-23 只有配置成品检才会自动创建成品检 // else{ // //不存在检测申请配置,走原来的路径,判断是否是最后一道工序 // if(baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ // finishApplyPartList.add(applyPartDTO); // } // } }else if(dir.equals(UNMOVELIBRARY)){ //如果不是成品检测,才需要去校验是否存在成品检 if(!reportType.equals(Apply.PRODUCT_APPLY)){ String reportNo = baseMapper.getFinishedProductReportNo(applyPart_cursor.getSystemNo()); if(!StringUtils.isBlank(reportNo)){ throw new RuntimeException("请先删除成品检检测汇报!汇报编号--" + reportNo); } isNeedFinishApply = baseMapper.isExistFinishedApplyPart(applyPart_cursor.getSystemNo()); } } } //是成品检测,则mes移库;或者非成品检且产出非最后一道工序,则移库(该规则作废) //if(reportType.equals(Apply.PRODUCT_APPLY) || !baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ if(!reportType.equals(Apply.PRODUCT_APPLY)){ //非成品检的移库 autoMoveStock(applyPart_cursor, dir, isNeedFinishApply); }else{ //成品检的移库(单独处理) String ruleApply = remoteParamService.getByKey(Apply.RULE_APPLY, SecurityConstants.FROM_IN).getData(); if(false && ruleApply.equals("true")){//成品检必定要经过过程检测 //如果没有尾检及工序检,则成品检也走上面的路径(待检移合格或不合格) if(baseMapper.isConfigMoveLibraryTest(applyPart_cursor.getSystemNo())){ reportUtils.autoMoveStockFinishedProductV2(applyPart_cursor,dir); }else{ autoMoveStock(applyPart_cursor, dir,false); } }else{ reportUtils.autoMoveStockFinishedProductV2(applyPart_cursor,dir); } } // } } //创建成品检 if (!finishApplyPartList.isEmpty()) { ApplyDTO applyDTO = new ApplyDTO(); applyDTO.setApplyPartList(finishApplyPartList); applyDTO.setApplyType(Apply.PRODUCT_APPLY); applyDTO.setFinishedProductAutoInsp(true);//很关键,标记为系统规则自动触发 applyService.saveDto(applyDTO); } return isNeedFinishApply; } private boolean moveLibrary_mes_v2(List applyPartList,String reportType,String dir) { //检测汇报类型为空则中断程序 if(StringUtils.isBlank(reportType)){ throw new RuntimeException("检测汇报类型为空!操作已中断!"); } List finishApplyPartList = new ArrayList<>();//成品检list // 是否需要成品检处理 boolean isNeedFinishApply = false; //不满足已首检&&首检状态为合格,则中断程序 for(ApplyPart applyPart_cursor:applyPartList){ //存在首检,且首检结果为合格(整改优化:汇报类型为尾检时才去判断是否存在首检) if(reportType.equals(Apply.OUTPUT_APPLY)){ if(!isFirstApplyGood(applyPart_cursor.getLotBatchNo())){ throw new RuntimeException("系统编号--" + applyPart_cursor.getSystemNo() + "|SN号--" + applyPart_cursor.getLotBatchNo() + "--首检未做或首检不合格!操作已中断!"); } } //批次首检不参与移库&&自动创建成品检 // if(!reportType.equals(Apply.BATCHFIRST_APPLY)){ //若工序为最后一道工序&&检测结果为合格&&汇报类型不是成品检,则自动生成成品检(该规则作废) //若工序为最后一道工序&&检测结果为合格&&汇报类型是非批次首检,则自动生成成品检(该规则作废) //(若工序为尾检或者工序检)&&检测结果为合格 //if((reportType.equals(Apply.OUTPUT_APPLY) || reportType.equals(Apply.PROCESS_APPLY)) && applyPart_cursor.getOperationId() != null && applyPart_cursor.getIsQualified() && baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ if((reportType.equals(Apply.OUTPUT_APPLY) || reportType.equals(Apply.PROCESS_APPLY)) && applyPart_cursor.getOperationId() != null && applyPart_cursor.getIsQualified()){ if(dir.equals(MOVELIBRARY)){ //判断检测申请规则是否配置了成品检 String ruleApply = remoteParamService.getByKey(Apply.RULE_APPLY, SecurityConstants.FROM_IN).getData(); ApplyPartDTO applyPartDTO = new ApplyPartDTO(); applyPartDTO.setOutBatchNo(applyPart_cursor.getLotBatchNo()); applyPartDTO.setPartId(applyPart_cursor.getReplacePartId() == null ? applyPart_cursor.getPartId() : applyPart_cursor.getReplacePartId()); applyPartDTO.setSystemNo(applyPart_cursor.getSystemNo()); applyPartDTO.setPartName(applyPart_cursor.getReplacePartId() == null ? applyPart_cursor.getPartDesc() : applyPart_cursor.getReplacePartName()); applyPartDTO.setPartNo(applyPart_cursor.getReplacePartId() == null ? applyPart_cursor.getPartNo() : applyPart_cursor.getReplacePartNo()); applyPartDTO.setCheckLength(applyPart_cursor.getCheckLength()); if(ruleApply.equals("true") && baseMapper.isExistTestApplyConfigBySystemNo(applyPart_cursor.getSystemNo())){ //存在成品检检测申请配置 if(baseMapper.isConfigFinishedProdTest(applyPart_cursor.getSystemNo())){ //校验一下配置规则 (2023-02-24 配置规则不再使用,从车间订单配置中获取) // String operationNo = baseMapper.selectOperationNoBySystemNo(applyPart_cursor.getSystemNo());//根据产出系统编号获取工序编号 testApplyRuleUtils.applyRulesCheckBySystemNo(applyPart_cursor.getSystemNo()); if (applyPart_cursor.getCheckLength().compareTo(BigDecimal.ZERO) > 0) { finishApplyPartList.add(applyPartDTO); isNeedFinishApply = true; } } } // 2023-02-23 只有配置成品检才会自动创建成品检 // else{ // //不存在检测申请配置,走原来的路径,判断是否是最后一道工序 // if(baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ // finishApplyPartList.add(applyPartDTO); // } // } } else if(dir.equals(UNMOVELIBRARY)) { //如果不是成品检测,才需要去校验是否存在成品检 if(!reportType.equals(Apply.PRODUCT_APPLY)){ String reportNo = baseMapper.getFinishedProductReportNo(applyPart_cursor.getSystemNo()); if(!StringUtils.isBlank(reportNo)){ throw new RuntimeException("请先删除成品检检测汇报!汇报编号--" + reportNo); } isNeedFinishApply = baseMapper.isExistFinishedApplyPart(applyPart_cursor.getSystemNo()); } } } //是成品检测,则mes移库;或者非成品检且产出非最后一道工序,则移库(该规则作废) //if(reportType.equals(Apply.PRODUCT_APPLY) || !baseMapper.isLastOperationBySystemNo(applyPart_cursor.getSystemNo())){ if(!reportType.equals(Apply.PRODUCT_APPLY)){ //非成品检的移库 autoMoveStockV2(applyPart_cursor, dir, isNeedFinishApply); }else{ //成品检的移库(单独处理) String ruleApply = remoteParamService.getByKey(Apply.RULE_APPLY, SecurityConstants.FROM_IN).getData(); if(false && ruleApply.equals("true")){//成品检必定要经过过程检测 //如果没有尾检及工序检,则成品检也走上面的路径(待检移合格或不合格) if(baseMapper.isConfigMoveLibraryTest(applyPart_cursor.getSystemNo())){ reportUtils.autoMoveStockFinishedProductV2(applyPart_cursor,dir); }else{ autoMoveStock(applyPart_cursor, dir,false); } }else{ reportUtils.autoMoveStockFinishedProductV2(applyPart_cursor,dir); } } // } } //创建成品检 if (!finishApplyPartList.isEmpty()) { ApplyDTO applyDTO = new ApplyDTO(); applyDTO.setApplyPartList(finishApplyPartList); applyDTO.setApplyType(Apply.PRODUCT_APPLY); applyDTO.setFinishedProductAutoInsp(true);//很关键,标记为系统规则自动触发 applyService.saveDto(applyDTO); } return isNeedFinishApply; } /** * 质检合格率统计报表 * @param qualityCheckRateInputDTO */ public IPage getQualityCheckRate(Page page, QualityCheckRateInputDTO qualityCheckRateInputDTO){ return baseMapper.getQualityCheckRate(page,qualityCheckRateInputDTO); } /** * 质检合格率统计柱状图 * @param qualityCheckRateInputDTO */ public List getQualityCheckRatePicture(QualityCheckRateInputDTO qualityCheckRateInputDTO){ return baseMapper.getQualityCheckRatePicture(qualityCheckRateInputDTO); } @Override public IPage getTestApplyPage(Page page, QueryWrapper gen, Integer queryType) { return this.baseMapper.getTestApplyPage(page, gen, queryType); } }