|  |  |  | @ -34,69 +34,80 @@ import java.util.List; | 
			
		
	
		
			
				
					|  |  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  |  | public class MonthReportServiceImpl extends ServiceImpl<MonthReportMapper, OperMonthReportEntity> implements IMonthReportService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IOperPersonalMonthReportService operPersonalMonthReportService; | 
			
		
	
		
			
				
					|  |  |  |  | 	private final IOperStationMonthReportService operStationMonthReportService; | 
			
		
	
		
			
				
					|  |  |  |  | 	private final ISysClient sysClient; | 
			
		
	
		
			
				
					|  |  |  |  |     private final IOperPersonalMonthReportService operPersonalMonthReportService; | 
			
		
	
		
			
				
					|  |  |  |  |     private final IOperStationMonthReportService operStationMonthReportService; | 
			
		
	
		
			
				
					|  |  |  |  |     private final ISysClient sysClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  |  | 	public StationRunReportAllVO getStationMonthReportByStationCode(Long deptId, String month) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |  | 		StationRunReportAllVO stationReportAllVO = new StationRunReportAllVO(); | 
			
		
	
		
			
				
					|  |  |  |  | 		Dept dept = sysClient.getDept(deptId).getData(); | 
			
		
	
		
			
				
					|  |  |  |  | 		OperMonthReportEntity operMonthReportEntity = this.getOne(new LambdaQueryWrapper<OperMonthReportEntity>(){{ | 
			
		
	
		
			
				
					|  |  |  |  | 			eq(OperMonthReportEntity::getMonth,month); | 
			
		
	
		
			
				
					|  |  |  |  | 			eq(OperMonthReportEntity::getStationCode, dept.getId()); | 
			
		
	
		
			
				
					|  |  |  |  | 			eq(OperMonthReportEntity::getIsDeleted, 0); | 
			
		
	
		
			
				
					|  |  |  |  | 			orderByDesc(OperMonthReportEntity::getObject); | 
			
		
	
		
			
				
					|  |  |  |  | 			last("limit 1;"); | 
			
		
	
		
			
				
					|  |  |  |  | 		}}); | 
			
		
	
		
			
				
					|  |  |  |  | 		//查询实时数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		if(ObjectUtil.isEmpty(operMonthReportEntity)){ | 
			
		
	
		
			
				
					|  |  |  |  | 			stationReportAllVO = operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(dept, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		//历史查询定时任务生成的数据
 | 
			
		
	
		
			
				
					|  |  |  |  | 		else{ | 
			
		
	
		
			
				
					|  |  |  |  | 			stationReportAllVO = ObjectUtil.isNotEmpty(operMonthReportEntity) ? (StationRunReportAllVO) ObjectHelper.byte2obj(operMonthReportEntity.getObject()) | 
			
		
	
		
			
				
					|  |  |  |  | 				: operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(dept, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		return stationReportAllVO; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public StationRunReportAllVO getStationMonthReportByStationCode(Long deptId, String month) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |  |         StationRunReportAllVO stationReportAllVO = new StationRunReportAllVO(); | 
			
		
	
		
			
				
					|  |  |  |  |         Dept dept = sysClient.getDept(deptId).getData(); | 
			
		
	
		
			
				
					|  |  |  |  |         OperMonthReportEntity operMonthReportEntity = this.getOne(new LambdaQueryWrapper<OperMonthReportEntity>() {{ | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getMonth, month); | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getStationCode, dept.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getIsDeleted, 0); | 
			
		
	
		
			
				
					|  |  |  |  |             orderByDesc(OperMonthReportEntity::getCreateTime); | 
			
		
	
		
			
				
					|  |  |  |  |             last("limit 1;"); | 
			
		
	
		
			
				
					|  |  |  |  |         }}); | 
			
		
	
		
			
				
					|  |  |  |  |         //查询实时数据
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (ObjectUtil.isEmpty(operMonthReportEntity)) { | 
			
		
	
		
			
				
					|  |  |  |  |             stationReportAllVO = operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(dept, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  |             if (ObjectUtil.isNotEmpty(stationReportAllVO)) { | 
			
		
	
		
			
				
					|  |  |  |  |                 OperMonthReportEntity saved = new OperMonthReportEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                 saved.setMonth(month); | 
			
		
	
		
			
				
					|  |  |  |  |                 saved.setType(DictConstant.MONTH_REPORT_STATION); | 
			
		
	
		
			
				
					|  |  |  |  |                 saved.setCreateDept(deptId); | 
			
		
	
		
			
				
					|  |  |  |  |                 saved.setStationCode(deptId.toString()); | 
			
		
	
		
			
				
					|  |  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |  |                     saved.setObject(ObjectHelper.obj2byte(stationReportAllVO)); | 
			
		
	
		
			
				
					|  |  |  |  |                 } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                     log.error("生成统计月报失败{}", e.toString()); | 
			
		
	
		
			
				
					|  |  |  |  |                     e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                 //修改为每运行一次,保存一次
 | 
			
		
	
		
			
				
					|  |  |  |  |                 this.save(operMonthReportEntity); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         //历史查询定时任务生成的数据
 | 
			
		
	
		
			
				
					|  |  |  |  |         else { | 
			
		
	
		
			
				
					|  |  |  |  |             stationReportAllVO = ObjectUtil.isNotEmpty(operMonthReportEntity) ? (StationRunReportAllVO) ObjectHelper.byte2obj(operMonthReportEntity.getObject()) | 
			
		
	
		
			
				
					|  |  |  |  |                     : operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(dept, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return stationReportAllVO; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  |  | 	public void setStationMonthReportByStationCode(Long deptId, String month){ | 
			
		
	
		
			
				
					|  |  |  |  | 		Dept deptVO = sysClient.getDept(deptId).getData(); | 
			
		
	
		
			
				
					|  |  |  |  | 		log.info("---{}机构---",deptVO.getDeptName()); | 
			
		
	
		
			
				
					|  |  |  |  | 		//查询该电站该月报是否已生成月报
 | 
			
		
	
		
			
				
					|  |  |  |  | 		OperMonthReportEntity operMonthReportEntityByMonth = this.getOne(new LambdaQueryWrapper<OperMonthReportEntity>() {{ | 
			
		
	
		
			
				
					|  |  |  |  | 				eq(OperMonthReportEntity::getMonth, month); | 
			
		
	
		
			
				
					|  |  |  |  | 				eq(OperMonthReportEntity::getType, DictConstant.MONTH_REPORT_STATION); | 
			
		
	
		
			
				
					|  |  |  |  | 				eq(OperMonthReportEntity::getStationCode, deptVO.getId()); | 
			
		
	
		
			
				
					|  |  |  |  | 				eq(OperMonthReportEntity::getIsDeleted, 0); | 
			
		
	
		
			
				
					|  |  |  |  | 				last("limit 1;"); | 
			
		
	
		
			
				
					|  |  |  |  | 			}}); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 			if (ObjectUtil.isEmpty(operMonthReportEntityByMonth)||month.equals(YearMonth.now().toString())) { | 
			
		
	
		
			
				
					|  |  |  |  | 				if (ObjectUtil.isNotEmpty(operMonthReportEntityByMonth)){ | 
			
		
	
		
			
				
					|  |  |  |  | 					this.removeById(operMonthReportEntityByMonth.getId()); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  |  | 				//按站点生成各电站运维月报
 | 
			
		
	
		
			
				
					|  |  |  |  | 				StationRunReportAllVO stationReportAllVO = operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(deptVO, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  | 				if (ObjectUtil.isNotEmpty(stationReportAllVO)) { | 
			
		
	
		
			
				
					|  |  |  |  | 					OperMonthReportEntity operMonthReportEntity = new OperMonthReportEntity(); | 
			
		
	
		
			
				
					|  |  |  |  | 					operMonthReportEntity.setMonth(month); | 
			
		
	
		
			
				
					|  |  |  |  | 					operMonthReportEntity.setType(DictConstant.MONTH_REPORT_STATION); | 
			
		
	
		
			
				
					|  |  |  |  | 					operMonthReportEntity.setCreateDept(deptVO.getId()); | 
			
		
	
		
			
				
					|  |  |  |  | 					operMonthReportEntity.setStationCode(deptVO.getId().toString()); | 
			
		
	
		
			
				
					|  |  |  |  | 					try { | 
			
		
	
		
			
				
					|  |  |  |  | 						operMonthReportEntity.setObject(ObjectHelper.obj2byte(stationReportAllVO)); | 
			
		
	
		
			
				
					|  |  |  |  | 					} catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  | 						e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  | 					} | 
			
		
	
		
			
				
					|  |  |  |  | 					//修改为每运行一次,保存一次
 | 
			
		
	
		
			
				
					|  |  |  |  | 					this.save(operMonthReportEntity); | 
			
		
	
		
			
				
					|  |  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  |  | 			} else { | 
			
		
	
		
			
				
					|  |  |  |  | 				log.info("该月{}已生成月报", deptVO.getDeptName()); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void setStationMonthReportByStationCode(Long deptId, String month) { | 
			
		
	
		
			
				
					|  |  |  |  |         Dept deptVO = sysClient.getDept(deptId).getData(); | 
			
		
	
		
			
				
					|  |  |  |  |         log.info("---{}机构---", deptVO.getDeptName()); | 
			
		
	
		
			
				
					|  |  |  |  |         //查询该电站该月报是否已生成月报
 | 
			
		
	
		
			
				
					|  |  |  |  |         OperMonthReportEntity operMonthReportEntityByMonth = this.getOne(new LambdaQueryWrapper<OperMonthReportEntity>() {{ | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getMonth, month); | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getType, DictConstant.MONTH_REPORT_STATION); | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getStationCode, deptVO.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |             eq(OperMonthReportEntity::getIsDeleted, 0); | 
			
		
	
		
			
				
					|  |  |  |  |             last("limit 1;"); | 
			
		
	
		
			
				
					|  |  |  |  |         }}); | 
			
		
	
		
			
				
					|  |  |  |  |         if (ObjectUtil.isNotEmpty(operMonthReportEntityByMonth)) { | 
			
		
	
		
			
				
					|  |  |  |  |             this.removeById(operMonthReportEntityByMonth.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         //按站点生成各电站运维月报
 | 
			
		
	
		
			
				
					|  |  |  |  |         StationRunReportAllVO stationReportAllVO = operStationMonthReportService.getStationMonthReportV2(month, BeanUtil.copy(deptVO, DeptVO.class)); | 
			
		
	
		
			
				
					|  |  |  |  |         if (ObjectUtil.isNotEmpty(stationReportAllVO)) { | 
			
		
	
		
			
				
					|  |  |  |  |             OperMonthReportEntity operMonthReportEntity = new OperMonthReportEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |             operMonthReportEntity.setMonth(month); | 
			
		
	
		
			
				
					|  |  |  |  |             operMonthReportEntity.setType(DictConstant.MONTH_REPORT_STATION); | 
			
		
	
		
			
				
					|  |  |  |  |             operMonthReportEntity.setCreateDept(deptVO.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |             operMonthReportEntity.setStationCode(deptVO.getId().toString()); | 
			
		
	
		
			
				
					|  |  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |  |                 operMonthReportEntity.setObject(ObjectHelper.obj2byte(stationReportAllVO)); | 
			
		
	
		
			
				
					|  |  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                 log.error("生成统计月报失败{}", e.toString()); | 
			
		
	
		
			
				
					|  |  |  |  |                 e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             //修改为每运行一次,保存一次
 | 
			
		
	
		
			
				
					|  |  |  |  |             this.save(operMonthReportEntity); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |