| | |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.enums.ContractType; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.oa.OAProcess; |
| | | import com.ruoyi.common.oa.OAProperty; |
| | | import com.ruoyi.common.oa.OAResult; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.inspect.dto.PushOADto; |
| | | import com.ruoyi.inspect.dto.UnqualifiedHandlerDto; |
| | | import com.ruoyi.inspect.excel.InsUnqualifiedHandlerExcelData; |
| | | import com.ruoyi.inspect.mapper.InsOrderMapper; |
| | | import com.ruoyi.inspect.mapper.InsSampleMapper; |
| | | import com.ruoyi.inspect.mapper.InsUnqualifiedHandlerMapper; |
| | | import com.ruoyi.inspect.pojo.CommonOa; |
| | | import com.ruoyi.inspect.pojo.InsOrder; |
| | | import com.ruoyi.inspect.pojo.InsUnqualifiedHandler; |
| | | import com.ruoyi.inspect.pojo.InsUnqualifiedHandlerFile; |
| | | import com.ruoyi.inspect.service.CommonOaService; |
| | | import com.ruoyi.inspect.service.InsOrderService; |
| | | import com.ruoyi.inspect.service.InsUnqualifiedHandlerFileService; |
| | | import com.ruoyi.inspect.service.InsUnqualifiedHandlerService; |
| | | import com.ruoyi.inspect.vo.UnqualifiedHandlerVO; |
| | |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private InsUnqualifiedHandlerFileService insUnqualifiedHandlerFileService; |
| | | @Resource |
| | | private InsOrderMapper insOrderMapper; |
| | | private InsSampleMapper insSampleMapper; |
| | | @Resource |
| | | private ISysDictTypeService sysDictTypeService; |
| | | @Resource |
| | | private NumberGenerator<InsUnqualifiedHandler> insUnqualifiedHandlerNumberGenerator; |
| | | |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getList() { |
| | | return baseMapper.selectList(null).stream().map(InsUnqualifiedHandler::getInsOrderId).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public Result pushOA(PushOADto pushOADto) { |
| | | //获取不合格处理记录 |
| | | UnqualifiedHandlerVO vo = baseMapper.findById(pushOADto.getHandlerId()); |
| | | UnqualifiedHandlerVO vo = baseMapper.findByGroupId(pushOADto.getGroupId(),pushOADto.getHandlerId()); |
| | | |
| | | //提交oa相关字段赋值 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | Map<String, String> mainFields = new HashMap<>(); |
| | | // mainFields.put("bh", vo.getNo());//编号 |
| | | // mainFields.put("gysmc", vo.getSupplierName());//供应商名称 |
| | | // mainFields.put("wlmc", vo.getMaterialName());//物料名称 |
| | | // mainFields.put("scpc", vo.getProductionBatch());//生产批次 |
| | | // mainFields.put("dhsl", vo.getCargoQuantity());//到货数量 |
| | | // mainFields.put("ggxh", vo.getSpecsModels());//规格型号 |
| | | // mainFields.put("bjrq", vo.getInspectTime().format(formatter));//报检日期 |
| | | // mainFields.put("fkr", SecurityUtils.getUsername());//反馈人 |
| | | // mainFields.put("fkrq", vo.getFeedbackTime().format(formatter));//反馈日期 |
| | | // mainFields.put("fl", vo.getClassification());//分类 |
| | | // mainFields.put("bhggs", vo.getOffGradeAscription());//不合格归属 |
| | | // mainFields.put("bhgqkms", vo.getUnqualifiedDesc());//不合格情况描述 |
| | | // mainFields.put("bh", vo.getNo());//编号 |
| | | mainFields.put("gysmcsuppliername", vo.getSupplierName());//供应商名称 |
| | | mainFields.put("wlmcmaterialname", vo.getMaterialName());//物料名称 |
| | | mainFields.put("scpcproductionbatch", vo.getProductionBatch());//生产批次 |
| | | mainFields.put("dhslcargoquantity", vo.getCargoQuantity());//到货数量 |
| | | mainFields.put("dhslcargoquantity", vo.getCargoQuantity() + vo.getBuyUnitMeas());//到货数量 |
| | | mainFields.put("ggxhspecificationsmodels", vo.getSpecsModels());//规格型号 |
| | | mainFields.put("bjrqdeclarationinspectdate", vo.getInspectTime().format(formatter));//报检日期 |
| | | mainFields.put("fkrprovideroffeedback", SecurityUtils.getUsername());//反馈人 |
| | |
| | | boolean oa = false; |
| | | try { |
| | | log.info("发起不合格处理OA审核流程"); |
| | | //根据IFS域获取对应的流程id |
| | | if(StringUtils.isBlank(pushOADto.getContract())){ |
| | | throw new RuntimeException("IFS域【"+pushOADto.getContract()+"】不存在,OA流程提交失败"); |
| | | } |
| | | String unqualifiedProcessId = StringUtils.equals(ContractType.ZTNS.getValue(),pushOADto.getContract())?oaProperty.getUnqualifiedProcessId():oaProperty.getUnqualifiedProcessIdByKJNS(); |
| | | log.info("不合格流程请求参数:{},{},{},{}",mainFields, requestName, unqualifiedProcessId,SecurityUtils.getUsername()); |
| | | String unqualifiedProcessId = oaProperty.getUnqualifiedProcessId(); |
| | | OAResult oaResult = OAProcess.start(mainFields, requestName, unqualifiedProcessId,SecurityUtils.getUsername()); |
| | | log.info("不合格流程ID:{},不合格处理OA审核流程结束,返回结果->{}",unqualifiedProcessId,oaResult); |
| | | log.info("不合格流程ID:{},不合格处理OA审核流程发起成功->{}",unqualifiedProcessId,oaResult); |
| | | oa = oaResult.success(); |
| | | if (oa) { |
| | | String addWorkflowResult = oaResult.getAddWorkflowResult(); |
| | | baseMapper.update(null, new LambdaUpdateWrapper<InsUnqualifiedHandler>() |
| | | .set(InsUnqualifiedHandler::getRequestId, addWorkflowResult) |
| | | .set(InsUnqualifiedHandler::getOaState, 2) |
| | | .eq(InsUnqualifiedHandler::getId, pushOADto.getHandlerId())); |
| | | .eq(InsUnqualifiedHandler::getGroupId, pushOADto.getGroupId())); |
| | | } else { |
| | | return Result.fail("提交oa失败: " + oaResult.getErrorMsg()); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void unqualifiedHandlerOACallback(Long oaWorkId, String checkResult, JSONArray objects) { |
| | | public void unqualifiedHandlerOACallback(Long oaWorkId, String checkResult, JSONObject response) { |
| | | // 没有这个就结束 |
| | | Long count1 = baseMapper.selectCount(Wrappers.<InsUnqualifiedHandler>lambdaQuery() |
| | | .eq(InsUnqualifiedHandler::getRequestId, Integer.valueOf(String.valueOf(oaWorkId)))); |
| | | if (count1 == 0) { |
| | | return; |
| | | } |
| | | |
| | | //处理措施map |
| | | Map<String, String> clcsMap = new HashMap<>(); |
| | | clcsMap.put("0","让步放行"); |
| | | clcsMap.put("1","退货"); |
| | | clcsMap.put("2","部分退货"); |
| | | clcsMap.put("3","降级使用"); |
| | | //oa状态:3通过 4驳回 |
| | | Integer oaState = "1".equals(checkResult) ? 3 : 4; |
| | | baseMapper.update(null, new LambdaUpdateWrapper<InsUnqualifiedHandler>() |
| | | .set(InsUnqualifiedHandler::getOaState, oaState) |
| | | .ge(InsUnqualifiedHandler::getRequestId, Integer.valueOf(String.valueOf(oaWorkId)))); |
| | | .set(InsUnqualifiedHandler::getClassification,response.getString("flclassification")) |
| | | .eq(InsUnqualifiedHandler::getRequestId, Integer.valueOf(String.valueOf(oaWorkId)))); |
| | | //保存oa审批流程记录 |
| | | List<CommonOa> commonOaList = new ArrayList<>(); |
| | | objects.forEach(l -> { |
| | | JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(l)); |
| | | JSONArray workflowRequestLogs = JSONArray.parseArray(JSONObject.toJSONString(response.get("workflowRequestLogs"))); |
| | | for (Object workflowRequestLog : workflowRequestLogs) { |
| | | JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(workflowRequestLog)); |
| | | CommonOa oa = new CommonOa(); |
| | | oa.setApprover(jsonObject.getString("operatorName")); |
| | | oa.setOperateId(jsonObject.getLong("operateId")); |
| | | oa.setWorkflowId(oaWorkId); |
| | | oa.setOperation(jsonObject.getString("operateType")); |
| | | oa.setApprovalDate(jsonObject.getString("operateDate")); |
| | | oa.setApprovalOpinion(jsonObject.getString("remark")); |
| | | oa.setNodeName(jsonObject.getString("nodeName")); |
| | | oa.setApprovalTime(jsonObject.getString("operateTime")); |
| | | //设置各节点的处理意见 |
| | | if(StringUtils.isNotBlank(oa.getNodeName())){ |
| | | if(oa.getNodeName().contains("质量")){ |
| | | oa.setOperation(clcsMap.get(response.getString("clcs1"))); |
| | | oa.setApprovalOpinion(response.getString("dbhgcpdclyqdealwiththenonconfo"));//1.对不合格产品的处理要求 |
| | | }else if(oa.getNodeName().contains("工艺")){ |
| | | oa.setApprovalOpinion(response.getString("gjyqimprovementrequirements"));//2.改进要求 |
| | | }else if(oa.getNodeName().contains("技术")){ |
| | | oa.setOperation(clcsMap.get(response.getString("clcs2"))); |
| | | oa.setApprovalOpinion(response.getString("csyqactionrequirement"));//3.措施要求 |
| | | }else if(oa.getNodeName().contains("总经理")){ |
| | | oa.setOperation(clcsMap.get(response.getString("clcs3"))); |
| | | oa.setApprovalOpinion(response.getString("zzclyqfinaltreatmentrequiremen"));//4.最终处理要求 |
| | | }else if(oa.getNodeName().contains("核算")){ |
| | | oa.setApprovalOpinion(response.getString("spyqcompensationrequirement"));//5.索赔要求 |
| | | }else{ |
| | | oa.setApprovalOpinion(jsonObject.getString("remark")); |
| | | } |
| | | } |
| | | |
| | | //查询判断之前是否添加过 |
| | | long count = commonOaService.count(Wrappers.<CommonOa>lambdaQuery() |
| | | .eq(CommonOa::getApprover, oa.getApprover()) |
| | | .eq(CommonOa::getWorkflowId, oa.getWorkflowId()) |
| | | .eq(CommonOa::getOperation, oa.getOperation()) |
| | | .eq(CommonOa::getApprovalDate, oa.getApprovalDate()) |
| | | .eq(CommonOa::getApprovalOpinion, oa.getApprovalOpinion()) |
| | | .eq(CommonOa::getNodeName, oa.getNodeName()) |
| | | .eq(CommonOa::getApprovalTime, oa.getApprovalTime()) |
| | | ); |
| | | .eq(CommonOa::getWorkflowId, oaWorkId) |
| | | .eq(CommonOa::getOperateId, oa.getOperateId())); |
| | | // 没有重复添加 |
| | | if (count == 0) { |
| | | commonOaList.add(oa); |
| | | } |
| | | }); |
| | | } |
| | | commonOaService.saveBatch(commonOaList); |
| | | |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addUnqualifiedHandler(UnqualifiedHandlerDto unqualifiedHandlerDto) { |
| | | if (unqualifiedHandlerDto.getInventoryQuantityId() == null) { |
| | | throw new ErrorException("缺少原材料id"); |
| | | } |
| | | long count = this.count(Wrappers.<InsUnqualifiedHandler>lambdaQuery() |
| | | .eq(InsUnqualifiedHandler::getInsOrderId, unqualifiedHandlerDto.getInsOrderId())); |
| | | .in(InsUnqualifiedHandler::getInsOrderId, unqualifiedHandlerDto.getSelectOrderIds())); |
| | | if (count > 0) { |
| | | throw new ErrorException("当前检验单已提交过不合格"); |
| | | throw new ErrorException("存在已提交过不合格处理的订单"); |
| | | } |
| | | //生成分组id |
| | | String groupId = insUnqualifiedHandlerNumberGenerator.generateNumberWithPrefix(6, "GROUP", InsUnqualifiedHandler::getGroupId); |
| | | // 原材料编号切割 |
| | | InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery() |
| | | .eq(InsOrder::getId, unqualifiedHandlerDto.getInsOrderId()) |
| | | .select(InsOrder::getEntrustCode)); |
| | | unqualifiedHandlerDto.setNo(order.getEntrustCode()); |
| | | for (Integer selectOrderId : unqualifiedHandlerDto.getSelectOrderIds()) { |
| | | InsUnqualifiedHandler insUnqualifiedHandler = new InsUnqualifiedHandler(); |
| | | BeanUtils.copyProperties(unqualifiedHandlerDto, insUnqualifiedHandler); |
| | | Map<String, Object> orderMap = insSampleMapper.selectInsOrder(selectOrderId); |
| | | insUnqualifiedHandler.setNo(orderMap.get("entrustCode").toString()); |
| | | insUnqualifiedHandler.setInventoryQuantityId(Integer.valueOf(orderMap.get("inventoryQuantityId").toString())); |
| | | insUnqualifiedHandler.setInsOrderId(selectOrderId); |
| | | insUnqualifiedHandler.setGroupId(groupId); |
| | | insUnqualifiedHandler.setProductionBatch(orderMap.get("updateBatchNo").toString()); |
| | | insUnqualifiedHandler.setCargoQuantity(Double.parseDouble(orderMap.get("qtyArrived").toString())); |
| | | insUnqualifiedHandler.setBuyUnitMeas(orderMap.get("buyUnitMeas").toString()); |
| | | |
| | | this.save(unqualifiedHandlerDto); |
| | | if (CollectionUtils.isNotEmpty(unqualifiedHandlerDto.getUnqualifiedHandlerFiles())) { |
| | | for (InsUnqualifiedHandlerFile unqualifiedHandlerFile : unqualifiedHandlerDto.getUnqualifiedHandlerFiles()) { |
| | | unqualifiedHandlerFile.setUnqualifiedId(unqualifiedHandlerDto.getId()); |
| | | this.save(insUnqualifiedHandler); |
| | | if (CollectionUtils.isNotEmpty(unqualifiedHandlerDto.getUnqualifiedHandlerFiles())) { |
| | | for (InsUnqualifiedHandlerFile unqualifiedHandlerFile : unqualifiedHandlerDto.getUnqualifiedHandlerFiles()) { |
| | | unqualifiedHandlerFile.setGroupId(insUnqualifiedHandler.getGroupId()); |
| | | } |
| | | insUnqualifiedHandlerFileService.updateBatchById(unqualifiedHandlerDto.getUnqualifiedHandlerFiles()); |
| | | } |
| | | insUnqualifiedHandlerFileService.updateBatchById(unqualifiedHandlerDto.getUnqualifiedHandlerFiles()); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | BeanUtil.copyProperties(insUnqualifiedHandler, unqualifiedHandlerDto); |
| | | // 查看附件 |
| | | List<InsUnqualifiedHandlerFile> list = insUnqualifiedHandlerFileService.list(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery() |
| | | .eq(InsUnqualifiedHandlerFile::getUnqualifiedId, unqualifiedHandlerDto.getId())); |
| | | .eq(InsUnqualifiedHandlerFile::getGroupId, unqualifiedHandlerDto.getGroupId())); |
| | | unqualifiedHandlerDto.setUnqualifiedHandlerFiles(list); |
| | | return unqualifiedHandlerDto; |
| | | } |
| | | |
| | | /** |
| | | * 删除不合格 |
| | | * @param id |
| | | * @param groupId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deleteUnqualifiedHandler(Integer id) { |
| | | public boolean deleteUnqualifiedHandler(String groupId) { |
| | | insUnqualifiedHandlerFileService.remove(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery() |
| | | .eq(InsUnqualifiedHandlerFile::getUnqualifiedId, id)); |
| | | this.removeById(id); |
| | | return true; |
| | | .eq(InsUnqualifiedHandlerFile::getGroupId, groupId)); |
| | | return this.remove(Wrappers.<InsUnqualifiedHandler>lambdaQuery().eq(InsUnqualifiedHandler::getGroupId, groupId)); |
| | | } |
| | | } |
| | | |