From d6372da6f37778e90a4bae02865e8ec77e980b6e Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期四, 17 七月 2025 17:14:26 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java | 547 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 441 insertions(+), 106 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java index 8cf5866..c91a37c 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java @@ -3,53 +3,55 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; import org.flowable.task.api.Task; -import org.jeecg.common.api.vo.FileUploadResult; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.DataBaseConstant; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.StrUtils; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; -import org.jeecg.modules.eam.constant.BusinessCodeConst; -import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; -import org.jeecg.modules.eam.constant.InspectionStatus; -import org.jeecg.modules.eam.entity.EamEquipment; -import org.jeecg.modules.eam.entity.EamInspectionOrder; -import org.jeecg.modules.eam.entity.EamInspectionOrderDetail; +import org.jeecg.modules.eam.constant.*; +import org.jeecg.modules.eam.request.*; +import org.jeecg.modules.system.entity.BaseFactory; +import org.jeecg.modules.system.entity.BaseFactoryUser; +import org.jeecg.modules.system.service.IBaseFactoryService; +import org.jeecg.modules.system.service.IBaseFactoryUserService; +import org.jeecg.modules.eam.entity.*; import org.jeecg.modules.eam.mapper.EamInspectionOrderMapper; -import org.jeecg.modules.eam.request.EamInspectionOrderQuery; -import org.jeecg.modules.eam.request.EamInspectionOrderRequest; -import org.jeecg.modules.eam.service.IEamEquipmentService; -import org.jeecg.modules.eam.service.IEamInspectionOrderDetailService; -import org.jeecg.modules.eam.service.IEamInspectionOrderService; -import org.jeecg.modules.eam.service.IEamReportRepairService; -import org.jeecg.modules.eam.vo.InspectionVo; +import org.jeecg.modules.eam.service.*; +import org.jeecg.modules.eam.util.DateUtils; import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl; import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; import org.jeecg.modules.flowable.apithird.service.FlowCommonService; import org.jeecg.modules.flowable.service.IFlowDefinitionService; import org.jeecg.modules.flowable.service.IFlowTaskService; -import org.jeecg.modules.system.service.IMdcUserProductionService; +import org.jeecg.modules.system.service.ISysDictService; +import org.jeecg.modules.system.service.ISysUserService; +import org.jeecg.modules.system.vo.UserSelector; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * @Description: 鐐规宸ュ崟 @@ -62,26 +64,36 @@ @Resource private EamInspectionOrderMapper eamInspectionOrderMapper; - @Autowired + @Resource private IEamInspectionOrderDetailService eamInspectionOrderDetailService; + @Resource + private IEamWeekInspectionDetailService eamWeekInspectionDetailService; + @Resource + private IBaseFactoryUserService baseFactoryUserService; + @Resource + private IBaseFactoryService baseFactoryService; @Resource private FlowCommonService flowCommonService; @Resource private IFlowDefinitionService flowDefinitionService; - @Autowired + @Resource private IFlowTaskService flowTaskService; - @Autowired + @Resource private IEamEquipmentService eamEquipmentService; - @Autowired + @Resource private FlowMyBusinessServiceImpl flowMyBusinessService; - @Autowired + @Resource private TaskService taskService; - @Autowired - private IEamEquipmentService iEamEquipmentService; - @Autowired - private IMdcUserProductionService mdcUserProductionService; - @Autowired + @Resource private IEamReportRepairService eamReportRepairService; + @Resource + private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; + @Resource + private ISysDictService sysDictService; + @Resource + private ISysUserService sysUserService; + @Resource + private IEamBaseHFCodeService eamBaseHFCodeService; @Override public IPage<EamInspectionOrder> queryPageList(Page<EamInspectionOrder> page, EamInspectionOrderQuery query) { @@ -96,8 +108,16 @@ List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); queryWrapper.in("e.equipment_code", equipArr); } else { - //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶� - queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); + //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶� + List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. + list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); + if (!CollectionUtils.isEmpty(baseFactoryUserList)) { + Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); + Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); + queryWrapper.in("e.factory_org_code", factoryCode); + }else { + return page; + } } //鏌ヨ鏉′欢杩囨护 if (query != null) { @@ -146,41 +166,358 @@ return eamInspectionOrderMapper.selectList(queryWrapper); } + /** + * 瀵煎嚭鑾峰彇鍩烘湰淇℃伅 + * @param equipmentCode 璁惧缂栫爜 + * @param inspectionDate 鐐规鏃ユ湡 + * @return + */ + @Override + public JSONObject exportInspectionOrderBaseInfo(String equipmentCode, String inspectionDate) { + if (StrUtils.isEmpty(inspectionDate)) { + // 鑾峰彇褰撳墠鏃ユ湡 + LocalDate currentDate = LocalDate.now(); + // 瀹氫箟鏃ユ湡鏍煎紡 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 鏍煎紡鍖栧綋鍓嶆湀浠� + inspectionDate = currentDate.format(formatter); + } + // 鍒涘缓缁撴灉瀵硅薄 + JSONObject result = new JSONObject(); + EamInspectionOrderBaseResponse eamInspectionOrderBaseResponse = eamInspectionOrderMapper.findInsOrderBaseInfo(equipmentCode, inspectionDate); + // 澶勭悊鍗曚綅 + String factoryOrgCode = eamInspectionOrderBaseResponse.getFactoryName(); + BaseFactory baseFactory = baseFactoryService.getOne(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getOrgCode, factoryOrgCode.substring(0, 6))); + eamInspectionOrderBaseResponse.setFactoryName(baseFactory.getFactoryName()); + result.put("data",Collections.singletonList(eamInspectionOrderBaseResponse)); + return result; + } + + /** + * 鏃ョ偣妫�椤瑰垪琛� + * @param equipmentCode 璁惧缂栫爜 + * @param inspectionDate 鐐规鏃ユ湡 + * @return + */ + @Override + public JSONObject exportInspectionOrderDetailList(String equipmentCode, String inspectionDate) { + if (StrUtils.isEmpty(inspectionDate)) { + // 鑾峰彇褰撳墠鏃ユ湡 + LocalDate currentDate = LocalDate.now(); + // 瀹氫箟鏃ユ湡鏍煎紡 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 鏍煎紡鍖栧綋鍓嶆湀浠� + inspectionDate = currentDate.format(formatter); + } + // 鍒涘缓缁撴灉瀵硅薄 + JSONObject result = new JSONObject(); + List<EamInsOrderDetailResultResponse> eamInsOrderDetailResultResponseList = eamInspectionOrderMapper.findInsOrderDetailList(equipmentCode, inspectionDate); + if (eamInsOrderDetailResultResponseList == null || eamInsOrderDetailResultResponseList.isEmpty()) { + return result; + } + Map<EamInsOrderDetailResultResponse, List<EamInsOrderDetailResultResponse>> groupMap = eamInsOrderDetailResultResponseList + .stream().collect(Collectors.groupingBy( + // 鍒嗙粍閿細鍖呭惈 itemCode銆乮temName銆乮temDemand 鐨勫璞� + item -> new EamInsOrderDetailResultResponse( + item.getItemCode(), + item.getItemName(), + item.getItemDemand() + ), + // 鐢� TreeMap 浣滀负瀹瑰櫒锛屽苟鎸囧畾鎸� itemCode 鎺掑簭鐨勬瘮杈冨櫒 + () -> new TreeMap<>(Comparator.comparingInt(EamInsOrderDetailResultResponse::getItemCode)), + // 鏀堕泦姣忕粍鐨勫厓绱犱负 List + Collectors.toList() + )); + List<Map<String, Object>> resultList = new ArrayList<>(); + groupMap.forEach((insOrderDetailResultResponse, insOrderDetailResultResponseList) -> { + Map<String, Object> resultMap = new LinkedHashMap<>(); + resultMap.put("itemCode", insOrderDetailResultResponse.getItemCode()); + resultMap.put("itemName", insOrderDetailResultResponse.getItemName()); + resultMap.put("itemDemand", insOrderDetailResultResponse.getItemDemand()); + Map<Integer, EamInsOrderDetailResultResponse> collect = insOrderDetailResultResponseList + .stream().collect(Collectors.toMap( + // 鍒嗙粍閿細鎻愬彇鏃ユ湡涓殑鈥滃ぉ鈥� + item -> { + Date date = item.getInspectionDate(); + LocalDate localDate = date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + return localDate.getDayOfMonth(); // 閿负鈥滃ぉ鈥濓紙1-31锛� + }, + // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄锛堜綔涓哄垵濮嬪�硷級 + item -> item, + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鈥滃ぉ鈥濇湁澶氫釜瀵硅薄鏃讹紝濡備綍澶勭悊锛堣繖閲岀ず渚嬪彇绗竴涓級 + (existing, replacement) -> existing // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + )); + for (int i = 1; i <= 31; i++) { + if (collect.containsKey(i)) { + String inspectionResult = ""; + if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) { + switch (collect.get(i).getInspectionResult()) { + case "NORMAL": + inspectionResult = "鈭�"; + break; + case "ANOMALY": + inspectionResult = "脳"; + break; + case "FAULT": + inspectionResult = "鈻�"; + break; + case "CLOSE": + inspectionResult = "T"; + break; + } + } + resultMap.put("inspectionResult" + i, inspectionResult); + } else { + resultMap.put("inspectionResult" + i, ""); + } + } + resultList.add(resultMap); + }); + result.put("data", resultList); + return result; + } + + /** + * 鏃ョ偣妫�璐d换浜哄垪琛� + * @param equipmentCode 璁惧缂栫爜 + * @param inspectionDate 鐐规鏃ユ湡 + * @return + */ + @Override + public JSONObject exportInspectionOrderDetailUserList(String equipmentCode, String inspectionDate) { + if (StrUtils.isEmpty(inspectionDate)) { + // 鑾峰彇褰撳墠鏃ユ湡 + LocalDate currentDate = LocalDate.now(); + // 瀹氫箟鏃ユ湡鏍煎紡 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 鏍煎紡鍖栧綋鍓嶆湀浠� + inspectionDate = currentDate.format(formatter); + } + // 鍒涘缓缁撴灉瀵硅薄 + JSONObject result = new JSONObject(); + List<EamInsOrderDetailUserResponse> eamInsOrderDetailUserResponseList = eamInspectionOrderMapper.findInspectionOrderDetailUserList(equipmentCode, inspectionDate); + if (eamInsOrderDetailUserResponseList == null || eamInsOrderDetailUserResponseList.isEmpty()) { + return result; + } + Map<Integer, EamInsOrderDetailUserResponse> groupMap = eamInsOrderDetailUserResponseList.stream().collect(Collectors.toMap( + // 鍒嗙粍閿細鎻愬彇鏃ユ湡涓殑鈥滃ぉ鈥� + item -> { + Date date = item.getInspectionDate(); + LocalDate localDate = date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + return localDate.getDayOfMonth(); // 閿负鈥滃ぉ鈥濓紙1-31锛� + }, + // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄锛堜綔涓哄垵濮嬪�硷級 + item -> item, + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鈥滃ぉ鈥濇湁澶氫釜瀵硅薄鏃讹紝濡備綍澶勭悊锛堣繖閲岀ず渚嬪彇绗竴涓級 + (existing, replacement) -> existing // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + )); + Map<String, Object> resultMap = new LinkedHashMap<>(); + for (int i = 1; i <= 31; i++) { + if (groupMap.containsKey(i)) { + EamInsOrderDetailUserResponse eamInsOrderDetailUserResponse = groupMap.get(i); + resultMap.put("operator" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamInsOrderDetailUserResponse.getOperator())); + resultMap.put("confirmUser" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamInsOrderDetailUserResponse.getConfirmUser())); + } else { + resultMap.put("operator" + i, ""); + resultMap.put("confirmUser" + i, ""); + } + } + result.put("data", Collections.singletonList(resultMap)); + return result; + } + + /** + * 鍛ㄧ偣妫�椤瑰垪琛� + * @param equipmentCode 璁惧缂栫爜 + * @param inspectionDate 鐐规鏃ユ湡 + * @return + */ + @Override + public JSONObject exportWeekInsDetailList(String equipmentCode, String inspectionDate) { + if (StrUtils.isEmpty(inspectionDate)) { + // 鑾峰彇褰撳墠鏃ユ湡 + LocalDate currentDate = LocalDate.now(); + // 瀹氫箟鏃ユ湡鏍煎紡 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 鏍煎紡鍖栧綋鍓嶆湀浠� + inspectionDate = currentDate.format(formatter); + } + // 鍒涘缓缁撴灉瀵硅薄 + JSONObject result = new JSONObject(); + List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = eamInspectionOrderMapper.findWeekInsDetailList(equipmentCode, inspectionDate); + if (eamWeekInsDetailResultResponseList == null || eamWeekInsDetailResultResponseList.isEmpty()) { + return result; + } + Map<EamWeekInsDetailResultResponse, List<EamWeekInsDetailResultResponse>> groupMap = eamWeekInsDetailResultResponseList + .stream().collect(Collectors.groupingBy( + // 鍒嗙粍閿細鍖呭惈 itemCode銆乮temName銆乮temDemand 鐨勫璞� + item -> new EamWeekInsDetailResultResponse( + item.getItemCode(), + item.getItemName(), + item.getItemDemand() + ), + // 鐢� TreeMap 浣滀负瀹瑰櫒锛屽苟鎸囧畾鎸� itemCode 鎺掑簭鐨勬瘮杈冨櫒 + () -> new TreeMap<>(Comparator.comparingInt(EamWeekInsDetailResultResponse::getItemCode)), + // 鏀堕泦姣忕粍鐨勫厓绱犱负 List + Collectors.toList() + )); + List<Map<String, Object>> resultList = new ArrayList<>(); + groupMap.forEach((weekInsDetailResultResponse, weekInsDetailResultResponseList) -> { + Map<String, Object> resultMap = new LinkedHashMap<>(); + resultMap.put("itemCode", weekInsDetailResultResponse.getItemCode()); + resultMap.put("itemName", weekInsDetailResultResponse.getItemName()); + resultMap.put("itemDemand", weekInsDetailResultResponse.getItemDemand()); + // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮� + AtomicInteger counter = new AtomicInteger(1); + Map<Integer, EamWeekInsDetailResultResponse> collect = weekInsDetailResultResponseList + .stream() + .collect(Collectors.toMap( + // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級 + item -> counter.getAndIncrement(), + // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄 + item -> item, + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴搴忓彿鏈夊涓璞℃椂锛堢悊璁轰笂涓嶄細鍙戠敓锛夛紝濡備綍澶勭悊 + (existing, replacement) -> existing, // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + // 鎸囧畾Map鐨勫叿浣撳疄鐜帮紙鍙�夛級 + LinkedHashMap::new // 淇濇寔鎻掑叆椤哄簭 + )); + for (int i = 1; i <= 5; i++) { + if (collect.containsKey(i)) { + String inspectionResult = ""; + if (!StrUtils.isEmpty(collect.get(i).getInspectionResult())) { + switch (collect.get(i).getInspectionResult()) { + case "NORMAL": + inspectionResult = "鈭�"; + break; + case "ANOMALY": + inspectionResult = "脳"; + break; + case "FAULT": + inspectionResult = "鈻�"; + break; + case "CLOSE": + inspectionResult = "T"; + break; + } + } + resultMap.put("inspectionResult" + i, inspectionResult); + } else { + resultMap.put("inspectionResult" + i, ""); + } + } + resultList.add(resultMap); + }); + result.put("data", resultList); + return result; + } + + /** + * 鍛ㄧ偣妫�璐d换浜哄垪琛� + * @param equipmentCode 璁惧缂栫爜 + * @param inspectionDate 鐐规鏃ユ湡 + * @return + */ + @Override + public JSONObject exportWeekInsOrderDetailUserList(String equipmentCode, String inspectionDate) { + if (StrUtils.isEmpty(inspectionDate)) { + // 鑾峰彇褰撳墠鏃ユ湡 + LocalDate currentDate = LocalDate.now(); + // 瀹氫箟鏃ユ湡鏍煎紡 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + // 鏍煎紡鍖栧綋鍓嶆湀浠� + inspectionDate = currentDate.format(formatter); + } + // 鍒涘缓缁撴灉瀵硅薄 + JSONObject result = new JSONObject(); + List<EamWeekInsDetailUserResponse> eamWeekInsDetailUserResponseList = eamInspectionOrderMapper.findWeekInsOrderDetailUserList(equipmentCode, inspectionDate); + if (eamWeekInsDetailUserResponseList == null || eamWeekInsDetailUserResponseList.isEmpty()) { + return result; + } + // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮� + AtomicInteger counter = new AtomicInteger(1); + Map<Integer, EamWeekInsDetailUserResponse> groupMap = eamWeekInsDetailUserResponseList + .stream() + .collect(Collectors.toMap( + // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級 + item -> counter.getAndIncrement(), + // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄锛堜綔涓哄垵濮嬪�硷級 + item -> item, + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鈥滃ぉ鈥濇湁澶氫釜瀵硅薄鏃讹紝濡備綍澶勭悊锛堣繖閲岀ず渚嬪彇绗竴涓級 + (existing, replacement) -> existing // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + )); + Map<String, Object> resultMap = new LinkedHashMap<>(); + for (int i = 1; i <= 5; i++) { + if (groupMap.containsKey(i)) { + EamWeekInsDetailUserResponse eamWeekInsDetailUserResponse = groupMap.get(i); + resultMap.put("operator" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamWeekInsDetailUserResponse.getInspector())); + resultMap.put("confirmUser" + i, sysDictService.queryTableDictTextByKey("sys_user", "realname", "username", eamWeekInsDetailUserResponse.getConfirmUser())); + } else { + resultMap.put("operator" + i, ""); + resultMap.put("confirmUser" + i, ""); + } + } + result.put("data", Collections.singletonList(resultMap)); + + return result; + } + @Override @Transactional(rollbackFor = Exception.class) - public boolean addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { + public Result<String> addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { + List<EamInspectionOrder> eamInspectionOrders = eamInspectionOrderMapper.selectList(new LambdaQueryWrapper<EamInspectionOrder>().eq(EamInspectionOrder::getStandardId, eamInspectionOrderRequest.getStandardId()).eq(EamInspectionOrder::getInspectionDate, eamInspectionOrderRequest.getInspectionDate()).ne(EamInspectionOrder::getInspectionStatus, InspectionStatus.ABOLISH.name())); + if (CollectionUtils.isNotEmpty(eamInspectionOrders)) { + return Result.error("娣诲姞澶辫触,绯荤粺宸插瓨鍦ㄥ綋鍓嶆棩鏈熷伐鍗曪紒"); + } EamInspectionOrder eamInspectionOrder = new EamInspectionOrder(); BeanUtils.copyProperties(eamInspectionOrderRequest, eamInspectionOrder); //淇敼鐘舵�� - if (StrUtil.isNotBlank(eamInspectionOrderRequest.getOperator())) { - eamInspectionOrder.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name()); - } else { - eamInspectionOrder.setInspectionStatus(InspectionStatus.WAIT_INSPECTION.name()); + eamInspectionOrder.setInspectionStatus(InspectionStatus.WAIT_INSPECTION.name()); + eamInspectionOrder.setDelFlag(CommonConstant.DEL_FLAG_0); + //HF鐮佸鐞� + EamBaseHFCode eamBaseHFCode = eamBaseHFCodeService.selectByCategory(HfTemplateCategoryEnum.INSPECTION.name()); + if (eamBaseHFCode == null) { + return Result.error("娣诲姞澶辫触,鏈厤缃偣妫�HF缂栫爜锛�"); } + eamInspectionOrder.setHfCode(eamBaseHFCode.getHfCode()); save(eamInspectionOrder); - //澶勭悊鏄庣粏鏁版嵁 - if (CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getTableDetailList())) { - eamInspectionOrderRequest.getTableDetailList().forEach(tableDetail -> { - tableDetail.setOrderId(eamInspectionOrder.getId()); - tableDetail.setId(null); - }); - eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); - } - //澶勭悊闄勪欢 - if (CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getFileList())) { - FileUploadResult fileUploadResult = eamInspectionOrderRequest.getFileList().get(0); - ObjectMapper mapper = new ObjectMapper(); - try { - String referenceFile = mapper.writeValueAsString(fileUploadResult); - eamInspectionOrder.setImageFiles(referenceFile); - } catch (JsonProcessingException e) { - log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e); + //澶勭悊鏃ョ偣妫�鏄庣粏鏁版嵁 + if (StrUtil.isNotBlank(eamInspectionOrderRequest.getStandardId())) { + List<EamMaintenanceStandardDetail> maintenanceStandardDetailList = eamMaintenanceStandardDetailService.list(new LambdaQueryWrapper<EamMaintenanceStandardDetail>().eq(EamMaintenanceStandardDetail::getStandardId, eamInspectionOrderRequest.getStandardId()).eq(EamMaintenanceStandardDetail::getItemCategory, InspectionItemCategroyEnum.DAY_INSPECTION.name())); + if (CollectionUtils.isNotEmpty(maintenanceStandardDetailList)) { + List<EamInspectionOrderDetail> inspectionOrderList = maintenanceStandardDetailList.stream().map(EamInspectionOrderDetail::new).collect(Collectors.toList()); + inspectionOrderList.forEach(tableDetail -> { + tableDetail.setOrderId(eamInspectionOrder.getId()); + tableDetail.setId(null); + }); + eamInspectionOrderDetailService.saveBatch(inspectionOrderList); } } - if (StrUtil.isNotBlank(eamInspectionOrderRequest.getOperator())) { - triggerProcess(eamInspectionOrder); + //澶勭悊鍛ㄧ偣妫�鏄庣粏鏁版嵁 + if (StrUtil.isNotBlank(eamInspectionOrderRequest.getStandardId()) && eamInspectionOrderRequest.getInspectionDate() != null) { + LambdaQueryWrapper<EamWeekInspectionDetail> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(EamWeekInspectionDetail::getStandardId, eamInspectionOrderRequest.getStandardId()); + queryWrapper.between(EamWeekInspectionDetail::getPlanInspectionDate, DateUtils.getFirstDayOfWeek(eamInspectionOrderRequest.getInspectionDate()), DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate())); + queryWrapper.orderByAsc(EamWeekInspectionDetail::getItemCode); + List<EamWeekInspectionDetail> eamWeekInspectionDetailList = eamWeekInspectionDetailService.list(queryWrapper); + if (CollectionUtil.isEmpty(eamWeekInspectionDetailList)) { + List<EamMaintenanceStandardDetail> maintenanceStandardDetailList = eamMaintenanceStandardDetailService.list(new LambdaQueryWrapper<EamMaintenanceStandardDetail>().eq(EamMaintenanceStandardDetail::getStandardId, eamInspectionOrderRequest.getStandardId()).eq(EamMaintenanceStandardDetail::getItemCategory, InspectionItemCategroyEnum.WEEK_INSPECTION.name())); + if (CollectionUtils.isNotEmpty(maintenanceStandardDetailList)) { + List<EamWeekInspectionDetail> weekInspectionDetailList = maintenanceStandardDetailList.stream().map(EamWeekInspectionDetail::new).collect(Collectors.toList()); + weekInspectionDetailList.forEach(weekInspectionDetail -> { + weekInspectionDetail.setEquipmentId(eamInspectionOrderRequest.getEquipmentId()); + weekInspectionDetail.setStandardId(eamInspectionOrderRequest.getStandardId()); + // TODO 鍛ㄧ偣妫�鏃ユ湡 + weekInspectionDetail.setPlanInspectionDate(eamInspectionOrderRequest.getInspectionDate()); + }); + eamWeekInspectionDetailService.saveBatch(weekInspectionDetailList); + } + } } - return true; + return Result.OK("娣诲姞鎴愬姛锛�"); } /** @@ -194,9 +531,9 @@ if (equipment == null) { return false; } else { - eamInspectionOrder.setEquipmentCode(equipment.getEquipmentCode()); + eamInspectionOrder.setEquipmentId(equipment.getId()); } - flowCommonService.initActBusiness("宸ュ崟鍙�: " + eamInspectionOrder.getOrderNum() + ";璁惧缂栧彿: " + eamInspectionOrder.getEquipmentCode() + ";瀹夎浣嶇疆: " + equipment.getInstallationPosition(), + flowCommonService.initActBusiness("宸ュ崟鍙�: " + eamInspectionOrder.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + (equipment.getInstallationPosition() == null ? "" : ";瀹夎浣嶇疆: " + equipment.getInstallationPosition()), eamInspectionOrder.getId(), "IEamInspectionOrderService", "eam_inspection", null); Map<String, Object> variables = new HashMap<>(); variables.put("dataId", eamInspectionOrder.getId()); @@ -224,16 +561,6 @@ eamInspectionOrder.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name()); } super.updateById(eamInspectionOrder); - //澶勭悊鏄庣粏鏁版嵁 - if (CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getTableDetailList())) { - eamInspectionOrderRequest.getTableDetailList().forEach(tableDetail -> { - tableDetail.setOrderId(eamInspectionOrder.getId()); - tableDetail.setCreateTime(new Date()); - }); - //鍒犻櫎鏄庣粏 - eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", eamInspectionOrder.getId())); - eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); - } return true; } @@ -247,7 +574,7 @@ @Transactional(rollbackFor = Exception.class) public boolean takeInspectionOrder(String id) { LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - if(user == null || !BusinessCodeConst.PCR0001.equals(user.getPost())) { + if (user == null || !BusinessCodeConst.PCR0001.equals(user.getPost())) { throw new JeecgBootException("涓嶆槸鎿嶄綔宸ワ紝鏃犳硶棰嗗彇姝ゅ伐鍗曪紒"); } EamInspectionOrder eamInspectionOrder = this.getById(id); @@ -325,8 +652,26 @@ throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰�"); } + EamEquipment equipment = eamEquipmentService.getById(eamInspectionOrder.getEquipmentId()); + if (equipment == null) { + throw new JeecgBootException("璁惧涓嶅瓨鍦紝璇锋鏌ワ紒"); + } + + // 妫�鏌ュ懆淇濊繃鏈熸椂闂� + if (eamInspectionOrderRequest.getTableWeekDetailList() == null || eamInspectionOrderRequest.getTableWeekDetailList().isEmpty()) { + List<EamWeekInspectionDetail> weekInspectionDetailList = eamWeekInspectionDetailService.list(new LambdaQueryWrapper<EamWeekInspectionDetail>().eq(EamWeekInspectionDetail::getStandardId, eamInspectionOrderRequest.getStandardId()).between(EamWeekInspectionDetail::getPlanInspectionDate, DateUtils.getFirstDayOfWeek(eamInspectionOrderRequest.getInspectionDate()), DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate()))); + if (weekInspectionDetailList != null && !weekInspectionDetailList.isEmpty()) { + if (StrUtil.isEmpty(eamInspectionOrderRequest.getOperator())) { + Date lastDate = DateUtils.getLastDayOfWeek(eamInspectionOrderRequest.getInspectionDate()); + if (DateUtils.isSameDay(lastDate, new Date())) { + throw new JeecgBootException("鏈懆鐐规鏈畬鎴愶紝璇疯繘琛屽~鎶ワ紒"); + } + } + } + } + // 璁剧疆娴佺▼鍙橀噺 - setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user); + setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user, equipment); // 瀹屾垚娴佺▼浠诲姟 Result result = flowTaskService.complete(eamInspectionOrderRequest); @@ -388,31 +733,30 @@ return true; } - private void setupProcessVariables(EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user) { + private void setupProcessVariables(EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user, EamEquipment equipment) { Map<String, Object> values = new HashMap<>(); if (InspectionStatus.UNDER_INSPECTION.name().equals(order.getInspectionStatus()) && user.getUsername().equals(order.getOperator())) { // 鐐规浜虹偣妫�缁撴潫 - String manager = Optional.ofNullable(iEamEquipmentService.getById(order.getEquipmentId())) - .map(EamEquipment::getEquipmentManager) - .orElse(null); - if (manager == null) { - throw new IllegalArgumentException("璁惧绠$悊鍛樻湭閰嶇疆"); - } - List<String> usernameList = Collections.singletonList(manager); values.put("dataId", order.getId()); values.put("organization", "鐐规浜虹偣妫�缁撴潫"); values.put("comment", "鐐规浜虹偣妫�缁撴潫"); - values.put("NextAssignee", usernameList); + // 鑾峰彇涓嬩竴姝ユ墽琛屼汉 + List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002); + if (CollectionUtil.isEmpty(userSelectors)) { + throw new JeecgBootException("璁惧鏈垎閰嶇粰缁翠慨宸ワ紝鏃犳硶杩涘叆涓嬬骇瀹℃壒锛�"); + } + List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); + values.put("NextAssignee", userApprovalList); request.setComment("鐐规浜虹偣妫�缁撴潫"); } else { - // 鐝粍闀跨‘璁� + // 缁翠慨宸ョ‘璁� values.put("dataId", order.getId()); values.put("organization", request.getConfirmComment()); values.put("comment", request.getConfirmComment()); values.put("confirmation", request.getConfirmDealType()); request.setComment(request.getConfirmComment()); if ("2".equals(request.getConfirmDealType())) { - // 鐝粍闀块┏鍥� + // 缁翠慨宸ラ┏鍥� List<String> usernames = new ArrayList<>(); usernames.add(order.getOperator()); order.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name()); @@ -428,18 +772,21 @@ // 鐐规瀹屾垚 order.setInspectionStatus(InspectionStatus.WAIT_CONFIRM.name()); order.setOperateTime(new Date()); - if (CollectionUtil.isNotEmpty(request.getFileList())) { - List<FileUploadResult> fileUploadResultList = request.getFileList(); - ObjectMapper mapper = new ObjectMapper(); - try { - String referenceFile = mapper.writeValueAsString(fileUploadResultList); - order.setImageFiles(referenceFile); - } catch (JsonProcessingException e) { - log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e); - } - } eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", order.getId())); eamInspectionOrderDetailService.saveBatch(request.getTableDetailList()); + + //璁剧疆鍛ㄧ偣妫� + if (request.getTableWeekDetailList() != null && !request.getTableWeekDetailList().isEmpty()) { + List<EamWeekInspectionDetail> tableWeekDetailList = request.getTableWeekDetailList(); + for (EamWeekInspectionDetail eamWeekInspectionDetail : tableWeekDetailList) { + if (StringUtils.isEmpty(eamWeekInspectionDetail.getInspectionResult())) { + break; + } + eamWeekInspectionDetail.setInspector(user.getUsername()); + eamWeekInspectionDetail.setInspectTime(new Date()); + } + eamWeekInspectionDetailService.saveOrUpdateBatch(tableWeekDetailList); + } } else if (InspectionStatus.WAIT_CONFIRM.name().equals(order.getInspectionStatus()) && StrUtil.isNotEmpty(request.getConfirmDealType())) { // 鐝粍闀跨‘璁や换鍔� order.setInspectionStatus(InspectionStatus.COMPLETE.name()); @@ -462,8 +809,10 @@ */ private void updateEamInspectionOrderDetail(EamInspectionOrder eamInspectionOrder) { List<EamInspectionOrderDetail> eamInspectionOrderDetails = eamInspectionOrderDetailService - .list(new QueryWrapper<EamInspectionOrderDetail>() - .eq("order_id", eamInspectionOrder.getId()).eq("report_flag", "1").eq("inspection_result", "2")); + .list(new LambdaQueryWrapper<EamInspectionOrderDetail>() + .eq(EamInspectionOrderDetail::getOrderId, eamInspectionOrder.getId()).eq(EamInspectionOrderDetail::getReportFlag, "1")); + + // TODO 鐐规瀹屾垚鍚庤嚜鍔ㄤ繚淇� eamReportRepairService.reportRepairFromInspection(eamInspectionOrder.getEquipmentId(), eamInspectionOrder.getOperator(), eamInspectionOrderDetails); } @@ -542,18 +891,4 @@ return (List<String>) object; } - @Override - public List<InspectionVo> findInspectionResult(String equipmentId,String itemDemand,String yearMonth) { - return this.baseMapper.findInspectionResult(equipmentId,itemDemand,yearMonth); - } - - @Override - public List<InspectionVo> findInspectionUser(String equipmentId,String yearMonth) { - return this.baseMapper.findInspectionUser(equipmentId,yearMonth); - } - - @Override - public List<Map<String, Object>> findInspectionStandard(String equipmentId) { - return this.baseMapper.findInspectionStandard(equipmentId); - } } -- Gitblit v1.9.3