Browse Source

Merge remote-tracking branch 'origin/prod-20240506' into prod-20240506

zhongwei
haungxing 5 months ago
parent
commit
de4fba2c3f
  1. 43
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java
  2. 43
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThreeGenerationEntity.java
  3. 14
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java
  4. 13
      hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/mapper/PersonManagemetMapper.java
  5. 55
      hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/mapper/PersonManagemetMapper.xml
  6. 22
      hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/service/impl/PresonManagementServiceImpl.java
  7. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java
  8. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java
  9. 72
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java
  10. 1
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java
  11. 11
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java
  12. 11
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java
  13. 22
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java
  14. 22
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java
  15. 13
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java
  16. 299
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java
  17. 1
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java
  18. 5
      hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml
  19. 5
      hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml
  20. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java

43
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThirtyGenerationEntity.java

@ -0,0 +1,43 @@
package com.hnac.hzims.equipment.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 ThirtyGenerationEntity 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;
}

43
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/ThreeGenerationEntity.java

@ -0,0 +1,43 @@
package com.hnac.hzims.equipment.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 ThreeGenerationEntity 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;
}

14
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/ScheduledConstant.java

@ -0,0 +1,14 @@
package com.hnac.hzims.operational.main.constant;
/**
* 定时任务JobHandler名称
* @author 11423
*/
public interface ScheduledConstant {
String THREE_YEAR_POWER_GENERATION = "threeYearPowerGeneration";
String THIRTY_DAY_POWER_GENERATION = "thirtyDayPowerGeneration";
String THIS_DAY_POWER_GENERATION = "thisDayPowerGeneration";
}

13
hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/mapper/PersonManagemetMapper.java

@ -19,20 +19,23 @@ import java.util.List;
*/
@Mapper
public interface PersonManagemetMapper extends UserDataScopeBaseMapper<PersonManagemetEntity> {
@UserDataAuth
List<PersonManagemetVo> getPersonManagemetEntity(
@Param(value = "type")String type, @Param(value = "deadStartTime") Date deadStartTime, @Param(value = "deadTime")Date deadTime,
@Param(value = "name")String name, @Param(value = "unitName")String unitName, @Param(value = "sex")String sex, @Param(value = "job")String job,
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status, @Param(value = "current")Integer current, @Param(value = "size")Integer size) ;
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status, @Param(value = "depetIds")List<Long> depetIds,
@Param(value = "current")Integer current, @Param(value = "size")Integer size) ;
Integer getCountByPersonManagemetEntity(
@Param(value = "type")String type, @Param(value = "deadStartTime") Date deadStartTime, @Param(value = "deadTime")Date deadTime,
@Param(value = "name")String name, @Param(value = "unitName")String unitName, @Param(value = "sex")String sex, @Param(value = "job")String job,
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status, @Param(value = "current")Integer current, @Param(value = "size")Integer size) ;
@UserDataAuth
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status, @Param(value = "depetIds")List<Long> depetIds,
@Param(value = "current")Integer current, @Param(value = "size")Integer size) ;
List<PersonManagemetExportVo> exportPersonManagemet(
@Param(value = "type")String type, @Param(value = "deadStartTime") Date deadStartTime, @Param(value = "deadTime")Date deadTime,
@Param(value = "name")String name, @Param(value = "unitName")String unitName, @Param(value = "sex")String sex, @Param(value = "job")String job,
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status) ;
@Param(value = "academicTitle")String academicTitle, @Param(value = "status")Integer status, @Param(value = "depetIds")List<Long> depetIds) ;
}

55
hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/mapper/PersonManagemetMapper.xml

@ -23,26 +23,15 @@
<result property="isDead" column="isDead" />
</collection>
</resultMap>
<!--嵌套查询-->
<select id="getPersonManagemetEntity" resultMap="PersonManagemetMap">
select a.id ,a.name,a.unit_name ,a.sex,a.job ,a.academic_title,a.phone ,a.CREATE_TIME,
b.id as certificatetId,b.person_id,b.type,b.dead_time,b.pic,b.CREATE_TIME as BCREATE_TIME,b.status,b.create_dept,
select c.id ,c.name,c.unit_name ,c.sex,c.job ,c.academic_title,c.phone ,c.CREATE_TIME,c.create_dept as create_dept,
b.id as certificatetId,b.person_id,b.type,b.dead_time,b.pic,b.CREATE_TIME as BCREATE_TIME,b.status,
case when b.dead_time is null then null
when b.dead_time &lt; NOW() then "过期" else "未过期" end as isDead
from(
select a.id ,a.name,a.unit_name ,a.sex,a.job ,a.academic_title,a.phone ,a.CREATE_TIME,a.create_dept as create_dept,a.is_deleted
from hzims_person_managemet as a
left join hzims_certificatet as b
on a.id=b.person_id and b.is_deleted = 0
where a.is_deleted = 0
<if test="type != null and type != ''">
and b.type = #{type}
</if>
<if test="deadStartTime != null and type != ''">
and b.dead_time &gt;= #{deadStartTime}
</if>
<if test="deadTime != null and type != ''">
and b.dead_time &lt;= #{deadTime}
</if>
<if test="name != null and name != ''">
and a.name like CONCAT('%',#{name},'%')
</if>
@ -55,15 +44,35 @@
<if test="job != null and job != ''">
and a.job like CONCAT('%',#{job},'%')
</if>
<if test="depetIds != null">
and a.create_dept in
<foreach collection="depetIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="academicTitle != null and academicTitle != ''">
and a.academic_title like CONCAT('%',#{academic_title},'%')
</if>
ORDER BY a.CREATE_TIME,BCREATE_TIME DESC
ORDER BY a.CREATE_TIME
LIMIT #{current}, #{size}
) as c
left join hzims_certificatet as b
on c.id=b.person_id and c.is_deleted = 0
where c.is_deleted = 0
<if test="type != null and type != ''">
and b.type = #{type}
</if>
<if test="deadStartTime != null and type != ''">
and b.dead_time &gt;= #{deadStartTime}
</if>
<if test="deadTime != null and type != ''">
and b.dead_time &lt;= #{deadTime}
</if>
ORDER BY c.CREATE_TIME,BCREATE_TIME DESC
</select>
<!--嵌套查询-->
<select id="getCountByPersonManagemetEntity" resultType="Integer">
select count(*)
select count(DISTINCT(a.id))
from hzims_person_managemet as a
left join hzims_certificatet as b
on a.id=b.person_id and b.is_deleted = 0
@ -92,6 +101,12 @@
<if test="academicTitle != null and academicTitle != ''">
and a.academic_title like CONCAT('%',#{academic_title},'%')
</if>
<if test="depetIds != null">
and a.create_dept in
<foreach collection="depetIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="status != null and status != ''">
and b.status =#{status}
</if>
@ -131,6 +146,12 @@
<if test="academicTitle != null and academicTitle != ''">
and a.academic_title like CONCAT('%',#{academic_title},'%')
</if>
<if test="depetIds != null">
and a.create_dept in
<foreach collection="depetIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="status != null and status != ''">
and b.status =#{status}
</if>

22
hzims-service/hzims-basic/src/main/java/com/hnac/hzims/basic/service/impl/PresonManagementServiceImpl.java

@ -2,6 +2,7 @@ package com.hnac.hzims.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnac.hzims.basic.entity.CertificatetEntity;
@ -15,13 +16,16 @@ import com.hnac.hzims.basic.vo.PersonManagemetVo;
import com.hnac.hzims.common.logs.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -49,12 +53,19 @@ public class PresonManagementServiceImpl extends BaseServiceImpl<PersonManagemet
@Override
public IPage<PersonManagemetVo> getPersonManagemetEntity(PersonManagemetVo personManagemetVo, Query query) {
R<List<Dept>> deptByCurrentUserR = sysClient.getDeptByCurrentUser();
if (!deptByCurrentUserR.isSuccess()&& CollectionUtils.isEmpty(deptByCurrentUserR.getData())){
throw new ServiceException("用户登录失效,请重试!");
}
List<Long> depetIds = deptByCurrentUserR.getData().stream().map(Dept::getId).collect(Collectors.toList());
List<PersonManagemetVo> personManagemetEntity = baseMapper.getPersonManagemetEntity(personManagemetVo.getType(), personManagemetVo.getDeadStartTime(), personManagemetVo.getDeadTime(),
personManagemetVo.getName(), personManagemetVo.getUnitName(), personManagemetVo.getSex(), personManagemetVo.getJob(),
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus(), (query.getCurrent()-1)*query.getSize(), query.getSize());
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus(), depetIds,
(query.getCurrent()-1)*query.getSize(), query.getSize());
Integer count = baseMapper.getCountByPersonManagemetEntity(personManagemetVo.getType(), personManagemetVo.getDeadStartTime(), personManagemetVo.getDeadTime(),
personManagemetVo.getName(), personManagemetVo.getUnitName(), personManagemetVo.getSex(), personManagemetVo.getJob(),
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus(), (query.getCurrent()-1)*query.getSize(), query.getSize());
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus(), depetIds,
(query.getCurrent()-1)*query.getSize(), query.getSize());
IPage<PersonManagemetVo> res = new Page<>();
res.setCurrent(query.getCurrent());
res.setSize(query.getSize());
@ -135,9 +146,14 @@ public class PresonManagementServiceImpl extends BaseServiceImpl<PersonManagemet
@Override
public List<PersonManagemetExportVo> exportPersonManagemet(PersonManagemetVo personManagemetVo) {
R<List<Dept>> deptByCurrentUserR = sysClient.getDeptByCurrentUser();
if (!deptByCurrentUserR.isSuccess()&& CollectionUtils.isEmpty(deptByCurrentUserR.getData())){
throw new ServiceException("用户登录失效,请重试!");
}
List<Long> depetIds = deptByCurrentUserR.getData().stream().map(Dept::getId).collect(Collectors.toList());
List<PersonManagemetExportVo> list = baseMapper.exportPersonManagemet(personManagemetVo.getType(), personManagemetVo.getDeadStartTime(), personManagemetVo.getDeadTime(),
personManagemetVo.getName(), personManagemetVo.getUnitName(), personManagemetVo.getSex(), personManagemetVo.getJob(),
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus());
personManagemetVo.getAcademicTitle(), personManagemetVo.getStatus(),depetIds);
list = list.stream().map(s -> {
CertificatetType[] types = CertificatetType.values();
for (int i = 0; i < types.length; i++) {

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThirtyGenerateMapper.java

@ -0,0 +1,12 @@
package com.hnac.hzims.scheduled.mapper.equipment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity;
/**
* @author ysj
*/
public interface ThirtyGenerateMapper extends BaseMapper<ThirtyGenerationEntity> {
}

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/ThreeGenerateMapper.java

@ -0,0 +1,12 @@
package com.hnac.hzims.scheduled.mapper.equipment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.equipment.entity.ThreeGenerationEntity;
/**
* @author ysj
*/
public interface ThreeGenerateMapper extends BaseMapper<ThreeGenerationEntity> {
}

72
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/GenerationScheduledTask.java

@ -0,0 +1,72 @@
package com.hnac.hzims.scheduled.scheduled;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.scheduled.service.operation.home.ObtainGenerationService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Date;
import static com.hnac.hzims.operational.main.constant.ScheduledConstant.*;
/**
* 设备发电量定时任务
* @author ysj
*/
@Slf4j
@Component
public class GenerationScheduledTask {
@Autowired
private ObtainGenerationService service;
/**
* 设备近3年发电量数据 : 按月分割
* @param param
* @return
*/
@XxlJob(THREE_YEAR_POWER_GENERATION)
public ReturnT<String> threeYearPowerGeneration(String param) {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}
service.threeYearPowerGeneration(param);
return new ReturnT<>("SUCCESS");
}
/**
* 设备30天发电量数据 : 按日分割
* @param param
* @return
*/
@XxlJob(THIRTY_DAY_POWER_GENERATION)
public ReturnT<String> thirtyDayPowerGeneration(String param) {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}
service.thirtyDayPowerGeneration(param);
return new ReturnT<>("SUCCESS");
}
/**
* 当天发电量数据
* @param param
* @return
*/
@XxlJob(THIS_DAY_POWER_GENERATION)
public ReturnT<String> thisDayPowerGeneration(String param) {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}
service.thisDayPowerGeneration(param);
return new ReturnT<>("SUCCESS");
}
}

1
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java

@ -8,7 +8,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Arrays;

11
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThirtyGenerateService.java

@ -0,0 +1,11 @@
package com.hnac.hzims.scheduled.service.equipment;
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity;
import org.springblade.core.mp.base.BaseService;
/**
* @author ysj
*/
public interface ThirtyGenerateService extends BaseService<ThirtyGenerationEntity> {
}

11
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/ThreeGenerateService.java

@ -0,0 +1,11 @@
package com.hnac.hzims.scheduled.service.equipment;
import com.hnac.hzims.equipment.entity.ThreeGenerationEntity;
import org.springblade.core.mp.base.BaseService;
/**
* @author ysj
*/
public interface ThreeGenerateService extends BaseService<ThreeGenerationEntity> {
}

22
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThirtyGenerateServiceImpl.java

@ -0,0 +1,22 @@
package com.hnac.hzims.scheduled.service.equipment.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity;
import com.hnac.hzims.scheduled.mapper.equipment.ThirtyGenerateMapper;
import com.hnac.hzims.scheduled.service.equipment.ThirtyGenerateService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* @author ysj
*/
@AllArgsConstructor
@Service
@Slf4j
@DS("equipment")
public class ThirtyGenerateServiceImpl extends BaseServiceImpl<ThirtyGenerateMapper, ThirtyGenerationEntity> implements ThirtyGenerateService {
}

22
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java

@ -0,0 +1,22 @@
package com.hnac.hzims.scheduled.service.equipment.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.hnac.hzims.equipment.entity.ThreeGenerationEntity;
import com.hnac.hzims.scheduled.mapper.equipment.ThreeGenerateMapper;
import com.hnac.hzims.scheduled.service.equipment.ThreeGenerateService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* @author ysj
*/
@AllArgsConstructor
@Service
@Slf4j
@DS("equipment")
public class ThreeGenerateServiceImpl extends BaseServiceImpl<ThreeGenerateMapper, ThreeGenerationEntity> implements ThreeGenerateService {
}

13
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ObtainGenerationService.java

@ -0,0 +1,13 @@
package com.hnac.hzims.scheduled.service.operation.home;
/**
* @author ysj
*/
public interface ObtainGenerationService {
void threeYearPowerGeneration(String param);
void thirtyDayPowerGeneration(String param);
void thisDayPowerGeneration(String param);
}

299
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ObtainGenerationServiceImpl.java

@ -0,0 +1,299 @@
package com.hnac.hzims.scheduled.service.operation.home.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity;
import com.hnac.hzims.equipment.entity.ThreeGenerationEntity;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.main.vo.PowerMonthVo;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.scheduled.service.equipment.ThirtyGenerateService;
import com.hnac.hzims.scheduled.service.equipment.ThreeGenerateService;
import com.hnac.hzims.scheduled.service.operation.fill.GenerateService;
import com.hnac.hzims.scheduled.service.operation.fill.PowerService;
import com.hnac.hzims.scheduled.service.operation.home.ObtainGenerationService;
import com.hnac.hzims.scheduled.service.operation.plate.DataService;
import com.hnac.hzims.scheduled.service.operation.station.StationService;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author ysj
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class ObtainGenerationServiceImpl implements ObtainGenerationService {
private final DataService dataService;
private final PowerService powerService;
private final StationService stationService;
private final GenerateService generateService;
private final ThreeGenerateService threeGenerateService;
private final ThirtyGenerateService thirtyGenerateService;
private final RedisTemplate redisTemplate;
@Value("${hzims.equipment.emInfo.emInfoList}")
public String device_cache_cofig_final;
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("obtain-generation-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 设备近3年发电量数据 : 按月分割
* @param param
*/
@Override
public void threeYearPowerGeneration(String param) {
// 步骤1.水电、光伏站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery().in(StationEntity::getType, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC)));
// 步骤2.缓存设备信息
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
// 步骤3.站点-设备3年发电量
this.saveGeneration(stations,devices);
}
/**
* 设备30天发电量数据 : 按日分割
* @param param
*/
@Override
public void thirtyDayPowerGeneration(String param) {
// 步骤1.水电、光伏站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery().in(StationEntity::getType, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC)));
// 步骤2.缓存设备信息
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
// 步骤3.站点-设备30发电量
this.saveThirtyGeneration(stations,devices);
}
/**
* 当天发电量
* @param param
*/
@Override
public void thisDayPowerGeneration(String param) {
// 步骤1.水电、光伏站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery().in(StationEntity::getType, Arrays.asList(HomePageConstant.HYDROPOWER,HomePageConstant.PHOTOVOLTAIC)));
// 步骤2.缓存设备信息
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() {});
// 步骤3.站点-设备当日发电量
}
/**
* 查询发电量
* @param stations
* @param devices
*/
private void saveThirtyGeneration(List<StationEntity> stations, List<EminfoAndEmParamVo> devices) {
Calendar calendar = Calendar.getInstance();
String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME);
calendar.add(Calendar.DAY_OF_MONTH,-29);
calendar.add(Calendar.HOUR_OF_DAY,-calendar.get(Calendar.HOUR_OF_DAY));
calendar.add(Calendar.MINUTE,-calendar.get(Calendar.MINUTE));
calendar.add(Calendar.SECOND,-calendar.get(Calendar.SECOND));
String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME);
// 将站点切割
int limit = countStep(stations.size());
List<List<StationEntity>> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList());
CountDownLatch countDownLatch = new CountDownLatch(limits.size());
for(List<StationEntity> item : limits){
try{
pool.submit(()->{
item.forEach(station->{
// 站点设备集合
List<EminfoAndEmParamVo> eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList());
// 遍历查询发电量
eminfos.forEach(device->{
List<AnalyseDataTaosVO> records = dataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER);
if(CollectionUtil.isEmpty(records)){
return;
}
// 保存设备发电量
thirtyGenerateService.saveBatch(records.stream().map(record -> {
ThirtyGenerationEntity generate = new ThirtyGenerationEntity();
generate.setStationId(station.getCode());
generate.setStationName(station.getName());
generate.setDeviceCode(device.getEmCode());
generate.setDeviceName(device.getName());
generate.setTenantId(station.getTenantId());
generate.setCreateDept(station.getRefDept());
generate.setCreateUser(station.getCreateUser());
generate.setUpdateUser(station.getUpdateUser());
Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s");
generate.setStrDay(DateUtil.format(time,DateUtil.PATTERN_DATETIME));
generate.setDay(time.getDay());
if(StringUtil.isEmpty(record.getVal())){
generate.setGenerate(BigDecimal.ZERO);
}else{
generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount()));
}
return generate;
}).collect(Collectors.toList()));
});
});
countDownLatch.countDown();
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList()));
});
}catch (Exception e){
log.error("save_generation_execute_complete_error : {}" ,e.getMessage());
}
}
// 等待所有线程执行完成
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
/**
* 保存站点-设备查询发电量
* @param stations
* @param devices
*/
private void saveGeneration(List<StationEntity> stations, List<EminfoAndEmParamVo> devices) {
// 开始时间
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12);
calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1);
String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00";
// 结束日期
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3);
calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH));
String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00";
// 将站点切割
int limit = countStep(stations.size());
List<List<StationEntity>> limits = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stations.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList());
CountDownLatch countDownLatch = new CountDownLatch(limits.size());
for(List<StationEntity> item : limits){
try{
pool.submit(()->{
item.forEach(station->{
// 站点设备集合
List<EminfoAndEmParamVo> eminfos = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList());
// 遍历查询发电量
eminfos.forEach(device->{
List<AnalyseDataTaosVO> records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER);
if(CollectionUtil.isEmpty(records)){
return;
}
// 保存设备发电量
threeGenerateService.saveBatch(records.stream().map(record -> {
ThreeGenerationEntity generate = new ThreeGenerationEntity();
generate.setStationId(station.getCode());
generate.setStationName(station.getName());
generate.setDeviceCode(device.getEmCode());
generate.setDeviceName(device.getName());
generate.setTenantId(station.getTenantId());
generate.setCreateDept(station.getRefDept());
generate.setCreateUser(station.getCreateUser());
generate.setUpdateUser(station.getUpdateUser());
Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s");
generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE));
generate.setMonth(time.getMonth() + 1);
if(StringUtil.isEmpty(record.getVal())){
generate.setGenerate(BigDecimal.ZERO);
}else{
generate.setGenerate(BigDecimal.valueOf(Double.parseDouble(record.getVal()) * device.getRideCount()));
}
return generate;
}).collect(Collectors.toList()));
});
// 填报发电量保存
threeGenerateService.saveBatch(this.saveFillGenerate(station,start,end));
});
countDownLatch.countDown();
log.error("save_generation_execute_complete: {}" ,item.stream().map(StationEntity::getName).collect(Collectors.toList()));
});
}catch (Exception e){
log.error("save_generation_execute_complete_error : {}" ,e.getMessage());
}
}
// 等待所有线程执行完成
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
/**
* 补充填报数据
* @param station
* @param start
* @param end
*/
private List<ThreeGenerationEntity> saveFillGenerate(StationEntity station, String start, String end) {
start = DateUtil.format(DateUtil.parse(start,DateUtil.PATTERN_DATETIME),"yyyy-MM");
end = DateUtil.format(DateUtil.parse(end,DateUtil.PATTERN_DATETIME),"yyyy-MM");
List<PowerMonthVo> powerMonths;
// 光伏
if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){
powerMonths = powerService.generateThreeYear(start,end,station.getRefDept());
}else{
// 水电
powerMonths = generateService.generateThreeYear(start,end,station.getCode());
}
if(CollectionUtil.isEmpty(powerMonths)){
return new ArrayList<>();
}
return powerMonths.stream().map(power->{
ThreeGenerationEntity generation = new ThreeGenerationEntity();
generation.setStationId(station.getCode());
generation.setStationName(station.getName());
generation.setTenantId(station.getTenantId());
generation.setCreateDept(station.getRefDept());
generation.setCreateUser(station.getCreateUser());
generation.setUpdateUser(station.getUpdateUser());
generation.setStrMonth(power.getStrMonth());
generation.setMonth(power.getMonth());
if(power.getPower() <= 0){
generation.setGenerate(BigDecimal.ZERO);
}else{
generation.setGenerate(BigDecimal.valueOf(Double.parseDouble(power.getPower().toString())).setScale(2, RoundingMode.HALF_UP));
}
return generation;
}).collect(Collectors.toList());
}
/**
* 计算切分次数
*/
private static Integer countStep(Integer size) {
return (size + 3 - 1) / 3;
}
}

