From 0fc8c9d43de7e74e192300fca708e2b1eb904775 Mon Sep 17 00:00:00 2001 From: tyty Date: Wed, 12 Apr 2023 18:56:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=80=BC=E7=8F=AD?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=9A=84=E5=AF=BC=E5=87=BA=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../duty/controller/ImsDutyRecController.java | 11 +++ .../duty/service/IImsAnalyseExampleService.java | 6 +- .../service/impl/ImsAnalyseExampleServiceImpl.java | 89 ++++++++++++++++++++-- .../duty/service/impl/ImsDutyMainServiceImpl.java | 2 +- .../duty/service/impl/ImsDutyRecServiceImpl.java | 2 + 5 files changed, 101 insertions(+), 9 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java index bc36ed1..ce66e89 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyRecController.java @@ -31,6 +31,7 @@ import org.springblade.flow.core.entity.BladeFlow; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -268,6 +269,16 @@ public class ImsDutyRecController extends BladeController { public R queryAnalyseExampleData( AnalyzeDataCondition analyzeDataCondition) { return iImsAnalyseExampleService.queryAnalyseExampleData(analyzeDataCondition); } + /** + * 导出分析实例数据 + */ + @PostMapping("/outPutAnalyseExampleData") + @ApiOperationSupport(order = 6) + @ApiOperation(value = "导出分析实例数据", notes = "传入analyseExample") + public void outPutAnalyseExampleData(HttpServletResponse response, @Valid @RequestBody AnalyzeDataCondition analyzeDataCondition) { + iImsAnalyseExampleService.outPutAnalyseExampleData(response, analyzeDataCondition); + } + /** * 查询:分析实例模板 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java index 830a136..a2c2cc6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsAnalyseExampleService.java @@ -6,6 +6,8 @@ import org.springblade.core.mp.base.BaseService; import org.springblade.core.tool.api.R; import org.springblade.core.mp.support.Query; +import javax.servlet.http.HttpServletResponse; + /** * 服务类 * @@ -14,8 +16,6 @@ import org.springblade.core.mp.support.Query; public interface IImsAnalyseExampleService extends BaseService { - - R queryAnalyseExampleData(AnalyzeDataCondition analyzeDataCondition); R queryAnalyseExample(AnalyseExample analyseExample,Query query); @@ -23,4 +23,6 @@ public interface IImsAnalyseExampleService extends BaseService { R getAnalyseId(String projectId); R updateAnalyseExample(AnalyseExample analyseExample); + + void outPutAnalyseExampleData(HttpServletResponse response, AnalyzeDataCondition analyzeDataCondition); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java index 02d69f8..46dfbd9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsAnalyseExampleServiceImpl.java @@ -1,16 +1,22 @@ package com.hnac.hzims.operational.duty.service.impl; +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.duty.entity.AnalyseExample; import com.hnac.hzims.operational.duty.mapper.ImsAnalyseExampleMapper; -import com.hnac.hzims.operational.duty.mapper.ImsDutyMainMapper; import com.hnac.hzims.operational.duty.service.IImsAnalyseExampleService; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.StationClient; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataCondition; import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataList; +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.v5.analyse.AnalyseDataHandlerClient; @@ -18,16 +24,20 @@ import com.hnac.hzinfo.sdk.v5.analyse.vo.AnalseInstanceVO; import lombok.extern.slf4j.Slf4j; import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.*; +import java.util.stream.Collectors; /** @@ -38,8 +48,6 @@ import java.util.List; @Slf4j @Service public class ImsAnalyseExampleServiceImpl extends BaseServiceImpl implements IImsAnalyseExampleService { - @Resource - private ImsDutyMainMapper imsDutyMainMapper; @Autowired private IAnalyseDataSearchClient searchClient; @Autowired @@ -119,6 +127,75 @@ public class ImsAnalyseExampleServiceImpl extends BaseServiceImpl page = (HzPage) analyseExampleData.getData(); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 + String fileName = URLEncoder.encode( name, "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + if(page.getRecords()!=null){ + List> head=new ArrayList<>(); + List title = new ArrayList<>(Arrays.asList("时间")); + head.add(title); + List records = page.getRecords(); + AnalyzeDataList analyzeDataList = records.get(0); + //把时间加属性名称作为表头 + List stringList=analyzeDataList.getFields().stream().map(FieldsData::getFieldName).collect(Collectors.toList()); + for (String s : stringList) { + head.add(Arrays.asList(s)); + } + //把数据填充 + List> data=new ArrayList<>(); + for (int i = 0; i < records.size(); i++) { + List arrayData=new ArrayList<>(); + String date = DateUtil.format(records.get(i).getTs(), DateUtil.PATTERN_DATETIME); + arrayData.add(date); + List dataBefore = records.get(i).getFields().stream().map(FieldsData::getValue).collect(Collectors.toList()); + arrayData.addAll(dataBefore); + data.add(arrayData); + } + System.out.println("---------------- 数据详情 = " + records.toString()); + //ExcelWriter初始化 + ExcelWriter excelWriter = EasyExcel + .write(response.getOutputStream()) + .autoCloseStream(Boolean.TRUE) + .registerConverter(new LongStringConverter()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(45)) + .build(); + WriteSheet writeSheet = EasyExcel.writerSheet(1, "值班日志").head(head).build(); + excelWriter.write(data, writeSheet); + // 这里需要设置关闭流 + excelWriter.finish(); + + + } + } catch (Exception e) { + System.out.println("exportExcel = " + e.toString()); + // 重置response + response.reset(); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + Map map = new HashMap<>(); + map.put("success", "false"); + map.put("msg", "值班日志信息导出失败" + e.getMessage()); + try { + response.getWriter().println(JSONUtils.toJSONString(map)); + } catch (IOException e3) { + throw new ServiceException( "发生异常 :" + e.toString()); + } + } + + } + private QueryWrapper getQueryWrapper(AnalyseExample analyseExample) { QueryWrapper queryWrapper = new QueryWrapper(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java index e90ebfe..8bb0812 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java @@ -176,7 +176,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, id); + eq(ImsDutyMainPersonEntity::getDutyMainId, imsSchedulingVo.getId()); last("limit 1"); }}); imsSchedulingVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java index 3bafe24..fb42004 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyRecServiceImpl.java @@ -338,6 +338,8 @@ public class ImsDutyRecServiceImpl extends BaseServiceImpl() {{ eq(ImsDutyMainPersonEntity::getDutyMainId, entity.getId()); eq(ImsDutyMainPersonEntity::getDutyChargePerson, AuthUtil.getUserId()); + last(" limit 1"); + }}); if (ObjectUtil.isEmpty(groupEntity)&&ObjectUtil.isEmpty(personEntity)) { return R.success("您不是该班组负责人,不可交班!"); From ecb6cf634f84245a15eb53b176061f75bc6a8353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Wed, 12 Apr 2023 20:13:05 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E6=9F=A5=E8=AF=A2=E8=AE=BE=E5=A4=87=E8=AF=95?= =?UTF-8?q?=E9=AA=8C=20=E6=A0=B9=E6=8D=AE=E5=8C=BA=E5=9F=9F=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=E6=9F=A5=E8=AF=A2=E5=AE=89=E5=85=A8=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=20=E6=9C=88=E5=BA=A6=E8=87=AA=E6=9F=A5=20=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E5=9F=B9=E8=AE=AD=20=E5=AE=89=E5=85=A8=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E4=BC=9A=E8=AE=AE=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../defect/entity/OperDefectEntity.java | 2 + .../hzims/message/fegin/IMessageSmsClient.java | 2 + .../hnac/hzims/message/fegin/IPushMsgClient.java | 2 + .../message/vo/msgpushrecord/PushStatTypeVo.java | 1 - .../hzims/message/vo/msgpushrecord/PushStatVo.java | 3 - .../areamonthly/feign/CheckCompanyFeignClient.java | 48 + .../feign/SafeEquipmentTrialFeignClient.java | 35 + .../areamonthly/feign/SafeproductFeignClient.java | 48 + .../fallback/CheckCompanyFeignClientFallback.java | 41 + .../SafeEquipmentTrialFeignClientFallback.java | 30 + .../fallback/SafeproductFeignClientFallback.java | 40 + .../safeproduct/areamonthly/vo/CheckCompanyVo.java | 33 + .../safeproduct/areamonthly/vo/CheckMonthVo.java | 34 + .../areamonthly/vo/SafeEquipmentTrialVO.java | 23 + .../safeproduct/dto/SafeEquipmentTrialDTO.java | 10 + .../safeproduct/entity/CheckCompanyEntity.java | 13 + .../hzims/safeproduct/entity/CheckMonthEntity.java | 25 + .../message/mapper/MessagePushRecordMapper.java | 7 + .../message/mapper/MessagePushRecordMapper.xml | 43 +- .../service/impl/MessagePushRecordServiceImpl.java | 130 +- .../access/dto/OperAccessStatisticsDTO.java | 13 + .../access/mapper/OperAccessStatisticsMapper.java | 21 +- .../access/mapper/OperAccessStatisticsMapper.xml | 6 + .../service/IOperAccessStatisticsService.java | 1 - .../defect/controller/OperDefectController.java | 5 - .../defect/service/IOperDefectService.java | 10 + .../defect/service/impl/OperDefectServiceImpl.java | 1707 ++++++++++---------- .../web/AreaMonthlyDetailsController.java | 175 ++ .../main/service/AreaMonthlyDetailsService.java | 47 + .../impl/AreaMonthlyDetailsServiceImpl.java | 122 +- .../controller/CheckCompanyController.java | 3 +- .../controller/CheckMonthController.java | 27 + .../controller/SafeEquipmentTrialController.java | 3 +- .../hzims/safeproduct/mapper/CheckMonthMapper.java | 9 + .../hzims/safeproduct/mapper/CheckMonthMapper.xml | 27 + .../safeproduct/service/ICheckCompanyService.java | 3 +- .../safeproduct/service/ICheckMonthService.java | 9 + .../service/SafeEquipmentTrialService.java | 3 +- .../service/impl/CheckCompanyServiceImpl.java | 206 +-- .../service/impl/CheckMonthServiceImpl.java | 14 + .../impl/SafeEquipmentTrialServiceImpl.java | 162 +- 41 files changed, 2012 insertions(+), 1131 deletions(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/CheckCompanyFeignClient.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeEquipmentTrialFeignClient.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeproductFeignClient.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/CheckCompanyFeignClientFallback.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeEquipmentTrialFeignClientFallback.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeproductFeignClientFallback.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckCompanyVo.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckMonthVo.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/SafeEquipmentTrialVO.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java index fba3124..7a5cbe2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/entity/OperDefectEntity.java @@ -104,9 +104,11 @@ public class OperDefectEntity extends TenantEntity { /** * 区域Id */ + @TableField(exist = false) private String areaId; /** * 年月 */ + @TableField(exist = false) private YearMonth yearMonth; } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageSmsClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageSmsClient.java index 0296932..be6eca0 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageSmsClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageSmsClient.java @@ -4,6 +4,8 @@ package com.hnac.hzims.message.fegin; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.req.SmsReq; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IPushMsgClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IPushMsgClient.java index 7fe7ccc..4f780ef 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IPushMsgClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IPushMsgClient.java @@ -7,6 +7,8 @@ import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.dto.WsPushDto; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatTypeVo.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatTypeVo.java index 6ef7e4c..c7fc6a1 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatTypeVo.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatTypeVo.java @@ -27,7 +27,6 @@ public class PushStatTypeVo { */ private String businessClassifyName; - /** * 业务分类统计 */ diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatVo.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatVo.java index 340629c..8c2b335 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatVo.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/PushStatVo.java @@ -29,15 +29,12 @@ public class PushStatVo { */ private Integer status; - - /** * 状态名称 */ private String statusName; - /** * 统计数量 */ diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/CheckCompanyFeignClient.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/CheckCompanyFeignClient.java new file mode 100644 index 0000000..9e7f665 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/CheckCompanyFeignClient.java @@ -0,0 +1,48 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.safeproduct.Constants; +import com.hnac.hzims.safeproduct.areamonthly.feign.fallback.CheckCompanyFeignClientFallback; +import com.hnac.hzims.safeproduct.areamonthly.feign.fallback.SafeproductFeignClientFallback; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import io.swagger.annotations.ApiOperation; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 19:35 + */ +@FeignClient(value = Constants.APP_NAME, fallback = CheckCompanyFeignClientFallback.class) +public interface CheckCompanyFeignClient { + + /** + * 查询安全检查 + * + * @param req + * @param query + * @return + */ + @GetMapping("/CheckCompany/list") + @ApiOperationSupport(order = 50) + @ApiOperation(value = "分页", notes = "查询条件:startDate,endDate,status") + R> list(CheckCompanyEntity req, Query query); + + + /** + * 详情 + * @param id + * @return + */ + @GetMapping("/detail") + @ApiOperationSupport(order = 40) + @ApiOperation(value = "详情", notes = "传入id") + public R detail(@RequestParam Long id); +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeEquipmentTrialFeignClient.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeEquipmentTrialFeignClient.java new file mode 100644 index 0000000..1781d1b --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeEquipmentTrialFeignClient.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.safeproduct.Constants; +import com.hnac.hzims.safeproduct.areamonthly.feign.fallback.CheckCompanyFeignClientFallback; +import com.hnac.hzims.safeproduct.areamonthly.feign.fallback.SafeEquipmentTrialFeignClientFallback; +import com.hnac.hzims.safeproduct.areamonthly.vo.SafeEquipmentTrialVO; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import io.swagger.annotations.ApiOperation; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 19:50 + */ +@FeignClient(value = Constants.APP_NAME, fallback = SafeEquipmentTrialFeignClientFallback.class) +public interface SafeEquipmentTrialFeignClient { + + + /** + * 分页 + */ + @GetMapping("/list") + @ApiOperationSupport(order = 50) + @ApiOperation(value = "分页", notes = "查询条件:createDept,fileName,startTime,endTime") + public R> list(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query) ; + +} + diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeproductFeignClient.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeproductFeignClient.java new file mode 100644 index 0000000..a12b162 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/SafeproductFeignClient.java @@ -0,0 +1,48 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.safeproduct.Constants; +import com.hnac.hzims.safeproduct.areamonthly.feign.fallback.SafeproductFeignClientFallback; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckMonthVo; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; +import io.swagger.annotations.ApiOperation; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 18:06 + */ +@FeignClient(value = Constants.APP_NAME, fallback = SafeproductFeignClientFallback.class) +public interface SafeproductFeignClient { + + /** + * 分页查询安全生产会议次数 + */ + @GetMapping("/checkMonth/listconferenceScope/{page}/{size}") + @ApiOperationSupport(order = 50) + @ApiOperation(value = "分页", notes = "查询条件:month,status,createDept") + public R> listconferenceScope(@PathVariable Long page, @PathVariable Long size, CheckMonthEntity req); + + + /** + * 详情 + */ + @GetMapping("/checkMonth/detail") + @ApiOperationSupport(order = 40) + @ApiOperation(value = "详情", notes = "传入id") + public R detail(@RequestParam Long id); + + + +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/CheckCompanyFeignClientFallback.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/CheckCompanyFeignClientFallback.java new file mode 100644 index 0000000..b756639 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/CheckCompanyFeignClientFallback.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign.fallback; + +import com.hnac.hzims.safeproduct.areamonthly.feign.CheckCompanyFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 19:35 + */ +@Service +public class CheckCompanyFeignClientFallback implements CheckCompanyFeignClient { + /** + * 查询安全检查 + * + * @param req + * @param query + * @return + */ + @Override + public R> list(CheckCompanyEntity req, Query query) { + return R.fail("远程调用失败"); + } + + /** + * 详情 + * + * @param id + * @return + */ + @Override + public R detail(Long id) { + return null; + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeEquipmentTrialFeignClientFallback.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeEquipmentTrialFeignClientFallback.java new file mode 100644 index 0000000..d0ae375 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeEquipmentTrialFeignClientFallback.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign.fallback; + +import com.hnac.hzims.safeproduct.areamonthly.feign.SafeEquipmentTrialFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.vo.SafeEquipmentTrialVO; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 19:50 + */ +@Service +public class SafeEquipmentTrialFeignClientFallback implements SafeEquipmentTrialFeignClient { + + /** + * 分页 + * + * @param safeEquipmentTrialDTO + * @param query + */ + @Override + public R> list(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query) { + return R.fail("远程调用失败"); + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeproductFeignClientFallback.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeproductFeignClientFallback.java new file mode 100644 index 0000000..b5c22c9 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/feign/fallback/SafeproductFeignClientFallback.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.safeproduct.areamonthly.feign.fallback; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.areamonthly.feign.SafeproductFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckMonthVo; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; +import org.springblade.core.mp.support.BladePage; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 18:07 + */ +@Service +public class SafeproductFeignClientFallback implements SafeproductFeignClient { + /** + * 分页查询安全生产会议次数 + * + * @param page + * @param size + * @param req + */ + @Override + public R> listconferenceScope(Long page, Long size, CheckMonthEntity req) { + return R.fail("远程调用失败"); + } + + /** + * 详情 + * + * @param id + */ + @Override + public R detail(Long id) { + return R.fail("远程调用失败"); + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckCompanyVo.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckCompanyVo.java new file mode 100644 index 0000000..b925505 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckCompanyVo.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.safeproduct.areamonthly.vo; + +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; +import java.util.Map; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 19:22 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CheckCompanyVo extends CheckCompanyEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("创建人名称") + private String createUserName; + + @ApiModelProperty("状态文本值") + private String statusText; + + @ApiModelProperty(value = "检查项实例") + List> items; +// +// @ApiModelProperty(value = "检查项实例") +// List> list; +} \ No newline at end of file diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckMonthVo.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckMonthVo.java new file mode 100644 index 0000000..9a04af7 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/CheckMonthVo.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.safeproduct.areamonthly.vo; + +import com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 18:09 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CheckMonthVo extends CheckMonthEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("创建人名称") + private String createUserName; + + @ApiModelProperty("部门名称") + private String deptName; + + @ApiModelProperty("状态文本值") + private String statusText; + + @ApiModelProperty(value = "检查项实例") + List items; +} + diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/SafeEquipmentTrialVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/SafeEquipmentTrialVO.java new file mode 100644 index 0000000..983fe83 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/areamonthly/vo/SafeEquipmentTrialVO.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.safeproduct.areamonthly.vo; + +import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/4/12 20:04 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class SafeEquipmentTrialVO extends SafeEquipmentTrialEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("创建人名称") + private String createUserName; +} + diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/SafeEquipmentTrialDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/SafeEquipmentTrialDTO.java index f460f6e..2e6e07f 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/SafeEquipmentTrialDTO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/SafeEquipmentTrialDTO.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.format.annotation.DateTimeFormat; +import java.time.YearMonth; import java.util.List; @@ -36,4 +37,13 @@ public class SafeEquipmentTrialDTO extends SafeEquipmentTrialEntity { @ApiModelProperty("创建部门集合") private List deptList; + + + @ApiModelProperty(value = "区域id") + private String areaId; + + + + @ApiModelProperty(value = "年月") + private YearMonth yearMonth; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckCompanyEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckCompanyEntity.java index 11b83e0..93582aa 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckCompanyEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckCompanyEntity.java @@ -1,5 +1,6 @@ package com.hnac.hzims.safeproduct.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; @@ -11,6 +12,7 @@ import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.time.LocalDateTime; +import java.time.YearMonth; /** * Created by Sam Huang 2022/5/6 8:16 @@ -47,4 +49,15 @@ public class CheckCompanyEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "检查机构") private String orgId; + + @TableField(exist = false) + @ApiModelProperty(value = "区域id") + private String areaId; + + + + @TableField(exist = false) + @ApiModelProperty(value = "年月") + private YearMonth yearMonth; + } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java index 60d4019..c91da19 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CheckMonthEntity.java @@ -1,5 +1,6 @@ package com.hnac.hzims.safeproduct.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; @@ -10,6 +11,7 @@ import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; import java.io.Serializable; +import java.time.YearMonth; /** * Created by Sam Huang 2022/5/6 8:16 @@ -32,4 +34,27 @@ public class CheckMonthEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "核查建议") private String suggest; + + /** + * 区域Id + */ + @TableField(exist = false) + @ApiModelProperty(value = "区域Id") + private String areaId; + + + /** + * 年月 + */ + @TableField(exist = false) + private YearMonth yearMonth; + + + + @TableField(exist = false) + private String itemName; + + + + } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.java index de23097..c317ec1 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.java @@ -36,4 +36,11 @@ public interface MessagePushRecordMapper extends UserDataScopeBaseMapper pushStat(@Param("vo") MessagePushRecordEntityVo vo); + + /** + * 查询出状态信息 + * @return + */ + List selectByStatus(); + } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml index a9fe853..0412c8c 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml @@ -5,28 +5,26 @@ - - - - - + + + + + - - - select PUSHER_NAME pusherName, - BUSINESS_CLASSIFY businessClassify, - count(1) count + select PUSHER_NAME pusherName, + BUSINESS_CLASSIFY businessClassify, + count(1) count from hzims_message_push_record IS_DELETED = 0 and - STATION_CODE = #{vo.stationCode} + DEPT_ID = #{vo.stationCode} and @@ -80,11 +78,10 @@ - - + @@ -93,13 +90,13 @@ + + \ No newline at end of file diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index 4455f42..d98330d 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.utils.CacheUtil; @@ -56,71 +57,70 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl { - throw new ServiceException("发送消息失败!"); - }); - // 更新推送状态以及推送时间 - LambdaUpdateWrapper luw = Wrappers.lambdaUpdate() - .set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) - .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) - .eq(MessagePushRecordEntity::getId, id); - return this.update(luw); - } + @Override + public Boolean send(Long id) { + MessagePushRecordEntity record = this.getById(id); + IMessageService messageSend = MessageFactory.getMessageSend(record.getType()); + Boolean result = messageSend.send(record); + Assert.isTrue(result, () -> { + throw new ServiceException("发送消息失败!"); + }); + // 更新推送状态以及推送时间 + LambdaUpdateWrapper luw = Wrappers.lambdaUpdate().set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()).set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS).eq(MessagePushRecordEntity::getId, id); + return this.update(luw); + } - /** @Author hx + /** + * @return java.lang.Boolean 推送解雇 + * @Author hx * @Description 保存并推送消息 * @Date 2023/4/12 10:23 * @Param [request] 消息记录 - * @return java.lang.Boolean 推送解雇 **/ - @Override - @Transactional(rollbackFor = Exception.class) - public Boolean saveAndSend(MessagePushRecordEntity request) { + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean saveAndSend(MessagePushRecordEntity request) { LocalDateTime now = LocalDateTime.now(); - if(MessageConstants.IMMEDIATELY.equals(request.getPushType())) { + if (MessageConstants.IMMEDIATELY.equals(request.getPushType())) { request.setPlanTime(now); request.setPushTime(now); // 立即推送消息 - if(this.save(request) && Func.isNotEmpty(request.getId())) { + if (this.save(request) && Func.isNotEmpty(request.getId())) { return this.send(request.getId()); } throw new ServiceException("保存消息失败!"); - } - else if(MessageConstants.PLAN.equals(request.getPushType())) { + } else if (MessageConstants.PLAN.equals(request.getPushType())) { return this.save(request); - } - else { + } else { throw new ServiceException("推送类型只能为即时推送或计划推送"); } } - /** - * 获取 QueryWrapper - * @param request 查询条件 - * @return QueryWrapper - */ - private LambdaQueryWrapper getQueryWrapper(MessagePushRecordEntity request) { - LambdaQueryWrapper lambda = Condition.getQueryWrapper(request).lambda(); - if(Func.isNotEmpty(request.getStartTime())) { - lambda.ge(MessagePushRecordEntity::getPushTime,request.getStartTime()); - } - if(Func.isNotEmpty(request.getEndTime())) { - lambda.le(MessagePushRecordEntity::getPushTime,request.getEndTime()); - } - lambda.orderByDesc(MessagePushRecordEntity::getPushTime); - return lambda; - } + /** + * 获取 QueryWrapper + * + * @param request 查询条件 + * @return QueryWrapper + */ + private LambdaQueryWrapper getQueryWrapper(MessagePushRecordEntity request) { + LambdaQueryWrapper lambda = Condition.getQueryWrapper(request).lambda(); + if (Func.isNotEmpty(request.getStartTime())) { + lambda.ge(MessagePushRecordEntity::getPushTime, request.getStartTime()); + } + if (Func.isNotEmpty(request.getEndTime())) { + lambda.le(MessagePushRecordEntity::getPushTime, request.getEndTime()); + } + lambda.orderByDesc(MessagePushRecordEntity::getPushTime); + return lambda; + } + /** * 短信推送统计 */ @@ -136,8 +136,7 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl> collect = - messagePushRecordVos.stream().collect(Collectors.groupingBy(MessagePushRecordVo::getType)); + Map> collect = messagePushRecordVos.stream().collect(Collectors.groupingBy(MessagePushRecordVo::getType)); List messagePushRecordTypeVos = new ArrayList<>(); //封装数据 @@ -195,21 +194,44 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl pushStat(MessagePushRecordEntityVo vo) { List pushStatTypeVos = baseMapper.pushStat(vo); pushStatTypeVos.forEach(item -> { + //查询出状态信息 + List statusList = baseMapper.selectByStatus(); //业务类型名称 String businessClassify = item.getBusinessClassify(); String businessTypeName = this.getBusinessClassifyByName(businessClassify); item.setBusinessClassifyName(businessTypeName); List pushStatList = item.getPushStatList(); - pushStatList.forEach(pushStat -> { - Integer status = pushStat.getStatus(); - //状态名称 - String name = this.getStatusByName(status); - pushStat.setStatusName(name); + List newPushStatList = new ArrayList<>(); + for (PushStatVo pushStat : pushStatList) { //业务类型名称 String businessClassifyPushStat = pushStat.getBusinessClassify(); String businessTypeNamePushStat = this.getBusinessClassifyByName(businessClassifyPushStat); pushStat.setBusinessClassifyName(businessTypeNamePushStat); - }); + Integer status = pushStat.getStatus(); + //如果list 包含这条数删除 + if (statusList.contains(status)) { + statusList.remove(status); + } + //状态名称 + String name = this.getStatusByName(status); + pushStat.setStatusName(name); + newPushStatList.add(pushStat); + } + //如何list不为空补0 + if (CollectionUtils.isNotEmpty(statusList)) { + for (int i = 0; i < statusList.size(); i++) { + PushStatVo pushStat = new PushStatVo(); + int status = statusList.get(i); + pushStat.setStatus(status); + pushStat.setPower(0L); + pushStat.setBusinessClassify(businessClassify); + pushStat.setBusinessClassifyName(businessTypeName); + pushStat.setStatusName(this.getStatusByName(status)); + newPushStatList.add(pushStat); + } + } + + item.setPushStatList(newPushStatList); }); return pushStatTypeVos; } @@ -218,12 +240,12 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl getPersonalUnreadMessage() { QueryWrapper query = Wrappers.query(); query.select("business_classify businessClassify,count(0) todoNum"); - query.eq("account",AuthUtil.getUserId()); + query.eq("account", AuthUtil.getUserId()); query.groupBy("business_classify"); List> list = this.listMaps(query); return list.stream().map(map -> { UnreadMessageVO unreadMessageVO = Func.toBean(map, UnreadMessageVO.class); - unreadMessageVO.setBusinessName(DictCache.getValue("businessClassify",unreadMessageVO.getBusinessClassify())); + unreadMessageVO.setBusinessName(DictCache.getValue("businessClassify", unreadMessageVO.getBusinessClassify())); return unreadMessageVO; }).collect(Collectors.toList()); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java index 8e0f492..0091f31 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/OperAccessStatisticsDTO.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import com.hnac.hzims.operational.access.entity.OperAccessStatisticsEntity; +import java.time.YearMonth; import java.util.List; /** @@ -25,4 +26,16 @@ public class OperAccessStatisticsDTO extends OperAccessStatisticsEntity { @ApiModelProperty(value = "创建机构集合") private List deptIds; + /** + * 年月 + */ + private YearMonth yearMonth; + + + /** + * 区域Id + */ + private String areaId; + + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.java index 6273e9b..80d3b8d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.java @@ -3,13 +3,13 @@ package com.hnac.hzims.operational.access.mapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.access.dto.OperAccessStatisticsDTO; import com.hnac.hzims.operational.access.entity.OperAccessStatisticsEntity; +import org.apache.ibatis.annotations.Param; import org.springblade.core.datascope.annotation.UserDataAuth; import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; import java.util.List; /** - * * Mapper 接口 * * @author xiashandong @@ -18,14 +18,13 @@ import java.util.List; public interface OperAccessStatisticsMapper extends UserDataScopeBaseMapper { - - /** - * 自定义分页 - * - * @param page - * @param dto - * @return - */ - @UserDataAuth - List selectPageList(IPage page, OperAccessStatisticsDTO dto); + /** + * 自定义分页 + * + * @param page + * @param dto + * @return + */ + @UserDataAuth + List selectPageList(IPage page, @Param("dto") OperAccessStatisticsDTO dto); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.xml index 949afc0..e63515d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/mapper/OperAccessStatisticsMapper.xml @@ -37,6 +37,12 @@ and OS.PLAN_END_TIME <= #{dto.planEndTime} + + and OS.CREATE_DEPT = #{dto.areaId} + + + and date_format(os.CREATE_TIME,'%Y-%m') = #{dto.yearMonth} + ORDER BY OS.CREATE_TIME DESC diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessStatisticsService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessStatisticsService.java index cfc2c2e..417d9ca 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessStatisticsService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/IOperAccessStatisticsService.java @@ -5,7 +5,6 @@ import com.hnac.hzims.operational.access.dto.OperAccessStatisticsDTO; import com.hnac.hzims.operational.access.entity.OperAccessStatisticsEntity; import com.hnac.hzims.operational.access.vo.OperAccessStatisticsVO; import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import javax.servlet.http.HttpServletResponse; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java index dd4a6a2..1ec49af 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/controller/OperDefectController.java @@ -85,11 +85,6 @@ public class OperDefectController extends BladeController { if (defect.getEndTime() != null) { queryWrapper.le(OperDefectEntity::getCreateTime, defect.getEndTime()); } - - queryWrapper.eq(StringUtils.isNotBlank(defect.getAreaId()), BaseEntity::getCreateDept, defect.getCreateDept()); - - queryWrapper.apply(defect.getYearMonth() != null,"date_format(CREATE_TIME,'%Y-%m')", defect.getYearMonth()); - queryWrapper.orderByDesc(OperDefectEntity::getActStartTime); IPage pages = defectService.page(Condition.getPage(query), queryWrapper); IPage vos = OperDefectWrapper.build().pageVO(pages); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java index abd8d0f..f1e652b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IOperDefectService.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.defect.service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.operational.defect.entity.OperDefectEntity; import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; import com.hnac.hzims.operational.defect.vo.OperDefectVO; @@ -88,4 +90,12 @@ public interface IOperDefectService extends BaseService { boolean updateDefectInfo(OperDefectEntity entity); boolean updateDefectHanderState(OperDefectEntity entity); + + /** + * 分页查询 + * @param operDefectEntityPage + * @param defect + * @return + */ + IPage selectPage(Page operDefectEntityPage, OperDefectEntity defect); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java index 625faab..d5df747 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/OperDefectServiceImpl.java @@ -2,7 +2,10 @@ package com.hnac.hzims.operational.defect.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.operational.access.constants.AccessConstants; import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity; import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; @@ -36,6 +39,7 @@ import org.apache.poi.ss.util.CellRangeAddress; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.secure.utils.AuthUtil; @@ -69,7 +73,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** - * 服务实现类 + * 服务实现类 * * @author Chill */ @@ -77,857 +81,856 @@ import java.util.stream.Collectors; @AllArgsConstructor public class OperDefectServiceImpl extends BaseServiceImpl implements IOperDefectService { - private static final Logger logger = LoggerFactory.getLogger(OperDefectServiceImpl.class); - - private final IFlowClient flowClient; - - private final OperDefectMapper operDefectMapper; - - private final IUserClient userClient; - - private final OperPhenomenonMapper operPhenomenonMapper; - - /** - * 开始问题处理流程 - * 问题处理流程的第一个处理节点人key 必须是 problemUser - * @param - */ - @Override - public void startFlow(OperPhenomenonEntity phenomenonEntity, OperDefectEntity defectEntity){ - User handler = UserCache.getUser(phenomenonEntity.getHandler()); - String handlerName = handler == null ? "" : handler.getName(); - String sourceName = DictCache.getValue(DefectConstant.SOURCE_CODE_DICT_KEY,phenomenonEntity.getSourceCode()); - String processName = "【" + sourceName + "】" + handlerName + " 发起的缺陷【" + phenomenonEntity.getDefectCode() + "】的问题处理流程"; - defectEntity.setCreateUser(phenomenonEntity.getCreateUser()); - defectEntity.setCreateDept(phenomenonEntity.getCreateDept()); - defectEntity.setTenantId(phenomenonEntity.getTenantId()); - save(defectEntity); - - Kv variables = Kv.create() - .set(ProcessConstant.TASK_VARIABLE_CREATE_USER, "taskUser_" + phenomenonEntity.getCreateUser()) - .set(DefectConstant.PROCESS_VARIABLE_HANDLE_USER, "taskUser_" + phenomenonEntity.getHandler()) - ; - R result = flowClient.startProcessInstanceContainNameByKey(defectEntity.getProcDefId(), FlowUtil.getBusinessKey("hzims_oper_defect",String.valueOf(defectEntity.getId())), processName, variables); - if (result.isSuccess()) { - BladeFlow flow = result.getData(); - log.debug("流程已启动,流程ID:" + flow.getProcessInstanceId()); - // 返回流程id写入defect - defectEntity.setProcessInstanceId(flow.getProcessInstanceId()); - defectEntity.setHandleStatus(DefectConstant.DefectHandlerStatusEnum.HANDLING_STATUS.getStatus().toString()); - updateById(defectEntity); - } else { - throw new ServiceException("开启流程失败,code="+result.getCode()); - } - - } - - - /** - * 处理问题 - * @param flow - * @return - */ - @Override - public boolean handleProcess(BladeFlow flow) { - if(!invalidHandleProcess(flow.getProcessInstanceId())){ - throw new ServiceException("当前缺陷开具了检修计划,需等任务执行完成才能处理缺陷"); - } - ComleteTask task = new ComleteTask(); - task.setTaskId(flow.getTaskId()); - task.setComment(flow.getComment()); - task.setAttachments(flow.getAttachments()); - task.setFlag(flow.getFlag()); - task.setVariables(flow.getVariables()); - Map map = flow.getVariables(); - - flowClient.completeTask(task); - Integer status = ProcessConstant.ProcessInstanceStatusEnum.running.ordinal(); - R result = flowClient.queryProcessInstanceStatus(flow.getProcessInstanceId()); - if(result.isSuccess()){ - status = ProcessConstant.ProcessInstanceStatusEnum.over.name().equals(result.getData())?ProcessConstant.ProcessInstanceStatusEnum.over.ordinal():status; - } - - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.set(OperDefectEntity::getHandleStatus,status); - //第一个流程节点传 - if(Func.isNotEmpty(map.get("actStartTime"))){ - updateWrapper.set(OperDefectEntity::getActStartTime, map.get("actStartTime").toString()); - } - //最后一个流程节点传 - if(Func.isNotEmpty(map.get("actEndTime"))){ - updateWrapper.set(OperDefectEntity::getActEndTime, map.get("actEndTime").toString()); - } - //最后一个流程节点传 - if(Func.isNotEmpty(map.get("disposeDesc"))){ - updateWrapper.set(OperDefectEntity::getDisposeDesc, map.get("disposeDesc").toString()); - } - /** - * 每一个流程节点都要传,这个数据属于叠加数据,例如第一个流程节点是8小时,第二个流程节点是2小时, - * 第一个节点完成后存储的数据是8 第二个节点完成后存储的数据是 8,2 - */ - if(Func.isNotEmpty(map.get("actHours"))){ - updateWrapper.set(OperDefectEntity::getActHours, map.get("actHours").toString()); - } - updateWrapper.eq(OperDefectEntity::getProcessInstanceId,flow.getProcessInstanceId()); - update(updateWrapper); - return true; - } - - /** - * 获取缺陷的统计月报 - * @param month 格式:"2021-01" - */ - @Override - public Map getDefectStatistics(String month){ - Map re = new HashMap<>(); - re.put("currentMonth", getCurrentMonthStatic(month)); - re.put("severalMonths", getStatisticBySeveralMonth(month)); - re.put("manageIndex", getManageIndexStatistic(month)); - re.put("repeat", getRepeatStatistic(month)); - return re; - } - - @Override - public void exportFualtMonthExcel(HttpServletResponse response, String month) throws IOException { - Map re = new HashMap<>(); - re = this.getDefectStatistics(month); - //获取数据 - List currentMonth = (List) re.get("currentMonth"); - List severalMonths = (List) re.get("severalMonths"); - OperDefectManageIndexDTO manageIndex = (OperDefectManageIndexDTO) re.get("manageIndex"); - List repeat = (List) re.get("repeat"); - - // 第一步,创建一个webbook,对应一个Excel文件 - HSSFWorkbook wb = new HSSFWorkbook(); - // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet - HSSFSheet sheet = wb.createSheet("缺陷月报("+month+")"); - sheet.setDefaultRowHeight((short) (20*20)); - //生成当前行 - int currentRow = 0; - for (int col=0;col<9;col++){ - sheet.setColumnWidth(col, 3900); - } - //创建标题行 - CellRangeAddress region1 = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 8); - sheet.addMergedRegion(region1); - //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 - HSSFRow headTitle = sheet.createRow(currentRow); - this.setFullHeadCell(wb,headTitle, (short) 9,0); - HSSFCell headCell = headTitle.getCell(0); - headCell.setCellValue("缺陷月报("+month+")"); - currentRow++; - - // 本月与前几月缺陷报表比较表格设置 - currentRow = this.setCompareMonthCell(currentMonth, severalMonths,wb, sheet, new Integer(currentRow)); - currentRow++; - - // 管理指标(本月)设置 - currentRow = this.setManageIndexCell(manageIndex, wb, sheet, currentRow); - currentRow++; - - // 重复分类缺陷汇总表设置 - this.setRepeatCell( repeat, wb, sheet, currentRow); - - // 下载导出 - String filename = "("+month+")缺陷月报表"; - // 设置头信息 - response.setCharacterEncoding("UTF-8"); - response.setContentType("application/vnd.ms-excel"); - ServletOutputStream outputStream = null; - //一定要设置成xlsx格式 - response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8")); - //创建一个输出流 - outputStream = response.getOutputStream(); - //写入数据 - wb.write(outputStream); - // 关闭 - outputStream.close(); - wb.close(); - } - - @Override - public List getDefectList(String emCode,List list) { - return this.baseMapper.selectDefectList(emCode,list); - } - @Override - public List getDefectByEmCodeList(String emCode) { - return this.baseMapper.selectDefectByEmCodeList(emCode); - } - - @Override - public List getFaultByFaultCode(LocalDate startDate, LocalDate endDate, List deptIdList) { - List defectReportsVOList; - DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE); - List operDefectVOS = this.baseMapper.selectDurationDefect(dtf.format(startDate), dtf.format(endDate), deptIdList); - - defectReportsVOList = operDefectVOS.stream().map(operDefectVO -> { - User finder = UserCache.getUser(operDefectVO.getFinder()); - String finderAndTime = (ObjectUtil.isNotEmpty(finder) && StringUtil.isNotBlank(finder.getName()) ? finder.getName() : operDefectVO.getFinder().toString()) - + ":" + DateFormatUtils.format(operDefectVO.getFindTime(), DateUtil.PATTERN_DATETIME); - String handlerAndTime = ""; - if (Func.isNotEmpty(operDefectVO.getHandler())) { - User handler = UserCache.getUser(operDefectVO.getHandler()); - String handlerName = ObjectUtil.isNotEmpty(handler) && StringUtil.isNotBlank(handler.getName()) ? handler.getName() : operDefectVO.getHandler().toString(); - String handleTime = Func.isNotEmpty(operDefectVO.getActEndTime()) ? DateFormatUtils.format(operDefectVO.getActEndTime(), DateUtil.PATTERN_DATETIME) : ""; - handlerAndTime = String.format("%s:%s", handlerName, handleTime); - } - String seriousSituation = DictCache.getValue(DefectConstant.LEVEL_CODE_DICT_KEY, operDefectVO.getDefectLevel()); - return DefectReportsVO.builder().faultName(operDefectVO.getFaultName()).seriousSituation(seriousSituation) - .finderAndTime(finderAndTime).handlerAndTime(handlerAndTime).handleSituation(operDefectVO.getConclusion()).build(); - }).collect(Collectors.toList()); - - return defectReportsVOList; - } - - @Override - public List getFaultByFaultCode(Map params) { - LocalDate startDate = LocalDate.parse(params.get("startDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - LocalDate endDate = LocalDate.parse(params.get("endDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - List deptIdList = (List) params.get("deptId"); - return getFaultByFaultCode(startDate,endDate,deptIdList); - } - - @Override - public List> getDefectConclusion(Map params) { - return operDefectMapper.getDefectConclusion(params); - } - - @Override - public R detail(OperDefectEntity defect) { - OperDefectEntity detail = getOne(Condition.getQueryWrapper(defect)); - OperDefectVO operDefectVO = null; - if(ObjectUtil.isNotEmpty(detail)) { - operDefectVO = OperDefectWrapper.build().entityVO(detail); - //获取检修计划 - IOperAccessPlanService planService = SpringUtil.getBean(OperAccessPlanServiceImpl.class); - OperAccessPlanEntity accessPlanEntity = planService.getOne(Wrappers.lambdaQuery() - .eq(OperAccessPlanEntity::getDefectId,detail.getId()) - ); - if(ObjectUtil.isNotEmpty(accessPlanEntity)){ - operDefectVO.setAccessPlanId(accessPlanEntity.getId()); - if(ObjectUtil.isNotEmpty(accessPlanEntity.getStatus()) && accessPlanEntity.getStatus() > AccessConstants.PLAN_DRAFT){ - operDefectVO.setEditStatus(0); - } - else { - operDefectVO.setEditStatus(1); - } - } - } - return R.data(operDefectVO); - } - - /** - * 获取安全检查消缺项统计 - * @param startDate 开始时间 - * @param endDate 结束时间 - * @param dept 机构ID - * @param defectType 缺陷类型;1: 重大缺陷 2:一般缺陷 - * @return SafeCheckStatisticVO 对象 - */ - @Override - public SafeCheckStatisticVO getDefectCheck(String startDate, String endDate, Long dept, String defectType) { - SafeCheckStatisticVO vo = new SafeCheckStatisticVO(); - //获取消缺总数 - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() - .eq(OperPhenomenonEntity::getCreateDept,dept) - .ge(OperPhenomenonEntity::getPlanStartTime,startDate) - .le(OperPhenomenonEntity::getPlanStartTime,endDate) - .eq(OperPhenomenonEntity::getIsDefect,1); - //缺陷等级为Ⅰ级缺陷时为重大缺陷 其他为一般缺陷 - if("1".equals(defectType)){ - vo.setProjectType(Constants.SafeCheckProjectEnum.SERIOUS_DEFECT.getType()); - vo.setProjectTypeName(Constants.SafeCheckProjectEnum.SERIOUS_DEFECT.getName()); - wrapper.eq(OperPhenomenonEntity::getDefectLevel,DefectConstant.DefectLevelEnum.ONE.getStatus()); - } - else if("2".equals(defectType)){ - vo.setProjectType(Constants.SafeCheckProjectEnum.NORMAL_DEFECT.getType()); - vo.setProjectTypeName(Constants.SafeCheckProjectEnum.NORMAL_DEFECT.getName()); - wrapper.ne(OperPhenomenonEntity::getDefectLevel,DefectConstant.DefectLevelEnum.ONE.getStatus()); - } - List operPhenomenonEntities = operPhenomenonMapper.selectList(wrapper); - if(CollectionUtil.isNotEmpty(operPhenomenonEntities)){ - //获取消缺率 - List finishDefects = operPhenomenonEntities.stream().filter( - p-> ObjectUtil.isNotEmpty(p.getConclusionStatus()) && "1".equals(p.getConclusionStatus()) - ).collect(Collectors.toList()); - vo.setTotal(operPhenomenonEntities.size()); - vo.setQualified(finishDefects.size()); - vo.setQualifiedRate(new BigDecimal(finishDefects.size()/(double)operPhenomenonEntities.size()*100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue()); - } - return vo; - } - - /** - * 根据流程ID判断该缺陷是否能执行 - * @param processInstanceId 流程ID - * @return - */ - private boolean invalidHandleProcess(String processInstanceId) { - boolean result = true; - OperDefectEntity defectEntity = super.getOne(new LambdaQueryWrapper(){{ - eq(OperDefectEntity::getProcessInstanceId, processInstanceId); - }}); - //若类型为检修 - if(Func.isNotEmpty(defectEntity.getDefectCode()) && DefectConstant.DefectSourceEnum.JX.getStatus().equals(defectEntity.getDefectCode().substring(0,2))){ - IOperAccessPlanService planService = SpringUtil.getBean(IOperAccessPlanService.class); - List planList = planService.list(new LambdaQueryWrapper(){{ - eq(OperAccessPlanEntity::getDefectId, defectEntity.getId()); - }}); - if(CollectionUtil.isNotEmpty(planList)){ - //获取未审核的计划 - List pendingReviewList = planList.stream().filter(p->p.getStatus() != AccessConstants.PLAN_FINISH).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(pendingReviewList)){ - result = false; - } - //获取检修计划ID集合 - List planIdList = planList.stream().map(OperAccessPlanEntity::getId).collect(Collectors.toList()); - IOperAccessTaskService taskService = SpringUtil.getBean(IOperAccessTaskService.class); - //未完成检修任务集合 - List taskList = taskService.list(new LambdaQueryWrapper(){{ - in(OperAccessTaskEntity::getPlanId, planIdList); - ne(OperAccessTaskEntity::getStatus, AccessConstants.ACCESS_TASK_STATUS_4); - }}); - if(CollectionUtil.isNotEmpty(taskList)){ - result = false; - } - } - } - return result; - } - - /** - * 创建标题单元格样式 - * @param wb - * @return - */ - private HSSFCellStyle setHeadCellStyle(HSSFWorkbook wb){ - HSSFCellStyle headStyle = wb.createCellStyle(); - //设置边框 - headStyle.setBorderLeft(BorderStyle.THIN); - headStyle.setBorderRight(BorderStyle.THIN); - headStyle.setBorderTop(BorderStyle.THIN); - headStyle.setBorderBottom(BorderStyle.THIN); - //二、设置单元格背景颜色 - headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); - headStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); - //三、设置居中: - headStyle.setAlignment(HorizontalAlignment.CENTER); // 居中 - headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 - //四、设置字体: - HSSFFont font = wb.createFont(); - font.setFontName("黑体"); - //font.setColor(); - font.setFontHeightInPoints((short) 12);//设置字体大小 - headStyle.setFont(font);//选择需要用到的字体格式 - - return headStyle; - } - - /** - * 创建表格内容单元格样式 - * @param wb - * @return - */ - private HSSFCellStyle setContentCellStyle(HSSFWorkbook wb){ - HSSFCellStyle contentStyle = wb.createCellStyle(); - //设置边框 - contentStyle.setBorderLeft(BorderStyle.THIN); - contentStyle.setBorderRight(BorderStyle.THIN); - contentStyle.setBorderTop(BorderStyle.THIN); - contentStyle.setBorderBottom(BorderStyle.THIN); - //三、设置居中: - contentStyle.setAlignment(HorizontalAlignment.CENTER); // 居中 - contentStyle.setVerticalAlignment(VerticalAlignment.CENTER); - //四、设置字体: - HSSFFont font = wb.createFont(); - font.setFontName("仿宋_GB2312"); - //font.setBold(true);//粗体显示 - font.setFontHeightInPoints((short) 10); - contentStyle.setFont(font);//选择需要用到的字体格式 - return contentStyle; - } - - /** - * 设置缺陷月报表excel导出-本月与前几月缺陷报表内单元格 - * @param sheet - * @param currentRow - */ - private int setCompareMonthCell(List currentMonth, List severalMonths, HSSFWorkbook wb,HSSFSheet sheet, int currentRow){ - //创建当月与1-至当月表表头 - HSSFRow headRow = sheet.createRow(currentRow); - //设置表头信息 - this.setFullHeadCell(wb,headRow, (short) 9,0); - HSSFCell compare_head1_cell1 = headRow.getCell(0); - compare_head1_cell1.setCellValue("指标名称"); - HSSFCell compare_head1_cell2 = headRow.getCell(1); - compare_head1_cell2.setCellValue("本月"); - HSSFCell compare_head1_cell3 = headRow.getCell(5); - compare_head1_cell3.setCellValue("(1-本月)累计"); - //合并单元格 - CellRangeAddress head1_region1 = new CellRangeAddress((short) currentRow, (short) currentRow+1, (short) 0, (short) 0); - CellRangeAddress head1_region2 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 1, (short) 4); - CellRangeAddress head1_region3 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 5, (short) 8); - sheet.addMergedRegion(head1_region1); - sheet.addMergedRegion(head1_region2); - sheet.addMergedRegion(head1_region3); - currentRow++; - //创建表头 - HSSFRow headRow2 = sheet.createRow(currentRow); - this.setFullHeadCell(wb,headRow2, (short) 9,0); - //设置表头信息 - HSSFCell compare_head2_cell1 = headRow2.getCell(1); - compare_head2_cell1.setCellValue("发生"); - - HSSFCell compare_head2_cell2 = headRow2.getCell(2); - compare_head2_cell2.setCellValue("比率(%)"); - - HSSFCell compare_head2_cell3 = headRow2.getCell(3); - compare_head2_cell3.setCellValue("消除"); - - HSSFCell compare_head2_cell4 = headRow2.getCell(4); - compare_head2_cell4.setCellValue("比率(%)"); - - HSSFCell compare_head2_cell5 = headRow2.getCell(5); - compare_head2_cell5.setCellValue("发生"); - - HSSFCell compare_head2_cell6 = headRow2.getCell(6); - compare_head2_cell6.setCellValue("比率(%)"); - - HSSFCell compare_head2_cell7 = headRow2.getCell(7); - compare_head2_cell7.setCellValue("发生"); - - HSSFCell compare_head2_cell8 = headRow2.getCell(8); - compare_head2_cell8.setCellValue("比率(%)"); - currentRow++; - - for(int i=0;i repeat, HSSFWorkbook wb, HSSFSheet sheet, int currentRow){ - //重复缺陷分类汇总表 - //表头1 - HSSFRow repeat_head1 = sheet.createRow(currentRow); - this.setFullHeadCell(wb,repeat_head1, (short) 9,0); - HSSFCell repeat_head1_cell = repeat_head1.getCell(0); - repeat_head1_cell.setCellValue("重复缺陷分类汇总表"); - CellRangeAddress repeat_religon = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 8); - sheet.addMergedRegion(repeat_religon); - currentRow++; - - //表头2 - CellRangeAddress repeat_head2_cell_religon = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 2); - sheet.addMergedRegion(repeat_head2_cell_religon); - - HSSFRow repeat_head2 = sheet.createRow(currentRow); - this.setFullHeadCell(wb,repeat_head2, (short) 9,0); - HSSFCell repeat_head2_cell1 = repeat_head2.getCell(3); - CellRangeAddress repeat_head2_cell1_religon = new CellRangeAddress(currentRow, currentRow, (short) 3, (short) 4); - sheet.addMergedRegion(repeat_head2_cell1_religon); - repeat_head2_cell1.setCellValue("发生数量"); - - HSSFCell repeat_head2_cell2 = repeat_head2.getCell(5); - CellRangeAddress repeat_head2_cell2_religon = new CellRangeAddress(currentRow, currentRow, (short) 5, (short) 6); - sheet.addMergedRegion(repeat_head2_cell2_religon); - repeat_head2_cell2.setCellValue("占重复缺陷总数的比率(%)"); - - HSSFCell repeat_head2_cell3 = repeat_head2.getCell(7); - CellRangeAddress repeat_head2_cell3_religon = new CellRangeAddress(currentRow, currentRow, (short) 7, (short) 8); - sheet.addMergedRegion(repeat_head2_cell3_religon); - repeat_head2_cell3.setCellValue("占总缺陷的比率(%)"); - - currentRow++; - - //内容 - for(int i=0;i getCurrentMonthStatic(String month) { - List statisticByMonth = this.baseMapper.getStatisticByMonth(month, AuthUtil.getDeptId()); - return getRatioStatic(statisticByMonth); - } - - /** - * 当年1月 - 当前月获取缺陷等级统计数据 - * @param month "2021-01" - * @return - */ - private List getStatisticBySeveralMonth(String month) { - Integer intervalMonth = Integer.valueOf(month.split("-")[1]); - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date ; - String firstMonth = month.split("-")[0] + "-01-01"; - try { - date = dateFormat.parse(firstMonth); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.add(Calendar.MONTH, intervalMonth); - date = calendar.getTime(); - } catch (ParseException e) { - throw new ServiceException("日期转换失败"); - } - log.error("firstMonth:"+firstMonth + "; end=" +dateFormat.format(date)); - - List statisticBySeveralMonth = this.baseMapper.getStatisticBySeveralMonth(firstMonth, dateFormat.format(date), AuthUtil.getDeptId()); - return getRatioStatic(statisticBySeveralMonth); - } - - /** - * 获取按月管理指标统计数据 - * @param month - * @return - */ - private OperDefectManageIndexDTO getManageIndexStatistic(String month){ - OperDefectManageIndexDTO manageIndex = new OperDefectManageIndexDTO(); - List list = this.baseMapper.getManageIndex(month, AuthUtil.getDeptId()); - manageIndex.setInTimeNum(list.get(0)); - if(!list.get(1).equals(0)){ - manageIndex.setInTimeRatio(list.get(0).equals(0)? 0.0 : Double.valueOf(list.get(0))/list.get(1)); - } - manageIndex.setHistoryRemindNum(list.get(3)); - manageIndex.setMonthRemindNum(list.get(2)); - if(!list.get(4).equals(0)) { - manageIndex.setDealRatio(list.get(1).equals(0) ? 0.0 : Double.valueOf(list.get(1)) / list.get(4)); - } - return manageIndex; - } - - /** - * 获取重复缺陷等级统计数据 - * @param month - * @return - */ - private List getRepeatStatistic(String month){ - List re = new ArrayList<>(); - - List repetStatistics = this.baseMapper.getRepetStatistics(AuthUtil.getDeptId()); - //总缺陷数 - int total = repetStatistics.stream().mapToInt(OperDefectStatisticsCodeDTO::getDefectNum).sum(); - //总重复缺陷数 - int totalRepeat = repetStatistics - .stream() - .filter(s-> s.getDefectNum() > 1 && s.getDefectLevel() != null ) - .collect(Collectors.summingInt(OperDefectStatisticsCodeDTO::getDefectNum)); - //等级重复统计 - Map repeatList = repetStatistics - .stream() - .filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null ) - .collect(Collectors.groupingBy(OperDefectStatisticsCodeDTO::getDefectLevel, - Collectors.summarizingInt(OperDefectStatisticsCodeDTO::getDefectNum))); - - OperDefectRepeatRatioDTO one = new OperDefectRepeatRatioDTO(); - one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); - if(repeatList.get(one.getDefectLevel()) != null){ - one.setHappenNum(repeatList.get(one.getDefectLevel()).getSum()); - one.setHappenRatio(one.getHappenNum()/Double.valueOf(total)); - one.setRepeatRatio(one.getHappenNum()/Double.valueOf(totalRepeat)); - } - - OperDefectRepeatRatioDTO two = new OperDefectRepeatRatioDTO(); - two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); - if(repeatList.get(two.getDefectLevel()) != null){ - two.setHappenNum(repeatList.get(two.getDefectLevel()).getSum()); - two.setHappenRatio(two.getHappenNum()/Double.valueOf(total)); - two.setRepeatRatio(two.getHappenNum()/Double.valueOf(totalRepeat)); - } - - OperDefectRepeatRatioDTO three = new OperDefectRepeatRatioDTO(); - three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); - if(repeatList.get(three.getDefectLevel()) != null) { - three.setHappenNum(repeatList.get(three.getDefectLevel()).getSum()); - three.setHappenRatio(three.getHappenNum() / Double.valueOf(total)); - three.setRepeatRatio(three.getHappenNum() / Double.valueOf(totalRepeat)); - } - - OperDefectRepeatRatioDTO addUp = OperDefectRepeatRatioDTO.builder() - .defectLevel("合计") - .happenNum(one.getHappenNum() + two.getHappenNum() + three.getHappenNum()) - .happenRatio(one.getHappenRatio() + two.getHappenRatio() + three.getHappenRatio()) - .repeatRatio(1.00) - .build(); - if(addUp.getHappenNum().equals(0L)){ - addUp.setRepeatRatio(0.0); - } - - re.addAll(Arrays.asList(one,two,three,addUp)); - return re; - } - - - private List getRatioStatic(List dtos){ - //本月统计返回 - List re = new ArrayList<>(); - OperDefectRatioDTO one = new OperDefectRatioDTO(); - one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); - OperDefectRatioDTO two = new OperDefectRatioDTO(); - two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); - OperDefectRatioDTO three = new OperDefectRatioDTO(); - three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); - - //等级统计 - Map collectLevel = dtos.stream().filter(s-> s.getDefectLevel() != null).collect(Collectors.groupingBy(OperDefectStatisticsStatusDTO::getDefectLevel, - Collectors.summarizingInt(OperDefectStatisticsStatusDTO::getDefectNum))); - //总缺陷数 - int total = dtos.stream().mapToInt(OperDefectStatisticsStatusDTO::getDefectNum).sum(); - //状态统计 - Map collectStatus = dtos.stream().collect(Collectors.groupingBy(OperDefectStatisticsStatusDTO::getHandleStatus, - Collectors.summarizingInt(OperDefectStatisticsStatusDTO::getDefectNum))); - - for (OperDefectStatisticsStatusDTO dto : dtos) { - if(dto.getDefectLevel()!=null){ - switch (dto.getDefectLevel()) { - case "1": - setReturnRatio(total, one, dto, collectLevel, collectStatus); - break; - case "2": - setReturnRatio(total, two, dto, collectLevel, collectStatus); - break; - case "3": - setReturnRatio(total, three, dto, collectLevel, collectStatus); - break; - default: - break; - } - } - } - int solveNum = collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()) == null? 0 : (int)collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()).getSum(); - OperDefectRatioDTO addUp = OperDefectRatioDTO.builder() - .happenNum(total) - .happenRatio(total == 0 ? 0 : 1.00) - .defectLevel("合计") - .sovleRatio(solveNum == 0 ? 0 : 1.00) - .sovleNum(solveNum) - .build(); - re.addAll(Arrays.asList(one,two,three,addUp)); - return re; - } - - - private void setReturnRatio(int total, OperDefectRatioDTO ratio, OperDefectStatisticsStatusDTO dto, - Map collectLevel, Map collectStatus){ - if(dto.getHandleStatus().equals(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus())) { - ratio.setSovleNum(dto.getDefectNum()); - ratio.setSovleRatio(Double.valueOf(dto.getDefectNum())/collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()).getSum()); - ratio.setHappenNum((int)collectLevel.get(dto.getDefectLevel()).getSum()); - ratio.setHappenRatio(ratio.getHappenNum()/Double.valueOf(total)); - } else { - ratio.setHappenNum((int)collectLevel.get(dto.getDefectLevel()).getSum()); - ratio.setHappenRatio(ratio.getHappenNum()/Double.valueOf(total)); - } - } - - /** - * 更新缺陷信息 - * @param entity - * @return - */ - @Override - public boolean updateDefectInfo(OperDefectEntity entity) { - return this.update(Wrappers.lambdaUpdate() - .set(OperDefectEntity::getActHours, entity.getActHours()) - .set(OperDefectEntity::getActStartTime,entity.getActStartTime()) - .set(OperDefectEntity::getActEndTime,entity.getActEndTime()) - .set(OperDefectEntity::getDisposeDesc,entity.getDisposeDesc()) - .eq(OperDefectEntity::getDefectCode,entity.getDefectCode())); - } - - @Override - public boolean updateDefectHanderState(OperDefectEntity entity) { - return this.update(Wrappers.lambdaUpdate() - .set(OperDefectEntity::getHandleStatus, entity.getHandleStatus()) - .eq(OperDefectEntity::getDefectCode,entity.getDefectCode())); - } + private static final Logger logger = LoggerFactory.getLogger(OperDefectServiceImpl.class); + + private final IFlowClient flowClient; + + private final OperDefectMapper operDefectMapper; + + private final IUserClient userClient; + + private final OperPhenomenonMapper operPhenomenonMapper; + + /** + * 开始问题处理流程 + * 问题处理流程的第一个处理节点人key 必须是 problemUser + * + * @param + */ + @Override + public void startFlow(OperPhenomenonEntity phenomenonEntity, OperDefectEntity defectEntity) { + User handler = UserCache.getUser(phenomenonEntity.getHandler()); + String handlerName = handler == null ? "" : handler.getName(); + String sourceName = DictCache.getValue(DefectConstant.SOURCE_CODE_DICT_KEY, phenomenonEntity.getSourceCode()); + String processName = "【" + sourceName + "】" + handlerName + " 发起的缺陷【" + phenomenonEntity.getDefectCode() + "】的问题处理流程"; + defectEntity.setCreateUser(phenomenonEntity.getCreateUser()); + defectEntity.setCreateDept(phenomenonEntity.getCreateDept()); + defectEntity.setTenantId(phenomenonEntity.getTenantId()); + save(defectEntity); + + Kv variables = Kv.create().set(ProcessConstant.TASK_VARIABLE_CREATE_USER, "taskUser_" + phenomenonEntity.getCreateUser()).set(DefectConstant.PROCESS_VARIABLE_HANDLE_USER, "taskUser_" + phenomenonEntity.getHandler()); + R result = flowClient.startProcessInstanceContainNameByKey(defectEntity.getProcDefId(), FlowUtil.getBusinessKey("hzims_oper_defect", String.valueOf(defectEntity.getId())), processName, variables); + if (result.isSuccess()) { + BladeFlow flow = result.getData(); + log.debug("流程已启动,流程ID:" + flow.getProcessInstanceId()); + // 返回流程id写入defect + defectEntity.setProcessInstanceId(flow.getProcessInstanceId()); + defectEntity.setHandleStatus(DefectConstant.DefectHandlerStatusEnum.HANDLING_STATUS.getStatus().toString()); + updateById(defectEntity); + } else { + throw new ServiceException("开启流程失败,code=" + result.getCode()); + } + + } + + + /** + * 处理问题 + * + * @param flow + * @return + */ + @Override + public boolean handleProcess(BladeFlow flow) { + if (!invalidHandleProcess(flow.getProcessInstanceId())) { + throw new ServiceException("当前缺陷开具了检修计划,需等任务执行完成才能处理缺陷"); + } + ComleteTask task = new ComleteTask(); + task.setTaskId(flow.getTaskId()); + task.setComment(flow.getComment()); + task.setAttachments(flow.getAttachments()); + task.setFlag(flow.getFlag()); + task.setVariables(flow.getVariables()); + Map map = flow.getVariables(); + + flowClient.completeTask(task); + Integer status = ProcessConstant.ProcessInstanceStatusEnum.running.ordinal(); + R result = flowClient.queryProcessInstanceStatus(flow.getProcessInstanceId()); + if (result.isSuccess()) { + status = ProcessConstant.ProcessInstanceStatusEnum.over.name().equals(result.getData()) ? ProcessConstant.ProcessInstanceStatusEnum.over.ordinal() : status; + } + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.set(OperDefectEntity::getHandleStatus, status); + //第一个流程节点传 + if (Func.isNotEmpty(map.get("actStartTime"))) { + updateWrapper.set(OperDefectEntity::getActStartTime, map.get("actStartTime").toString()); + } + //最后一个流程节点传 + if (Func.isNotEmpty(map.get("actEndTime"))) { + updateWrapper.set(OperDefectEntity::getActEndTime, map.get("actEndTime").toString()); + } + //最后一个流程节点传 + if (Func.isNotEmpty(map.get("disposeDesc"))) { + updateWrapper.set(OperDefectEntity::getDisposeDesc, map.get("disposeDesc").toString()); + } + /** + * 每一个流程节点都要传,这个数据属于叠加数据,例如第一个流程节点是8小时,第二个流程节点是2小时, + * 第一个节点完成后存储的数据是8 第二个节点完成后存储的数据是 8,2 + */ + if (Func.isNotEmpty(map.get("actHours"))) { + updateWrapper.set(OperDefectEntity::getActHours, map.get("actHours").toString()); + } + updateWrapper.eq(OperDefectEntity::getProcessInstanceId, flow.getProcessInstanceId()); + update(updateWrapper); + return true; + } + + /** + * 获取缺陷的统计月报 + * + * @param month 格式:"2021-01" + */ + @Override + public Map getDefectStatistics(String month) { + Map re = new HashMap<>(); + re.put("currentMonth", getCurrentMonthStatic(month)); + re.put("severalMonths", getStatisticBySeveralMonth(month)); + re.put("manageIndex", getManageIndexStatistic(month)); + re.put("repeat", getRepeatStatistic(month)); + return re; + } + + @Override + public void exportFualtMonthExcel(HttpServletResponse response, String month) throws IOException { + Map re = new HashMap<>(); + re = this.getDefectStatistics(month); + //获取数据 + List currentMonth = (List) re.get("currentMonth"); + List severalMonths = (List) re.get("severalMonths"); + OperDefectManageIndexDTO manageIndex = (OperDefectManageIndexDTO) re.get("manageIndex"); + List repeat = (List) re.get("repeat"); + + // 第一步,创建一个webbook,对应一个Excel文件 + HSSFWorkbook wb = new HSSFWorkbook(); + // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet + HSSFSheet sheet = wb.createSheet("缺陷月报(" + month + ")"); + sheet.setDefaultRowHeight((short) (20 * 20)); + //生成当前行 + int currentRow = 0; + for (int col = 0; col < 9; col++) { + sheet.setColumnWidth(col, 3900); + } + //创建标题行 + CellRangeAddress region1 = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 8); + sheet.addMergedRegion(region1); + //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列 + HSSFRow headTitle = sheet.createRow(currentRow); + this.setFullHeadCell(wb, headTitle, (short) 9, 0); + HSSFCell headCell = headTitle.getCell(0); + headCell.setCellValue("缺陷月报(" + month + ")"); + currentRow++; + + // 本月与前几月缺陷报表比较表格设置 + currentRow = this.setCompareMonthCell(currentMonth, severalMonths, wb, sheet, new Integer(currentRow)); + currentRow++; + + // 管理指标(本月)设置 + currentRow = this.setManageIndexCell(manageIndex, wb, sheet, currentRow); + currentRow++; + + // 重复分类缺陷汇总表设置 + this.setRepeatCell(repeat, wb, sheet, currentRow); + + // 下载导出 + String filename = "(" + month + ")缺陷月报表"; + // 设置头信息 + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/vnd.ms-excel"); + ServletOutputStream outputStream = null; + //一定要设置成xlsx格式 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8")); + //创建一个输出流 + outputStream = response.getOutputStream(); + //写入数据 + wb.write(outputStream); + // 关闭 + outputStream.close(); + wb.close(); + } + + @Override + public List getDefectList(String emCode, List list) { + return this.baseMapper.selectDefectList(emCode, list); + } + + @Override + public List getDefectByEmCodeList(String emCode) { + return this.baseMapper.selectDefectByEmCodeList(emCode); + } + + @Override + public List getFaultByFaultCode(LocalDate startDate, LocalDate endDate, List deptIdList) { + List defectReportsVOList; + DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE); + List operDefectVOS = this.baseMapper.selectDurationDefect(dtf.format(startDate), dtf.format(endDate), deptIdList); + + defectReportsVOList = operDefectVOS.stream().map(operDefectVO -> { + User finder = UserCache.getUser(operDefectVO.getFinder()); + String finderAndTime = (ObjectUtil.isNotEmpty(finder) && StringUtil.isNotBlank(finder.getName()) ? finder.getName() : operDefectVO.getFinder().toString()) + ":" + DateFormatUtils.format(operDefectVO.getFindTime(), DateUtil.PATTERN_DATETIME); + String handlerAndTime = ""; + if (Func.isNotEmpty(operDefectVO.getHandler())) { + User handler = UserCache.getUser(operDefectVO.getHandler()); + String handlerName = ObjectUtil.isNotEmpty(handler) && StringUtil.isNotBlank(handler.getName()) ? handler.getName() : operDefectVO.getHandler().toString(); + String handleTime = Func.isNotEmpty(operDefectVO.getActEndTime()) ? DateFormatUtils.format(operDefectVO.getActEndTime(), DateUtil.PATTERN_DATETIME) : ""; + handlerAndTime = String.format("%s:%s", handlerName, handleTime); + } + String seriousSituation = DictCache.getValue(DefectConstant.LEVEL_CODE_DICT_KEY, operDefectVO.getDefectLevel()); + return DefectReportsVO.builder().faultName(operDefectVO.getFaultName()).seriousSituation(seriousSituation).finderAndTime(finderAndTime).handlerAndTime(handlerAndTime).handleSituation(operDefectVO.getConclusion()).build(); + }).collect(Collectors.toList()); + + return defectReportsVOList; + } + + @Override + public List getFaultByFaultCode(Map params) { + LocalDate startDate = LocalDate.parse(params.get("startDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + LocalDate endDate = LocalDate.parse(params.get("endDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + List deptIdList = (List) params.get("deptId"); + return getFaultByFaultCode(startDate, endDate, deptIdList); + } + + @Override + public List> getDefectConclusion(Map params) { + return operDefectMapper.getDefectConclusion(params); + } + + @Override + public R detail(OperDefectEntity defect) { + OperDefectEntity detail = getOne(Condition.getQueryWrapper(defect)); + OperDefectVO operDefectVO = null; + if (ObjectUtil.isNotEmpty(detail)) { + operDefectVO = OperDefectWrapper.build().entityVO(detail); + //获取检修计划 + IOperAccessPlanService planService = SpringUtil.getBean(OperAccessPlanServiceImpl.class); + OperAccessPlanEntity accessPlanEntity = planService.getOne(Wrappers.lambdaQuery().eq(OperAccessPlanEntity::getDefectId, detail.getId())); + if (ObjectUtil.isNotEmpty(accessPlanEntity)) { + operDefectVO.setAccessPlanId(accessPlanEntity.getId()); + if (ObjectUtil.isNotEmpty(accessPlanEntity.getStatus()) && accessPlanEntity.getStatus() > AccessConstants.PLAN_DRAFT) { + operDefectVO.setEditStatus(0); + } else { + operDefectVO.setEditStatus(1); + } + } + } + return R.data(operDefectVO); + } + + /** + * 获取安全检查消缺项统计 + * + * @param startDate 开始时间 + * @param endDate 结束时间 + * @param dept 机构ID + * @param defectType 缺陷类型;1: 重大缺陷 2:一般缺陷 + * @return SafeCheckStatisticVO 对象 + */ + @Override + public SafeCheckStatisticVO getDefectCheck(String startDate, String endDate, Long dept, String defectType) { + SafeCheckStatisticVO vo = new SafeCheckStatisticVO(); + //获取消缺总数 + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery().eq(OperPhenomenonEntity::getCreateDept, dept).ge(OperPhenomenonEntity::getPlanStartTime, startDate).le(OperPhenomenonEntity::getPlanStartTime, endDate).eq(OperPhenomenonEntity::getIsDefect, 1); + //缺陷等级为Ⅰ级缺陷时为重大缺陷 其他为一般缺陷 + if ("1".equals(defectType)) { + vo.setProjectType(Constants.SafeCheckProjectEnum.SERIOUS_DEFECT.getType()); + vo.setProjectTypeName(Constants.SafeCheckProjectEnum.SERIOUS_DEFECT.getName()); + wrapper.eq(OperPhenomenonEntity::getDefectLevel, DefectConstant.DefectLevelEnum.ONE.getStatus()); + } else if ("2".equals(defectType)) { + vo.setProjectType(Constants.SafeCheckProjectEnum.NORMAL_DEFECT.getType()); + vo.setProjectTypeName(Constants.SafeCheckProjectEnum.NORMAL_DEFECT.getName()); + wrapper.ne(OperPhenomenonEntity::getDefectLevel, DefectConstant.DefectLevelEnum.ONE.getStatus()); + } + List operPhenomenonEntities = operPhenomenonMapper.selectList(wrapper); + if (CollectionUtil.isNotEmpty(operPhenomenonEntities)) { + //获取消缺率 + List finishDefects = operPhenomenonEntities.stream().filter(p -> ObjectUtil.isNotEmpty(p.getConclusionStatus()) && "1".equals(p.getConclusionStatus())).collect(Collectors.toList()); + vo.setTotal(operPhenomenonEntities.size()); + vo.setQualified(finishDefects.size()); + vo.setQualifiedRate(new BigDecimal(finishDefects.size() / (double) operPhenomenonEntities.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + return vo; + } + + /** + * 根据流程ID判断该缺陷是否能执行 + * + * @param processInstanceId 流程ID + * @return + */ + private boolean invalidHandleProcess(String processInstanceId) { + boolean result = true; + OperDefectEntity defectEntity = super.getOne(new LambdaQueryWrapper() {{ + eq(OperDefectEntity::getProcessInstanceId, processInstanceId); + }}); + //若类型为检修 + if (Func.isNotEmpty(defectEntity.getDefectCode()) && DefectConstant.DefectSourceEnum.JX.getStatus().equals(defectEntity.getDefectCode().substring(0, 2))) { + IOperAccessPlanService planService = SpringUtil.getBean(IOperAccessPlanService.class); + List planList = planService.list(new LambdaQueryWrapper() {{ + eq(OperAccessPlanEntity::getDefectId, defectEntity.getId()); + }}); + if (CollectionUtil.isNotEmpty(planList)) { + //获取未审核的计划 + List pendingReviewList = planList.stream().filter(p -> p.getStatus() != AccessConstants.PLAN_FINISH).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(pendingReviewList)) { + result = false; + } + //获取检修计划ID集合 + List planIdList = planList.stream().map(OperAccessPlanEntity::getId).collect(Collectors.toList()); + IOperAccessTaskService taskService = SpringUtil.getBean(IOperAccessTaskService.class); + //未完成检修任务集合 + List taskList = taskService.list(new LambdaQueryWrapper() {{ + in(OperAccessTaskEntity::getPlanId, planIdList); + ne(OperAccessTaskEntity::getStatus, AccessConstants.ACCESS_TASK_STATUS_4); + }}); + if (CollectionUtil.isNotEmpty(taskList)) { + result = false; + } + } + } + return result; + } + + /** + * 创建标题单元格样式 + * + * @param wb + * @return + */ + private HSSFCellStyle setHeadCellStyle(HSSFWorkbook wb) { + HSSFCellStyle headStyle = wb.createCellStyle(); + //设置边框 + headStyle.setBorderLeft(BorderStyle.THIN); + headStyle.setBorderRight(BorderStyle.THIN); + headStyle.setBorderTop(BorderStyle.THIN); + headStyle.setBorderBottom(BorderStyle.THIN); + //二、设置单元格背景颜色 + headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + headStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); + //三、设置居中: + headStyle.setAlignment(HorizontalAlignment.CENTER); // 居中 + headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 + //四、设置字体: + HSSFFont font = wb.createFont(); + font.setFontName("黑体"); + //font.setColor(); + font.setFontHeightInPoints((short) 12);//设置字体大小 + headStyle.setFont(font);//选择需要用到的字体格式 + + return headStyle; + } + + /** + * 创建表格内容单元格样式 + * + * @param wb + * @return + */ + private HSSFCellStyle setContentCellStyle(HSSFWorkbook wb) { + HSSFCellStyle contentStyle = wb.createCellStyle(); + //设置边框 + contentStyle.setBorderLeft(BorderStyle.THIN); + contentStyle.setBorderRight(BorderStyle.THIN); + contentStyle.setBorderTop(BorderStyle.THIN); + contentStyle.setBorderBottom(BorderStyle.THIN); + //三、设置居中: + contentStyle.setAlignment(HorizontalAlignment.CENTER); // 居中 + contentStyle.setVerticalAlignment(VerticalAlignment.CENTER); + //四、设置字体: + HSSFFont font = wb.createFont(); + font.setFontName("仿宋_GB2312"); + //font.setBold(true);//粗体显示 + font.setFontHeightInPoints((short) 10); + contentStyle.setFont(font);//选择需要用到的字体格式 + return contentStyle; + } + + /** + * 设置缺陷月报表excel导出-本月与前几月缺陷报表内单元格 + * + * @param sheet + * @param currentRow + */ + private int setCompareMonthCell(List currentMonth, List severalMonths, HSSFWorkbook wb, HSSFSheet sheet, int currentRow) { + //创建当月与1-至当月表表头 + HSSFRow headRow = sheet.createRow(currentRow); + //设置表头信息 + this.setFullHeadCell(wb, headRow, (short) 9, 0); + HSSFCell compare_head1_cell1 = headRow.getCell(0); + compare_head1_cell1.setCellValue("指标名称"); + HSSFCell compare_head1_cell2 = headRow.getCell(1); + compare_head1_cell2.setCellValue("本月"); + HSSFCell compare_head1_cell3 = headRow.getCell(5); + compare_head1_cell3.setCellValue("(1-本月)累计"); + //合并单元格 + CellRangeAddress head1_region1 = new CellRangeAddress((short) currentRow, (short) currentRow + 1, (short) 0, (short) 0); + CellRangeAddress head1_region2 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 1, (short) 4); + CellRangeAddress head1_region3 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 5, (short) 8); + sheet.addMergedRegion(head1_region1); + sheet.addMergedRegion(head1_region2); + sheet.addMergedRegion(head1_region3); + currentRow++; + //创建表头 + HSSFRow headRow2 = sheet.createRow(currentRow); + this.setFullHeadCell(wb, headRow2, (short) 9, 0); + //设置表头信息 + HSSFCell compare_head2_cell1 = headRow2.getCell(1); + compare_head2_cell1.setCellValue("发生"); + + HSSFCell compare_head2_cell2 = headRow2.getCell(2); + compare_head2_cell2.setCellValue("比率(%)"); + + HSSFCell compare_head2_cell3 = headRow2.getCell(3); + compare_head2_cell3.setCellValue("消除"); + + HSSFCell compare_head2_cell4 = headRow2.getCell(4); + compare_head2_cell4.setCellValue("比率(%)"); + + HSSFCell compare_head2_cell5 = headRow2.getCell(5); + compare_head2_cell5.setCellValue("发生"); + + HSSFCell compare_head2_cell6 = headRow2.getCell(6); + compare_head2_cell6.setCellValue("比率(%)"); + + HSSFCell compare_head2_cell7 = headRow2.getCell(7); + compare_head2_cell7.setCellValue("发生"); + + HSSFCell compare_head2_cell8 = headRow2.getCell(8); + compare_head2_cell8.setCellValue("比率(%)"); + currentRow++; + + for (int i = 0; i < currentMonth.size(); i++) { + HSSFRow row = sheet.createRow(currentRow); + this.setFullHeadCell(wb, row, (short) 9, 1); + OperDefectRatioDTO currentRatioDTO = currentMonth.get(i); + OperDefectRatioDTO severalRatioDTO = severalMonths.get(i); + //创建表格内容第一个单元格 + HSSFCell compare_content_cell1 = row.getCell(0); + if ("1".equals(currentRatioDTO.getDefectLevel())) { + compare_content_cell1.setCellValue("一类缺陷"); + } else if ("2".equals(currentRatioDTO.getDefectLevel())) { + compare_content_cell1.setCellValue("二类缺陷"); + } else if ("3".equals(currentRatioDTO.getDefectLevel())) { + compare_content_cell1.setCellValue("三类缺陷"); + } else if ("合计".equals(currentRatioDTO.getDefectLevel())) { + compare_content_cell1.setCellValue(currentRatioDTO.getDefectLevel()); + } + HSSFCell compare_content_cell2 = row.getCell(1); + compare_content_cell2.setCellValue(currentRatioDTO.getHappenNum()); + HSSFCell compare_content_cell3 = row.getCell(2); + compare_content_cell3.setCellValue(this.dealDouble(currentRatioDTO.getHappenRatio())); + HSSFCell compare_content_cell4 = row.getCell(3); + compare_content_cell4.setCellValue(currentRatioDTO.getSovleNum()); + HSSFCell compare_content_cell5 = row.getCell(4); + compare_content_cell5.setCellValue(this.dealDouble(currentRatioDTO.getSovleRatio())); + + HSSFCell compare_content_cell6 = row.getCell(5); + compare_content_cell6.setCellValue(severalRatioDTO.getHappenNum()); + HSSFCell compare_content_cell7 = row.getCell(6); + compare_content_cell7.setCellValue(this.dealDouble(severalRatioDTO.getHappenRatio())); + HSSFCell compare_content_cell8 = row.getCell(7); + compare_content_cell8.setCellValue(severalRatioDTO.getSovleNum()); + HSSFCell compare_content_cell9 = row.getCell(8); + compare_content_cell9.setCellValue(this.dealDouble(severalRatioDTO.getSovleRatio())); + currentRow++; + } + return currentRow; + } + + /** + * 设置缺陷月报表excel导出-管理指标(本月)表内单元格 + * + * @param wb + * @param sheet + * @param currentRow 记录表格中叠加后的数据 + */ + private int setManageIndexCell(OperDefectManageIndexDTO manageIndex, HSSFWorkbook wb, HSSFSheet sheet, int currentRow) { + //管理指标表头 + HSSFRow headRow3 = sheet.createRow(currentRow); + this.setFullHeadCell(wb, headRow3, (short) 9, 0); + HSSFCell manage_index_head = headRow3.getCell(0); + manage_index_head.setCellValue("管理指标(本月)"); + CellRangeAddress head1_region4 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 0, (short) 8); + sheet.addMergedRegion(head1_region4); + currentRow++; + + HSSFRow headRow4 = sheet.createRow(currentRow); + this.setFullHeadCell(wb, headRow4, (short) 9, 0); + HSSFCell repeat_head2_cell = headRow4.getCell(0); + repeat_head2_cell.setCellValue("及时消除的缺陷数"); + HSSFCell repeat_head2_cell2 = headRow4.getCell(2); + repeat_head2_cell2.setCellValue("消除及时率(%)"); + HSSFCell repeat_head2_cell3 = headRow4.getCell(4); + repeat_head2_cell3.setCellValue("消缺率(%)"); + HSSFCell repeat_head2_cell4 = headRow4.getCell(5); + repeat_head2_cell4.setCellValue("历史遗留缺陷数"); + HSSFCell repeat_head2_cell5 = headRow4.getCell(7); + repeat_head2_cell5.setCellValue("本月遗留缺陷"); + + //合并单元格 + CellRangeAddress head2_region1 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 0, (short) 1); + CellRangeAddress head2_region2 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 2, (short) 3); + CellRangeAddress head2_region3 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 5, (short) 6); + CellRangeAddress head2_region4 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 7, (short) 8); + + sheet.addMergedRegion(head2_region1); + sheet.addMergedRegion(head2_region2); + sheet.addMergedRegion(head2_region3); + sheet.addMergedRegion(head2_region4); + + currentRow++; + + //表格内容行 + HSSFRow manage_index_row = sheet.createRow(currentRow); + this.setFullHeadCell(wb, manage_index_row, (short) 9, 1); + //表格内容 + //第一列 + CellRangeAddress manage_religon1 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 0, (short) 1); + sheet.addMergedRegion(manage_religon1); + HSSFCell manage_index_cell = manage_index_row.getCell(0); + manage_index_cell.setCellStyle(this.setContentCellStyle(wb)); + manage_index_cell.setCellValue(manageIndex.getInTimeNum()); + //第二列 + CellRangeAddress manage_religon2 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 2, (short) 3); + sheet.addMergedRegion(manage_religon2); + HSSFCell manage_index_cel2 = manage_index_row.getCell(2); + manage_index_cel2.setCellValue(this.dealDouble(manageIndex.getInTimeRatio())); + //第三列 + HSSFCell manage_index_cel3 = manage_index_row.getCell(4); + manage_index_cel3.setCellValue(this.dealDouble(manageIndex.getDealRatio())); + //第四列 + CellRangeAddress manage_religon3 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 5, (short) 6); + sheet.addMergedRegion(manage_religon3); + HSSFCell manage_index_cel4 = manage_index_row.getCell(5); + manage_index_cel4.setCellValue(manageIndex.getHistoryRemindNum()); + //第五列 + CellRangeAddress manage_religon4 = new CellRangeAddress((short) currentRow, (short) currentRow, (short) 7, (short) 8); + sheet.addMergedRegion(manage_religon4); + HSSFCell manage_index_cel5 = manage_index_row.getCell(7); + manage_index_cel5.setCellValue(manageIndex.getMonthRemindNum()); + currentRow++; + return currentRow; + } + + /** + * 设置缺陷月报表excel导出-重复分类缺陷汇总表内单元格 + * + * @param wb + * @param sheet + * @param currentRow 记录表格中叠加后的数据 + */ + private int setRepeatCell(List repeat, HSSFWorkbook wb, HSSFSheet sheet, int currentRow) { + //重复缺陷分类汇总表 + //表头1 + HSSFRow repeat_head1 = sheet.createRow(currentRow); + this.setFullHeadCell(wb, repeat_head1, (short) 9, 0); + HSSFCell repeat_head1_cell = repeat_head1.getCell(0); + repeat_head1_cell.setCellValue("重复缺陷分类汇总表"); + CellRangeAddress repeat_religon = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 8); + sheet.addMergedRegion(repeat_religon); + currentRow++; + + //表头2 + CellRangeAddress repeat_head2_cell_religon = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 2); + sheet.addMergedRegion(repeat_head2_cell_religon); + + HSSFRow repeat_head2 = sheet.createRow(currentRow); + this.setFullHeadCell(wb, repeat_head2, (short) 9, 0); + HSSFCell repeat_head2_cell1 = repeat_head2.getCell(3); + CellRangeAddress repeat_head2_cell1_religon = new CellRangeAddress(currentRow, currentRow, (short) 3, (short) 4); + sheet.addMergedRegion(repeat_head2_cell1_religon); + repeat_head2_cell1.setCellValue("发生数量"); + + HSSFCell repeat_head2_cell2 = repeat_head2.getCell(5); + CellRangeAddress repeat_head2_cell2_religon = new CellRangeAddress(currentRow, currentRow, (short) 5, (short) 6); + sheet.addMergedRegion(repeat_head2_cell2_religon); + repeat_head2_cell2.setCellValue("占重复缺陷总数的比率(%)"); + + HSSFCell repeat_head2_cell3 = repeat_head2.getCell(7); + CellRangeAddress repeat_head2_cell3_religon = new CellRangeAddress(currentRow, currentRow, (short) 7, (short) 8); + sheet.addMergedRegion(repeat_head2_cell3_religon); + repeat_head2_cell3.setCellValue("占总缺陷的比率(%)"); + + currentRow++; + + //内容 + for (int i = 0; i < repeat.size(); i++) { + HSSFRow repeat_row = sheet.createRow(currentRow); + this.setFullHeadCell(wb, repeat_row, (short) 9, 1); + //第一列 + HSSFCell repeat_cell1 = repeat_row.getCell(0); + CellRangeAddress repeat_content_religon = new CellRangeAddress(currentRow, currentRow, (short) 0, (short) 2); + sheet.addMergedRegion(repeat_content_religon); + if ("1".equals(repeat.get(i).getDefectLevel())) { + repeat_cell1.setCellValue("一类缺陷"); + } else if ("2".equals(repeat.get(i).getDefectLevel())) { + repeat_cell1.setCellValue("二类缺陷"); + } else if ("3".equals(repeat.get(i).getDefectLevel())) { + repeat_cell1.setCellValue("三类缺陷"); + } else if ("合计".equals(repeat.get(i).getDefectLevel())) { + repeat_cell1.setCellValue(repeat.get(i).getDefectLevel()); + } + //第二列 + HSSFCell repeat_cell2 = repeat_row.getCell(3); + CellRangeAddress repeat_content_religon1 = new CellRangeAddress(currentRow, currentRow, (short) 3, (short) 4); + sheet.addMergedRegion(repeat_content_religon1); + repeat_cell2.setCellValue(repeat.get(i).getHappenNum()); + + //第三列 + HSSFCell repeat_cell3 = repeat_row.getCell(5); + CellRangeAddress repeat_content_religon2 = new CellRangeAddress(currentRow, currentRow, (short) 5, (short) 6); + sheet.addMergedRegion(repeat_content_religon2); + repeat_cell3.setCellValue(this.dealDouble(repeat.get(i).getRepeatRatio())); + + //第四列 + HSSFCell repeat_cell4 = repeat_row.getCell(7); + CellRangeAddress repeat_content_religon3 = new CellRangeAddress(currentRow, currentRow, (short) 7, (short) 8); + sheet.addMergedRegion(repeat_content_religon3); + repeat_cell4.setCellValue(this.dealDouble(repeat.get(i).getHappenRatio())); + currentRow++; + } + return currentRow; + } + + /** + * 补全合并单元格时 表格行所有单元格 + * + * @param headRow + * @param rowLen + * @param status 0:设置表头样式 1:设置内容样式 + */ + private void setFullHeadCell(HSSFWorkbook wb, HSSFRow headRow, short rowLen, int status) { + for (int i = 0; i < rowLen; i++) { + HSSFCell hssfcell = headRow.createCell(i); + if (status == 0) { + hssfcell.setCellStyle(this.setHeadCellStyle(wb)); + } else if (status == 1) { + hssfcell.setCellStyle(this.setContentCellStyle(wb)); + } + } + } + + /** + * 处理double数据保留两位小数 + * + * @param num + * @return + */ + private Double dealDouble(Double num) { + if (num != null) { + BigDecimal b = new BigDecimal(num * 100); + return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + return null; + } + + /** + * 获取当前月统计数据 + * + * @param month + * @return + */ + private List getCurrentMonthStatic(String month) { + List statisticByMonth = this.baseMapper.getStatisticByMonth(month, AuthUtil.getDeptId()); + return getRatioStatic(statisticByMonth); + } + + /** + * 当年1月 - 当前月获取缺陷等级统计数据 + * + * @param month "2021-01" + * @return + */ + private List getStatisticBySeveralMonth(String month) { + Integer intervalMonth = Integer.valueOf(month.split("-")[1]); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date; + String firstMonth = month.split("-")[0] + "-01-01"; + try { + date = dateFormat.parse(firstMonth); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.MONTH, intervalMonth); + date = calendar.getTime(); + } catch (ParseException e) { + throw new ServiceException("日期转换失败"); + } + log.error("firstMonth:" + firstMonth + "; end=" + dateFormat.format(date)); + + List statisticBySeveralMonth = this.baseMapper.getStatisticBySeveralMonth(firstMonth, dateFormat.format(date), AuthUtil.getDeptId()); + return getRatioStatic(statisticBySeveralMonth); + } + + /** + * 获取按月管理指标统计数据 + * + * @param month + * @return + */ + private OperDefectManageIndexDTO getManageIndexStatistic(String month) { + OperDefectManageIndexDTO manageIndex = new OperDefectManageIndexDTO(); + List list = this.baseMapper.getManageIndex(month, AuthUtil.getDeptId()); + manageIndex.setInTimeNum(list.get(0)); + if (!list.get(1).equals(0)) { + manageIndex.setInTimeRatio(list.get(0).equals(0) ? 0.0 : Double.valueOf(list.get(0)) / list.get(1)); + } + manageIndex.setHistoryRemindNum(list.get(3)); + manageIndex.setMonthRemindNum(list.get(2)); + if (!list.get(4).equals(0)) { + manageIndex.setDealRatio(list.get(1).equals(0) ? 0.0 : Double.valueOf(list.get(1)) / list.get(4)); + } + return manageIndex; + } + + /** + * 获取重复缺陷等级统计数据 + * + * @param month + * @return + */ + private List getRepeatStatistic(String month) { + List re = new ArrayList<>(); + + List repetStatistics = this.baseMapper.getRepetStatistics(AuthUtil.getDeptId()); + //总缺陷数 + int total = repetStatistics.stream().mapToInt(OperDefectStatisticsCodeDTO::getDefectNum).sum(); + //总重复缺陷数 + int totalRepeat = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.summingInt(OperDefectStatisticsCodeDTO::getDefectNum)); + //等级重复统计 + Map repeatList = repetStatistics.stream().filter(s -> s.getDefectNum() > 1 && s.getDefectLevel() != null).collect(Collectors.groupingBy(OperDefectStatisticsCodeDTO::getDefectLevel, Collectors.summarizingInt(OperDefectStatisticsCodeDTO::getDefectNum))); + + OperDefectRepeatRatioDTO one = new OperDefectRepeatRatioDTO(); + one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); + if (repeatList.get(one.getDefectLevel()) != null) { + one.setHappenNum(repeatList.get(one.getDefectLevel()).getSum()); + one.setHappenRatio(one.getHappenNum() / Double.valueOf(total)); + one.setRepeatRatio(one.getHappenNum() / Double.valueOf(totalRepeat)); + } + + OperDefectRepeatRatioDTO two = new OperDefectRepeatRatioDTO(); + two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); + if (repeatList.get(two.getDefectLevel()) != null) { + two.setHappenNum(repeatList.get(two.getDefectLevel()).getSum()); + two.setHappenRatio(two.getHappenNum() / Double.valueOf(total)); + two.setRepeatRatio(two.getHappenNum() / Double.valueOf(totalRepeat)); + } + + OperDefectRepeatRatioDTO three = new OperDefectRepeatRatioDTO(); + three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); + if (repeatList.get(three.getDefectLevel()) != null) { + three.setHappenNum(repeatList.get(three.getDefectLevel()).getSum()); + three.setHappenRatio(three.getHappenNum() / Double.valueOf(total)); + three.setRepeatRatio(three.getHappenNum() / Double.valueOf(totalRepeat)); + } + + OperDefectRepeatRatioDTO addUp = OperDefectRepeatRatioDTO.builder().defectLevel("合计").happenNum(one.getHappenNum() + two.getHappenNum() + three.getHappenNum()).happenRatio(one.getHappenRatio() + two.getHappenRatio() + three.getHappenRatio()).repeatRatio(1.00).build(); + if (addUp.getHappenNum().equals(0L)) { + addUp.setRepeatRatio(0.0); + } + + re.addAll(Arrays.asList(one, two, three, addUp)); + return re; + } + + + private List getRatioStatic(List dtos) { + //本月统计返回 + List re = new ArrayList<>(); + OperDefectRatioDTO one = new OperDefectRatioDTO(); + one.setDefectLevel(DefectConstant.DefectLevelEnum.ONE.getStatus()); + OperDefectRatioDTO two = new OperDefectRatioDTO(); + two.setDefectLevel(DefectConstant.DefectLevelEnum.TWO.getStatus()); + OperDefectRatioDTO three = new OperDefectRatioDTO(); + three.setDefectLevel(DefectConstant.DefectLevelEnum.THREE.getStatus()); + + //等级统计 + Map collectLevel = dtos.stream().filter(s -> s.getDefectLevel() != null).collect(Collectors.groupingBy(OperDefectStatisticsStatusDTO::getDefectLevel, Collectors.summarizingInt(OperDefectStatisticsStatusDTO::getDefectNum))); + //总缺陷数 + int total = dtos.stream().mapToInt(OperDefectStatisticsStatusDTO::getDefectNum).sum(); + //状态统计 + Map collectStatus = dtos.stream().collect(Collectors.groupingBy(OperDefectStatisticsStatusDTO::getHandleStatus, Collectors.summarizingInt(OperDefectStatisticsStatusDTO::getDefectNum))); + + for (OperDefectStatisticsStatusDTO dto : dtos) { + if (dto.getDefectLevel() != null) { + switch (dto.getDefectLevel()) { + case "1": + setReturnRatio(total, one, dto, collectLevel, collectStatus); + break; + case "2": + setReturnRatio(total, two, dto, collectLevel, collectStatus); + break; + case "3": + setReturnRatio(total, three, dto, collectLevel, collectStatus); + break; + default: + break; + } + } + } + int solveNum = collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()) == null ? 0 : (int) collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()).getSum(); + OperDefectRatioDTO addUp = OperDefectRatioDTO.builder().happenNum(total).happenRatio(total == 0 ? 0 : 1.00).defectLevel("合计").sovleRatio(solveNum == 0 ? 0 : 1.00).sovleNum(solveNum).build(); + re.addAll(Arrays.asList(one, two, three, addUp)); + return re; + } + + + private void setReturnRatio(int total, OperDefectRatioDTO ratio, OperDefectStatisticsStatusDTO dto, Map collectLevel, Map collectStatus) { + if (dto.getHandleStatus().equals(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus())) { + ratio.setSovleNum(dto.getDefectNum()); + ratio.setSovleRatio(Double.valueOf(dto.getDefectNum()) / collectStatus.get(DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()).getSum()); + ratio.setHappenNum((int) collectLevel.get(dto.getDefectLevel()).getSum()); + ratio.setHappenRatio(ratio.getHappenNum() / Double.valueOf(total)); + } else { + ratio.setHappenNum((int) collectLevel.get(dto.getDefectLevel()).getSum()); + ratio.setHappenRatio(ratio.getHappenNum() / Double.valueOf(total)); + } + } + + /** + * 更新缺陷信息 + * + * @param entity + * @return + */ + @Override + public boolean updateDefectInfo(OperDefectEntity entity) { + return this.update(Wrappers.lambdaUpdate().set(OperDefectEntity::getActHours, entity.getActHours()).set(OperDefectEntity::getActStartTime, entity.getActStartTime()).set(OperDefectEntity::getActEndTime, entity.getActEndTime()).set(OperDefectEntity::getDisposeDesc, entity.getDisposeDesc()).eq(OperDefectEntity::getDefectCode, entity.getDefectCode())); + } + + @Override + public boolean updateDefectHanderState(OperDefectEntity entity) { + return this.update(Wrappers.lambdaUpdate().set(OperDefectEntity::getHandleStatus, entity.getHandleStatus()).eq(OperDefectEntity::getDefectCode, entity.getDefectCode())); + } + + /** + * 分页查询 + * + * @param operDefectEntityPage + * @param defect + * @return + */ + @Override + public IPage selectPage(Page operDefectEntityPage, OperDefectEntity defect) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(StringUtils.isNotBlank(defect.getDefectCode()), OperDefectEntity::getDefectCode, defect.getDefectCode()); + + //缺陷编号 + queryWrapper.ge(defect.getActStartTime() != null, OperDefectEntity::getActStartTime, defect.getActStartTime()); + + queryWrapper.le(defect.getActEndTime() != null, OperDefectEntity::getActEndTime, defect.getActEndTime()); + + + queryWrapper.ge(defect.getStartTime() != null, OperDefectEntity::getCreateTime, defect.getStartTime()); + + queryWrapper.le(defect.getEndTime() != null, OperDefectEntity::getCreateTime, defect.getEndTime()); + //区域Id + queryWrapper.eq(BaseEntity::getCreateDept, defect.getCreateDept()); + //年月查询 + queryWrapper.apply(defect.getYearMonth() != null, "date_format(CREATE_TIME,'%Y-%m') = '" + + defect.getYearMonth() + "'"); + + queryWrapper.orderByDesc(OperDefectEntity::getActStartTime); + return baseMapper.selectPage(operDefectEntityPage, queryWrapper); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java index 0e63ad2..99a9de9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/web/AreaMonthlyDetailsController.java @@ -1,11 +1,26 @@ package com.hnac.hzims.operational.main.controller.web; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.operational.access.dto.OperAccessStatisticsDTO; +import com.hnac.hzims.operational.access.service.IOperAccessStatisticsService; +import com.hnac.hzims.operational.access.vo.OperAccessStatisticsVO; +import com.hnac.hzims.operational.defect.entity.OperDefectEntity; +import com.hnac.hzims.operational.defect.service.IOperDefectService; +import com.hnac.hzims.operational.defect.vo.OperDefectVO; +import com.hnac.hzims.operational.defect.wrapper.OperDefectWrapper; import com.hnac.hzims.operational.main.service.AreaMonthlyDetailsService; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckMonthVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.SafeEquipmentTrialVO; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoEvaluateVO; import com.hnac.hzims.ticket.areamonthly.dto.TicketInfoEvaluateDto; @@ -16,7 +31,9 @@ import com.hnac.hzinfo.inspect.task.entity.TaskEntity; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.support.BladePage; +import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.SpringQueryMap; @@ -43,6 +60,10 @@ public class AreaMonthlyDetailsController { private final IOperMaintenanceTaskService taskService; + private final IOperDefectService defectService; + + + private final IOperAccessStatisticsService accessStatisticsService; /** * 操作票 根据月份,区域 获取操作详情数据 @@ -143,4 +164,158 @@ public class AreaMonthlyDetailsController { return R.data(task); } + + /** + * 根据区域和月份分页查询缺陷库 + */ + @ApiOperationSupport(order = 70) + @ApiOperation(value = "分页查询") + @GetMapping("/queryDefectPageList/{page}/{size}") + public R> queryDefectPageList( + @PathVariable Long page, + @PathVariable Long size, + OperDefectEntity defect) { + Page operDefectEntityPage = new Page<>(page, size); + IPage pages = defectService.selectPage(operDefectEntityPage, defect); + IPage vos = OperDefectWrapper.build().pageVO(pages); + return R.data(vos); + } + + + /** + * 根据区域和月份分页查询缺陷库 详情 + */ + @GetMapping("queryDefectPageDetail/detail") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "详情", notes = "传入defect") + public R queryDefectPageDetail(OperDefectEntity defect) { + return defectService.detail(defect); + } + + + /** + * 根据区域和月份分页查询检修任务 + */ + @ApiOperationSupport(order = 80) + @ApiOperation(value = "根据区域和月份分页查询检修任务") + @GetMapping("/queryReconditionPageList/{page}/{size}") + public R> queryReconditionPageList( + @PathVariable Long page, @PathVariable Long size, + OperAccessStatisticsDTO result) { + Page dbPage = new Page<>(page, size); + R> r = accessStatisticsService.list(result, dbPage); + return r; + } + + + /** + * 根据区域 编号查询检修任务详情 + */ + @GetMapping("/queryReconditionPageDetail/detail") + @ApiOperationSupport(order = 40) + @ApiOperation(value = "根据区域 编号查询检修任务详情") + public R queryReconditionPageDetail(@RequestParam Long id) { + R detail = accessStatisticsService.detail(id); + return detail; + } + + + /** + * 根据区域编号查询安全生产会议次数 + */ + @GetMapping("/queryProduceNumByAreaCode/{page}/{size}") + @ApiOperationSupport(order = 90) + @ApiOperation(value = "根据区域编号查询安全生产会议次数") + public R> queryProduceNumByAreaCode(@PathVariable Long page, @PathVariable Long size, + CheckMonthEntity req) { + req.setItemName("现场每月1次安全生产会议"); + BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, + req); + return R.data(checkMonthVoBladePage); + } + + /** + * 根据区域编号查询技能培训 + */ + @GetMapping("/querySkillByAreaCode/{page}/{size}") + @ApiOperationSupport(order = 100) + @ApiOperation(value = "根据区域编号查询技能培训") + public R> querySkillByAreaCode(@PathVariable Long page, @PathVariable Long size, CheckMonthEntity req) { + req.setItemName("每月开展1次技能培训"); + BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, + req); + return R.data(checkMonthVoBladePage); + } + + + /** + * 根据区域编号查询月度自查 + */ + @GetMapping("/queryProduceByAreaCode/{page}/{size}") + @ApiOperationSupport(order = 100) + @ApiOperation(value = "根据区域编号查询技能培训") + public R> queryProduceByAreaCode(@PathVariable Long page, @PathVariable Long size, CheckMonthEntity req) { + BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryProduceByAreaCode(page, size, + req); + return R.data(checkMonthVoBladePage); + } + + + + /** + * 根据区域编号查询 月度自查 技能培训 安全生产会议次数 + */ + @GetMapping("/queryProduceByAreaCodeDetail/detail/{id}") + @ApiOperationSupport(order = 40) + @ApiOperation(value = "详情", notes = "传入id") + public R queryProduceByAreaCodeDetail(@PathVariable Long id){ + CheckMonthVo checkMonthVo = areaMonthlyDetailsService.queryProduceByAreaCodeDetail(id); + return R.data(checkMonthVo); + } + + + /** + * 根据区域编号查询安全检查 + */ + @GetMapping("/querySecurityAreaCode/{page}/{size}") + @ApiOperationSupport(order = 100) + @ApiOperation(value = "根据区域编号查询安全检查") + public R> querySecurityAreaCode(@PathVariable Long page, + @PathVariable Long size, + CheckCompanyEntity req) { + BladePage checkMonthVoBladePage = areaMonthlyDetailsService.querySecurityAreaCode(page, size, + req); + return R.data(checkMonthVoBladePage); + } + + + /** + * 根据区域编号查询安全检查 详情 + */ + @GetMapping("/querySecurityAreaCode/detail/{id}") + @ApiOperationSupport(order = 100) + @ApiOperation(value = "根据区域编号查询安全检查 详情") + public R querySecurityAreaCodeDetail(@PathVariable Long id) { + CheckCompanyVo checkMonthVoBladePage = areaMonthlyDetailsService.querySecurityAreaCodeDetail(id); + return R.data(checkMonthVoBladePage); + } + + + + /** + * 根据区域编号查询设备试验 + */ + @GetMapping("/queryEquipmentAreaCode/{page}/{size}") + @ApiOperationSupport(order = 100) + @ApiOperation(value = "根据区域编号查询设备试验") + public R> queryEquipmentAreaCode( + @PathVariable Long page, + @PathVariable Long size, + SafeEquipmentTrialDTO safeEquipmentTrialDTO) { + BladePage checkMonthVoBladePage = areaMonthlyDetailsService.queryEquipmentAreaCode(page + ,size,safeEquipmentTrialDTO); + return R.data(checkMonthVoBladePage); + } + + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AreaMonthlyDetailsService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AreaMonthlyDetailsService.java index 1322f12..9c3bc26 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AreaMonthlyDetailsService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AreaMonthlyDetailsService.java @@ -1,6 +1,12 @@ package com.hnac.hzims.operational.main.service; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckMonthVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.SafeEquipmentTrialVO; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoEvaluateVO; import com.hnac.hzims.ticket.areamonthly.dto.TicketInfoEvaluateDto; @@ -75,4 +81,45 @@ public interface AreaMonthlyDetailsService { * @return */ TaskEntity queryCheckTaskById(Long id); + + /** + * 根据区域编号查询安全生产会议次数 技能培训 + * @param page + * @param size + * @param req + * @return + */ + BladePage queryProduceByAreaCode(Long page, Long size, CheckMonthEntity req); + + /** + * 根据区域编号查询 月度自查 技能培训 安全生产会议次数 + */ + CheckMonthVo queryProduceByAreaCodeDetail(Long id); + + + /** + * 根据区域编号查询安全检查 + * @param page + * @param size + * @param req + * @return + */ + BladePage querySecurityAreaCode(Long page, Long size, CheckCompanyEntity req); + + /** + * 根据区域编号查询安全检查 详情 + * @param id + * @return + */ + CheckCompanyVo querySecurityAreaCodeDetail(Long id); + + /** + * 根据区域编号查询设备试验 + * @param page + * @param size + * @param safeEquipmentTrialDTO + * @return + */ + BladePage queryEquipmentAreaCode(Long page, Long size, SafeEquipmentTrialDTO safeEquipmentTrialDTO); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthlyDetailsServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthlyDetailsServiceImpl.java index 6dfda4f..1c43df8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthlyDetailsServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthlyDetailsServiceImpl.java @@ -1,6 +1,15 @@ package com.hnac.hzims.operational.main.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.areamonthly.feign.CheckCompanyFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.feign.SafeEquipmentTrialFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.feign.SafeproductFeignClient; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckCompanyVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.CheckMonthVo; +import com.hnac.hzims.safeproduct.areamonthly.vo.SafeEquipmentTrialVO; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; +import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; import com.hnac.hzims.ticket.allTicket.entity.TicketInfoEvaluateEntity; import com.hnac.hzims.ticket.allTicket.vo.TicketInfoEvaluateVO; import com.hnac.hzims.ticket.areamonthly.dto.TicketInfoEvaluateDto; @@ -38,6 +47,13 @@ public class AreaMonthlyDetailsServiceImpl implements AreaMonthlyDetailsService private final TaskFeignClient taskFeignClient; + private final SafeproductFeignClient safeproductFeignClient; + + private final CheckCompanyFeignClient checkCompanyFeignClient; + + + private final SafeEquipmentTrialFeignClient safeEquipmentTrialFeignClient; + /** * 根据月份,区域 获取操作详情数据 @@ -49,8 +65,7 @@ public class AreaMonthlyDetailsServiceImpl implements AreaMonthlyDetailsService */ @Override public BladePage areaMonthlyWithOperation(Long page, Long size, StandardTicketWithAreaVo areaMonthly) { - R> pageR = - ticketFeignClient.areaMonthlyWithOperation(page, size, areaMonthly); + R> pageR = ticketFeignClient.areaMonthlyWithOperation(page, size, areaMonthly); if (pageR.isSuccess()) { log.info("获取操作详情数据成功"); return pageR.getData(); @@ -68,9 +83,8 @@ public class AreaMonthlyDetailsServiceImpl implements AreaMonthlyDetailsService * @return */ @Override - public BladePage workTicketListByMonthAndArea(Long page, Long size,StandardTicketWithAreaVo areaMonthlyVo) { - R> pageR = - ticketFeignClient.workTicketListByMonthAndArea(page, size, areaMonthlyVo); + public BladePage workTicketListByMonthAndArea(Long page, Long size, StandardTicketWithAreaVo areaMonthlyVo) { + R> pageR = ticketFeignClient.workTicketListByMonthAndArea(page, size, areaMonthlyVo); if (pageR.isSuccess()) { log.info("获取操作详情数据成功"); return pageR.getData(); @@ -149,6 +163,7 @@ public class AreaMonthlyDetailsServiceImpl implements AreaMonthlyDetailsService /** * 根据id查询巡检任务 + * * @param id * @return */ @@ -162,4 +177,101 @@ public class AreaMonthlyDetailsServiceImpl implements AreaMonthlyDetailsService log.error("获取检查巡检任务详情失败", detail.getMsg()); return null; } + + /** + * 根据区域编号查询安全生产会议次数 技能培训 + * + * @param page + * @param size + * @param req + * @return + */ + @Override + public BladePage queryProduceByAreaCode(Long page, Long size, CheckMonthEntity req) { + R> detail = safeproductFeignClient.listconferenceScope(page, size, req); + if (detail.isSuccess()) { + log.info("获取安全生产会议次数 技能培训成功"); + return detail.getData(); + } + log.error("获取安全生产会议次数 技能培训失败", detail.getMsg()); + return null; + } + + /** + * 根据区域编号查询 月度自查 技能培训 安全生产会议次数 + * + * @param id + */ + @Override + public CheckMonthVo queryProduceByAreaCodeDetail(Long id) { + R detail = safeproductFeignClient.detail(id); + if (detail.isSuccess()) { + log.info("根据区域编号查询 月度自查 技能培训 安全生产会议次数成功"); + return detail.getData(); + } + log.error("根据区域编号查询 月度自查 技能培训 安全生产会议次数失败", detail.getMsg()); + return null; + } + + /** + * 根据区域编号查询安全检查 + * + * @param page + * @param size + * @param req + * @return + */ + @Override + public BladePage querySecurityAreaCode(Long page, Long size, CheckCompanyEntity req) { + Query query = new Query(); + query.setCurrent(page.intValue()); + query.setSize(size.intValue()); + R> list = checkCompanyFeignClient.list(req, query); + if (list.isSuccess()) { + log.info("根据区域编号查询安全检查成功"); + return list.getData(); + } + log.error("根据区域编号查询安全检查失败", list.getMsg()); + return null; + } + + /** + * 根据区域编号查询安全检查详情 + * + * @param id + * @return + */ + @Override + public CheckCompanyVo querySecurityAreaCodeDetail(Long id) { + R detailed = checkCompanyFeignClient.detail(id); + if (detailed.isSuccess()) { + log.info(" 根据区域编号查询安全检查详情成功"); + return detailed.getData(); + } + log.error(" 根据区域编号查询安全检查详情失败", detailed.getMsg()); + return null; + } + + /** + * 根据区域编号查询设备试验 + * + * @param page + * @param size + * @param safeEquipmentTrialDTO + * @return + */ + @Override + public BladePage queryEquipmentAreaCode(Long page, Long size, SafeEquipmentTrialDTO safeEquipmentTrialDTO) { + Query query = new Query(); + query.setCurrent(page.intValue()); + query.setSize(size.intValue()); + R> list = safeEquipmentTrialFeignClient.list(safeEquipmentTrialDTO, query); + if (list.isSuccess()) { + log.info("根据区域编号查询设备试验成功"); + return list.getData(); + } + log.error("根据区域编号查询设备试验失败", list.getMsg()); + return null; + + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckCompanyController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckCompanyController.java index 6cf81d8..24d5f35 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckCompanyController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckCompanyController.java @@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.system.entity.Dept; @@ -76,7 +77,7 @@ public class CheckCompanyController extends BladeController { @GetMapping("/list") @ApiOperationSupport(order = 50) @ApiOperation(value = "分页", notes = "查询条件:startDate,endDate,status") - public R> list(CheckCompanyEntity req, Query query) { + public R> list(CheckCompanyEntity req, Query query) { return CheckCompanyService.pageCondition(req, query); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckMonthController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckMonthController.java index d783ac6..2359474 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckMonthController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CheckMonthController.java @@ -1,6 +1,7 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.safeproduct.dto.CheckMonthDTO; import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; @@ -11,6 +12,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.system.entity.Dept; @@ -108,4 +110,29 @@ public class CheckMonthController extends BladeController { return R.data(page); } + + + + /** + * 分页查询安全生产会议次数 + */ + @GetMapping("/listconferenceScope/{page}/{size}") + @ApiOperationSupport(order = 50) + @ApiOperation(value = "分页", notes = "查询条件:month,status,createDept") + public R> listconferenceScope( + @PathVariable Long page, @PathVariable Long size, + CheckMonthEntity req) { + Page objectPage = new Page<>(page, size); + R> pageR = checkMonthlyService.listconferenceScope(req,objectPage); + IPage pages = pageR.getData(); + pages.getRecords().forEach(monthlyVo -> { + R deptR = sysClient.getDept(monthlyVo.getCreateDept()); + if (deptR.isSuccess()) { + monthlyVo.setDeptName(Optional.ofNullable(deptR.getData()).map(Dept::getDeptName).orElse(null)); + } + }); + BladePage bladePage = BladePage.of(pages); + return R.data(bladePage); + } + } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SafeEquipmentTrialController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SafeEquipmentTrialController.java index 70249b2..20685f3 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SafeEquipmentTrialController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/SafeEquipmentTrialController.java @@ -14,6 +14,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; @@ -58,7 +59,7 @@ public class SafeEquipmentTrialController extends BladeController { @ApiOperation(value = "分页", notes = "查询条件:createDept,fileName,startTime,endTime") @OperationAnnotation(title = "设备试验",operatorType = OperatorType.MOBILE,businessType = BusinessType.GENCODE, action = "分页条件") - public R> list(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query) { + public R> list(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query) { return service.pageCondition(safeEquipmentTrialDTO, query); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.java index 4f6701a..943098c 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.java @@ -2,7 +2,9 @@ package com.hnac.hzims.safeproduct.mapper; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; +import com.hnac.hzims.safeproduct.vo.CheckMonthVo; import org.apache.ibatis.annotations.Param; import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; import org.springblade.core.mp.support.Query; @@ -21,4 +23,11 @@ public interface CheckMonthMapper extends UserDataScopeBaseMapper pageNotDataScope(IPage page, @Param("req") CheckMonthEntity req); + /** + * 分页查询安全生产会议次数 + * @param objectPage + * @param req + * @return + */ + IPage listconferenceScope(IPage objectPage, @Param("req") CheckMonthEntity req); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.xml index f9f6710..84ad46d 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.xml +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CheckMonthMapper.xml @@ -15,5 +15,32 @@ order by CREATE_TIME desc + + diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckCompanyService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckCompanyService.java index 0987903..217a5dc 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckCompanyService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckCompanyService.java @@ -8,6 +8,7 @@ import com.hnac.hzims.safeproduct.entity.CheckQuarterEntity; import com.hnac.hzims.safeproduct.vo.CheckCompanyVo; import com.hnac.hzims.safeproduct.vo.CheckQuarterVo; import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -24,6 +25,6 @@ public interface ICheckCompanyService extends BaseService { R detail(Long id); - R> pageCondition(CheckCompanyEntity req, Query query); + R> pageCondition(CheckCompanyEntity req, Query query); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckMonthService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckMonthService.java index 337117a..d71a996 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckMonthService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICheckMonthService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.safeproduct.service; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.safeproduct.dto.CheckMonthDTO; import com.hnac.hzims.safeproduct.entity.CheckMonthEntity; import com.hnac.hzims.safeproduct.vo.CheckMonthVo; @@ -25,4 +26,12 @@ public interface ICheckMonthService extends BaseService { R> pageNotDataScope(CheckMonthEntity req, Query query); + + /** + * 分页查询安全生产会议次数 + * @param req + * @param objectPage + * @return + */ + R> listconferenceScope(CheckMonthEntity req, Page objectPage); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/SafeEquipmentTrialService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/SafeEquipmentTrialService.java index 1ba9d36..33fad1b 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/SafeEquipmentTrialService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/SafeEquipmentTrialService.java @@ -6,6 +6,7 @@ import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; import com.hnac.hzims.safeproduct.vo.SafeEquipmentTrialVO; import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -16,7 +17,7 @@ import java.util.List; */ public interface SafeEquipmentTrialService extends BaseService { - R> pageCondition(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query); + R> pageCondition(SafeEquipmentTrialDTO safeEquipmentTrialDTO, Query query); int getSafeEquipmentCount(SafeEquipmentTrialDTO dto); diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckCompanyServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckCompanyServiceImpl.java index 841ca7e..becd6c8 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckCompanyServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckCompanyServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; 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.StringUtils; import com.hnac.hzims.safeproduct.dto.CheckCompanyDTO; import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; import com.hnac.hzims.safeproduct.entity.CheckItemEntity; @@ -15,7 +16,9 @@ import com.hnac.hzims.safeproduct.vo.CheckCompanyVo; import com.hnac.hzims.safeproduct.wrapper.CheckCompanyWrapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseEntity; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -37,112 +40,117 @@ import java.util.stream.Collectors; @Slf4j public class CheckCompanyServiceImpl extends BaseServiceImpl implements ICheckCompanyService { - private final CheckCompanyMapper CheckCompanyMapper; + private final CheckCompanyMapper CheckCompanyMapper; - private final ICheckItemInstanceService itemInstanceService; + private final ICheckItemInstanceService itemInstanceService; - private final ISysClient sysClient; + private final ISysClient sysClient; - @Override - public boolean doSave(CheckCompanyDTO req) { - boolean result = save(req); - if (result) { - Long checkId = req.getId(); - List items = req.getItems(); - items.forEach(item -> { - item.setOid(item.getId()); - item.setId(null); - item.setCheckId(checkId); - }); - itemInstanceService.saveBatch(items); - } - return result; - } + @Override + public boolean doSave(CheckCompanyDTO req) { + boolean result = save(req); + if (result) { + Long checkId = req.getId(); + List items = req.getItems(); + items.forEach(item -> { + item.setOid(item.getId()); + item.setId(null); + item.setCheckId(checkId); + }); + itemInstanceService.saveBatch(items); + } + return result; + } - @Override - public boolean doUpdate(CheckCompanyDTO req) { - boolean result = updateById(req); - if (result) { - List items = req.getItems(); - items.forEach(itemInstanceService::updateById); - } - return result; - } + @Override + public boolean doUpdate(CheckCompanyDTO req) { + boolean result = updateById(req); + if (result) { + List items = req.getItems(); + items.forEach(itemInstanceService::updateById); + } + return result; + } - @Override - public R detail(Long id) { - CheckCompanyEntity entity = CheckCompanyMapper.selectById(id); - CheckCompanyVo vo = CheckCompanyWrapper.build().entityVO(entity); - //查询检查项 - QueryWrapper queryMapper = new QueryWrapper<>(); - queryMapper.eq("CHECK_ID", vo.getId()); - queryMapper.orderByAsc("ORG_ID", "SORT"); - List items = itemInstanceService.list(queryMapper); - //查询子项,用于前端判断 - items.forEach(item -> item.setChildren(findChildren(item, items))); - //按部门分组 - List> list = new ArrayList<>(); - Map> map = items.stream().collect(Collectors.groupingBy(CheckItemInstanceEntity::getOrgId)); - for (Map.Entry> entry : map.entrySet()) { - Map data = new HashMap<>(); - data.put("deptId", entry.getKey()); - R deptR = sysClient.getDept(entry.getKey()); - if (deptR.isSuccess()) { - data.put("deptName", Optional.ofNullable(deptR.getData()).map(Dept::getDeptName).orElse(null)); - } else { - data.put("deptName", null); - } - data.put("items", entry.getValue()); - list.add(data); - } - vo.setItems(list); - return R.data(vo); - } + @Override + public R detail(Long id) { + CheckCompanyEntity entity = CheckCompanyMapper.selectById(id); + CheckCompanyVo vo = CheckCompanyWrapper.build().entityVO(entity); + //查询检查项 + QueryWrapper queryMapper = new QueryWrapper<>(); + queryMapper.eq("CHECK_ID", vo.getId()); + queryMapper.orderByAsc("ORG_ID", "SORT"); + List items = itemInstanceService.list(queryMapper); + //查询子项,用于前端判断 + items.forEach(item -> item.setChildren(findChildren(item, items))); + //按部门分组 + List> list = new ArrayList<>(); + Map> map = items.stream().collect(Collectors.groupingBy(CheckItemInstanceEntity::getOrgId)); + for (Map.Entry> entry : map.entrySet()) { + Map data = new HashMap<>(); + data.put("deptId", entry.getKey()); + R deptR = sysClient.getDept(entry.getKey()); + if (deptR.isSuccess()) { + data.put("deptName", Optional.ofNullable(deptR.getData()).map(Dept::getDeptName).orElse(null)); + } else { + data.put("deptName", null); + } + data.put("items", entry.getValue()); + list.add(data); + } + vo.setItems(list); + return R.data(vo); + } - private List findChildren(CheckItemInstanceEntity entity, List list) { - List child = new ArrayList<>(); - for (CheckItemInstanceEntity itemEntity : list) { - if (null != itemEntity.getParentItem() - && itemEntity.getParentItem().equals(entity.getOid()) - && itemEntity.getOrgId().equals(entity.getOrgId())) { - child.add(itemEntity); - itemEntity.setChildren(findChildren(itemEntity, list)); - } - } - return child; - } + private List findChildren(CheckItemInstanceEntity entity, List list) { + List child = new ArrayList<>(); + for (CheckItemInstanceEntity itemEntity : list) { + if (null != itemEntity.getParentItem() + && itemEntity.getParentItem().equals(entity.getOid()) + && itemEntity.getOrgId().equals(entity.getOrgId())) { + child.add(itemEntity); + itemEntity.setChildren(findChildren(itemEntity, list)); + } + } + return child; + } - @Override - public boolean doDelete(String ids) { - List list = Func.toLongList(ids); - boolean result = deleteLogic(list); - if (result) { - list.forEach(id -> { - QueryWrapper queryMapper = new QueryWrapper<>(); - queryMapper.eq("CHECK_ID", id); - itemInstanceService.remove(queryMapper); - }); - } - return result; - } + @Override + public boolean doDelete(String ids) { + List list = Func.toLongList(ids); + boolean result = deleteLogic(list); + if (result) { + list.forEach(id -> { + QueryWrapper queryMapper = new QueryWrapper<>(); + queryMapper.eq("CHECK_ID", id); + itemInstanceService.remove(queryMapper); + }); + } + return result; + } - @Override - public R> pageCondition(CheckCompanyEntity req, Query query) { - Wrapper queryWrapper = new LambdaQueryWrapper() {{ - orderByDesc(CheckCompanyEntity::getCreateTime); - if (ObjectUtil.isNotEmpty(req.getStartTime())) { - ge(CheckCompanyEntity::getStartTime, req.getStartTime()); - } - if (ObjectUtil.isNotEmpty(req.getEndTime())) { - le(CheckCompanyEntity::getEndTime, req.getEndTime()); - } - if (ObjectUtil.isNotEmpty(req.getStatus())) { - eq(CheckCompanyEntity::getStatus, req.getStatus()); - } - }}; - IPage page = page(Condition.getPage(query), queryWrapper); - page.setRecords(CheckCompanyWrapper.build().listVO(page.getRecords())); - return R.data(page); - } + @Override + public R> pageCondition(CheckCompanyEntity req, Query query) { + Wrapper queryWrapper = new LambdaQueryWrapper() {{ + orderByDesc(CheckCompanyEntity::getCreateTime); + if (ObjectUtil.isNotEmpty(req.getStartTime())) { + ge(CheckCompanyEntity::getStartTime, req.getStartTime()); + } + if (ObjectUtil.isNotEmpty(req.getEndTime())) { + le(CheckCompanyEntity::getEndTime, req.getEndTime()); + } + if (ObjectUtil.isNotEmpty(req.getStatus())) { + eq(CheckCompanyEntity::getStatus, req.getStatus()); + } + eq(StringUtils.isNotBlank(req.getAreaId()), BaseEntity::getCreateDept, req.getAreaId()); + apply(req.getYearMonth() != null, "date_format(start_time ,'%Y-%m') = '" + + req.getYearMonth() + "'" + "and date_format(end_time,'%Y-%m') = '" + req.getYearMonth() + "'"); + + }}; + IPage page = page(Condition.getPage(query), queryWrapper); + page.setRecords(CheckCompanyWrapper.build().listVO(page.getRecords())); + BladePage bladePage = BladePage.of(page); + return R.data(bladePage); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckMonthServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckMonthServiceImpl.java index 0b1a41b..e316f8a 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckMonthServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CheckMonthServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; 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.extension.plugins.pagination.Page; import com.hnac.hzims.safeproduct.dto.CheckMonthDTO; import com.hnac.hzims.safeproduct.entity.CheckItemEntity; import com.hnac.hzims.safeproduct.entity.CheckItemInstanceEntity; @@ -140,4 +141,17 @@ public class CheckMonthServiceImpl extends BaseServiceImpl> listconferenceScope(CheckMonthEntity req, Page objectPage) { + IPage page = checkMonthMapper.listconferenceScope(objectPage, req); + page.setRecords(CheckMonthWrapper.build().listVO(page.getRecords())); + return R.data(page); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafeEquipmentTrialServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafeEquipmentTrialServiceImpl.java index b9ffebb..7c9f4a9 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafeEquipmentTrialServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/SafeEquipmentTrialServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.safeproduct.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.hnac.hzims.safeproduct.dto.SafeEquipmentDTO; import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; import com.hnac.hzims.safeproduct.entity.SafeEquipmentTrialEntity; @@ -11,6 +12,7 @@ import com.hnac.hzims.safeproduct.vo.SafeEquipmentTrialVO; import com.hnac.hzims.safeproduct.wrapper.SafeEquipmentTrialWrapper; import lombok.RequiredArgsConstructor; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -26,83 +28,91 @@ import java.util.Optional; @RequiredArgsConstructor public class SafeEquipmentTrialServiceImpl extends BaseServiceImpl implements SafeEquipmentTrialService { - /** - * 分页查询 - * @param param - * @param query - * @return - */ - @Override - public R> pageCondition(SafeEquipmentTrialDTO param, Query query) { - QueryWrapper queryWrapper = new QueryWrapper() {{ - if(Optional.ofNullable(param.getCreateDept()).isPresent()){ - eq("create_dept",param.getCreateDept()); - } - if(Optional.ofNullable(param.getFileName()).isPresent()){ - like("file_name","%".concat(param.getFileName()).concat("%")); - } - if(Optional.ofNullable(param.getStartTime()).isPresent()){ - gt("create_time", param.getStartTime()); - } - if(Optional.ofNullable(param.getEndTime()).isPresent()){ - lt("create_time", param.getEndTime()); - } - orderByDesc("create_time"); - }}; - IPage pages = super.page(Condition.getPage(query), queryWrapper); - List list = SafeEquipmentTrialWrapper.build().listVO(pages.getRecords()); - return R.data(pages.setRecords(list)); - } + /** + * 分页查询 + * + * @param param + * @param query + * @return + */ + @Override + public R> pageCondition(SafeEquipmentTrialDTO param, Query query) { + QueryWrapper queryWrapper = new QueryWrapper() {{ + if (Optional.ofNullable(param.getCreateDept()).isPresent()) { + eq("create_dept", param.getCreateDept()); + } + if (Optional.ofNullable(param.getFileName()).isPresent()) { + like("file_name", "%".concat(param.getFileName()).concat("%")); + } + if (Optional.ofNullable(param.getStartTime()).isPresent()) { + gt("create_time", param.getStartTime()); + } + if (Optional.ofNullable(param.getEndTime()).isPresent()) { + lt("create_time", param.getEndTime()); + } + lambda().eq(StringUtils.isNotBlank(param.getAreaId()), SafeEquipmentTrialEntity::getCreateDept, + param.getAreaId()); + eq(param.getYearMonth() != null, "date_format(CREATE_TIME,'%Y-%m)", param.getYearMonth()); + orderByDesc("create_time"); + }}; + IPage pages = super.page(Condition.getPage(query), queryWrapper); + List list = SafeEquipmentTrialWrapper.build().listVO(pages.getRecords()); + pages.setRecords(list); + BladePage bladePage = BladePage.of(pages); + return R.data(bladePage); + } - /** - * 获取设备试验次数 - * @param param - * @return - */ - @Override - public int getSafeEquipmentCount(SafeEquipmentTrialDTO param) { - if(ObjectUtil.isEmpty(param)){ - return 0; - } - QueryWrapper queryWrapper = new QueryWrapper() {{ - if(CollectionUtil.isEmpty(param.getDeptList())){ - if(Optional.ofNullable(param.getCreateDept()).isPresent()){ - eq("create_dept",param.getCreateDept()); - } - } else { - in("create_dept",param.getDeptList()); - } - if(Optional.ofNullable(param.getStartTime()).isPresent()){ - gt("create_time", param.getStartTime()); - } - if(Optional.ofNullable(param.getEndTime()).isPresent()){ - lt("create_time", param.getEndTime()); - } - }}; - return this.baseMapper.selectCount(queryWrapper); - } + /** + * 获取设备试验次数 + * + * @param param + * @return + */ + @Override + public int getSafeEquipmentCount(SafeEquipmentTrialDTO param) { + if (ObjectUtil.isEmpty(param)) { + return 0; + } + QueryWrapper queryWrapper = new QueryWrapper() {{ + if (CollectionUtil.isEmpty(param.getDeptList())) { + if (Optional.ofNullable(param.getCreateDept()).isPresent()) { + eq("create_dept", param.getCreateDept()); + } + } else { + in("create_dept", param.getDeptList()); + } + if (Optional.ofNullable(param.getStartTime()).isPresent()) { + gt("create_time", param.getStartTime()); + } + if (Optional.ofNullable(param.getEndTime()).isPresent()) { + lt("create_time", param.getEndTime()); + } + }}; + return this.baseMapper.selectCount(queryWrapper); + } - /** - * 查询设备列表 - * @param entity - * @return - */ - @Override - public List getList(SafeEquipmentDTO entity) { - QueryWrapper queryWrapper = new QueryWrapper() {{ - if(CollectionUtil.isEmpty(entity.getDeptList())){ - if(Optional.ofNullable(entity.getCreateDept()).isPresent()){ - eq("create_dept",entity.getCreateDept()); - } - } else { - in("create_dept",entity.getDeptList()); - } - if(Optional.ofNullable(entity.getTime()).isPresent()){ - gt("create_time", entity.getTime()); - lt("create_time", entity.getTime()); - } - }}; - return this.baseMapper.selectList(queryWrapper); - } + /** + * 查询设备列表 + * + * @param entity + * @return + */ + @Override + public List getList(SafeEquipmentDTO entity) { + QueryWrapper queryWrapper = new QueryWrapper() {{ + if (CollectionUtil.isEmpty(entity.getDeptList())) { + if (Optional.ofNullable(entity.getCreateDept()).isPresent()) { + eq("create_dept", entity.getCreateDept()); + } + } else { + in("create_dept", entity.getDeptList()); + } + if (Optional.ofNullable(entity.getTime()).isPresent()) { + gt("create_time", entity.getTime()); + lt("create_time", entity.getTime()); + } + }}; + return this.baseMapper.selectList(queryWrapper); + } } From 21395db1204617c4b9e0acf1b1b28005a0b189ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Thu, 13 Apr 2023 12:40:22 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/msgpushrecord/MessagePushRecordTypeVo.java | 4 + .../vo/msgpushrecord/MessagePushRecordVo.java | 6 ++ .../message/mapper/MessagePushRecordMapper.xml | 1 + .../service/impl/MessagePushRecordServiceImpl.java | 112 ++++++++++++++++++++- .../hzims/operational/OperationApplication.java | 9 ++ 5 files changed, 128 insertions(+), 4 deletions(-) diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java index 8ed09ba..a1ce5ed 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordTypeVo.java @@ -17,6 +17,10 @@ public class MessagePushRecordTypeVo { * 消息类型 */ private String type; + /** + * 消息类型名称 + */ + private String typeName; private List messagePushRecordList; } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java index 0362dd8..444ef94 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/vo/msgpushrecord/MessagePushRecordVo.java @@ -40,6 +40,12 @@ public class MessagePushRecordVo implements Serializable { */ private String type; + + /** + * 消息类型名称 + */ + private String typeName; + /** * 统计数量 */ diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml index 0412c8c..0eb5aa4 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/mapper/MessagePushRecordMapper.xml @@ -22,6 +22,7 @@ from hzims_message_push_record IS_DELETED = 0 + and PLAN_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 12 MONTH) AND NOW() and DEPT_ID = #{vo.stationCode} diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index d98330d..b18aefd 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -34,10 +34,13 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import javax.validation.Valid; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.Year; import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -146,6 +149,52 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl { + List messagePushRecordList = item1.getMessagePushRecordList(); + //String messageType = DictCache.getValue("messageType", item1.getType()); + //System.out.println("messageType = " + messageType); + String typeByName = getTypeByName(item1.getType()); + item1.setTypeName(typeByName); + //获取以往12个月的数据 + List previousMonth = this.getPreviousMonth(); + //创建新的数组 List + List lists = new ArrayList<>(); + messagePushRecordList.forEach(item2 -> { + YearMonth strMonth = item2.getStrMonth(); + // 字符串转localDate 获取月份 + item2.setMonth(strMonth.getMonthValue()); + item2.setYear(strMonth.getYear()); + if (previousMonth.contains(strMonth)) { + previousMonth.remove(strMonth); + } + //封装typeValue + item2.setTypeName(typeByName); + lists.add(item2); + }); + + //如果还存在YearMonth,把MessagePushRecordVo添加到新的数组 List + if (CollectionUtils.isNotEmpty(previousMonth)) { + for (YearMonth yearMonth : previousMonth) { + MessagePushRecordVo messagePushRecordVo = new MessagePushRecordVo(); + messagePushRecordVo.setYear(yearMonth.getYear()); + messagePushRecordVo.setMonth(yearMonth.getMonthValue()); + messagePushRecordVo.setType(item1.getType()); + messagePushRecordVo.setPower(0L); + messagePushRecordVo.setStrMonth(yearMonth); + //封装typeValue + messagePushRecordVo.setTypeName(typeByName); + lists.add(messagePushRecordVo); + } + } + List newLists = lists.stream().sorted(Comparator.comparing(MessagePushRecordVo::getStrMonth).reversed()).collect(Collectors.toList()); + // 封装到 setMessagePushRecordList + item1.setMessagePushRecordList(newLists); + }); + + return messagePushRecordTypeVos; } @@ -271,8 +320,44 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl typeName + * + * @param key 状态 + */ + private String getTypeByName(String key) { + String value = null; + switch (key) { + case "appPush": + value = "app推送"; + break; + case "smsPush": + value = "短信推送"; + break; + case "websocketPush": + value = "web推送"; + break; + case "mailPush": + value = "邮件推送"; + break; + default: + value = DictCache.getValue("messageType", key); + if (value == null) { + log.error("状态异常,没有这状态"); + value = key; + } break; } return value; @@ -300,8 +385,14 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl getPreviousMonth() { + List month = new ArrayList<>(); + YearMonth today = YearMonth.now(); + for (int i = 0; i <= 11; i++) { + YearMonth localDate = today.minusMonths(i); + month.add(localDate); + } + return month; + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java index e8cca7f..42143c2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/OperationApplication.java @@ -40,6 +40,15 @@ import javax.annotation.Resource; @Resource public class OperationApplication extends SpringBootServletInitializer { + static{ + System.setProperty("--spring.cloud.nacos.discovery.server-addr", "http://175.6.40.67:10042"); + System.setProperty("--spring.cloud.nacos.config.server-addr", "http://175.6.40.67:10042"); + System.setProperty("--spring.cloud.nacos.username", "nacos"); + System.setProperty("--spring.cloud.nacos.password", "nacos"); + } + + + public static void main(String[] args) { BladeApplication.run(OperationalConstants.APP_NAME, OperationApplication.class, args); } From 171fa370ad1f4d51bd5c981ecd9debd764b4045a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E9=A3=9E=E5=AE=87?= <2684146481@qq.com> Date: Thu, 13 Apr 2023 12:57:51 +0800 Subject: [PATCH 4/7] =?UTF-8?q?message=20=E7=A7=BB=E9=99=A4lettuce-core=20?= =?UTF-8?q?jar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hzims-service/message/pom.xml | 32 ++++++++++++++++++++++ .../hzims/safeproduct/SafeproductApplication.java | 1 + 2 files changed, 33 insertions(+) diff --git a/hzims-service/message/pom.xml b/hzims-service/message/pom.xml index 45c05b2..7e4c91f 100644 --- a/hzims-service/message/pom.xml +++ b/hzims-service/message/pom.xml @@ -19,7 +19,39 @@ org.springblade blade-core-boot + + + org.springblade + blade-starter-redis + + + + + + org.springblade + blade-starter-redis + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + io.lettuce + lettuce-core + + + + + org.springblade blade-core-cloud diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/SafeproductApplication.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/SafeproductApplication.java index 168c095..fd3af8b 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/SafeproductApplication.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/SafeproductApplication.java @@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @ComponentScan(basePackages = {"com.hnac.*"}) public class SafeproductApplication { + public static void main(String[] args) { BladeApplication.run(Constants.APP_NAME, SafeproductApplication.class, args); } From 30b7bd603e2735acc341b614f5df287ab1d64ac3 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 14:34:59 +0800 Subject: [PATCH 5/7] =?UTF-8?q?#=E6=B3=B5=E7=AB=99=E3=80=81=E5=85=89?= =?UTF-8?q?=E4=BC=8F=E5=8F=91=E7=94=B5=E9=87=8F=E3=80=81=E7=94=A8=E7=94=B5?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alert/constants/AbnormalAlarmConstant.java | 7 +- .../hzims/operational/alert/vo/SoeParamVo.java | 29 + .../hzims/operational/alert/vo/SoeReustVo.java | 31 + .../operational/fill/entity/GenerateEntity.java | 2 +- .../hzims/operational/fill/entity/UseEntity.java | 2 +- .../hnac/hzims/operational/fill/vo/QueryVo.java | 8 + .../operational/main/vo/GenerationPowerVo.java | 4 + .../operational/main/vo/PhotovoltaicDeviceVo.java | 50 +- .../operational/main/vo/PhotovoltaicTargetVo.java | 1 + .../operational/station/StationConstants.java | 2 + .../alert/controller/AbnormalAlarmController.java | 16 +- .../alert/service/HistoryAbnormalAlarmService.java | 4 + .../impl/HistoryAbnormalAlarmServiceImpl.java | 62 +- .../operational/fill/mapper/GenerateMapper.java | 4 + .../operational/fill/mapper/GenerateMapper.xml | 8 + .../operational/fill/service/GenerateService.java | 6 + .../operational/fill/service/PowerService.java | 8 + .../hzims/operational/fill/service/UseService.java | 12 + .../fill/service/impl/GenerateServiceImpl.java | 40 ++ .../fill/service/impl/PowerServiceImpl.java | 59 ++ .../fill/service/impl/UseServiceImpl.java | 84 ++- .../main/controller/HydropowerController.java | 1 - .../main/controller/WebHomeController.java | 4 +- .../main/scheduled/ScheduledCreateTask.java | 14 +- .../main/service/HydropowerService.java | 22 + .../operational/main/service/IWaterService.java | 2 +- .../operational/main/service/IWebHomeService.java | 23 - .../main/service/impl/HomePageServiceImpl.java | 90 ++- .../main/service/impl/HydropowerServiceImpl.java | 743 ++++++++++++++++++++ .../main/service/impl/PhotovoltaicServiceImpl.java | 60 +- .../main/service/impl/WaterServiceImpl.java | 282 ++++---- .../main/service/impl/WebHomeServiceImpl.java | 744 --------------------- .../service/IOperMaintenanceTaskService.java | 8 +- .../station/service/impl/ImsDeptServiceImpl.java | 2 +- 34 files changed, 1452 insertions(+), 982 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeParamVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeReustVo.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWebHomeService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java index 6835eba..1bdcfb6 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java @@ -13,8 +13,13 @@ public interface AbnormalAlarmConstant { /**通讯恢复*/ String ABNORMAL_STATUS = "1"; - String TYPE_NAMES[] = {"默认", "系统", "告警", "故障", "用户操作", "遥测越限", "遥信变位", "注册信息", "信息提示", "设备巡检", "遥控操作", "遥测越限恢复","未定义","通讯中断","数据异常"}; + String[] TYPE_NAMES = {"默认", "系统", "告警", "故障", "用户操作", "遥测越限", "遥信变位", "注册信息", "信息提示", "设备巡检", "遥控操作", "遥测越限恢复","未定义","通讯中断","数据异常"}; /**处理、延后、误报*/ List HANDLE_WAY = Arrays.asList(1L,2L,3L,4L); + + /** + * 2-告警,3-故障,5-遥测越限,13-通讯异常,14-数据异常 + */ + List SOE_TYPE_LIST = Arrays.asList(2,3,5,13,14); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeParamVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeParamVo.java new file mode 100644 index 0000000..2f9d104 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeParamVo.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.operational.alert.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + * @date 2023/03/23 13:34:37 + * @version 4.0.0 + */ +@Data +public class SoeParamVo { + + @ApiModelProperty(value = "站点编码") + private String code; + + @ApiModelProperty(value = "查询开始时间:yyyy-MM-dd HH:mm:ss") + private String date; + + @ApiModelProperty(value = "2-告警,3-故障,5-遥测越限,13-通讯异常,14-数据异常") + private Integer type; + + @ApiModelProperty(value = "当前页码") + private Integer current; + + + @ApiModelProperty(value = "每页条目") + private Integer size; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeReustVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeReustVo.java new file mode 100644 index 0000000..379542d --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/SoeReustVo.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.operational.alert.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/23 13:34:37 + * @version 4.0.0 + */ +@Data +public class SoeReustVo { + + @ApiModelProperty(value = "最新的时间") + private String date; + + @ApiModelProperty(value = "告警数据") + private List soeList; + + @ApiModelProperty(value = "数量统计") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Integer count; + + @ApiModelProperty(value = "总条数") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long total; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java index 52c1bea..9e3c7f0 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/GenerateEntity.java @@ -26,7 +26,7 @@ public class GenerateEntity extends TenantEntity implements Serializable { private String dataOrigin; @ApiModelProperty("发电量") - private BigDecimal generate; + private Double generate; @ApiModelProperty("填报月份") private String fillDate; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java index 6ae9334..f097c8d 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java @@ -26,7 +26,7 @@ public class UseEntity extends TenantEntity implements Serializable { private String dataOrigin; @ApiModelProperty("发电量") - private BigDecimal use; + private Double employ; @ApiModelProperty("填报月份") private String fillDate; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java index 42cde47..01c68fc 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/vo/QueryVo.java @@ -5,6 +5,11 @@ import lombok.Data; import java.util.Date; +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ @Data public class QueryVo{ @@ -19,4 +24,7 @@ public class QueryVo{ @ApiModelProperty("设备编号") private String deviceCode; + + @ApiModelProperty("站点接入类型") + private String dataOrigin; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java index b744dba..854a5d5 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/GenerationPowerVo.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.main.vo; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -12,8 +14,10 @@ public class GenerationPowerVo { private String date; @ApiModelProperty(value = "发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float generate; @ApiModelProperty(value = "功率·") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float load; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java index b81247b..68bf536 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicDeviceVo.java @@ -198,101 +198,103 @@ public class PhotovoltaicDeviceVo { private Double dc_voltage_twelve; - @ApiModelProperty(value = "直流电流1") + @ApiModelProperty(value = "串流电流1") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_one; - @ApiModelProperty(value = "直流电流2") + @ApiModelProperty(value = "串流电流2") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_two; - @ApiModelProperty(value = "直流电流3") + @ApiModelProperty(value = "串流电流3") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_three; - @ApiModelProperty(value = "直流电流4") + @ApiModelProperty(value = "串流电流4") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_four; - @ApiModelProperty(value = "直流电流5") + @ApiModelProperty(value = "串流电流5") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_five; - @ApiModelProperty(value = "直流电流6") + @ApiModelProperty(value = "串流电流6") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_six; - @ApiModelProperty(value = "直流电流7") + @ApiModelProperty(value = "串流电流7") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_seven; - @ApiModelProperty(value = "直流电流8") + @ApiModelProperty(value = "串流电流8") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_eight; - @ApiModelProperty(value = "直流电流9") + @ApiModelProperty(value = "串流电流9") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_nine; - @ApiModelProperty(value = "直流电流10") + @ApiModelProperty(value = "串流电流10") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_ten; - @ApiModelProperty(value = "直流电流11") + @ApiModelProperty(value = "串流电流11") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_eleven; - @ApiModelProperty(value = "直流电流12") + @ApiModelProperty(value = "串流电流12") @JsonSerialize(nullsUsing = NullSerializer.class) private Double series_twelve; - @ApiModelProperty(value = "直流电压1") + + + @ApiModelProperty(value = "串流电压1") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_one; - @ApiModelProperty(value = "直流电压2") + @ApiModelProperty(value = "串流电压2") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_two; - @ApiModelProperty(value = "直流电压3") + @ApiModelProperty(value = "串流电压3") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_three; - @ApiModelProperty(value = "直流电压4") + @ApiModelProperty(value = "串流电压4") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_four; - @ApiModelProperty(value = "直流电压5") + @ApiModelProperty(value = "串流电压5") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_five; - @ApiModelProperty(value = "直流电压6") + @ApiModelProperty(value = "串流电压6") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_six; - @ApiModelProperty(value = "直流电压7") + @ApiModelProperty(value = "串流电压7") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_seven; - @ApiModelProperty(value = "直流电压8") + @ApiModelProperty(value = "串流电压8") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_eight; - @ApiModelProperty(value = "直流电压9") + @ApiModelProperty(value = "串流电压9") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_nine; - @ApiModelProperty(value = "直流电压10") + @ApiModelProperty(value = "串流电压10") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_ten; - @ApiModelProperty(value = "直流电压11") + @ApiModelProperty(value = "串流电压11") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_eleven; - @ApiModelProperty(value = "直流电压12") + @ApiModelProperty(value = "串流电压12") @JsonSerialize(nullsUsing = NullSerializer.class) private Double se_voltage_twelve; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicTargetVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicTargetVo.java index 3562934..557b706 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicTargetVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicTargetVo.java @@ -25,6 +25,7 @@ public class PhotovoltaicTargetVo { private String deviceName; @ApiModelProperty(value = "当日运行时长") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double runHours; @ApiModelProperty(value = "年发电量: kWh") diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/StationConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/StationConstants.java index 8f9da7f..48ad9d1 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/StationConstants.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/StationConstants.java @@ -20,6 +20,8 @@ public interface StationConstants { //自动添加或修改机构数据 String TASK_VALUE_IMS_DEPT_CREATE = "imsDeptCreate"; + String DATA_ORIGIN_FILL = "1"; + enum DeptCategoryEnum { STATION(4,"站点") ; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java index 5af23db..e5c525b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java @@ -7,6 +7,8 @@ import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; import com.hnac.hzims.operational.alert.vo.AlarmParamVo; import com.hnac.hzims.operational.alert.vo.AlarmReustVo; +import com.hnac.hzims.operational.alert.vo.SoeParamVo; +import com.hnac.hzims.operational.alert.vo.SoeReustVo; import com.hnac.hzims.operational.config.vo.*; import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; import io.swagger.annotations.Api; @@ -112,7 +114,7 @@ public class AbnormalAlarmController extends BladeController { * */ @ApiLog - @ApiOperation(value = "智能优化接口") + @ApiOperation(value = "原始告警接口") @ApiOperationSupport(order = 7) @RequestMapping(value = "/alarms", method = {RequestMethod.GET, RequestMethod.POST}) public R alarms(AlarmParamVo param){ @@ -120,6 +122,18 @@ public class AbnormalAlarmController extends BladeController { } /** + * + */ + @ApiLog + @ApiOperation(value = "等级告警接口") + @ApiOperationSupport(order = 7) + @RequestMapping(value = "/terrace_alarms", method = {RequestMethod.GET, RequestMethod.POST}) + public R terrace_alarms(SoeParamVo param){ + return R.data(service.terrace_alarms(param)); + } + + + /** * 智能告警数量: 时间范围当天 */ @ApiLog diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java index ac56340..94ec897 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.vo.AlarmParamVo; import com.hnac.hzims.operational.alert.vo.AlarmReustVo; +import com.hnac.hzims.operational.alert.vo.SoeParamVo; +import com.hnac.hzims.operational.alert.vo.SoeReustVo; import com.hnac.hzims.operational.config.vo.*; import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; import org.springblade.core.mp.base.BaseService; @@ -33,4 +35,6 @@ public interface HistoryAbnormalAlarmService extends BaseService alarmData(AlarmDataPageVo page,Query query); List queryStationName(); + + SoeReustVo terrace_alarms(SoeParamVo param); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 3c615b6..8d1cb2a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -4,17 +4,16 @@ 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.Wrappers; -import com.fasterxml.jackson.core.type.TypeReference; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; import com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper; import com.hnac.hzims.operational.alert.service.AlarmHandleService; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.alert.vo.AlarmDataVo; -import com.hnac.hzims.operational.alert.vo.AlarmParamVo; -import com.hnac.hzims.operational.alert.vo.AlarmReustVo; -import com.hnac.hzims.operational.config.vo.*; +import com.hnac.hzims.operational.alert.vo.*; +import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; +import com.hnac.hzims.operational.config.vo.AlarmVo; +import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; @@ -24,7 +23,9 @@ import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; -import com.hnac.hzinfo.sdk.core.utils.JsonUtil; +import com.hnac.hzinfo.sdk.v5.soe.SoeClient; +import com.hnac.hzinfo.sdk.v5.soe.dto.SoeDTO; +import com.hnac.hzinfo.sdk.v5.soe.vo.SoeVO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; @@ -60,6 +61,9 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl wrapper = Wrappers.lambdaQuery(); + if(StringUtils.isNotEmpty(param.getCode())){ + wrapper.eq(StationEntity::getCode,param.getCode()); + } + List stations = stationService.list(wrapper); + if(CollectionUtil.isEmpty(stations)){ + return new SoeReustVo(); + } + // 参数设置 + SoeDTO soe_params = new SoeDTO(); + //soe_params.setProjectId(); + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME) + " 00:00:00"; + soe_params.setBeginTime(DateUtil.parse(start,DateUtil.PATTERN_DATETIME)); + soe_params.setEndTime(DateUtil.parse(end,DateUtil.PATTERN_DATETIME)); + soe_params.setNeedPage(true); + soe_params.setPage(param.getCurrent()); + soe_params.setPageSize(param.getSize()); + if(ObjectUtil.isEmpty(param.getType())){ + soe_params.setTypes(AbnormalAlarmConstant.SOE_TYPE_LIST); + }else{ + soe_params.setTypes(Collections.singletonList(param.getType())); + } + // 查询等级告警数据 + Result> soes = soeClient.pageQuery(soe_params); + if(!soes.isSuccess() || ObjectUtil.isEmpty(soes.getData())){ + return new SoeReustVo(); + } + List handles = this.getAlarmHandleIds(); + + + return null; + } + + + /** * 获取处理数据ID集合 * @return */ @@ -372,7 +419,7 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl { + List records(@Param("date") String date,@Param("station") String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/mapper/GenerateMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/mapper/GenerateMapper.xml index d937e42..67d0642 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/mapper/GenerateMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/mapper/GenerateMapper.xml @@ -1,4 +1,12 @@ + + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java index 0bd1f45..8e7bcfe 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java @@ -6,10 +6,13 @@ import com.hnac.hzims.operational.fill.entity.RainfallEntity; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.vo.RainfallVo; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import java.util.List; + /** * @author ysj * @date 2023/04/10 11:16:07 @@ -22,4 +25,7 @@ public interface GenerateService extends BaseService { // 新增/修改发电量填报数据 boolean saveUpdate(GenerateEntity entity); + + // 获取站点填报发电量 + List generateThreeYear(String start, String end, String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/PowerService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/PowerService.java index b1aea53..6ff6d55 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/PowerService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/PowerService.java @@ -3,10 +3,14 @@ package com.hnac.hzims.operational.fill.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.fill.entity.PowerEntity; import com.hnac.hzims.operational.fill.vo.PowerVo; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import java.util.List; + /** * 其他填报接口 */ @@ -17,4 +21,8 @@ public interface PowerService extends BaseService { R upd(PowerEntity entity); R> pageCondition(PowerVo vo, Query query); + + Double generate(String date,Long station); + + List generateThreeYear(String start,String end,Long station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/UseService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/UseService.java index e25c60e..e80d319 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/UseService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/UseService.java @@ -4,10 +4,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.fill.entity.UseEntity; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.vo.UseVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import java.util.List; +import java.util.Map; + /** * @author ysj * @date 2023/04/10 11:16:07 @@ -20,4 +24,12 @@ public interface UseService extends BaseService { // 新增/修改用电量填报数据 boolean saveUpdate(UseEntity entity); + + // 查询填报用电量 + Float use(String date,String station); + + // 查询30天填报用电量 + List use30Day(String day, String station); + + Map generateThreeYear(String start, String end, String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 1d1e2ae..6ff4613 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -3,12 +3,14 @@ package com.hnac.hzims.operational.fill.service.impl; 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.Wrappers; import com.hnac.hzims.operational.fill.entity.GenerateEntity; import com.hnac.hzims.operational.fill.mapper.GenerateMapper; import com.hnac.hzims.operational.fill.service.GenerateService; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.wrapper.GenerateWrapper; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -16,11 +18,15 @@ import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * @author ysj @@ -50,6 +56,9 @@ public class GenerateServiceImpl extends BaseServiceImpl generateThreeYear(String start, String end, String station) { + List records = this.list(Wrappers.lambdaQuery() + .eq(GenerateEntity::getStationCode,station) + .between(GenerateEntity::getFillDate,start,end) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + // 返回结果 + return records.stream().peek( + record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01") + ).collect(Collectors.toMap(GenerateEntity::getFillDate,GenerateEntity::getGenerate,Double::sum)). + entrySet().stream().map(entry->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(entry.getKey()); + if(Math.abs(entry.getValue()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(entry.getValue().toString())); + } + return mon; + }).collect(Collectors.toList()); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/PowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/PowerServiceImpl.java index 091e690..eb6a697 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/PowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/PowerServiceImpl.java @@ -1,12 +1,16 @@ package com.hnac.hzims.operational.fill.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.operational.fill.entity.PowerEntity; import com.hnac.hzims.operational.fill.mapper.PowerMapper; import com.hnac.hzims.operational.fill.service.PowerService; import com.hnac.hzims.operational.fill.vo.PowerVo; import com.hnac.hzims.operational.fill.wrapper.PowerWrapper; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; @@ -14,12 +18,16 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.system.feign.ISysClient; import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Slf4j @@ -97,4 +105,55 @@ public class PowerServiceImpl extends BaseServiceImpl return R.data(pages.setRecords(list)); } + /** + * 根据时间、机构查询发电量 + * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 所属机构 + * @return + */ + @Override + public Double generate(String date, Long station) { + List powers = this.list(Wrappers.lambdaQuery() + .likeRight(PowerEntity::getMon,date) + .eq(PowerEntity::getCreateDept,station) + // 类型: 光伏 + .eq(PowerEntity::getType,1) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0.0; + } + return powers.stream().mapToDouble(PowerEntity::getPowerMon).sum(); + } + + /** + * + * @param start 开始时间 : yyyy-mm + * @param end 结束时间 : yyyy-mm + * @param station 所属机构 + * @return + */ + @Override + public List generateThreeYear(String start, String end, Long station) { + List fills = this.list(Wrappers.lambdaQuery() + .between(PowerEntity::getMon,start,end) + .eq(PowerEntity::getCreateDept,station) + // 类型: 光伏 + .eq(PowerEntity::getType,1) + ); + if(CollectionUtil.isEmpty(fills)){ + return new ArrayList<>(); + + } + return fills.stream().map(fill->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(DateUtil.format(DateUtil.parse(fill.getMon(),"yyyy-MM"),DateUtil.PATTERN_DATE)); + if(Math.abs(fill.getPowerMon()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(fill.getPowerMon().toString())); + } + return mon; + }).collect(Collectors.toList()); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/UseServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/UseServiceImpl.java index 5093822..4488e91 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/UseServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/UseServiceImpl.java @@ -3,12 +3,17 @@ package com.hnac.hzims.operational.fill.service.impl; 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.Wrappers; +import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.fill.entity.PowerEntity; import com.hnac.hzims.operational.fill.entity.UseEntity; import com.hnac.hzims.operational.fill.mapper.UseMapper; import com.hnac.hzims.operational.fill.service.UseService; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.vo.UseVo; import com.hnac.hzims.operational.fill.wrapper.UseWrapper; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -16,11 +21,14 @@ import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * @author ysj @@ -50,6 +58,9 @@ public class UseServiceImpl extends BaseServiceImpl implem if(!ObjectUtil.isEmpty(filter.getEndTime())){ le("FILL_DATE",filter.getEndTime()); } + if(!ObjectUtil.isEmpty(filter.getDataOrigin())){ + eq("DATA_ORIGIN",filter.getDataOrigin()); + } orderByDesc("create_time"); }}; IPage pages = super.page(Condition.getPage(query), queryWrapper); @@ -78,4 +89,75 @@ public class UseServiceImpl extends BaseServiceImpl implem return this.updateById(entity); } + /** + * 根据时间、机构查询用电量 + * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 所属机构 + * @return + */ + @Override + public Float use(String date, String station) { + List powers = this.list(Wrappers.lambdaQuery() + .likeRight(UseEntity::getFillDate,date) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0f; + } + return (float) powers.stream().mapToDouble(UseEntity::getEmploy).sum(); + } + + /** + * 查询30天填报用电量 + * @param day : 结束日期 yyyy-MM-dd + * @param station 站点编码 + * @return + */ + @Override + public List use30Day(String day, String station) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = this.list(Wrappers.lambdaQuery() + .between(UseEntity::getFillDate,start,end) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record->{ + UsrPowerVo use = new UsrPowerVo(); + use.setDate(record.getFillDate()); + if(Math.abs(record.getEmploy()) <= 0){ + use.setUsrPower(0f); + }else{ + use.setUsrPower(Float.parseFloat(record.getEmploy().toString())); + } + return use; + }).collect(Collectors.toList()); + } + + /** + * 查询近3年的填报用电量 + * @param start + * @param end + * @param station + * @return + */ + @Override + public Map generateThreeYear(String start, String end, String station) { + List records = this.list(Wrappers.lambdaQuery() + .between(UseEntity::getFillDate,start,end) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new HashMap<>(); + + } + return records.stream().peek(record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")). + collect(Collectors.toMap(UseEntity::getFillDate, value->Float.parseFloat(value.getEmploy().toString()),Float::sum)); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HydropowerController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HydropowerController.java index d542570..666b45c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HydropowerController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/HydropowerController.java @@ -88,7 +88,6 @@ public class HydropowerController extends BladeController { - @ApiLog @ApiOperation("计划发电趋势") @GetMapping("/planGenerationTrend") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java index db9ee80..c7a5096 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java @@ -1,7 +1,7 @@ package com.hnac.hzims.operational.main.controller; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.operational.main.service.IWebHomeService; +import com.hnac.hzims.operational.main.service.HydropowerService; import com.hnac.hzims.operational.main.vo.HydropowerStationVo; import com.hnac.hzims.operational.main.vo.HydropowerUnitVo; import io.swagger.annotations.Api; @@ -23,7 +23,7 @@ import java.util.List; @AllArgsConstructor public class WebHomeController extends BladeController { - private final IWebHomeService service; + private final HydropowerService service; @ApiLog @ApiOperation("水电站站点统计") @GetMapping("/webStation") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java index b681a2f..08e591d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java @@ -13,7 +13,6 @@ import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -44,7 +43,7 @@ public class ScheduledCreateTask { @Autowired private IAreaMonthReportService reportService; @Autowired - private IWebHomeService webHomeService; + private HydropowerService hydropowerService; @Autowired private PhotovoltaicService photovoltaicService; @Autowired @@ -169,10 +168,9 @@ public class ScheduledCreateTask { * 获取站点近3年发电量数据 * @return ReturnT */ - //@XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) - @Scheduled(cron = "0/40 * * * * ? ") - public ReturnT powerGenerationRecentYear() throws Exception { - String param = ""; + @XxlJob(ELECTRICITY_GENERATION_RECENT_YEAR) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT powerGenerationRecentYear(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } @@ -274,7 +272,7 @@ public class ScheduledCreateTask { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - webHomeService.loadHydropowerReal(param); + hydropowerService.loadHydropowerReal(param); return new ReturnT<>("SUCCESS"); } @@ -288,7 +286,7 @@ public class ScheduledCreateTask { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - webHomeService.loadHydropowerTarget(param); + hydropowerService.loadHydropowerTarget(param); return new ReturnT<>("SUCCESS"); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java new file mode 100644 index 0000000..b7a0576 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.operational.main.service; + +import com.hnac.hzims.operational.main.vo.HydropowerStationVo; +import com.hnac.hzims.operational.main.vo.HydropowerUnitVo; + +import java.util.List; + +/** + * WEB水电站首页接口 + */ +public interface HydropowerService { + + void loadHydropowerReal(String param); + + void loadHydropowerTarget(String param); + + HydropowerStationVo webStation(Long deptId); + + List hydropowerDevice(Long deptId); + + List webStationList(Long deptId); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWaterService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWaterService.java index 6de994a..c0ff232 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWaterService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWaterService.java @@ -27,7 +27,7 @@ public interface IWaterService { List waterYearRain(Long deptId); - Dept getTitleDetp(List authList, Long deptId); + Dept getTitleDetp(Long deptId); WaterStationVo waterStationPage(Long deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWebHomeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWebHomeService.java deleted file mode 100644 index c09cf15..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IWebHomeService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.hnac.hzims.operational.main.service; - -import com.hnac.hzims.operational.main.vo.HydropowerStationVo; -import com.hnac.hzims.operational.main.vo.HydropowerUnitVo; -import com.hnac.hzims.operational.main.vo.WaterStationVo; - -import java.util.List; - -/** - * WEB水电站首页接口 - */ -public interface IWebHomeService { - - void loadHydropowerReal(String param); - - void loadHydropowerTarget(String param); - - HydropowerStationVo webStation(Long deptId); - - List hydropowerDevice(Long deptId); - - List webStationList(Long deptId); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java index a2b0b17..7d82b1b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java @@ -65,22 +65,40 @@ import java.util.stream.Collectors; @Slf4j public class HomePageServiceImpl implements IHomePageService { - private final IAnalyseDataService analyseDataService; - private final IPlanGenertionClient planGenertionClient; - private final IMainSystemMonitoringService maintenanceTaskService; - private final IMainTaskStatisticService mainTaskStatisticService; private final IStationService stationService; + private final PowerService powerService; + private final OverService overService; - private final OverDetailsService overDetailsService; + private final SolveService solveService; + private final OtherService otherService; + + private final OverDetailsService overDetailsService; + + private final IAnalyseDataService analyseDataService; + + private final PowerService photovoltaicService; + + private final GenerateService hydropowerService; + + private final IMainSystemMonitoringService maintenanceTaskService; + + private final IMainTaskStatisticService mainTaskStatisticService; + private final ISysClient sysClient; + private final ISoeClient soeClient; + + private final IPlanGenertionClient planGenertionClient; + private final ITicketInfoAllClient ticketInfoAllClient; - private final RedisTemplate redisTemplate; + private final IAnalyseInstanceClient analyseInstanceClient; + private final RedisTemplate redisTemplate; + private final static String KEY_INDICATORS_INFO = "hzims:operation:key:indicators:info"; private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; @@ -154,6 +172,8 @@ public class HomePageServiceImpl implements IHomePageService { // 充电桩 case 7: break; + default: + break; } }); redisTemplate.opsForValue().set(KEY_INDICATORS_INFO, keyIndicatorsVo); @@ -237,10 +257,7 @@ public class HomePageServiceImpl implements IHomePageService { stationList.forEach(station -> { // 站点设备集合 List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(stationDevices)){ - return; - } - Map generateMap = this.getGenerateYear(stationDevices,start,end); + Map generateMap = this.getGenerateYear(station,stationDevices,start,end); if(MapUtils.isEmpty(generateMap)){ return; } @@ -256,26 +273,47 @@ public class HomePageServiceImpl implements IHomePageService { * @param end * @return */ - private Map getGenerateYear(List devices, String start, String end) { + private Map getGenerateYear(StationEntity station,List devices, String start, String end) { List datas = new ArrayList<>(); - devices.forEach(device->{ - List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return; - } - datas.addAll(records.stream().map(record -> { - PowerMonthVo generate = new PowerMonthVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toList())); - }); + // 设备采集发电量 + if(CollectionUtil.isNotEmpty(devices)){ + devices.forEach(device->{ + List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + datas.addAll(records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toList())); + }); + } + // 补充填报数据 + datas.addAll(this.generateFill(station,start,end)); if(CollectionUtil.isEmpty(datas)){ return null; } - return datas.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth, Collectors.collectingAndThen( - Collectors.mapping(PowerMonthVo::getPower, Collectors.reducing(Float::sum)),Optional::get))); + return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); + } + + /** + * 补充填报数据 + * @param station + * @param start + * @param end + */ + private List generateFill(StationEntity station, String start, String end) { + start = DateUtil.format(DateUtil.parse(start,DateUtil.PATTERN_DATETIME),"yyyy-MM"); + end = DateUtil.format(DateUtil.parse(end,DateUtil.PATTERN_DATETIME),"yyyy-MM"); + // 光伏 + if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){ + return photovoltaicService.generateThreeYear(start,end,station.getRefDept()); + // 水电 + } + return hydropowerService.generateThreeYear(start,end,station.getCode()); } /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java new file mode 100644 index 0000000..8393825 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -0,0 +1,743 @@ +package com.hnac.hzims.operational.main.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.equipment.feign.IPlanGenertionClient; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.equipment.vo.PlanPowerYearVo; +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; +import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; +import com.hnac.hzims.operational.main.service.*; +import com.hnac.hzims.operational.main.vo.*; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.service.IStationAttributeService; +import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.soe.ISoeClient; +import com.hnac.hzinfo.datasearch.soe.domian.SoeData; +import lombok.RequiredArgsConstructor; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +/** + * APP首页实现类 + */ +@Service +@RequiredArgsConstructor +public class HydropowerServiceImpl implements HydropowerService { + + private final IAnalyseDataService analyseDataService; + + private final IHomePageService homePageService; + + private final IMainSystemMonitoringService maintenanceTaskService; + + private final IStationService stationService; + + private final IStationAttributeService attributeService; + + private final IWaterService waterService; + + private final IPlanGenertionClient planGenertionClient; + + private final ISoeClient soeClient; + + private final IWeatherService weatherService; + + private final RedisTemplate redisTemplate; + + @Value("${hzims.operation.realIdKey}") + public String real_id_key; + + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; + private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; + private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; + + + /** + * 加载水电站机组实时数据 + * @param param + */ + @Override + public void loadHydropowerReal(String param) { + // 有效设备 + List valid = this.getValidDeviceList(); + if(CollectionUtil.isEmpty(valid)){ + return; + } + // 实时数据 + Map map = this.getRealMap(); + // 单位 + Map unitMap = this.attributeService.getPointUnit(); + List list = new ArrayList<>(); + valid.forEach(device->{ + HydropowerUnitRealVo realVo = new HydropowerUnitRealVo(); + realVo.setDeptId(device.getCreateDept()); + realVo.setDeviceCode(device.getEmCode()); + realVo.setDeptName(device.getName()); + realVo.setDeviceName(device.getName()); + // 开关机状态 + String state = this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY); + realVo.setState(state); + // 有功功率 + String activePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER); + realVo.setActivePower(activePower); + // 无功功率 + String reactivePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER); + realVo.setReactivePower(reactivePower); + // 功率因数 + String powerFactor = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR); + realVo.setPowerFactor(powerFactor); + // 机组频率 + String frequency = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY); + realVo.setFrequency(frequency); + // 导叶开度 + String guideOpen = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN); + realVo.setGuideOpen(guideOpen); + // 定子电压 + String statorVoltage = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE); + realVo.setStatorVoltage(statorVoltage); + // 定子电流 + String statorCurrent = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT); + realVo.setStatorCurrent(statorCurrent); + // 单位设置 + this.setttingUnit(device,unitMap,realVo); + list.add(realVo); + }); + redisTemplate.opsForValue().set(load_hydropower_unit_real_key,list); + } + + /** + * 获取实时数据 + * @return + */ + private Map getRealMap() { + String json = (String) redisTemplate.opsForValue().get(real_id_key); + if(StringUtil.isBlank(json)){ + return null; + } + return JSONObject.parseObject(json, new TypeReference>() {}); + } + + /** + * 加载水电站机组指标数据 + * @param param + */ + @Override + public void loadHydropowerTarget(String param) { + // 有效设备 + List valid = this.getValidDeviceList(); + if(CollectionUtil.isEmpty(valid)){ + return; + } + List list = new ArrayList<>(); + valid.forEach(device->{ + HydropowerUnitTargetVo targetVo = new HydropowerUnitTargetVo(); + targetVo.setDeptId(device.getCreateDept()); + targetVo.setDeviceCode(device.getEmCode()); + targetVo.setDeviceName(device.getName()); + targetVo.setDeptName(device.getName()); + // 当年发电量 + float powerYear = this.getGenerationPower(device,0); + targetVo.setPowerYear(powerYear); + // 当月发电量 + float powerMon = this.getGenerationPower(device,1); + targetVo.setPowerMon(powerMon); + // 当日发电量 + float powerDay = this.getGenerationPower(device,2); + // 当天有功功率 + List activePowerVoList = waterService.getActivePowerVoList(device); + targetVo.setActivePowerVoList(activePowerVoList); + // 30天发电量 + List generationPowerVoList = this.getGenerationPowerList(device); + targetVo.setGenerationPowerVoList(generationPowerVoList); + targetVo.setPowerDay(powerDay); + list.add(targetVo); + }); + redisTemplate.opsForValue().set(load_hydropower_unit_target_key,list); + } + + /** + * 获取有效设备 + * @return + */ + private List getValidDeviceList() { + // 水利站点(All) + List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), null); + if(CollectionUtil.isEmpty(stationList)){ + return null; + } + // 获取所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + if(CollectionUtil.isEmpty(deviceList)){ + return null; + } + // 有效泵租设备 + List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(deptIdList)){ + return null; + } + return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); + } + + + /** + * 获取监测点实时数据 + * @param em + * @param targets + * @return + */ + private String getSignageValue(EminfoAndEmParamVo em,Map map, String targets) { + if(ObjectUtil.isEmpty(em) || MapUtils.isEmpty(map)){ + return "0"; + } + Map point = em.getPoint(); + if(MapUtils.isEmpty(point)){ + return "0"; + } + String realId = point.get(targets); + if(StringUtil.isBlank(realId)){ + return "0"; + } + String value = map.get(realId); + if(StringUtil.isBlank(value)){ + return "0"; + } + // 获取value + return value; + } + + /** + * 单位设置 + * @param device + * @param unitMap + * @param realVo + */ + private void setttingUnit(EminfoAndEmParamVo device, Map unitMap, HydropowerUnitRealVo realVo) { + if(MapUtils.isEmpty(unitMap)){ + return; + } + // 有功功率单位 + String power = unitMap.get(device.getId()+HomePageConstant.CONCAT_P); + if(StringUtil.isNotBlank(power)){ + realVo.setPowerUnit(power); + } else { + realVo.setPowerUnit("kW"); + } + // 无功功率 + String reactivePowerUnit = unitMap.get(device.getId()+HomePageConstant.CONCAT_Q); + if(StringUtil.isNotBlank(reactivePowerUnit)){ + realVo.setReactivePowerUnit(reactivePowerUnit); + } else { + realVo.setReactivePowerUnit("kVa r"); + } + // 定子电压单位 + String voltage = unitMap.get(device.getId()+HomePageConstant.CONCAT_UAB); + if(StringUtil.isNotBlank(voltage)){ + realVo.setVoltageUnit(voltage); + } else { + realVo.setVoltageUnit("V"); + } + // 定子电流单位 + String current = unitMap.get(device.getId()+HomePageConstant.CONCAT_IA); + if(StringUtil.isNotBlank(current)){ + realVo.setCurrentUnit(current); + } else { + realVo.setCurrentUnit("A"); + } + } + + /** + * 获取年、月、日发电量 + * @param device + * @param scope + * @return + */ + private float getGenerationPower(EminfoAndEmParamVo device,int scope) { + String start,end; + int accessRules; + Calendar calendar = Calendar.getInstance(); + switch (scope){ + // 年 + case 0: + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + accessRules = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); + break; + // 月 + case 1: + start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + accessRules = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); + break; + // 日 + case 2: + String time = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + start = time + " 00:00:00"; + end = time + " 23:59:59"; + accessRules = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); + break; + default: + throw new IllegalStateException("Unexpected value: " + scope); + } + return analyseDataService.periodTargetFloat(start,end,accessRules,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + } + + /** + * 近30天发电量 + * @param device + * @return + */ + private List getGenerationPowerList(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = analyseDataService.periodTargetData(start,end,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return generate; + }).collect(Collectors.toList()); + } + + /** + * 水电站-站点信息 + * @param deptId + * @return + */ + @Override + public HydropowerStationVo webStation(Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return null; + } + // 站点 + StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); + if(ObjectUtil.isEmpty(station)){ + return null; + } + List list = this.getHydropowerStationList(Collections.singletonList(station)); + if(CollectionUtil.isEmpty(list)){ + return null; + } + return list.get(0); + } + + /** + * 获取首页站点信息 + * @param list + * @return + */ + private List getHydropowerStationList(List list) { + if(CollectionUtil.isEmpty(list)){ + return null; + } + // 实时监测点数据 + List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); + // 获取站点机组指标数据 + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + // 实时天气 + Map weather = this.getWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); + // 七天天气 + Map weekWeather = this.getWeekWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); + List result = new ArrayList<>(); + list.forEach(station ->{ + HydropowerStationVo response = new HydropowerStationVo(); + response.setDeptId(station.getRefDept()); + response.setDeptName(station.getName()); + response.setStationCode(station.getCode()); + // 站点状态 + List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); + if (CollectionUtil.isNotEmpty(soeDataList)) { + response.setStationStatus(false); + } else { + response.setStationStatus(true); + } + // 站点实时天气 + String temp = this.getTemp(weather,station.getCode()); + response.setTemp(temp); + // 站点七天天气 + List dailys = this.getDailyList(weekWeather,station.getCode()); + response.setWeather(dailys); + // 限制水位 + response.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + int runDay = this.getRunDay(station); + response.setRunDay(runDay); + // 装机容量 + double installedCapacity = this.getInstalledCapacity(deviceList,station.getRefDept()); + response.setInstalledCapacity(installedCapacity); + // 总有功功率(总发电负荷) + double powerSum = this.getPowerSum(realList,station.getRefDept()); + response.setPowerSum(powerSum); + // 总有功单位 + String unit = this.getPowerUnit(realList,station.getRefDept()); + response.setPowerUnit(unit); + // 月计划发电量 + float planPowerMon = this.getPlanPowerrMon(station.getCode()); + response.setPlanPowerMon(planPowerMon); + // 年计划发电量 + float planPowerYear = this.getPlanPowerYear(station.getCode()); + response.setPlanPowerYear(planPowerYear); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),response); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),response); + // 年发电量完成百分比 + List powerYearList = this.handlePowerFinish(station); + response.setPowerYearMap(powerYearList); + // 设备信息 + List devices = this.getDevices(station,realList,targetList); + response.setDeviceList(devices); + result.add(response); + }); + return result; + } + + /** + * 获取站点设备信息 + * @param station + * @return + */ + private List getDevices(StationEntity station,List realList,List targetList) { + if(CollectionUtil.isEmpty(realList) || CollectionUtil.isEmpty(targetList)){ + return null; + } + // 有效站点机组数据 + List validRealList = realList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList()); + // 有效站点机组指标数据 + List validTargetList = targetList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList()); + List list = new ArrayList<>(); + for(HydropowerUnitRealVo real : validRealList){ + HydropowerUnitVo hydropowerUnitVo = new HydropowerUnitVo(); + // 设备编号 + hydropowerUnitVo.setDeivceCode(real.getDeviceCode()); + hydropowerUnitVo.setDeivceName(real.getDeviceName()); + // 实时数据 + hydropowerUnitVo.setHydropowerPumpRealVo(real); + // 指标数据 + if(CollectionUtil.isNotEmpty(validTargetList)){ + List target = targetList.stream().filter(o->real.getDeviceCode().equals(o.getDeviceCode())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(target)){ + hydropowerUnitVo.setHydropowerPumpTargetVo(target.get(0)); + } + } + list.add(hydropowerUnitVo); + } + return list.stream().sorted(Comparator.comparing(HydropowerUnitVo::getDeivceCode)).collect(Collectors.toList()); + } + + /** + * 获取实时温度 + * @param weather + * @param code + * @return + */ + private String getTemp(Map weather, String code) { + if(MapUtils.isEmpty(weather)){ + return "21"; + } + HeWeatherWeatherNowResponse now = weather.get(code); + if(ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())){ + return "21"; + } + return now.getNow().getTemp(); + } + + /** + * 获取七天天气 + * @param weekWeather + * @param code + * @return + */ + private List getDailyList(Map weekWeather, String code) { + if(MapUtils.isEmpty(weekWeather)){ + return null; + } + HeWeatherWeatherDailyResponse week = weekWeather.get(code); + if(ObjectUtil.isEmpty(week)){ + return null; + } + return week.getDaily(); + } + + /** + * 获取站点实时天气 + * @param codes + */ + private Map getWeather(List codes) { + if(CollectionUtil.isEmpty(codes)){ + return null; + } + // 实时天气 + return this.weatherService.getNowWeather(codes); + } + + /** + * 获取七天天气 + * @param codes + */ + private Map getWeekWeather(List codes) { + if(CollectionUtil.isEmpty(codes)){ + return null; + } + // 实时天气 + return this.weatherService.getWeekWeather(codes); + } + + /** + * 获取设备装机容量 + * @param list + * @param refDept + * @return + */ + private double getInstalledCapacity(List list, Long refDept) { + if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(refDept)){ + return 0.0; + } + return list.stream().filter(o -> refDept.equals(o.getCreateDept())).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); + } + + /** + * 获取站点运行天数 + * @param station + * @return + */ + private int getRunDay(StationEntity station) { + if (ObjectUtil.isEmpty(station.getCommissionTime())) { + return 0; + } + // 计算投运时间与当前时间相隔天数 + Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); + return (int) dur.toDays(); + } + + /** + * 获取总发电负荷 + * @param deptId + * @return + */ + private Double getPowerSum(List realList,Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return 0.0; + } + // 获取站点机组实时数据 + if(CollectionUtil.isEmpty(realList)){ + return 0.0; + } + return realList.stream().filter(o->deptId.equals(o.getDeptId())).mapToDouble(o->Double.parseDouble(o.getActivePower())).sum(); + } + + /** + * 获取总发电负荷单位 + * @param realList + * @param deptId + * @return + */ + private String getPowerUnit(List realList, Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return "kW"; + } + // 获取站点机组实时数据 + if(CollectionUtil.isEmpty(realList)){ + return "kW"; + } + List unit = realList.stream().filter(o->deptId.equals(o.getDeptId()) && StringUtil.isNotBlank(o.getPowerUnit())).map(HydropowerUnitRealVo::getPowerUnit).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(unit)){ + return "kW"; + } + return unit.get(0); + } + + /** + * 获取月计划发电量 + * @param code + * @return + */ + private float getPlanPowerrMon(String code) { + R R = planGenertionClient.planGenerationMonthCount(code, DateUtil.format(new Date(), "yyyy-MM")); + if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + return 0f; + } + return R.getData(); + } + + /** + * 获取年计划发电量 + * @param code + * @return + */ + private float getPlanPowerYear(String code) { + R R = planGenertionClient.planGenerationYearCount(code); + if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + return 0f; + } + // 查询年计划发电量 + return R.getData(); + } + + /** + * 站点信息处理 + * @param deptId + * @param response + */ + private void handleStationInfo(Long deptId, HydropowerStationVo response) { + response.setPowerMon(0f); + response.setPowerYear(0f); + response.setPowerRateYear(0.0); + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + if(CollectionUtil.isEmpty(targetList)){ + return; + } + // 月发电量 + float powerMont = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); + response.setPowerMon(powerMont); + // 年发电量 + float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); + response.setPowerYear(powerYear); + // 年发电完成率 + float planPowerYear = response.getPlanPowerYear(); + if(Math.abs(planPowerYear) <= 0){ + response.setPowerRateYear(0.0); + } else { + double powerRateYear = BigDecimal.valueOf(powerYear / planPowerYear * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + response.setPowerRateYear(powerRateYear); + } + } + + /** + * 站点水位数据处理 + * @param code + * @param response + */ + private void handleWaterLeve(String code, HydropowerStationVo response) { + response.setFrontWaterLevel(0.0); + List levelList = (List) redisTemplate.opsForValue().get(loadwater_level_key); + if(CollectionUtil.isEmpty(levelList)){ + return; + } + List validList = levelList.stream().filter(o-> code.equals(o.getStationCode())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(validList)){ + return; + } + WaterLevelVo level = validList.get(0); + // 前池水位、当日水位曲线 + response.setFrontWaterLevel(level.getFrontWaterLevel()); + response.setFrontCurveMap(level.getFrontCurveMap()); + } + + /** + * 年发电量完成百分比 + * @param station + */ + private List handlePowerFinish(StationEntity station) { + String code = station.getCode(); + if(StringUtil.isBlank(code)){ + return null; + } + // 实际发电量 + Map> powerMap = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); + // 查询计划发电量 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + List planPowerList = planGenertionClient.getPlanPowerByYear(code,calendar.get(Calendar.YEAR)); + // 获取月份集合 + List monList = homePageService.getMonthList(0,12,false); + return monList.stream().map(o->{ + PowerMonthVo vo = new PowerMonthVo(); + LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), o), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + vo.setStrMonth(o); + vo.setYear(localDate.getYear()); + vo.setMonth(localDate.getMonthValue()); + // 实际发电量 + if(CollectionUtil.isEmpty(powerMap)){ + vo.setPower(0f); + }else{ + Map map = powerMap.get(station.getId()); + if(MapUtils.isEmpty(map)){ + vo.setPower(0f); + }else{ + vo.setPower(map.get(o)); + } + } + // 计划发电量 + if(CollectionUtil.isEmpty(planPowerList)){ + vo.setPlanPower(0f); + }else{ + String mon = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); + List list = planPowerList.stream().filter(s->mon.equals(s.getMon())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(list)){ + vo.setPlanPower(0f); + }else{ + vo.setPlanPower(list.get(0).getPlanPower()); + } + } + return vo; + }).collect(Collectors.toList()); + } + + /** + * 水电站-机组列表 + * @param deptId + * @return + */ + @Override + public List hydropowerDevice(Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return null; + } + // 查询站点 + StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); + if(ObjectUtil.isEmpty(station)){ + return null; + } + // 实时监测点数据 + List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); + // 获取站点机组指标数据 + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + return this.getDevices(station,realList,targetList); + } + + /** + * 水电站站点列表 + * @param deptId + * @return + */ + @Override + public List webStationList(Long deptId) { + List list = stationService.getStationType(null,Collections.singletonList(HomePageConstant.HYDROPOWER),null); + if(CollectionUtil.isEmpty(list)){ + return null; + } + return this.getHydropowerStationList(list); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index 1f30818..dcead7c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -7,6 +7,7 @@ import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; +import com.hnac.hzims.operational.fill.service.PowerService; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; @@ -68,10 +69,12 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { private final IAnalyseDataService analyseDataService; - private final IHistoryDataSearchClient historySearchClient; - private final IMainTaskStatisticService taskService; + private final PowerService generateService; + + private final IHistoryDataSearchClient historySearchClient; + private final ISysClient sysClient; private final ITicketInfoClient ticketInfoClient; @@ -243,6 +246,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { return; } List list = new ArrayList<>(); + // 接入站点设备统计 devices.forEach(device -> { PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); target.setDeptId(device.getCreateDept()); @@ -273,9 +277,18 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setGenerationPowerVoList(this.getGenerateByMon(device)); list.add(target); }); + // 补充站点填报发电量 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getType, HomePageConstant.PHOTOVOLTAIC) + .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) + ); + if(CollectionUtil.isNotEmpty(stations)){ + list.addAll(this.generateFill(stations)); + } redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); } + /** * 当天有功功率 * @@ -325,6 +338,45 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); } + /** + * 获取光伏站点填报数据 + * @param stations + * @return + */ + private List generateFill(List stations) { + Calendar calendar = Calendar.getInstance(); + //String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + //calendar.add(Calendar.DAY_OF_MONTH,-1); + //String yesterday = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + return stations.stream().map(station ->{ + PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); + // 当日运行时长 + target.setRunHours(0.0); + // 日发电量 + target.setGenerationDay(0.0); + // 昨日发电量 + target.setGenerationYesterday(0.0); + // 收益 + target.setIncome(0.0); + // 日发电量 + // 月发电量 + target.setGenerationMon(generateService.generate(mon,station.getRefDept())); + // 节约标准煤 + target.setTec(target.getGenerationMon() * 0.0001229); + // 二氧化碳减排 + target.setCo2(target.getGenerationMon() * 0.000997); + // 减少森林砍伐 + target.setDeforest(target.getGenerationMon() * 0.000553); + // 年发电量 + target.setGenerationYear(generateService.generate(year,station.getRefDept())); + // 30天发电量 + return target; + }).collect(Collectors.toList()); + } /** * 根据事件查询数据值 @@ -1462,7 +1514,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } // 功率 photovoltaic.setActivePowerVoList( - devices.stream().map(PhotovoltaicDeviceVo::getActivePowerVoList).flatMap(Collection::stream).collect(Collectors.groupingBy(PhotovoltaicPowerVo::getHour)).entrySet().stream().map(entry -> { + devices.stream().map(PhotovoltaicDeviceVo::getActivePowerVoList).filter(ObjectUtil::isNotEmpty).flatMap(Collection::stream).collect(Collectors.groupingBy(PhotovoltaicPowerVo::getHour)).entrySet().stream().map(entry -> { PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); load.setHour(entry.getKey()); load.setActivePower(String.valueOf(entry.getValue().stream().mapToDouble(o -> Double.parseDouble(o.getActivePower())).sum())); @@ -1471,7 +1523,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { ); // 发电量 photovoltaic.setGenerationPowerVoList( - devices.stream().map(PhotovoltaicDeviceVo::getGenerationPowerVoList).flatMap(Collection::stream).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { + devices.stream().map(PhotovoltaicDeviceVo::getGenerationPowerVoList).filter(ObjectUtil::isNotEmpty).flatMap(Collection::stream).collect(Collectors.groupingBy(GenerationPowerVo::getDate)).entrySet().stream().map(entry -> { GenerationPowerVo generate = new GenerationPowerVo(); generate.setDate(entry.getKey()); generate.setGenerate((float) entry.getValue().stream().mapToDouble(o -> Double.valueOf(o.getGenerate())).sum()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java index 878208d..a27d3fa 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java @@ -3,15 +3,18 @@ package com.hnac.hzims.operational.main.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo; +import com.hnac.hzims.operational.fill.service.UseService; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.station.StationConstants; import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IHzimsAnalyzeModelStationService; @@ -44,8 +47,6 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; @@ -60,26 +61,28 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class WaterServiceImpl implements IWaterService { - private final IAnalyseDataService analyseDataService; + private final UseService useService; private final IHomePageService homePageService; private final IStationService stationService; + private final IWeatherService weatherService; + + private final IAnalyseDataService analyseDataService; + private final ISideHustleService sideHustleService; private final IMainSystemMonitoringService maintenanceTaskService; private final IHzimsAnalyzeModelStationService modelStationService; - private final IAnalyseDataSearchClient analyseDataSearchClient; + private final ISysClient sysClient; - private final IWeatherService weatherService; + private final IAnalyseDataSearchClient analyseDataSearchClient; private final IHistoryDataSearchClient historyDataSearchClient; - private final ISysClient sysClient; - private final RedisTemplate redisTemplate; @Value("${hzims.operation.realIdKey}") @@ -91,13 +94,6 @@ public class WaterServiceImpl implements IWaterService { private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - // 日期格式化yyyy-mm-dd - private final SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); - // 日期格式化yyyy-mm-dd - private final SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); - // 时间格式化yyyy-MM-dd HH:mm:ss" - private final DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - /** * 水利-泵组实时加载 * @param param @@ -149,43 +145,50 @@ public class WaterServiceImpl implements IWaterService { @Override public void loadWaterPumpTarget(String param) { List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ - return; - } List list = new ArrayList<>(); - valid.forEach(device->{ - WaterPumpTargetVo waterPumpTargetVo = new WaterPumpTargetVo(); - waterPumpTargetVo.setDeptId(device.getCreateDept()); - waterPumpTargetVo.setDeviceCode(device.getEmCode()); - waterPumpTargetVo.setDeptName(device.getName()); - // 当年用电量 - float usrPowerYear = this.getUsrPowerYear(device); - waterPumpTargetVo.setUsrPowerYear(usrPowerYear); - // 当月用电量 - float usrPowerMon = this.getUsrPowerMon(device); - waterPumpTargetVo.setUsrPowerMon(usrPowerMon); - // 当日用电量 - float usrPowerDay = this.getUsrPowerDay(device); - waterPumpTargetVo.setUsrPowerDay(usrPowerDay); - // 月运行次数、时长 - WaterRunVo runMon = this.getRunData(device,1); - waterPumpTargetVo.setRunCountMon(runMon.getCount()); - waterPumpTargetVo.setRunDurationMon(runMon.getHour()); - // 年运行次数、时长 - WaterRunVo runYear = this.getRunData(device,0); - waterPumpTargetVo.setRunCountYear(runYear.getCount()); - waterPumpTargetVo.setRunDurationYear(runYear.getHour()); - // 当日机组有功功率 - List activePowerVoList = this.getActivePowerVoList(device); - waterPumpTargetVo.setActivePowerVoList(activePowerVoList); - // 近30天用电量 - List usrPowerVoList = this.getUsrPowerVoList(device); - waterPumpTargetVo.setUsrPowerVoList(usrPowerVoList); - // 近3年用电量 - Map usrYearMap = this.getUsrYearMap(device); - waterPumpTargetVo.setUsrYearMap(usrYearMap); - list.add(waterPumpTargetVo); - }); + if(CollectionUtil.isNotEmpty(valid)){ + valid.forEach(device->{ + WaterPumpTargetVo waterPumpTargetVo = new WaterPumpTargetVo(); + waterPumpTargetVo.setDeptId(device.getCreateDept()); + waterPumpTargetVo.setDeviceCode(device.getEmCode()); + waterPumpTargetVo.setDeptName(device.getName()); + // 当年用电量 + float usrPowerYear = this.getUsrPowerYear(device); + waterPumpTargetVo.setUsrPowerYear(usrPowerYear); + // 当月用电量 + float usrPowerMon = this.getUsrPowerMon(device); + waterPumpTargetVo.setUsrPowerMon(usrPowerMon); + // 当日用电量 + float usrPowerDay = this.getUsrPowerDay(device); + waterPumpTargetVo.setUsrPowerDay(usrPowerDay); + // 月运行次数、时长 + WaterRunVo runMon = this.getRunData(device,1); + waterPumpTargetVo.setRunCountMon(runMon.getCount()); + waterPumpTargetVo.setRunDurationMon(runMon.getHour()); + // 年运行次数、时长 + WaterRunVo runYear = this.getRunData(device,0); + waterPumpTargetVo.setRunCountYear(runYear.getCount()); + waterPumpTargetVo.setRunDurationYear(runYear.getHour()); + // 当日机组有功功率 + List activePowerVoList = this.getActivePowerVoList(device); + waterPumpTargetVo.setActivePowerVoList(activePowerVoList); + // 近30天用电量 + List usrPowerVoList = this.getUsrPowerVoList(device); + waterPumpTargetVo.setUsrPowerVoList(usrPowerVoList); + // 近3年用电量 + Map usrYearMap = this.getUsrYearMap(device); + waterPumpTargetVo.setUsrYearMap(usrYearMap); + list.add(waterPumpTargetVo); + }); + } + // 补充站点填报发电量 + List stations = stationService.list(Wrappers.lambdaQuery() + .in(StationEntity::getType, HomePageConstant.waterList) + .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) + ); + if(CollectionUtil.isNotEmpty(stations)){ + list.addAll(this.useFill(stations)); + } redisTemplate.opsForValue().set(loadwaterpump_target_key,list); } @@ -279,12 +282,8 @@ public class WaterServiceImpl implements IWaterService { if(StringUtil.isBlank(time)){ return 0.0; } - try{ - Date date = sdf.parse(time); - if(System.currentTimeMillis() - date.getTime() > 30 * 60 * 1000L){ - return 0.0; - } - }catch (ParseException e){ + Date date = DateUtil.parse(time,DateUtil.DATETIME_FORMAT); + if(System.currentTimeMillis() - date.getTime() > 30 * 60 * 1000L){ return 0.0; } return Double.parseDouble(R.getData().get(0).getValue()); @@ -297,7 +296,7 @@ public class WaterServiceImpl implements IWaterService { * @return */ private Map getWaterLevelMap(String instanceCode, String signage) { - LocalDateTime beginTime = LocalDateTime.parse(DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"), dtf); + LocalDateTime beginTime = LocalDateTime.parse(DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"), DateUtil.DATETIME_FORMATTER); LocalDateTime endTime = LocalDateTime.now(); AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); List signboardConditions = new ArrayList<>(); @@ -573,11 +572,11 @@ public class WaterServiceImpl implements IWaterService { */ private float getUsrPowerYear(EminfoAndEmParamVo device) { Calendar calendar = Calendar.getInstance(); - String end = sdf.format(calendar.getTime()); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String start = df.format(calendar.getTime()); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); // 当年用电量 return analyseDataService.periodTargetFloat(start,end,6,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); } @@ -801,36 +800,82 @@ public class WaterServiceImpl implements IWaterService { /** + * 获取填报用电量 + * @param stations + * @return + */ + private List useFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + //calendar.add(Calendar.DAY_OF_MONTH,-1); + //String yesterday = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + return stations.stream().map(station ->{ + WaterPumpTargetVo target = new WaterPumpTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); + // 月运行次数、时长 + target.setRunCountMon(0); + target.setRunDurationMon(0.0); + // 年运行次数、时长 + target.setRunCountYear(0); + target.setRunDurationYear(0.0); + // 当年用电量 + target.setUsrPowerYear(useService.use(year,station.getCode())); + // 当月用电量 + target.setUsrPowerMon(useService.use(mon,station.getCode())); + // 当日用电量 + target.setUsrPowerDay(useService.use(day,station.getCode())); + if(StationConstants.DATA_ORIGIN_FILL.equals(station.getDataOrigin())){ + // 30天用电量 + target.setUsrPowerVoList(useService.use30Day(day,station.getCode())); + } + // 近3年用电量 + target.setUsrYearMap(this.useThreeYear(station.getCode())); + return target; + }).collect(Collectors.toList()); + } + + /** + * 填报近3年发电量 + * @param station + * @return + */ + private Map useThreeYear(String station) { + // 开始时间 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),"yyyy-MM"); + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + return useService.generateThreeYear(start,end,station); + } + + /** * 水利首页-指标数据 * @param deptId * @return */ @Override public WaterConservancyVo waterConservancy(Long deptId) { - //根据用户权限获取机构 - R> R = sysClient.getDeptByCurrentUser(); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return null; - } - // 获取水利站点 - List stationList = stationService.getStationList(R.getData(),deptId,HomePageConstant.waterList,HomePageConstant.HYDROPOWER_SERVETYPE); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 站点归属机构集合 - List deptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptList)){ - return null; + // 查询水利站点 + List stations = stationService.getHomeStationList(deptId, HomePageConstant.waterList, HomePageConstant.HYDROPOWER_SERVETYPE); + if (CollectionUtil.isEmpty(stations)) { + return new WaterConservancyVo(); } WaterConservancyVo response = new WaterConservancyVo(); // 查询指标标题机构 - Dept title = this.getTitleDetp(R.getData(),deptId); + Dept title = this.getTitleDetp(deptId); if(ObjectUtil.isNotEmpty(title)){ response.setDepartId(title.getId()); response.setDepartName(title.getDeptName()); } - response.setWaterStationCount((int) stationList.stream().filter(o->HomePageConstant.PUMPING.equals(o.getType())).count()); - response.setSluiceGateCount((int) stationList.stream().filter(o->HomePageConstant.GATE.equals(o.getType())).count()); + response.setWaterStationCount((int) stations.stream().filter(o->HomePageConstant.PUMPING.equals(o.getType())).count()); + response.setSluiceGateCount((int) stations.stream().filter(o->HomePageConstant.GATE.equals(o.getType())).count()); response.setWaterInstall(0.0); response.setWaterPower(0.0); response.setKWhYear(0f); @@ -838,39 +883,35 @@ public class WaterServiceImpl implements IWaterService { response.setKWhDay(0f); // 获取设备实时数据 List list = (List) redisTemplate.opsForValue().get(loadwaterpump_real_key); - if(CollectionUtil.isEmpty(list)){ - return response; - } - // 获取站点机构有效设备 - List valid = list.stream().filter(o->deptList.contains(o.getDeptId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(valid)){ - return response; + if(CollectionUtil.isNotEmpty(list)){ + // 获取站点机构有效设备 + List valid = list.stream().filter(o->stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(valid)){ + // 装机容量 + double waterInstall = valid.stream().mapToDouble(WaterPumpRealVo::getInstalledCapacity).sum(); + response.setWaterInstall(waterInstall); + // 有功功率 + double waterPower = valid.stream().mapToDouble(WaterPumpRealVo::getActivePower).sum(); + response.setWaterPower(waterPower); + } } - // 装机容量 - double waterInstall = valid.stream().mapToDouble(WaterPumpRealVo::getInstalledCapacity).sum(); - response.setWaterInstall(waterInstall); - // 有功功率 - double waterPower = valid.stream().mapToDouble(WaterPumpRealVo::getActivePower).sum(); - response.setWaterPower(waterPower); // 获取设备指标数据 List targetList = (List) redisTemplate.opsForValue().get(loadwaterpump_target_key); - if(CollectionUtil.isEmpty(targetList)){ - return response; - } - // 获取站点机构有效设备 - List validTarget = targetList.stream().filter(o->deptList.contains(o.getDeptId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(valid)){ - return response; + if(CollectionUtil.isNotEmpty(targetList)){ + // 获取站点机构有效设备 + List validTarget = targetList.stream().filter(o->stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(o.getDeptId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(validTarget)){ + // 年用电量 + double kwhYear = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerYear).sum(); + response.setKWhYear((float) kwhYear); + // 月用电量 + double kwhMon = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerMon).sum(); + response.setKWhMon((float) kwhMon); + // 日用电量 + double kwhDay = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerDay).sum(); + response.setKWhDay((float) kwhDay); + } } - // 年用电量 - double kwhYear = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerYear).sum(); - response.setKWhYear((float) kwhYear); - // 月用电量 - double kwhMon = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerMon).sum(); - response.setKWhMon((float) kwhMon); - // 日用电量 - double kwhDay = validTarget.stream().mapToDouble(WaterPumpTargetVo::getUsrPowerDay).sum(); - response.setKWhDay((float) kwhDay); return response; } @@ -1154,16 +1195,17 @@ public class WaterServiceImpl implements IWaterService { * @return */ @Override - public Dept getTitleDetp(List authList, Long deptId) { + public Dept getTitleDetp(Long deptId) { + R> depts = sysClient.getDeptByCurrentUser(); if(null == deptId){ // 最小类型机构 - Dept dept = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)).orElse(null); + Dept dept = depts.getData().stream().min(Comparator.comparing(Dept::getDeptCategory)).orElse(null); if(ObjectUtil.isEmpty(dept)){ return null; } return dept; } - List list = authList.stream().filter(o->deptId.equals(o.getId())).collect(Collectors.toList()); + List list = depts.getData().stream().filter(o->deptId.equals(o.getId())).collect(Collectors.toList()); if(CollectionUtil.isEmpty(list)){ return null; } @@ -1496,26 +1538,6 @@ public class WaterServiceImpl implements IWaterService { } /** - * 获取近30天集合 - * @return - */ - private List getRecent30Day() { - List list = new ArrayList<>(); - // 开始日期 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - list.add(df.format(calendar.getTime())); - // 获取日期之间的月 - int i = 0; - while (i < 30) { - calendar.add(Calendar.DATE, - 1); - list.add(df.format(calendar.getTime())); - i++; - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - /** * 闸门列表 * @param deptId * @return @@ -1536,7 +1558,7 @@ public class WaterServiceImpl implements IWaterService { if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { return null; } - Dept title = this.getTitleDetp(R.getData(),deptId); + Dept title = this.getTitleDetp(deptId); if(ObjectUtil.isEmpty(title)){ return null; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java deleted file mode 100644 index ef89f5a..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WebHomeServiceImpl.java +++ /dev/null @@ -1,744 +0,0 @@ -package com.hnac.hzims.operational.main.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.hnac.hzims.EquipmentConstants; -import com.hnac.hzims.equipment.feign.IPlanGenertionClient; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.equipment.vo.PlanPowerYearVo; -import com.hnac.hzims.hzimsweather.response.weather.Daily; -import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; -import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; -import com.hnac.hzims.operational.main.service.*; -import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationAttributeService; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.soe.ISoeClient; -import com.hnac.hzinfo.datasearch.soe.domian.SoeData; -import lombok.RequiredArgsConstructor; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.stream.Collectors; - -/** - * APP首页实现类 - */ -@Service -@RequiredArgsConstructor -public class WebHomeServiceImpl implements IWebHomeService { - - private final IAnalyseDataService analyseDataService; - - private final IHomePageService homePageService; - - private final IMainSystemMonitoringService maintenanceTaskService; - - private final IStationService stationService; - - private final IStationAttributeService attributeService; - - private final IWaterService waterService; - - private final IPlanGenertionClient planGenertionClient; - - private final ISoeClient soeClient; - - private final IWeatherService weatherService; - - private final RedisTemplate redisTemplate; - - @Value("${hzims.operation.realIdKey}") - public String real_id_key; - - private final static String recent_year_power_data = "hzims:operation:key:power:data"; - private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; - private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; - private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - - - /** - * 加载水电站机组实时数据 - * @param param - */ - @Override - public void loadHydropowerReal(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ - return; - } - // 实时数据 - Map map = this.getRealMap(); - // 单位 - Map unitMap = this.attributeService.getPointUnit(); - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitRealVo realVo = new HydropowerUnitRealVo(); - realVo.setDeptId(device.getCreateDept()); - realVo.setDeviceCode(device.getEmCode()); - realVo.setDeptName(device.getName()); - realVo.setDeviceName(device.getName()); - // 开关机状态 - String state = this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY); - realVo.setState(state); - // 有功功率 - String activePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER); - realVo.setActivePower(activePower); - // 无功功率 - String reactivePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER); - realVo.setReactivePower(reactivePower); - // 功率因数 - String powerFactor = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR); - realVo.setPowerFactor(powerFactor); - // 机组频率 - String frequency = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY); - realVo.setFrequency(frequency); - // 导叶开度 - String guideOpen = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN); - realVo.setGuideOpen(guideOpen); - // 定子电压 - String statorVoltage = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE); - realVo.setStatorVoltage(statorVoltage); - // 定子电流 - String statorCurrent = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT); - realVo.setStatorCurrent(statorCurrent); - // 单位设置 - this.setttingUnit(device,unitMap,realVo); - list.add(realVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_real_key,list); - } - - /** - * 获取实时数据 - * @return - */ - private Map getRealMap() { - String json = (String) redisTemplate.opsForValue().get(real_id_key); - if(StringUtil.isBlank(json)){ - return null; - } - return JSONObject.parseObject(json, new TypeReference>() {}); - } - - /** - * 加载水电站机组指标数据 - * @param param - */ - @Override - public void loadHydropowerTarget(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ - return; - } - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitTargetVo targetVo = new HydropowerUnitTargetVo(); - targetVo.setDeptId(device.getCreateDept()); - targetVo.setDeviceCode(device.getEmCode()); - targetVo.setDeviceName(device.getName()); - targetVo.setDeptName(device.getName()); - // 当年发电量 - float powerYear = this.getGenerationPower(device,0); - targetVo.setPowerYear(powerYear); - // 当月发电量 - float powerMon = this.getGenerationPower(device,1); - targetVo.setPowerMon(powerMon); - // 当日发电量 - float powerDay = this.getGenerationPower(device,2); - // 当天有功功率 - List activePowerVoList = waterService.getActivePowerVoList(device); - targetVo.setActivePowerVoList(activePowerVoList); - // 30天发电量 - List generationPowerVoList = this.getGenerationPowerList(device); - targetVo.setGenerationPowerVoList(generationPowerVoList); - targetVo.setPowerDay(powerDay); - list.add(targetVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_target_key,list); - } - - /** - * 获取有效设备 - * @return - */ - private List getValidDeviceList() { - // 水利站点(All) - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), null); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 获取所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - if(CollectionUtil.isEmpty(deviceList)){ - return null; - } - // 有效泵租设备 - List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptIdList)){ - return null; - } - return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); - } - - - /** - * 获取监测点实时数据 - * @param em - * @param targets - * @return - */ - private String getSignageValue(EminfoAndEmParamVo em,Map map, String targets) { - if(ObjectUtil.isEmpty(em) || MapUtils.isEmpty(map)){ - return "0"; - } - Map point = em.getPoint(); - if(MapUtils.isEmpty(point)){ - return "0"; - } - String realId = point.get(targets); - if(StringUtil.isBlank(realId)){ - return "0"; - } - String value = map.get(realId); - if(StringUtil.isBlank(value)){ - return "0"; - } - // 获取value - return value; - } - - /** - * 单位设置 - * @param device - * @param unitMap - * @param realVo - */ - private void setttingUnit(EminfoAndEmParamVo device, Map unitMap, HydropowerUnitRealVo realVo) { - if(MapUtils.isEmpty(unitMap)){ - return; - } - // 有功功率单位 - String power = unitMap.get(device.getId()+HomePageConstant.CONCAT_P); - if(StringUtil.isNotBlank(power)){ - realVo.setPowerUnit(power); - } else { - realVo.setPowerUnit("kW"); - } - // 无功功率 - String reactivePowerUnit = unitMap.get(device.getId()+HomePageConstant.CONCAT_Q); - if(StringUtil.isNotBlank(reactivePowerUnit)){ - realVo.setReactivePowerUnit(reactivePowerUnit); - } else { - realVo.setReactivePowerUnit("kVa r"); - } - // 定子电压单位 - String voltage = unitMap.get(device.getId()+HomePageConstant.CONCAT_UAB); - if(StringUtil.isNotBlank(voltage)){ - realVo.setVoltageUnit(voltage); - } else { - realVo.setVoltageUnit("V"); - } - // 定子电流单位 - String current = unitMap.get(device.getId()+HomePageConstant.CONCAT_IA); - if(StringUtil.isNotBlank(current)){ - realVo.setCurrentUnit(current); - } else { - realVo.setCurrentUnit("A"); - } - } - - /** - * 获取年、月、日发电量 - * @param device - * @param scope - * @return - */ - private float getGenerationPower(EminfoAndEmParamVo device,int scope) { - String start,end; - int accessRules; - Calendar calendar = Calendar.getInstance(); - switch (scope){ - // 年 - case 0: - end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - accessRules = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); - break; - // 月 - case 1: - start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - accessRules = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); - break; - // 日 - case 2: - String time = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - start = time + " 00:00:00"; - end = time + " 23:59:59"; - accessRules = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); - break; - default: - throw new IllegalStateException("Unexpected value: " + scope); - } - return analyseDataService.periodTargetFloat(start,end,accessRules,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - } - - /** - * 近30天发电量 - * @param device - * @return - */ - private List getGenerationPowerList(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH,-29); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - List records = analyseDataService.periodTargetData(start,end,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - GenerationPowerVo generate = new GenerationPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); - return generate; - }).collect(Collectors.toList()); - } - - /** - * 水电站-站点信息 - * @param deptId - * @return - */ - @Override - public HydropowerStationVo webStation(Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return null; - } - // 站点 - StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); - if(ObjectUtil.isEmpty(station)){ - return null; - } - List list = this.getHydropowerStationList(Collections.singletonList(station)); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return list.get(0); - } - - /** - * 获取首页站点信息 - * @param list - * @return - */ - private List getHydropowerStationList(List list) { - if(CollectionUtil.isEmpty(list)){ - return null; - } - // 实时监测点数据 - List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); - // 获取站点机组指标数据 - List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - // 所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - // 实时天气 - Map weather = this.getWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - // 七天天气 - Map weekWeather = this.getWeekWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - List result = new ArrayList<>(); - list.forEach(station ->{ - HydropowerStationVo response = new HydropowerStationVo(); - response.setDeptId(station.getRefDept()); - response.setDeptName(station.getName()); - response.setStationCode(station.getCode()); - // 站点状态 - List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); - if (CollectionUtil.isNotEmpty(soeDataList)) { - response.setStationStatus(false); - } else { - response.setStationStatus(true); - } - // 站点实时天气 - String temp = this.getTemp(weather,station.getCode()); - response.setTemp(temp); - // 站点七天天气 - List dailys = this.getDailyList(weekWeather,station.getCode()); - response.setWeather(dailys); - // 限制水位 - response.setLimitWaterLevel(station.getLimitWaterLevel()); - // 运行天数 - int runDay = this.getRunDay(station); - response.setRunDay(runDay); - // 装机容量 - double installedCapacity = this.getInstalledCapacity(deviceList,station.getRefDept()); - response.setInstalledCapacity(installedCapacity); - // 总有功功率(总发电负荷) - double powerSum = this.getPowerSum(realList,station.getRefDept()); - response.setPowerSum(powerSum); - // 总有功单位 - String unit = this.getPowerUnit(realList,station.getRefDept()); - response.setPowerUnit(unit); - // 月计划发电量 - float planPowerMon = this.getPlanPowerrMon(station.getCode()); - response.setPlanPowerMon(planPowerMon); - // 年计划发电量 - float planPowerYear = this.getPlanPowerYear(station.getCode()); - response.setPlanPowerYear(planPowerYear); - // 月发电量、年发电量、年发电完成率 - this.handleStationInfo(station.getRefDept(),response); - // 水位、水位曲线 - this.handleWaterLeve(station.getCode(),response); - // 年发电量完成百分比 - List powerYearList = this.handlePowerFinish(station); - response.setPowerYearMap(powerYearList); - // 设备信息 - List devices = this.getDevices(station,realList,targetList); - response.setDeviceList(devices); - result.add(response); - }); - return result; - } - - /** - * 获取站点设备信息 - * @param station - * @return - */ - private List getDevices(StationEntity station,List realList,List targetList) { - if(CollectionUtil.isEmpty(realList) || CollectionUtil.isEmpty(targetList)){ - return null; - } - // 有效站点机组数据 - List validRealList = realList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList()); - // 有效站点机组指标数据 - List validTargetList = targetList.stream().filter(o-> null != station.getRefDept() && station.getRefDept().equals(o.getDeptId())).collect(Collectors.toList()); - List list = new ArrayList<>(); - for(HydropowerUnitRealVo real : validRealList){ - HydropowerUnitVo hydropowerUnitVo = new HydropowerUnitVo(); - // 设备编号 - hydropowerUnitVo.setDeivceCode(real.getDeviceCode()); - hydropowerUnitVo.setDeivceName(real.getDeviceName()); - // 实时数据 - hydropowerUnitVo.setHydropowerPumpRealVo(real); - // 指标数据 - if(CollectionUtil.isNotEmpty(validTargetList)){ - List target = targetList.stream().filter(o->real.getDeviceCode().equals(o.getDeviceCode())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(target)){ - hydropowerUnitVo.setHydropowerPumpTargetVo(target.get(0)); - } - } - list.add(hydropowerUnitVo); - } - return list.stream().sorted(Comparator.comparing(HydropowerUnitVo::getDeivceCode)).collect(Collectors.toList()); - } - - /** - * 获取实时温度 - * @param weather - * @param code - * @return - */ - private String getTemp(Map weather, String code) { - if(MapUtils.isEmpty(weather)){ - return "21"; - } - HeWeatherWeatherNowResponse now = weather.get(code); - if(ObjectUtil.isEmpty(now) || ObjectUtil.isEmpty(now.getNow())){ - return "21"; - } - return now.getNow().getTemp(); - } - - /** - * 获取七天天气 - * @param weekWeather - * @param code - * @return - */ - private List getDailyList(Map weekWeather, String code) { - if(MapUtils.isEmpty(weekWeather)){ - return null; - } - HeWeatherWeatherDailyResponse week = weekWeather.get(code); - if(ObjectUtil.isEmpty(week)){ - return null; - } - return week.getDaily(); - } - - /** - * 获取站点实时天气 - * @param codes - */ - private Map getWeather(List codes) { - if(CollectionUtil.isEmpty(codes)){ - return null; - } - // 实时天气 - return this.weatherService.getNowWeather(codes); - } - - /** - * 获取七天天气 - * @param codes - */ - private Map getWeekWeather(List codes) { - if(CollectionUtil.isEmpty(codes)){ - return null; - } - // 实时天气 - return this.weatherService.getWeekWeather(codes); - } - - /** - * 获取设备装机容量 - * @param list - * @param refDept - * @return - */ - private double getInstalledCapacity(List list, Long refDept) { - if(CollectionUtil.isEmpty(list) || ObjectUtil.isEmpty(refDept)){ - return 0.0; - } - return list.stream().filter(o -> refDept.equals(o.getCreateDept())).mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum(); - } - - /** - * 获取站点运行天数 - * @param station - * @return - */ - private int getRunDay(StationEntity station) { - if (ObjectUtil.isEmpty(station.getCommissionTime())) { - return 0; - } - // 计算投运时间与当前时间相隔天数 - Duration dur = Duration.between(station.getCommissionTime(), LocalDateTime.now()); - return (int) dur.toDays(); - } - - /** - * 获取总发电负荷 - * @param deptId - * @return - */ - private Double getPowerSum(List realList,Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return 0.0; - } - // 获取站点机组实时数据 - if(CollectionUtil.isEmpty(realList)){ - return 0.0; - } - return realList.stream().filter(o->deptId.equals(o.getDeptId())).mapToDouble(o->Double.parseDouble(o.getActivePower())).sum(); - } - - /** - * 获取总发电负荷单位 - * @param realList - * @param deptId - * @return - */ - private String getPowerUnit(List realList, Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return "kW"; - } - // 获取站点机组实时数据 - if(CollectionUtil.isEmpty(realList)){ - return "kW"; - } - List unit = realList.stream().filter(o->deptId.equals(o.getDeptId()) && StringUtil.isNotBlank(o.getPowerUnit())).map(HydropowerUnitRealVo::getPowerUnit).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(unit)){ - return "kW"; - } - return unit.get(0); - } - - /** - * 获取月计划发电量 - * @param code - * @return - */ - private float getPlanPowerrMon(String code) { - R R = planGenertionClient.planGenerationMonthCount(code, DateUtil.format(new Date(), "yyyy-MM")); - if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ - return 0f; - } - return R.getData(); - } - - /** - * 获取年计划发电量 - * @param code - * @return - */ - private float getPlanPowerYear(String code) { - R R = planGenertionClient.planGenerationYearCount(code); - if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ - return 0f; - } - // 查询年计划发电量 - return R.getData(); - } - - /** - * 站点信息处理 - * @param deptId - * @param response - */ - private void handleStationInfo(Long deptId, HydropowerStationVo response) { - response.setPowerMon(0f); - response.setPowerYear(0f); - response.setPowerRateYear(0.0); - List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - if(CollectionUtil.isEmpty(targetList)){ - return; - } - // 月发电量 - float powerMont = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerMon).sum(); - response.setPowerMon(powerMont); - // 年发电量 - float powerYear = (float) targetList.stream().filter(o-> deptId.equals(o.getDeptId())).mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum(); - response.setPowerYear(powerYear); - // 年发电完成率 - float planPowerYear = response.getPlanPowerYear(); - if(Math.abs(planPowerYear) <= 0){ - response.setPowerRateYear(0.0); - } else { - double powerRateYear = BigDecimal.valueOf(powerYear / planPowerYear * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - response.setPowerRateYear(powerRateYear); - } - } - - /** - * 站点水位数据处理 - * @param code - * @param response - */ - private void handleWaterLeve(String code, HydropowerStationVo response) { - response.setFrontWaterLevel(0.0); - List levelList = (List) redisTemplate.opsForValue().get(loadwater_level_key); - if(CollectionUtil.isEmpty(levelList)){ - return; - } - List validList = levelList.stream().filter(o-> code.equals(o.getStationCode())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(validList)){ - return; - } - WaterLevelVo level = validList.get(0); - // 前池水位、当日水位曲线 - response.setFrontWaterLevel(level.getFrontWaterLevel()); - response.setFrontCurveMap(level.getFrontCurveMap()); - } - - /** - * 年发电量完成百分比 - * @param station - */ - private List handlePowerFinish(StationEntity station) { - String code = station.getCode(); - if(StringUtil.isBlank(code)){ - return null; - } - // 实际发电量 - Map> powerMap = (Map>) redisTemplate.opsForValue().get(recent_year_power_data); - // 查询计划发电量 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - List planPowerList = planGenertionClient.getPlanPowerByYear(code,calendar.get(Calendar.YEAR)); - // 获取月份集合 - List monList = homePageService.getMonthList(0,12,false); - return monList.stream().map(o->{ - PowerMonthVo vo = new PowerMonthVo(); - LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), o), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - vo.setStrMonth(o); - vo.setYear(localDate.getYear()); - vo.setMonth(localDate.getMonthValue()); - // 实际发电量 - if(CollectionUtil.isEmpty(powerMap)){ - vo.setPower(0f); - }else{ - Map map = powerMap.get(station.getId()); - if(MapUtils.isEmpty(map)){ - vo.setPower(0f); - }else{ - vo.setPower(map.get(o)); - } - } - // 计划发电量 - if(CollectionUtil.isEmpty(planPowerList)){ - vo.setPlanPower(0f); - }else{ - String mon = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")); - List list = planPowerList.stream().filter(s->mon.equals(s.getMon())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(list)){ - vo.setPlanPower(0f); - }else{ - vo.setPlanPower(list.get(0).getPlanPower()); - } - } - return vo; - }).collect(Collectors.toList()); - } - - /** - * 水电站-机组列表 - * @param deptId - * @return - */ - @Override - public List hydropowerDevice(Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return null; - } - // 查询站点 - StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); - if(ObjectUtil.isEmpty(station)){ - return null; - } - // 实时监测点数据 - List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); - // 获取站点机组指标数据 - List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - return this.getDevices(station,realList,targetList); - } - - /** - * 水电站站点列表 - * @param deptId - * @return - */ - @Override - public List webStationList(Long deptId) { - List list = stationService.getStationType(null,Collections.singletonList(HomePageConstant.HYDROPOWER),null); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return this.getHydropowerStationList(list); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IOperMaintenanceTaskService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IOperMaintenanceTaskService.java index 3a23096..45098e1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IOperMaintenanceTaskService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IOperMaintenanceTaskService.java @@ -3,16 +3,13 @@ package com.hnac.hzims.operational.maintenance.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.operational.maintenance.dto.OperMaintenanceTaskDTO; -import com.hnac.hzims.operational.maintenance.vo.RegularWorkVO; -import com.hnac.hzims.operational.report.vo.MaintenanceReportVO; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskVO; -import com.hnac.hzims.ticket.areamonthly.vo.AreaMonthlyVo; +import com.hnac.hzims.operational.maintenance.vo.RegularWorkVO; +import com.hnac.hzims.operational.report.vo.MaintenanceReportVO; import com.hnac.hzims.ticket.areamonthly.vo.MaintenanceTaskVo; import com.hnac.hzims.ticket.areamonthly.vo.MaintenanceTaskWithAreaVo; import com.hnac.hzims.vo.SafeCheckStatisticVO; -import com.hnac.hzinfo.inspect.areamonthly.vo.TaskListQuery; -import com.hnac.hzinfo.inspect.areamonthly.vo.TaskVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -20,7 +17,6 @@ import org.springblade.flow.core.vo.ComleteTask; import org.springframework.web.bind.annotation.RequestParam; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.List; import java.util.Map; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/ImsDeptServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/ImsDeptServiceImpl.java index 1978644..12fcb92 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/ImsDeptServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/ImsDeptServiceImpl.java @@ -319,7 +319,7 @@ public class ImsDeptServiceImpl extends ServiceImpl Date: Thu, 13 Apr 2023 16:40:41 +0800 Subject: [PATCH 6/7] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E5=8F=91?= =?UTF-8?q?=E5=A1=AB=E6=8A=A5=E7=94=B5=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/operational/fill/entity/UseEntity.java | 5 + .../operational/fill/service/GenerateService.java | 9 + .../fill/service/impl/GenerateServiceImpl.java | 54 +++ .../main/controller/WebHomeController.java | 9 +- .../main/service/HydropowerService.java | 2 +- .../main/service/impl/HydropowerServiceImpl.java | 406 ++++++++++++--------- .../main/service/impl/SideHustleServiceImpl.java | 72 +--- .../main/service/impl/WaterServiceImpl.java | 182 ++++----- 8 files changed, 395 insertions(+), 344 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java index f097c8d..75b7786 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/entity/UseEntity.java @@ -5,12 +5,17 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springblade.core.tenant.mp.TenantEntity; import java.io.Serializable; import java.math.BigDecimal; +/** + * @author usj + */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("hzims_fill_use") @ApiModel(value="UseEntity", description="保存用电量填报数据对象") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java index 8e7bcfe..29bb8aa 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/GenerateService.java @@ -6,12 +6,15 @@ import com.hnac.hzims.operational.fill.entity.RainfallEntity; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.vo.RainfallVo; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import java.util.List; +import java.util.Map; /** * @author ysj @@ -26,6 +29,12 @@ public interface GenerateService extends BaseService { // 新增/修改发电量填报数据 boolean saveUpdate(GenerateEntity entity); + // 查询填报用电量 + Float generate(String date,String station); + + // 查询30天填报用电量 + List generate30Day(String day, String station); + // 获取站点填报发电量 List generateThreeYear(String start, String end, String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 6ff4613..2b1f037 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.fill.entity.UseEntity; import com.hnac.hzims.operational.fill.mapper.GenerateMapper; import com.hnac.hzims.operational.fill.service.GenerateService; import com.hnac.hzims.operational.fill.vo.GenerateVo; import com.hnac.hzims.operational.fill.vo.QueryVo; import com.hnac.hzims.operational.fill.wrapper.GenerateWrapper; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; @@ -25,6 +28,7 @@ import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -88,6 +92,56 @@ public class GenerateServiceImpl extends BaseServiceImpl powers = this.list(Wrappers.lambdaQuery() + .likeRight(GenerateEntity::getFillDate,date) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0f; + } + return (float) powers.stream().mapToDouble(GenerateEntity::getGenerate).sum(); + } + + /** + * 查询30天填报用电量 + * @param day : 结束日期 yyyy-MM-dd + * @param station 站点编码 + * @return + */ + @Override + public List generate30Day(String day, String station) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = this.list(Wrappers.lambdaQuery() + .between(GenerateEntity::getFillDate,start,end) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record->{ + GenerationPowerVo generate = new GenerationPowerVo(); + generate.setDate(record.getFillDate()); + if(Math.abs(record.getGenerate()) <= 0){ + generate.setGenerate(0f); + }else{ + generate.setGenerate(Float.parseFloat(record.getGenerate().toString())); + } + return generate; + }).collect(Collectors.toList()); + } + + /** * * @param start 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd * @param end 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java index c7a5096..1f53f74 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/WebHomeController.java @@ -17,6 +17,9 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +/** + * @author ysj + */ @RestController @RequestMapping("/webHome") @Api(value = "app首页", tags = "app-首页") @@ -24,12 +27,13 @@ import java.util.List; public class WebHomeController extends BladeController { private final HydropowerService service; + @ApiLog @ApiOperation("水电站站点统计") @GetMapping("/webStation") @ApiOperationSupport(order = 1) public R hydropowerStation(@ApiParam(value = "站点机构ID") Long deptId) { - HydropowerStationVo response = service.webStation(deptId); + HydropowerStationVo response = service.station(deptId); return R.data(response); } @ApiLog @@ -41,7 +45,6 @@ public class WebHomeController extends BladeController { return R.data(list); } @ApiLog - @ApiOperation("水电站站点列表") @GetMapping("/webStationList") @ApiOperationSupport(order = 2) @@ -49,4 +52,4 @@ public class WebHomeController extends BladeController { return R.data(service.webStationList(deptId)); } -} +} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java index b7a0576..6ccae65 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/HydropowerService.java @@ -14,7 +14,7 @@ public interface HydropowerService { void loadHydropowerTarget(String param); - HydropowerStationVo webStation(Long deptId); + HydropowerStationVo station(Long deptId); List hydropowerDevice(Long deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index 8393825..38f74be 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.main.service.impl; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.EquipmentConstants; import com.hnac.hzims.equipment.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; @@ -9,9 +10,10 @@ import com.hnac.hzims.equipment.vo.PlanPowerYearVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; +import com.hnac.hzims.operational.fill.service.GenerateService; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationAttributeService; import com.hnac.hzims.operational.station.service.IStationService; @@ -44,23 +46,25 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class HydropowerServiceImpl implements HydropowerService { - private final IAnalyseDataService analyseDataService; - - private final IHomePageService homePageService; + private final IWaterService waterService; - private final IMainSystemMonitoringService maintenanceTaskService; + private final IWeatherService weatherService; private final IStationService stationService; - private final IStationAttributeService attributeService; + private final GenerateService generateService; - private final IWaterService waterService; + private final IHomePageService homePageService; - private final IPlanGenertionClient planGenertionClient; + private final IAnalyseDataService analyseDataService; + + private final IStationAttributeService attributeService; + + private final IMainSystemMonitoringService maintenanceTaskService; private final ISoeClient soeClient; - private final IWeatherService weatherService; + private final IPlanGenertionClient planGenertionClient; private final RedisTemplate redisTemplate; @@ -79,63 +83,54 @@ public class HydropowerServiceImpl implements HydropowerService { */ @Override public void loadHydropowerReal(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ return; } // 实时数据 Map map = this.getRealMap(); // 单位 Map unitMap = this.attributeService.getPointUnit(); - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitRealVo realVo = new HydropowerUnitRealVo(); - realVo.setDeptId(device.getCreateDept()); - realVo.setDeviceCode(device.getEmCode()); - realVo.setDeptName(device.getName()); - realVo.setDeviceName(device.getName()); + // 实时数据 + List reals = devices.stream().map(device->{ + HydropowerUnitRealVo real = new HydropowerUnitRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); + real.setDeviceName(device.getName()); // 开关机状态 - String state = this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY); - realVo.setState(state); + real.setState(this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY)); // 有功功率 - String activePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER); - realVo.setActivePower(activePower); + real.setActivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER)); // 无功功率 - String reactivePower = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER); - realVo.setReactivePower(reactivePower); + real.setReactivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER)); // 功率因数 - String powerFactor = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR); - realVo.setPowerFactor(powerFactor); + real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR)); // 机组频率 - String frequency = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY); - realVo.setFrequency(frequency); + real.setFrequency(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY)); // 导叶开度 - String guideOpen = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN); - realVo.setGuideOpen(guideOpen); + real.setGuideOpen(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN)); // 定子电压 - String statorVoltage = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE); - realVo.setStatorVoltage(statorVoltage); + real.setStatorVoltage(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE)); // 定子电流 - String statorCurrent = this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT); - realVo.setStatorCurrent(statorCurrent); + real.setStatorCurrent(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT)); // 单位设置 - this.setttingUnit(device,unitMap,realVo); - list.add(realVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_real_key,list); - } - - /** - * 获取实时数据 - * @return - */ - private Map getRealMap() { - String json = (String) redisTemplate.opsForValue().get(real_id_key); - if(StringUtil.isBlank(json)){ - return null; + this.setttingUnit(device,unitMap,real); + return real; + }).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(reals)){ + return; } - return JSONObject.parseObject(json, new TypeReference>() {}); + redisTemplate.opsForValue().set(load_hydropower_unit_real_key,reals); } /** @@ -144,59 +139,98 @@ public class HydropowerServiceImpl implements HydropowerService { */ @Override public void loadHydropowerTarget(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 补充填补发电指标 + List targets = this.generteFill(stations); + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isNotEmpty(devices)){ + targets.addAll(devices.stream().map(device->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当年发电量 + target.setPowerYear(this.getGenerationPower(device,0)); + // 当月发电量 + target.setPowerMon(this.getGenerationPower(device,1)); + // 当日发电量 + target.setPowerDay(this.getGenerationPower(device,2)); + // 当天有功功率 + target.setActivePowerVoList(waterService.getActivePowerVoList(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerationPowerList(device)); + return target; + }).collect(Collectors.toList())); + } + // 站点指标数据为空 + if(CollectionUtil.isEmpty(targets)){ return; } - List list = new ArrayList<>(); - valid.forEach(device->{ - HydropowerUnitTargetVo targetVo = new HydropowerUnitTargetVo(); - targetVo.setDeptId(device.getCreateDept()); - targetVo.setDeviceCode(device.getEmCode()); - targetVo.setDeviceName(device.getName()); - targetVo.setDeptName(device.getName()); + redisTemplate.opsForValue().set(load_hydropower_unit_target_key,targets); + } + + /** + * 获取填报用电量 + * @param stations + * @return + */ + private List generteFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + return stations.stream().map(station ->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); // 当年发电量 - float powerYear = this.getGenerationPower(device,0); - targetVo.setPowerYear(powerYear); + target.setPowerYear(generateService.generate(year,station.getCode())); // 当月发电量 - float powerMon = this.getGenerationPower(device,1); - targetVo.setPowerMon(powerMon); + target.setPowerMon(generateService.generate(mon,station.getCode())); // 当日发电量 - float powerDay = this.getGenerationPower(device,2); - // 当天有功功率 - List activePowerVoList = waterService.getActivePowerVoList(device); - targetVo.setActivePowerVoList(activePowerVoList); + target.setPowerDay(generateService.generate(day,station.getCode())); // 30天发电量 - List generationPowerVoList = this.getGenerationPowerList(device); - targetVo.setGenerationPowerVoList(generationPowerVoList); - targetVo.setPowerDay(powerDay); - list.add(targetVo); - }); - redisTemplate.opsForValue().set(load_hydropower_unit_target_key,list); + target.setGenerationPowerVoList(generateService.generate30Day(day,station.getCode())); + return target; + }).collect(Collectors.toList()); } + /** - * 获取有效设备 + * 泵站设备 + * @param stations * @return */ - private List getValidDeviceList() { - // 水利站点(All) - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(HomePageConstant.HYDROPOWER), null); - if(CollectionUtil.isEmpty(stationList)){ - return null; + private List pumpDevices(List stations){ + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); } - // 获取所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - if(CollectionUtil.isEmpty(deviceList)){ - return null; + List devices = maintenanceTaskService.getEmInfoList(); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); } - // 有效泵租设备 - List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptIdList)){ + return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); + } + + /** + * 获取实时数据 + * @return + */ + private Map getRealMap() { + String json = (String) redisTemplate.opsForValue().get(real_id_key); + if(StringUtil.isBlank(json)){ return null; } - return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); + return JSONObject.parseObject(json, new TypeReference>() {}); } @@ -334,7 +368,7 @@ public class HydropowerServiceImpl implements HydropowerService { * @return */ @Override - public HydropowerStationVo webStation(Long deptId) { + public HydropowerStationVo station(Long deptId) { if(ObjectUtil.isEmpty(deptId)){ return null; } @@ -343,86 +377,76 @@ public class HydropowerServiceImpl implements HydropowerService { if(ObjectUtil.isEmpty(station)){ return null; } - List list = this.getHydropowerStationList(Collections.singletonList(station)); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return list.get(0); + // 实时监测点数据 + List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); + // 获取站点机组指标数据 + List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + // 实时天气 + Map weather = this.getWeather(Collections.singletonList(station.getCode())); + // 七天天气 + Map weekWeather = this.getWeekWeather(Collections.singletonList(station.getCode())); + HydropowerStationVo response = new HydropowerStationVo(); + response.setDeptId(station.getRefDept()); + response.setDeptName(station.getName()); + response.setStationCode(station.getCode()); + // 站点状态 + List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); + response.setStationStatus(!CollectionUtil.isNotEmpty(soeDataList)); + // 站点实时天气 + response.setTemp(this.getTemp(weather,station.getCode())); + // 站点七天天气 + response.setWeather(this.getDailyList(weekWeather,station.getCode())); + // 限制水位 + response.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + response.setRunDay(this.getRunDay(station)); + // 装机容量 + response.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); + // 总有功功率(总发电负荷) + response.setPowerSum(this.getPowerSum(realList,station.getRefDept())); + // 总有功单位 + response.setPowerUnit(this.getPowerUnit(realList,station.getRefDept())); + // 月计划发电量 + response.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); + // 年计划发电量 + response.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),response); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),response); + // 年发电量完成百分比 + response.setPowerYearMap(this.handlePowerFinish(station)); + // 设备信息 + response.setDeviceList(this.getDevices(station,realList,targetList)); + return response; } + /** - * 获取首页站点信息 - * @param list + * 水电站-机组列表 + * @param deptId * @return */ - private List getHydropowerStationList(List list) { - if(CollectionUtil.isEmpty(list)){ + @Override + public List hydropowerDevice(Long deptId) { + if(ObjectUtil.isEmpty(deptId)){ + return null; + } + // 查询站点 + StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); + if(ObjectUtil.isEmpty(station)){ return null; } // 实时监测点数据 List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); // 获取站点机组指标数据 List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - // 所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - // 实时天气 - Map weather = this.getWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - // 七天天气 - Map weekWeather = this.getWeekWeather(list.stream().map(StationEntity::getCode).collect(Collectors.toList())); - List result = new ArrayList<>(); - list.forEach(station ->{ - HydropowerStationVo response = new HydropowerStationVo(); - response.setDeptId(station.getRefDept()); - response.setDeptName(station.getName()); - response.setStationCode(station.getCode()); - // 站点状态 - List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); - if (CollectionUtil.isNotEmpty(soeDataList)) { - response.setStationStatus(false); - } else { - response.setStationStatus(true); - } - // 站点实时天气 - String temp = this.getTemp(weather,station.getCode()); - response.setTemp(temp); - // 站点七天天气 - List dailys = this.getDailyList(weekWeather,station.getCode()); - response.setWeather(dailys); - // 限制水位 - response.setLimitWaterLevel(station.getLimitWaterLevel()); - // 运行天数 - int runDay = this.getRunDay(station); - response.setRunDay(runDay); - // 装机容量 - double installedCapacity = this.getInstalledCapacity(deviceList,station.getRefDept()); - response.setInstalledCapacity(installedCapacity); - // 总有功功率(总发电负荷) - double powerSum = this.getPowerSum(realList,station.getRefDept()); - response.setPowerSum(powerSum); - // 总有功单位 - String unit = this.getPowerUnit(realList,station.getRefDept()); - response.setPowerUnit(unit); - // 月计划发电量 - float planPowerMon = this.getPlanPowerrMon(station.getCode()); - response.setPlanPowerMon(planPowerMon); - // 年计划发电量 - float planPowerYear = this.getPlanPowerYear(station.getCode()); - response.setPlanPowerYear(planPowerYear); - // 月发电量、年发电量、年发电完成率 - this.handleStationInfo(station.getRefDept(),response); - // 水位、水位曲线 - this.handleWaterLeve(station.getCode(),response); - // 年发电量完成百分比 - List powerYearList = this.handlePowerFinish(station); - response.setPowerYearMap(powerYearList); - // 设备信息 - List devices = this.getDevices(station,realList,targetList); - response.setDeviceList(devices); - result.add(response); - }); - return result; + return this.getDevices(station,realList,targetList); } + /** * 获取站点设备信息 * @param station @@ -705,39 +729,63 @@ public class HydropowerServiceImpl implements HydropowerService { }).collect(Collectors.toList()); } + /** - * 水电站-机组列表 + * 水电站站点列表 * @param deptId * @return */ @Override - public List hydropowerDevice(Long deptId) { - if(ObjectUtil.isEmpty(deptId)){ - return null; - } - // 查询站点 - StationEntity station = stationService.getStationByCodeOrRefDept(null,deptId); - if(ObjectUtil.isEmpty(station)){ + public List webStationList(Long deptId) { + List stations = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE,Collections.singletonList(HomePageConstant.HYDROPOWER),null); + if(CollectionUtil.isEmpty(stations)){ return null; } // 实时监测点数据 List realList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); // 获取站点机组指标数据 List targetList = (List) redisTemplate.opsForValue().get(load_hydropower_unit_target_key); - return this.getDevices(station,realList,targetList); - } - - /** - * 水电站站点列表 - * @param deptId - * @return - */ - @Override - public List webStationList(Long deptId) { - List list = stationService.getStationType(null,Collections.singletonList(HomePageConstant.HYDROPOWER),null); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return this.getHydropowerStationList(list); + // 所有设备 + List deviceList = maintenanceTaskService.getEmInfoList(); + // 实时天气 + Map weather = this.getWeather(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); + // 七天天气 + Map weekWeather = this.getWeekWeather(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); + return stations.stream().map(station->{ + HydropowerStationVo hydropower = new HydropowerStationVo(); + hydropower.setDeptId(station.getRefDept()); + hydropower.setDeptName(station.getName()); + hydropower.setStationCode(station.getCode()); + // 站点状态 + List soeDataList = soeClient.getByLastLimitTime(null, station.getCode(), 1).getData(); + hydropower.setStationStatus(!CollectionUtil.isNotEmpty(soeDataList)); + // 站点实时天气 + hydropower.setTemp(this.getTemp(weather,station.getCode())); + // 站点七天天气 + hydropower.setWeather(this.getDailyList(weekWeather,station.getCode())); + // 限制水位 + hydropower.setLimitWaterLevel(station.getLimitWaterLevel()); + // 运行天数 + hydropower.setRunDay(this.getRunDay(station)); + // 装机容量 + hydropower.setInstalledCapacity(this.getInstalledCapacity(deviceList,station.getRefDept())); + // 总有功功率(总发电负荷) + hydropower.setPowerSum(this.getPowerSum(realList,station.getRefDept())); + // 总有功单位 + hydropower.setPowerUnit(this.getPowerUnit(realList,station.getRefDept())); + // 月计划发电量 + hydropower.setPlanPowerMon(this.getPlanPowerrMon(station.getCode())); + // 年计划发电量 + hydropower.setPlanPowerYear(this.getPlanPowerYear(station.getCode())); + // 月发电量、年发电量、年发电完成率 + this.handleStationInfo(station.getRefDept(),hydropower); + // 水位、水位曲线 + this.handleWaterLeve(station.getCode(),hydropower); + // 年发电量完成百分比 + hydropower.setPowerYearMap(this.handlePowerFinish(station)); + // 设备信息 + hydropower.setDeviceList(this.getDevices(station,realList,targetList)); + return hydropower; + }).collect(Collectors.toList()); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java index decfe3d..1da8b9b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/SideHustleServiceImpl.java @@ -23,9 +23,9 @@ import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.duty.vo.DutyInfoVo; import com.hnac.hzims.operational.duty.vo.DutyTaskVo; import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.*; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; @@ -66,6 +66,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.stream.Collectors; +/** + * @author ysj + */ @Service @RequiredArgsConstructor @Slf4j @@ -308,13 +311,6 @@ public class SideHustleServiceImpl implements ISideHustleService { }}); List faultList = operPhenomenonEntityList.stream().map(OperPhenomenonEntity::getEmCode).distinct().collect(Collectors.toList()); deviceClassifyMap.put(HomePageConstant.FAULT,faultList); - // 保养 - /*List operMaintenanceTaskEntityList = operMaintenanceTaskService.list(new QueryWrapper() {{ - in("EM_CODE", deviceCodeList); - ne("STATUS", MaintenanceConstant.TASK_STATUS_5); - }}); - List maintainList = operMaintenanceTaskEntityList.stream().map(OperMaintenanceTaskEntity::getEmCode).collect(Collectors.toList()); - deviceClassifyMap.put(HomePageConstant.MAINTAIN,maintainList);*/ // 检修 List operAccessTaskEntityList = operAccessTaskService.list(new QueryWrapper() {{ in("EM_CODE", deviceCodeList); @@ -506,11 +502,11 @@ public class SideHustleServiceImpl implements ISideHustleService { areaDutyVo.setGeneratingCapacity(generatingCapacity); } - /** + /*** * 根据当班时间查询发电量 * @param devices - * @param startDate - * @param endDate + * @param start + * @param end * @return */ private float generateByDuty(List devices, Date start, Date end) { @@ -520,7 +516,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } for(EminfoAndEmParamVo device : devices ){ generate += analyseDataService.periodTargetFloat(DateUtil.format(start,DateUtil.PATTERN_DATETIME),DateUtil.format(end,DateUtil.PATTERN_DATETIME),3,5,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - }; + } return generate; } @@ -585,7 +581,7 @@ public class SideHustleServiceImpl implements ISideHustleService { dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE)); dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND)); return dateCal.getTime(); - }; + } /** * 获取结束时间 @@ -608,7 +604,7 @@ public class SideHustleServiceImpl implements ISideHustleService { dateCal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); dateCal.set(Calendar.SECOND, endCal.get(Calendar.SECOND)); return dateCal.getTime(); - }; + } /** * 当班运行数据 @@ -840,7 +836,7 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } Map> powerMap = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); - List monList = homePageService.getMonthList(0,12,false);; + List monList = homePageService.getMonthList(0,12,false); // 获取总发电量 float sumPower = this.getSumPower(map.values(),powerMap,monList); List list = new ArrayList<>(); @@ -854,7 +850,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } areaPowerScaleVo.setPower(power); // 发电量占比 - double scale = this.getPowerScale(power,sumPower);; + double scale = this.getPowerScale(power,sumPower); areaPowerScaleVo.setScale(scale); list.add(areaPowerScaleVo); }); @@ -874,7 +870,7 @@ public class SideHustleServiceImpl implements ISideHustleService { return null; } // 获取站点编码集合 - List codes = map.entrySet().stream().map(o-> o.getValue().get(0).getCode()).collect(Collectors.toList()); + List codes = map.values().stream().map(stationEntities -> stationEntities.get(0).getCode()).collect(Collectors.toList()); // 获取站点实时天气 Map nowWeather = this.weatherService.getNowWeather( codes); // 获取站点7日天气 @@ -974,7 +970,7 @@ public class SideHustleServiceImpl implements ISideHustleService { * @return */ private List getStationData() { - Map map = new HashMap<>(); + Map map; Object json = redisTemplate.opsForValue().get(station_data_key); if (ObjectUtil.isNotEmpty(json)) { map = JSONObject.parseObject(json.toString(), new TypeReference>() { @@ -1166,9 +1162,7 @@ public class SideHustleServiceImpl implements ISideHustleService { } List codeList = new ArrayList<>(); // 添加所有站点Code - map.values().forEach(item->{ - codeList.addAll(item.stream().map(StationEntity::getCode).collect(Collectors.toList())); - }); + map.values().forEach(item-> codeList.addAll(item.stream().map(StationEntity::getCode).collect(Collectors.toList()))); if(CollectionUtil.isEmpty(codeList)){ return null; } @@ -1214,7 +1208,6 @@ public class SideHustleServiceImpl implements ISideHustleService { return; } // 存放设备信息集合 - List deviceVoList = new ArrayList<>(); List equipmentCodeList = R.getData().stream().map(EmInfoEntity::getNumber).collect(Collectors.toList()); // 总数 @@ -1224,7 +1217,7 @@ public class SideHustleServiceImpl implements ISideHustleService { // 故障 List fault = this.handlerDeviceStatus(faultList,equipmentCodeList,"故障"); equipmentCountVo.setFaultCount((long) fault.size()); - deviceVoList.addAll(fault); + List deviceVoList = new ArrayList<>(fault); // 检修 List overhaul = this.handlerDeviceStatus(overhaultList,equipmentCodeList,"检修"); equipmentCountVo.setOverhaulCount((long) overhaul.size()); @@ -1266,7 +1259,7 @@ public class SideHustleServiceImpl implements ISideHustleService { if(CollectionUtil.isEmpty(statusList) || CollectionUtil.isEmpty(equipmentCodeList)){ return new ArrayList<>(); } - List statusDevice = statusList.stream().filter(o->equipmentCodeList.contains(o)).distinct().collect(Collectors.toList()); + List statusDevice = statusList.stream().filter(equipmentCodeList::contains).distinct().collect(Collectors.toList()); if(CollectionUtil.isEmpty(statusDevice)){ return new ArrayList<>(); } @@ -1340,37 +1333,6 @@ public class SideHustleServiceImpl implements ISideHustleService { } /** - * 递归查询子站点 - * - * @param departList - * @param parentPart - * @param list - * @return - */ - private List getAreaStation(List departList, Dept parentPart, List list) { - departList.forEach(dept -> { - if (dept.getParentId().equals(parentPart.getId())) { - // FIXME 是否只需要添加站点 - if (dept.getDeptCategory().equals(4)) { - list.add(dept); - } - getAreaStation(departList, dept, list); - } - }); - if(CollectionUtil.isEmpty(list)){ - return null; - } - List deptList = list.stream().map(Dept::getId).collect(Collectors.toList()); - List stationList = this.getStation(Collections.singletonList(HomePageConstant.HYDROPOWER), deptList); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - return list.stream().filter(o->refDeptList.contains(o.getId())).collect(Collectors.toList()); - } - - - /** * 区域机构下是否存在水电站 * @param deptAuthList * @param area diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java index a27d3fa..76f664a 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java @@ -100,41 +100,42 @@ public class WaterServiceImpl implements IWaterService { */ @Override public void loadWaterPumpReal(String param) { - // 有效设备 - List valid = this.getValidDeviceList(); - if(CollectionUtil.isEmpty(valid)){ + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ return; } // 实时数据 Map map = this.getRealMap(); - List list = new ArrayList<>(); - valid.forEach(device->{ - WaterPumpRealVo waterPumpRealVo = new WaterPumpRealVo(); - waterPumpRealVo.setDeptId(device.getCreateDept()); - waterPumpRealVo.setDeviceCode(device.getEmCode()); - waterPumpRealVo.setDeptName(device.getName()); + List list = devices.stream().map(device->{ + WaterPumpRealVo real = new WaterPumpRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); // 装机容量 - waterPumpRealVo.setInstalledCapacity(device.getInstalledCapacity()); + real.setInstalledCapacity(device.getInstalledCapacity()); // 开机状态 - int state = this.getPumpState(device,map); - waterPumpRealVo.setState(state); + real.setState(this.getPumpState(device,map)); // 功率因数 - double powerFactor = this.getPowerFactor(device,map); - waterPumpRealVo.setPowerFactor(powerFactor); + real.setPowerFactor(this.getPowerFactor(device,map)); // 有功功率 - float activePower = this.getActivePower(device,map); - waterPumpRealVo.setActivePower(activePower); + real.setActivePower(this.getActivePower(device,map)); // 无功功率 - float reactivePower = this.getReactivePower(device,map); - waterPumpRealVo.setReactivePower(reactivePower); + real.setReactivePower(this.getReactivePower(device,map)); // 电压 - double voltage = this.getVoltage(device,map); - waterPumpRealVo.setVoltage(voltage); + real.setVoltage(this.getVoltage(device,map)); // 电流 - double current = this.getCurrent(device,map); - waterPumpRealVo.setCurrent(current); - list.add(waterPumpRealVo); - }); + real.setCurrent(this.getCurrent(device,map)); + return real; + }).collect(Collectors.toList()); redisTemplate.opsForValue().set(loadwaterpump_real_key,list); } @@ -144,50 +145,47 @@ public class WaterServiceImpl implements IWaterService { */ @Override public void loadWaterPumpTarget(String param) { - List valid = this.getValidDeviceList(); - List list = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(valid)){ - valid.forEach(device->{ - WaterPumpTargetVo waterPumpTargetVo = new WaterPumpTargetVo(); - waterPumpTargetVo.setDeptId(device.getCreateDept()); - waterPumpTargetVo.setDeviceCode(device.getEmCode()); - waterPumpTargetVo.setDeptName(device.getName()); + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + // 补充站点填报发电量 + List list = this.useFill(stations); + // 站点设备数据统计 + if(CollectionUtil.isNotEmpty(devices)){ + list.addAll(devices.stream().map(device->{ + WaterPumpTargetVo target = new WaterPumpTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeptName(device.getName()); // 当年用电量 - float usrPowerYear = this.getUsrPowerYear(device); - waterPumpTargetVo.setUsrPowerYear(usrPowerYear); + target.setUsrPowerYear(this.getUsrPowerYear(device)); // 当月用电量 - float usrPowerMon = this.getUsrPowerMon(device); - waterPumpTargetVo.setUsrPowerMon(usrPowerMon); + target.setUsrPowerMon(this.getUsrPowerMon(device)); // 当日用电量 - float usrPowerDay = this.getUsrPowerDay(device); - waterPumpTargetVo.setUsrPowerDay(usrPowerDay); + target.setUsrPowerDay(this.getUsrPowerDay(device)); + // 当日机组有功功率 + target.setActivePowerVoList(this.getActivePowerVoList(device)); + // 近30天用电量 + target.setUsrPowerVoList(this.getUsrPowerVoList(device)); + // 近3年用电量 + target.setUsrYearMap(this.getUsrYearMap(device)); // 月运行次数、时长 WaterRunVo runMon = this.getRunData(device,1); - waterPumpTargetVo.setRunCountMon(runMon.getCount()); - waterPumpTargetVo.setRunDurationMon(runMon.getHour()); + target.setRunCountMon(runMon.getCount()); + target.setRunDurationMon(runMon.getHour()); // 年运行次数、时长 WaterRunVo runYear = this.getRunData(device,0); - waterPumpTargetVo.setRunCountYear(runYear.getCount()); - waterPumpTargetVo.setRunDurationYear(runYear.getHour()); - // 当日机组有功功率 - List activePowerVoList = this.getActivePowerVoList(device); - waterPumpTargetVo.setActivePowerVoList(activePowerVoList); - // 近30天用电量 - List usrPowerVoList = this.getUsrPowerVoList(device); - waterPumpTargetVo.setUsrPowerVoList(usrPowerVoList); - // 近3年用电量 - Map usrYearMap = this.getUsrYearMap(device); - waterPumpTargetVo.setUsrYearMap(usrYearMap); - list.add(waterPumpTargetVo); - }); - } - // 补充站点填报发电量 - List stations = stationService.list(Wrappers.lambdaQuery() - .in(StationEntity::getType, HomePageConstant.waterList) - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) - ); - if(CollectionUtil.isNotEmpty(stations)){ - list.addAll(this.useFill(stations)); + target.setRunCountYear(runYear.getCount()); + target.setRunDurationYear(runYear.getHour()); + return target; + }).collect(Collectors.toList())); } redisTemplate.opsForValue().set(loadwaterpump_target_key,list); } @@ -234,22 +232,19 @@ public class WaterServiceImpl implements IWaterService { } /** - * 获取监测点位是否配置 - * @param instanceCode + * 泵站设备 + * @param stations * @return */ - private boolean getSetting(String instanceCode) { - // 获取设备监测点位:未配置监测点位不进行统计设备 - List list = new ArrayList<>(); - MultiAnalyzeCodePO po = new MultiAnalyzeCodePO(); - po.setDeviceCode(instanceCode); - po.setSignages(Collections.singletonList(HomePageConstant.FRONT_WATER_LEVEL)); - list.add(po); - R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return true; + private List pumpDevices(List stations){ + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); } - return false; + List devices = maintenanceTaskService.getEmInfoList(); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); } /** @@ -264,7 +259,7 @@ public class WaterServiceImpl implements IWaterService { List signages = Collections.singletonList(signage); realData.setSignages(signages); // 调用fegin接口查询实时数据 - R> R = null; + R> R; try { R = analyseDataSearchClient.getRealDataByAnalyzeCode(realData); } catch (Exception e) { @@ -333,29 +328,6 @@ public class WaterServiceImpl implements IWaterService { } /** - * 获取有效设备 - * @return - */ - private List getValidDeviceList() { - // 水利站点(All) - List stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, HomePageConstant.waterList, null); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 获取所有设备 - List deviceList = maintenanceTaskService.getEmInfoList(); - if(CollectionUtil.isEmpty(deviceList)){ - return null; - } - // 有效泵租设备 - List deptIdList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptIdList)){ - return null; - } - return deviceList.stream().filter(o->deptIdList.contains(o.getCreateDept())).collect(Collectors.toList()); - } - - /** * 获取有效站点模型 * @return */ @@ -793,7 +765,7 @@ public class WaterServiceImpl implements IWaterService { PowerMonthVo generate = new PowerMonthVo(); Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); generate.setStrMonth(DateUtil.format(time, DateUtil.PATTERN_DATE)); - generate.setPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); return generate; }).collect(Collectors.toMap(PowerMonthVo::getStrMonth,PowerMonthVo::getPower)); } @@ -809,8 +781,6 @@ public class WaterServiceImpl implements IWaterService { String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); String year = String.valueOf(calendar.get(Calendar.YEAR)); - //calendar.add(Calendar.DAY_OF_MONTH,-1); - //String yesterday = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); return stations.stream().map(station ->{ WaterPumpTargetVo target = new WaterPumpTargetVo(); target.setDeptId(station.getRefDept()); @@ -929,7 +899,7 @@ public class WaterServiceImpl implements IWaterService { return null; } // 获取站点编码集合 - List codes = map.entrySet().stream().map(o-> o.getValue().get(0).getCode()).collect(Collectors.toList()); + List codes = map.values().stream().map(stationEntities -> stationEntities.get(0).getCode()).collect(Collectors.toList()); // 获取实时天气 Map nowWeather = this.weatherService.getNowWeather(codes); // 获取七天天气 @@ -1018,7 +988,7 @@ public class WaterServiceImpl implements IWaterService { * @return */ private List getStationList(Map> map) { - return map.values().stream().collect(Collectors.toList()).get(0); + return new ArrayList<>(map.values()).get(0); } /** @@ -1102,7 +1072,7 @@ public class WaterServiceImpl implements IWaterService { if(CollectionUtil.isEmpty(stationList)){ return null; } - List codeList = stationList.stream().filter(o->StringUtil.isNotBlank(o.getCode())).map(StationEntity::getCode).collect(Collectors.toList()); + List codeList = stationList.stream().map(StationEntity::getCode).filter(StringUtil::isNotBlank).collect(Collectors.toList()); if(CollectionUtil.isEmpty(codeList)){ return null; } @@ -1331,12 +1301,12 @@ public class WaterServiceImpl implements IWaterService { response.setUsePowerMon((float) kwhMon); // 月运行时长 Optional waterPumpTargetVoOptional = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationMon)); - double monRunTime = waterPumpTargetVoOptional.isPresent() ? waterPumpTargetVoOptional.map(WaterPumpTargetVo::getRunDurationMon).orElse(0.0) : 0.0; + double monRunTime = waterPumpTargetVoOptional.map(WaterPumpTargetVo::getRunDurationMon).orElse(0.0); //double monRunTime = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationMon)).get().getRunDurationMon(); response.setRunDurationMon(monRunTime); // 年运行时长 Optional optionalWaterPumpTargetVo = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationYear)); - double yearRunTime = optionalWaterPumpTargetVo.isPresent() ? optionalWaterPumpTargetVo.map(WaterPumpTargetVo::getRunDurationYear).orElse(0.0) : 0.0; + double yearRunTime = optionalWaterPumpTargetVo.map(WaterPumpTargetVo::getRunDurationYear).orElse(0.0); //double yearRunTime = validTaget.stream().max(Comparator.comparing(WaterPumpTargetVo::getRunDurationYear)).get().getRunDurationYear(); response.setRunDurationYear(yearRunTime); // 水位曲线/年用电量 From 87a7c96f5446d5443341cf05deafd521c48dfff3 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 13 Apr 2023 16:41:58 +0800 Subject: [PATCH 7/7] =?UTF-8?q?#=E6=B0=B4=E7=94=B5=E7=AB=99=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=9C=88=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/main/vo/AreaMonthReportVo.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java index 0d7d77b..3d3894e 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/AreaMonthReportVo.java @@ -1,5 +1,7 @@ package com.hnac.hzims.operational.main.vo; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -10,65 +12,85 @@ import lombok.Data; public class AreaMonthReportVo { @ApiModelProperty(value = "区域Id") + @JsonSerialize(nullsUsing = NullSerializer.class) private Long areaId; @ApiModelProperty(value = "区域名称") private String areaName; @ApiModelProperty(value = "计划发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float planPower; @ApiModelProperty(value = "实际发电量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Float actualPower; @ApiModelProperty(value = "发电完成率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double powerFinishRate; @ApiModelProperty(value = "同比") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double comparePowerRate; @ApiModelProperty(value = "发电计划预测") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double predictPlanPower; @ApiModelProperty(value = "操作票") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer operate; @ApiModelProperty(value = "操作票合格率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double operaQualifyRate; @ApiModelProperty(value = "工作票") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer work; @ApiModelProperty(value = "工作票合格率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double workQualifyRate; @ApiModelProperty(value = "日常维护") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer routineMaintenance; @ApiModelProperty(value = "巡检任务") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer inspect; @ApiModelProperty(value = "缺陷数") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer defect; @ApiModelProperty(value = "消缺率") + @JsonSerialize(nullsUsing = NullSerializer.class) private Double defectRate; @ApiModelProperty(value = "检修任务数量") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer maintenanceTasks; @ApiModelProperty(value = "安全生产会议次数") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer safetyMeeting; @ApiModelProperty(value = "月度自查报告") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer selfReport; @ApiModelProperty(value = "设备试验") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer deviceTry; @ApiModelProperty(value = "技能培训") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer skillTrainy; @ApiModelProperty(value = "安全大检查") + @JsonSerialize(nullsUsing = NullSerializer.class) private Integer securityCheck; }