20 changed files with 602 additions and 12 deletions
			
			
		| @ -0,0 +1,43 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.entity; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.annotation.SqlCondition; | ||||||
|  | import com.baomidou.mybatisplus.annotation.TableName; | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import org.springblade.core.mp.support.QueryField; | ||||||
|  | import org.springblade.core.tenant.mp.TenantEntity; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | @TableName("ecology_flow_data") | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ApiModel(value = "生态流量数据表", description = "生态流量数据表") | ||||||
|  | public class EcologyFlowDataEntity extends TenantEntity { | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "站点编号") | ||||||
|  |     private Long stationId; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "月份") | ||||||
|  |     private String mon; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "站点名称") | ||||||
|  |     private String stationName; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "在线率") | ||||||
|  |     private BigDecimal onLine; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "达标率") | ||||||
|  |     private BigDecimal demonstrate; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "及时率") | ||||||
|  |     private BigDecimal timely; | ||||||
|  | 
 | ||||||
|  |     @ApiModelProperty(value = "完整率") | ||||||
|  |     private BigDecimal complete; | ||||||
|  | } | ||||||
| @ -0,0 +1,29 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.entity; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.annotation.TableName; | ||||||
|  | import io.swagger.annotations.ApiModel; | ||||||
|  | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import org.springblade.core.tenant.mp.TenantEntity; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | @TableName("ecology_flow_station") | ||||||
|  | @EqualsAndHashCode(callSuper = true) | ||||||
|  | @ApiModel(value = "生态流量站点表", description = "生态流量站点表") | ||||||
|  | public class EcologyFlowStationEntity extends TenantEntity { | ||||||
|  | 
 | ||||||
|  |     private Long stationId; | ||||||
|  | 
 | ||||||
|  |     private String stationName; | ||||||
|  | 
 | ||||||
|  |     private Long isOnLine; | ||||||
|  | 
 | ||||||
|  |     private Long isDemonstrate; | ||||||
|  | 
 | ||||||
|  |     private Long isTimely; | ||||||
|  | 
 | ||||||
|  |     private Long isComplete; | ||||||
|  | } | ||||||
| @ -0,0 +1,23 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.vo; | ||||||
|  | 
 | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | public class DemonstrateTopVo { | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty(value = "站点编号") | ||||||
|  | 	private Long stationId; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty(value = "站点名称") | ||||||
|  | 	private String stationName; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty(value = "达标率") | ||||||
|  | 	private BigDecimal demonstrate; | ||||||
|  | } | ||||||
| @ -0,0 +1,32 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.vo; | ||||||
|  | 
 | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | public class EcologFlowStationVo { | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("达标率") | ||||||
|  | 	private Double demonstrate; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("及时率") | ||||||
|  | 	private Double timely; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("完整率") | ||||||
|  | 	private Double complete; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("在线率") | ||||||
|  | 	private Double onLine; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("接入站点数量") | ||||||
|  | 	private Integer count; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("达标率排行榜") | ||||||
|  | 	List<DemonstrateTopVo> tops; | ||||||
|  | } | ||||||
| @ -0,0 +1,29 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.vo; | ||||||
|  | 
 | ||||||
|  | import io.swagger.annotations.ApiModelProperty; | ||||||
|  | import lombok.Data; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | public class TrendChartVo { | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("时间") | ||||||
|  | 	private Integer ts; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("及时率") | ||||||
|  | 	private Double timely; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("完整率") | ||||||
|  | 	private Double complete; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("在线率") | ||||||
|  | 	private Double onLine; | ||||||
|  | 
 | ||||||
|  | 	@ApiModelProperty("达标率") | ||||||
|  | 	private Double demonstrate; | ||||||
|  | } | ||||||
| @ -0,0 +1,185 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.controller; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.core.metadata.IPage; | ||||||
|  | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowDataService; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowStationService; | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.annotations.ApiOperation; | ||||||
|  | import io.swagger.annotations.ApiParam; | ||||||
|  | import lombok.AllArgsConstructor; | ||||||
|  | import org.springblade.core.boot.ctrl.BladeController; | ||||||
|  | import org.springblade.core.log.annotation.ApiLog; | ||||||
|  | import org.springblade.core.mp.support.Condition; | ||||||
|  | import org.springblade.core.mp.support.Query; | ||||||
|  | import org.springblade.core.tool.api.R; | ||||||
|  | import org.springblade.core.tool.utils.Func; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  | 
 | ||||||
