yang_shj
4 months ago
25 changed files with 727 additions and 10 deletions
@ -0,0 +1,46 @@
|
||||
package com.hnac.hzims.electric.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* 实体类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@TableName("hzims_em_thirty_generate") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ApiModel(value = "设备30天发电量对象", description = "") |
||||
public class ThirtyEntity extends TenantEntity { |
||||
|
||||
@ApiModelProperty(value = "站点编码") |
||||
private String stationId; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String stationName; |
||||
|
||||
@ApiModelProperty(value = "设备编号") |
||||
private String deviceCode; |
||||
|
||||
@ApiModelProperty(value = "设备名称") |
||||
private String deviceName; |
||||
|
||||
@ApiModelProperty(value = "月份 : String") |
||||
private String strDay; |
||||
|
||||
@ApiModelProperty(value = "月份 : Int") |
||||
private Integer day; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
private BigDecimal generate; |
||||
|
||||
@ApiModelProperty(value = "无功发电量") |
||||
private BigDecimal reactiveGenerate; |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.hnac.hzims.electric.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.tenant.mp.TenantEntity; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* 实体类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@TableName("hzims_em_three_generate") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ApiModel(value = "设备3年发电量对象", description = "") |
||||
public class ThreeEntity extends TenantEntity { |
||||
|
||||
@ApiModelProperty(value = "站点编码") |
||||
private String stationId; |
||||
|
||||
@ApiModelProperty(value = "站点名称") |
||||
private String stationName; |
||||
|
||||
@ApiModelProperty(value = "设备编号") |
||||
private String deviceCode; |
||||
|
||||
@ApiModelProperty(value = "设备名称") |
||||
private String deviceName; |
||||
|
||||
@ApiModelProperty(value = "月份 : String") |
||||
private String strMonth; |
||||
|
||||
@ApiModelProperty(value = "月份 : Int") |
||||
private Integer month; |
||||
|
||||
@ApiModelProperty(value = "发电量") |
||||
private BigDecimal generate; |
||||
|
||||
@ApiModelProperty(value = "无功电量") |
||||
private BigDecimal reactiveGenerate; |
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.hnac.hzims.electric.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @author 表头 |
||||
*/ |
||||
@Data |
||||
public class TableHeadVo { |
||||
|
||||
@ApiModelProperty(value = "表头名字") |
||||
private String tableName; |
||||
|
||||
@ApiModelProperty(value = "是否存在子表头") |
||||
private Boolean isChildren; |
||||
|
||||
@ApiModelProperty(value = "子表头列表") |
||||
private List<String> children; |
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.hnac.hzims.electric.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import com.hnac.hzims.electric.service.IElectricReportService; |
||||
import com.hnac.hzims.equipment.entity.EmAssociationEntity; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.mp.support.Condition; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@RestController |
||||
@AllArgsConstructor |
||||
@RequestMapping("/electric") |
||||
@Api(tags = "电量报表") |
||||
public class ElectricReportController extends BladeController { |
||||
|
||||
private final IElectricReportService service; |
||||
|
||||
@GetMapping("/basics") |
||||
@ApiOperationSupport(order = 1) |
||||
@ApiOperation(value = "基础报表", notes = "传入 type : 0-日报 1-月报 2-年报") |
||||
public R<Map<String,Object>> basics(@RequestParam(value = "deptId",required = false) Long deptId, |
||||
@RequestParam(value = "type") Long type, |
||||
@RequestParam(value = "time") String time) { |
||||
return R.data(service.basics(deptId,type,time)); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.hnac.hzims.electric.mapper; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.hnac.hzims.electric.entity.ThirtyEntity; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ThirtyMapper extends BaseMapper<ThirtyEntity> { |
||||
|
||||
} |
@ -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.electric.mapper.ThirtyMapper"> |
||||
|
||||
</mapper> |
@ -0,0 +1,13 @@
|
||||
package com.hnac.hzims.electric.mapper; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.hnac.hzims.electric.entity.ThreeEntity; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ThreeMapper extends BaseMapper<ThreeEntity> { |
||||
|
||||
|
||||
} |
@ -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.electric.mapper.ThreeMapper"> |
||||
|
||||
</mapper> |
@ -0,0 +1,12 @@
|
||||
package com.hnac.hzims.electric.service; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface IElectricReportService { |
||||
|
||||
|
||||
Map<String, Object> basics(Long deptId, Long type,String time); |
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.hnac.hzims.electric.service; |
||||
|
||||
import com.hnac.hzims.electric.entity.ThirtyEntity; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ThirtyService extends BaseService<ThirtyEntity> { |
||||
|
||||
} |
@ -0,0 +1,11 @@
|
||||
package com.hnac.hzims.electric.service; |
||||
|
||||
import com.hnac.hzims.electric.entity.ThreeEntity; |
||||
import org.springblade.core.mp.base.BaseService; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface ThreeService extends BaseService<ThreeEntity> { |
||||
|
||||
} |
@ -0,0 +1,385 @@
|
||||
package com.hnac.hzims.electric.service.impl; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.hnac.hzims.electric.entity.ThirtyEntity; |
||||
import com.hnac.hzims.electric.entity.ThreeEntity; |
||||
import com.hnac.hzims.electric.service.IElectricReportService; |
||||
import com.hnac.hzims.electric.service.ThirtyService; |
||||
import com.hnac.hzims.electric.service.ThreeService; |
||||
import com.hnac.hzims.electric.vo.TableHeadVo; |
||||
import com.hnac.hzims.operational.station.entity.StationEntity; |
||||
import com.hnac.hzims.operational.station.feign.IStationClient; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.core.tool.utils.CollectionUtil; |
||||
import org.springblade.core.tool.utils.DateUtil; |
||||
import org.springblade.core.tool.utils.ObjectUtil; |
||||
import org.springblade.system.entity.Dept; |
||||
import org.springblade.system.feign.ISysClient; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class ElectricReportServiceImpl implements IElectricReportService { |
||||
|
||||
private final ThreeService threeService; |
||||
|
||||
private final ThirtyService thirtyService; |
||||
|
||||
private final ISysClient sysClient; |
||||
|
||||
private final IStationClient stationClient; |
||||
|
||||
/** |
||||
* 基础报表 |
||||
* @param deptId |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Map<String, Object> basics(Long deptId, Long type,String time) { |
||||
Map<String, Object> result = new HashMap<>(); |
||||
|
||||
// 步骤1.查询当前用户权限机构
|
||||
R<List<Dept>> depts = sysClient.getDeptByCurrentUser(); |
||||
|
||||
// 步骤2.确认机构级别
|
||||
Integer category = this.category(depts.getData(),deptId); |
||||
if(category < 0){ |
||||
return result; |
||||
} |
||||
|
||||
// 步骤3.根据级别进行查询发电数据
|
||||
switch (category){ |
||||
case 4: |
||||
return this.station(deptId,type,time); |
||||
case 3: |
||||
List<Long> deptIds = depts.getData().stream().filter(dept->dept.getParentId().equals(deptId)).map(Dept::getId).collect(Collectors.toList()); |
||||
return this.area(deptIds,type,time); |
||||
case 2: |
||||
case 1: |
||||
//return this.group();
|
||||
default: |
||||
return result; |
||||
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 确认机构级别 |
||||
* @param deptId |
||||
* @return |
||||
*/ |
||||
private Integer category(List<Dept> depts,Long deptId) { |
||||
if(ObjectUtil.isEmpty(deptId)){ |
||||
if(CollectionUtil.isEmpty(depts)){ |
||||
return -1; |
||||
} |
||||
Optional<Dept> optional = depts.stream().min(Comparator.comparing(Dept::getDeptCategory)); |
||||
return optional.get().getDeptCategory(); |
||||
} |
||||
R<Dept> dept = sysClient.getDept(deptId); |
||||
if(!dept.isSuccess() || ObjectUtil.isEmpty(dept)){ |
||||
return -1; |
||||
} |
||||
return dept.getData().getDeptCategory(); |
||||
} |
||||
|
||||
/** |
||||
* 区域级别数据 |
||||
* @param deptIds |
||||
* @param type |
||||
* @param time |
||||
* @return |
||||
*/ |
||||
private Map<String, Object> area(List<Long> deptIds, Long type, String time) { |
||||
// 查询站点
|
||||
R<List<StationEntity>> stations = stationClient.getStationsByRefDepts(deptIds); |
||||
if(!stations.isSuccess() || ObjectUtil.isEmpty(stations.getData())){ |
||||
return new HashMap<>(); |
||||
} |
||||
|
||||
Map<String,Object> result = new HashMap<>(); |
||||
// 月
|
||||
if (type == 1) { |
||||
// 查询月数据
|
||||
List<ThirtyEntity> thirtys = thirtyService.list(Wrappers.<ThirtyEntity>lambdaQuery() |
||||
//.isNotNull(ThirtyEntity::getDeviceCode)
|
||||
.in(ThirtyEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) |
||||
.like(ThirtyEntity::getStrDay,time) |
||||
); |
||||
if(CollectionUtil.isEmpty(thirtys)){ |
||||
return new HashMap<>(); |
||||
} |
||||
// 表头
|
||||
List<TableHeadVo> tableHeads = new ArrayList<>(); |
||||
TableHeadVo firstHead = new TableHeadVo(); |
||||
firstHead.setTableName("日期"); |
||||
firstHead.setIsChildren(false); |
||||
tableHeads.add(firstHead); |
||||
TableHeadVo secondHead = new TableHeadVo(); |
||||
secondHead.setTableName("日总计发电量"); |
||||
secondHead.setIsChildren(true); |
||||
secondHead.setChildren(Arrays.asList("日总有功","日总无功")); |
||||
tableHeads.add(secondHead); |
||||
|
||||
// 根据设备分组
|
||||
Map<String,List<ThirtyEntity>> group = thirtys.stream().collect(Collectors.groupingBy(ThirtyEntity::getStationName)); |
||||
group.keySet().stream().sorted().forEach(key->{ |
||||
TableHeadVo tableHead = new TableHeadVo(); |
||||
tableHead.setTableName(key + "发电量(kWh)"); |
||||
tableHead.setIsChildren(true); |
||||
tableHead.setChildren(Arrays.asList("日有功","日无功")); |
||||
tableHeads.add(tableHead); |
||||
}); |
||||
|
||||
result.put("tableHead",tableHeads); |
||||
// 组装数据
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(DateUtil.parse(time + "-01 00:00:00",DateUtil.PATTERN_DATETIME)); |
||||
calendar.add(Calendar.MONTH,1); |
||||
Date end = calendar.getTime(); |
||||
calendar.add(Calendar.MONTH,-1); |
||||
Date start = calendar.getTime(); |
||||
List<List<Object>> tableDate = new ArrayList<>(); |
||||
while (start.compareTo(end) < 0){ |
||||
List<Object> item = new ArrayList<>(); |
||||
String day = DateUtil.format(start,DateUtil.PATTERN_DATE); |
||||
item.add(start.getDate() + "日"); |
||||
// 总计:有功、无功
|
||||
item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
|
||||
// 遍历站点
|
||||
group.entrySet().stream().sorted(Map.Entry. |
||||
comparingByKey()).forEach(entry->{ |
||||
item.add(entry.getValue().stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(entry.getValue().stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
}); |
||||
calendar.add(Calendar.DAY_OF_MONTH,1); |
||||
start = calendar.getTime(); |
||||
tableDate.add(item); |
||||
} |
||||
result.put("tableDate",tableDate); |
||||
} |
||||
// 年
|
||||
else if (type == 2) { |
||||
// 查询月数据
|
||||
List<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>lambdaQuery() |
||||
.isNotNull(ThreeEntity::getDeviceCode) |
||||
.in(ThreeEntity::getStationId,stations.getData().stream().map(StationEntity::getCode).collect(Collectors.toList())) |
||||
.like(ThreeEntity::getStrMonth,time) |
||||
); |
||||
if(CollectionUtil.isEmpty(threes)){ |
||||
return new HashMap<>(); |
||||
} |
||||
// 表头
|
||||
List<TableHeadVo> tableHeads = new ArrayList<>(); |
||||
TableHeadVo firstHead = new TableHeadVo(); |
||||
firstHead.setTableName("月份"); |
||||
firstHead.setIsChildren(false); |
||||
tableHeads.add(firstHead); |
||||
TableHeadVo secondHead = new TableHeadVo(); |
||||
secondHead.setTableName("月总计发电量"); |
||||
secondHead.setIsChildren(true); |
||||
secondHead.setChildren(Arrays.asList("月总有功","月总无功")); |
||||
tableHeads.add(secondHead); |
||||
|
||||
// 根据站点分组
|
||||
Map<String,List<ThreeEntity>> group = threes.stream().collect(Collectors.groupingBy(ThreeEntity::getStationName)); |
||||
group.keySet().stream().sorted().forEach(key->{ |
||||
TableHeadVo tableHead = new TableHeadVo(); |
||||
tableHead.setTableName(key + "发电量(kWh)"); |
||||
tableHead.setIsChildren(true); |
||||
tableHead.setChildren(Arrays.asList("月有功","月无功")); |
||||
tableHeads.add(tableHead); |
||||
}); |
||||
|
||||
result.put("tableHead",tableHeads); |
||||
// 组装数据
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(DateUtil.parse(time + "-01-01 00:00:00",DateUtil.PATTERN_DATETIME)); |
||||
calendar.add(Calendar.YEAR,1); |
||||
Date end = calendar.getTime(); |
||||
calendar.add(Calendar.YEAR,-1); |
||||
Date start = calendar.getTime(); |
||||
List<List<Object>> tableDate = new ArrayList<>(); |
||||
while (start.compareTo(end) < 0){ |
||||
List<Object> item = new ArrayList<>(); |
||||
String mon = DateUtil.format(start,"yyyy-MM"); |
||||
item.add(start.getMonth() + 1 + "月"); |
||||
// 总计:有功、无功
|
||||
item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
|
||||
// 遍历站点
|
||||
group.entrySet().stream().sorted(Map.Entry. |
||||
comparingByKey()).forEach(entry->{ |
||||
item.add(entry.getValue().stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(entry.getValue().stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
}); |
||||
calendar.add(Calendar.MONTH,1); |
||||
start = calendar.getTime(); |
||||
tableDate.add(item); |
||||
} |
||||
result.put("tableDate",tableDate); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 站点级别数据 |
||||
* @param deptId |
||||
* @param type |
||||
* @return |
||||
*/ |
||||
private Map<String, Object> station(Long deptId, Long type,String time) { |
||||
// 查询站点
|
||||
StationEntity param = new StationEntity(); |
||||
param.setRefDept(deptId); |
||||
R<StationEntity> station = stationClient.getStationByCodeOrRedDept(param); |
||||
if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){ |
||||
return new HashMap<>(); |
||||
} |
||||
|
||||
Map<String,Object> result = new HashMap<>(); |
||||
// 日
|
||||
if (type == 0) { |
||||
|
||||
} |
||||
// 月
|
||||
else if (type == 1) { |
||||
// 查询月数据
|
||||
List<ThirtyEntity> thirtys = thirtyService.list(Wrappers.<ThirtyEntity>lambdaQuery() |
||||
.isNotNull(ThirtyEntity::getDeviceCode) |
||||
.eq(ThirtyEntity::getStationId,station.getData().getCode()) |
||||
.like(ThirtyEntity::getStrDay,time) |
||||
); |
||||
if(CollectionUtil.isEmpty(thirtys)){ |
||||
return new HashMap<>(); |
||||
} |
||||
// 表头
|
||||
List<TableHeadVo> tableHeads = new ArrayList<>(); |
||||
TableHeadVo firstHead = new TableHeadVo(); |
||||
firstHead.setTableName("日期"); |
||||
firstHead.setIsChildren(false); |
||||
tableHeads.add(firstHead); |
||||
TableHeadVo secondHead = new TableHeadVo(); |
||||
secondHead.setTableName("日总计发电量"); |
||||
secondHead.setIsChildren(true); |
||||
secondHead.setChildren(Arrays.asList("日总有功","日总无功")); |
||||
tableHeads.add(secondHead); |
||||
|
||||
// 根据设备分组
|
||||
Map<String,List<ThirtyEntity>> group = thirtys.stream().collect(Collectors.groupingBy(ThirtyEntity::getDeviceName)); |
||||
group.keySet().stream().sorted().forEach(key->{ |
||||
TableHeadVo tableHead = new TableHeadVo(); |
||||
tableHead.setTableName(key + "发电量(kWh)"); |
||||
tableHead.setIsChildren(true); |
||||
tableHead.setChildren(Arrays.asList("日有功","日无功")); |
||||
tableHeads.add(tableHead); |
||||
}); |
||||
|
||||
result.put("tableHead",tableHeads); |
||||
// 组装数据
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(DateUtil.parse(time + "-01 00:00:00",DateUtil.PATTERN_DATETIME)); |
||||
calendar.add(Calendar.MONTH,1); |
||||
Date end = calendar.getTime(); |
||||
calendar.add(Calendar.MONTH,-1); |
||||
Date start = calendar.getTime(); |
||||
List<List<Object>> tableDate = new ArrayList<>(); |
||||
while (start.compareTo(end) < 0){ |
||||
List<Object> item = new ArrayList<>(); |
||||
String day = DateUtil.format(start,DateUtil.PATTERN_DATE); |
||||
item.add(start.getDate() + "日"); |
||||
// 总计:有功、无功
|
||||
item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(thirtys.stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
|
||||
// 遍历机组
|
||||
group.entrySet().stream().sorted(Map.Entry. |
||||
comparingByKey()).forEach(entry->{ |
||||
item.add(entry.getValue().stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(entry.getValue().stream().filter(thirty -> thirty.getStrDay().contains(day)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
}); |
||||
calendar.add(Calendar.DAY_OF_MONTH,1); |
||||
start = calendar.getTime(); |
||||
tableDate.add(item); |
||||
} |
||||
result.put("tableDate",tableDate); |
||||
} |
||||
// 年
|
||||
else if (type == 2) { |
||||
// 查询月数据
|
||||
List<ThreeEntity> threes = threeService.list(Wrappers.<ThreeEntity>lambdaQuery() |
||||
.isNotNull(ThreeEntity::getDeviceCode) |
||||
.eq(ThreeEntity::getStationId,station.getData().getCode()) |
||||
.like(ThreeEntity::getStrMonth,time) |
||||
); |
||||
if(CollectionUtil.isEmpty(threes)){ |
||||
return new HashMap<>(); |
||||
} |
||||
// 表头
|
||||
List<TableHeadVo> tableHeads = new ArrayList<>(); |
||||
TableHeadVo firstHead = new TableHeadVo(); |
||||
firstHead.setTableName("月份"); |
||||
firstHead.setIsChildren(false); |
||||
tableHeads.add(firstHead); |
||||
TableHeadVo secondHead = new TableHeadVo(); |
||||
secondHead.setTableName("月总计发电量"); |
||||
secondHead.setIsChildren(true); |
||||
secondHead.setChildren(Arrays.asList("月总有功","月总无功")); |
||||
tableHeads.add(secondHead); |
||||
|
||||
// 根据设备分组
|
||||
Map<String,List<ThreeEntity>> group = threes.stream().collect(Collectors.groupingBy(ThreeEntity::getDeviceName)); |
||||
group.keySet().stream().sorted().forEach(key->{ |
||||
TableHeadVo tableHead = new TableHeadVo(); |
||||
tableHead.setTableName(key + "发电量(kWh)"); |
||||
tableHead.setIsChildren(true); |
||||
tableHead.setChildren(Arrays.asList("月有功","月无功")); |
||||
tableHeads.add(tableHead); |
||||
}); |
||||
|
||||
result.put("tableHead",tableHeads); |
||||
// 组装数据
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTime(DateUtil.parse(time + "-01-01 00:00:00",DateUtil.PATTERN_DATETIME)); |
||||
calendar.add(Calendar.YEAR,1); |
||||
Date end = calendar.getTime(); |
||||
calendar.add(Calendar.YEAR,-1); |
||||
Date start = calendar.getTime(); |
||||
List<List<Object>> tableDate = new ArrayList<>(); |
||||
while (start.compareTo(end) < 0){ |
||||
List<Object> item = new ArrayList<>(); |
||||
String mon = DateUtil.format(start,"yyyy-MM"); |
||||
item.add(start.getMonth() + 1 + "月"); |
||||
// 总计:有功、无功
|
||||
item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(threes.stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
|
||||
// 遍历机组
|
||||
group.entrySet().stream().sorted(Map.Entry. |
||||
comparingByKey()).forEach(entry->{ |
||||
item.add(entry.getValue().stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getGenerate().doubleValue()).sum()); |
||||
item.add(entry.getValue().stream().filter(three -> three.getStrMonth().contains(mon)).mapToDouble(o->o.getReactiveGenerate().doubleValue()).sum()); |
||||
}); |
||||
calendar.add(Calendar.MONTH,1); |
||||
start = calendar.getTime(); |
||||
tableDate.add(item); |
||||
} |
||||
result.put("tableDate",tableDate); |
||||
} |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.electric.service.impl; |
||||
|
||||
import com.hnac.hzims.electric.entity.ThirtyEntity; |
||||
import com.hnac.hzims.electric.mapper.ThirtyMapper; |
||||
import com.hnac.hzims.electric.service.ThirtyService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class ThirtyServiceImpl extends BaseServiceImpl<ThirtyMapper, ThirtyEntity> implements ThirtyService { |
||||
|
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.hnac.hzims.electric.service.impl; |
||||
|
||||
import com.hnac.hzims.electric.entity.ThreeEntity; |
||||
import com.hnac.hzims.electric.mapper.ThreeMapper; |
||||
import com.hnac.hzims.electric.service.ThreeService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class ThreeServiceImpl extends BaseServiceImpl<ThreeMapper, ThreeEntity> implements ThreeService { |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue