| | |
| | | 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: 点检工单 |
| | |
| | | |
| | | @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) { |
| | |
| | | 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) { |
| | |
| | | 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、itemName、itemDemand 的对象 |
| | | 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 = ""; |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 日点检责任人列表 |
| | | * @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、itemName、itemDemand 的对象 |
| | | 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 = ""; |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 周点检责任人列表 |
| | | * @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("添加成功!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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()); |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | @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); |
| | |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | // 点检完成 |
| | | 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()); |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |