diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java index 7d22c2e..4d5d095 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClient.java @@ -79,7 +79,7 @@ public interface IEmInfoClient { String GET_EM_INFO_TREE_BY_EM_CODE = API_PREFIX + "/getEmInfoTreeByEmCode"; String UPDATE_BY_EM_CODE = API_PREFIX + "/updateByEmCode"; String UPDATE_BATCH_EM_STATE = API_PREFIX + "/updateBachEmState"; - + String GET_CHILDREN_BY_EM_CODE = API_PREFIX + "/getChildrenByEmCode"; String GET_EM_CREATE_TABLE = API_PREFIX + "/getEmCreateTable"; @PostMapping(DETAIL) @@ -153,4 +153,12 @@ public interface IEmInfoClient { @PostMapping(GET_EM_CREATE_TABLE) List getEmCreateTable(@RequestParam("list") List tableNames); + + /** + * 获取设备下的子设备编号列表 + * @param emCode 设备编号 + * @return 子设备编号列表 + */ + @GetMapping(GET_CHILDREN_BY_EM_CODE) + R> getChildrenByEmCode(@RequestParam("emCode") String emCode); } diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java index f79cbfd..e8b0b95 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/feign/IEmInfoClientBack.java @@ -98,4 +98,9 @@ public class IEmInfoClientBack implements IEmInfoClient { public List getEmCreateTable(List tableNames) { return new ArrayList<>(); } + + @Override + public R> getChildrenByEmCode(String emCode) { + return R.fail("远程调用失败"); + } } diff --git a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java index fbe4fea..a6d0812 100644 --- a/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java +++ b/hzims-service-api/ticket-api/src/main/java/com/hnac/hzims/ticket/constants/TicketConstants.java @@ -169,7 +169,7 @@ public interface TicketConstants { } public static String getTicketNameByType(String type) { - Optional optional = Arrays.stream(WordFileNameEnum.values()).filter(e -> type.equals(e.getType())).findFirst(); + Optional optional = Arrays.stream(TicketTypeNameEnum.values()).filter(e -> type.equals(e.getType())).findFirst(); return optional.map(e -> e.fileName).orElse(null); } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java index 5d999c3..dd24111 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/feign/EmInfoClient.java @@ -3,19 +3,20 @@ package com.hnac.hzims.equipment.feign; 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.toolkit.Wrappers; +import com.google.common.collect.Lists; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.service.IEmInfoService; import com.hnac.hzims.equipment.vo.DeviceVO; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.system.vo.CreateTableVO; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.stream.Collectors; @RestController @@ -133,6 +134,16 @@ public class EmInfoClient implements IEmInfoClient { return service.getEmCreateTable(tableNames); } + @Override + public R> getChildrenByEmCode(@RequestParam String emCode) { + EmInfoEntity emInfo = service.getOne(Wrappers.lambdaQuery().eq(EmInfoEntity::getNumber, emCode)); + if(ObjectUtil.isEmpty(emInfo)) { + return R.data(Lists.newArrayList()); + } + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery().like(EmInfoEntity::getPath, emInfo.getPath()); + return R.data(service.list(wrapper).stream().map(EmInfoEntity::getNumber).distinct().collect(Collectors.toList())); + } + /** * * @param emCode diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java index 0d468b4..12726bd 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java @@ -599,14 +599,15 @@ public class EmInfoServiceImpl extends BaseServiceImpl Arrays.stream(path.split("/"))).distinct().collect(Collectors.toList()); emCodes.addAll(childrenEmCode); } + EmInfoEntity emInfo = this.getOne(Wrappers.lambdaQuery().eq(EmInfoEntity::getNumber, parentCode)); // 获取parentCode下的子设备集合 LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() - .eq(EmInfoEntity::getGpid, parentCode) + .eq(EmInfoEntity::getGpid, Optional.ofNullable(emInfo).map(EmInfoEntity::getId).orElse(0L)) .eq(EmInfoEntity::getDepartment,deptId); List emInfoList = this.list(queryWrapper); List result = emInfoList.stream().map(emInfoEntity -> { JSONObject object = JSONObject.parseObject(JSON.toJSONString(emInfoEntity)); - object.put("disabled", emCodes.contains(emInfoEntity.getNumber()) ? true : false); + object.put("disabled", emCodes.contains(emInfoEntity.getNumber()) ? false : true); return object; }).collect(Collectors.toList()); return result; diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java index 2e97031..0614870 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/services/impl/ObjectServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.google.zxing.BarcodeFormat; +import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzinfo.inspect.Constants; import com.hnac.hzinfo.inspect.obj.ObjectConstants; import com.hnac.hzinfo.inspect.obj.entity.*; @@ -58,6 +59,8 @@ public class ObjectServiceImpl extends BaseServiceImpl emCodeList = Func.toStrList(",", object.getEmCodes()); - Function getTemplateProjectByEmCode = index -> { + Function getTemplateProjectByEmCode = emCode -> { ProjectEntity project = new ProjectEntity(); - project.setEmCode(emCodeList.get(index)); + project.setEmCode(emCode); project.setStatus(ObjectConstants.ProjectEnableEnum.YES.getEnableType()); ProjectEntity one = projectService.getOne(project); - return TemplateProjectEntity.builder().templateId(template.getId()).projectId(one.getId()).sort(index).build(); + return TemplateProjectEntity.builder().templateId(template.getId()).projectId(one.getId()).build(); }; List templateProjectList = Stream.iterate(0,n -> n + 1).limit(emCodeList.size()) - .map(getTemplateProjectByEmCode).collect(Collectors.toList()); + .flatMap(index -> emInfoClient.getChildrenByEmCode(emCodeList.get(index)).getData().stream()).map(getTemplateProjectByEmCode).collect(Collectors.toList()); templateProjectService.saveBatch(templateProjectList); } } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java index b3e8b1a..3d2a9a3 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/config/ThreadPoolConfig.java @@ -25,6 +25,6 @@ public class ThreadPoolConfig { @Bean public ExecutorService appMessagePushExecutor() { - return new ThreadPoolExecutor(2, 5, 5L, TimeUnit.SECONDS,new LinkedBlockingQueue()); + return new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS,new LinkedBlockingQueue()); } } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java index c5c3958..560bbcc 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java @@ -51,7 +51,7 @@ public class MessagePushRecordController extends BladeController { @ApiOperation("查询消息推送记录列表") @ApiOperationSupport(order = 3) public R> list(MessagePushRecordEntity request) { - return R.data(messagePushRecordService.list(request)); + return R.data(messagePushRecordService.listNoUserScope(request)); } @GetMapping("/listPage") @@ -62,7 +62,7 @@ public class MessagePushRecordController extends BladeController { title = "消息管理", operatorType = OperatorType.MOBILE, businessType = BusinessType.GENCODE, action = "分页查询消息推送记录列表") public R> listPage(MessagePushRecordEntity request, Query query) { - return R.data(messagePushRecordService.listPage(request, query)); + return R.data(messagePushRecordService.listPageNoUserScope(request, query)); } @GetMapping("/send/{id}") diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java index 56a2974..94a1d31 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java @@ -22,6 +22,13 @@ public interface IMessagePushRecordService extends BaseService list(MessagePushRecordEntity request); /** + * 查询消息推送记录列表 - 无数据权限 + * @param request + * @return + */ + List listNoUserScope(MessagePushRecordEntity request); + + /** * 分页查询消息推送记录列表 * @param request 查询条件 * @param query 分页 @@ -29,6 +36,14 @@ public interface IMessagePushRecordService extends BaseService listPage(MessagePushRecordEntity request, Query query); + /** + * 分页查询消息推送记录列表 - 无数据权限 + * @param request 查询条件 + * @param query 分页 + * @return 消息记录列表 + */ + IPage listPageNoUserScope(MessagePushRecordEntity request, Query query); + /** @Author hx * @Description 根据ID发送短信 * @Date 2023/4/4 17:37 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 909b955..cbc3f0c 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 @@ -57,10 +57,20 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl listNoUserScope(MessagePushRecordEntity request) { + return noAurhScopeMapper.selectList(this.getQueryWrapper(request)); + } + + @Override public IPage listPage(MessagePushRecordEntity request, Query query) { return this.page(Condition.getPage(query), this.getQueryWrapper(request)); } + @Override + public IPage listPageNoUserScope(MessagePushRecordEntity request, Query query) { + return noAurhScopeMapper.selectPage(Condition.getPage(query), this.getQueryWrapper(request)); + } + /** * @return java.lang.Boolean 推送结果 * @Author hx diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java index f9a3356..a86b507 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java @@ -1,7 +1,9 @@ package com.hnac.hzims.operational.config.controller; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.operational.config.service.CentralMonitorService; +import com.hnac.hzims.operational.config.vo.PointDataVo; import com.hnac.hzims.operational.station.service.IRealMonitorService; import com.hnac.hzims.operational.main.vo.RealStationVo; import com.hnac.hzinfo.datasearch.PointData; @@ -57,7 +59,7 @@ public class CentralMonitorController extends BladeController { public R selectCommunication(@PathVariable Integer page, @PathVariable Integer size, String roleId){ - HzPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId); + IPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId); return R.data(result); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java index cceb159..887026e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java @@ -1,6 +1,8 @@ package com.hnac.hzims.operational.config.service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.config.vo.PointDataVo; import com.hnac.hzims.operational.main.vo.RealStationVo; import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.sdk.core.response.HzPage; @@ -26,6 +28,6 @@ public interface CentralMonitorService{ * @param roleId * @return */ - HzPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId); + IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index 8d0afa6..7d9bc9b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -1,10 +1,14 @@ package com.hnac.hzims.operational.config.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hnac.hzims.operational.config.service.CentralMonitorService; +import com.hnac.hzims.operational.config.vo.PointDataVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.main.vo.RealStationVo; +import com.hnac.hzims.operational.ticket.fegin.StationFeginService; import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; @@ -12,12 +16,15 @@ import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -81,24 +88,38 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { * @return */ @Override - public HzPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId) { + public IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId) { OriginalDataQuery originalDataQuery = new OriginalDataQuery(); originalDataQuery.setRealId(roleId); originalDataQuery.setLimit(size); - LocalDateTime startTime = LocalDateTime.now(); - LocalDateTime endTime = startTime.minusHours(1); + LocalDateTime endTime = LocalDateTime.now(); + LocalDateTime startTime = endTime.minusHours(1); originalDataQuery.setBeginTime(this.getOriginalDate(startTime)); originalDataQuery.setEndTime(this.getOriginalDate(endTime)); Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); if (!originalDataByRealIds.isSuccess()) { - throw new IllegalArgumentException("数据不存在"); + throw new ServiceException("数据不存在"); } - return originalDataByRealIds.getData(); + HzPage data = originalDataByRealIds.getData(); + List collect = data.getRecords().stream().map(item -> { + PointDataVo pointDataVo = new PointDataVo(); + BeanUtils.copyProperties(item, pointDataVo); + //通过站点id获取站点名称 + String station = pointDataVo.getStation(); + String stationName = stationService.selectStationById(station); + pointDataVo.setStationName(stationName); + return pointDataVo; + }).collect(Collectors.toList()); + + IPage iPage = new Page(data.getCurrent(), data.getSize()); + iPage.setRecords(collect); + return iPage; } /** * LocalDateTime 转 date + * * @param localDateTime * @return */ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/vo/PointDataVo.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/vo/PointDataVo.java new file mode 100644 index 0000000..444da82 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/vo/PointDataVo.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.operational.config.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +/** + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/8/1 10:37 + */ +@Data +public class PointDataVo { + + /** + * 站点id + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + private String station; + + + /** + * 站点名称 + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + private String stationName; + /** + * 数据采集时间 + */ + private String time; + /** + * 数据 + */ + private String value; + /** + * 质量值 + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer q; + + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private String signage; + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/BarChartDemo.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/BarChartDemo.java deleted file mode 100644 index 85747a3..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/BarChartDemo.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.hnac.hzims.operational.data.controller; - -import java.awt.*; -import java.io.FileOutputStream; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; - -import com.hnac.hzims.operational.report.vo.TicketChartCell; -import com.hnac.hzims.operational.report.vo.TicketChartVo; -import com.hnac.hzims.ticket.constants.TicketConstants; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartFrame; -import org.jfree.chart.ChartUtils; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.BarRenderer; -import org.jfree.chart.renderer.category.StandardBarPainter; -import org.jfree.chart.title.TextTitle; -import org.jfree.data.category.CategoryDataset; -import org.jfree.data.category.DefaultCategoryDataset; - -public class BarChartDemo { -// public static void main(String[] args) { -// // 1. 得到数据 -// CategoryDataset dataset = getDataSetTicket(); -//// CategoryDataset dataset = getDataSet(); -//// CategoryDataset dataset = getDataSet3(); -// // 2. 构造chart -// JFreeChart chart = ChartFactory.createBarChart( -// "水果产量图", // 图表标题 -// "水果", // 目录轴的显示标签--横轴 -// "产量", // 数值轴的显示标签--纵轴 -// dataset, // 数据集 -// PlotOrientation.VERTICAL, // 图表方向:水平、 -// true, // 是否显示图例(对于简单的柱状图必须 -// false, // 是否生成工具 -// false // 是否生成URL链接 -// ); -// // 3. 处理chart中文显示问题 -// iSetBarChart(chart); -// -// // 4. chart输出图片 -//// writeChartAsImage(chart, "fruit.jpg"); -// writeChartAsImage(chart, "ticket.jpg"); -// -//// writeChartAsImage(chart, "fruit2.jpg"); -// -// // 5. chart 以swing形式输出 -// ChartFrame pieFrame = new ChartFrame("水果生产", chart); -// pieFrame.pack(); -// pieFrame.setVisible(true); -// -// } - - /** - * 获取一个演示用的组合数据集对象 - * - * @return - */ - private static CategoryDataset getDataSet() { - DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - dataset.addValue(100, "北京", "苹果"); - dataset.addValue(120, "上海", "苹果"); - dataset.addValue(160, "广州", "苹果"); - dataset.addValue(210, "北京", "梨子"); - dataset.addValue(220, "上海", "梨子"); - dataset.addValue(230, "广州", "梨子"); - dataset.addValue(330, "北京", "葡萄"); - dataset.addValue(340, "上海", "葡萄"); - dataset.addValue(340, "广州", "葡萄"); - dataset.addValue(420, "北京", "香蕉"); - dataset.addValue(430, "上海", "香蕉"); - dataset.addValue(400, "广州", "香蕉"); - dataset.addValue(510, "北京", "荔枝"); - dataset.addValue(530, "上海", "荔枝"); - dataset.addValue(510, "广州", "荔枝"); - return dataset; - } - - private static CategoryDataset getDataSet3() { - DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - dataset.addValue(100, "北京", "苹果"); - dataset.addValue(210, "北京", "梨子"); - dataset.addValue(330, "北京", "葡萄"); - dataset.addValue(420, "北京", "香蕉"); - dataset.addValue(510, "北京", "荔枝"); - return dataset; - } - - - private static CategoryDataset getDataSetTicket() { - List ticketList = new ArrayList<>(); - TicketConstants.TicketTypeNameEnum[] values = TicketConstants.TicketTypeNameEnum.values(); - TicketChartVo sum=new TicketChartVo(); - List sas = new ArrayList<>(); - sum.setDeptName("总计"); - for (TicketConstants.TicketTypeNameEnum value : values) { - TicketChartCell ticketChartCell = new TicketChartCell(); - ticketChartCell.setTicketType(value.getType()); - ticketChartCell.setTicketName(value.getFileName()); - Integer integer = Integer.valueOf(value.getType()); - ticketChartCell.setTicketMon(30+ integer); - BigDecimal d=BigDecimal.valueOf(integer).divide(BigDecimal.valueOf(100),2,BigDecimal.ROUND_UP); - ticketChartCell.setTicketMonPerc(0.3+ d.doubleValue()); - sas.add(ticketChartCell); - } - sum.setChartCells(sas); - ticketList.add(sum); - //两票柱状图数据 - // 创建数据 - DefaultCategoryDataset dataset = new DefaultCategoryDataset(); -// for (TicketChartVo chartVo : ticketList) { -// for (int i = 0; i < chartVo.getChartCells().size(); i++) { -// TicketChartCell ticketChartCell = chartVo.getChartCells().get(i); -// dataset.addValue(ticketChartCell.getTicketMon(), ticketChartCell.getTicketName(), ticketChartCell.getTicketName()); -// } -// } - - dataset.addValue(33+1, "", "倒闸操作票"); - dataset.addValue(33+2,"", "开机操作票"); - dataset.addValue(33+3,"", "停机操作票"); - dataset.addValue(33+4,"", "第一种工作票"); - dataset.addValue(33+5,"", "第二种工作票"); - dataset.addValue(33+6,"", "水力机械票"); - return dataset; - } - - /** - * 解决图表汉字显示问题 - * - * @param chart - */ - private static void processChart(JFreeChart chart) { - CategoryPlot plot = chart.getCategoryPlot(); - CategoryAxis domainAxis = plot.getDomainAxis(); - ValueAxis rAxis = plot.getRangeAxis(); - chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - TextTitle textTitle = chart.getTitle(); - textTitle.setFont(new Font("宋体", Font.PLAIN, 20)); - domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); - domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); - rAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); - rAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); - chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12)); - // renderer.setItemLabelGenerator(new LabelGenerator(0.0)); - // renderer.setItemLabelFont(new Font("宋体", Font.PLAIN, 12)); - // renderer.setItemLabelsVisible(true); - } - - /** - * 输出图片 - * - * @param chart - */ - private static void writeChartAsImage(JFreeChart chart, String fileName) { - FileOutputStream fos_jpg = null; - try { - fos_jpg = new FileOutputStream("D:\\test\\"+fileName); - ChartUtils.writeChartAsJPEG(fos_jpg, 1, chart, 400, 300, null); -// ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 400, 300, null); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - fos_jpg.close(); - } catch (Exception e) { - } - } - } - - - public static void iSetBarChart(JFreeChart chart) { - CategoryPlot categoryplot = chart.getCategoryPlot();// 图本身 - ValueAxis rangeAxis = categoryplot.getRangeAxis(); - CategoryAxis domainAxis = categoryplot.getDomainAxis(); - // 设置Y轴的提示文字样式 - rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); - // 设置Y轴刻度线的长度 - rangeAxis.setTickMarkInsideLength(10f); - - domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // 横轴上的 - domainAxis.setLowerMargin(0.1); - domainAxis.setUpperMargin(0.1); - - // rangeAxis.setTickMarkOutsideLength(10f); - // 设置X轴下的标签文字 - domainAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); - // 设置X轴上提示文字样式 - domainAxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); - NumberAxis vn = (NumberAxis) categoryplot.getRangeAxis(); - - // 设置Y轴的数字为百分比样式显示设置Y轴的数字为百分比样式显示 - DecimalFormat df = new DecimalFormat("0.0"); - vn.setNumberFormatOverride(df); - // 使柱状图反过来显示 - // vn.setInverted(true); - // vn.setVerticalTickLabels(true); - - // 自定义柱状图中柱子的样式 - CustomRenderer brender = new CustomRenderer(); - // 设置柱状图的顶端显示数字 - brender.setIncludeBaseInRange(true); - brender.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); - brender.setDefaultItemLabelsVisible(true); - // 设置柱子为平面图不是立体的 - brender.setBarPainter(new StandardBarPainter()); - // 设置柱状图之间的距离0.1代表10%; - brender.setItemMargin(0.3); - // 设置柱子的阴影,false代表没有阴影 - brender.setShadowVisible(false); - - // 设置图的背景为白色 - categoryplot.setBackgroundPaint(Color.WHITE); - // 设置背景虚线的颜色 - categoryplot.setRangeGridlinePaint(Color.decode("#B6A2DE")); - // 去掉柱状图的背景边框,使边框不可见 - categoryplot.setOutlineVisible(false); - // 设置标题的字体样式 - chart.getTitle().setFont(new Font("微软雅黑", Font.PLAIN, 24)); - // 设置图表下方图例上的字体样式 - chart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12)); - - categoryplot.setRenderer(brender); - - - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java index 6bcade8..38638c5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java @@ -14,6 +14,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.tool.api.R; @@ -22,8 +23,11 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; +import java.io.IOException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -121,14 +125,32 @@ public class AreaMonthReportController extends BladeController { public R exportHydropowerStationMonthReport(HttpServletResponse response, @ApiParam(value = "日期-年", required = true) Integer year,@ApiParam(value = "日期-月", required = true) Integer month, @ApiParam(value = "日期-日", required = true) Integer date,@ApiParam(value = "站点Id", required = true) Long stationId,@ApiParam(value = "月报类型", required = true) Long type) { + HashMap map = new HashMap<>(); if (type==1){ - HashMap map = new HashMap<>(); service.exportHydropowerStationMonthReport(response, map,year,month,date,stationId); - WordUtils.exportWord("template/waterMonV3.docx", "F:/", "生成月报.docx", map); //word模板相对路径、word生成路径、word生成的文件名称、数据源 - } + XWPFDocument xwpfDocument = WordUtils.exportWordV2("template/waterMonReport.docx", map); + // 下载导出 + String filename = "(" + year+"年"+month+"月"+ ")水电站月报"; + // 设置头信息 + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/vnd.ms-excel"); + ServletOutputStream outputStream = null; + try { + //设置xlsx格式 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".docx", "UTF-8")); + //创建一个输出流 + outputStream = response.getOutputStream(); - return R.success("测试成功"); + //写入数据 + xwpfDocument.write(outputStream); + // 关闭 + outputStream.close(); + xwpfDocument.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return R.data("导出成功"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java index dd80fb7..77f6308 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.main.service.impl; import cn.afterturn.easypoi.entity.ImageEntity; 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.entity.PlanGenerationEntity; import com.hnac.hzims.equipment.feign.IEmParamClient; import com.hnac.hzims.equipment.feign.IPlanGenertionClient; @@ -25,7 +26,6 @@ import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.util.JFreeUtil; import com.hnac.hzims.operational.util.TimeUtils; -import com.hnac.hzims.operational.util.WordUtils; import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; import com.hnac.hzims.safeproduct.feign.ISafeCheckClient; import com.hnac.hzims.safeproduct.feign.ISafeEquipmentTrialClient; @@ -69,6 +69,7 @@ import java.math.BigDecimal; import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -83,7 +84,7 @@ import java.util.stream.Collectors; */ @Service @RequiredArgsConstructor -public class AreaMonthReportServiceImpl implements IAreaMonthReportService { +public class AreaMonthReportServiceImpl implements IAreaMonthReportService { @NotNull private final IMainTaskStatisticService mainTaskStatisticService; @@ -119,8 +120,6 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { private final ISafeCheckClient safeCheckClient; - - @Value("${hzims.operation.area.report}") private String area_month_report_key; @@ -202,9 +201,12 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { } return R.data("success"); } - @Override public R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap map, Integer year, Integer month, Integer date, Long deptId) { + R> deptByCurrentUser = sysClient.getDeptByCurrentUser(); + if (!deptByCurrentUser.isSuccess()||deptByCurrentUser.getData()!=null){ + return R.fail("用户权限查询失败"); + } R deptNameR = sysClient.getDeptName(deptId); if (!deptNameR.isSuccess()) { return R.fail("暂无该机构"); @@ -218,7 +220,18 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { if (deptList == null) { return R.fail("该机构不包含水站信息"); } + List deptByUser = deptByCurrentUser.getData().stream().map(s -> s.getId()).collect(Collectors.toList()); + if (!deptByUser.contains(deptId)){ + return R.fail("该用户不包含该机构权限,请申请权限再试"); + } List deptIds = deptList.stream().map(s -> s.getId()).collect(Collectors.toList()); + List stationEntityList = stationService.list(Wrappers.lambdaQuery() + .in(StationEntity::getRefDept, deptIds) + .eq(StationEntity::getType, HomePageConstant.HYDROPOWER)); + Integer commissionTime = stationEntityList.stream().map(s -> { + Duration dur = Duration.between(s.getCommissionTime(), LocalDateTime.now()); + return (int) dur.toDays();}).reduce(Integer::max).get(); + List stationIds = stationEntityList.stream().map(s -> s.getId()).collect(Collectors.toList()); //其它普通数据 map.put("year", year); Integer yearBefore = year - 1; @@ -227,48 +240,40 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { Integer monthBefore = month - 1; map.put("monthBefore", monthBefore); map.put("date", date); - map.put("commissionTime", "commissionTime"); + map.put("commissionTime", commissionTime.toString()); map.put("stationName", deptName); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); + map.put("writeTime", simpleDateFormat.format(new Date())); + List> safelist=new ArrayList<>(); + List> form=new ArrayList<>(); + for (Dept dept : deptList) { + HashMap temp = new HashMap<>(); + HashMap temp2 = new HashMap<>(); + temp.put("name", dept.getDeptName()); + temp2.put("name", dept.getDeptName()); + safelist.add(temp); + form.add(temp2); + } + map.put("safelist",safelist); + map.put("form",form); + map.put("form2",form); // 今年年度 String yearStart = TimeUtils.getYear(year); - String yearEnd = TimeUtils.getYearEnd(year); String yearEndV2 = TimeUtils.getYearEndV2(year); - //去年年度 - String yearBeforeStart = TimeUtils.getYear(yearBefore); - String yearBeforeEnd = TimeUtils.getYearEnd(yearBefore); // 今年当月 String monthStart = TimeUtils.getMonthStart(year, month); - String monthEnd = TimeUtils.getMonthEnd(year, month); String monthEndV2 = TimeUtils.getMonthEndV2(year, month); - // 今年上个月 - String beforeMonthStart = TimeUtils.getMonthStart(year, monthBefore); - String beforeMonthEnd = TimeUtils.getMonthEnd(year, monthBefore); - // 去年当月 - String monthStartBeforeYear = TimeUtils.getMonthStart(yearBefore, month); - String monthEndBeforeYear = TimeUtils.getMonthEnd(yearBefore, month); - // 所有设备信息 - List devices = mainSystemMonitoringService.getEmInfoList(); List reals = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); -// R installedCapacityCountByDepts = emParamClient.getInstalledCapacityCountByDepts(deptIds); -// if (installedCapacityCountByDepts.isSuccess()){ -// double sum = Optional.ofNullable(installedCapacityCountByDepts.getData()) -// .orElse(new ArrayList<>()).stream() -// .filter(s -> s.getInstalledCapacity() != null) -// .mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum(); -// map.put("installedCapacity", 0); -// } -// List realsByDept = reals.stream().filter(s -> deptIds.contains(s.getDeptId())).collect(Collectors.toList()); -// TODO 伪造数据 - List realsByDept = reals.stream().filter(s -> deptIds.contains(s.getDeptId())).map(s->{s.setInstalledCapacity(3.2);return s;}).collect(Collectors.toList()); - + List realsByDept = reals.stream().filter(s -> deptIds.contains(s.getDeptId())).collect(Collectors.toList()); // 装机容量占比数据组装 //总容量 double sum = Optional.ofNullable(realsByDept) .orElse(new ArrayList<>()).stream() .filter(s -> s.getInstalledCapacity() != null) .mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum(); - map.put("installedCapacity", sum); + BigDecimal sumData=new BigDecimal(sum).divide(new BigDecimal(1000),2,BigDecimal.ROUND_UP); + map.put("installedCapacity", sumData); //各站点分组 Map> listMap = Optional.ofNullable(realsByDept) .orElse(new ArrayList<>()).stream() @@ -290,140 +295,97 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { ImageEntity capacityProportionChart = JFreeUtil.pieChartByDouble("水电项目装机容量占比图", capacityProportionMap, 500, 400); map.put("capacityProportionChart", capacityProportionChart); //各发电站发电量环比图+表格数据组装 + List deptIdsString = deptIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()); + List planYearData = planGenertionClient.getPlanGenerationByParam(null, deptIdsString, year.toString()); List powerPercentageVoList = new ArrayList<>(); - for (Dept dept : deptList) { - MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); - powerVo.setDeptId(dept.getId()); - powerVo.setDeptName(dept.getDeptName()); - BigDecimal powerYear = new BigDecimal(0); - BigDecimal powerYearBefore = new BigDecimal(0); - BigDecimal powerMonth = new BigDecimal(0); - BigDecimal powerMonthBefore = new BigDecimal(0); - BigDecimal powerMonthYearBefore = new BigDecimal(0); - Double planGeneration = 0d; -// todo shuju -// List planYearData = planGenertionClient.getPlanGenerationByParam(null, Arrays.asList(dept.getId().toString()), year.toString()); - PlanGenerationEntity planGenerationEntity=new PlanGenerationEntity(); - planGenerationEntity.setPlanGeneration(2f); - List planYearData =new ArrayList<>(); - planYearData.add(planGenerationEntity); - if (CollectionUtils.isNotEmpty(planYearData)) { - planGeneration = Double.valueOf(planYearData.get(0).getPlanGeneration()); - } - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(dept.getId())).collect(Collectors.toList()); - for (EminfoAndEmParamVo device : stationDevices) { + //水电站,光伏站和带代运维数据近三年数据 + Map> powerMapThree = (Map>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); + List listByYear = TimeUtils.getListByYear(year); + List listByYearBefore = TimeUtils.getListByYear(yearBefore); + String monStart = TimeUtils.getMon(year, month); + String monStartYearBefore = TimeUtils.getMon(yearBefore, month); + String monStartMonBefore = TimeUtils.getMon(year, monthBefore); + for (Map.Entry> deviceMap : powerMapThree.entrySet()) { + String deptNameByKey = ""; + if (stationIds.contains(deviceMap.getKey())) { + MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); + powerVo.setDeptId(deviceMap.getKey()); + List collect = stationEntityList.stream().filter(s -> deviceMap.getKey().equals(s.getId())).collect(Collectors.toList()); + if (collect!=null) { + Long dept = collect.get(0).getRefDept(); + List dep = deptList.stream().filter(s -> dept.equals(s.getId())).collect(Collectors.toList()); + deptNameByKey=dep.get(0).getDeptName(); + } + powerVo.setDeptName(deptNameByKey); + BigDecimal powerYear = new BigDecimal(0); + BigDecimal powerYearBefore = new BigDecimal(0); + BigDecimal powerMonth = new BigDecimal(0); + BigDecimal powerMonthBefore = new BigDecimal(0); + BigDecimal powerMonthYearBefore = new BigDecimal(0); + Double planGeneration = 0d; + List planGenerationById = planYearData.stream().filter(s -> collect.get(0).getRefDept().equals(s.getStationDeptId())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(planGenerationById)) { + planGeneration = Double.valueOf(planGenerationById.get(0).getPlanGeneration()); + } + //当前机构近三年的数据 + Map value = deviceMap.getValue(); //今年发电量 -// List analyseData = analyseDataService.periodTargetData(yearStart, yearEnd, 3, EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); - AnalyseDataTaosVO analyseData1=new AnalyseDataTaosVO(); - analyseData1.setVal("2"); - List analyseData =new ArrayList<>(); - analyseData.add(analyseData1); - // todo 数据还原 - if (CollectionUtil.isNotEmpty(analyseData)) { - BigDecimal yearPower = analyseData.stream().filter(ktv -> ktv.getVal() != null) - .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) - .reduce(BigDecimal.ZERO, BigDecimal::add); - powerYear = powerYear.add(yearPower); + powerYear=value.entrySet().stream().filter(s->listByYear.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + //转换单位kwh-》万Kwh + powerYear=powerYear.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerYearBefore=value.entrySet().stream().filter(s->listByYearBefore.contains(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerYearBefore=powerYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonth=value.entrySet().stream().filter(s->monStart.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonth=powerMonth.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonthBefore=value.entrySet().stream().filter(s->monStartMonBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthBefore=powerMonthBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerMonthYearBefore=value.entrySet().stream().filter(s->monStartYearBefore.equals(s.getKey())).map(s->BigDecimal.valueOf(s.getValue())).reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthYearBefore=powerMonthYearBefore.divide(new BigDecimal(10000),2,BigDecimal.ROUND_UP); + powerVo.setPowerYear(powerYear.doubleValue()); + powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); + BigDecimal yearPercentage = new BigDecimal(0); + BigDecimal planPercentage = new BigDecimal(0); + if (powerYearBefore.compareTo(BigDecimal.ZERO) != 0) { + yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); } - //去年发电量 -// List analyseDataYearBefore = analyseDataService.periodTargetData(yearBeforeStart, yearBeforeEnd, 3, EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); - AnalyseDataTaosVO analyseDataYearBefore1=new AnalyseDataTaosVO(); - analyseDataYearBefore1.setVal("16"); - List analyseDataYearBefore =new ArrayList<>(); - analyseDataYearBefore.add(analyseDataYearBefore1); - // todo 数据还原 - if (CollectionUtil.isNotEmpty(analyseDataYearBefore)) { - BigDecimal powerBefore = analyseDataYearBefore.stream().filter(ktv -> ktv.getVal() != null) - .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) - .reduce(BigDecimal.ZERO, BigDecimal::add); - powerYearBefore = powerYearBefore.add(powerBefore); + if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO) != 0) { + planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); } - //今年当月发电量 -// List analyseDataMonth = analyseDataService.periodTargetData(monthStart, monthEnd, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); - AnalyseDataTaosVO analyseDataMonth1=new AnalyseDataTaosVO(); - analyseDataMonth1.setVal("0.66"); - List analyseDataMonth =new ArrayList<>(); - analyseDataMonth.add(analyseDataMonth1); - // todo 数据还原 - if (CollectionUtil.isNotEmpty(analyseDataMonth)) { - BigDecimal powerBefore = analyseDataMonth.stream().filter(ktv -> ktv.getVal() != null) - .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) - .reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonth = powerMonth.add(powerBefore); + powerVo.setPlanPercentage(planPercentage.doubleValue()); + powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); + powerVo.setPowerMon(powerMonth.doubleValue()); + powerVo.setPowerMonBefore(powerMonthBefore.doubleValue()); + powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); + BigDecimal monPercentage = new BigDecimal(0); + if (powerMonthYearBefore.compareTo(BigDecimal.ZERO) != 0) { + monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); } - //上个月发电量 -// List analyseDataMonthBefore = analyseDataService.periodTargetData(beforeMonthStart, beforeMonthEnd, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); - AnalyseDataTaosVO analyseDataMonthBefore1=new AnalyseDataTaosVO(); - analyseDataMonthBefore1.setVal("0.56"); - List analyseDataMonthBefore =new ArrayList<>(); - analyseDataMonthBefore.add(analyseDataMonthBefore1); -// todo 数据还原 - if (CollectionUtil.isNotEmpty(analyseDataMonthBefore)) { - BigDecimal powerBefore = analyseDataMonthBefore.stream().filter(ktv -> ktv.getVal() != null) - .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) - .reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonthBefore = powerMonthBefore.add(powerBefore); - } - //去年当月发电量 -// List analyseDataMonthBeforeYear = analyseDataService.periodTargetData(monthStartBeforeYear, monthEndBeforeYear, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); - AnalyseDataTaosVO analyseDataMonthBeforeYear1=new AnalyseDataTaosVO(); - analyseDataMonthBeforeYear1.setVal("0.3"); - List analyseDataMonthBeforeYear =new ArrayList<>(); - analyseDataMonthBeforeYear.add(analyseDataMonthBeforeYear1); -// todo 数据还原 - if (CollectionUtil.isNotEmpty(analyseDataMonthBeforeYear)) { - BigDecimal powerBefore = analyseDataMonthBeforeYear.stream().filter(ktv -> ktv.getVal() != null) - .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) - .reduce(BigDecimal.ZERO, BigDecimal::add); - powerMonthYearBefore = powerMonthYearBefore.add(powerBefore); - } - } - powerVo.setPowerYear(powerYear.doubleValue()); - powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); - BigDecimal yearPercentage = new BigDecimal(0); - BigDecimal planPercentage = new BigDecimal(0); - if (powerYearBefore.compareTo(BigDecimal.ZERO)!=0) { - yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); - } - if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO)!=0) { - planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); - } - powerVo.setPlanPercentage(planPercentage.doubleValue()); - powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); - powerVo.setPowerMon(powerMonth.doubleValue()); - powerVo.setPowerMonBefore(powerMonthBefore.doubleValue()); - powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); - BigDecimal monPercentage = new BigDecimal(0); - if (powerMonthYearBefore.compareTo(BigDecimal.ZERO)!=0) { - monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); + powerVo.setPowerMonPercentage(monPercentage.doubleValue()); + powerPercentageVoList.add(powerVo); } - powerVo.setPowerMonPercentage(monPercentage.doubleValue()); - powerPercentageVoList.add(powerVo); } +// getPowerData(deptList, yearStart, yearEnd, yearBeforeStart, yearBeforeEnd, monthStart, monthEnd, beforeMonthStart, beforeMonthEnd, monthStartBeforeYear, monthEndBeforeYear, devices, planYearData, powerPercentageVoList); // 各发电站发电量环比图数据组装 - //柱状图图数据 // 创建数据 DefaultCategoryDataset powerDataset = new DefaultCategoryDataset(); for (MonPowerPercentageVo monPowerPercentageVo : powerPercentageVoList) { - powerDataset.addValue(monPowerPercentageVo.getPowerMonYearBefore(),monthBefore +"月", monPowerPercentageVo.getDeptName()); + powerDataset.addValue(monPowerPercentageVo.getPowerMonBefore(),monthBefore +"月", monPowerPercentageVo.getDeptName()); powerDataset.addValue(monPowerPercentageVo.getPowerMon(), month +"月", monPowerPercentageVo.getDeptName()); - } - String powerTitle=deptName+"水电运维项目各电站发电量环比对比图(万kWh)"; - String powerDomainAxis="发电量"; - String powerRangeAxis="站点名称"; - ImageEntity powerChainHistogram = JFreeUtil.iCreateBarChart( powerTitle, powerDomainAxis, powerRangeAxis, powerDataset, 500, 400); + String powerTitle = deptName + "水电运维项目各电站发电量环比对比图(万kWh)"; + String powerDomainAxis = "发电量"; + String powerRangeAxis = "站点名称"; + ImageEntity powerChainHistogram = JFreeUtil.iCreateBarChart(powerTitle, powerDomainAxis, powerRangeAxis, powerDataset, 500, 400); map.put("powerChainHistogram", powerChainHistogram); - //柱状图下的表格 + //柱状图下添加的表格 if (powerPercentageVoList != null) { ArrayList> powerMap = new ArrayList<>(powerPercentageVoList.size()); for (MonPowerPercentageVo monPowerPercentageVo : powerPercentageVoList) { HashMap power = new HashMap<>(); power.put("name", monPowerPercentageVo.getDeptName()); - power.put("monthBefore", String.valueOf(monPowerPercentageVo.getPowerMonBefore())); - power.put("month", String.valueOf(monPowerPercentageVo.getPowerMon())); + power.put("monthBefore", monPowerPercentageVo.getPowerMonBefore()+"MW"); + power.put("month",monPowerPercentageVo.getPowerMon()+"MW"); powerMap.add(power); } map.put("power", powerMap); @@ -440,11 +402,11 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { temp.put("name", monPowerPercentageVo.getDeptName()); temp.put("powerMonBefore", String.valueOf(monPowerPercentageVo.getPowerMonYearBefore())); temp.put("powerYearBefore", String.valueOf(monPowerPercentageVo.getPowerYearBefore())); - temp.put("mon",String.valueOf(monPowerPercentageVo.getPowerMon())); - temp.put("year",String.valueOf(monPowerPercentageVo.getPowerYear())); - temp.put("monPercentage", monPowerPercentageVo.getPowerMonPercentage()*100+"%"); - temp.put("yearPercentage", monPowerPercentageVo.getPowerYearPercentage()*100+"%"); - temp.put("plan",monPowerPercentageVo.getPlanPercentage()*100+"%"); + temp.put("mon", String.valueOf(monPowerPercentageVo.getPowerMon())); + temp.put("year", String.valueOf(monPowerPercentageVo.getPowerYear())); + temp.put("monPercentage", monPowerPercentageVo.getPowerMonPercentage() * 100 + "%"); + temp.put("yearPercentage", monPowerPercentageVo.getPowerYearPercentage() * 100 + "%"); + temp.put("plan", monPowerPercentageVo.getPlanPercentage() * 100 + "%"); list.add(temp); } map.put("powerGeneration", list); @@ -459,12 +421,14 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { wrapper.eq(OperPhenomenonEntity::getDiscriminateStatus, TreatMethodConstant.AUTO_SCREENED); wrapper.in(OperPhenomenonEntity::getCreateDept, deptIds); List monPhenomenonList = operPhenomenonService.list(wrapper); - monPhenomenonList= monPhenomenonList.stream().filter(s -> s.getDefectLevel() != null).collect(Collectors.toList()); - List monConclusionList = monPhenomenonList.stream().filter(s -> s.getConclusionStatus().equals(1)).collect(Collectors.toList()); + monPhenomenonList = monPhenomenonList.stream().filter(s -> s.getDefectLevel() != null).collect(Collectors.toList()); + List monConclusionList = monPhenomenonList.stream().filter(s -> s.getConclusionStatus().equals("1")).collect(Collectors.toList()); +// 只填写二类及以上缺陷 + List monConclusionListBy = monConclusionList.stream().filter(s -> !s.getDefectGrading().equals("1")).collect(Collectors.toList()); // 各电站缺陷处理统计表 - monConclusionList.stream().sorted(Comparator.comparing(OperPhenomenonEntity::getDefectGrading).reversed().thenComparing(OperPhenomenonEntity::getCreateTime)); - ArrayList> checkList = new ArrayList<>(monConclusionList.size()); - for (OperPhenomenonEntity operPhenomenonEntity : monConclusionList) { + monConclusionListBy.stream().sorted(Comparator.comparing(OperPhenomenonEntity::getCreateDept).reversed().thenComparing(OperPhenomenonEntity::getDefectGrading)); + ArrayList> checkList = new ArrayList<>(); + for (OperPhenomenonEntity operPhenomenonEntity : monConclusionListBy) { Long createDept = operPhenomenonEntity.getCreateDept(); R createDeptName = sysClient.getDeptName(createDept); if (!createDeptName.isSuccess() && createDeptName.getData() != null) { @@ -473,9 +437,21 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //表格数据 HashMap temp = new HashMap<>(); temp.put("name", createDeptName.getData()); - temp.put("level", operPhenomenonEntity.getDefectGrading()); - temp.put("createTime", operPhenomenonEntity.getCreateTime().toString()); - temp.put("findTime", operPhenomenonEntity.getFindTime().toString()); + String checkLevel=""; + if(operPhenomenonEntity.getDefectGrading().equals("1")) { + checkLevel="Ⅰ级缺陷"; + } + if(operPhenomenonEntity.getDefectGrading().equals("2") ){ + checkLevel="Ⅱ级缺陷"; + } + if(operPhenomenonEntity.getDefectGrading().equals("3") ){ + checkLevel="Ⅲ级缺陷"; + } + temp.put("level", checkLevel); + String createTime= simpleDateFormat.format(operPhenomenonEntity.getCreateTime()); + temp.put("createTime", createTime); + String findTime= simpleDateFormat.format(operPhenomenonEntity.getFindTime()); + temp.put("findTime", findTime); temp.put("descripiton", operPhenomenonEntity.getDescripiton()); temp.put("disposeDesc", operPhenomenonEntity.getDisposeDesc()); checkList.add(temp); @@ -490,8 +466,8 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { wrapperYear.eq(OperPhenomenonEntity::getDiscriminateStatus, TreatMethodConstant.AUTO_SCREENED); wrapperYear.in(OperPhenomenonEntity::getCreateDept, deptIds); List yearPhenomenonEntities = operPhenomenonService.list(wrapperYear); - yearPhenomenonEntities= yearPhenomenonEntities.stream().filter(s ->StringUtil.isNotBlank(s.getDefectGrading())).filter(s -> ObjectUtil.isNotEmpty(s.getCreateDept())).collect(Collectors.toList()); - List yearConclusionList = yearPhenomenonEntities.stream().filter(s -> s.getConclusionStatus().equals(1)).collect(Collectors.toList()); + yearPhenomenonEntities = yearPhenomenonEntities.stream().filter(s -> StringUtil.isNotBlank(s.getDefectGrading())).filter(s -> ObjectUtil.isNotEmpty(s.getCreateDept())).collect(Collectors.toList()); + List yearConclusionList = yearPhenomenonEntities.stream().filter(s -> s.getConclusionStatus().equals("1")).collect(Collectors.toList()); ArrayList> checkStatistics = new ArrayList<>(); List checkChartRes = new ArrayList<>(); @@ -499,13 +475,13 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { //表格数据 HashMap temp = new HashMap<>(); temp.put("deptName", "总计"); - temp.put("checkLevel", "0"); + temp.put("checkLevel", "无等级"); temp.put("findShortagesMon", "0"); temp.put("shortagesMon", "0"); temp.put("findShortagesYear", "0"); temp.put("shortagesYear", "0"); - temp.put("shortagesRate", "0"); - checkList.add(temp); + temp.put("shortagesRate", "0%"); + checkStatistics.add(temp); map.put("checkStatistics", checkStatistics); } else { Map>> phenomenonMap = yearPhenomenonEntities.stream().collect( @@ -515,13 +491,13 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { R deptName1 = sysClient.getDeptName(deptMapEntry.getKey()); for (Map.Entry> levelList : deptMapEntry.getValue().entrySet()) { Integer findShortagesYear = levelList.getValue().size(); - Integer shortagesYear = yearConclusionList.stream().filter(s -> s.getDefectLevel().equals(deptMapEntry)).filter(s -> s.getDefectLevel().equals(deptMapEntry)).collect(Collectors.toList()).size(); + Integer shortagesYear = yearConclusionList.stream().filter(s -> s.getDefectGrading().equals(levelList.getKey())).collect(Collectors.toList()).size(); Double shortagesRate = 0d; if (findShortagesYear != 0 && shortagesYear != 0) { shortagesRate = BigDecimal.valueOf(shortagesYear).divide(BigDecimal.valueOf(findShortagesYear), 2, BigDecimal.ROUND_UP).doubleValue(); } - Integer findShortagesMon = Optional.ofNullable(monPhenomenonList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectLevel().equals(deptMapEntry)).filter(s -> s.getDefectLevel().equals(deptMapEntry)).collect(Collectors.toList()).size(); - Integer shortagesMon = Optional.ofNullable(monConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectLevel().equals(deptMapEntry)).filter(s -> s.getDefectLevel().equals(deptMapEntry)).collect(Collectors.toList()).size(); + Integer findShortagesMon = Optional.ofNullable(monPhenomenonList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectGrading().equals(levelList.getKey())).collect(Collectors.toList()).size(); + Integer shortagesMon = Optional.ofNullable(monConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectGrading().equals(levelList.getKey())).collect(Collectors.toList()).size(); CheckChartVo checkChartVo = new CheckChartVo(deptName1.getData(), levelList.getKey(), findShortagesMon, shortagesMon, findShortagesYear, shortagesYear, shortagesRate); checkChartRes.add(checkChartVo); } @@ -530,37 +506,41 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { Map> levelPhenomenonList = yearPhenomenonEntities.stream().collect(Collectors.groupingBy(OperPhenomenonEntity::getDefectGrading)); for (Map.Entry> levelPhenomenon : levelPhenomenonList.entrySet()) { Integer findShortagesYear = levelPhenomenon.getValue().size(); - Integer shortagesYear = Optional.ofNullable(yearConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectLevel().equals(levelPhenomenon)).collect(Collectors.toList()).size(); + Integer shortagesYear = Optional.ofNullable(yearConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectGrading().equals(levelPhenomenon.getKey())).collect(Collectors.toList()).size(); Double shortagesRate = 0d; if (findShortagesYear != 0 && shortagesYear != 0) { shortagesRate = BigDecimal.valueOf(shortagesYear).divide(BigDecimal.valueOf(findShortagesYear), 2, BigDecimal.ROUND_UP).doubleValue(); } - Integer findShortagesMon = Optional.ofNullable(monPhenomenonList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectLevel().equals(levelPhenomenon)).collect(Collectors.toList()).size(); - Integer shortagesMon = Optional.ofNullable(monConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectLevel().equals(levelPhenomenon)).collect(Collectors.toList()).size(); + Integer findShortagesMon = Optional.ofNullable(monPhenomenonList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectGrading().equals(levelPhenomenon.getKey())).collect(Collectors.toList()).size(); + Integer shortagesMon = Optional.ofNullable(monConclusionList).orElse(new ArrayList<>()).stream().filter(s -> s.getDefectGrading().equals(levelPhenomenon.getKey())).collect(Collectors.toList()).size(); CheckChartVo checkChartVo = new CheckChartVo("总计", levelPhenomenon.getKey(), findShortagesMon, shortagesMon, findShortagesYear, shortagesYear, shortagesRate); checkChartRes.add(checkChartVo); } + for (CheckChartVo checkChartRe : checkChartRes) { + //表格数据 + HashMap temp = new HashMap<>(); + temp.put("deptName", checkChartRe.getDeptName()); + String checkLevel=null; + if(checkChartRe.getCheckLevel().equals("1")) { + checkLevel="Ⅰ级缺陷"; + } + if(checkChartRe.getCheckLevel().equals("2")) { + checkLevel="Ⅱ级缺陷"; + } + if(checkChartRe.getCheckLevel().equals("3")) { + checkLevel="Ⅲ级缺陷"; + } + temp.put("checkLevel", checkLevel); + temp.put("findShortagesMon", checkChartRe.getFindShortagesMon().toString()); + temp.put("shortagesMon", checkChartRe.getShortagesMon().toString()); + temp.put("findShortagesYear", checkChartRe.getShortagesYear().toString()); + temp.put("shortagesYear", checkChartRe.getFindShortagesYear().toString()); + temp.put("shortagesRate", checkChartRe.getShortagesRate()* 100 + "%"); + checkStatistics.add(temp); + map.put("checkStatistics", checkStatistics); + } } - for (CheckChartVo checkChartRe : checkChartRes) { - //表格数据 - HashMap temp = new HashMap<>(); - temp.put("deptName", checkChartRe.getDeptName()); - temp.put("checkLevel", checkChartRe.getCheckLevel()); - temp.put("findShortagesMon",checkChartRe.getFindShortagesMon().toString()); - temp.put("shortagesMon",checkChartRe.getShortagesMon().toString()); - temp.put("findShortagesYear", checkChartRe.getShortagesYear().toString()); - temp.put("shortagesYear", checkChartRe.getFindShortagesYear().toString()); - temp.put("shortagesRate", checkChartRe.getShortagesRate().toString()); - checkList.add(temp); - map.put("checkStatistics", checkStatistics); - } - - -// if (CollectionUtils.isNotEmpty(ticketNumbers)) { -// String percent = PercentCountUtils.getPercent(evaluateEntities.size(), ticketNumbers.size()); -// ticketCount.setPercentPassTicket(percent); -// } // 两票执行情况 R> yearTicket = ticketInfoClient.getWorkTicketByTime(yearStart, yearEndV2); R> yearOperateTicket = ticketInfoClient.getOperateTicketByTime(yearStart, yearEndV2); @@ -572,7 +552,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { List ticketList = new ArrayList<>(); for (Dept dept : deptList) { String stationId = dept.getStationId(); - if (stationId==null){ + if (stationId == null) { continue; } TicketChartVo chartVo = new TicketChartVo(); @@ -582,61 +562,61 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { TicketChartCell ticketChartCell = new TicketChartCell(); ticketChartCell.setTicketType(value.getType()); ticketChartCell.setTicketName(value.getFileName()); - if (value.getTicketType()==2){ + if (value.getTicketType() == 2) { List yearTicketCollect = Optional.ofNullable(yearTicket.getData()).orElse(new ArrayList<>()).stream() - .filter(s ->stationId.equals(s.getSignageCode())) + .filter(s -> stationId.equals(s.getSignageCode())) .filter(s -> s.getType().equals(value.getType())).collect(Collectors.toList()); List monthTicketCollect = Optional.ofNullable(monthTicket.getData()).orElse(new ArrayList<>()).stream() .filter(s -> s.getSignageCode().equals(stationId)) .filter(s -> s.getType().equals(value.getType())).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(yearTicketCollect)){ + if (CollectionUtils.isNotEmpty(yearTicketCollect)) { //年合格率和数量 Integer count = yearTicketCollect.size(); ticketChartCell.setTicketYear(count); List ticketIds = yearTicketCollect.stream().map(s -> s.getId()).collect(Collectors.toList()); R ticketPassCount = ticketInfoClient.getTicketPassByIds(ticketIds); - if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null&&count!=0) { + if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null && count != 0) { Double ticketYearPerc = BigDecimal.valueOf(ticketPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketYeaPercr(ticketYearPerc); } } - if (CollectionUtils.isNotEmpty(monthTicketCollect)){ + if (CollectionUtils.isNotEmpty(monthTicketCollect)) { //月合格率和数量 Integer count = monthTicketCollect.size(); ticketChartCell.setTicketMon(count); List monthTicketIds = monthTicketCollect.stream().map(s -> s.getId()).collect(Collectors.toList()); R ticketMonthPassCount = ticketInfoClient.getTicketPassByIds(monthTicketIds); - if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null&&count!=0) { + if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null && count != 0) { Double ticketMonthPerc = BigDecimal.valueOf(ticketMonthPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketMonPerc(ticketMonthPerc); } } } - if (value.getTicketType()==1){ + if (value.getTicketType() == 1) { List yearOperateCollect = Optional.ofNullable(yearOperateTicket.getData()).orElse(new ArrayList<>()).stream() - .filter(s ->stationId.equals(s.getSignageCode())) + .filter(s -> stationId.equals(s.getSignageCode())) .filter(s -> s.getTicketType().equals(value.getType())).collect(Collectors.toList()); List monthOperateCollect = Optional.ofNullable(monthOperateTicket.getData()).orElse(new ArrayList<>()).stream() .filter(s -> s.getSignageCode().equals(stationId)) .filter(s -> s.getTicketType().equals(value.getType())).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(yearOperateCollect)){ + if (CollectionUtils.isNotEmpty(yearOperateCollect)) { //年合格率和数量 Integer count = yearOperateCollect.size(); ticketChartCell.setTicketYear(count); List ticketIds = yearOperateCollect.stream().map(s -> s.getId()).collect(Collectors.toList()); R ticketPassCount = ticketInfoClient.getTicketPassByIds(ticketIds); - if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null&&count!=0) { + if (ticketPassCount.isSuccess() && ticketPassCount.getData() != null && count != 0) { Double ticketYearPerc = BigDecimal.valueOf(ticketPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketYeaPercr(ticketYearPerc); } } - if (CollectionUtils.isNotEmpty(monthOperateCollect)){ + if (CollectionUtils.isNotEmpty(monthOperateCollect)) { //月合格率和数量 Integer count = monthOperateCollect.size(); ticketChartCell.setTicketMon(count); List monthTicketIds = monthOperateCollect.stream().map(s -> s.getId()).collect(Collectors.toList()); R ticketMonthPassCount = ticketInfoClient.getTicketPassByIds(monthTicketIds); - if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null&&count!=0) { + if (ticketMonthPassCount.isSuccess() && ticketMonthPassCount.getData() != null && count != 0) { Double ticketMonthPerc = BigDecimal.valueOf(ticketMonthPassCount.getData()).divide(BigDecimal.valueOf(count), 2, BigDecimal.ROUND_UP).doubleValue(); ticketChartCell.setTicketMonPerc(ticketMonthPerc); } @@ -647,11 +627,14 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { chartVo.setChartCells(cellList); ticketList.add(chartVo); } - List sumCollect=new ArrayList<>(); - ticketList.stream().map(s -> sumCollect.addAll(s.getChartCells())); - Map> groupingCollect = sumCollect.stream().collect(Collectors.groupingBy(TicketChartCell::getTicketType)); + List allCollect = new ArrayList<>(); + List sumCollect = new ArrayList<>(); + for (TicketChartVo ticketChartVo : ticketList) { + allCollect.addAll( ticketChartVo.getChartCells()); + } + Map> groupingCollect = allCollect.stream().collect(Collectors.groupingBy(TicketChartCell::getTicketType)); for (Map.Entry> mapTicketChart : groupingCollect.entrySet()) { - TicketChartCell sumCell=new TicketChartCell(); + TicketChartCell sumCell = new TicketChartCell(); sumCell.setTicketType(mapTicketChart.getKey()); sumCell.setTicketName(TicketConstants.TicketTypeNameEnum.getTicketNameByType(mapTicketChart.getKey())); List ticketChartValue = mapTicketChart.getValue(); @@ -661,72 +644,132 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { sumCell.setTicketYeaPercr(ticketChartValue.stream().mapToDouble(TicketChartCell::getTicketYeaPercr).sum()); sumCollect.add(sumCell); } - TicketChartVo ticketChartVo=new TicketChartVo(); + TicketChartVo ticketChartVo = new TicketChartVo(); ticketChartVo.setDeptName("总计"); ticketChartVo.setChartCells(sumCollect); - + ticketList.add(ticketChartVo); +// 两票排序 + ticketList.sort(Comparator.comparing(TicketChartVo::getDeptName,Comparator.reverseOrder())); //两票表格数据 ArrayList> ticketListRes = new ArrayList<>(); for (TicketChartVo chartVo : ticketList) { HashMap ticketMap = new HashMap<>(); + HashMap ticketMap2 = new HashMap<>(); for (TicketChartCell chartCell : chartVo.getChartCells()) { String ticketType = chartCell.getTicketType(); - ticketMap.put("deptName",chartVo.getDeptName()); - ticketMap.put("info","执行"); - ticketMap.put("infoPass","合格率"); - ticketMap.put("ticketMon"+ticketType,String.valueOf(chartCell.getTicketMon())); - ticketMap.put("ticketYear"+ticketType,String.valueOf(chartCell.getTicketYear())); - ticketMap.put("ticketMonPerc"+ticketType,String.valueOf(chartCell.getTicketMonPerc())); - ticketMap.put("ticketYeaPercr"+ticketType,String.valueOf(chartCell.getTicketYeaPercr())); + ticketMap.put("deptName", chartVo.getDeptName()); + ticketMap2.put("deptName", chartVo.getDeptName()); + ticketMap.put("info", "执行"); + ticketMap2.put("info", "合格率"); + ticketMap.put("ticketMon" + ticketType, String.valueOf(chartCell.getTicketMon())); + ticketMap.put("ticketYear" + ticketType, String.valueOf(chartCell.getTicketYear())); + ticketMap2.put("ticketMon" + ticketType, chartCell.getTicketMonPerc()* 100 + "%"); + ticketMap2.put("ticketYear" + ticketType, chartCell.getTicketYeaPercr()* 100 + "%"); } ticketListRes.add(ticketMap); + ticketListRes.add(ticketMap2); } + ticketListRes.sort(Comparator.comparing(o -> o.get("deptName"))); map.put("ticketList", ticketListRes); //两票柱状图数据 - // 创建数据 + // 创建柱状和折线数据库 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - for (TicketChartVo chartVo : ticketList) { - for (int i = 0; i < chartVo.getChartCells().size(); i++) { - TicketChartCell ticketChartCell = chartVo.getChartCells().get(i); - dataset.addValue(ticketChartCell.getTicketMon(), String.valueOf(i), ticketChartCell.getTicketName()); - } + for (TicketChartCell sumTicket : sumCollect) { + dataset.addValue(sumTicket.getTicketMon(), "数量", sumTicket.getTicketName()); } DefaultCategoryDataset datasetLine = new DefaultCategoryDataset(); - for (TicketChartVo chartVo : ticketList) { - for (int i = 0; i < chartVo.getChartCells().size(); i++) { - TicketChartCell ticketChartCell = chartVo.getChartCells().get(i); - datasetLine.addValue(ticketChartCell.getTicketMonPerc(), ticketChartCell.getTicketName(), ticketChartCell.getTicketName()); - } + for (TicketChartCell sumTicket : sumCollect) { + datasetLine.addValue(sumTicket.getTicketMonPerc(), "合格率", sumTicket.getTicketName()); } - String title=deptName+"水电运维项目两票统计表"; - String domainAxis="数量"; - String rangeAxis="票据类型"; - ImageEntity ticketImage = JFreeUtil.iCreateBarLineChart(true, title, domainAxis, rangeAxis, dataset, datasetLine,662, 378); + String title = deptName + "水电运维项目两票统计表"; + String rangeAxis = "数量"; + ImageEntity ticketImage = JFreeUtil.iCreateBarLineChart(true, title, null, rangeAxis, dataset, datasetLine, 662, 378); map.put("ticketImage", ticketImage); - -// //模拟表格数据 -// ArrayList> list = new ArrayList<>(2); -// -// HashMap temp = new HashMap<>(3); -// temp.put("name", "name1"); -//// temp.put("name", "第一个人"); -//// temp.put("age", "23"); -// list.add(temp); -// temp = new HashMap<>(3); -// temp.put("name", "2"); -//// temp.put("name", "第二个人"); -//// temp.put("age", "24"); -// list.add(temp); -// map.put("safelist", list); - - -// //模拟柱状图图数据 -// String[] monthArray = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月"}; -// double[] value = {20, 30, 25, 50, 40, 25, 50, 40}; -// ImageEntity lineEntity = JFreeUtil.lineChart("测试111", monthArray, value, 300, 200); -// map.put("lineEntity", lineEntity); return R.success("成功"); + } + + private void getPowerData(List deptList, String yearStart, String yearEnd, String yearBeforeStart, String yearBeforeEnd, String monthStart, String monthEnd, String beforeMonthStart, String beforeMonthEnd, String monthStartBeforeYear, String monthEndBeforeYear, List devices, List planYearData, List powerPercentageVoList) { + for (Dept dept : deptList) { + MonPowerPercentageVo powerVo = new MonPowerPercentageVo(); + powerVo.setDeptId(dept.getId()); + powerVo.setDeptName(dept.getDeptName()); + BigDecimal powerYear = new BigDecimal(0); + BigDecimal powerYearBefore = new BigDecimal(0); + BigDecimal powerMonth = new BigDecimal(0); + BigDecimal powerMonthBefore = new BigDecimal(0); + BigDecimal powerMonthYearBefore = new BigDecimal(0); + Double planGeneration = 0d; + List planGenerationById = planYearData.stream().filter(s -> dept.getId().equals(s.getCreateDept())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(planGenerationById)) { + planGeneration = Double.valueOf(planGenerationById.get(0).getPlanGeneration()); + } + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(dept.getId())).collect(Collectors.toList()); + for (EminfoAndEmParamVo device : stationDevices) { + //今年发电量 + List analyseData = analyseDataService.periodTargetData(yearStart, yearEnd, 3, EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); + if (CollectionUtil.isNotEmpty(analyseData)) { + BigDecimal yearPower = analyseData.stream().filter(ktv -> ktv.getVal() != null) + .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + powerYear = powerYear.add(yearPower); + } + //去年发电量 + List analyseDataYearBefore = analyseDataService.periodTargetData(yearBeforeStart, yearBeforeEnd, 3, EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); + if (CollectionUtil.isNotEmpty(analyseDataYearBefore)) { + BigDecimal powerBefore = analyseDataYearBefore.stream().filter(ktv -> ktv.getVal() != null) + .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + powerYearBefore = powerYearBefore.add(powerBefore); + } + //今年当月发电量 + List analyseDataMonth = analyseDataService.periodTargetData(monthStart, monthEnd, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); + if (CollectionUtil.isNotEmpty(analyseDataMonth)) { + BigDecimal powerBefore = analyseDataMonth.stream().filter(ktv -> ktv.getVal() != null) + .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonth = powerMonth.add(powerBefore); + } + //上个月发电量 + List analyseDataMonthBefore = analyseDataService.periodTargetData(beforeMonthStart, beforeMonthEnd, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); + if (CollectionUtil.isNotEmpty(analyseDataMonthBefore)) { + BigDecimal powerBefore = analyseDataMonthBefore.stream().filter(ktv -> ktv.getVal() != null) + .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthBefore = powerMonthBefore.add(powerBefore); + } + //去年当月发电量 + List analyseDataMonthBeforeYear = analyseDataService.periodTargetData(monthStartBeforeYear, monthEndBeforeYear, 3, EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(), device.getEmCode(), HomePageConstant.ELECTRICITY_CONSUMPTION); + if (CollectionUtil.isNotEmpty(analyseDataMonthBeforeYear)) { + BigDecimal powerBefore = analyseDataMonthBeforeYear.stream().filter(ktv -> ktv.getVal() != null) + .map(ktv -> BigDecimal.valueOf(Double.valueOf(ktv.getVal()))) + .reduce(BigDecimal.ZERO, BigDecimal::add); + powerMonthYearBefore = powerMonthYearBefore.add(powerBefore); + } + } + powerVo.setPowerYear(powerYear.doubleValue()); + powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); + BigDecimal yearPercentage = new BigDecimal(0); + BigDecimal planPercentage = new BigDecimal(0); + if (powerYearBefore.compareTo(BigDecimal.ZERO) != 0) { + yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); + } + if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO) != 0) { + planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); + } + powerVo.setPlanPercentage(planPercentage.doubleValue()); + powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); + powerVo.setPowerMon(powerMonth.doubleValue()); + powerVo.setPowerMonBefore(powerMonthBefore.doubleValue()); + powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); + BigDecimal monPercentage = new BigDecimal(0); + if (powerMonthYearBefore.compareTo(BigDecimal.ZERO) != 0) { + monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); + } + powerVo.setPowerMonPercentage(monPercentage.doubleValue()); + powerPercentageVoList.add(powerVo); + } } private static void getTabelSum(Long deptId, List powerPercentageVoList, List planYearAll, List planMonAll, HashMap map) { @@ -752,15 +795,15 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { powerVo.setPowerYearBefore(powerYearBefore.doubleValue()); BigDecimal yearPercentage = new BigDecimal(0); BigDecimal planPercentage = new BigDecimal(0); - if (powerYearBefore.compareTo(BigDecimal.ZERO)!=0) { + if (powerYearBefore.compareTo(BigDecimal.ZERO) != 0) { // 年累计环比 yearPercentage = (powerYear.subtract(powerYearBefore)).divide(powerYearBefore, 2, BigDecimal.ROUND_UP); } - if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO)!=0) { + if (BigDecimal.valueOf(planGeneration).compareTo(BigDecimal.ZERO) != 0) { planPercentage = powerYear.divide(BigDecimal.valueOf(planGeneration), 2, BigDecimal.ROUND_UP); // 年计划完成率 map.put("yearCompletionRate", planPercentage.toString()); - }else { + } else { map.put("yearCompletionRate", 0); } powerVo.setPowerYearPercentage(yearPercentage.doubleValue()); @@ -773,7 +816,7 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { map.put("powerMon", powerMonth.toString()); // 项目月计划完成量 BigDecimal planMonPercentage = new BigDecimal(0); - if (powerMonth.compareTo(BigDecimal.ZERO)!=0 &&BigDecimal.valueOf(planMonGeneration).compareTo(BigDecimal.ZERO)!=0) { + if (powerMonth.compareTo(BigDecimal.ZERO) != 0 && BigDecimal.valueOf(planMonGeneration).compareTo(BigDecimal.ZERO) != 0) { planMonPercentage = powerMonth.divide(BigDecimal.valueOf(planMonGeneration), 2, BigDecimal.ROUND_UP); } map.put("monCompletionRate", planMonPercentage); @@ -786,12 +829,12 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService { .reduce(BigDecimal.ZERO, BigDecimal::add); powerVo.setPowerMonYearBefore(powerMonthYearBefore.doubleValue()); BigDecimal monPercentage = new BigDecimal(0); - if (powerMonthYearBefore.compareTo(BigDecimal.ZERO)!=0) { - monPercentage =(powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); + if (powerMonthYearBefore.compareTo(BigDecimal.ZERO) != 0) { + monPercentage = (powerMonth.subtract(powerMonthYearBefore)).divide(powerMonthYearBefore, 2, BigDecimal.ROUND_UP); } //发电量环比增加 BigDecimal monAdd = powerMonth.subtract(powerMonthBefore); - if (powerMonthBefore.compareTo(BigDecimal.ZERO)==0) { + if (powerMonthBefore.compareTo(BigDecimal.ZERO) == 0) { map.put("percentageAdd", 0); } else { map.put("percentageAdd", monAdd.divide(powerMonthBefore, 2, BigDecimal.ROUND_UP).toString()); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java index 1d8e8d1..95e2bc6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationService.java @@ -131,4 +131,10 @@ public interface IStationService extends BaseService { */ void uniqueStationByStation(String signage); + /** + * 通过站点id获取站点名称 + * @param station + * @return + */ + String selectStationById(String station); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index e2b5123..bc86153 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.station.service.impl; import com.alibaba.fastjson.JSON; 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.common.service.UserAuthDataService; @@ -37,6 +38,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; +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.mp.support.Query; @@ -106,19 +108,20 @@ public class StationServiceImpl extends BaseServiceImpl questionClient.submitStationInfo(configVO.getFdpStationType(), req.getCode(), "运维平台推送"), "智能诊断站点推送").start(); } // 如果设备数据来源未选定其他 则进行站点初始化操作 if (StationConstants.GATHER.equals(req.getDataOrigin()) && !StationConstants.HZ3000_OTHER.equals(req.getDataSource())) { - log.info("{}站点开始数据平台新建项目",req.getCode()); + log.info("{}站点开始数据平台新建项目", req.getCode()); new Thread(() -> this.instanceProject(req), "数据平台新建项目").start(); } } @@ -697,8 +700,30 @@ public class StationServiceImpl extends BaseServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(StationEntity::getSignage, signage); Integer count = baseMapper.selectCount(queryWrapper); - if (count > 0){ - throw new ServiceException("两票编号抬头已存在"); + if (count > 0) { + throw new ServiceException("两票编号抬头已存在"); + } + } + + + /** + * 通过站点id获取站点名称 + * + * @param station + * @return + */ + @Override + public String selectStationById(String station) { + if (StringUtils.isEmpty(station)) { + return null; + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(BaseEntity::getId, station); + queryWrapper.lambda().or().eq(StationEntity::getCode, station); + StationEntity stationEntity = baseMapper.selectOne(queryWrapper); + if (stationEntity != null) { + return stationEntity.getName(); } + return null; } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java index 40a632c..909c71c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.util; import cn.afterturn.easypoi.entity.ImageEntity; import cn.hutool.core.lang.Assert; +import com.hnac.hzims.operational.data.controller.CustomRenderer; import lombok.extern.slf4j.Slf4j; import org.apache.poi.xwpf.usermodel.XWPFTable; import org.jfree.chart.ChartFactory; @@ -12,9 +13,7 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; -import org.jfree.chart.labels.StandardCategoryToolTipGenerator; -import org.jfree.chart.labels.StandardPieSectionLabelGenerator; +import org.jfree.chart.labels.*; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.DatasetRenderingOrder; import org.jfree.chart.plot.PiePlot; @@ -23,6 +22,7 @@ import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.chart.renderer.category.StandardBarPainter; +import org.jfree.chart.ui.TextAnchor; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge; @@ -288,14 +288,20 @@ public class JFreeUtil { CategoryPlot categoryplot = chart.getCategoryPlot(); categoryplot.setDataset(1, datasetLine); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); + //数据标签展示 lineandshaperenderer.setDefaultToolTipGenerator(new StandardCategoryToolTipGenerator()); lineandshaperenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); lineandshaperenderer.setDefaultLinesVisible(true); - lineandshaperenderer.setSeriesPaint(0, Color.decode("#9BBB59")); +// lineandshaperenderer.setDefaultItemLabelPaint(Color.BLACK); +// lineandshaperenderer.setDefaultItemLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); +// lineandshaperenderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition( +// ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT)); + lineandshaperenderer.setSeriesPaint(0, Color.BLACK); categoryplot.setRenderer(1, lineandshaperenderer); - NumberAxis numberaxis = new NumberAxis("平均值"); - numberaxis.setLabelFont(new Font("宋体", Font.TRUETYPE_FONT, 12)); + NumberAxis numberaxis = new NumberAxis("合格率"); + numberaxis.setLabelFont(new Font("微软雅黑", Font.TRUETYPE_FONT, 12)); categoryplot.setRangeAxis(1, numberaxis); +// // 显示折线图,1,1坐标轴都在右侧 categoryplot.mapDatasetToRangeAxis(1, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); } @@ -345,13 +351,16 @@ public class JFreeUtil { CategoryAxis domainAxis = categoryplot.getDomainAxis(); // 设置Y轴的提示文字样式 rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); +// chart.setTextAntiAlias(false); // 设置Y轴刻度线的长度 rangeAxis.setTickMarkInsideLength(10f); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // 横轴上的 domainAxis.setLowerMargin(0.1); domainAxis.setUpperMargin(0.1); - + // 设置横轴的label为45度 + domainAxis.setMaximumCategoryLabelWidthRatio(4f); + domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // rangeAxis.setTickMarkOutsideLength(10f); // 设置X轴下的标签文字 domainAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); @@ -367,17 +376,17 @@ public class JFreeUtil { // vn.setVerticalTickLabels(true); // 自定义柱状图中柱子的样式 - BarRenderer brender = new BarRenderer(); - brender.setSeriesPaint(0, Color.decode("#C0504D")); // 给series1 Bar - brender.setSeriesPaint(1, Color.decode("#E46C0A")); // 给series2 Bar - brender.setSeriesPaint(2, Color.decode("#4F81BD")); // 给series3 Bar - brender.setSeriesPaint(3, Color.decode("#00B050")); // 给series4 Bar - brender.setSeriesPaint(4, Color.decode("#7030A0")); // 给series5 Bar - brender.setSeriesPaint(5, Color.decode("#00BF00")); // 给series6 Bar + CustomRenderer brender = new CustomRenderer(); // 设置柱状图的顶端显示数字 + brender.setDefaultItemLabelsVisible(true); brender.setIncludeBaseInRange(true); brender.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); - brender.setDefaultItemLabelsVisible(true); + brender.setDefaultItemLabelPaint(Color.WHITE); + brender.setDefaultItemLabelFont(new Font("微软雅黑", Font.PLAIN, 12)); + brender.setDefaultPositiveItemLabelPosition(new ItemLabelPosition( + ItemLabelAnchor.INSIDE11, TextAnchor.TOP_LEFT)); + brender.setMinimumBarLength(10); + // 设置柱子为平面图不是立体的 brender.setBarPainter(new StandardBarPainter()); // 设置柱状图之间的距离0.1代表10%; @@ -437,8 +446,8 @@ public class JFreeUtil { // brender.setSeriesPaint(5, Color.decode("#00BF00")); // 给series6 Bar // 设置柱状图的顶端显示数字 brender.setIncludeBaseInRange(true); -// brender.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); -// brender.setBaseItemLabelsVisible(isBaseItemLabelsVisible()); + brender.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); + brender.setDefaultItemLabelsVisible(true); // 设置柱子为平面图不是立体的 brender.setBarPainter(new StandardBarPainter()); // 设置柱状图之间的距离0.1代表10%; @@ -459,7 +468,6 @@ public class JFreeUtil { categoryplot.setRenderer(brender); - } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java index 71005de..58bf871 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java @@ -2,8 +2,10 @@ package com.hnac.hzims.operational.util; import org.springblade.core.tool.utils.DateUtil; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; public class TimeUtils { @@ -108,4 +110,37 @@ public class TimeUtils { String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 23:59:59"; return end; } + public static List getListByYear(Integer year) { + List monthList=new ArrayList<>(); + for (int i = 1; i <13; i++) { + // 创建一个Calendar对象 + Calendar calendar = Calendar.getInstance(); + // 设置年份 + calendar.set(Calendar.YEAR, Integer.valueOf(year)); + // 设置月份为1(即一月) + calendar.set(Calendar.MONTH, i); + calendar.set(Calendar.DAY_OF_MONTH, 1); + // 将日期对象减去一天,即为当月的最后一天 + String mon = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE); + + monthList.add(mon); + } + return monthList; + } + public static String getMon(Integer year,Integer month) { + // 创建一个Calendar对象 + Calendar calendar = Calendar.getInstance(); + // 设置年份 + calendar.set(Calendar.YEAR, year); + // 设置月份为1(即一月) + calendar.set(Calendar.MONTH, month-1); + // 设置日期为1 + calendar.set(Calendar.DATE, 1); + // 设置时间为0点0分0秒 + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) ; + return start; + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/WordUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/WordUtils.java index 306ab29..5b28ec5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/WordUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/WordUtils.java @@ -7,12 +7,17 @@ import com.hnac.hzims.operational.util.pojo.HttpResponse; import freemarker.cache.StringTemplateLoader; import freemarker.template.Configuration; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.apache.poi.xwpf.usermodel.XWPFTableRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.List; import java.util.Map; /** @@ -83,4 +88,87 @@ public abstract class WordUtils { } } + public static XWPFDocument exportWordV2(String templatePath, Map params) { + try { + XWPFDocument doc = WordExportUtil.exportWord07(templatePath, params); +// 合并第一列相同行的数据 + tableIfSame(doc); + return doc; + } catch (Exception e) { + e.printStackTrace(); + return new XWPFDocument(); + } + } + + /** + * 合并第一列相同行的数据 + * @param xwpfDocument + */ + public static void tableIfSame(XWPFDocument xwpfDocument){ + //获取文档中所有的表格 + List tableList = xwpfDocument.getTables(); + if (tableList.size()>0){ + //循环表格 + for (int tabIndex=0;tabIndex rows = xwpfTable.getRows(); + for (int i = 0; i < rows.size(); i++) { + if (i==rows.size()-1){ + continue; + } + XWPFTableCell cell = rows.get(i).getCell(0); + XWPFTableCell cell2 = rows.get(i+1).getCell(0); + String text = cell.getText(); + String text2 = cell2.getText(); + if (text2.equals(text)){ + mergeCellsVertically(xwpfTable,0,i,i+1); + } + } + } + } + } + + /** + * word单元格列合并 + * @param table 表格 + * @param row 合并列所在行 + * @param startCell 开始列 + * @param endCell 结束列 + * @date 2020年4月8日 下午4:43:54 + */ + public static void mergeCellsHorizontal(XWPFTable table, int row, int startCell, int endCell) { + for (int i = startCell; i <= endCell; i++) { + XWPFTableCell cell = table.getRow(row).getCell(i); + if (i == startCell) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + } + } + } + + /** + * word单元格行合并 + * @param table 表格 + * @param col 合并行所在列 + * @param startRow 开始行 + * @param endRow 结束行 + * @date 2020年4月8日 下午4:46:18 + */ + public static void mergeCellsVertically(XWPFTable table, int col, int startRow, int endRow) { + for (int i = startRow; i <= endRow; i++) { + XWPFTableCell cell = table.getRow(i).getCell(col); + if (i == startRow) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + } + } + } + } diff --git a/hzims-service/operational/src/main/resources/template/waterMonReport.docx b/hzims-service/operational/src/main/resources/template/waterMonReport.docx new file mode 100644 index 0000000..f29b321 Binary files /dev/null and b/hzims-service/operational/src/main/resources/template/waterMonReport.docx differ