|  | import javax.validation.Valid; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Api(tags = {"生态流量监测中心"}) | ||||||
|  | @RestController | ||||||
|  | @AllArgsConstructor | ||||||
|  | @RequestMapping("/ecology") | ||||||
|  | public class EcologyController extends BladeController { | ||||||
|  | 
 | ||||||
|  |     private final EcologyFlowStationService stationService; | ||||||
|  |      | ||||||
|  |     private final EcologyFlowDataService dataService; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 数据初始化 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/generate") | ||||||
|  |     @ApiOperationSupport(order = 1) | ||||||
|  |     @ApiOperation(value = "数据生成", notes = "数据生成") | ||||||
|  |     public R generate(@RequestParam Long mon,@RequestParam String year) { | ||||||
|  |         return R.status(stationService.generate(mon,year)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 站点数据排行 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |         @PostMapping("/station_top") | ||||||
|  |     @ApiOperationSupport(order = 1) | ||||||
|  |     @ApiOperation(value = "站点数据及达标率排行", notes = "站点数据及达标率排行") | ||||||
|  |     public R station_top() { | ||||||
|  |         return R.data(stationService.station_top()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 站点数据排行 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/trend_chart") | ||||||
|  |     @ApiOperationSupport(order = 1) | ||||||
|  |     @ApiOperation(value = "指标趋势图", notes = "指标趋势图") | ||||||
|  |     public R trend_chart(@RequestParam String type) { | ||||||
|  |         return R.data(stationService.trend_chart(type)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点新增或修改 | ||||||
|  |      * @param entity | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/station/submit") | ||||||
|  |     @ApiOperationSupport(order = 1) | ||||||
|  |     @ApiOperation(value = "新增或修改", notes = "EcologyFlowStationEntity") | ||||||
|  |     public R station_submit(@Valid @RequestBody EcologyFlowStationEntity entity) { | ||||||
|  |         return R.status(stationService.saveOrUpdate(entity)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点删除 | ||||||
|  |      * @param ids | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/station/remove") | ||||||
|  |     @ApiOperationSupport(order = 2) | ||||||
|  |     @ApiOperation(value = "逻辑删除", notes = "传入ids") | ||||||
|  |     public R station_remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { | ||||||
|  |         return R.status(stationService.deleteLogic(Func.toLongList(ids))); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点列表查询 | ||||||
|  |      * @param entity | ||||||
|  |      * @param query | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @ApiLog | ||||||
|  |     @GetMapping("/station/list") | ||||||
|  |     @ApiOperationSupport(order = 3) | ||||||
|  |     @ApiOperation(value = "分页", notes = "EcologyFlowStationEntity") | ||||||
|  |     public R<IPage<EcologyFlowStationEntity>> station_list(EcologyFlowStationEntity entity, Query query) { | ||||||
|  |         IPage<EcologyFlowStationEntity> pages = stationService.page(Condition.getPage(query), Condition.getQueryWrapper(entity)); | ||||||
|  |         return R.data(pages); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点详情 | ||||||
|  |      * @param entity | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @ApiLog | ||||||
|  |     @RequestMapping(value = "/station/detail", method = {RequestMethod.GET, RequestMethod.POST}) | ||||||
|  |     @ApiOperationSupport(order = 4) | ||||||
|  |     @ApiOperation(value = "详情", notes = "EcologyFlowStationEntity") | ||||||
|  |     public R<EcologyFlowStationEntity> station_detail(EcologyFlowStationEntity entity) { | ||||||
|  |         EcologyFlowStationEntity detail = stationService.getOne(Condition.getQueryWrapper(entity)); | ||||||
|  |         return R.data(detail); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点新增或修改 | ||||||
|  |      * @param entity | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/data/submit") | ||||||
|  |     @ApiOperationSupport(order = 1) | ||||||
|  |     @ApiOperation(value = "新增或修改", notes = "EcologyFlowDataEntity") | ||||||
|  |     public R data_submit(@Valid @RequestBody EcologyFlowDataEntity entity) { | ||||||
|  |         return R.status(dataService.saveOrUpdate(entity)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点删除 | ||||||
|  |      * @param ids | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @PostMapping("/data/remove") | ||||||
|  |     @ApiOperationSupport(order = 2) | ||||||
|  |     @ApiOperation(value = "逻辑删除", notes = "传入ids") | ||||||
|  |     public R data_remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { | ||||||
|  |         return R.status(dataService.deleteLogic(Func.toLongList(ids))); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点列表查询 | ||||||
|  |      * @param entity | ||||||
|  |      * @param query | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @ApiLog | ||||||
|  |     @GetMapping("/data/list") | ||||||
|  |     @ApiOperationSupport(order = 3) | ||||||
|  |     @ApiOperation(value = "分页", notes = "EcologyFlowdataEntity") | ||||||
|  |     public R<IPage<EcologyFlowDataEntity>> data_list(EcologyFlowDataEntity entity, Query query) { | ||||||
|  |         IPage<EcologyFlowDataEntity> pages = dataService.page(Condition.getPage(query), Condition.getQueryWrapper(entity)); | ||||||
|  |         return R.data(pages); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 生态流量站点详情 | ||||||
|  |      * @param entity | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @ApiLog | ||||||
|  |     @RequestMapping(value = "/data/detail", method = {RequestMethod.GET, RequestMethod.POST}) | ||||||
|  |     @ApiOperationSupport(order = 4) | ||||||
|  |     @ApiOperation(value = "详情", notes = "EcologyFlowdataEntity") | ||||||
|  |     public R<EcologyFlowDataEntity> data_detail(EcologyFlowDataEntity entity) { | ||||||
|  |         EcologyFlowDataEntity detail = dataService.getOne(Condition.getQueryWrapper(entity)); | ||||||
|  |         return R.data(detail); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.mapper; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author YSJ | ||||||
|  |  */ | ||||||
|  | public interface EcologyFlowDataMapper extends BaseMapper<EcologyFlowDataEntity> { | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,5 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||||
|  | <mapper namespace="com.hnac.hzims.operational.ecology.mapper.EcologyFlowDataMapper"> | ||||||
|  | 
 | ||||||
|  | </mapper> | ||||||
| @ -0,0 +1,11 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.mapper; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @author YSJ | ||||||
|  |  */ | ||||||
|  | public interface EcologyFlowStationMapper extends BaseMapper<EcologyFlowStationEntity> { | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,4 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||||
|  | <mapper namespace="com.hnac.hzims.operational.ecology.mapper.EcologyFlowStationMapper"> | ||||||
|  | </mapper> | ||||||
| @ -0,0 +1,14 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.service; | ||||||
|  | 
 | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.TrendChartVo; | ||||||
|  | import org.springblade.core.mp.base.BaseService; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 告警处理接口 | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | public interface EcologyFlowDataService extends BaseService<EcologyFlowDataEntity> { | ||||||
|  | } | ||||||
| @ -0,0 +1,22 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.service; | ||||||
|  | 
 | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.EcologFlowStationVo; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.TrendChartVo; | ||||||
|  | import org.springblade.core.mp.base.BaseService; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 告警处理接口 | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | public interface EcologyFlowStationService extends BaseService<EcologyFlowStationEntity> { | ||||||
|  | 
 | ||||||
|  |     EcologFlowStationVo station_top(); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     Boolean generate(Long mon,String year); | ||||||
|  | 
 | ||||||
|  |     List<TrendChartVo> trend_chart(String type); | ||||||
|  | } | ||||||
| @ -0,0 +1,30 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.service.impl; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.mapper.EcologyFlowDataMapper; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowDataService; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowStationService; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.TrendChartVo; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.springblade.core.mp.base.BaseServiceImpl; | ||||||
|  | import org.springblade.core.tool.utils.CollectionUtil; | ||||||
|  | import org.springblade.core.tool.utils.DateUtil; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | import java.util.*; | ||||||
|  | import java.util.stream.Collectors; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 历史告警实现类 | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Slf4j | ||||||
|  | @Service | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | public class EcologyFlowDataServiceImpl extends BaseServiceImpl<EcologyFlowDataMapper, EcologyFlowDataEntity> implements EcologyFlowDataService { | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,145 @@ | |||||||
|  | package com.hnac.hzims.operational.ecology.service.impl; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||||
|  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowDataEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.entity.EcologyFlowStationEntity; | ||||||
|  | import com.hnac.hzims.operational.ecology.mapper.EcologyFlowStationMapper; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowDataService; | ||||||
|  | import com.hnac.hzims.operational.ecology.service.EcologyFlowStationService; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.DemonstrateTopVo; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.EcologFlowStationVo; | ||||||
|  | import com.hnac.hzims.operational.ecology.vo.TrendChartVo; | ||||||
|  | import lombok.RequiredArgsConstructor; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.springblade.core.mp.base.BaseServiceImpl; | ||||||
|  | import org.springblade.core.tool.utils.CollectionUtil; | ||||||
|  | import org.springblade.core.tool.utils.DateUtil; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | import java.util.*; | ||||||
|  | import java.util.stream.Collectors; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 历史告警实现类 | ||||||
|  |  * @author ysj | ||||||
|  |  */ | ||||||
|  | @Slf4j | ||||||
|  | @Service | ||||||
|  | @RequiredArgsConstructor | ||||||
|  | public class EcologyFlowStationServiceImpl extends BaseServiceImpl<EcologyFlowStationMapper, EcologyFlowStationEntity> implements EcologyFlowStationService { | ||||||
|  | 
 | ||||||
|  |     private final EcologyFlowDataService dataService; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 数据初始化 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @Override | ||||||
|  |     public Boolean generate(Long mon,String year) { | ||||||
|  |         // 步骤1.查询站点列表
 | ||||||
|  |         List<EcologyFlowStationEntity> ecologys = this.list(); | ||||||
|  |         if(CollectionUtil.isEmpty(ecologys)){ | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |         Random random=new Random(); | ||||||
|  |         List<EcologyFlowDataEntity> datas = new ArrayList<>(); | ||||||
|  |         for(EcologyFlowStationEntity ecology : ecologys){ | ||||||
|  |             int iter = Math.toIntExact(mon); | ||||||
|  |             while (Math.abs(iter) > 0){ | ||||||
|  |                 EcologyFlowDataEntity entity = new EcologyFlowDataEntity(); | ||||||
|  |                 entity.setMon(year + "-" + ((iter > 10) ? iter : "0" + iter)); | ||||||
|  |                 entity.setStationId(ecology.getStationId()); | ||||||
|  |                 entity.setStationName(ecology.getStationName()); | ||||||
|  |                 entity.setOnLine(BigDecimal.valueOf(random.nextDouble() * 100)); | ||||||
|  |                 entity.setComplete(BigDecimal.valueOf(random.nextDouble() * 100)); | ||||||
|  |                 entity.setTimely(BigDecimal.valueOf(random.nextDouble() * 100)); | ||||||
|  |                 entity.setDemonstrate(BigDecimal.valueOf(random.nextDouble() * 100)); | ||||||
|  |                 datas.add(entity); | ||||||
|  |                 iter--; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return this.dataService.saveBatch(datas); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 站点数据,达标率排行榜 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @Override | ||||||
|  |     public EcologFlowStationVo station_top() { | ||||||
|  |         List<EcologyFlowStationEntity> stations = this.list(); | ||||||
|  |         if(CollectionUtil.isEmpty(stations)){ | ||||||
|  |             return new EcologFlowStationVo(); | ||||||
|  |         } | ||||||
|  |         EcologFlowStationVo station = new EcologFlowStationVo(); | ||||||
|  |         station.setComplete(BigDecimal.valueOf((int) stations.stream().filter(o -> o.getIsComplete().equals(1L)).count() / (double) stations.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | ||||||
|  |         station.setOnLine(BigDecimal.valueOf((int) stations.stream().filter(o -> o.getIsOnLine().equals(1L)).count() / (double) stations.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | ||||||
|  |         station.setDemonstrate(BigDecimal.valueOf((int) stations.stream().filter(o -> o.getIsDemonstrate().equals(1L)).count() / (double) stations.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | ||||||
|  |         station.setTimely(BigDecimal.valueOf((int) stations.stream().filter(o -> o.getIsTimely().equals(1L)).count() / (double) stations.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); | ||||||
|  |         station.setCount(stations.size()); | ||||||
|  | 
 | ||||||
|  |         List<EcologyFlowDataEntity> datas = dataService.list(Wrappers.<EcologyFlowDataEntity>lambdaQuery(). | ||||||
|  |                 like(EcologyFlowDataEntity::getMon, DateUtil.format(new Date(),"yyyy-MM"))); | ||||||
|  |         if(CollectionUtil.isEmpty(datas)){ | ||||||
|  |             return station; | ||||||
|  |         } | ||||||
|  |         station.setTops(datas.stream().map(data->{ | ||||||
|  |             DemonstrateTopVo top = new DemonstrateTopVo(); | ||||||
|  |             top.setStationId(data.getStationId()); | ||||||
|  |             top.setStationName(data.getStationName()); | ||||||
|  |             top.setDemonstrate(data.getDemonstrate()); | ||||||
|  |             return top; | ||||||
|  |         }).sorted(Comparator.comparing(DemonstrateTopVo::getDemonstrate).reversed()).collect(Collectors.toList())); | ||||||
|  |         return station; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 指标趋势图 | ||||||
|  |      * @param type | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @Override | ||||||
|  |     public List<TrendChartVo> trend_chart(String type) { | ||||||
|  |         LambdaQueryWrapper<EcologyFlowDataEntity> wrapper = new LambdaQueryWrapper<>(); | ||||||
|  |         if("0".equals(type)){ | ||||||
|  |             wrapper.like(EcologyFlowDataEntity::getMon, DateUtil.format(new Date(),"yyyy")); | ||||||
|  |         } | ||||||
|  |         List<EcologyFlowDataEntity> datas = this.dataService.list(wrapper); | ||||||
|  |         if(CollectionUtil.isEmpty(datas)){ | ||||||
|  |             return new ArrayList<>(); | ||||||
|  |         } | ||||||
|  |         List<TrendChartVo> charts; | ||||||
|  |         if("0".equals(type)){ | ||||||
|  |             Map<String,List<EcologyFlowDataEntity>> map = datas.stream().collect(Collectors.groupingBy(EcologyFlowDataEntity::getMon)); | ||||||
|  |             charts = map.entrySet().stream().map(entry->{ | ||||||
|  |                 TrendChartVo chart = new TrendChartVo(); | ||||||
|  |                 Date date = DateUtil.parse(entry.getKey() + "-01 00:00:00",DateUtil.PATTERN_DATETIME); | ||||||
|  |                 chart.setTs(date.getMonth() + 1); | ||||||
|  |                 chart.setTimely(entry.getValue().stream().mapToDouble(o->o.getTimely().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setDemonstrate(entry.getValue().stream().mapToDouble(o->o.getDemonstrate().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setOnLine(entry.getValue().stream().mapToDouble(o->o.getOnLine().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setComplete(entry.getValue().stream().mapToDouble(o->o.getComplete().doubleValue()).average().getAsDouble()); | ||||||
|  |                 return chart; | ||||||
|  |             }).collect(Collectors.toList()); | ||||||
|  |         }else{ | ||||||
|  |             Map<String,List<EcologyFlowDataEntity>> map = datas.stream().peek(o->{ | ||||||
|  |                 Date date = DateUtil.parse(o.getMon() + "-01 00:00:00",DateUtil.PATTERN_DATETIME); | ||||||
|  |                 o.setMon(DateUtil.format(date,"yyyy")); | ||||||
|  |             }).collect(Collectors.groupingBy(EcologyFlowDataEntity::getMon)); | ||||||
|  |             charts = map.entrySet().stream().map(entry->{ | ||||||
|  |                 TrendChartVo chart = new TrendChartVo(); | ||||||
|  |                 chart.setTs(Integer.valueOf(entry.getKey())); | ||||||
|  |                 chart.setTimely(entry.getValue().stream().mapToDouble(o->o.getTimely().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setDemonstrate(entry.getValue().stream().mapToDouble(o->o.getDemonstrate().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setOnLine(entry.getValue().stream().mapToDouble(o->o.getOnLine().doubleValue()).average().getAsDouble()); | ||||||
|  |                 chart.setComplete(entry.getValue().stream().mapToDouble(o->o.getComplete().doubleValue()).average().getAsDouble()); | ||||||
|  |                 return chart; | ||||||
|  |             }).collect(Collectors.toList()); | ||||||
|  |         } | ||||||
|  |         return charts.stream().sorted(Comparator.comparing(TrendChartVo::getTs)).collect(Collectors.toList()); | ||||||
|  |     } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue