| | |
| | | import org.apache.shiro.SecurityUtils; |
| | | 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.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.dto.EamRepairOrderDto; |
| | | import org.jeecg.modules.eam.dto.EamReportRepairDto; |
| | | import org.jeecg.modules.eam.dto.EchartsDto; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.EamReportRepairMapper; |
| | | import org.jeecg.modules.eam.request.EamReportRepairQuery; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private IEamRepairOrderService iEamRepairOrderService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | @Autowired |
| | | private IEamReportThreeNoSpareService eamReportThreeNoSpareService; |
| | | @Autowired |
| | | private IEamBaseHFCodeService hfCodeService; |
| | | /** |
| | | * 分页列表 |
| | | * |
| | |
| | | eamReportProductHazards.setReportId(eamReportRepair.getId()); |
| | | eamReportProductHazards.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0)); |
| | | eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.PENDING_SUBMIT.name()); |
| | | EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_PRODUCT_HAZARDS.name()); |
| | | if (eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置产品安全隐患确认的HF编码,添加失败!"); |
| | | } |
| | | eamReportProductHazards.setHfCode(eamBaseHFCode.getHfCode()); |
| | | iEamReportProductHazardsService.save(eamReportProductHazards); |
| | | } |
| | | if (StrUtil.isNotEmpty(eamReportRepair.getIsAccidentsRegister())&&("1").equals(eamReportRepair.getIsAccidentsRegister())) { |
| | | //添加设备事故登记表 |
| | | EamReportAccidentsRegister eamReportAccidentsRegister = new EamReportAccidentsRegister(); |
| | | BeanUtils.copyProperties(eamReportRepairRequest, eamReportAccidentsRegister); |
| | | eamReportAccidentsRegister.setId(null); |
| | | eamReportAccidentsRegister.setReportId(eamReportRepair.getId()); |
| | | eamReportAccidentsRegister.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0)); |
| | | eamReportAccidentsRegister.setRegisterStatus(EamReportAccidentsRegisterEnum.PENDING_SUBMIT.name()); |
| | | EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_ACCIDENTS_REGISTER.name()); |
| | | if (eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置设备事故登记表的HF编码,添加失败!"); |
| | | } |
| | | eamReportAccidentsRegister.setHfCode(eamBaseHFCode.getHfCode()); |
| | | iEamReportAccidentsRegisterService.save(eamReportAccidentsRegister); |
| | | //生成三不原则 |
| | | EamReportThreeNoSpare eamReportThreeNoSpare = new EamReportThreeNoSpare(); |
| | | BeanUtils.copyProperties(eamReportRepairRequest, eamReportThreeNoSpare); |
| | | eamReportThreeNoSpare.setId(null); |
| | | eamReportThreeNoSpare.setReportId(eamReportRepair.getId()); |
| | | eamReportThreeNoSpare.setPreventionMeasures(eamReportAccidentsRegister.getTakeSteps()); |
| | | eamReportThreeNoSpare.setSubmitStatus(EamReportThreeNoSpareEnum.PENDING_SUBMIT.name()); |
| | | eamReportThreeNoSpare.setDelFlag(Integer.valueOf(CommonConstant.DEFAULT_0)); |
| | | EamBaseHFCode threeHfCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.REPORT_THREE_NO_SPARE.name()); |
| | | if (threeHfCode == null) { |
| | | throw new JeecgBootException("未配置三不放过原则表的HF编码,添加失败!"); |
| | | } |
| | | eamReportThreeNoSpare.setHfCode(threeHfCode.getHfCode()); |
| | | eamReportThreeNoSpareService.save(eamReportThreeNoSpare); |
| | | } |
| | | //生成维修工单 |
| | | EamRepairOrder eamRepairOrder=new EamRepairOrder(); |
| | |
| | | eamRepairOrder.setReportId(eamReportRepair.getId()); |
| | | eamRepairOrder.setReportPerson(eamReportRepair.getCreateBy()); |
| | | eamRepairOrder.setFaultPhenomenon(eamReportRepair.getFaultDescription()); |
| | | eamRepairOrder.setFaultStartTime(eamReportRepair.getFaultStartTime()); |
| | | eamRepairOrder.setClaimStatus("0"); |
| | | eamRepairOrder.setRepairStatus(EamRepairOrderRepairStatusEnum.PENDING_REPAIR.name()); |
| | | iEamRepairOrderService.save(eamRepairOrder); |
| | | //更新设备维修状态 |
| | |
| | | } |
| | | updateWrapper.eq(EamReportRepair::getId,eamReportRepairDto.getId()); |
| | | this.update(eamReportRepair,updateWrapper); |
| | | //修改维修工单 |
| | | EamRepairOrder eamRepairOrder=iEamRepairOrderService. |
| | | getOne(new QueryWrapper<EamRepairOrder>().eq("report_id",eamReportRepairDto.getId())); |
| | | eamRepairOrder.setFaultStartTime(eamReportRepairDto.getFaultStartTime()); |
| | | eamRepairOrder.setFaultPhenomenon(eamReportRepairDto.getFaultDescription()); |
| | | iEamRepairOrderService.updateById(eamRepairOrder); |
| | | return true; |
| | | } |
| | | |
| | |
| | | eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name()); |
| | | return entity; |
| | | } |
| | | |
| | | public List<EchartsDto> reportRepairList() { |
| | | List<EchartsDto> echartsDtoList = new ArrayList<>(); |
| | | |
| | | // 用户数据权限检查 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return echartsDtoList; // 返回空列表而非null |
| | | } |
| | | |
| | | QueryWrapper<EamReportRepairDto> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0); |
| | | |
| | | // 设备过滤逻辑 |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService |
| | | .list(new LambdaQueryWrapper<BaseFactoryUser>() |
| | | .eq(BaseFactoryUser::getUserId, sysUser.getId())); |
| | | |
| | | if (CollectionUtils.isEmpty(baseFactoryUserList)) { |
| | | return echartsDtoList; // 返回空列表而非null |
| | | } |
| | | |
| | | Set<String> factoryIds = baseFactoryUserList.stream() |
| | | .map(BaseFactoryUser::getFactoryId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | Set<String> factoryCodes = baseFactoryService.listByIds(factoryIds) |
| | | .stream() |
| | | .map(BaseFactory::getOrgCode) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | queryWrapper.in("e.factory_org_code", factoryCodes); |
| | | } |
| | | |
| | | // 获取基础数据 |
| | | List<EamReportRepairDto> baseList = this.baseMapper.queryList(queryWrapper); |
| | | int totalCount = baseList.size(); |
| | | |
| | | // 获取停机数量 |
| | | int shutdownCount = this.baseMapper.queryList( |
| | | queryWrapper.clone().eq("breakdown_flag", "1") |
| | | ).size(); |
| | | |
| | | // 计算运行数量 |
| | | int runningCount = totalCount - shutdownCount; |
| | | |
| | | // 处理零值情况 |
| | | if (totalCount == 0) { |
| | | // 添加所有零值数据项 |
| | | addZeroValueData(echartsDtoList, "报修总数", "bx"); |
| | | addZeroValueData(echartsDtoList, "停机总数", "stop"); |
| | | addZeroValueData(echartsDtoList, "运行总数", "run"); |
| | | return echartsDtoList; |
| | | } |
| | | |
| | | // 计算百分比 |
| | | BigDecimal total = new BigDecimal(totalCount); |
| | | String bxPercentage = calculatePercentage(totalCount, BigDecimal.valueOf(totalCount)); |
| | | String stopPercentage = calculatePercentage(shutdownCount, BigDecimal.valueOf(totalCount)); |
| | | String runPercentage = calculatePercentage(runningCount, BigDecimal.valueOf(totalCount)); |
| | | |
| | | // 构建返回数据 |
| | | echartsDtoList.add(createEchartsDto("报修总数", "bx", totalCount, bxPercentage)); |
| | | echartsDtoList.add(createEchartsDto("停机总数", "stop", shutdownCount, stopPercentage)); |
| | | echartsDtoList.add(createEchartsDto("运行总数", "run", runningCount, runPercentage)); |
| | | |
| | | return echartsDtoList; |
| | | } |
| | | |
| | | // 辅助方法:添加零值数据 |
| | | private void addZeroValueData(List<EchartsDto> list, String name, String code) { |
| | | EchartsDto dto = new EchartsDto(); |
| | | dto.setName(name); |
| | | dto.setCode(code); |
| | | dto.setValue("0"); |
| | | dto.setPercentage("0.00%"); |
| | | list.add(dto); |
| | | } |
| | | |
| | | // 辅助方法:计算百分比 |
| | | private String calculatePercentage(int value, BigDecimal total) { |
| | | return new BigDecimal(value) |
| | | .multiply(new BigDecimal(100)) |
| | | .divide(total, 2, RoundingMode.HALF_UP) + "%"; |
| | | } |
| | | |
| | | // 辅助方法:创建EchartsDto对象 |
| | | private EchartsDto createEchartsDto(String name, String code, int value, String percentage) { |
| | | EchartsDto dto = new EchartsDto(); |
| | | dto.setName(name); |
| | | dto.setCode(code); |
| | | dto.setValue(String.valueOf(value)); |
| | | dto.setPercentage(percentage); |
| | | return dto; |
| | | } |
| | | } |