| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.common.AsyncQueryExecutor; |
| | | import com.example.erp.dto.pp.PatchLogAddDTO; |
| | | import com.example.erp.dto.pp.PatchLogDTO; |
| | | import com.example.erp.dto.pp.exportReplenishDTO; |
| | | import com.example.erp.dto.sd.OrderDTO; |
| | | import com.example.erp.entity.pp.FlowCard; |
| | | import com.example.erp.entity.pp.PatchLog; |
| | | import com.example.erp.entity.pp.ReportingWork; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import javax.annotation.PreDestroy; |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | |
| | | |
| | | @Service |
| | |
| | | |
| | | final LogService logService; |
| | | |
| | | //多线程池 |
| | | @Resource |
| | | private AsyncQueryExecutor asyncExecutor; |
| | | |
| | | public ReplenishService(PatchLogMapper patchMapper, SysErrorService sysErrorService, ReportingWorkMapper reportingWorkMapper,FlowCardMapper flowCardMapper,LogService logService) { |
| | | this.patchMapper = patchMapper; |
| | | this.sysErrorService = sysErrorService; |
| | |
| | | |
| | | } |
| | | |
| | | public Map<String, Object> SelectReplenish(Integer pageNum, Integer pageSize, List<String> selectDate, PatchLogDTO patchLogDTO) { |
| | | Integer offset = (pageNum-1)*pageSize; |
| | | // public Map<String, Object> SelectReplenish(Integer pageNum, Integer pageSize, List<String> selectDate, PatchLogDTO patchLogDTO) { |
| | | // Integer offset = (pageNum-1)*pageSize; |
| | | // String endDate = LocalDate.now().toString(); |
| | | // String startDate = LocalDate.now().minusDays(15).toString(); |
| | | // if(selectDate !=null && selectDate.size()==2){ |
| | | // if(!selectDate.get(0).isEmpty()){ |
| | | // startDate = selectDate.get(0); |
| | | // } |
| | | // if(!selectDate.get(1).isEmpty()){ |
| | | // endDate = selectDate.get(1); |
| | | // } |
| | | // } |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("data",patchMapper.SelectReplenish(offset,pageSize,startDate,endDate,patchLogDTO)); |
| | | // map.put("total",patchMapper.SelectReplenishPageTotal(offset,pageSize,startDate,endDate,patchLogDTO)); |
| | | // |
| | | // List<String> list = new ArrayList<>(); |
| | | // list.add(startDate); |
| | | // list.add(endDate); |
| | | // map.put("selectDate",list); |
| | | // return map; |
| | | // } |
| | | |
| | | public Map<String, Object> SelectReplenish( |
| | | Integer pageNum, Integer pageSize, |
| | | List<String> selectDate, PatchLogDTO patchLogDTO) { |
| | | |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | |
| | | // 默认时间范围:过去15天 |
| | | String endDate = LocalDate.now().toString(); |
| | | String startDate = LocalDate.now().minusDays(15).toString(); |
| | | if(selectDate !=null && selectDate.size()==2){ |
| | | if(!selectDate.get(0).isEmpty()){ |
| | | |
| | | // 用户自定义时间段 |
| | | if (selectDate != null && selectDate.size() == 2) { |
| | | if (!selectDate.get(0).isEmpty()) { |
| | | startDate = selectDate.get(0); |
| | | } |
| | | if(!selectDate.get(1).isEmpty()){ |
| | | if (!selectDate.get(1).isEmpty()) { |
| | | endDate = selectDate.get(1); |
| | | } |
| | | } |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("data",patchMapper.SelectReplenish(offset,pageSize,startDate,endDate,patchLogDTO)); |
| | | map.put("total",patchMapper.SelectReplenishPageTotal(offset,pageSize,startDate,endDate,patchLogDTO)); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(startDate); |
| | | list.add(endDate); |
| | | map.put("selectDate",list); |
| | | return map; |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | | try { |
| | | // 使用线程池并行执行两个SQL |
| | | String finalStartDate = startDate; |
| | | String finalEndDate = endDate; |
| | | CompletableFuture<List<PatchLogDTO>> dataFuture = |
| | | asyncExecutor.runAsync(() -> |
| | | patchMapper.SelectReplenish(offset, pageSize, finalStartDate, finalEndDate, patchLogDTO)); |
| | | |
| | | CompletableFuture<Map<String, Integer>> totalFuture = |
| | | asyncExecutor.runAsync(() -> |
| | | patchMapper.SelectReplenishPageTotal(offset, pageSize, finalStartDate, finalEndDate, patchLogDTO)); |
| | | |
| | | // 等待两个任务都完成 |
| | | CompletableFuture.allOf(dataFuture, totalFuture).join(); |
| | | |
| | | result.put("data", dataFuture.get()); |
| | | result.put("total", totalFuture.get()); |
| | | |
| | | // 返回时间段 |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(startDate); |
| | | list.add(endDate); |
| | | result.put("selectDate", list); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("并行查询补片记录异常:" + e.getMessage(), e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | public Boolean saveReplenish(Map<String,Object> object) { |
| | | boolean saveState = true; |
| | |
| | | //判断是否已经审核 |
| | | if(patchLog1.getReviewStatus()==0){ |
| | | ReportingWork reportingWork = reportingWorkMapper |
| | | .selectOne(new QueryWrapper<ReportingWork>().eq("reporting_work_id",patchLog.getReportingWorkId())); |
| | | .selectOne(new QueryWrapper<ReportingWork>() |
| | | .eq("reporting_work_id",patchLog.getReportingWorkId())); |
| | | //修改小片流程卡数量 |
| | | patchMapper.updateOrderProcessDetail(patchLog,reportingWork); |
| | | //审核 |
| | |
| | | if(Objects.equals(type, "补片")){ |
| | | alias="BP"; |
| | | } |
| | | //查询当天的最大数量 |
| | | Integer maximum=patchMapper.getMaximum(); |
| | | //查询当天最新的编号 |
| | | String str=patchMapper.getMaximum(); |
| | | if (str == null){ |
| | | str="00"; |
| | | } |
| | | String maximum = str.substring(str.length() - 2); |
| | | int lastTwoInteger = Integer.parseInt(maximum); |
| | | //设置两位不够补0 |
| | | String formattedNumber = String.format("%02d", maximum+1); |
| | | String formattedNumber = String.format("%02d", lastTwoInteger+1); |
| | | //格式化当前日期 |
| | | Date currentDate = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); |
| | |
| | | List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); |
| | | if (!flowCardList.isEmpty()) { |
| | | for (FlowCard flowCard : flowCardList) { |
| | | if (lableType != 2){ |
| | | if (lableType != 2){//成品标签 |
| | | Map<String, Object> itemmap = new HashMap<>(); |
| | | itemmap.put("data", flowCardMapper.getRepairPrintCustomData(flowCard.getProcessId(),flowCard.getTechnologyNumber(),flowCard.getReportingWorkId())); |
| | | itemmap.put("data", flowCardMapper.getRepairPrintCustomData(flowCard.getProcessId(),flowCard.getTechnologyNumber(),flowCard.getReportingWorkId(),flowCard.getOrderNumber())); |
| | | list.add(itemmap); |
| | | } |
| | | else{ |
| | | else{//小片标签 |
| | | Map<String, Object> itemmap = new HashMap<>(); |
| | | itemmap.put("data", flowCardMapper.getRepairPrintCustomDataSemi(flowCard.getProcessId(),flowCard.getTechnologyNumber(),flowCard.getReportingWorkId())); |
| | | List<Map<String,Object>> customDataSemi =flowCardMapper.getRepairPrintCustomDataSemi(flowCard.getProcessId(),flowCard.getTechnologyNumber(),flowCard.getReportingWorkId(),flowCard.getOrderNumber()); |
| | | for (Map<String, Object> dataMap : customDataSemi) { |
| | | dataMap.put("newList", flowCardMapper.getgetPrintCustomDataSemiSp( |
| | | flowCard.getProcessId(), |
| | | dataMap.get("technologyNumber").toString(), |
| | | flowCard.getOrderNumber() |
| | | )); |
| | | } |
| | | itemmap.put("data", customDataSemi); |
| | | list.add(itemmap); |
| | | } |
| | | |
| | |
| | | //判断是否已经审核 |
| | | if(patchLog1.getReviewStatus()==0){ |
| | | //删除补片表对应补片id数据 |
| | | patchMapper.deleteReplenishMp(patchLog.getPatchId()); |
| | | //修改次破明细表补片数量和状态 |
| | | patchMapper.updatePatchDdMp(patchLog.getReportingWorkId(),patchLog.getOrderSort(),patchLog.getTechnologyNumber(),patchLog.getPatchNum()); |
| | | patchMapper.deleteReplenishMp(patchLog1.getId()); |
| | | //删除次破明细表 |
| | | patchMapper.updatePatchDdMp(patchLog1.getReportingWorkId(),patchLog1.getOrderSort(),patchLog1.getTechnologyNumber(),patchLog1.getPatchNum(),patchLog1.getPatchReason()); |
| | | //修改报工明细表状态 |
| | | patchMapper.updatePatchBgMp(patchLog.getReportingWorkId(),patchLog.getOrderSort(),patchLog.getTechnologyNumber()); |
| | | patchMapper.updatePatchBgMp(patchLog1.getReportingWorkId(),patchLog1.getOrderSort(),patchLog1.getTechnologyNumber()); |
| | | //修改报工主表次破数量 |
| | | reportingWorkMapper.updateRWPatchNum(patchLog1.getReportingWorkId(),patchLog1.getPatchNum()); |
| | | //修改报工副表次破数量 |
| | | reportingWorkMapper.updateRWDPatchNum(patchLog1.getReportingWorkId(),patchLog1.getOrderSort(),patchLog1.getTechnologyNumber(),patchLog1.getPatchNum()); |
| | | //更新报工流程表数据 |
| | | reportingWorkMapper.updateReplenishWorkProcess(patchLog1.getProcessId(),patchLog1.getOrderSort(),patchLog1.getTechnologyNumber(),patchLog1.getPatchNum(),patchLog1.getPatchProcesses()); |
| | | |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("deleteReplenishSv补片删除"); |
| | | log.setOperatorId((String) object.get("userId")); |
| | | log.setOperator((String) object.get("userName")); |
| | | logService.saveLog(log); |
| | | } |
| | | else{ |
| | | saveState = false; |
| | |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysError.setFunc("deleteReplenishSv"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | |
| | | List<PatchLog> patchLoglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("patchLog")), PatchLog.class); |
| | | if (!patchLoglist.isEmpty()){ |
| | | for (PatchLog patchLog : patchLoglist) { |
| | | //查询是否已生成工程号 |
| | | Integer projectCount = patchMapper.selectProjectCount(patchLog.getProcessId(),patchLog.getPatchId(),patchLog.getTechnologyNumber()); |
| | | //查询流程卡工艺流程 |
| | | String technologicalProcess = reportingWorkMapper.SelectTechnologicalProcess(patchLog.getProcessId(), String.valueOf(patchLog.getTechnologyNumber())); |
| | | if (technologicalProcess!=null || !technologicalProcess.equals("")) { |
| | | String[] processList = technologicalProcess.split("->"); |
| | | //获取工艺流程第一个工序 |
| | | String interceptProcess = processList[0]; |
| | | Integer firstStep=reportingWorkMapper.getFirstStep(patchLog.getProcessId(),patchLog.getOrderSort(),patchLog.getTechnologyNumber(),interceptProcess); |
| | | if (firstStep>=patchLog.getPatchNum()){ |
| | | ReportingWork reportingWork = reportingWorkMapper |
| | | .selectOne(new QueryWrapper<ReportingWork>().eq("reporting_work_id",patchLog.getReportingWorkId())); |
| | | //修改小片流程卡数量 |
| | | patchMapper.updateOrderProcessDetailCancel(patchLog,reportingWork); |
| | | //审核 |
| | | patchMapper.updateReplenishCancel(patchLog); |
| | | } |
| | | else { |
| | | saveState = false; |
| | | } |
| | | }else{ |
| | | if (projectCount == 0){ |
| | | if (technologicalProcess!=null || !technologicalProcess.equals("")) { |
| | | String[] processList = technologicalProcess.split("->"); |
| | | //获取工艺流程第一个工序 |
| | | String interceptProcess = processList[0]; |
| | | Integer firstStep=reportingWorkMapper.getFirstStep(patchLog.getProcessId(),patchLog.getOrderSort(),patchLog.getTechnologyNumber(),interceptProcess); |
| | | if (firstStep>=patchLog.getPatchNum()){ |
| | | ReportingWork reportingWork = reportingWorkMapper |
| | | .selectOne(new QueryWrapper<ReportingWork>().eq("reporting_work_id",patchLog.getReportingWorkId())); |
| | | //修改小片流程卡数量 |
| | | patchMapper.updateOrderProcessDetailCancel(patchLog,reportingWork); |
| | | //审核 |
| | | patchMapper.updateReplenishCancel(patchLog); |
| | | } |
| | | else { |
| | | saveState = false; |
| | | } |
| | | }else{ |
| | | saveState = false; |
| | | } |
| | | |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("updateCancelReviewSv补片反审"); |
| | | log.setOperatorId((String) object.get("userId")); |
| | | log.setOperator((String) object.get("userName")); |
| | | logService.saveLog(log); |
| | | } else { |
| | | saveState = false; |
| | | } |
| | | |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("updateCancelReviewSv补片反审"); |
| | | log.setOperatorId((String) object.get("userId")); |
| | | log.setOperator((String) object.get("userName")); |
| | | logService.saveLog(log); |
| | | } |
| | | } |
| | | |
| | | // } catch (Exception e) { |
| | | // TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | // //将异常传入数据库 |
| | | // SysError sysError = new SysError(); |
| | | // sysError.setError(e.toString()); |
| | | // sysError.setFunc("updateCancelReviewSv"); |
| | | // sysErrorService.insert(sysError); |
| | | // saveState = false; |
| | | // |
| | | // } |
| | | |
| | | return saveState; |
| | | } |
| | | |
| | | // public List exportReplenishSv(Map<String, Object> dates) { |
| | | // } |
| | | public List<exportReplenishDTO> exportReplenishSv(List<LocalDate> dates) { |
| | | return patchMapper.exportReplenishMp(dates); |
| | | } |
| | | } |
| | | |