| | |
| | | package com.ruoyi.inspect.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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 com.ruoyi.system.mapper.UserMapper; |
| | | import com.ruoyi.system.service.ISysDictDataService; |
| | | import com.ruoyi.system.service.ISysDictTypeService; |
| | | import com.ruoyi.system.service.UserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDate; |
| | | 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 |
| | |
| | | response.reset(); |
| | | try{ |
| | | //查询字典 |
| | | List<SysDictData> materialPropType = sysDictTypeService.selectDictDataByType("material_prop_type"); |
| | | List<SysDictData> materialPropType = sysDictTypeService.selectDictDataByType("material_prop_type");//物料属性 |
| | | List<SysDictData> categoriesNoConformities = sysDictTypeService.selectDictDataByType("categories_no_conformities");//不合格分类 |
| | | List<SysDictData> attributionNoConformities = sysDictTypeService.selectDictDataByType("attribution_no_conformities");// 不合格归属 |
| | | //查询不合格处理记录 |
| | | IPage<UnqualifiedHandlerVO> pageList = pageList(new Page<>(-1, -1), unqualifiedHandlerDto); |
| | | List<InsUnqualifiedHandlerExcelData> records = pageList.getRecords().stream().map(m->{ |
| | | InsUnqualifiedHandlerExcelData handlerExcelData = new InsUnqualifiedHandlerExcelData(); |
| | | BeanUtil.copyProperties(m,handlerExcelData); |
| | | handlerExcelData.setMaterialProp(materialPropType.stream().filter(f-> StringUtils.equals(f.getDictValue(),handlerExcelData.getMaterialProp())).findFirst().orElse(new SysDictData()).getDictLabel()); |
| | | if(StringUtils.equals(handlerExcelData.getClassification(),"0")){ |
| | | handlerExcelData.setClassification("一类不合格"); |
| | | }else if(StringUtils.equals(handlerExcelData.getClassification(),"1")){ |
| | | handlerExcelData.setClassification("二类不合格"); |
| | | } |
| | | if(StringUtils.equals(handlerExcelData.getOffGradeAscription(),"0")){ |
| | | handlerExcelData.setOffGradeAscription("生产反馈不合格"); |
| | | }else if(StringUtils.equals(handlerExcelData.getOffGradeAscription(),"1")){ |
| | | handlerExcelData.setOffGradeAscription("检测不合格"); |
| | | } |
| | | handlerExcelData.setClassification(categoriesNoConformities.stream().filter(f-> StringUtils.equals(f.getDictValue(),handlerExcelData.getClassification())).findFirst().orElse(new SysDictData()).getDictLabel()); |
| | | handlerExcelData.setOffGradeAscription(attributionNoConformities.stream().filter(f-> StringUtils.equals(f.getDictValue(),handlerExcelData.getOffGradeAscription())).findFirst().orElse(new SysDictData()).getDictLabel()); |
| | | return handlerExcelData; |
| | | }).collect(Collectors.toList()); |
| | | //设置response |
| | |
| | | } |
| | | |
| | | @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()); |
| | | |
| | | if (vo.getRequestId() != null) { |
| | | throw new ErrorException("该不合格处理已提交过OA"); |
| | | } |
| | | 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("gysmcsuppliername", vo.getSupplierName());//供应商名称 |
| | | mainFields.put("wlmcmaterialname", vo.getMaterialName());//物料名称 |
| | | mainFields.put("scpcproductionbatch", vo.getProductionBatch());//生产批次 |
| | | mainFields.put("dhslcargoquantity", vo.getCargoQuantity() + vo.getBuyUnitMeas());//到货数量 |
| | | mainFields.put("ggxhspecificationsmodels", vo.getSpecsModels());//规格型号 |
| | | mainFields.put("bjrqdeclarationinspectdate", vo.getInspectTime().format(formatter));//报检日期 |
| | | mainFields.put("fkrprovideroffeedback", SecurityUtils.getUsername());//反馈人 |
| | | mainFields.put("fkrqfeedbacktime", vo.getFeedbackTime().format(formatter));//反馈日期 |
| | | mainFields.put("flclassification", vo.getClassification());//分类 |
| | | mainFields.put("bhggsoffgradeascription", vo.getOffGradeAscription());//不合格归属 |
| | | mainFields.put("bhgqkmsunqualifieddescription", vo.getUnqualifiedDesc());//不合格情况描述 |
| | | |
| | | //查询附件 |
| | | List<InsUnqualifiedHandlerFile> handlerFiles = insUnqualifiedHandlerFileService.list(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery() |
| | |
| | | if (CollectionUtils.isNotEmpty(handlerFiles)) { |
| | | StringBuilder fileUrl = new StringBuilder(); |
| | | for (int i = 0; i < handlerFiles.size(); i++) { |
| | | String path = handlerFiles.get(i).getType().equals(1) ? "/lims/img/" : "/lims/word/"; |
| | | String path = handlerFiles.get(i).getType().equals(1) ? "/img/" : "/word/"; |
| | | if (i == handlerFiles.size() - 1) { |
| | | fileUrl.append("<a href='" + oaProperty.getProdIp()).append(path + handlerFiles.get(i).getFileUrl() |
| | | + "'target='_blank'>" + handlerFiles.get(i).getFileName() + "</a>"); |
| | |
| | | + "'target='_blank'>" + handlerFiles.get(i).getFileName() + "</a>").append("<br/>"); |
| | | } |
| | | } |
| | | mainFields.put("xlimsfj", fileUrl.toString()); |
| | | mainFields.put("fjlj", fileUrl.toString()); |
| | | } |
| | | //流程标题 |
| | | String requestName = vo.getHeadline(); |
| | |
| | | log.info("发起不合格处理OA审核流程"); |
| | | String unqualifiedProcessId = oaProperty.getUnqualifiedProcessId(); |
| | | OAResult oaResult = OAProcess.start(mainFields, requestName, unqualifiedProcessId,SecurityUtils.getUsername()); |
| | | log.info("不合格处理OA审核流程结束,返回结果->{}" + 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; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED) |
| | | public boolean updateUnqualifiedHandler(UnqualifiedHandlerDto unqualifiedHandlerDto) { |
| | | // 删除附件, 重新添加 |
| | | insUnqualifiedHandlerFileService.remove(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery() |
| | |
| | | } |
| | | insUnqualifiedHandlerFileService.updateBatchById(unqualifiedHandlerDto.getUnqualifiedHandlerFiles()); |
| | | } |
| | | |
| | | return this.updateById(unqualifiedHandlerDto); |
| | | boolean isUpdated = this.updateById(unqualifiedHandlerDto); |
| | | if(isUpdated){ |
| | | //推送OA |
| | | PushOADto pushOADto = new PushOADto(); |
| | | pushOADto.setHandlerId(unqualifiedHandlerDto.getId()); |
| | | pushOADto.setContract(unqualifiedHandlerDto.getContract()); |
| | | pushOA(pushOADto); |
| | | } |
| | | 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)); |
| | | } |
| | | } |
| | | |