1
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java

@ -97,6 +97,7 @@ public class DataServiceImpl implements DataService {
List<AnalyzeDataConditionPO> signboardConditions = new ArrayList<>();
AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO();
analyzeDataConditionPO.setFull(1);
po.setDeviceCode(deviceCode);
analyzeDataConditionPO.setSignages(signages);
analyzeDataConditionPO.setKeepFigures(2);

5
hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThirtyGenerateMapper.xml

@ -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.scheduled.mapper.equipment.ThirtyGenerateMapper">
</mapper>

5
hzims-service/hzims-scheduled/src/main/resources/mapper/equipment/ThreeGenerateMapper.xml

@ -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.scheduled.mapper.equipment.ThreeGenerateMapper">
</mapper>

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/census/service/impl/TargetServiceImpl.java

@ -164,7 +164,7 @@ public class TargetServiceImpl implements TargetService {
double sum = stationDevices.stream().mapToDouble(EminfoAndEmParamVo::getInstalledCapacity).sum();
item.setInstalledCapacity(sum);
// 装机容量详情
List<String> details = stationDevices.stream().map(device-> "[" + device.getName() + " " +device.getInstalledCapacity() +"kW]").collect(Collectors.toList());
List<String> details = stationDevices.stream().map(device-> "[" + device.getName() + " " + (int) Math.floor(device.getInstalledCapacity()) +"kW]").collect(Collectors.toList());
item.setDetail(String.join("|",details));
return item;
}).filter(capacity->Math.abs(capacity.getInstalledCapacity()) > 0).collect(Collectors.toList());

Loading…
Cancel
Save