From f5ff2db99121dd082b553f1652ff0c619d80a45b Mon Sep 17 00:00:00 2001 From: ty <1577900710@qq.com> Date: Tue, 23 Apr 2024 21:08:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=9C=88=E6=8A=A5=E7=94=9F=E6=88=90=E5=92=8C=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/controller/MonthReportController.java | 14 +++++ .../schedule/OperStationCreateMonthReport.java | 6 ++- .../report/service/IMonthReportService.java | 3 ++ .../service/impl/MonthReportServiceImpl.java | 61 +++++++++++++++++++--- .../impl/OperStationMonthReportServiceImpl.java | 17 +++--- .../hzims/operational/report/vo/RunReportVO.java | 4 +- .../allTicket/fegin/TicketInfoAllClient.java | 17 +++--- 7 files changed, 96 insertions(+), 26 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/MonthReportController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/MonthReportController.java index a9f3e2a..01bd8fb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/MonthReportController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/MonthReportController.java @@ -75,6 +75,20 @@ public class MonthReportController { StationRunReportAllVO stationReportAllVO = monthReportService.getStationMonthReportByStationCode(deptId,month); return R.data(stationReportAllVO); } + + @ApiLog + @GetMapping("/setStationMonthReportByStationCode") + @ApiOperation(value = "根据站点编码生成站点月报",notes = "根据站点编码获取站点月报") + @ApiOperationSupport(order = 1) + @OperationAnnotation(moduleName = "生产月报", + title = "生成统计月报",operatorType = OperatorType.MOBILE,businessType = BusinessType.GENCODE, + action = "生成统计月报") + public void setStationMonthReportByStationCode(@RequestParam("deptId") Long deptId,@RequestParam("month") String month) throws Exception { +// LocalDate startDate = DateUtil.getFirstDayByYearMonth(month); +// LocalDate endDate = DateUtil.getLastDayByYearMonth(month); +// return R.data(taskMonthService.getStationMonthReport(startDate,endDate,deptId.toString())); + monthReportService.setStationMonthReportByStationCode(deptId,month); + } // // @ApiLog // @GetMapping("/getPersonalMonthReport") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/schedule/OperStationCreateMonthReport.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/schedule/OperStationCreateMonthReport.java index f71d305..8a82adb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/schedule/OperStationCreateMonthReport.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/schedule/OperStationCreateMonthReport.java @@ -61,6 +61,7 @@ public class OperStationCreateMonthReport { eq(OperMonthReportEntity::getMonth,yearAndMonth); eq(OperMonthReportEntity::getType, DictConstant.MONTH_REPORT_STATION); eq(OperMonthReportEntity::getStationCode, deptVO.getId()); + eq(OperMonthReportEntity::getIsDeleted, 0); }}); if(CollectionUtil.isEmpty(operMonthReportEntityList)){ //按站点生成各电站运维月报 @@ -76,15 +77,18 @@ public class OperStationCreateMonthReport { entityList.add(operMonthReportEntity); } catch (IOException e) { e.printStackTrace(); + log.error(e.toString()); } + //修改为每运行一次,保存一次 + monthReportService.save(operMonthReportEntity); } } else{ log.info("该月{}已生成月报",deptVO.getDeptName()); } }//); - monthReportService.saveBatch(entityList); log.info("---{}月份电站月报生成完成---",yearAndMonth); + log.info("---{}月份电站月报生成完成---"+entityList.toString()); return new ReturnT<>("SUCCESS"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IMonthReportService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IMonthReportService.java index f9b415f..7c6b1a5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IMonthReportService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/IMonthReportService.java @@ -5,6 +5,7 @@ import com.hnac.hzims.operational.report.vo.StationReportAllVO; import com.hnac.hzims.operational.report.entity.OperMonthReportEntity; import com.hnac.hzims.operational.report.vo.StationRunReportAllVO; import org.springblade.core.mp.base.BaseService; +import org.springblade.core.tool.api.R; public interface IMonthReportService extends BaseService { /** @@ -16,6 +17,8 @@ public interface IMonthReportService extends BaseService */ StationRunReportAllVO getStationMonthReportByStationCode(Long deptId, String month) throws Exception; + void setStationMonthReportByStationCode(Long deptId, String month) throws Exception; + /** * 查询个人月报 * @param month diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/MonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/MonthReportServiceImpl.java index be01b60..02b30ed 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/MonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/MonthReportServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.operational.report.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.report.constants.DictConstant; import com.hnac.hzims.operational.report.service.IOperPersonalMonthReportService; import com.hnac.hzims.operational.report.service.IOperStationMonthReportService; import com.hnac.hzims.operational.report.vo.PersonalMonthReportVO; @@ -15,14 +16,18 @@ import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; import org.springblade.system.vo.DeptVO; import org.springframework.stereotype.Service; +import java.io.IOException; import java.time.YearMonth; +import java.util.List; @Service @AllArgsConstructor @@ -37,24 +42,64 @@ public class MonthReportServiceImpl extends BaseServiceImpl(){{ + 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{ - OperMonthReportEntity operMonthReportEntity = this.getOne(new LambdaQueryWrapper(){{ - eq(OperMonthReportEntity::getMonth,month); - eq(OperMonthReportEntity::getStationCode, dept.getId()); - orderByDesc(OperMonthReportEntity::getObject); - last("limit 1;"); - }}); 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() {{ + 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 PersonalMonthReportVO getPersonalMonthReport(String month) throws Exception { // PersonalMonthReportVO personalMonthReportVO = new PersonalMonthReportVO(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java index 3f193e8..95b22cf 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java @@ -75,9 +75,7 @@ import java.time.LocalTime; import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -114,7 +112,11 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor /** * 通过线程池异步获取月报各模块内容 主要分为八块内容 **/ - private static final ExecutorService pool = Executors.newFixedThreadPool(POOL_QUANTITY); +// private static final ExecutorService pool = Executors.newFixedThreadPool(POOL_QUANTITY); + private static final ExecutorService pool = new ThreadPoolExecutor(8, 10, + 1, TimeUnit.HOURS, new ArrayBlockingQueue<>(5, true), + Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); + /** * 统计月报-电站-对内 @@ -1222,9 +1224,10 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor int sum = stationReportAllVo.getTicketInfoStatisticVOList().stream().filter(s->"合计".equals(s.getTicketInfoType())).mapToInt(TicketInfoStatisticVO::getTicketInfoNumber).sum(); int qualifiedNum = stationReportAllVo.getTicketInfoStatisticVOList().stream().filter(s->"合计".equals(s.getTicketInfoType())).mapToInt(TicketInfoStatisticVO::getTicketInfoQualifiedNum).sum(); // double ticketInfoProportion = new BigDecimal(qualifiedNum ).divide(sum,2, RoundingMode.HALF_DOWN).doubleValue(); - double ticketInfoProportion = sum == 0 ? 0 : new BigDecimal(qualifiedNum).divide(new BigDecimal(sum*100),2, - RoundingMode.HALF_DOWN).doubleValue(); - String phenomenonConclusion = "5、本月开票%s张,合格率%s;"; + double ticketInfoProportion = sum == 0 ? 0 : new BigDecimal(qualifiedNum).divide(new BigDecimal(sum),2, + RoundingMode.HALF_DOWN).multiply(new BigDecimal(100)) + .setScale(2,RoundingMode.HALF_DOWN).doubleValue(); + String phenomenonConclusion = "5、本月开票%s张,合格率百分之%s%%"; conclusion.append(String.format(phenomenonConclusion, sum, ticketInfoProportion)).append(";\r\n"); }else { conclusion.append("5、本月未开票;\r\n"); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunReportVO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunReportVO.java index 9a92921..5eefcbf 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunReportVO.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunReportVO.java @@ -17,11 +17,11 @@ public class RunReportVO implements Serializable { @ApiModelProperty("姓名") private String userName; @ApiModelProperty("完成次数") - private Integer completeNum; + private Integer completeNum=0; @ApiModelProperty("完成任务数量") private List completeList; @ApiModelProperty("未完成次数") - private Integer incompleteNum; + private Integer incompleteNum=0; @ApiModelProperty("完成任务数量") private List incompleteList; @ApiModelProperty("备注") diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/allTicket/fegin/TicketInfoAllClient.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/allTicket/fegin/TicketInfoAllClient.java index 5eaa0a5..0101bfa 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/allTicket/fegin/TicketInfoAllClient.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/allTicket/fegin/TicketInfoAllClient.java @@ -71,15 +71,16 @@ public class TicketInfoAllClient implements ITicketInfoAllClient { TicketInfoStatisticVO ticketInfoStatisticVO=new TicketInfoStatisticVO(); ticketInfoStatisticVO.setTicketInfoType("合计"); int sum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoNumber).sum(); - int CompleteNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoCompleteNum).sum(); - int InvalidatedNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoInvalidatedNum).sum(); - int QualifiedNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoQualifiedNum).sum(); - Double Proportion = new BigDecimal(QualifiedNum).divide(new BigDecimal(sum),2, RoundingMode.UP).doubleValue(); + int completeNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoCompleteNum).sum(); + int invalidatedNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoInvalidatedNum).sum(); + int qualifiedNum = workTicketStatistic.stream().mapToInt(TicketInfoStatisticVO::getTicketInfoQualifiedNum).sum(); + Double proportion = new BigDecimal(qualifiedNum).divide(new BigDecimal(sum),2, RoundingMode.UP) + .multiply(new BigDecimal(100)).setScale(2, RoundingMode.UP).doubleValue(); ticketInfoStatisticVO.setTicketInfoNumber(sum); - ticketInfoStatisticVO.setTicketInfoCompleteNum(CompleteNum); - ticketInfoStatisticVO.setTicketInfoInvalidatedNum(InvalidatedNum); - ticketInfoStatisticVO.setTicketInfoQualifiedNum(QualifiedNum); - ticketInfoStatisticVO.setTicketInfoProportion(Proportion); + ticketInfoStatisticVO.setTicketInfoCompleteNum(completeNum); + ticketInfoStatisticVO.setTicketInfoInvalidatedNum(invalidatedNum); + ticketInfoStatisticVO.setTicketInfoQualifiedNum(qualifiedNum); + ticketInfoStatisticVO.setTicketInfoProportion(proportion); workTicketStatistic.add(ticketInfoStatisticVO); }else { TicketInfoStatisticVO ticketInfoStatisticVO=new TicketInfoStatisticVO();