初次提交
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
package com.ho.business;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 业务中心启动类
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"com.ho.common", "com.ho.business"})
|
||||
@MapperScan(basePackages = "com.ho.business.mapper")
|
||||
@EnableDiscoveryClient
|
||||
@EnableScheduling
|
||||
@EnableFeignClients(basePackages = {"com.ho.business.feignclient"})
|
||||
@EnableAsync //开启异步
|
||||
@EnableCaching
|
||||
public class BusinessApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BusinessApplication.class, args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,248 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.alibaba.excel.metadata.Head;
|
||||
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.ElecPriceTemplateExcel;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.RowRangeDto;
|
||||
import com.ho.business.vo.resp.tabSort.TabSortExcel;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BizMergeStrategy extends AbstractMergeStrategy {
|
||||
|
||||
private Map<String, List<RowRangeDto>> strategyMap;
|
||||
private Sheet sheet;
|
||||
|
||||
public BizMergeStrategy(Map<String, List<RowRangeDto>> strategyMap) {
|
||||
this.strategyMap = strategyMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(Sheet sheet, Cell cell, Head head, Integer integer) {
|
||||
this.sheet = sheet;
|
||||
//如果没有标题,只有表头的话,这里的 cell.getRowIndex() == 1
|
||||
if (cell.getColumnIndex() == 0) {
|
||||
/**
|
||||
* 保证每个cell被合并一次,如果不加上面的判断,因为是一个cell一个cell操作的,
|
||||
* 例如合并A2:A3,当cell为A2时,合并A2,A3,但是当cell为A3时,又是合并A2,A3,
|
||||
* 但此时A2,A3已经是合并的单元格了
|
||||
*/
|
||||
for (Map.Entry<String, List<RowRangeDto>> entry : strategyMap.entrySet()) {
|
||||
Integer columnIndex = Integer.valueOf(entry.getKey());
|
||||
entry.getValue().forEach(rowRange -> {
|
||||
//添加一个合并请求
|
||||
sheet.addMergedRegionUnsafe(new CellRangeAddress(rowRange.getStart(),
|
||||
rowRange.getEnd(), columnIndex, columnIndex));
|
||||
});
|
||||
}
|
||||
}
|
||||
if (cell.getColumnIndex() == 5) {
|
||||
/**
|
||||
* 保证每个cell被合并一次,如果不加上面的判断,因为是一个cell一个cell操作的,
|
||||
* 例如合并A2:A3,当cell为A2时,合并A2,A3,但是当cell为A3时,又是合并A2,A3,
|
||||
* 但此时A2,A3已经是合并的单元格了
|
||||
*/
|
||||
for (Map.Entry<String, List<RowRangeDto>> entry : strategyMap.entrySet()) {
|
||||
Integer columnIndex = Integer.valueOf(entry.getKey());
|
||||
entry.getValue().forEach(rowRange -> {
|
||||
//添加一个合并请求
|
||||
sheet.addMergedRegionUnsafe(new CellRangeAddress(rowRange.getStart(),
|
||||
rowRange.getEnd(), columnIndex, columnIndex));
|
||||
});
|
||||
}
|
||||
}
|
||||
if (cell.getColumnIndex() == 6) {
|
||||
/**
|
||||
* 保证每个cell被合并一次,如果不加上面的判断,因为是一个cell一个cell操作的,
|
||||
* 例如合并A2:A3,当cell为A2时,合并A2,A3,但是当cell为A3时,又是合并A2,A3,
|
||||
* 但此时A2,A3已经是合并的单元格了
|
||||
*/
|
||||
for (Map.Entry<String, List<RowRangeDto>> entry : strategyMap.entrySet()) {
|
||||
Integer columnIndex = Integer.valueOf(entry.getKey());
|
||||
entry.getValue().forEach(rowRange -> {
|
||||
//添加一个合并请求
|
||||
sheet.addMergedRegionUnsafe(new CellRangeAddress(rowRange.getStart(),
|
||||
rowRange.getEnd(), columnIndex, columnIndex));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, List<RowRangeDto>> addAnnualMerStrategy(List<ElecPriceTemplateExcel> excelList) {
|
||||
Map<String, List<RowRangeDto>> strategyMap = new HashMap<>();
|
||||
ElecPriceTemplateExcel excel = null;
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
ElecPriceTemplateExcel ElecPriceTemplateExcel = excelList.get(i);
|
||||
//如果名字一样,将名字合并(真正开发中一般不会通过名字这样字段,而是通过一些关联的唯一值,比如父id)
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getTemplateName().equals(excel.getTemplateName())){ // 名字相同则合并第一列
|
||||
// BizMergeStrategy.fillStrategyMap(strategyMap, "0", i+1);
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "0", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getIsEnable().equals(excel.getIsEnable())){ // 名字相同则合并第一列
|
||||
if (ElecPriceTemplateExcel.getTemplateName() .equals( excel.getTemplateName())) {
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "5", i );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getUpdateTime().equals(excel.getUpdateTime())){ // 名字相同则合并第一列
|
||||
if (ElecPriceTemplateExcel.getTemplateName().equals(excel.getTemplateName())) {
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "9", i );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getValidityStartTime().equals(excel.getValidityStartTime())){ // 名字相同则合并第一列
|
||||
if (ElecPriceTemplateExcel.getTemplateName().equals(excel.getTemplateName())) {
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "6", i );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getValidityEndTime().equals(excel.getValidityEndTime())){ // 名字相同则合并第一列
|
||||
if (ElecPriceTemplateExcel.getTemplateName().equals(excel.getTemplateName())) {
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "7", i );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (ElecPriceTemplateExcel.getDiscount().equals(excel.getDiscount())){ // 名字相同则合并第一列
|
||||
if (ElecPriceTemplateExcel.getTemplateName().equals(excel.getTemplateName())) {
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "8", i );
|
||||
}
|
||||
}
|
||||
}
|
||||
excel = ElecPriceTemplateExcel;
|
||||
}
|
||||
return strategyMap;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, List<RowRangeDto>> addAnnualMerStrategy4TabSort(List<TabSortExcel> excelList) {
|
||||
Map<String, List<RowRangeDto>> strategyMap = new HashMap<>();
|
||||
TabSortExcel excel = null;
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
TabSortExcel tabSortExcel = excelList.get(i);
|
||||
//如果名字一样,将名字合并(真正开发中一般不会通过名字这样字段,而是通过一些关联的唯一值,比如父id)
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getTabName() != null && tabSortExcel.getTabName().equals(excel.getTabName()) ){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "0", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getTagName() != null && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "1", i );
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getTagNameEn() != null && tabSortExcel.getTagNameEn().equals(excel.getTagNameEn())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "2", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getTagType() != null && tabSortExcel.getTagType().equals(excel.getTagType()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "3", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getSrcId() != null && tabSortExcel.getSrcId().equals(excel.getSrcId()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "4", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getDeviceType() != null && tabSortExcel.getDeviceType().equals(excel.getDeviceType()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "5", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getCol() != null && tabSortExcel.getCol().equals(excel.getCol()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "6", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getMaxValue() != null && tabSortExcel.getMaxValue().equals(excel.getMaxValue()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "7", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getMinValue() != null && tabSortExcel.getMinValue().equals(excel.getMinValue()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "8", i);
|
||||
}
|
||||
}
|
||||
if (excel != null) {
|
||||
if (tabSortExcel.getFrame() != null && tabSortExcel.getFrame().equals(excel.getFrame()) && tabSortExcel.getTagName().equals(excel.getTagName())){ // 名字相同则合并第一列
|
||||
//如果没有标题,只有表头的话,这里为 BizMergeStrategy.fillStrategyMap(strategyMap, "1", i);
|
||||
BizMergeStrategy.fillStrategyMap(strategyMap, "9", i );
|
||||
}
|
||||
}
|
||||
excel = tabSortExcel;
|
||||
}
|
||||
return strategyMap;
|
||||
}
|
||||
|
||||
private static void fillStrategyMap(Map<String, List<RowRangeDto>> strategyMap, String key, int index){
|
||||
List<RowRangeDto> rowRangeDtoList = strategyMap.get(key) == null ? new ArrayList<>() : strategyMap.get(key);
|
||||
boolean flag = false;
|
||||
for (RowRangeDto dto : rowRangeDtoList) {
|
||||
//分段list中是否有end索引是上一行索引的,如果有,则索引+1
|
||||
if (dto.getEnd() == index) {
|
||||
dto.setEnd(index + 1);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
//如果没有,则新增分段
|
||||
if (!flag) {
|
||||
rowRangeDtoList.add(new RowRangeDto(index, index + 1));
|
||||
}
|
||||
strategyMap.put(key, rowRangeDtoList);
|
||||
}
|
||||
|
||||
|
||||
public static HorizontalCellStyleStrategy CellStyleStrategy(){
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
//设置背景颜色
|
||||
headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
||||
//设置头字体
|
||||
WriteFont headWriteFont = new WriteFont();
|
||||
headWriteFont.setFontHeightInPoints((short)13);
|
||||
headWriteFont.setBold(true);
|
||||
headWriteCellStyle.setWriteFont(headWriteFont);
|
||||
//设置头居中
|
||||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
//内容策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
//设置 水平居中
|
||||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
|
||||
return horizontalCellStyleStrategy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,226 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.common.tools.annotation.*;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.IPUtils;
|
||||
import com.ho.common.tools.vo.req.PositionVo;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 业务模块切面
|
||||
* 目前实现日志和token校验
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BusinessAspect {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
SaveLogComponent saveLogComponent;
|
||||
|
||||
/**
|
||||
* 此处的切点是注解的方式
|
||||
* 只要出现 @LogAnnotation注解都会进入
|
||||
* 改为切入点是controller,不然日志记录不清晰,只有LogAnnotation才入库
|
||||
*/
|
||||
//@Pointcut("@annotation(com.ho.common.tools.annotation.LogAnnotation)")
|
||||
@Pointcut("execution(* com.ho.*.controller.*.*(..))")
|
||||
public void pointCut() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 环绕增强,相当于MethodInterceptor
|
||||
*
|
||||
* @param point
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Around("pointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
long beginTime = System.currentTimeMillis();
|
||||
ServletRequestAttributes servletAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletAttributes.getRequest();
|
||||
UserDetailRespVO userDetail = null;
|
||||
SimpleUser simpleUser = null;
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
//是否是token忽略
|
||||
TokenIgnore tokenIgnoreAnnotation = method.getAnnotation(TokenIgnore.class);
|
||||
//是否大屏token
|
||||
LargeScreenToken largeScreenToken = method.getAnnotation(LargeScreenToken.class);
|
||||
//通用大屏
|
||||
CommonLargeScreenToken commonLargeScreenToken = method.getAnnotation(CommonLargeScreenToken.class);
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
log.info("token:" + token);
|
||||
String url = request.getRequestURL().toString();
|
||||
String className = point.getTarget().getClass().getName();
|
||||
String methodName = signature.getName();
|
||||
log.info("请求url:{} ,method:{}, 开始时间: {}", url, method, beginTime);
|
||||
//没有tokenIgnore注解的方法,验证token
|
||||
if (tokenIgnoreAnnotation == null) {
|
||||
//判断token是否有效
|
||||
String tokenKey = checkToken(token);
|
||||
userDetail = (UserDetailRespVO) redisService.get(tokenKey);
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME + userDetail.getLoginChannel() + ":" + userDetail.getUsername();
|
||||
simpleUser = (SimpleUser) redisService.get(userNameKey);
|
||||
if(simpleUser ==null){
|
||||
log.info("User token has expired ! token :{}", token);
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PARSE_ERROR);
|
||||
}
|
||||
log.info("userName: {}, groupId:{}, deptId:{}", userDetail.getUsername(), simpleUser.getGroupId(), simpleUser.getDeptId());
|
||||
//延长token时间
|
||||
redisService.expire(tokenKey, 2, TimeUnit.HOURS);
|
||||
redisService.expire(userNameKey, 2, TimeUnit.HOURS);
|
||||
}
|
||||
//有大屏token(largeScreenToken)的接口 , 因为这个token不过期,并且它的键值对和
|
||||
if (largeScreenToken != null) {
|
||||
String tokenKey = checkLargeToken(token);
|
||||
userDetail = (UserDetailRespVO) redisService.get(tokenKey);
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME_LARGE_SCREEN + "pc:" + userDetail.getUsername();
|
||||
simpleUser = (SimpleUser) redisService.get(userNameKey);
|
||||
log.info("userName: {}, userId: {}, groupId:{}", userDetail.getUsername(), simpleUser.getUserId(), simpleUser.getGroupId());
|
||||
//大屏token做延长有效期,先不让过期
|
||||
redisService.expire(tokenKey, 365, TimeUnit.DAYS);
|
||||
redisService.expire(userNameKey, 365, TimeUnit.DAYS);
|
||||
|
||||
}
|
||||
//有通用大屏接口
|
||||
if(commonLargeScreenToken != null){
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN_COMMON_LARGE_SCREEN + token;
|
||||
simpleUser = (SimpleUser) redisService.get(tokenKey);
|
||||
if( simpleUser != null){
|
||||
redisService.expire(tokenKey, 30, TimeUnit.DAYS);
|
||||
}
|
||||
}
|
||||
// 按钮权限校验
|
||||
HzPermission hzPermission = method.getAnnotation(HzPermission.class);
|
||||
if (null != hzPermission) {
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
userDetail = (UserDetailRespVO) redisService.get(tokenKey);
|
||||
List<String> powerList = userDetail.getPowerList();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String s : powerList) {
|
||||
map.put(s, s);
|
||||
}
|
||||
String[] value = hzPermission.value();
|
||||
String str = null;
|
||||
for (String s : value) {
|
||||
str = map.get(s);
|
||||
if (str != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null == str) {
|
||||
throw new BusinessException(BaseResponseCode.PERMISSION_DENIED);
|
||||
}
|
||||
}
|
||||
//请求参数
|
||||
String params = null;
|
||||
try {
|
||||
//请求的参数
|
||||
Object[] args = point.getArgs();
|
||||
//MultipartFile类型的跳过转Json
|
||||
if (args != null && args.length > 0 && args[0] != null) {
|
||||
String simpleClassName = args[0].getClass().getSimpleName();
|
||||
log.info("SimpleClassName:" + simpleClassName);
|
||||
//不包含文件类型才打印日志
|
||||
if (!StringUtils.isBlank(simpleClassName) && !simpleClassName.contains("Multipart")) {
|
||||
params = JSON.toJSONString(args[0]);
|
||||
log.info("params:" + params);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
log.info("methodName:{}, className:{}", methodName, className);
|
||||
LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
|
||||
//执行目标方法
|
||||
//执行方法
|
||||
Object result = point.proceed();
|
||||
//方法执行结果
|
||||
//log.info("返回:" + JSON.toJSONString(result));
|
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
log.info("耗时:{}, url:{},param:{}", time, url,params);
|
||||
if (time > CommonConstant.timeoutMilliSeconds) {
|
||||
log.error("接口超时: time:{}, url:{},", time,url);
|
||||
}
|
||||
//有日志注解的入库
|
||||
if (logAnnotation != null) {
|
||||
SysLog sysLog = new SysLog();
|
||||
//设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request));
|
||||
//param可能过长,只保留1500字节长度
|
||||
if (params != null && params.length() > 1500) {
|
||||
params = params.substring(0, 1500);
|
||||
}
|
||||
sysLog.setParams(params);
|
||||
sysLog.setMethod(methodName);
|
||||
sysLog.setOperation(logAnnotation.title() + "-" + logAnnotation.action());
|
||||
//保存日志
|
||||
try {
|
||||
log.info(sysLog.toString());
|
||||
saveLogComponent.saveSysLog(sysLog, userDetail, simpleUser, time);
|
||||
} catch (Exception e) {
|
||||
log.error("e={}", e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//验证token
|
||||
private String checkToken(String token) {
|
||||
if (token == null || StringUtils.isEmpty(token)) {
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
|
||||
}
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
if (!redisService.hasKey(tokenKey)) {
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PAST_DUE);
|
||||
}
|
||||
return tokenKey;
|
||||
}
|
||||
|
||||
//验证大屏token
|
||||
private String checkLargeToken(String largeToken) {
|
||||
if (largeToken == null || StringUtils.isEmpty(largeToken)) {
|
||||
throw new BusinessException(BaseResponseCode.INVALID_BIG_SCREEN_TOKEN);
|
||||
}
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN_LARGE_SCREEN + largeToken;
|
||||
if (!redisService.hasKey(tokenKey)) {
|
||||
throw new BusinessException(BaseResponseCode.INVALID_BIG_SCREEN_TOKEN);
|
||||
}
|
||||
return tokenKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: Caffeine配置类
|
||||
* @date 2023/4/14
|
||||
*/
|
||||
@Configuration
|
||||
public class CaffeineConfig extends CaffeineCacheManager{
|
||||
|
||||
//10秒钟的缓存
|
||||
@Bean(name = "tenSecondCacheManager")
|
||||
@Primary
|
||||
public CacheManager tenSecondCacheManager(){
|
||||
Caffeine caffeine = Caffeine.newBuilder()
|
||||
.initialCapacity(50) //初始大小
|
||||
.maximumSize(20000) //最大大小
|
||||
.expireAfterWrite(10 ,TimeUnit.SECONDS); //写入/多久过期
|
||||
|
||||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setAllowNullValues(true);
|
||||
caffeineCacheManager.setCaffeine(caffeine);
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
//30秒钟的缓存
|
||||
@Bean(name = "thirtySecondCacheManager")
|
||||
public CacheManager thirtySecondCacheManager(){
|
||||
Caffeine caffeine = Caffeine.newBuilder()
|
||||
.initialCapacity(50) //初始大小
|
||||
.maximumSize(20000) //最大大小
|
||||
.expireAfterWrite(30 ,TimeUnit.SECONDS); //写入/多久过期
|
||||
|
||||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setAllowNullValues(true);
|
||||
caffeineCacheManager.setCaffeine(caffeine);
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
//2分钟的缓存
|
||||
@Bean(name = "towMinuteCacheManager")
|
||||
public CacheManager towMinuteCacheManager(){
|
||||
Caffeine caffeine = Caffeine.newBuilder()
|
||||
.initialCapacity(50) //初始大小
|
||||
.maximumSize(20000) //最大大小
|
||||
.expireAfterWrite(2, TimeUnit.MINUTES); //写入/多久过期
|
||||
|
||||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setAllowNullValues(true);
|
||||
caffeineCacheManager.setCaffeine(caffeine);
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
//5分钟的缓存
|
||||
@Bean(name = "fiveMinuteCacheManager")
|
||||
public CacheManager fiveMinuteCacheManager(){
|
||||
Caffeine caffeine = Caffeine.newBuilder()
|
||||
.initialCapacity(50) //初始大小
|
||||
.maximumSize(20000) //最大大小
|
||||
.expireAfterWrite(50, TimeUnit.MINUTES); //写入/多久过期
|
||||
|
||||
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
|
||||
caffeineCacheManager.setAllowNullValues(true);
|
||||
caffeineCacheManager.setCaffeine(caffeine);
|
||||
return caffeineCacheManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import org.hibernate.validator.internal.engine.path.PathImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @描述 全局异常处理
|
||||
* @创建人 fancl
|
||||
* @创建时间 2021/2/26
|
||||
* @修改人
|
||||
*/
|
||||
//迁移到common模块中
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
||||
//绑定Exception
|
||||
@ExceptionHandler(Exception.class)
|
||||
public <T> DataResult<T> handle(Exception ex) {
|
||||
|
||||
log.error("业务异常e:", ex);
|
||||
//异常的日志都打印记录
|
||||
log.error(ex.getMessage() + ":" + ex.getMessage());
|
||||
|
||||
|
||||
//DataResult result = new DataResult(BaseResponseCode.OPERATION_ERRO.getCode(), ex.getMessage());
|
||||
DataResult result = new DataResult(BaseResponseCode.OPERATION_ERRO);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//绑定 BusinessException
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public <T> DataResult<T> handler(BusinessException businessException) {
|
||||
log.error("业务 BusinessException 异常e:", businessException);
|
||||
return new DataResult<>(businessException.getMessageCode(), businessException.getDetailMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数校验异常处理类
|
||||
* 参数为实体类
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public DataResult handleBindException(MethodArgumentNotValidException ex) {
|
||||
FieldError fieldError = ex.getBindingResult().getFieldError();
|
||||
log.error("参数校验异常:{}({})", fieldError.getDefaultMessage(), fieldError.getField());
|
||||
DataResult result = new DataResult(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION.getCode(),fieldError.getDefaultMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验 非实体请求参数
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = ConstraintViolationException.class)
|
||||
public DataResult handle(ConstraintViolationException ex) {
|
||||
log.error("业务ConstraintViolationException异常e:", ex);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Set<ConstraintViolation<?>> constraintViolations = ex.getConstraintViolations();
|
||||
for (ConstraintViolation<?> constraintViolation : constraintViolations) {
|
||||
PathImpl pathImpl = (PathImpl) constraintViolation.getPropertyPath();
|
||||
String paramName = pathImpl.getLeafNode().getName();
|
||||
String message = constraintViolation.getMessage();
|
||||
msg.append(message);
|
||||
}
|
||||
log.error(msg.toString(), ex);
|
||||
// 返回参数错误提示
|
||||
return new DataResult(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/10/20
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SaveLogComponent {
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@Autowired
|
||||
UserFeignClient userFeignClient;
|
||||
|
||||
//保存日志
|
||||
@Async
|
||||
public void saveSysLog(SysLog sysLog, UserDetailRespVO user, SimpleUser simpleUser, long time) {
|
||||
sysLog.setId(snowflake.nextId());
|
||||
sysLog.setGroupId(simpleUser.getGroupId());
|
||||
sysLog.setDeptId(simpleUser.getDeptId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setUserId(user.getUserId());
|
||||
sysLog.setTime((int) time);
|
||||
//调用User-center的服务记录日志
|
||||
userFeignClient.insertLog(sysLog);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @description swagger2配置
|
||||
* @date 2022/8/10
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
@Value("${swagger2.projectName}")
|
||||
private String projectName;
|
||||
|
||||
@Value("${swagger2.controllerPath}")
|
||||
private String controllerPath;
|
||||
|
||||
//根据配置启用或关闭swagger接口
|
||||
@Value("${swagger2.enable}")
|
||||
private Boolean enable;
|
||||
|
||||
//Swagger2接口文档版本
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(controllerPath))
|
||||
.paths(PathSelectors.any()) //可以根据url路径设置哪些请求加入文档,忽略哪些请求
|
||||
.build()
|
||||
.enable(enable);
|
||||
}
|
||||
|
||||
public ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(projectName) //设置文档的标题
|
||||
.description("REST API") //设置文档的描述
|
||||
.version(VERSION)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.alibaba.druid.support.http.StatViewServlet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 线程池配置
|
||||
* @date 2023/1/11
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class ThreadPoolConfiguration {
|
||||
|
||||
@Bean
|
||||
ThreadPoolTaskExecutor tdThreadPoolExecutor(){
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
int core = Runtime.getRuntime().availableProcessors();
|
||||
log.info("core:" +core);
|
||||
executor.setCorePoolSize(core);
|
||||
//最大线程数是核心线程数10倍
|
||||
executor.setMaxPoolSize(core * 10);
|
||||
//
|
||||
executor.setKeepAliveSeconds(600);
|
||||
executor.setQueueCapacity(core * 10);
|
||||
executor.setThreadNamePrefix("td-thread-execute");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
ServletRegistrationBean regisDruid() {
|
||||
//固定写法,配置访问路径
|
||||
ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
|
||||
//配置登录信息,固定写法
|
||||
HashMap<String, String> initParams = new HashMap<>();
|
||||
//账号和密码的key是固定的
|
||||
initParams.put("loginUsername", "fan");
|
||||
initParams.put("loginPassword", "111111");
|
||||
|
||||
//允许谁可以访问
|
||||
initParams.put("allow", "");
|
||||
bean.setInitParameters(initParams);
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,174 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.util.RedisCommon;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 时间处理类, 将时间以等值间隔字符串形势存储在redis中
|
||||
* @date 2022/9/15
|
||||
*/
|
||||
//@Component
|
||||
public class TimeIntervalPostConstructor {
|
||||
|
||||
@Autowired
|
||||
RedisCommon redisUtil;
|
||||
|
||||
@PostConstruct
|
||||
public void buildTimeMinutes() {
|
||||
Date date = new Date();
|
||||
//建立5分钟间隔数组
|
||||
List<String> fiveMinutesList = new ArrayList<>(300);
|
||||
List<String> OneMinutesList = new ArrayList<>(1440);
|
||||
List<String> sixtyMinutesList = new ArrayList<>(24);
|
||||
List<String> thirtyMinutesList = new ArrayList<>(48);
|
||||
fiveMinutesList = minute(date, 5);
|
||||
OneMinutesList = minute(date, 1);
|
||||
thirtyMinutesList = minute(date,30);
|
||||
sixtyMinutesList = minute2(date, 60);
|
||||
redisUtil.set(RedisKeyConstant.FIVE_MINUTE_INTERVAL, fiveMinutesList);
|
||||
redisUtil.set(RedisKeyConstant.ONE_MINUTE_INTERVAL, OneMinutesList);
|
||||
redisUtil.set(RedisKeyConstant.SIXTY_MINUTE_INTERVAL,sixtyMinutesList);
|
||||
redisUtil.set(RedisKeyConstant.THIRTY_MINUTE_INTERVAL,thirtyMinutesList);
|
||||
}
|
||||
|
||||
//增加每月每天日期 和 增加每年的12个月
|
||||
@PostConstruct
|
||||
public void buildTimeDaysAndMonth() {
|
||||
//每月每天
|
||||
Date date = new Date();
|
||||
List<String> currentMonthList = new ArrayList<>(getCurrentMonthLastDay());
|
||||
currentMonthList = day(date, 1);
|
||||
redisUtil.set(RedisKeyConstant.ONE_DAY_INTERVAL,currentMonthList);
|
||||
//每年每月
|
||||
Date dateMonth = new Date();
|
||||
List<String> currentYearMonthList = new ArrayList<>(20);
|
||||
currentYearMonthList = month(date, 1);
|
||||
redisUtil.set(RedisKeyConstant.MONTH_INTERVAL,currentYearMonthList);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//时间字符串格式(以分钟为单位)
|
||||
static List<String> minute(Date date, int offset) {
|
||||
Date start = dayStartDate(date);//转换为天的起始date
|
||||
Date nextDayDate = nextDay(start);//下一天的date
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
List<String> result = new ArrayList<>(720);
|
||||
while (start.compareTo(nextDayDate) < 0) {
|
||||
result.add(sdf.format(start));
|
||||
//日期加5分钟
|
||||
start = addMinutes(start, offset);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//年月日时分秒
|
||||
static List<String> minute2(Date date, int offset) {
|
||||
Date start = dayStartDate(date);//转换为天的起始date
|
||||
Date nextDayDate = nextDay(start);//下一天的date
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
List<String> result = new ArrayList<>(20);
|
||||
while (start.compareTo(nextDayDate) < 0) {
|
||||
result.add(sdf.format(start));
|
||||
//日期加5分钟
|
||||
start = addMinutes(start, offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//以天为单位
|
||||
static List<String> day(Date date, int offset) {
|
||||
Date start = DateUtil.beginOfMonth(date);//转换为天的起始date
|
||||
Date nextDayDate = DateUtil.endOfMonth(date);//下一天的date
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
List<String> result = new ArrayList<>(getCurrentMonthLastDay());
|
||||
while (start.compareTo(nextDayDate) < 0) {
|
||||
result.add(sdf.format(start));
|
||||
//日期加一天
|
||||
start = addDays(start, offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//以月为单位
|
||||
static List<String> month(Date date, int offset) {
|
||||
Date start = DateUtil.beginOfYear(date);//转换为天的起始date
|
||||
Date nextDayDate = DateUtil.endOfYear(date);//下一天的date
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
||||
List<String> result = new ArrayList<>(20);
|
||||
while (start.compareTo(nextDayDate) < 0) {
|
||||
result.add(sdf.format(start));
|
||||
//加一个月
|
||||
start = addMonth(start, offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//增加时间间隔
|
||||
private static Date addMinutes(Date start, int offset) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(start);
|
||||
c.add(Calendar.MINUTE, offset);
|
||||
return c.getTime();
|
||||
}
|
||||
private static Date addDays(Date start, int offset) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(start);
|
||||
c.add(Calendar.DAY_OF_MONTH, offset);
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
private static Date addMonth(Date start, int offset) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(start);
|
||||
c.add(Calendar.MONTH, offset);
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
private static Date nextDay(Date start) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(start);
|
||||
c.add(Calendar.DATE, 1);
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
private static Date dayStartDate(Date date) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
return c.getTime();
|
||||
}
|
||||
|
||||
public static int getCurrentMonthLastDay()
|
||||
{
|
||||
Calendar a = Calendar.getInstance();
|
||||
a.set(Calendar.DATE, 1);//把日期设置为当月第一天
|
||||
a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
|
||||
int maxDate = a.get(Calendar.DATE);
|
||||
return maxDate;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Date dateMonth = new Date();
|
||||
List<String> currentYearMonthList = new ArrayList<>(20);
|
||||
currentYearMonthList = month(dateMonth, 1);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||
|
||||
@Configuration
|
||||
public class WebSocketConfig {
|
||||
@Bean
|
||||
public ServerEndpointExporter serverEndpointExporter(){
|
||||
return new ServerEndpointExporter();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package com.ho.business.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.datacollect.api.constant.DataCollectConstant;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@ServerEndpoint(value = "/websocket")
|
||||
@Component
|
||||
@Slf4j
|
||||
public class WebSocketServer {
|
||||
|
||||
//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
|
||||
private static int onlineCount = 0;
|
||||
|
||||
//concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
|
||||
private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();
|
||||
|
||||
public static ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
|
||||
//与某个客户端的连接会话,需要通过它来给客户端发送数据
|
||||
private Session session;
|
||||
|
||||
/**
|
||||
* 连接建立成功调用的方法
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session) {
|
||||
this.session = session;
|
||||
webSocketSet.add(this); //加入set中
|
||||
addOnlineCount(); //在线数加1
|
||||
System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
|
||||
try {
|
||||
sendMessage("SUCCESS");
|
||||
} catch (IOException e) {
|
||||
System.out.println("IO异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭调用的方法
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose() {
|
||||
webSocketSet.remove(this); //从set中删除
|
||||
subOnlineCount(); //在线数减1
|
||||
map.remove(this.session.getId());
|
||||
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到客户端消息后调用的方法
|
||||
*
|
||||
* @param message 客户端发送过来的消息
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
System.out.println("来自客户端的消息:" + message);
|
||||
//群发消息
|
||||
for (WebSocketServer item : webSocketSet) {
|
||||
try {
|
||||
if (session.equals(item.session)) {
|
||||
JSONObject jsonObject = (JSONObject) JSONObject.parse(message);
|
||||
if (jsonObject.containsKey(DataCollectConstant.STATION_ID)) {
|
||||
map.put(session.getId(), jsonObject.get(DataCollectConstant.STATION_ID) + "," + jsonObject.get(CommonConstant.METHOD));
|
||||
}
|
||||
item.sendMessage("来自服务器回应:"+message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发生错误时调用
|
||||
*
|
||||
* @param session
|
||||
* @param error
|
||||
*/
|
||||
@OnError
|
||||
public void onError(Session session, Throwable error) {
|
||||
System.out.println("发生错误");
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
public void sendMessage(String message) throws IOException {
|
||||
this.session.getBasicRemote().sendText(message);
|
||||
//this.session.getAsyncRemote().sendText(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 群发自定义消息
|
||||
*/
|
||||
public static void sendInfo(String id, String message) throws IOException {
|
||||
for (WebSocketServer item : webSocketSet) {
|
||||
try {
|
||||
if (item.session.getId().equals(id)) {
|
||||
item.sendMessage(message);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized int getOnlineCount() {
|
||||
return onlineCount;
|
||||
}
|
||||
|
||||
public static synchronized void addOnlineCount() {
|
||||
WebSocketServer.onlineCount++;
|
||||
}
|
||||
|
||||
public static synchronized void subOnlineCount() {
|
||||
WebSocketServer.onlineCount--;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,309 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.entity.DeviceTypeCol;
|
||||
import com.ho.business.entity.DeviceTypeConfig;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.AutoDeviceCurveService;
|
||||
import com.ho.business.service.DeviceTypeColService;
|
||||
import com.ho.business.service.DeviceTypeConfigService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.AutoDeviceCurveVo;
|
||||
import com.ho.business.vo.SingleValueColVo;
|
||||
import com.ho.business.vo.req.device.DeviceTypeQuery;
|
||||
import com.ho.business.vo.resp.point.PointCurveHomeResp;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.vo.req.StationHomeRespVo;
|
||||
import com.ho.td.api.entity.query.TdBaseTimeQuery;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author catkins
|
||||
* @date 2023年10月23日 15:40
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "autoDeviceCurve")
|
||||
@Api(tags = "多媒体-自动化设备测试-曲线通用查询")
|
||||
@Slf4j
|
||||
public class AutoDeviceCurveController {
|
||||
|
||||
@Autowired
|
||||
private AutoDeviceCurveService autoDeviceCurveService;
|
||||
|
||||
@Autowired
|
||||
private DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
@Autowired
|
||||
private StationService stationService;
|
||||
|
||||
@Autowired
|
||||
DeviceTypeColService deviceTypeColService;
|
||||
|
||||
|
||||
@PostMapping("queryCurve")
|
||||
@ApiOperation(value = "查询两个曲线的差值/查询单条曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<List<StationHomeRespVo>> queryCurve(@RequestBody AutoDeviceCurveVo vo) {
|
||||
if (vo == null) {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
Integer stationId = vo.getStationId();
|
||||
String deviceType = vo.getDeviceType();
|
||||
|
||||
// 根据电站id查询电站详细信息
|
||||
Station station = stationService.selectById(stationId);
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.selectByDeviceType(deviceType, station.getGroupId());
|
||||
|
||||
/** todo: 组装第一个col的td查询参数 */
|
||||
/** start */
|
||||
TdBaseTimeQuery col_1_td_query = null;
|
||||
String col1 = vo.getCol1();
|
||||
if (StringUtil.isNotEmpty(col1)) {
|
||||
vo.setCol(vo.getCol1());
|
||||
col_1_td_query = processParams(vo, station, deviceTypeConfig);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
|
||||
// 如果第一个结果集就为空则不往下继续,直接返回空结果
|
||||
if( col_1_td_query == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
List<StationHomeRespVo> vos_1 = autoDeviceCurveService.queryData(col_1_td_query);
|
||||
/** end */
|
||||
|
||||
/** todo: 组装第二个col的td查询参数 */
|
||||
/** start */
|
||||
TdBaseTimeQuery col_2_td_query = null;
|
||||
String col2 = vo.getCol2();
|
||||
if (StringUtil.isNotEmpty(col2)) {
|
||||
vo.setCol(vo.getCol2());
|
||||
col_2_td_query = processParams(vo, station, deviceTypeConfig);
|
||||
}
|
||||
List<StationHomeRespVo> vos_2 = null;
|
||||
if ( col_2_td_query != null ) {
|
||||
vos_2 = autoDeviceCurveService.queryData(col_2_td_query);
|
||||
}
|
||||
/** end */
|
||||
String startTime = vo.getStartTime();
|
||||
String endTime = vo.getEndTime();
|
||||
List<String> min = getMin(DateUtil.parse(startTime), DateUtil.parse(endTime), vo.getInterval());
|
||||
|
||||
List<StationHomeRespVo> curve = autoDeviceCurveService.getCurve(vos_1, vos_2,min);
|
||||
//根据登录人设置集团id和用户id
|
||||
return DataResult.success(curve);
|
||||
}
|
||||
|
||||
@PostMapping("getOneValue")
|
||||
@ApiOperation(value = "查询单个值")
|
||||
@TokenIgnore
|
||||
public DataResult<BigDecimal> getOneValue(@RequestBody AutoDeviceCurveVo vo) {
|
||||
|
||||
Integer stationId = vo.getStationId();
|
||||
String deviceType = vo.getDeviceType();
|
||||
|
||||
// 根据电站id查询电站详细信息
|
||||
Station station = stationService.selectById(stationId);
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.selectByDeviceType(deviceType, station.getGroupId());
|
||||
|
||||
/** todo: 组装td查询参数 */
|
||||
/** start */
|
||||
TdBaseTimeQuery col_1_td_query = null;
|
||||
String col1 = vo.getCol1();
|
||||
if (StringUtil.isNotEmpty(col1)) {
|
||||
vo.setCol(vo.getCol1());
|
||||
col_1_td_query = processParams(vo, station, deviceTypeConfig);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
|
||||
if( col_1_td_query == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
List<StationHomeRespVo> vos_1 = autoDeviceCurveService.queryData(col_1_td_query);
|
||||
/** end */
|
||||
BigDecimal oneValue = autoDeviceCurveService.getOneValue(vos_1);
|
||||
|
||||
return DataResult.success(oneValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理td数据库查询参数方法
|
||||
* @param vo
|
||||
* @param station
|
||||
* @param deviceTypeConfig
|
||||
* @return
|
||||
*/
|
||||
private TdBaseTimeQuery processParams(AutoDeviceCurveVo vo, Station station, DeviceTypeConfig deviceTypeConfig) {
|
||||
if (vo == null) {
|
||||
return null;
|
||||
}
|
||||
TdBaseTimeQuery tdBaseQuery = new TdBaseTimeQuery();
|
||||
tdBaseQuery = new TdBaseTimeQuery();
|
||||
tdBaseQuery.setBeginTime(vo.getStartTime());
|
||||
tdBaseQuery.setEndTime(vo.getEndTime());
|
||||
tdBaseQuery.setTime("1m");
|
||||
tdBaseQuery.setStationId(station.getId());
|
||||
tdBaseQuery.setGroupId(station.getGroupId());
|
||||
tdBaseQuery.setTableName(deviceTypeConfig.getModelName());
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(station.getGroupId());
|
||||
deviceTypeQuery.setDeviceType(vo.getDeviceType());
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
if (deviceTypeConfigs == null || deviceTypeConfigs.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
tdBaseQuery.setModelName(deviceTypeConfigs.get(0).getModelName());
|
||||
String deviceCol = vo.getCol();
|
||||
tdBaseQuery.setCol(deviceCol);
|
||||
Integer srcId = autoDeviceCurveService.getSrcIdByStationId(station.getId(), vo.getDeviceType());
|
||||
tdBaseQuery.setSrcId(srcId);
|
||||
return tdBaseQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照指定分钟间隔获取两个时间段内所有时间字符串集合
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @param delay 间隔的分钟数
|
||||
* @return
|
||||
*/
|
||||
private List<String> getMin(Date startDate, Date endDate, int delay) {
|
||||
List<String> allMin = new ArrayList<>();
|
||||
Calendar t1 = Calendar.getInstance();
|
||||
t1.setTime(startDate);//开始时间
|
||||
Calendar t2 = Calendar.getInstance();
|
||||
t2.setTime(endDate);//结束时间
|
||||
for (; t1.compareTo(t2) < 0; t1.add(Calendar.MINUTE, delay)) {
|
||||
allMin.add(DateUtil.format(t1.getTime(), "yyyy-MM-dd HH:mm"));
|
||||
}
|
||||
return allMin;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("queryCurveNew")
|
||||
@ApiOperation(value = "查询两个曲线的差值/查询单条曲线,返回的对象是一个包含点位定义的符合对象")
|
||||
@TokenIgnore
|
||||
public DataResult<List<PointCurveHomeResp>> queryCurveNew(@RequestBody List<AutoDeviceCurveVo> voList) {
|
||||
//创建返回对象
|
||||
List<PointCurveHomeResp> list = new ArrayList<>();
|
||||
if(voList!=null && !voList.isEmpty()){
|
||||
for (AutoDeviceCurveVo vo : voList) {
|
||||
PointCurveHomeResp homeVo = getHomeVo(vo);
|
||||
if(homeVo!=null){
|
||||
list.add(homeVo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
//获取曲线返回对象
|
||||
private PointCurveHomeResp getHomeVo(AutoDeviceCurveVo vo){
|
||||
if (vo == null) {
|
||||
return null;
|
||||
}
|
||||
//创建返回对象
|
||||
PointCurveHomeResp pointCurveHomeResp = new PointCurveHomeResp();
|
||||
Integer stationId = vo.getStationId();
|
||||
String deviceType = vo.getDeviceType();
|
||||
|
||||
// 根据电站id查询电站详细信息
|
||||
Station station = stationService.selectById(stationId);
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.selectByDeviceType(deviceType, station.getGroupId());
|
||||
//有设备类型才做后面的事
|
||||
if(deviceTypeConfig == null){
|
||||
log.error("查询设备类型配置为空, deviceType:{} , groupId: {}" ,deviceType,station.getGroupId() );
|
||||
return null;
|
||||
}
|
||||
//查点定义
|
||||
DeviceTypeCol deviceTypeCol = deviceTypeColService.selectTypeAndCol(vo.getCol1(), vo.getDeviceType());
|
||||
pointCurveHomeResp.setDeviceName(deviceTypeConfig.getName());
|
||||
if(deviceTypeCol!=null){
|
||||
pointCurveHomeResp.setCol(vo.getCol1());
|
||||
pointCurveHomeResp.setColName(deviceTypeCol.getColName());
|
||||
}
|
||||
/** todo: 组装第一个col的td查询参数 */
|
||||
/** start */
|
||||
TdBaseTimeQuery col_1_td_query = null;
|
||||
String col1 = vo.getCol1();
|
||||
if (StringUtil.isNotEmpty(col1)) {
|
||||
vo.setCol(vo.getCol1());
|
||||
col_1_td_query = processParams(vo, station, deviceTypeConfig);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
|
||||
// 如果第一个结果集就为空则不往下继续,直接返回空结果
|
||||
if( col_1_td_query == null ){
|
||||
log.error("col_1_td_query is null");
|
||||
return null;
|
||||
}
|
||||
List<StationHomeRespVo> curve = autoDeviceCurveService.queryData(col_1_td_query);
|
||||
pointCurveHomeResp.setStaticCurveList(curve);
|
||||
return pointCurveHomeResp;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("getOneValueNew")
|
||||
@ApiOperation(value = "查询单个值 返回复合对象")
|
||||
@TokenIgnore
|
||||
public DataResult<SingleValueColVo> getOneValueNew(@RequestBody AutoDeviceCurveVo vo) {
|
||||
|
||||
Integer stationId = vo.getStationId();
|
||||
String deviceType = vo.getDeviceType();
|
||||
// 根据电站id查询电站详细信息
|
||||
Station station = stationService.selectById(stationId);
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.selectByDeviceType(deviceType, station.getGroupId());
|
||||
|
||||
/** todo: 组装td查询参数 */
|
||||
/** start */
|
||||
TdBaseTimeQuery col_1_td_query = null;
|
||||
String col1 = vo.getCol1();
|
||||
if (StringUtil.isNotEmpty(col1)) {
|
||||
vo.setCol(vo.getCol1());
|
||||
col_1_td_query = processParams(vo, station, deviceTypeConfig);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
if( col_1_td_query == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
List<StationHomeRespVo> vos_1 = autoDeviceCurveService.queryData(col_1_td_query);
|
||||
/** end */
|
||||
BigDecimal oneValue = autoDeviceCurveService.getOneValue(vos_1);
|
||||
//查点对应的点表信息
|
||||
//因为配置的点是不带站结尾,所以需要拼接 deviceType
|
||||
DeviceTypeCol deviceTypeCol = deviceTypeColService.selectTypeAndCol(col1, deviceType);
|
||||
SingleValueColVo singleValueColVo = new SingleValueColVo();
|
||||
if(deviceTypeCol!=null){
|
||||
BeanUtil.copyProperties(deviceTypeCol,singleValueColVo);
|
||||
}
|
||||
singleValueColVo.setValue(oneValue);
|
||||
return DataResult.success(singleValueColVo);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.BatteryStackService;
|
||||
import com.ho.business.vo.req.batteryStack.CurveReqVo;
|
||||
import com.ho.business.vo.resp.batteryStack.CurveRespVo;
|
||||
import com.ho.business.vo.resp.point.PointCurveResp;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.vo.req.StationHomeRespVo;
|
||||
import com.ho.common.tools.vo.req.StatisticsCurve;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 电池堆控制层
|
||||
* @DateTime: 2023/5/8 10:58
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "batteryStack")
|
||||
@Api(tags = "电池堆")
|
||||
@Slf4j
|
||||
public class BatteryStackController {
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
BatteryStackService batteryStackService;
|
||||
|
||||
|
||||
//温湿度 (抽样)
|
||||
@PostMapping("/universalCurve")
|
||||
@ApiOperation(value = "通用曲线")
|
||||
public DataResult<List<CurveRespVo>> universalCurve(@RequestBody CurveReqVo vo) {
|
||||
List<CurveRespVo> resList = batteryStackService.getUniversalCurve(vo);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (CurveRespVo curveRespVo : resList) {
|
||||
List<StationHomeRespVo> list = curveRespVo.getStaticCurveList();
|
||||
for (StationHomeRespVo stationHomeRespVo : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
|
||||
//bigDecimalUtil.ifIsNUll(stationHomeRespVo);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@PostMapping("/socCurve")
|
||||
@ApiOperation(value = "soc曲线")
|
||||
public DataResult<List<CurveRespVo>> socCurve(@RequestBody CurveReqVo vo) {
|
||||
List<CurveRespVo> resList = batteryStackService.getSocCurve(vo);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (CurveRespVo curveRespVo : resList) {
|
||||
List<StationHomeRespVo> list = curveRespVo.getStaticCurveList();
|
||||
for (StationHomeRespVo stationHomeRespVo : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
|
||||
//bigDecimalUtil.ifIsNUll(stationHomeRespVo);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
//历史曲线
|
||||
@PostMapping("/stackHisData")
|
||||
@ApiOperation(value = "历史数据")
|
||||
public DataResult<List<PointCurveResp>> stackHisData(@RequestBody CurveReqVo vo) {
|
||||
List<PointCurveResp> resList = batteryStackService.getStackHisData(vo);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (PointCurveResp pointCurveResp : resList) {
|
||||
List<StatisticsCurve> staticCurveList = pointCurveResp.getStaticCurveList();
|
||||
for (StatisticsCurve statisticsRespVO : staticCurveList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(statisticsRespVO);
|
||||
//bigDecimalUtil.ifIsNUll(statisticsRespVO);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.business.entity.Device;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.ModelDeviceService;
|
||||
import com.ho.business.vo.req.point.PointReqVO;
|
||||
import com.ho.business.vo.resp.point.BmsCellResp;
|
||||
import com.ho.business.vo.resp.point.BmsClusterResp;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: BMS点表页面
|
||||
* @date 2023/4/25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "bmsPcs")
|
||||
@Api(tags = "BMS PCS点表")
|
||||
@Slf4j
|
||||
public class BmsController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
ModelDeviceService modelDeviceService;
|
||||
|
||||
@PostMapping("getBmsCluster")
|
||||
@ApiOperation(value = "BMS簇页面数据")
|
||||
public DataResult<BmsClusterResp> getBmsCluster(@RequestBody @Valid PointReqVO pointReq) {
|
||||
if (pointReq.getStationId() == null || pointReq.getSrcId() == null) {
|
||||
throw new BusinessException(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION);
|
||||
}
|
||||
//根据设备查询设备类型
|
||||
Device device = deviceService.selectByStationIdAndSrcId(pointReq.getStationId(), pointReq.getSrcId());
|
||||
if (device == null) {
|
||||
throw new BusinessException(BaseResponseCode.CORRESPONDING_DEVICE_DOES_NOT_EXIST);
|
||||
}
|
||||
if (device.getDeviceType() == null) {
|
||||
throw new BusinessException(BaseResponseCode.DEVICE_TYPE_NOT_CONFIG);
|
||||
}
|
||||
String deviceType = device.getDeviceType();
|
||||
//从redis取数据
|
||||
String key = deviceType + ":" + pointReq.getStationId() + ":" + pointReq.getSrcId();
|
||||
Object o = redisService.hgetall(key);
|
||||
HashMap<String, Object> map = (HashMap) o;
|
||||
BmsClusterResp bmsClusterResp = JSON.parseObject(JSON.toJSONString(map), BmsClusterResp.class);
|
||||
return DataResult.success(bmsClusterResp);
|
||||
}
|
||||
|
||||
@PostMapping("getPcsCell")
|
||||
@ApiOperation(value = "Pcs单体电池页面数据")
|
||||
public DataResult<BmsCellResp> getPcsCell(@RequestBody @Valid PointReqVO pointReq) {
|
||||
if (pointReq.getStationId() == null || pointReq.getSrcId() == null) {
|
||||
throw new BusinessException(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION);
|
||||
}
|
||||
//根据设备查询设备类型
|
||||
Device device = deviceService.selectByStationIdAndSrcId(pointReq.getStationId(), pointReq.getSrcId());
|
||||
if (device == null) {
|
||||
throw new BusinessException(BaseResponseCode.CORRESPONDING_DEVICE_DOES_NOT_EXIST);
|
||||
}
|
||||
String deviceType = device.getDeviceType();
|
||||
//从redis取数据
|
||||
String key = deviceType + ":" + pointReq.getStationId() + ":" + pointReq.getSrcId();
|
||||
Object o = redisService.hgetall(key);
|
||||
HashMap<String, Object> map = (HashMap) o;
|
||||
BmsCellResp bmsCellResp = JSON.parseObject(JSON.toJSONString(map), BmsCellResp.class);
|
||||
return DataResult.success(bmsCellResp);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,355 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.vo.DeviceTransfer;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.bozhou.AirBozhouResp;
|
||||
import com.ho.business.vo.resp.bozhou.BoZhouStationStatus;
|
||||
import com.ho.business.vo.resp.bozhou.StationDataResp;
|
||||
import com.ho.business.vo.resp.point.WareHouse;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.datacollect.api.constant.DataCollectConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 亳州Controller
|
||||
* @date 2023/5/17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "bozhou")
|
||||
@Api(tags = "亳州首页")
|
||||
@Slf4j
|
||||
@Data
|
||||
public class BoZhouController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@PostMapping("/status")
|
||||
@ApiOperation(value = "站首页的中间部分")
|
||||
public DataResult<BoZhouStationStatus> getStatus(@RequestBody StationReq req) {
|
||||
Integer stationId = req.getStationId();
|
||||
BoZhouStationStatus stationStatus = new BoZhouStationStatus();
|
||||
//先查这个站下的PCS
|
||||
List<DeviceRespVO> airList = deviceService.getListByDeviceType(req.getStationId(), DeviceTypeConstant.PCS);
|
||||
if (airList.isEmpty()) {
|
||||
airList = deviceService.getListByFuzzyDeviceType(stationId, DeviceTypeConstant.PCS);
|
||||
}
|
||||
if (!airList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = airList.get(0);
|
||||
//在缓存里拿映射字段
|
||||
String key = deviceRespVO.getDeviceType() + ":" + deviceRespVO.getStationId() + ":" + deviceRespVO.getSrcId();
|
||||
stationStatus.setFlowDirection(deviceRespVO.getFlowDirection());
|
||||
Map<Object, Object> map = redisService.hgetall(key);
|
||||
if (map != null) {
|
||||
DeviceTransfer deviceStateStandDeviceTransfer = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.deviceStateStand);
|
||||
DeviceTransfer runningStateDeviceTransfer = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.runningState);
|
||||
DeviceTransfer remoteInPlaceDeviceTransfer = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.remoteInPlace);
|
||||
DeviceTransfer runStateDeviceTransfer = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.runState);
|
||||
//停机
|
||||
if (runStateDeviceTransfer != null && runStateDeviceTransfer.getValue() != null) {
|
||||
if (BigDecimal.ONE.compareTo(runStateDeviceTransfer.getValue()) == 0) {
|
||||
//
|
||||
stationStatus.setWorkStatus(0);
|
||||
}
|
||||
}
|
||||
//待机
|
||||
if (deviceStateStandDeviceTransfer != null && deviceStateStandDeviceTransfer.getValue() != null) {
|
||||
|
||||
if (BigDecimal.ONE.compareTo(deviceStateStandDeviceTransfer.getValue()) == 0) {
|
||||
//
|
||||
stationStatus.setWorkStatus(1);
|
||||
}
|
||||
}
|
||||
//运行
|
||||
if (runningStateDeviceTransfer != null && runningStateDeviceTransfer.getValue() != null) {
|
||||
if (BigDecimal.ONE.compareTo(runningStateDeviceTransfer.getValue()) == 0) {
|
||||
//
|
||||
stationStatus.setWorkStatus(2);
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceStateStandDeviceTransfer != null && deviceStateStandDeviceTransfer.getValue() != null) {
|
||||
//stationStatus.setDeviceStateStand(deviceStateStandDeviceTransfer.getValue().intValue());
|
||||
}
|
||||
|
||||
if (runningStateDeviceTransfer != null && runningStateDeviceTransfer.getValue() != null) {
|
||||
//stationStatus.setOnGrid(onGridDeviceTransfer.getValue().intValue());
|
||||
}
|
||||
if (remoteInPlaceDeviceTransfer != null && remoteInPlaceDeviceTransfer.getValue() != null) {
|
||||
stationStatus.setRemoteInPlace(remoteInPlaceDeviceTransfer.getValue().intValue());
|
||||
}
|
||||
//另外4个
|
||||
WareHouse bms = getBms(stationId);
|
||||
if (bms != null) {
|
||||
BigDecimal soc = bms.getSoc();
|
||||
BigDecimal soh = bms.getSoh();
|
||||
if (soc != null) {
|
||||
String result = String.format("%.3f", soc);
|
||||
stationStatus.setSoc(new BigDecimal(result));
|
||||
}
|
||||
if (soh != null) {
|
||||
String result = String.format("%.3f", soh);
|
||||
stationStatus.setSoh(new BigDecimal(result));
|
||||
}
|
||||
}
|
||||
DeviceTransfer outputPower = (DeviceTransfer) redisService.hget(key, "outputPower");
|
||||
DeviceTransfer reactivePowerPCS = (DeviceTransfer) redisService.hget(key, "reactivePowerPCS");
|
||||
if (outputPower != null) {
|
||||
stationStatus.setActivePowerPCS(outputPower.getValue().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
if (reactivePowerPCS != null) {
|
||||
stationStatus.setReactivePowerPCS(reactivePowerPCS.getValue().setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DataResult.success(stationStatus);
|
||||
}
|
||||
|
||||
@PostMapping("/stationData")
|
||||
@ApiOperation(value = "电站数据")
|
||||
public DataResult<StationDataResp> stationData(@RequestBody StationReq stationReq) {
|
||||
StationDataResp bozhou = new StationDataResp();
|
||||
List<DeviceRespVO> deviceList = deviceService.getListByDeviceType(stationReq.getStationId(), DeviceTypeConstant.PCS);
|
||||
//累计充放电量
|
||||
List<DeviceRespVO> bmsList = deviceService.getListByDeviceType(stationReq.getStationId(), DeviceTypeConstant.BMS);
|
||||
|
||||
if (!deviceList.isEmpty()) {
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
String key = deviceRespVO.getDeviceType() + ":" + deviceRespVO.getStationId() + ":" + deviceRespVO.getSrcId();
|
||||
Map<Object, Object> map = redisService.hgetall(key);
|
||||
DeviceTransfer allowableChargePower = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ALLOWABLE_CHARGE_POWER);
|
||||
DeviceTransfer allowableDischargePower = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ALLOWABLE_DISCHARGE_POWER);
|
||||
//DeviceTransfer accumulatedChargePowerLow = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ACCUMULATED_CHARGE_POWER_LOW);
|
||||
DeviceTransfer accumulatedChargePowerHigh = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ACCUMULATED_CHARGE_POWER_HIGH);
|
||||
//DeviceTransfer accumulatedDischargePowerLow = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ACCUMULATED_DISCHARGE_POWER_LOW);
|
||||
DeviceTransfer accumulatedDischargePowerHigh = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.ACCUMULATED_DISCHARGE_POWER_HIGH);
|
||||
|
||||
if (allowableChargePower != null) {
|
||||
bozhou.setAllowableChargePower(allowableChargePower.getValue());
|
||||
}
|
||||
if (allowableDischargePower != null) {
|
||||
bozhou.setAllowableDischargePower(allowableDischargePower.getValue());
|
||||
}
|
||||
// if (accumulatedChargePowerLow != null) {
|
||||
// bozhou.setAccumulatedChargePowerLow(accumulatedChargePowerLow.getValue());
|
||||
// }
|
||||
if (accumulatedChargePowerHigh != null) {
|
||||
bozhou.setAccumulatedChargePowerHigh(accumulatedChargePowerHigh.getValue());
|
||||
}
|
||||
/*if (accumulatedDischargePowerLow != null) {
|
||||
bozhou.setAccumulatedDischargePowerLow(accumulatedDischargePowerLow.getValue());
|
||||
}*/
|
||||
if (accumulatedDischargePowerHigh != null) {
|
||||
bozhou.setAccumulatedDischargePowerHigh(accumulatedDischargePowerHigh.getValue());
|
||||
}
|
||||
//有功,无功
|
||||
DeviceTransfer outputPower = (DeviceTransfer) map.get("outputPower");
|
||||
DeviceTransfer reactivePowerPCS = (DeviceTransfer) map.get("reactivePowerPCS");
|
||||
if(outputPower!=null){
|
||||
bozhou.setOutputPower(outputPower.getValue());
|
||||
}
|
||||
if(reactivePowerPCS!=null){
|
||||
bozhou.setReactivePowerPCS(reactivePowerPCS.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
//累计充放电
|
||||
if (!bmsList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = bmsList.get(0);
|
||||
//累计充放电
|
||||
String key = deviceRespVO.getDeviceType() + ":" + deviceRespVO.getStationId() + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
DeviceTransfer totalCharge = (DeviceTransfer) redisService.hget(key, "totalCharge");
|
||||
DeviceTransfer totalDischarge = (DeviceTransfer) redisService.hget(key, "totalDischarge");
|
||||
if (totalCharge != null) {
|
||||
BigDecimal value = totalCharge.getValue();
|
||||
if (value.compareTo(BigDecimal.ZERO) < 0) {
|
||||
value = new BigDecimal(65536).add(value);
|
||||
}
|
||||
bozhou.setAccumulatedChargePowerLow(value);
|
||||
}
|
||||
if (totalDischarge != null) {
|
||||
BigDecimal value = totalDischarge.getValue();
|
||||
if (value.compareTo(BigDecimal.ZERO) < 0) {
|
||||
value = new BigDecimal(65536).add(value);
|
||||
}
|
||||
bozhou.setAccumulatedDischargePowerLow(value);
|
||||
}
|
||||
DeviceTransfer soc = (DeviceTransfer) redisService.hget(key, "soc");
|
||||
if(soc!=null){
|
||||
bozhou.setSoc(soc.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
deviceList = deviceService.getListByDeviceType(stationReq.getStationId(), DeviceTypeConstant.ELE_METER);
|
||||
if (!deviceList.isEmpty()) {
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
String key = deviceRespVO.getDeviceType() + ":" + deviceRespVO.getStationId() + ":" + deviceRespVO.getSrcId();
|
||||
Map<Object, Object> map = redisService.hgetall(key);
|
||||
DeviceTransfer gridF = (DeviceTransfer) map.get(DataCollectConstant.PCS_POINT.GRID_F);
|
||||
if (gridF != null) {
|
||||
bozhou.setGridF(gridF.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
bigDecimalUtil.keepDecimalPlaces(bozhou, 3);
|
||||
return DataResult.success(bozhou);
|
||||
}
|
||||
|
||||
@PostMapping("/airCondition")
|
||||
@ApiOperation(value = "空调")
|
||||
public DataResult<AirBozhouResp> airCondition(@RequestBody StationReq stationReq) {
|
||||
AirBozhouResp bozhou = new AirBozhouResp();
|
||||
Integer stationId = stationReq.getStationId();
|
||||
//先查这个站下的空调
|
||||
List<DeviceRespVO> airList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.AIR_CONDITION);
|
||||
if (!airList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = airList.get(0);
|
||||
//在缓存里拿映射字段
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
Map<Object, Object> infos = redisService.hgetall(key);
|
||||
//分别拿8个字段
|
||||
//空调室内温度
|
||||
DeviceTransfer airconditionInnerTemperature = (DeviceTransfer) infos.get("airconditionInnerTemperature");
|
||||
BigDecimal airconditionInnerTemperatureBig = BigDecimal.ZERO;
|
||||
if (airconditionInnerTemperature != null) {
|
||||
airconditionInnerTemperatureBig = airconditionInnerTemperature.getValue();
|
||||
if (airconditionInnerTemperatureBig != null) {
|
||||
String result = String.format("%.2f", airconditionInnerTemperatureBig);
|
||||
airconditionInnerTemperatureBig = new BigDecimal(result);
|
||||
}
|
||||
}
|
||||
bozhou.setAirconditionInnerTemperature(airconditionInnerTemperatureBig);
|
||||
//空调冷凝/环境温度
|
||||
DeviceTransfer airconditionEnvTemperature = (DeviceTransfer) infos.get("airconditionEnvTemperature");
|
||||
BigDecimal airconditionEnvTemperatureBig = BigDecimal.ZERO;
|
||||
if (airconditionEnvTemperature != null) {
|
||||
airconditionEnvTemperatureBig = airconditionEnvTemperature.getValue();
|
||||
if (airconditionEnvTemperatureBig != null) {
|
||||
String result = String.format("%.2f", airconditionEnvTemperatureBig);
|
||||
airconditionEnvTemperatureBig = new BigDecimal(result);
|
||||
}
|
||||
}
|
||||
bozhou.setAirconditionEnvTemperature(airconditionEnvTemperatureBig);
|
||||
//空调冷凝风机输出/加湿器输出
|
||||
DeviceTransfer airconditionHumidifierOutput = (DeviceTransfer) infos.get("airconditionHumidifierOutput");
|
||||
BigDecimal airconditionHumidifierOutputBig = BigDecimal.ZERO;
|
||||
if (airconditionHumidifierOutput != null) {
|
||||
airconditionHumidifierOutputBig = airconditionHumidifierOutput.getValue();
|
||||
}
|
||||
bozhou.setAirconditionHumidifierOutput(airconditionHumidifierOutputBig);
|
||||
//空调蒸发温度
|
||||
DeviceTransfer airconditionEvaporateTemperature = (DeviceTransfer) infos.get("airconditionEvaporateTemperature");
|
||||
BigDecimal airconditionEvaporateTemperatureBig = BigDecimal.ZERO;
|
||||
if (airconditionEvaporateTemperature != null) {
|
||||
airconditionEvaporateTemperatureBig = airconditionEvaporateTemperature.getValue();
|
||||
if (airconditionEvaporateTemperatureBig != null) {
|
||||
String result = String.format("%.2f", airconditionEvaporateTemperatureBig);
|
||||
airconditionEvaporateTemperatureBig = new BigDecimal(result);
|
||||
}
|
||||
}
|
||||
bozhou.setAirconditionEvaporateTemperature(airconditionEvaporateTemperatureBig);
|
||||
//空调除湿温度
|
||||
DeviceTransfer airconditionDehumidificateTemperature = (DeviceTransfer) infos.get("airconditionDehumidificateTemperature");
|
||||
BigDecimal airconditionDehumidificateTemperatureBig = BigDecimal.ZERO;
|
||||
if (airconditionDehumidificateTemperature != null) {
|
||||
airconditionDehumidificateTemperatureBig = airconditionDehumidificateTemperature.getValue();
|
||||
}
|
||||
bozhou.setAirconditionDehumidificateTemperature(airconditionDehumidificateTemperatureBig);
|
||||
//空调室内湿度
|
||||
DeviceTransfer airconditionInnerHumidity = (DeviceTransfer) infos.get("airconditionInnerHumidity");
|
||||
BigDecimal airconditionInnerHumidityBig = BigDecimal.ZERO;
|
||||
if (airconditionInnerHumidity != null) {
|
||||
airconditionInnerHumidityBig = airconditionInnerHumidity.getValue();
|
||||
|
||||
}
|
||||
bozhou.setAirconditionInnerHumidity(airconditionInnerHumidityBig);
|
||||
//空调湿度回差
|
||||
DeviceTransfer airconditionReturnHumidity = (DeviceTransfer) infos.get("airconditionReturnHumidity");
|
||||
BigDecimal airconditionReturnHumidityBig = BigDecimal.ZERO;
|
||||
if (airconditionReturnHumidity != null) {
|
||||
airconditionReturnHumidityBig = airconditionReturnHumidity.getValue();
|
||||
}
|
||||
bozhou.setAirconditionReturnHumidity(airconditionReturnHumidityBig);
|
||||
//空调湿度设定
|
||||
DeviceTransfer airconditionSetHumidity = (DeviceTransfer) infos.get("airconditionSetHumidity");
|
||||
BigDecimal airconditionSetHumidityBig = BigDecimal.ZERO;
|
||||
if (airconditionSetHumidity != null) {
|
||||
airconditionSetHumidityBig = airconditionSetHumidity.getValue();
|
||||
}
|
||||
bozhou.setAirconditionSetHumidity(airconditionSetHumidityBig);
|
||||
//空调温度设定
|
||||
DeviceTransfer airconditionSetTemperature = (DeviceTransfer) infos.get("airconditionSetTemperature");
|
||||
BigDecimal airconditionSetTemperatureBig = BigDecimal.ZERO;
|
||||
if (airconditionSetTemperature != null) {
|
||||
airconditionSetTemperatureBig = airconditionSetTemperature.getValue();
|
||||
}
|
||||
bozhou.setAirconditionSetTemperature(airconditionSetTemperatureBig);
|
||||
}
|
||||
}
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
/* for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
|
||||
bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
|
||||
}*/
|
||||
return DataResult.success(bozhou);
|
||||
}
|
||||
|
||||
|
||||
//BMS值 SOC,SOH
|
||||
private WareHouse getBms(Integer stationId) {
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
List<DeviceRespVO> bmsList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.BMS);
|
||||
if (bmsList.isEmpty()) {
|
||||
bmsList = deviceService.getListByFuzzyDeviceType(stationId, DeviceTypeConstant.BMS);
|
||||
}
|
||||
WareHouse wareHouse = new WareHouse();
|
||||
if (!bmsList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = bmsList.get(0);
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
wareHouse.setBmsSrcId(deviceRespVO.getSrcId());
|
||||
DeviceTransfer soc = (DeviceTransfer) redisService.hget(key, "soc");
|
||||
DeviceTransfer soh = (DeviceTransfer) redisService.hget(key, "soh");
|
||||
if (soc != null) {
|
||||
wareHouse.setSoc(soc.getValue());
|
||||
}
|
||||
if (soh != null) {
|
||||
wareHouse.setSoh(soh.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return wareHouse;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,207 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.CabinService;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.StationHomeService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.DeviceTransfer;
|
||||
import com.ho.business.vo.req.MonitorQuery;
|
||||
import com.ho.business.vo.req.device.DeviceTreeReq;
|
||||
import com.ho.business.vo.req.point.PointReqVO;
|
||||
import com.ho.business.vo.resp.AppRealTimeCurveRespVo;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.cabin.*;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.vo.req.PointData;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 仓
|
||||
* @date 2023/5/5
|
||||
*/
|
||||
@RequestMapping(ContextConstant.BUSINESS + "station")
|
||||
@RestController
|
||||
@Api(tags = "舱堆簇包-舱")
|
||||
@Slf4j
|
||||
public class CabinController {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
StationHomeService stationHomeService;
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
CabinService cabinService;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@PostMapping("leftPanel")
|
||||
@ApiOperation(value = "左侧主面板")
|
||||
public DataResult<LeftPanel> leftPanel(@RequestBody @Valid PointReqVO reqVO) {
|
||||
LeftPanel leftPanel = new LeftPanel();
|
||||
Integer stationId = reqVO.getStationId();
|
||||
//查电站数据
|
||||
Station station = stationService.selectById(stationId);
|
||||
if (station == null) {
|
||||
return DataResult.success(leftPanel);
|
||||
}
|
||||
//舱装机容量和额定功率 是 总值/舱个数
|
||||
Integer cabinNum = station.getCabinNum();
|
||||
if (cabinNum != null && cabinNum != 0) {
|
||||
BigDecimal capacity = station.getCapacity();
|
||||
|
||||
BigDecimal ratePower = station.getRatePower();
|
||||
BigDecimal cap = capacity.divide(new BigDecimal(cabinNum), 2, BigDecimal.ROUND_HALF_UP);
|
||||
//BigDecimal rate = ratePower.divide(new BigDecimal(cabinNum), 2, BigDecimal.ROUND_HALF_UP);
|
||||
leftPanel.setCapacity(cap);
|
||||
//leftPanel.setAcPower(rate);
|
||||
}
|
||||
//根据设备pid查询下面的温度
|
||||
List<DeviceRespVO> list = deviceService.getListByDeviceTypeAndPid(reqVO.getStationId(), reqVO.getSrcId(), DeviceTypeConstant.PCS);
|
||||
if (!list.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = list.get(0);
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
DeviceTransfer deviceTransfer = (DeviceTransfer) redisService.hget(key, "outputPower");
|
||||
if (deviceTransfer != null) {
|
||||
BigDecimal value = deviceTransfer.getValue();
|
||||
leftPanel.setAcPower(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
//日充日放等
|
||||
LeftPanel leftPanelCharge = cabinService.powerGeneration(stationId, reqVO.getSrcId());
|
||||
|
||||
if( leftPanelCharge != null ){
|
||||
leftPanel.setDayCharge(leftPanelCharge.getDayCharge());
|
||||
leftPanel.setDayDischarge(leftPanelCharge.getDayDischarge());
|
||||
leftPanel.setMonthCharge(leftPanelCharge.getMonthCharge() == null ? BigDecimal.ZERO.add(leftPanelCharge.getDayCharge()) : leftPanelCharge.getMonthCharge().add(leftPanelCharge.getDayCharge()));
|
||||
leftPanel.setMonthDischarge(leftPanelCharge.getMonthDischarge() == null ? BigDecimal.ZERO.add(leftPanelCharge.getDayDischarge()) : leftPanelCharge.getMonthDischarge().add(leftPanelCharge.getDayDischarge()));
|
||||
leftPanel.setYearCharge(leftPanelCharge.getYearCharge());
|
||||
leftPanel.setYearDischarge(leftPanelCharge.getYearDischarge());
|
||||
leftPanel.setTotalCharge(leftPanelCharge.getTotalCharge());
|
||||
leftPanel.setTaotalDischarge(leftPanelCharge.getTaotalDischarge());
|
||||
leftPanel.setCumulatedCharge(leftPanelCharge.getTotalCharge());
|
||||
leftPanel.setCumulatedDischarge(leftPanelCharge.getTaotalDischarge());
|
||||
}
|
||||
return DataResult.success(leftPanel);
|
||||
}
|
||||
|
||||
@PostMapping("chargeCurve")
|
||||
@ApiOperation(value = "充放电曲线,近一年,按天")
|
||||
public DataResult<List<ChargeDischarge>> elecPriceCurve(@RequestBody @Valid PointReqVO reqVO) {
|
||||
Integer stationId = reqVO.getStationId();
|
||||
log.info("stationId:{}, srcId:{}", stationId, reqVO.getSrcId());
|
||||
//从elec_meter_value取值
|
||||
//数据加工是按照BSM维度进行的,先查这个设备下的BMS
|
||||
//计算今天和一年前的日期
|
||||
Date date = new Date();
|
||||
String now = DateUtil.format(date, CommonConstant.DATE_YMD);
|
||||
DateTime oneYearBeforeDateTime = DateUtil.offsetDay(date, -365);
|
||||
//一年前作为开始日期,今天作为结束日期
|
||||
String begin = DateUtil.format(oneYearBeforeDateTime, CommonConstant.DATE_YMD);
|
||||
List<ChargeDischarge> chargeList = cabinService.getChargeList(stationId, reqVO.getSrcId(), begin, now);
|
||||
return DataResult.success(chargeList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("socCurve")
|
||||
@ApiOperation(value = "SOC曲线,近24小时")
|
||||
public DataResult<List<PointData>> socCurve(@RequestBody @Valid PointReqVO reqVO) {
|
||||
List<PointData> list = new ArrayList<>();
|
||||
//当前时间往前取24小时
|
||||
List<String> houres24 = (List<String>) redisService.get(RedisKeyConstant.SIXTY_MINUTE_INTERVAL);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/powerCurve")
|
||||
@ApiOperation(value = "功率曲线")
|
||||
public DataResult<List<AppRealTimeCurveRespVo>> powerCurve(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<AppRealTimeCurveRespVo> resList = stationHomeService.getPowerCurve(monitorQuery);
|
||||
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
|
||||
bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "温度电压正太分布")
|
||||
@PostMapping("temperatureVoltageData")
|
||||
public DataResult<TemperatureVoltageResp> temperatureVoltageData(@RequestBody DeviceTreeReq vo) {
|
||||
TemperatureVoltageResp temperatureVoltageData = deviceService.getTemperatureVoltageData(vo);
|
||||
return DataResult.success(temperatureVoltageData);
|
||||
}
|
||||
|
||||
//温湿度 (抽样)
|
||||
@PostMapping("/temperatureHumidityCurve")
|
||||
@ApiOperation(value = "温湿度曲线")
|
||||
@Cacheable(cacheManager = "towMinuteCacheManager", value = "temperatureHumidityCurve", key = "#monitorQuery.stationId+'_'+#monitorQuery.srcId+'_'+#monitorQuery.sampleTime", sync = true)
|
||||
public DataResult<List<TemperatureHumidityResp>> temperatureHumidityCurve(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<TemperatureHumidityResp> resList = stationHomeService.getTemperatureHumidityCurve(monitorQuery);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (TemperatureHumidityResp temperatureHumidityResp : resList) {
|
||||
List<TemperatureValue> list = temperatureHumidityResp.getList();
|
||||
//改为使用
|
||||
for (TemperatureValue temperatureValue : list) {
|
||||
BigDecimal temperature = temperatureValue.getTemperature();
|
||||
BigDecimal humidity = temperatureValue.getHumidity();
|
||||
if (temperature != null) {
|
||||
String result = String.format("%.3f", temperature);
|
||||
temperatureValue.setTemperature(new BigDecimal(result));;
|
||||
}
|
||||
if (humidity != null) {
|
||||
String result = String.format("%.3f", humidity);
|
||||
temperatureValue.setHumidity(new BigDecimal(result));;
|
||||
}
|
||||
//bigDecimalUtil.keepTwoDecimalPlaces(temperatureValue);
|
||||
//bigDecimalUtil.ifIsNUll(temperatureValue);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@PostMapping("/auxPowerCurve")
|
||||
@ApiOperation(value = "辅助功率曲线")
|
||||
public DataResult<List<PointData>> auxPowerCurve(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<PointData> auxPower = cabinService.getAuxPower(monitorQuery.getStationId(), monitorQuery.getSrcId());
|
||||
for (PointData pointData : auxPower) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pointData);
|
||||
}
|
||||
return DataResult.success(auxPower);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,343 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.service.CockpitService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.req.cockpit.CockpitReqVO;
|
||||
import com.ho.business.vo.resp.StationRespVO;
|
||||
import com.ho.business.vo.resp.cockpit.*;
|
||||
import com.ho.common.tools.annotation.LargeScreenToken;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.EnvConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.util.IPUtils;
|
||||
import com.ho.common.tools.vo.req.WeatherReq;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 驾驶舱
|
||||
* Author yule
|
||||
* Date 2023/1/10 15:47
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "cockpit")
|
||||
@Api(tags = "驾驶舱")
|
||||
@Slf4j
|
||||
public class CockpitController {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
CockpitService cockpitService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
@Value("${event.currentMaxDay}")
|
||||
Integer currentMaxDay;
|
||||
|
||||
@Value("${event.bigScreenEventLimit}")
|
||||
Integer bigScreenEventLimit;
|
||||
|
||||
@PostMapping("/testBigToken")
|
||||
@ApiOperation(value = "测试使用大屏token访问接口")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<StationSummaryRespVO> bigScreen(HttpServletRequest request) {
|
||||
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
Integer groupId = user.getGroupId();
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/summary")
|
||||
@ApiOperation(value = "电站概述")
|
||||
@ApiIgnore
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<StationSummaryRespVO> summary(HttpServletRequest request) {
|
||||
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
StationSummaryRespVO respVO = cockpitService.getSummary(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(respVO);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/revenueStatistics")
|
||||
@ApiOperation(value = "收益统计")
|
||||
@TokenIgnore
|
||||
@ApiIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<RevenueStatisticsRespVO>> revenueStatistics(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<RevenueStatisticsRespVO> respVO = cockpitService.getRevenueStatistics(user);
|
||||
for (RevenueStatisticsRespVO revenueStatisticsRespVO : respVO) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(revenueStatisticsRespVO);
|
||||
bigDecimalUtil.ifIsNUll(revenueStatisticsRespVO);
|
||||
}
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/revenueStatisticsJob")
|
||||
@ApiOperation(value = "收益统计定时任务")
|
||||
@TokenIgnore
|
||||
@ApiIgnore
|
||||
public DataResult<List<RevenueStatisticsRespVO>> revenueStatisticsJob() {
|
||||
cockpitService.getRevenueStatistics();
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/totalPowerGeneration")
|
||||
@ApiOperation(value = "总发电量")
|
||||
@TokenIgnore
|
||||
@ApiIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<TotalPowerGenerationRespVO>> totalPowerGeneration(@RequestBody CockpitReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<TotalPowerGenerationRespVO> respVO = cockpitService.getTotalPowerGenerations(vo, user);
|
||||
for (TotalPowerGenerationRespVO totalPowerGenerationRespVO : respVO) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(totalPowerGenerationRespVO);
|
||||
bigDecimalUtil.ifIsNUll(totalPowerGenerationRespVO);
|
||||
}
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/proportionOfPowerGeneration")
|
||||
@ApiOperation(value = "发电占比")
|
||||
@TokenIgnore
|
||||
@ApiIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<ProportionOfPowerRespVO>> proportionOfPowerGeneration(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<ProportionOfPowerRespVO> respVO = cockpitService.getProportionOfPowerGeneration(user);
|
||||
for (ProportionOfPowerRespVO proportionOfPowerRespVO : respVO) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(proportionOfPowerRespVO);
|
||||
bigDecimalUtil.ifIsNUll(proportionOfPowerRespVO);
|
||||
}
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/revenueRanking")
|
||||
@ApiOperation(value = "收益排行")
|
||||
@TokenIgnore
|
||||
@ApiIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<RevenueRespVO>> revenueRanking(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<RevenueRespVO> respVO = cockpitService.getRevenueRanking(user);
|
||||
for (RevenueRespVO revenueRespVO : respVO) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(revenueRespVO);
|
||||
bigDecimalUtil.ifIsNUll(revenueRespVO);
|
||||
}
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/weather")
|
||||
@ApiOperation(value = "大屏天气接口")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<WeatherRespVo> weather(HttpServletRequest request) {
|
||||
String ipAddr = IPUtils.getIpAddr(request);
|
||||
log.info("获取到IP: {}", ipAddr);
|
||||
if (env.equals("dev") || env.equals("exp")) {
|
||||
ipAddr = "114.222.185.168";
|
||||
}
|
||||
//通合的先显示南通的地址IP,后续再优化
|
||||
else if(EnvConstant.TONG_HE.equals(env)){
|
||||
ipAddr = "221.227.154.59";
|
||||
}
|
||||
//调用file-center的天气接口
|
||||
WeatherReq weatherReq = new WeatherReq();
|
||||
weatherReq.setIp(ipAddr);
|
||||
DataResult<WeatherRespVo> weatherResult = fileCenterFeignClient.queryWeather(weatherReq);
|
||||
log.info("天气接口数据:" + weatherResult);
|
||||
return DataResult.success(weatherResult.getData());
|
||||
}
|
||||
|
||||
@PostMapping("/groupData")
|
||||
@ApiOperation(value = "集团数据")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<GroupDataRespVo> groupData(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
//
|
||||
Integer groupId = user.getGroupId();
|
||||
String key = RedisKeyConstant.COCKPIT.GROUP_DATA + groupId;
|
||||
if(redisService.hasKey(key)){
|
||||
log.info("大屏集团数据走redis缓存: {}", groupId);
|
||||
GroupDataRespVo groupDataRespVo = (GroupDataRespVo)redisService.get(key);
|
||||
return DataResult.success(groupDataRespVo);
|
||||
}
|
||||
GroupDataRespVo groupDataRespVo = cockpitService.getGroupData(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(groupDataRespVo);
|
||||
bigDecimalUtil.ifIsNUll(groupDataRespVo);
|
||||
redisService.set(key, groupDataRespVo, 2, TimeUnit.MINUTES);
|
||||
return DataResult.success(groupDataRespVo);
|
||||
}
|
||||
|
||||
@PostMapping("/cumulative")
|
||||
@ApiOperation(value = "累计总和")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<CumulativeRespVO> cumulative(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
Integer groupId = user.getGroupId();
|
||||
String key = RedisKeyConstant.COCKPIT.CUMULATIVE + groupId;
|
||||
if(redisService.hasKey(key)){
|
||||
log.info("大屏累计总和走redis缓存: {}", groupId);
|
||||
CumulativeRespVO respVO = (CumulativeRespVO)redisService.get(key);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
CumulativeRespVO respVO = cockpitService.getCumulative(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(respVO);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
redisService.set(key, respVO, 6, TimeUnit.MINUTES);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/stationMap")
|
||||
@ApiOperation(value = "电站地图")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationMapRespVO>> stationMap(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
Integer groupId = user.getGroupId();
|
||||
String key = RedisKeyConstant.COCKPIT.STATION_MAP + groupId;
|
||||
if(redisService.hasKey(key)){
|
||||
log.info("大屏电站地图走redis缓存: {}", groupId);
|
||||
List<StationMapRespVO> respVO = (List<StationMapRespVO>)redisService.get(key);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
List<StationMapRespVO> respVO = cockpitService.getStationMap(user);
|
||||
redisService.set(key, respVO, 6, TimeUnit.MINUTES);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/conditionMonitoring")
|
||||
@ApiOperation(value = "状态监测")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<ConditionMonitoringRespVO> conditionMonitoring(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
ConditionMonitoringRespVO respVO = cockpitService.getConditionMonitoring(user);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/stationOperation")
|
||||
@ApiOperation(value = "电站运行数据")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationOperationRespVO>> stationOperation(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<StationOperationRespVO> list = cockpitService.getStationOperation(user);
|
||||
for (StationOperationRespVO stationOperationRespVO : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationOperationRespVO);
|
||||
bigDecimalUtil.ifIsNUll(stationOperationRespVO);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/chargeCockpitPowerGeneration")
|
||||
@ApiOperation(value = "定时修改集团数据中的储能累计放电量和充电桩累计放电量" ,hidden = true)
|
||||
@TokenIgnore
|
||||
public void chargeCockpitPowerGeneration(){
|
||||
List<Station> stations = stationService.selectAll();
|
||||
List<Integer> groupIdList = stations.stream().map(s -> {
|
||||
return s.getGroupId();
|
||||
}).distinct().collect(Collectors.toList());
|
||||
for (Integer groupId : groupIdList) {
|
||||
//储能累计放电量key
|
||||
String energyKey = RedisKeyConstant.COCKPIT.ENERGY_POWER_GENERATION +groupId;
|
||||
if (redisService.hasKey(energyKey)){
|
||||
BigDecimal energyPowerGeneration = (BigDecimal) redisService.get(energyKey);
|
||||
BigDecimal sum = energyPowerGeneration.add(CommonConstant.TongHeCockpit.DailyEnergyPowerGeneration.divide(new BigDecimal(24),4,BigDecimal.ROUND_HALF_UP));
|
||||
redisService.set(energyKey,sum);
|
||||
}else {
|
||||
redisService.set(energyKey,CommonConstant.TongHeCockpit.EnergyPowerGeneration);
|
||||
}
|
||||
//充电桩累计放电量key
|
||||
String chargePileKey = RedisKeyConstant.COCKPIT.CHARGE_PILE_POWER_GENERATION + groupId;
|
||||
if (redisService.hasKey(chargePileKey)){
|
||||
BigDecimal chargePilePowerGeneration = (BigDecimal) redisService.get(chargePileKey);
|
||||
BigDecimal sum = chargePilePowerGeneration.add(CommonConstant.TongHeCockpit.DailyChargePilePowerGeneration.divide(new BigDecimal(24),4,BigDecimal.ROUND_HALF_UP));
|
||||
redisService.set(chargePileKey,sum);
|
||||
}else {
|
||||
redisService.set(chargePileKey,CommonConstant.TongHeCockpit.ChargePilePowerGeneration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/capacityProportion")
|
||||
@ApiOperation(value = "装机占比")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<CapacityProportionResp> capacityProportion(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
CapacityProportionResp capacityProportionResp = cockpitService.capacityProportion(user);
|
||||
return DataResult.success(capacityProportionResp);
|
||||
}
|
||||
|
||||
@PostMapping("/monitoringStation")
|
||||
@ApiOperation(value = "电站实时监控")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationRespVO>> monitoringStation(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<StationRespVO> list = cockpitService.monitoringStation(user);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.ColCountService;
|
||||
import com.ho.business.vo.req.colCount.ColCountDel;
|
||||
import com.ho.business.vo.req.colCount.ColCountReq;
|
||||
import com.ho.business.vo.resp.colCount.ColCountResp;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Description 指标偏差值
|
||||
* @Author xwz
|
||||
* @Date 2023/7/5
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "colCount")
|
||||
@Api(tags = "指标偏差值")
|
||||
public class ColCountController {
|
||||
|
||||
@Autowired
|
||||
ColCountService colCountService;
|
||||
|
||||
@PostMapping("pageList")
|
||||
@ApiOperation(value = "查询指标偏差值")
|
||||
public DataResult<ColCountResp> pageList(@RequestBody ColCountReq vo) {
|
||||
PageResult<ColCountResp> pageList = colCountService.getPageList(vo);
|
||||
return DataResult.success(pageList);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增指标偏差值")
|
||||
@LogAnnotation(title = "指标偏差值", action = "新增指标偏差值")
|
||||
public DataResult<ColCountResp> add(@RequestBody ColCountReq vo) {
|
||||
if(null==vo.getColName()||null==vo.getCol()||null==vo.getDeviceType()){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
ColCountReq queryCol = new ColCountReq();
|
||||
queryCol.setStationId(vo.getStationId());
|
||||
queryCol.setCol(vo.getCol());
|
||||
queryCol.setDeviceType(vo.getDeviceType());
|
||||
List<ColCountResp> list = colCountService.selectByParam(queryCol);
|
||||
if(null != list && list.size()>0){
|
||||
throw new BusinessException(BaseResponseCode.EXISTS_DUPLICATE_DATA);
|
||||
}
|
||||
int i = colCountService.insertColCount(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "更新指标偏差值")
|
||||
@LogAnnotation(title = "指标偏差值", action = "更新指标偏差值")
|
||||
public DataResult<ColCountResp> update(@RequestBody ColCountReq vo) {
|
||||
int i = colCountService.updateById(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除指标偏差值")
|
||||
@LogAnnotation(title = "指标偏差值", action = "删除指标偏差值")
|
||||
public DataResult<ColCountResp> delte(@RequestBody ColCountDel vo) {
|
||||
colCountService.deleteByList(vo.getIds());
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,366 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Device;
|
||||
import com.ho.business.service.CommonService;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.vo.DeviceTransfer;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.device.CommonQuery;
|
||||
import com.ho.business.vo.req.device.CommonValueQuery;
|
||||
import com.ho.business.vo.req.device.DeviceTreeReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.EnvironmentalControlVo;
|
||||
import com.ho.business.vo.resp.cabin.TemperatureVoltageNewResp;
|
||||
import com.ho.business.vo.resp.point.ElecDataResp;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.datacollect.api.constant.DataCollectConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/5/8
|
||||
*/
|
||||
@RequestMapping(ContextConstant.BUSINESS + "common")
|
||||
@RestController
|
||||
@Api(tags = "通用设备状态查询")
|
||||
@Slf4j
|
||||
public class CommonController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
CommonService commonService;
|
||||
|
||||
@PostMapping("newValue")
|
||||
@ApiOperation(value = "最新设备点数据")
|
||||
public DataResult<JSONObject> newValue(@RequestBody CommonValueQuery reqVo) {
|
||||
//查设备, 分为实体设备和虚拟设备,如果是实体设备,直接从对应缓存拿
|
||||
Integer stationId = reqVo.getStationId();
|
||||
Integer srcId = reqVo.getSrcId();
|
||||
List<String> cols = reqVo.getColList();
|
||||
Device device = deviceService.selectByStationIdAndSrcId(stationId, srcId);
|
||||
if (device == null) {
|
||||
throw new BusinessException(BaseResponseCode.CORRESPONDING_DEVICE_DOES_NOT_EXIST);
|
||||
}
|
||||
//返回的信息
|
||||
JSONObject retInfo = new JSONObject();
|
||||
String deviceType = device.getDeviceType();
|
||||
log.info("deviceType: {}", deviceType);
|
||||
//实体设备
|
||||
if (device.getVirtual() == 0) {
|
||||
//PCS
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.PCS)) {
|
||||
JSONObject realInfo = commonService.getRealInfo(device, cols);
|
||||
realInfo = commonService.dealPCS(realInfo, device);
|
||||
//只保留要前端请求的
|
||||
for (String col : cols) {
|
||||
if (realInfo.containsKey(col)) {
|
||||
retInfo.put(col, realInfo.get(col));
|
||||
}
|
||||
}
|
||||
//加电流流向
|
||||
retInfo.put(DeviceTypeConstant.FLOW_DIRECTION, device.getFlowDirection());
|
||||
}
|
||||
//BMS
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.BMS)) {
|
||||
/*JSONObject realInfo = commonService.getRealInfo(device, cols);
|
||||
retInfo = commonService.dealBMS(realInfo, device);*/
|
||||
Map<Object, Object> infoFromRedis = commonService.getInfoFromRedis(device);
|
||||
//查询与BMS pid相同的设备
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.getListByDeviceTypeAndPid(stationId, device.getPid(), DeviceTypeConstant.TRANSMITTER);
|
||||
//筛选出温湿度仪的设备
|
||||
for (DeviceRespVO deviceRespVO : deviceRespVOS) {
|
||||
Map<Object, Object> dealTransmitterMap = commonService.dealTransmitter(deviceRespVO);
|
||||
infoFromRedis.putAll(dealTransmitterMap);
|
||||
}
|
||||
//查对应PCS的有功
|
||||
List<DeviceRespVO> pcsList = deviceService.getListByDeviceTypeAndPid(stationId, device.getPid(), DeviceTypeConstant.PCS);
|
||||
if (!pcsList.isEmpty()) {
|
||||
DeviceRespVO pcsDevice = pcsList.get(0);
|
||||
String key = pcsDevice.getDeviceType() + ":" + stationId + ":" + pcsDevice.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
DeviceTransfer outputPower = (DeviceTransfer) redisService.hget(key, "outputPower");
|
||||
if (outputPower != null) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("value", outputPower.getValue() == null ? outputPower.getValue() : outputPower.getValue().setScale(3, BigDecimal.ROUND_HALF_UP));
|
||||
jsonObject.put("updateTime", outputPower.getUpdateTime());
|
||||
jsonObject.put("srcId", pcsDevice.getSrcId());
|
||||
jsonObject.put("deviceType", pcsDevice.getDeviceType());
|
||||
infoFromRedis.put("outputPower", jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (String col : cols) {
|
||||
if (infoFromRedis.containsKey(col)) {
|
||||
Object obj = infoFromRedis.get(col);
|
||||
if (obj != null && obj instanceof DeviceTransfer) {
|
||||
DeviceTransfer deviceTransfer = (DeviceTransfer) obj;
|
||||
//保留2位小数
|
||||
if (null != deviceTransfer) {
|
||||
BigDecimal value = deviceTransfer.getValue();
|
||||
if (value != null) {
|
||||
String result = String.format("%.3f", value);
|
||||
deviceTransfer.setValue(new BigDecimal(result));
|
||||
}
|
||||
}
|
||||
retInfo.put(col, deviceTransfer);
|
||||
} else {
|
||||
retInfo.put(col, obj);
|
||||
}
|
||||
} else {
|
||||
DeviceTransfer deviceTransfer = new DeviceTransfer();
|
||||
retInfo.put(col, deviceTransfer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//EMU
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.EMU)) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
retInfo = commonService.dealEMU(device, cols);
|
||||
|
||||
for (String col : cols) {
|
||||
if (retInfo.containsKey(col)) {
|
||||
jsonObject.put(col, retInfo.get(col));
|
||||
} else {
|
||||
DeviceTransfer deviceTransfer = new DeviceTransfer();
|
||||
jsonObject.put(col, deviceTransfer);
|
||||
}
|
||||
}
|
||||
retInfo = jsonObject;
|
||||
|
||||
}
|
||||
//空调
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.AIR_CONDITION)) {
|
||||
cols.add(DeviceTypeConstant.AIRCONDITIONFAULT);
|
||||
retInfo = commonService.dealAirCondition(device, cols);
|
||||
}
|
||||
//消防设备
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.STORAGE_FIRE)) {
|
||||
//先查询所有缓存数据集
|
||||
Map<Object, Object> infoFromRedis = commonService.getInfoFromRedis(device);
|
||||
retInfo = commonService.dealFire(infoFromRedis, cols, device);
|
||||
|
||||
}
|
||||
//电表
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.ELE_METER)) {
|
||||
retInfo = commonService.getRealInfo(device, cols);
|
||||
}
|
||||
//液冷
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.LIQUID_COOLING)) {
|
||||
retInfo = commonService.getLiquidCooling(device, cols);
|
||||
}
|
||||
//光储逆变器
|
||||
if (deviceType != null && deviceType.contains(DeviceTypeConstant.OPTICAL_STORAGE)) {
|
||||
/* 储能侧电表 torageMeter
|
||||
负载侧电表 loadMeter
|
||||
并网侧电表 gridMeter*/
|
||||
//将电表三个和其他值分离出来
|
||||
List<String> collect = cols.stream().filter(i -> "torageMeter".equals(i)
|
||||
|| "loadMeter".equals(i)
|
||||
|| "gridMeter".equals(i)).collect(Collectors.toList());
|
||||
retInfo = commonService.getLiquidCooling(device, cols);
|
||||
for (String col : collect) {
|
||||
JSONObject dd = commonService.getElecData(device, col);
|
||||
retInfo.putAll(dd);
|
||||
}
|
||||
}
|
||||
}
|
||||
//虚拟设备
|
||||
else if (device.getVirtual() == 1) {
|
||||
//需要查这个设备的父设备
|
||||
// Integer parentSrcId = device.getPid();
|
||||
Device parentDevice = deviceService.selectByStationIdAndSrcId(stationId, device.getFromId());
|
||||
if (parentDevice == null) {
|
||||
log.error("该虚拟设备没找到父设备");
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
if (parentDevice.getDeviceType() == null) {
|
||||
log.error("该虚拟来源的设备没有配置设备类型");
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
|
||||
if (device.getDeviceType().contains(DeviceTypeConstant.STACK)) {
|
||||
//簇数据
|
||||
Map<String, String> colMap = cols.stream().collect(Collectors.toMap(Function.identity(), Function.identity()));
|
||||
if (cols.size() < 24 || colMap.containsKey(DataCollectConstant.BMS_POINT.clusterAlarmCodeLBit + CommonConstant.ZERO)) {
|
||||
//因为原来的接口方法不能有效的区分,在少量改动的前提下,故而只能折中,根据参数个数来区分走什么方法
|
||||
retInfo = commonService.getVirtualInfo(device, parentDevice, reqVo.getColList());
|
||||
} else {
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setPId(device.getSrcId());
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
retInfo = commonService.getVirtualClusterInfo(deviceList, parentDevice, reqVo.getColList());
|
||||
}
|
||||
} else {
|
||||
//电池包数据以及其他类型的虚拟设备都走这个
|
||||
retInfo = commonService.getVirtualInfo(device, parentDevice, reqVo.getColList());
|
||||
}
|
||||
}
|
||||
//虚拟设备
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "电池包温度电压柱状图以及运行数据")
|
||||
@PostMapping("packTemperatureVoltageData")
|
||||
public DataResult<TemperatureVoltageNewResp> packTemperatureVoltageData(@RequestBody DeviceTreeReq vo) {
|
||||
TemperatureVoltageNewResp temperatureVoltageData = commonService.getTemperatureVoltageData(vo);
|
||||
return DataResult.success(temperatureVoltageData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个空调通用接口
|
||||
*
|
||||
* @param reqVo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/commonAirCondition")
|
||||
@ApiOperation(value = "空调")
|
||||
public DataResult<JSONObject> commonAirCondition(@RequestBody CommonQuery reqVo) {
|
||||
JSONObject retInfo = new JSONObject();
|
||||
Integer stationId = reqVo.getStationId();
|
||||
//先查这个站下的空调
|
||||
List<DeviceRespVO> airList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.AIR_CONDITION);
|
||||
if (!airList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = airList.get(0);
|
||||
//在缓存里拿映射字段
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
Map<Object, Object> infos = redisService.hgetall(key);
|
||||
List<String> cols = reqVo.getColList();
|
||||
for (String col : cols) {
|
||||
if (infos.containsKey(col)) {
|
||||
DeviceTransfer deviceTransfer = (DeviceTransfer) infos.get(col);
|
||||
retInfo.put(col, deviceTransfer == null ? "" : NumberUtil.round(deviceTransfer.getValue(), 2));
|
||||
} else {
|
||||
retInfo.put(col, "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个空调通用接口
|
||||
*
|
||||
* @param reqVo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getAirCondition")
|
||||
@ApiOperation(value = "空调新接口")
|
||||
public DataResult<JSONObject> getAirCondition(@RequestBody CommonQuery reqVo) {
|
||||
List<EnvironmentalControlVo> resultList = commonService.getAirCondition(reqVo);
|
||||
return DataResult.success(resultList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("warningPCS")
|
||||
@ApiOperation(value = "215kW标准柜PCS状态字")
|
||||
public DataResult<JSONObject> warningPCS(@RequestBody CommonValueQuery reqVo) {
|
||||
JSONObject retInfo = new JSONObject();
|
||||
Integer stationId = reqVo.getStationId();
|
||||
//先查这个站下的空调
|
||||
List<DeviceRespVO> airList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.STATUS_PCS);
|
||||
if (!airList.isEmpty()) {
|
||||
DeviceRespVO deviceRespVO = airList.get(0);
|
||||
//在缓存里拿映射字段
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
Map<Object, Object> infos = redisService.hgetall(key);
|
||||
List<String> cols = reqVo.getColList();
|
||||
for (String col : cols) {
|
||||
if (infos.containsKey(col)) {
|
||||
DeviceTransfer deviceTransfer = (DeviceTransfer) infos.get(col);
|
||||
retInfo.put(col, deviceTransfer == null ? "" : NumberUtil.round(deviceTransfer.getValue(), 2));
|
||||
} else {
|
||||
retInfo.put(col, "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("storageFire")
|
||||
@ApiOperation(value = "消防关联字段回显")
|
||||
public DataResult<JSONObject> getStorageFire(@RequestBody CommonValueQuery reqVo) {
|
||||
Integer stationId = reqVo.getStationId();
|
||||
Integer srcId = reqVo.getSrcId();
|
||||
List<String> cols = reqVo.getColList();
|
||||
Device device = deviceService.selectByStationIdAndSrcId(stationId, srcId);
|
||||
if (device == null) {
|
||||
throw new BusinessException(BaseResponseCode.CORRESPONDING_DEVICE_DOES_NOT_EXIST);
|
||||
}
|
||||
//返回的信息
|
||||
JSONObject retInfo = commonService.getLiquidCooling(device, cols);
|
||||
return DataResult.success(retInfo);
|
||||
}
|
||||
|
||||
@PostMapping("/middlePart")
|
||||
@ApiOperation(value = "站首页的中间部分-分开的(电表总有功功率)")
|
||||
public DataResult<JSONObject> middlePart(@RequestBody CommonQuery reqVo) {
|
||||
Object middlePart = commonService.getMiddlePart(reqVo);
|
||||
return DataResult.success(middlePart);
|
||||
}
|
||||
|
||||
@PostMapping("/getElec")
|
||||
@ApiOperation(value = "站首页的中间部分获取电表功率(并网侧电表以及负载负载侧电表)")
|
||||
public DataResult<List<ElecDataResp>> getElec(@RequestBody CommonQuery reqVo) {
|
||||
List<ElecDataResp> list = commonService.getElec(reqVo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/getEleMeter")
|
||||
@ApiOperation(value = "站首页的中间部分获取电表功率(储能侧电表)")
|
||||
public DataResult<JSONObject> getEleMeter(@RequestBody CommonQuery reqVo) {
|
||||
Object list = commonService.getEleMeter(reqVo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/getPVElec")
|
||||
@ApiOperation(value = "站首页的中间部分获取电表功率(光伏并网设备)")
|
||||
public DataResult<JSONObject> getPVElec(@RequestBody CommonQuery reqVo) {
|
||||
Object list = commonService.getPVElec(reqVo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/getOpticalStorage")
|
||||
@ApiOperation(value = "站首页的中间部分光储一体机(光储逆变器)")
|
||||
public DataResult<JSONObject> getOpticalStorage(@RequestBody CommonQuery reqVo) {
|
||||
Object middlePart = commonService.getOpticalStorage(reqVo);
|
||||
return DataResult.success(middlePart);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.Convert;
|
||||
import com.ho.business.service.ConvertService;
|
||||
import com.ho.business.vo.req.colCount.ColCountReq;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 遥测转遥信控制页面
|
||||
* @DateTime: 2023/7/11 14:33
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "convert")
|
||||
@Api(tags = "遥测转遥信配置页面")
|
||||
@Slf4j
|
||||
public class ConvertController {
|
||||
@Autowired
|
||||
ConvertService convertService;
|
||||
//新增
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增遥测转遥信")
|
||||
@LogAnnotation(title = "遥测转遥信", action = "新增遥测转遥信值")
|
||||
public DataResult add(@RequestBody Convert vo) {
|
||||
convertService.add(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除遥测转遥信")
|
||||
@LogAnnotation(title = "遥测转遥信", action = "删除遥测转遥信值")
|
||||
public DataResult delete(@RequestBody Convert vo) {
|
||||
convertService.delete(vo.getId());
|
||||
return DataResult.success();
|
||||
}
|
||||
//删除
|
||||
|
||||
//分页查询
|
||||
//根据colName进行查询
|
||||
@PostMapping("pageList")
|
||||
@ApiOperation(value = "查询遥测转遥信值")
|
||||
public DataResult<Convert> pageList(@RequestBody ColCountReq vo) {
|
||||
PageResult<Convert> pageList = convertService.getPageList(vo);
|
||||
return DataResult.success(pageList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,431 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Device;
|
||||
import com.ho.business.entity.DeviceType;
|
||||
import com.ho.business.entity.DeviceTypeConfig;
|
||||
import com.ho.business.service.DeviceCallService;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.DeviceTypeConfigService;
|
||||
import com.ho.business.vo.req.DeviceByDeviceTypeReq;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.device.*;
|
||||
import com.ho.business.vo.req.deviceModel.SynchronousReqVo;
|
||||
import com.ho.business.vo.req.export.ExportReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.point.DevicePointResp;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.*;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 设备管理
|
||||
* Author yule
|
||||
* Date 2022/10/13 11:35
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "device")
|
||||
@Api(tags = "业务模块-设备管理")
|
||||
public class DeviceController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
|
||||
@Autowired
|
||||
DeviceCallService deviceCallService;
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "设备列表,分页")
|
||||
public DataResult<PageResult<DeviceRespVO>> page(@RequestBody @Valid DeviceReqVO deviceReqVO, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
//设置集团id
|
||||
deviceReqVO.setGroupId(simpleUser.getGroupId());
|
||||
//如果 stationId没传 要查所辖电站的数据
|
||||
Integer stationId = deviceReqVO.getStationId();
|
||||
if (StringUtils.isEmpty(stationId)) {
|
||||
deviceReqVO.setStationIds(simpleUser.getStationIds());
|
||||
}
|
||||
PageResult<DeviceRespVO> list = deviceService.getPageListByInfo(deviceReqVO);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增设备(做虚拟设备新增使用)")
|
||||
@LogAnnotation(title = "业务模块-设备管理", action = "新增设备虚拟设备")
|
||||
public DataResult add(@RequestBody @Valid DeviceAddReq adddevice) {
|
||||
deviceService.insertBatch(adddevice);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "修改设备属性")
|
||||
@LogAnnotation(title = "业务模块-设备管理", action = "修改设备属性")
|
||||
@HzPermission(PermissionConstant.SYS_DEVICE_EDIT)
|
||||
public DataResult update(@RequestBody @Valid DeviceUpdateReq deviceUpdateReq) {
|
||||
//先查设备是否存在
|
||||
Device deviceQuery = deviceService.selectById(deviceUpdateReq.getId());
|
||||
if (deviceQuery == null) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
// if (deviceUpdateReq.getDeviceType() == null) {
|
||||
// throw new BusinessException(BaseResponseCode.CHOOSE_DEVICE);
|
||||
// }
|
||||
Device device = new Device();
|
||||
device.setId(deviceUpdateReq.getId());
|
||||
|
||||
if (deviceUpdateReq.getDeviceName() != null) {
|
||||
device.setDeviceName(deviceUpdateReq.getDeviceName());
|
||||
}
|
||||
if (deviceUpdateReq.getDeviceType() != null) {
|
||||
device.setDeviceType(deviceUpdateReq.getDeviceType());
|
||||
}
|
||||
if (!StringUtils.isEmpty(deviceUpdateReq.getHide())) {
|
||||
device.setHide(deviceUpdateReq.getHide());
|
||||
}
|
||||
device.setProducer(deviceUpdateReq.getProducer());
|
||||
if (!StringUtils.isEmpty(deviceUpdateReq.getFlowDirection())) {
|
||||
device.setFlowDirection(deviceUpdateReq.getFlowDirection());
|
||||
}
|
||||
if (deviceUpdateReq.getProducerType() != null) {
|
||||
device.setProducerType(deviceUpdateReq.getProducerType());
|
||||
}
|
||||
if (deviceUpdateReq.getUnitType() != null) {
|
||||
device.setUnitType(deviceUpdateReq.getUnitType());
|
||||
}
|
||||
device.setGroupId(deviceQuery.getGroupId());
|
||||
device.setStationId(deviceQuery.getStationId());
|
||||
device.setVirtual(deviceQuery.getVirtual());
|
||||
device.setSrcId(deviceQuery.getSrcId());
|
||||
int i = deviceService.update(device);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("one")
|
||||
@ApiOperation(value = "根据id查询单个设备")
|
||||
public DataResult<DeviceRespVO> getDevice(@RequestBody DeviceIdReqVo deviceId) {
|
||||
DeviceRespVO deviceRespVO = deviceService.getDeviceRespVO(deviceId.getId());
|
||||
return DataResult.success(deviceRespVO);
|
||||
}
|
||||
|
||||
@PostMapping("deviceType")
|
||||
@ApiOperation(value = "查询电站下的设备类型列表,不分页")
|
||||
public DataResult<List<DeviceType>> selectByStationId(@RequestBody DeviceStationReqVo dvo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (null == dvo.getStationId()) {
|
||||
return DataResult.success(new ArrayList<>());
|
||||
}
|
||||
//根据电站id查询Device表中的device_type
|
||||
List<String> deviceList = deviceService.selectDistinctDeviceTypeByStationId(dvo.getStationId());
|
||||
deviceList.removeIf(s -> {
|
||||
boolean flag = false;
|
||||
if (DeviceTypeConstant.STATION.equals(s)) {
|
||||
flag = true;
|
||||
} else if (DeviceTypeConstant.WAREHOUSE.equals(s)) {
|
||||
flag = true;
|
||||
} else if (DeviceTypeConstant.BAY.equals(s)) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
);
|
||||
if (deviceList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_DEVICE_NOT_EXIST);
|
||||
}
|
||||
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||
//再根据设备类型查询名称返回
|
||||
if (!deviceList.isEmpty()) {
|
||||
//改为从deviceTypeConfig表擦
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setDeviceTypeList(deviceList);
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
for (DeviceTypeConfig deviceTypeConfig : deviceTypeConfigs) {
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setTypeId(deviceTypeConfig.getId());
|
||||
deviceType.setDeviceType(deviceTypeConfig.getDeviceType());
|
||||
deviceType.setName(deviceTypeConfig.getName());
|
||||
deviceTypes.add(deviceType);
|
||||
}
|
||||
}
|
||||
return DataResult.success(deviceTypes);
|
||||
}
|
||||
|
||||
@GetMapping("{stationId}")
|
||||
@ApiOperation(value = "查询电站下的设备列表")
|
||||
public DataResult<List<DeviceRespVO>> getDeviceByStationId(@PathVariable @Valid Integer stationId) {
|
||||
List<DeviceRespVO> deviceList = deviceService.getDeviceByStationId(stationId);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@PostMapping("DeviceByStationIds")
|
||||
@ApiOperation(value = "批量查询电站下的设备列表")
|
||||
public DataResult<List<DeviceRespVO>> getDeviceByStationIds(@RequestBody @Valid List<Integer> stationIds) {
|
||||
List<DeviceRespVO> deviceList = deviceService.getDeviceByStationIds(stationIds);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@PostMapping("updateDevice")
|
||||
@ApiOperation(value = "修改设备属性")
|
||||
@HzPermission(PermissionConstant.SYS_DEVICE_EDIT)
|
||||
public DataResult updateDevice(@RequestBody @Valid DeviceUpdateReq deviceUpdateReq) {
|
||||
//先查设备是否存在
|
||||
Device deviceQuery = deviceService.selectById(deviceUpdateReq.getId());
|
||||
if (deviceQuery == null) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
if (deviceUpdateReq.getDeviceType() == null) {
|
||||
throw new BusinessException(BaseResponseCode.CHOOSE_DEVICE);
|
||||
}
|
||||
Device device = new Device();
|
||||
device.setId(deviceUpdateReq.getId());
|
||||
if (!StringUtils.isEmpty(deviceUpdateReq.getCategory())) {
|
||||
device.setCategory(deviceUpdateReq.getCategory());
|
||||
}
|
||||
if (!StringUtils.isEmpty(deviceUpdateReq.getDeviceName())) {
|
||||
device.setDeviceName(deviceUpdateReq.getDeviceName());
|
||||
}
|
||||
if (!StringUtils.isEmpty(deviceUpdateReq.getDeviceType())) {
|
||||
device.setDeviceType(deviceUpdateReq.getDeviceType());
|
||||
}
|
||||
/*if (deviceUpdateReq.getDeviceType() == null) {
|
||||
throw new BusinessException(BaseResponseCode.CHOOSE_DEVICE);
|
||||
}*/
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//设备型号,经度,维度等信息存入json
|
||||
if (deviceUpdateReq.getLatitude() != null) {
|
||||
jsonObject.put("latitude", deviceUpdateReq.getLatitude());
|
||||
}
|
||||
if (deviceUpdateReq.getLongitude() != null) {
|
||||
jsonObject.put("longitude", deviceUpdateReq.getLongitude());
|
||||
}
|
||||
if (deviceUpdateReq.getAddress() != null) {
|
||||
jsonObject.put("address", deviceUpdateReq.getAddress());
|
||||
}
|
||||
if (deviceUpdateReq.getDeviceModel() != null) {
|
||||
jsonObject.put("deviceModel", deviceUpdateReq.getDeviceModel());
|
||||
}
|
||||
if (deviceUpdateReq.getKwhFee() != null) {
|
||||
jsonObject.put("kwhFee", deviceUpdateReq.getKwhFee());
|
||||
}
|
||||
if (deviceUpdateReq.getServiceFee() != null) {
|
||||
jsonObject.put("serviceFee", deviceUpdateReq.getServiceFee());
|
||||
}
|
||||
if (!jsonObject.isEmpty()) {
|
||||
device.setDeviceJson(jsonObject);
|
||||
}
|
||||
|
||||
int i = deviceService.updateChargePile(device);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("pageByDeviceType")
|
||||
@ApiOperation(value = "设备列表,不分页(设备批量下发页面查询使用)")
|
||||
public DataResult<List<DeviceRespVO>> pageByDeviceType(@RequestBody @Valid DeviceByDeviceTypeReq vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
//设置集团id
|
||||
deviceReqVO.setGroupId(simpleUser.getGroupId());
|
||||
deviceReqVO.setDeviceTypePrefix(vo.getDeviceType());
|
||||
List<DeviceRespVO> pageListByDeviceType = deviceService.getListByDeviceType(deviceReqVO);
|
||||
return DataResult.success(pageListByDeviceType);
|
||||
}
|
||||
|
||||
@PostMapping("getInterval")
|
||||
@ApiOperation(value = "查询电站下的间隔")
|
||||
public DataResult<List<DeviceRespVO>> getInterval(@RequestBody DeviceIntervalReqVo vo) {
|
||||
vo.setCategory(CommonConstant.TWO);
|
||||
List<DeviceRespVO> deviceList = deviceService.getIntervalDevice(vo);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@PostMapping("getIntervalDevice")
|
||||
@ApiOperation(value = "查询间隔下的设备")
|
||||
public DataResult<List<DeviceRespVO>> getIntervalDevice(@RequestBody DeviceIntervalReqVo vo) {
|
||||
List<DeviceRespVO> deviceList = deviceService.getIntervalDevice(vo);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "树状结构设备(设备带接入点,告警页面专用)")
|
||||
@PostMapping("treeDevices")
|
||||
public DataResult<List<DevicePointResp>> treeDevices(@RequestBody DeviceStationReqVo deviceTypeReq) {
|
||||
List<DeviceRespVO> deviceList = deviceService.selectAllDeviceAndSrcIdNotZero(deviceTypeReq.getStationId());
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectDeviceByStationId(deviceTypeReq.getStationId());
|
||||
Map<Integer, List<DeviceRespVO>> dataMap = deviceRespVOS.stream().collect(Collectors.groupingBy(DeviceRespVO::getId));
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
if (!dataMap.containsKey(deviceRespVO.getId())) {
|
||||
deviceRespVOS.add(deviceRespVO);
|
||||
}
|
||||
}
|
||||
List<DevicePointResp> treeDevices = new ArrayList<>();
|
||||
if (!deviceRespVOS.isEmpty()) {
|
||||
treeDevices = deviceTypeConfigService.getTreeDevices(deviceRespVOS);
|
||||
}
|
||||
return DataResult.success(treeDevices);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "树状结构设备(储能总览,设备列表页面专用)")
|
||||
@PostMapping("homePageTreeDevices")
|
||||
public DataResult<List<DevicePointResp>> homePageTreeDevices(@RequestBody DeviceTreeReq vo) {
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectByIdAndSrcIdNotZero(vo.getStationId());
|
||||
List<DevicePointResp> treeDevices = new ArrayList<>();
|
||||
if (!deviceRespVOS.isEmpty()) {
|
||||
treeDevices = deviceTypeConfigService.getTreeDevices(deviceRespVOS, vo.getSrcId());
|
||||
}
|
||||
return DataResult.success(treeDevices);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "平铺过滤隐藏的真实设备(储能总览,设备列表页面APP专用)")
|
||||
@PostMapping("appHomePageDevices")
|
||||
public DataResult<List<DeviceRespVO>> appHomePageDevices(@RequestBody DeviceTreeReq vo) {
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectByIdAndSrcIdNotZero(vo.getStationId());
|
||||
deviceRespVOS = deviceRespVOS.stream().filter(i -> i.getCategory() > CommonConstant.TWO).collect(Collectors.toList());
|
||||
return DataResult.success(deviceRespVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据条件生成树状结构设备")
|
||||
@PostMapping("treeVirtualDevices")
|
||||
public DataResult<List<DevicePointResp>> treeVirtualDevices(@RequestBody DeviceTreeReq vo) {
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectAllDeviceAndSrcIdNotZero(vo.getStationId());
|
||||
List<DevicePointResp> treeDevices = new ArrayList<>();
|
||||
if (null != deviceRespVOS && !deviceRespVOS.isEmpty()) {
|
||||
List<DeviceRespVO> deviceGroupRespVOS = deviceService.selectGroup(deviceRespVOS);
|
||||
if (!deviceGroupRespVOS.isEmpty()) {
|
||||
treeDevices = deviceTypeConfigService.getTreeDevices(deviceGroupRespVOS, vo.getSrcId());
|
||||
}
|
||||
}
|
||||
return DataResult.success(treeDevices);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据条件生成树状结构设备(真实设备)")
|
||||
@TokenIgnore
|
||||
@PostMapping("treeTrueDevices")
|
||||
public DataResult<List<DevicePointResp>> treeTrueDevices(@RequestBody DeviceTreeReq vo) {
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectAllDeviceAndSrcIdNotZero(vo.getStationId());
|
||||
deviceRespVOS = deviceRespVOS.stream().filter(i -> CommonConstant.ZERO.equals(i.getVirtual())).collect(Collectors.toList());
|
||||
List<DeviceRespVO> deviceGroupRespVOS = deviceService.selectGroup(deviceRespVOS);
|
||||
List<DevicePointResp> treeDevices = new ArrayList<>();
|
||||
if (!deviceGroupRespVOS.isEmpty()) {
|
||||
treeDevices = deviceTypeConfigService.getTreeDevices(deviceGroupRespVOS, vo.getSrcId());
|
||||
}
|
||||
return DataResult.success(treeDevices);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加删除功能,且只删除新增的虚拟设备;
|
||||
*
|
||||
* @param deviceId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除")
|
||||
@LogAnnotation(title = "业务模块-设备管理", action = "删除虚拟设备")
|
||||
public DataResult deletePlanningPolicy(@RequestBody DeviceIdReqVo deviceId) {
|
||||
deviceService.deleteById(deviceId.getId());
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//4、增加一个真实设备列表(v0 c3)
|
||||
@PostMapping("getRealDevice")
|
||||
@ApiOperation(value = "查询电站下的真实设备")
|
||||
public DataResult<List<Device>> getRealDevice(@RequestBody DeviceIntervalReqVo vo) {
|
||||
Device device = new Device();
|
||||
device.setStationId(vo.getStationId());
|
||||
device.setVirtual(CommonConstant.ZERO);
|
||||
device.setCategory(CommonConstant.THREE);
|
||||
List<Device> deviceList = deviceService.getRealDevice(device);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
//加一个查询虚拟设备的接口
|
||||
@PostMapping("getVirtualDevice")
|
||||
@ApiOperation(value = "查询虚拟设备的接口")
|
||||
public DataResult<List<Device>> getVirtualDevice(@RequestBody DeviceIntervalReqVo vo) {
|
||||
Device device = new Device();
|
||||
device.setStationId(vo.getStationId());
|
||||
device.setVirtual(CommonConstant.ONE);
|
||||
device.setCategory(CommonConstant.THREE);
|
||||
device.setDeviceName(vo.getName());
|
||||
List<Device> deviceList = deviceService.getRealDevice(device);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@PostMapping("getChildDevice")
|
||||
@ApiOperation(value = "查询设备下子设备")
|
||||
public DataResult<List<Device>> getChildDevice(@RequestBody DeviceIntervalReqVo vo) {
|
||||
Device device = new Device();
|
||||
device.setStationId(vo.getStationId());
|
||||
device.setPid(vo.getSrcId());
|
||||
List<Device> deviceList = deviceService.getRealDevice(device);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
//一键同步功能
|
||||
@PostMapping("/getSynchronousVD")
|
||||
@ApiOperation(value = "一键同步虚拟设备功能")
|
||||
@LogAnnotation(title = "业务模块-设备管理", action = "一键同步虚拟设备功能")
|
||||
//deviceType
|
||||
public DataResult getSynchronousVD(@RequestBody SynchronousReqVo vo) {
|
||||
deviceService.getSynchronousVD(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param vo
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation(value = "导出数据")
|
||||
public void exportExcel(@RequestBody ExportReq vo, HttpServletResponse response) {
|
||||
deviceService.exportExcel(vo,response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入文件
|
||||
* @param file
|
||||
* @param type
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
@ApiOperation(value = "导入数据")
|
||||
public DataResult importExcel(@RequestBody MultipartFile file,@RequestParam Integer type) {
|
||||
deviceService.importExcel(file,type);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,191 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
|
||||
import com.ho.business.entity.DeviceTypeCol;
|
||||
import com.ho.business.entity.ModelDeviceCol;
|
||||
import com.ho.business.entity.ModelTypeCol;
|
||||
import com.ho.business.service.DeviceModelService;
|
||||
import com.ho.business.service.ModelDeviceColService;
|
||||
import com.ho.business.vo.req.deviceModel.DeviceColSelectReqVo;
|
||||
import com.ho.business.vo.req.deviceModel.DeviceModelAddReqVo;
|
||||
import com.ho.business.vo.req.deviceModel.DeviceModelDeleteReqVo;
|
||||
import com.ho.business.vo.req.deviceModel.DeviceTypeColAddReq;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 设备端和模型的增删改查
|
||||
* @DateTime: 2023/3/7 16:43
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "deviceModel")
|
||||
@Api(tags = "业务模块-设备_模型字段管理")
|
||||
public class DeviceModelController {
|
||||
|
||||
@Autowired
|
||||
DeviceModelService deviceModelService;
|
||||
|
||||
@Autowired
|
||||
ModelDeviceColService modelDeviceColService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
//设备字典表 (新增 修改 查询入参(deviceType ) 删除(加判断逻辑,查看是否已经引用))
|
||||
@PostMapping("addBatchDevice")
|
||||
@ApiOperation(value = "新增设备字段接口")
|
||||
@LogAnnotation(title = "设备字段管理", action = "新增设备字段信息")
|
||||
@HzPermission(PermissionConstant.SYS_EMSDEVICE_ADD)
|
||||
public DataResult<DeviceTypeCol> addBatchDevice(@RequestBody @Validated DeviceModelAddReqVo vo) {
|
||||
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_EQUIPMENT_FIELD);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
deviceModelService.addBatchDevice(vo);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("addDeviceTypeCol")
|
||||
@ApiOperation(value = "新增单个设备字段接口")
|
||||
@LogAnnotation(title = "设备字段管理", action = "新增设备字段信息")
|
||||
public DataResult<DeviceTypeCol> addDeviceTypeCol(@RequestBody @Validated DeviceTypeColAddReq vo) {
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_EQUIPMENT_FIELD);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
deviceModelService.addDeviceTypeCol(vo);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteBatchDevice")
|
||||
@ApiOperation(value = "批量删除设备字段")
|
||||
@LogAnnotation(title = "设备字段管理", action = "批量删除设备字段")
|
||||
@HzPermission(PermissionConstant.SYS_EMSDEVICE_DELETE)
|
||||
public DataResult deleteBatchDevice(@RequestBody @Valid DeviceModelDeleteReqVo vo) {
|
||||
deviceModelService.deleteBatchDevice(vo);
|
||||
return DataResult.success();
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/deviceColPage")
|
||||
@ApiOperation(value = "分页查询设备字段接口")
|
||||
public DataResult<PageResult<DeviceTypeCol>> deviceColPage(@RequestBody DeviceColSelectReqVo vo) {
|
||||
//PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
List<DeviceTypeCol> deviceColPage = deviceModelService.deviceColPage(vo);
|
||||
//通过type和DeviceTypeColId 去关联表中查找数据,然后对比
|
||||
List<Integer> collect = deviceColPage.stream().map(DeviceTypeCol::getId).collect(Collectors.toList());
|
||||
List<ModelDeviceCol> modelDeviceCols = modelDeviceColService.selectByDeviceIds(collect, vo.getType());
|
||||
Map<Integer, List<ModelDeviceCol>> modelMap = modelDeviceCols.stream().collect(Collectors.groupingBy(ModelDeviceCol::getDeviceColId));
|
||||
for (DeviceTypeCol deviceTypeCol : deviceColPage) {
|
||||
if (modelMap.get(deviceTypeCol.getId()) != null) {
|
||||
deviceTypeCol.setChange(false);
|
||||
} else {
|
||||
deviceTypeCol.setChange(true);
|
||||
}
|
||||
}
|
||||
//PageResult pageResult = PageUtils.getPageResult(new PageInfo<>(deviceColPage));
|
||||
return DataResult.success(deviceColPage);
|
||||
}
|
||||
|
||||
|
||||
//模型字典表 (新增 修改 查询 删除)
|
||||
@PostMapping("/ModelColPage")
|
||||
@ApiOperation(value = "分页查询模型字段接口")
|
||||
public DataResult<PageResult<ModelTypeCol>> ModelColPage(@RequestBody DeviceColSelectReqVo vo) {
|
||||
List<ModelTypeCol> modelColPage = deviceModelService.ModelColPage(vo);
|
||||
//查询已经被使用过的模型字段 根据deviceType 和模型Id进行查询
|
||||
List<Integer> collect = modelColPage.stream().map(ModelTypeCol::getId).collect(Collectors.toList());
|
||||
|
||||
List<ModelDeviceCol> modelDeviceCols = modelDeviceColService.selectByModelType(collect, vo.getType());
|
||||
|
||||
//增加模型是否被使用判断
|
||||
Map<Integer, List<ModelDeviceCol>> modelMap = modelDeviceCols.stream().collect(Collectors.groupingBy(ModelDeviceCol::getModelColId));
|
||||
for (ModelTypeCol modelTypeCol : modelColPage) {
|
||||
if (modelMap.get(modelTypeCol.getId()) != null) {
|
||||
modelTypeCol.setChange(false);
|
||||
} else {
|
||||
modelTypeCol.setChange(true);
|
||||
}
|
||||
}
|
||||
return DataResult.success(modelColPage);
|
||||
}
|
||||
|
||||
@PostMapping("addBatchModel")
|
||||
@ApiOperation(value = "新增模型字段接口")
|
||||
@HzPermission(PermissionConstant.SYS_EMSMODEL_ADD)
|
||||
@LogAnnotation(title = "模型字段管理", action = "新增模型字段信息")
|
||||
public DataResult<ModelTypeCol> addBatchModel(@RequestBody @Valid DeviceModelAddReqVo vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
vo.setGroupId(user.getGroupId());
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_MODEL_CONFIG);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
deviceModelService.addBatchModel(vo);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteBatchModel")
|
||||
@ApiOperation(value = "批量删除模型字段")
|
||||
@LogAnnotation(title = "模型字段管理", action = "批量删除模型字段")
|
||||
@HzPermission(PermissionConstant.SYS_EMSMODEL_DELETE)
|
||||
public DataResult deleteBatchModel(@RequestBody @Valid DeviceModelDeleteReqVo vo) {
|
||||
deviceModelService.deleteBatchModel(vo);
|
||||
return DataResult.success();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,206 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.ho.business.constant.FileTypeConstant;
|
||||
import com.ho.business.entity.DeviceTypeCol;
|
||||
import com.ho.business.service.DeviceTypeColService;
|
||||
import com.ho.business.vo.req.DeviceTypeColImportVO;
|
||||
import com.ho.business.vo.req.deviceModel.SynchronousReqVo;
|
||||
import com.ho.business.vo.req.deviceTypeCol.DeviceTypeColQueryVo;
|
||||
import com.ho.business.vo.resp.DeviceTypeColExportVO;
|
||||
import com.ho.business.vo.resp.DeviceTypeColRespVO;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.DefineConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.EasyExcelUtil;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description device_type_col相关数据操作
|
||||
* @Author : xueweizhi
|
||||
* @Date : 2023/3/16 14:09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "deviceTypeCol")
|
||||
@Api(tags = "点表数据操作")
|
||||
@Slf4j
|
||||
public class DeviceTypeColController {
|
||||
|
||||
@Autowired
|
||||
DeviceTypeColService deviceTypeColService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
/**
|
||||
* 读取excel文件
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
@ApiOperation(value = "导入点表数据")
|
||||
@LogAnnotation(title = "点表数据操作", action = "导入电表数据")
|
||||
public DataResult importExcel(@RequestBody MultipartFile file, HttpServletRequest httpServletRequest) {
|
||||
String token = httpServletRequest.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String msg = null;
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") != -1) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
||||
extension = extension.toLowerCase();
|
||||
}
|
||||
if (!FileTypeConstant.XLS.equals(extension)) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_FORMAT_ONLY);
|
||||
}
|
||||
try {
|
||||
List<DeviceTypeColImportVO> list = EasyExcel.read(file.getInputStream()).head(DeviceTypeColImportVO.class).sheet().doReadSync();
|
||||
int len = list.size();
|
||||
DeviceTypeColImportVO deviceTypeCol = null;
|
||||
Map<String, DeviceTypeColImportVO> map = new HashMap<>();
|
||||
for (int i = 0; i < len; i++) {
|
||||
deviceTypeCol = list.get(i);
|
||||
if (!CommonConstant.ONE.equals(deviceTypeCol.getIsSave()) && !CommonConstant.ZERO.equals(deviceTypeCol.getIsSave())) {
|
||||
log.info("导入模板是否可写,第{}行填值错误填值错误,只能是0或1,{}", (i + 1), deviceTypeCol.getIsSave());
|
||||
// msg = "导入模板是否可写,第" + (i + 1) + "行填值错误,只能是0或1";
|
||||
msg = DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPECOL_CHECK1 + (i + 1) + DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPECOL_CHECK2;
|
||||
break;
|
||||
}
|
||||
if (deviceTypeCol.getMaxValue() == null || deviceTypeCol.getMinValue() == null) {
|
||||
log.info("导入模板最大值最小值,第{}行填值错误,maxValue:{},minValue:{}", (i + 1), deviceTypeCol.getMaxValue(), deviceTypeCol.getMinValue());
|
||||
// msg = "导入模板最大值最小值,第" + (i + 1) + "行填值错误,不能为空";
|
||||
msg = DefineConstant.DeviceTypeCol.IMPORT_VALUE_MAXVALUE_CHECK1 + (i + 1) + DefineConstant.DeviceTypeCol.IMPORT_VALUE_MAXVALUE_CHECK2;
|
||||
break;
|
||||
}
|
||||
if (CommonConstant.THREE.equals(deviceTypeCol.getSensType()) || CommonConstant.ONE.equals(deviceTypeCol.getSensType())) {
|
||||
if (BigDecimal.ONE.compareTo(deviceTypeCol.getMaxValue()) != 0 || BigDecimal.ZERO.compareTo(deviceTypeCol.getMinValue()) != 0) {
|
||||
log.info("导入模板最大值最小值,第{}行填值错误,遥控最大值只能填写1,最小值只能填0,maxValue:{},minValue:{}", (i + 1), deviceTypeCol.getMaxValue(), deviceTypeCol.getMinValue());
|
||||
// msg = "导入模板最大值最小值,第" + (i + 1) + "行填值错误,遥控最大值只能填写1,最小值只能填0";
|
||||
msg = DefineConstant.DeviceTypeCol.IMPORT_VALUE_SENSTYPE_CHECK1 + (i + 1) + DefineConstant.DeviceTypeCol.IMPORT_VALUE_SENSTYPE_CHECK2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (map.get(deviceTypeCol.getDeviceType() + "_" + deviceTypeCol.getCol()) != null) {
|
||||
// msg = "导入模板第" + (i + 1) + "行填值错误,已存类型为" + deviceTypeCol.getDeviceType() + "且字段key为" + deviceTypeCol.getCol() + "的值";
|
||||
msg = DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPE_CHECK1 + (i + 1) + DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPE_CHECK2 + deviceTypeCol.getDeviceType() + DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPE_CHECK3 + deviceTypeCol.getCol() + DefineConstant.DeviceTypeCol.IMPORT_VALUE_DEVICETYPE_CHECK4;
|
||||
break;
|
||||
}
|
||||
map.put(deviceTypeCol.getDeviceType() + "_" + deviceTypeCol.getCol(), deviceTypeCol);
|
||||
}
|
||||
if (null == msg) {
|
||||
int count = deviceTypeColService.insertList(list,user.getGroupId());
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA.getCode(), msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
if (msg != null) {
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA.getCode(), msg);
|
||||
}
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出点表数据
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation(value = "导出点表数据")
|
||||
@LogAnnotation(title = "点表数据操作", action = "导出电表数据")
|
||||
public void exportExcel(@RequestBody DeviceTypeColRespVO deviceTypeColRespVO, HttpServletResponse response) {
|
||||
List<DeviceTypeCol> deviceList = deviceTypeColService.selectByDeviceType(deviceTypeColRespVO.getDeviceType());
|
||||
String fileName = "点表";
|
||||
String sheetName = "点表数据";
|
||||
try {
|
||||
List<DeviceTypeColExportVO> exportList = new ArrayList<>();
|
||||
DeviceTypeColExportVO deviceTypeColExportVO = null;
|
||||
for (DeviceTypeCol typeCol : deviceList) {
|
||||
deviceTypeColExportVO = new DeviceTypeColExportVO();
|
||||
BeanUtils.copyProperties(typeCol, deviceTypeColExportVO);
|
||||
exportList.add(deviceTypeColExportVO);
|
||||
}
|
||||
EasyExcelUtil.writeExcel(response, exportList, fileName, sheetName, DeviceTypeColExportVO.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("exportTemplate")
|
||||
@ApiOperation(value = "导出模板")
|
||||
@LogAnnotation(title = "点表数据操作", action = "导出模板")
|
||||
public void exportTemplate(HttpServletResponse response) {
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
String fileName = URLEncoder.encode("deviceTypeColTemplate.xls", "utf-8");
|
||||
InputStream fis = getResourcesFileInputStream("template/deviceTypeColTemplate.xls");
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
response.setHeader("Content-disposition", "attachment;fileName=" + fileName);
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
out = response.getOutputStream();
|
||||
out.write(buffer);
|
||||
} catch (Exception ex) {
|
||||
log.error("下载失败,{}", ex.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
assert out != null;
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出模板
|
||||
private static InputStream getResourcesFileInputStream(String fileName) {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperation(value = "分页查询点表数据")
|
||||
public DataResult<PageResult<DeviceTypeCol>> page(@RequestBody DeviceTypeColQueryVo vo) {
|
||||
PageResult<DeviceTypeCol> deviceTypeColPageResult = deviceTypeColService.selectPage(vo);
|
||||
return DataResult.success(deviceTypeColPageResult);
|
||||
}
|
||||
|
||||
@PostMapping("/syPointTable")
|
||||
@ApiOperation(value = "一键同步点表")
|
||||
@LogAnnotation(title = "业务模块-点表数据操作", action = "一键同步点表功能")
|
||||
public DataResult syPointTable(@RequestBody SynchronousReqVo vo) {
|
||||
deviceTypeColService.syPointTable(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,314 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.DeviceTypeConfig;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.DeviceTypeConfigService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.device.*;
|
||||
import com.ho.business.vo.req.deviceModel.SynchronousReqVo;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.device.DeviceTypeSimpleResp;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 设备类型配置
|
||||
* @date 2023/3/18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "deviceConfig")
|
||||
@Api(tags = "业务模块-设备类型配置")
|
||||
public class DeviceTypeConfigController {
|
||||
|
||||
@Autowired
|
||||
DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "分页查询设备类型配置列表")
|
||||
public DataResult<PageResult<DeviceTypeConfig>> page(@RequestBody DeviceStationPageReqVo reqVo, HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//改为从预置的简化表中查有效的设备
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setStationId(reqVo.getStationId());
|
||||
//查集团和该电站的设备类型
|
||||
//deviceTypeQuery.setType("all");
|
||||
PageHelper.startPage(reqVo.getPageNum(), reqVo.getPageSize());
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
//看有几个站
|
||||
Map<Integer, List<DeviceTypeConfig>> stationDeviceMap = deviceTypeConfigs.stream().filter(d -> d.getStationId() != null)
|
||||
.collect(Collectors.groupingBy(DeviceTypeConfig::getStationId));
|
||||
Map<Integer, String> stationMap = new HashMap<>();
|
||||
for (Integer stationId : stationDeviceMap.keySet()) {
|
||||
Station station = stationService.selectById(stationId);
|
||||
if (station != null) {
|
||||
stationMap.putIfAbsent(station.getId(), station.getName());
|
||||
}
|
||||
|
||||
}
|
||||
//补充电站名称
|
||||
for (DeviceTypeConfig deviceTypeConfig : deviceTypeConfigs) {
|
||||
if (stationMap.containsKey(deviceTypeConfig.getStationId())) {
|
||||
deviceTypeConfig.setStationName(stationMap.get(deviceTypeConfig.getStationId()));
|
||||
}
|
||||
}
|
||||
return DataResult.success(PageUtils.getPageResult(new PageInfo<>(deviceTypeConfigs)));
|
||||
}
|
||||
|
||||
@PostMapping("queryDeviceTypeListForGroup")
|
||||
@ApiOperation(value = "scope是电站的时候查询集团级别的设备类型")
|
||||
public DataResult<List<DeviceTypeConfig>> queryDeviceTypeListForGroup(HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setScope(DeviceTypeConstant.SCOPE_GROUP);
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
return DataResult.success(deviceTypeConfigs);
|
||||
}
|
||||
|
||||
//查询单个
|
||||
@PostMapping("findOne")
|
||||
@ApiOperation(value = "根据id查询单个对象")
|
||||
public DataResult<DeviceTypeConfig> findOne(@RequestBody DeviceIdReqVo reqVo) {
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.queryById(reqVo.getId());
|
||||
if (deviceTypeConfig == null) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
return DataResult.success(deviceTypeConfig);
|
||||
}
|
||||
|
||||
@PostMapping("queryListByStation")
|
||||
@ApiOperation(value = "按电站查询设备类型,维护设备的设备类型时使用")
|
||||
public DataResult<List<DeviceTypeConfig>> queryListByStation(@RequestBody DeviceStationReqVo reqVo, HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//改为从预置的简化表中查有效的设备
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setStationId(reqVo.getStationId());
|
||||
//查集团和该电站的设备类型
|
||||
deviceTypeQuery.setType("all");
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
return DataResult.success(deviceTypeConfigs);
|
||||
}
|
||||
|
||||
@PostMapping("queryList")
|
||||
@ApiOperation(value = "根据用户所在组,查询集团级的设备类型")
|
||||
public DataResult<List<DeviceTypeConfig>> queryList(HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//改为从预置的简化表中查有效的设备
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
//查集团设备类型
|
||||
deviceTypeQuery.setScope(CommonConstant.ONE);
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
return DataResult.success(deviceTypeConfigs);
|
||||
}
|
||||
|
||||
@PostMapping("queryDeviceTypeByGroup")
|
||||
@ApiOperation(value = "查集团设备类型(只显示大类型)")
|
||||
public DataResult<List<DeviceTypeSimpleResp>> queryDeviceTypeByGroup(HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//改为从预置的简化表中查有效的设备
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
//查集团级
|
||||
deviceTypeQuery.setScope(DeviceTypeConstant.SCOPE_GROUP);
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
//要返回的结果对象
|
||||
List<DeviceTypeSimpleResp> deviceTypeList = new ArrayList<>();
|
||||
//各种逆变器类型需要汇总,截取_前面的
|
||||
String deviceTypeNew = null;
|
||||
for (DeviceTypeConfig deviceTypeConfig : deviceTypeConfigs) {
|
||||
deviceTypeNew = deviceTypeConfig.getDeviceType();
|
||||
if (deviceTypeNew.contains("_")) {
|
||||
deviceTypeNew = deviceTypeNew.substring(0, deviceTypeNew.indexOf("_"));
|
||||
deviceTypeConfig.setDeviceType(deviceTypeNew);
|
||||
}
|
||||
}
|
||||
Map<String, List<DeviceTypeConfig>> deviceTypeMap = deviceTypeConfigs.stream().collect(Collectors.groupingBy(DeviceTypeConfig::getDeviceType));
|
||||
for (Map.Entry<String, List<DeviceTypeConfig>> entry : deviceTypeMap.entrySet()) {
|
||||
DeviceTypeSimpleResp deviceTypeSimple = new DeviceTypeSimpleResp();
|
||||
deviceTypeSimple.setDeviceType(entry.getKey());
|
||||
DeviceTypeConfig deviceTypeConfig = entry.getValue().get(0);
|
||||
String deviceTypeName = deviceTypeConfig.getName();
|
||||
if (deviceTypeName.contains("(")) {
|
||||
deviceTypeName = deviceTypeName.substring(0, deviceTypeName.indexOf("("));
|
||||
}
|
||||
deviceTypeSimple.setDeviceTypeName(deviceTypeName);
|
||||
deviceTypeList.add(deviceTypeSimple);
|
||||
}
|
||||
|
||||
return DataResult.success(deviceTypeList);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增一个设备类型配置")
|
||||
@LogAnnotation(title = "业务模块-设备类型配置", action = "新增设备类型配置")
|
||||
@HzPermission(PermissionConstant.SYS_DEVICETYPE_ADD)
|
||||
public DataResult add(@RequestBody DeviceTypeConfigAddReq reqVo, HttpServletRequest request) {
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
Integer stationId = null;
|
||||
Station station = null;
|
||||
//平台用户不能新增,需要集团用户新增
|
||||
if (CommonConstant.ZERO.equals(user.getDeptId())) {
|
||||
throw new BusinessException(BaseResponseCode.PLAT_USER_CANNOT_OPERATE);
|
||||
}
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setScope(reqVo.getScope());
|
||||
//判断是否有重复数据
|
||||
//是集团就排除电站,只有电站才带上stationId
|
||||
if (DeviceTypeConstant.SCOPE_STATION.equals(reqVo.getScope())) {
|
||||
//当为电站时,电站id必须传递
|
||||
if (reqVo.getStationId() == null) {
|
||||
throw new BusinessException(BaseResponseCode.SCOPE_IS_STATION_ID_CANNOT_NULL);
|
||||
}
|
||||
stationId = reqVo.getStationId();
|
||||
station = stationService.selectById(stationId);
|
||||
if (station == null) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_YC_NOT_EXISTS);
|
||||
}
|
||||
deviceTypeQuery.setStationId(stationId);
|
||||
//电站维度,因为前端传入的deviceType是集团的,所以查询时需要做个处理,把 deviceType 加上电站后缀
|
||||
String stationDeviceType = reqVo.getDeviceType() + "_" + station.getId();
|
||||
deviceTypeQuery.setDeviceType(stationDeviceType);
|
||||
deviceTypeQuery.setName(null);
|
||||
} else if (DeviceTypeConstant.SCOPE_GROUP.equals(reqVo.getScope())) {
|
||||
//集团级
|
||||
//devicetype 做重复判断
|
||||
deviceTypeQuery.setDeviceType(reqVo.getDeviceType());
|
||||
/* deviceTypeQuery.setName(reqVo.getName());*/
|
||||
}
|
||||
//模型名不需要判断重复
|
||||
//判断是否有同名的
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
if (!deviceTypeConfigs.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_ALREADY_EXISTS);
|
||||
}
|
||||
//创建入库数据
|
||||
DeviceTypeConfig deviceTypeConfig = new DeviceTypeConfig();
|
||||
//这几个字段是公共的
|
||||
deviceTypeConfig.setGroupId(user.getGroupId());
|
||||
deviceTypeConfig.setScope(reqVo.getScope());
|
||||
deviceTypeConfig.setModelName(reqVo.getModelName());
|
||||
//集团级 的 设备类型使用用户输入的
|
||||
if (DeviceTypeConstant.SCOPE_GROUP.equals(reqVo.getScope())) {
|
||||
deviceTypeConfig.setDeviceType(reqVo.getDeviceType());
|
||||
deviceTypeConfig.setName(reqVo.getName());
|
||||
|
||||
} else if (DeviceTypeConstant.SCOPE_STATION.equals(reqVo.getScope())) {
|
||||
deviceTypeConfig.setStationId(reqVo.getStationId());
|
||||
//电站维度的设备类型 是全局类型 增加_stationId后缀
|
||||
deviceTypeConfig.setDeviceType(reqVo.getDeviceType() + "_" + station.getId());
|
||||
deviceTypeConfig.setName(reqVo.getName() + "_" + station.getName());
|
||||
}
|
||||
//创建人 创建时间
|
||||
deviceTypeConfig.setCreator(user.getUserId());
|
||||
deviceTypeConfig.setCreateTime(new Date());
|
||||
//scope是集团级 name不做修改, 如果是电站级 ,deviceType后缀加上电站id
|
||||
deviceTypeConfigService.add(deviceTypeConfig);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "更新设备类型配置")
|
||||
public DataResult update(@RequestBody DeviceTypeConfigAddReq reqVo) {
|
||||
deviceTypeConfigService.update(reqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除一个设备类型配置")
|
||||
@LogAnnotation(title = "业务模块-设备类型配置", action = "删除设备类型配置")
|
||||
@HzPermission(PermissionConstant.SYS_DEVICETYPE_DELETE)
|
||||
public DataResult delete(@RequestBody DeviceIdReqVo reqVo, HttpServletRequest request) {
|
||||
//先查是否有这个id
|
||||
DeviceTypeConfig deviceTypeConfig = deviceTypeConfigService.queryById(reqVo.getId());
|
||||
if (deviceTypeConfig == null) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
//根据token查用户
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//device表被引用就不能删除
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setGroupId(user.getGroupId());
|
||||
List<String> deviceTypeList = new ArrayList<>();
|
||||
deviceTypeList.add(deviceTypeConfig.getDeviceType());
|
||||
deviceReqVO.setDeviceTypeList(deviceTypeList);
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
if (!deviceList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.REFERENCES_EXIST_DELETED_DATA);
|
||||
}
|
||||
//逻辑删除,记录删除信息
|
||||
DeviceTypeConfig deviceTypeConfigDeleted = new DeviceTypeConfig();
|
||||
deviceTypeConfigDeleted.setId(deviceTypeConfig.getId());
|
||||
deviceTypeConfigDeleted.setDeleted(CommonConstant.DELETED_FLAG);
|
||||
deviceTypeConfigService.updateById(deviceTypeConfigDeleted);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/syDeviceTypeConfig")
|
||||
@ApiOperation(value = "一键同步设备类型配置")
|
||||
@LogAnnotation(title = "业务模块-设备类型配置", action = "一键同步设备类型配置")
|
||||
public DataResult syDeviceTypeConfig(@RequestBody SynchronousReqVo vo) {
|
||||
if (vo.getStationId() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_SRC_STATION);
|
||||
}
|
||||
if (vo.getModelStationId() == null || vo.getDesStationName() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_MODEL_STATION);
|
||||
}
|
||||
int result = deviceTypeConfigService.syDeviceTypeConfig(vo);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.DynamicConfigTitle;
|
||||
import com.ho.business.entity.PointPolysemyConfig;
|
||||
import com.ho.business.service.DynamicConfigService;
|
||||
import com.ho.business.vo.req.dynamicConfig.*;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.dynamicConfig.CurveConfigQueryResp;
|
||||
import com.ho.business.vo.resp.dynamicConfig.PointConfigDataResp;
|
||||
import com.ho.business.vo.resp.dynamicConfig.PointConfigResultResp;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "dynamicConfig")
|
||||
@Api(tags = "动态配置")
|
||||
public class DynamicConfigController {
|
||||
|
||||
@Autowired
|
||||
DynamicConfigService dynamicConfigService;
|
||||
|
||||
@PostMapping("addCurveList")
|
||||
@ApiOperation(value = "批量增加曲线配置信息")
|
||||
@HzPermission(PermissionConstant.CURVE_BATCH_CONFIGURATION)
|
||||
public DataResult addCurve(@RequestBody List<CurveConfigAdd> vo) {
|
||||
if (vo.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
//辅助线不需要绑定点过滤
|
||||
List<CurveConfigAdd> otherList = vo.stream().filter(i -> !(i.getCurveType() == null || CommonConstant.ONE.equals(i.getCurveType()))).collect(Collectors.toList());
|
||||
for (CurveConfigAdd c : otherList) {
|
||||
if (c.getList() == null || c.getList().isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_NOT_NULL);
|
||||
}
|
||||
//普通线
|
||||
if (CommonConstant.ZERO.equals(c.getCurveType()) && c.getList().size() != 1) {
|
||||
throw new BusinessException(BaseResponseCode.CURVE_DATA_ERROR);
|
||||
}
|
||||
}
|
||||
int result = dynamicConfigService.addCurveList(vo);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("queryCurveConfig")
|
||||
@ApiOperation(value = "查询曲线配置信息")
|
||||
public DataResult<List<CurveConfigQueryResp>> queryCurveConfig(@RequestBody DynamicConfigQuery vo) {
|
||||
List<CurveConfigQueryResp> result = dynamicConfigService.queryCurveConfig(vo);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("addPointList")
|
||||
@ApiOperation(value = "增加点配置信息")
|
||||
@HzPermission(PermissionConstant.ADDPOINTLIST)
|
||||
public DataResult addPointList(@RequestBody List<PointConfigAdd> list) {
|
||||
if (list.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
//除了自算尖峰平谷(4)不需要绑定点、自定义名称(10),其余都要校验绑定点位
|
||||
List<PointConfigAdd> sevenList = list.stream().filter(i -> !(i.getPointType() == null || CommonConstant.FOUR.equals(i.getPointType()) || CommonConstant.TEN.equals(i.getPointType()))).collect(Collectors.toList());
|
||||
for (PointConfigAdd p : sevenList) {
|
||||
if (p.getList() == null || p.getList().isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_NOT_NULL);
|
||||
}
|
||||
if (p.getList().size() != 1) {
|
||||
if (CommonConstant.ZERO.equals(p.getPointType()) || CommonConstant.TWO.equals(p.getPointType()) || CommonConstant.THREE.equals(p.getPointType())) {
|
||||
throw new BusinessException(BaseResponseCode.COMMON_POINT_DATA_ERROR);
|
||||
}
|
||||
}
|
||||
if (CommonConstant.THREE.equals(p.getPointType()) && (p.getDisassemble() == null || p.getDisassemble().getValue() == null)) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_DATA_ERROR);
|
||||
}
|
||||
if (CommonConstant.TWO.equals(p.getPointType())) {
|
||||
List<PointPolysemyConfig> polysemyList = p.getPolysemyList();
|
||||
if (polysemyList == null || polysemyList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_DATA_ERROR_MORE);
|
||||
} else {
|
||||
for (PointPolysemyConfig m : polysemyList) {
|
||||
if (m.getName() == null || m.getValue() == null) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_DATA_ERROR_MORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CommonConstant.ELEVEN.equals(p.getPointType())) {
|
||||
List<PointPolysemyConfig> polysemyList = p.getPolysemyList();
|
||||
if (polysemyList == null || polysemyList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_DATA_ERROR_MORE);
|
||||
} else {
|
||||
for (PointPolysemyConfig m : polysemyList) {
|
||||
if (m.getName() == null || m.getValue() == null || m.getSymbol() == null) {
|
||||
throw new BusinessException(BaseResponseCode.POINT_DATA_ERROR_MORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = dynamicConfigService.addPointList(list);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("pointList")
|
||||
@ApiOperation(value = "查询配置信息")
|
||||
public DataResult<List<PointConfigResultResp>> pointList(@RequestBody PointConfigQuery vo) {
|
||||
List<PointConfigResultResp> resultRespList = dynamicConfigService.pointList(vo);
|
||||
return DataResult.success(resultRespList);
|
||||
}
|
||||
|
||||
@PostMapping("pointListData")
|
||||
@ApiOperation(value = "配置点数据集合")
|
||||
public DataResult<List<PointConfigDataResp>> pointListData(@RequestBody PointConfigQuery vo) {
|
||||
List<PointConfigDataResp> pointConfigData = dynamicConfigService.getPointConfigData(vo);
|
||||
return DataResult.success(pointConfigData);
|
||||
}
|
||||
|
||||
@PostMapping("syncDynamicConfig")
|
||||
@ApiOperation(value = "同步动态配置")
|
||||
@HzPermission(PermissionConstant.SYNCDYNAMICCONFIG)
|
||||
public DataResult syncDynamicConfig(@RequestBody SyncDynamicConfigParam vo) {
|
||||
dynamicConfigService.syncDynamicConfig(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("dynamicConfigDevice")
|
||||
@ApiOperation(value = "查询配置页面设备")
|
||||
public DataResult<List<DeviceRespVO>> dynamicConfigDevice(@RequestBody SyncDynamicConfigDeviceQuery vo) {
|
||||
List<DeviceRespVO> deviceRespVOList = dynamicConfigService.dynamicConfigDevice(vo);
|
||||
return DataResult.success(deviceRespVOList);
|
||||
}
|
||||
|
||||
@PostMapping("addDynamicConfigTitle")
|
||||
@ApiOperation(value = "动态配置标题")
|
||||
public DataResult addDynamicConfigTitle(@RequestBody DynamicConfigTitle vo) {
|
||||
String name = vo.getName();
|
||||
if (name != null && name.length() > CommonConstant.FIFTY) {
|
||||
throw new BusinessException(BaseResponseCode.PARAM_EXCEED_LENGTH.getCode(), BaseResponseCode.PARAM_EXCEED_LENGTH.getMsg() + CommonConstant.FIFTY);
|
||||
}
|
||||
int count = dynamicConfigService.addDynamicConfigTitle(vo);
|
||||
return DataResult.success(count);
|
||||
}
|
||||
|
||||
@PostMapping("queryDynamicConfigTitle")
|
||||
@ApiOperation(value = "查询动态配置标题")
|
||||
public DataResult<List<DynamicConfigTitle>> queryDynamicConfigTitle(@RequestBody DynamicConfigTitle vo) {
|
||||
List<DynamicConfigTitle> dynamicConfigTitles = dynamicConfigService.queryDynamicConfigTitle(vo);
|
||||
return DataResult.success(dynamicConfigTitles);
|
||||
}
|
||||
|
||||
@PostMapping("delDynamicConfigTitle")
|
||||
@ApiOperation(value = "删除动态配置标题")
|
||||
@HzPermission(PermissionConstant.DELDYNAMICCONFIGTITLE)
|
||||
public DataResult delDynamicConfigTitle(@RequestBody DynamicConfigTitle vo) {
|
||||
int count = dynamicConfigService.delDynamicConfigTitle(vo);
|
||||
return DataResult.success(count);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,444 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
||||
import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
||||
import com.ho.business.entity.*;
|
||||
import com.ho.business.service.EarningsCalculateService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.util.QueuesUtil;
|
||||
import com.ho.business.vo.OneKeyComputationVo;
|
||||
import com.ho.business.vo.req.carbin.EarningsCalculateReq;
|
||||
import com.ho.business.vo.resp.cabin.EarningsCalculateResp;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "earningsCalculate")
|
||||
@Api(tags = "尖峰平谷电量电价")
|
||||
@Slf4j
|
||||
public class EarningsCalculateController {
|
||||
public static final Integer PAGE_LIST_TYPE = 0;
|
||||
public static final Integer REPORT_LIST_TYPE = 1;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
|
||||
@Autowired
|
||||
EarningsCalculateService earningsCalculateService;
|
||||
|
||||
@Autowired
|
||||
private StationService stationService;
|
||||
|
||||
@PostMapping("/getTotal")
|
||||
@ApiOperation(value = "获取月发电量报表")
|
||||
@TokenIgnore
|
||||
public DataResult<EarningsCalculateResp> getTotal(@RequestBody EarningsCalculateReq earningsCalculateReq){
|
||||
EarningsCalculateResp total = earningsCalculateService.getTotal(earningsCalculateReq,PAGE_LIST_TYPE);
|
||||
if( earningsCalculateReq != null && earningsCalculateReq.getStationId() != null ){
|
||||
Integer stationId = earningsCalculateReq.getStationId();
|
||||
OneKeyProgress oneKeyProgress = (OneKeyProgress) redisService.hget(QueuesUtil.PROGRESS_REDIS_KEY, stationId.toString());
|
||||
if( oneKeyProgress != null && earningsCalculateReq.getTime() != null
|
||||
&& oneKeyProgress.getDate() != null
|
||||
&& oneKeyProgress.getDate().equals(earningsCalculateReq.getTime())){
|
||||
double progress = oneKeyProgress.getProgress()==null?1:oneKeyProgress.getProgress();
|
||||
String format = df.format(progress * 100);
|
||||
total.setProgress(format);
|
||||
total.setFinish(0);
|
||||
if ( format.equals("100.00") ) {
|
||||
total.setFinish(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(total);
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/all")
|
||||
@ApiOperation(value = "查询所有电站接口")
|
||||
public void all(@RequestBody(required = false) String beginTime) {
|
||||
try {
|
||||
log.info("定时任务调用了/earningsCalculate/all方法:{}","执行了删除操作");
|
||||
/** todo: 先删除一下昨日数据 */
|
||||
/** start */
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
String yesterdayStr = DateUtil.formatDate(yesterday);
|
||||
if ( beginTime != null ) {
|
||||
int i = earningsCalculateService.deleteByDay(beginTime, null);
|
||||
} else {
|
||||
beginTime = yesterdayStr;
|
||||
int i = earningsCalculateService.deleteByDay(yesterdayStr, null);
|
||||
}
|
||||
// QueuesUtil.date = beginTime;
|
||||
/** end */
|
||||
} catch (Exception e) {
|
||||
log.error("删除昨日数据失败:{}",e.getMessage());
|
||||
}
|
||||
List<Station> stations = stationService.selectAll();
|
||||
//批量算的时候只计算
|
||||
stations = stations.stream().filter(i -> CommonConstant.ONE.equals(i.getStatus())).collect(Collectors.toList());
|
||||
earningsCalculateService.queryDeviceByStationId(stations,null,beginTime);
|
||||
}
|
||||
|
||||
private List<String> getBetweenDate(String begin,String end){
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
List<String> betweenList = new ArrayList<String>();
|
||||
|
||||
try{
|
||||
Calendar startDay = Calendar.getInstance();
|
||||
startDay.setTime(format.parse(begin));
|
||||
startDay.add(Calendar.DATE, -1);
|
||||
while(true){
|
||||
startDay.add(Calendar.DATE, 1);
|
||||
Date newDate = startDay.getTime();
|
||||
String newend=format.format(newDate);
|
||||
betweenList.add(newend);
|
||||
if(end.equals(newend)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return betweenList;
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/export")
|
||||
@ApiOperation(value = "导出")
|
||||
public void export(HttpServletRequest req, HttpServletResponse response, @RequestBody EarningsCalculateReq earningsCalculateReq) {
|
||||
EarningsCalculateResp total = earningsCalculateService.getTotal(earningsCalculateReq,PAGE_LIST_TYPE);
|
||||
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
response.setContentType("multipart/form-data");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//文件名字
|
||||
String fileName = "demo.xlsx";
|
||||
response.setHeader("Content-disposition", "attachment;filename=" +fileName);
|
||||
|
||||
//文件模板输入流
|
||||
InputStream inputStream = new ClassPathResource("template/earningsTemplate.xlsx").getInputStream();
|
||||
|
||||
// 添加合并单元格地址
|
||||
//List<CellRangeAddress> list = new ArrayList<>();
|
||||
////new CellRangeAddress(开始行,结束行,开始列,结束列)
|
||||
//list.add(new CellRangeAddress(4, 14, 0, 1));
|
||||
//list.add(new CellRangeAddress(4, 14, 2, 11));
|
||||
//list.add(new CellRangeAddress(4, 14, 12, 13));
|
||||
//ExcelWriter writer = EasyExcel.write(out).withTemplate(inputStream).build();
|
||||
//WriteSheet sheet = EasyExcel.writerSheet().registerWriteHandler(new MyHandler(0,list)).build();
|
||||
//填充列表开启自动换行,自动换行表示每次写入一条list数据是都会重新生成一行空行,此选项默认是关闭的,需要提前设置为true
|
||||
|
||||
ExcelWriter writer = EasyExcel.write(out).withTemplate(inputStream).build();
|
||||
WriteSheet sheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
|
||||
|
||||
List<EarningsCalculate> charge = new ArrayList<EarningsCalculate>();
|
||||
List<EarningCalculateDischarge> discharge = new ArrayList<EarningCalculateDischarge>();
|
||||
EarningCalculateDischarge earningCalculateDischarge = null;
|
||||
|
||||
/** todo: 拆分费率数据 */
|
||||
/** start */
|
||||
if( total != null && total.getList() != null ){
|
||||
List<EarningsCalculate> list = total.getList();
|
||||
for (EarningsCalculate earningsCalculate : list) {
|
||||
if( earningsCalculate.getType() == 0 ){
|
||||
charge.add(earningsCalculate);
|
||||
} else {
|
||||
earningCalculateDischarge = new EarningCalculateDischarge();
|
||||
earningCalculateDischarge.setDischarge(earningsCalculate.getDigital());
|
||||
earningCalculateDischarge.setDisElec(earningsCalculate.getElec());
|
||||
earningCalculateDischarge.setDisRateType(earningsCalculate.getRateType());
|
||||
discharge.add(earningCalculateDischarge);
|
||||
}
|
||||
}
|
||||
}
|
||||
/** end */
|
||||
|
||||
/** todo: 组装导出数据 */
|
||||
/** start */
|
||||
List<EarningsCalculate> newCharge = new ArrayList<EarningsCalculate>();
|
||||
EarningsCalculate earnings = null;
|
||||
int index = 0;
|
||||
if ( discharge.size() == charge.size() ) {
|
||||
for (EarningsCalculate earningsCalculate : charge) {
|
||||
earningsCalculate.setDischarge(discharge.get(index).getDischarge());
|
||||
earningsCalculate.setDisElec(discharge.get(index).getDisElec());
|
||||
earningsCalculate.setDisRateType(discharge.get(index).getDisRateType());
|
||||
index++;
|
||||
}
|
||||
} else if ( discharge.size() > charge.size() ){
|
||||
for (EarningCalculateDischarge calculateDischarge : discharge) {
|
||||
if( index < charge.size() ){
|
||||
charge.get(index).setDischarge(calculateDischarge.getDischarge());
|
||||
charge.get(index).setDisElec(calculateDischarge.getDisElec());
|
||||
charge.get(index).setDisRateType(calculateDischarge.getDisRateType());
|
||||
} else {
|
||||
earnings = new EarningsCalculate();
|
||||
earnings.setDischarge(calculateDischarge.getDischarge());
|
||||
earnings.setDisElec(calculateDischarge.getDisElec());
|
||||
earnings.setDisRateType(calculateDischarge.getDisRateType());
|
||||
newCharge.add(earnings);
|
||||
}
|
||||
}
|
||||
} else if ( discharge.size() < charge.size() ){
|
||||
for (EarningsCalculate earningsCalculate : charge) {
|
||||
if( index < discharge.size() ){
|
||||
earningsCalculate.setDischarge(discharge.get(index).getDischarge());
|
||||
earningsCalculate.setDisElec(discharge.get(index).getDisElec());
|
||||
earningsCalculate.setDisRateType(discharge.get(index).getDisRateType());
|
||||
}
|
||||
}
|
||||
}
|
||||
newCharge.addAll(charge);
|
||||
/** end */
|
||||
|
||||
|
||||
writer.fill(new FillWrapper("charge", newCharge), fillConfig, sheet);
|
||||
//填充数据
|
||||
writer.fill(total,fillConfig,sheet);
|
||||
//填充完成
|
||||
writer.finish();
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/exportReport")
|
||||
@ApiOperation(value = "导出")
|
||||
public void exportReport(HttpServletRequest req, HttpServletResponse response, @RequestBody EarningsCalculateReq earningsCalculateReq) {
|
||||
EarningsCalculateResp total = earningsCalculateService.getTotal(earningsCalculateReq,REPORT_LIST_TYPE);
|
||||
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
response.setContentType("multipart/form-data");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//文件名字
|
||||
String fileName = "demo.xlsx";
|
||||
response.setHeader("Content-disposition", "attachment;filename=" +fileName);
|
||||
//文件模板输入流
|
||||
InputStream inputStream = new ClassPathResource("template/earningsUserTemplate.xlsx").getInputStream();
|
||||
|
||||
// 添加合并单元格地址
|
||||
//List<CellRangeAddress> list = new ArrayList<>();
|
||||
////new CellRangeAddress(开始行,结束行,开始列,结束列)
|
||||
//list.add(new CellRangeAddress(4, 14, 0, 1));
|
||||
//list.add(new CellRangeAddress(4, 14, 2, 11));
|
||||
//list.add(new CellRangeAddress(4, 14, 12, 13));
|
||||
//ExcelWriter writer = EasyExcel.write(out).withTemplate(inputStream).build();
|
||||
//WriteSheet sheet = EasyExcel.writerSheet().registerWriteHandler(new MyHandler(0,list)).build();
|
||||
//填充列表开启自动换行,自动换行表示每次写入一条list数据是都会重新生成一行空行,此选项默认是关闭的,需要提前设置为true
|
||||
|
||||
ExcelWriter writer = EasyExcel.write(out).withTemplate(inputStream).build();
|
||||
WriteSheet sheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
|
||||
|
||||
List<EarningsCalculate> charge = new ArrayList<EarningsCalculate>();
|
||||
List<EarningCalculateDischarge> discharge = new ArrayList<EarningCalculateDischarge>();
|
||||
EarningCalculateDischarge earningCalculateDischarge = null;
|
||||
|
||||
/** todo: 拆分费率数据 */
|
||||
/** start */
|
||||
if( total != null && total.getList() != null ){
|
||||
List<EarningsCalculate> list = total.getList();
|
||||
for (EarningsCalculate earningsCalculate : list) {
|
||||
if( earningsCalculate.getType() == 0 ){
|
||||
charge.add(earningsCalculate);
|
||||
} else {
|
||||
earningCalculateDischarge = new EarningCalculateDischarge();
|
||||
earningCalculateDischarge.setDischarge(earningsCalculate.getDigital());
|
||||
earningCalculateDischarge.setDisElec(earningsCalculate.getElec());
|
||||
earningCalculateDischarge.setDisRateType(earningsCalculate.getRateType());
|
||||
discharge.add(earningCalculateDischarge);
|
||||
}
|
||||
}
|
||||
}
|
||||
/** end */
|
||||
|
||||
/** todo: 组装导出数据 */
|
||||
/** start */
|
||||
List<EarningsCalculate> newCharge = new ArrayList<EarningsCalculate>();
|
||||
EarningsCalculate earnings = null;
|
||||
int index = 0;
|
||||
if ( discharge.size() == charge.size() ) {
|
||||
for (EarningsCalculate earningsCalculate : charge) {
|
||||
earningsCalculate.setDischarge(discharge.get(index).getDischarge());
|
||||
earningsCalculate.setDisElec(discharge.get(index).getDisElec());
|
||||
earningsCalculate.setDisRateType(discharge.get(index).getDisRateType());
|
||||
index++;
|
||||
}
|
||||
} else if ( discharge.size() > charge.size() ){
|
||||
for (EarningCalculateDischarge calculateDischarge : discharge) {
|
||||
if( index < charge.size() ){
|
||||
charge.get(index).setDischarge(calculateDischarge.getDischarge());
|
||||
charge.get(index).setDisElec(calculateDischarge.getDisElec());
|
||||
charge.get(index).setDisRateType(calculateDischarge.getDisRateType());
|
||||
} else {
|
||||
earnings = new EarningsCalculate();
|
||||
earnings.setDischarge(calculateDischarge.getDischarge());
|
||||
earnings.setDisElec(calculateDischarge.getDisElec());
|
||||
earnings.setDisRateType(calculateDischarge.getDisRateType());
|
||||
newCharge.add(earnings);
|
||||
}
|
||||
}
|
||||
} else if ( discharge.size() < charge.size() ){
|
||||
for (EarningsCalculate earningsCalculate : charge) {
|
||||
if( index < discharge.size() ){
|
||||
earningsCalculate.setDischarge(discharge.get(index).getDischarge());
|
||||
earningsCalculate.setDisElec(discharge.get(index).getDisElec());
|
||||
earningsCalculate.setDisRateType(discharge.get(index).getDisRateType());
|
||||
}
|
||||
}
|
||||
}
|
||||
newCharge.addAll(charge);
|
||||
/** end */
|
||||
writer.fill(new FillWrapper("charge", newCharge), fillConfig, sheet);
|
||||
//填充数据
|
||||
writer.fill(total,fillConfig,sheet);
|
||||
//填充完成
|
||||
writer.finish();
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/freezeMonthTotalEle")
|
||||
@ApiOperation(value = "冻结月度总充总放")
|
||||
public void freezeMonthTotalEle(){
|
||||
/** todo: 查询所有电站,为所有电站进行月度总充总放做冻结(加上偏移量之后的冻结值) */
|
||||
List<Station> stations = stationService.selectAll();
|
||||
earningsCalculateService.freezeMonthTotalEle(stations);
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/testTemplateCurve")
|
||||
@ApiOperation(value = "测试获取电价模板")
|
||||
public DataResult<List<EarningsCalculateSub>> testTemplateCurve(){
|
||||
List<EarningsCalculateSub> earningsCalculateSubs = earningsCalculateService.queryElecTemplateSubByStationId(401, 0, DateUtil.now());
|
||||
return DataResult.success(earningsCalculateSubs);
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/testRateTemplateCurve")
|
||||
@ApiOperation(value = "测试获取电价模板")
|
||||
public DataResult<List<EarningsCalculateSub>> testRateTemplateCurve(){
|
||||
List<EarningsCalculateSub> earningsCalculateSubs = earningsCalculateService.queryElecRateTemplateSubByStationId(401, 0, DateUtil.now());
|
||||
return DataResult.success(earningsCalculateSubs);
|
||||
}
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/oneKeyComputation")
|
||||
@ApiOperation(value = "一键重算")
|
||||
@HzPermission(PermissionConstant.ONEKEYCOMPUTATION)
|
||||
public DataResult<Map<String,Object>> oneKeyComputation( @RequestBody OneKeyComputationVo vo) {
|
||||
Map<String,Object> result = new HashMap<String,Object>(0);
|
||||
result.put("msg","");
|
||||
result.put("progress","");
|
||||
result.put("finish","");
|
||||
// 重算执行标识,防止重复触发
|
||||
if( vo == null || vo.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
Integer stationId = vo.getStationId();
|
||||
// 判断队列里是否已经存在需要计算的数据,如果有则不继续计算,给页面扔出提示,阻止重复执行
|
||||
OneKeyProgress oneKeyProgress = (OneKeyProgress) redisService.hget(QueuesUtil.PROGRESS_REDIS_KEY, stationId.toString());
|
||||
if ( oneKeyProgress == null && vo.getStartTime() != null && vo.getEndTime() != null ) {
|
||||
List<Station> stations = stationService.selectAll();
|
||||
vo.setStations(stations);
|
||||
QueuesUtil.setOneKeyComputationMap(stationId,vo);
|
||||
result.put("msg","正在计算中!");
|
||||
result.put("progress",0);
|
||||
result.put("finish",0);
|
||||
OneKeyProgress progress = new OneKeyProgress();
|
||||
progress.setProgress(0.0);
|
||||
redisService.hset(QueuesUtil.PROGRESS_REDIS_KEY,vo.getStationId().toString(),progress);
|
||||
} else if( oneKeyProgress != null ){
|
||||
result.put("msg","正在计算中!");
|
||||
double progress = oneKeyProgress.getProgress()==null?1:oneKeyProgress.getProgress();
|
||||
String format = df.format(progress * 100);
|
||||
result.put("progress",format);
|
||||
result.put("finish",0);
|
||||
if ( format.equals("100.00") ) {
|
||||
result.put("finish",1);
|
||||
result.put("msg","计算完成!");
|
||||
redisService.hdel(QueuesUtil.PROGRESS_REDIS_KEY, stationId.toString());
|
||||
}
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
@TokenIgnore
|
||||
@PostMapping("/getOneKeyComputationProgress")
|
||||
@ApiOperation(value = "一键重算进度查询")
|
||||
public DataResult<Map<String,Object>> getOneKeyComputationProgress( @RequestBody OneKeyComputationVo vo) {
|
||||
Map<String,Object> result = new HashMap<String,Object>(0);
|
||||
result.put("msg","");
|
||||
result.put("progress","");
|
||||
result.put("finish","");
|
||||
// 重算执行标识,防止重复触发
|
||||
if( vo == null || vo.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
Integer stationId = vo.getStationId();
|
||||
// 判断队列里是否已经存在需要计算的数据,如果有则不继续计算,给页面扔出提示,阻止重复执行
|
||||
OneKeyProgress oneKeyProgress = (OneKeyProgress) redisService.hget(QueuesUtil.PROGRESS_REDIS_KEY, stationId.toString());
|
||||
if( oneKeyProgress != null ){
|
||||
result.put("msg","正在计算中!");
|
||||
double progress = oneKeyProgress.getProgress()==null?1:oneKeyProgress.getProgress();
|
||||
String format = df.format(progress * 100);
|
||||
result.put("progress",format);
|
||||
result.put("finish",0);
|
||||
if ( format.equals("100.00") ) {
|
||||
result.put("finish",1);
|
||||
result.put("msg","计算完成!");
|
||||
redisService.hdel(QueuesUtil.PROGRESS_REDIS_KEY, stationId.toString());
|
||||
// QueuesUtil.removeOneKeyProgress(stationId);
|
||||
}
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.entity.ElecPrice;
|
||||
import com.ho.business.service.ElecPriceService;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName ElecPriceController.java
|
||||
* @Description 电价管理
|
||||
* @createTime 2022年09月09日 11:09:00
|
||||
*/
|
||||
|
||||
@RequestMapping(ContextConstant.BUSINESS + "price")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "业务模块-电价管理")
|
||||
public class ElecPriceController {
|
||||
|
||||
@Autowired
|
||||
ElecPriceService elecPriceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
//查询所有
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "查询所有电价接口", hidden = true)
|
||||
public DataResult<List<ElecPrice>> selectAll() {
|
||||
DataResult<List<ElecPrice>> result = DataResult.success();
|
||||
List<ElecPrice> elecPrices = elecPriceService.selectAll();
|
||||
result.setData(elecPrices);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据用户查询所属集团电价
|
||||
@GetMapping("groupElecPrice")
|
||||
@ApiOperation(value = "集团最新电价列表")
|
||||
public DataResult<List<ElecPrice>> groupElecPrice(HttpServletRequest request) {
|
||||
|
||||
String token = request.getHeader(CommonConstant.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
Integer groupId = simpleUser.getGroupId();
|
||||
//电站id不传,只查集团电价
|
||||
List<ElecPrice> elecPrices = elecPriceService.selectLatestPrices(groupId, null, null, null);
|
||||
return DataResult.success(elecPrices);
|
||||
}
|
||||
|
||||
//根据电站id查询
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据电站id查询电价信息")
|
||||
// @LogAnnotation(title = "监控管理", action = "根据电站id查询电价信息")
|
||||
public DataResult<List<ElecPrice>> selectById(@PathVariable @Valid Integer id) {
|
||||
DataResult<List<ElecPrice>> result = DataResult.success();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.DATE);
|
||||
List<ElecPrice> elecPrices = null;
|
||||
String newTime = elecPriceService.selectStartTime(id);
|
||||
if (newTime != null) {
|
||||
DateTime parse = DateUtil.parse(newTime);
|
||||
DateTime beginOfDayTime = DateUtil.beginOfDay(parse);
|
||||
String beginTime = sdf.format(beginOfDayTime);
|
||||
//根据时间戳查询当天电价
|
||||
log.info("beginTime:" + beginTime);
|
||||
elecPrices = elecPriceService.selectByStationIdAndTime(id, beginTime);
|
||||
}
|
||||
result.setData(elecPrices);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,518 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.business.config.BizMergeStrategy;
|
||||
import com.ho.business.entity.*;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.business.service.EarningsCalculateService;
|
||||
import com.ho.business.service.ElecPriceCurveService;
|
||||
import com.ho.business.service.StationSnService;
|
||||
import com.ho.business.vo.EleRateFileVo;
|
||||
import com.ho.business.vo.req.elecPriceCurve.BatchDeleteReq;
|
||||
import com.ho.business.vo.req.elecPriceCurve.ElecPriceTemplateReq;
|
||||
import com.ho.business.vo.req.elecPriceCurve.ElecPriceTemplateReqVO;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.ElecPriceData;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.ElecPriceTemplate;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.ElecPriceTemplateExcel;
|
||||
import com.ho.business.vo.resp.elecPriceCurve.RowRangeDto;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.vo.req.SysSubDictVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 电价曲线模板设置
|
||||
* Author yule
|
||||
* Date 2023/4/19 14:28
|
||||
*/
|
||||
@RequestMapping(ContextConstant.BUSINESS + "elecPriceCurve")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "电价曲线模板设置")
|
||||
public class ElecPriceCurveController {
|
||||
|
||||
@Autowired
|
||||
ElecPriceCurveService elecPriceCurveService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
EarningsCalculateService earningsCalculateService;
|
||||
|
||||
@Autowired
|
||||
UserFeignClient userFeignClient;
|
||||
|
||||
public static final String DICT_TYPE = "electrovalence_type";
|
||||
|
||||
private static Map<String, String> staticMap = new HashMap<>(0);
|
||||
|
||||
// 费率类型静态字典
|
||||
private static final Map<String,String> issuesMap = new HashMap<String,String>(){{
|
||||
put("1","001803");
|
||||
put("2","001802");
|
||||
put("3","001801");
|
||||
put("4","001800");
|
||||
}};
|
||||
|
||||
// 生效月份列表
|
||||
public static final String MONTH ="25402";
|
||||
// 费率开始时间
|
||||
public static final String START_TIME ="25407";
|
||||
// 费率结束时间
|
||||
public static final String END_TIME ="25406";
|
||||
// 费率类型
|
||||
public static final String RATE_TYPE ="25405";
|
||||
|
||||
@Autowired
|
||||
StationSnService stationSnService;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
public static final String JSON_FILE_NAME = "fee_write.json";
|
||||
|
||||
public static final String FILE_PATH = "/deploy/fep/cfg";
|
||||
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增电价曲线模板")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "新增电价曲线模板")
|
||||
@TokenIgnore
|
||||
public DataResult add(@RequestBody @Valid ElecPriceTemplate elecPriceTemplate, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
elecPriceTemplate.setGroupId(user.getGroupId());
|
||||
elecPriceCurveService.add(elecPriceTemplate);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleted")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "删除电价曲线模板")
|
||||
@ApiOperation(value = "删除电价曲线模板")
|
||||
//@TokenIgnore
|
||||
@HzPermission(PermissionConstant.STRATEGY_ELECURVE_SINGLEDELETE)
|
||||
public DataResult deleted(@RequestBody ElecPriceTemplateReq elecPriceTemplateReq) {
|
||||
elecPriceCurveService.deleted(elecPriceTemplateReq);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("batchDelete")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "批量删除电价曲线模板")
|
||||
@ApiOperation(value = "批量删除电价曲线模板")
|
||||
//@TokenIgnore
|
||||
@HzPermission(PermissionConstant.strategy_eleCurve_delete)
|
||||
public DataResult batchDelete(@RequestBody BatchDeleteReq elecPriceTemplateReq){
|
||||
elecPriceCurveService.batchDelete(elecPriceTemplateReq);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "修改电价曲线模板")
|
||||
@ApiOperation(value = "修改电价曲线模板")
|
||||
@TokenIgnore
|
||||
public DataResult update(@RequestBody @Valid ElecPriceTemplate elecPriceTemplate) {
|
||||
elecPriceCurveService.update(elecPriceTemplate);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("one")
|
||||
@ApiOperation(value = "查询单个电价曲线模板")
|
||||
@HzPermission(PermissionConstant.STRATEGY_ELECURVE_EDIT)
|
||||
//@TokenIgnore
|
||||
public DataResult<ElecPriceTemplate> one(@RequestBody ElecPriceTemplateReq elecPriceTemplateReq) {
|
||||
ElecPriceTemplate elecPriceTemplate = elecPriceCurveService.getOne(elecPriceTemplateReq);
|
||||
return DataResult.success(elecPriceTemplate);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("all")
|
||||
@ApiOperation(value = "查询所有电价曲线模板")
|
||||
//@TokenIgnore
|
||||
public DataResult<List<ElecPriceData>> getAll(@RequestBody @Valid ElecPriceTemplateReqVO vo) {
|
||||
List<ElecPriceTemplate> list = elecPriceCurveService.getAll(vo);
|
||||
List<ElecPriceData> resultList = new ArrayList<>();
|
||||
for (ElecPriceTemplate elecTemplate : list) {
|
||||
if ( elecTemplate.getDiscount() != null ) {
|
||||
elecTemplate.setDiscount(elecTemplate.getDiscount()*100);
|
||||
}
|
||||
List<ElecTemplateSub> subList = elecTemplate.getList();
|
||||
if ( subList != null && subList.size() > 0 ) {
|
||||
for (ElecTemplateSub elecTemplateSub : subList) {
|
||||
ElecPriceData data = new ElecPriceData();
|
||||
BeanUtils.copyProperties(elecTemplate,data);
|
||||
data.setPrice(elecTemplateSub.getPrice());
|
||||
data.setBeginTime(elecTemplateSub.getBeginTime());
|
||||
data.setEndTime(elecTemplateSub.getEndTime());
|
||||
data.setType(elecTemplateSub.getType());
|
||||
resultList.add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(resultList);
|
||||
}
|
||||
|
||||
@PostMapping("exportTemplate")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "导出模板")
|
||||
@ApiOperation(value = "导出模板")
|
||||
@HzPermission(PermissionConstant.STRATEGY_ELECURVE_EXPORTTEMPLATE)
|
||||
public void exportTemplate(HttpServletResponse response) {
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
String fileName = URLEncoder.encode("elecPriceTemplate.xls", "utf-8");
|
||||
InputStream fis = getResourcesFileInputStream("template/elecPriceTemplate.xls");
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
response.setHeader("Content-disposition", "attachment;fileName=" + fileName);
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
out = response.getOutputStream();
|
||||
out.write(buffer);
|
||||
} catch (Exception ex) {
|
||||
log.error("下载失败,{}", ex.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
assert out != null;
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
log.error("下载模板失败,{}", e.getMessage());
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_DATA_IMPORT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("importExcel")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "导入电价曲线数据")
|
||||
@ApiOperation(value = "导入电价曲线数据")
|
||||
@HzPermission(PermissionConstant.STRATEGY_ELECURVE_IMPORT)
|
||||
@TokenIgnore
|
||||
public DataResult importExcel(@RequestBody MultipartFile file, @Param("stationId") Integer stationId, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String msg = "";
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
String name = "";
|
||||
String isEnable = "";
|
||||
String updateTime = "";
|
||||
Date validityStartTime = null;
|
||||
Date validityEndTime = null;
|
||||
Double discount = 1.0;
|
||||
inputStream = file.getInputStream();
|
||||
List<ElecPriceTemplateExcel> excelList = EasyExcel.read(inputStream).head(ElecPriceTemplateExcel.class).sheet().doReadSync();
|
||||
//给合并单元格的值进行填充
|
||||
for (ElecPriceTemplateExcel elecPriceTemplateExcel : excelList) {
|
||||
elecPriceTemplateExcel.setStationId(stationId);
|
||||
elecPriceTemplateExcel.setGroupId(user.getGroupId());
|
||||
if (elecPriceTemplateExcel.getTemplateName() != null) {
|
||||
name = elecPriceTemplateExcel.getTemplateName();
|
||||
} else {
|
||||
elecPriceTemplateExcel.setTemplateName(name);
|
||||
}
|
||||
if (elecPriceTemplateExcel.getIsEnable() != null) {
|
||||
isEnable = elecPriceTemplateExcel.getIsEnable();
|
||||
} else {
|
||||
elecPriceTemplateExcel.setIsEnable(isEnable);
|
||||
}
|
||||
if (elecPriceTemplateExcel.getUpdateTime() != null) {
|
||||
updateTime = elecPriceTemplateExcel.getUpdateTime();
|
||||
} else {
|
||||
elecPriceTemplateExcel.setUpdateTime(updateTime);
|
||||
}
|
||||
if( elecPriceTemplateExcel.getValidityStartTime() != null ){
|
||||
validityStartTime = elecPriceTemplateExcel.getValidityStartTime();
|
||||
} else {
|
||||
elecPriceTemplateExcel.setValidityStartTime(validityStartTime);
|
||||
}
|
||||
if (elecPriceTemplateExcel.getValidityEndTime()!= null){
|
||||
validityEndTime = elecPriceTemplateExcel.getValidityEndTime();
|
||||
} else {
|
||||
elecPriceTemplateExcel.setValidityEndTime(validityEndTime);
|
||||
}
|
||||
if( elecPriceTemplateExcel.getDiscount() != null ) {
|
||||
discount = elecPriceTemplateExcel.getDiscount();
|
||||
}else{
|
||||
elecPriceTemplateExcel.setDiscount(discount);
|
||||
}
|
||||
}
|
||||
elecPriceCurveService.importExcel(excelList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
//出现自定义异常,直接抛出
|
||||
if (e.getClass().equals(BusinessException.class)){
|
||||
throw new BusinessException(((BusinessException) e).getMessageCode(),e.getMessage());
|
||||
}
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return DataResult.success(msg);
|
||||
}
|
||||
|
||||
@PostMapping("exportExcel")
|
||||
@ApiOperation(value = "导出电价曲线数据")
|
||||
@LogAnnotation(title = "电价曲线模板设置", action = "导出电价曲线数据")
|
||||
@HzPermission(PermissionConstant.STRATEGY_ELECURVE_EXPORT)
|
||||
public void exportExcel(@RequestBody BatchDeleteReq batchDeleteReq ,HttpServletResponse response){
|
||||
List<Integer> ids = batchDeleteReq.getIds();
|
||||
if (ids == null || ids.isEmpty()){
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_SELECT_ELECTRICITY_PRICE_TEMPLATE_DATA);
|
||||
}
|
||||
List<ElecPriceTemplate> list = elecPriceCurveService.getListByIds(batchDeleteReq);
|
||||
List<ElecPriceTemplateExcel> excelList = new ArrayList<>();
|
||||
//转化为excel对象
|
||||
for (ElecPriceTemplate elecPriceTemplate : list) {
|
||||
List<ElecTemplateSub> elecPriceTemplateList = elecPriceTemplate.getList();
|
||||
for (ElecTemplateSub elecTemplateSub : elecPriceTemplateList) {
|
||||
//赋值
|
||||
ElecPriceTemplateExcel excel = new ElecPriceTemplateExcel();
|
||||
BeanUtils.copyProperties(elecTemplateSub,excel);
|
||||
excel.setPrice(elecTemplateSub.getPrice().toString());
|
||||
excel.setTemplateName(elecPriceTemplate.getTemplateName());
|
||||
excel.setUpdateTime(DateUtil.format(elecPriceTemplate.getUpdateTime(),CommonConstant.DATE));
|
||||
excel.setValidityStartTime(elecPriceTemplate.getValidityStartTime());
|
||||
excel.setValidityEndTime(elecPriceTemplate.getValidityEndTime());
|
||||
if ( elecPriceTemplate.getDiscount() != null ) {
|
||||
excel.setDiscount(elecPriceTemplate.getDiscount()*100);
|
||||
}
|
||||
if (CommonConstant.ONE.equals(elecPriceTemplate.getIsEnable())){
|
||||
excel.setIsEnable(CommonConstant.IS_ENABLE);
|
||||
}else {
|
||||
excel.setIsEnable(CommonConstant.NOT_IS_ENABlE);
|
||||
}
|
||||
excelList.add(excel);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<RowRangeDto>> strategyMap = BizMergeStrategy.addAnnualMerStrategy(excelList);
|
||||
try {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
||||
String filename = URLEncoder.encode("电价模板", "utf-8");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + filename + ".xlsx");
|
||||
|
||||
EasyExcel.write(response.getOutputStream(), ElecPriceTemplateExcel.class)
|
||||
.excelType(ExcelTypeEnum.XLSX).head(ElecPriceTemplateExcel.class)
|
||||
//.registerWriteHandler(new TitleSheetWriteHandler("我是一个小标题",2)) // 标题及样式,lastCol为标题第0列到底lastCol列的宽度
|
||||
//设置默认样式及写入头信息开始的行数
|
||||
.registerWriteHandler(new BizMergeStrategy(strategyMap)) // 注册合并策略
|
||||
// .registerWriteHandler(BizMergeStrategy.CellStyleStrategy()) // 设置样式
|
||||
.sheet("电价曲线")
|
||||
.doWrite(excelList);
|
||||
}catch (Exception e) {
|
||||
log.error("下载失败,{}", e.getMessage());
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_DATA_IMPORT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// 导出模板
|
||||
private static InputStream getResourcesFileInputStream(String fileName) {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("addSearch")
|
||||
@ApiOperation(value = "新增模板查询电价(查询国网参考电价)")
|
||||
@LogAnnotation(title = "新增模板查询电价", action = "新增模板查询电价")
|
||||
@TokenIgnore
|
||||
public DataResult<ElecPriceTemplate> addSearch(@RequestBody ElecTemplate elecTemplate) {
|
||||
ElecPriceTemplate elecPriceTemplate = null;
|
||||
if( elecTemplate != null && elecTemplate.getStationId() != null ){
|
||||
elecPriceTemplate = elecPriceCurveService.addSearch(elecTemplate.getStationId());
|
||||
}
|
||||
return DataResult.success(elecPriceTemplate);
|
||||
}
|
||||
|
||||
@PostMapping("sendEleRateFile")
|
||||
@ApiOperation(value = "下发电价曲线文件")
|
||||
@TokenIgnore
|
||||
public DataResult sendEleRateFile(@RequestBody EleRateFileVo vo){
|
||||
if( vo == null || vo.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
// 查询字典表,拿到类型与value对应关系
|
||||
if (staticMap.size() == 0) {
|
||||
SysSubDictVO sysSubDictVO = new SysSubDictVO();
|
||||
sysSubDictVO.setType(DICT_TYPE);
|
||||
staticMap = userFeignClient.getSysSubDict(sysSubDictVO);
|
||||
}
|
||||
// 查询到电价模板配置信息,组装成json
|
||||
String jsonStr = parseJson(vo);
|
||||
// 生成文件
|
||||
wirteFile(JSON_FILE_NAME,jsonStr);
|
||||
// 取得json文件
|
||||
File fileToCompress = new File(JSON_FILE_NAME);
|
||||
Map<String, Object> result = uploadFile(vo, fileToCompress);
|
||||
if( fileToCompress.exists() ){
|
||||
if (fileToCompress.delete()) {
|
||||
System.out.println("临时文件删除成功!");
|
||||
} else {
|
||||
System.out.println("临时文件删除失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("临时文件不存在!");
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装json
|
||||
* @param earningsCalculateSubs
|
||||
* @return
|
||||
*/
|
||||
private String parseJson(EleRateFileVo vo){
|
||||
JSONObject jsonStr = new JSONObject();
|
||||
JSONObject json = new JSONObject();
|
||||
String now = DateUtil.now();
|
||||
json.put("sdt",now);
|
||||
// 第二层
|
||||
JSONArray details = new JSONArray();
|
||||
JSONObject detail = null;
|
||||
// 最内层
|
||||
JSONArray timeDevisions = null;
|
||||
JSONObject timeDevision = null;
|
||||
List<String> yearMonth = getYearMonth();
|
||||
List<EarningsCalculateSub> baseData = new ArrayList<>(0);
|
||||
for (String month : yearMonth) {
|
||||
timeDevisions = new JSONArray();
|
||||
detail = new JSONObject();
|
||||
List<EarningsCalculateSub> earningsCalculateSubs = earningsCalculateService.queryElecTemplateSubByStationId(vo.getStationId(), null, month);
|
||||
if( earningsCalculateSubs != null && earningsCalculateSubs.size() > 0 ){
|
||||
baseData = earningsCalculateSubs;
|
||||
}
|
||||
for (EarningsCalculateSub earningsCalculateSub : baseData) {
|
||||
timeDevision = new JSONObject();
|
||||
String key = getKey(earningsCalculateSub.getType());
|
||||
timeDevision.put(RATE_TYPE,issuesMap.get(key));
|
||||
timeDevision.put(END_TIME,earningsCalculateSub.getEndTime());
|
||||
timeDevision.put(START_TIME,earningsCalculateSub.getBeginTime());
|
||||
timeDevisions.add(timeDevision);
|
||||
}
|
||||
detail.put(MONTH,month.substring(5,7));
|
||||
detail.put("timeDevisions",timeDevisions);
|
||||
details.add(detail);
|
||||
}
|
||||
JSONObject detailsStr = new JSONObject();
|
||||
detailsStr.put("details",details);
|
||||
// 实际数据的字段
|
||||
// json.put("con1",detailsStr);
|
||||
json.put("con",detailsStr.toString());
|
||||
json.put("uuid",UUID.randomUUID());
|
||||
json.put("det","254");
|
||||
json.put("dc","254000");
|
||||
jsonStr.put("ac","");
|
||||
jsonStr.put("bv","");
|
||||
jsonStr.put("cp","");
|
||||
jsonStr.put("dm","");
|
||||
jsonStr.put("dt","");
|
||||
jsonStr.put("ec","");
|
||||
jsonStr.put("mi","");
|
||||
jsonStr.put("pb","");
|
||||
jsonStr.put("pt",now);
|
||||
jsonStr.put("pv","");
|
||||
jsonStr.put("rt","");
|
||||
// jsonStr.put("bd1",json);
|
||||
jsonStr.put("bd",json.toString());
|
||||
System.err.println(jsonStr.toJSONString());
|
||||
return jsonStr.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据value获取key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private String getKey(String value){
|
||||
if( staticMap.size() == 0 ){
|
||||
return null;
|
||||
}
|
||||
return staticMap.entrySet().stream().collect(Collectors.toMap(entity-> entity.getValue(), entity-> entity.getKey())).get(value);
|
||||
}
|
||||
|
||||
private List<String> getYearMonth(){
|
||||
List<String> yearMonth = new ArrayList<>();
|
||||
int year = YearMonth.now().getYear();
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
YearMonth of = YearMonth.of(year, i);
|
||||
yearMonth.add(of+"-01");
|
||||
}
|
||||
return yearMonth;
|
||||
}
|
||||
|
||||
public static void wirteFile(String filePath,String json){
|
||||
try (FileWriter writer = new FileWriter(filePath, true)) {
|
||||
writer.write(json);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> uploadFile(EleRateFileVo eleRateFileVo, File file){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
Integer stationId = eleRateFileVo.getStationId();
|
||||
List<StationSn> snList = stationSnService.getSnListByStationId(stationId);
|
||||
String serialNo = "";
|
||||
for (StationSn stationSn : snList) {
|
||||
serialNo = stationSn.getSn();
|
||||
}
|
||||
try {
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
MockMultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "multipart/form-data", input);
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = fileCenterFeignClient.fileUploadForDevice(multipartFile, stationId, serialNo, FILE_PATH);
|
||||
HeartbeatResp data = heartbeatRespDataResult.getData();
|
||||
if( !data.getHeartbeatStatus().equals(CommonConstant.ONE) ){
|
||||
throw new BusinessException(BaseResponseCode.FILE_ISSUE_FAIL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
result.put("code", "500");
|
||||
result.put("msg", "下发JSON文件发生异常");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.ForwardColTemplateService;
|
||||
import com.ho.business.vo.req.ForwardColTemplateReq;
|
||||
import com.ho.business.vo.resp.ForwardColTemplateResp;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "forwardColTemplate")
|
||||
@Api(tags = "转发模板")
|
||||
@Slf4j
|
||||
public class ForwardColTemplateController {
|
||||
|
||||
@Autowired
|
||||
ForwardColTemplateService forwardColTemplateService;
|
||||
|
||||
/**
|
||||
* 编辑页面 新增接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addForwardColTemplate")
|
||||
@ApiOperation(value = "新增模板")
|
||||
public DataResult addForwardColTemplate(@RequestBody ForwardColTemplateReq template) {
|
||||
int i = forwardColTemplateService.addForwardColTemplate(template);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面 查看详情接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getForwardColTemplateDetail")
|
||||
@ApiOperation(value = "查看详情")
|
||||
public DataResult<List<ForwardColTemplateResp>> getForwardColTemplateDetail(@RequestBody ForwardColTemplateReq template) {
|
||||
if( template == null || template.getId() == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
List<ForwardColTemplateResp> forwardColTemplateDetail = forwardColTemplateService.getForwardColTemplateDetail(template);
|
||||
return DataResult.success(forwardColTemplateDetail);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑页面 编辑接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("modifyForwardColTemplate")
|
||||
@ApiOperation(value = "编辑模板")
|
||||
public DataResult modifyForwardColTemplate(@RequestBody ForwardColTemplateReq template) {
|
||||
forwardColTemplateService.modifyForwardColTemplate(template);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.HisCurveRelate;
|
||||
import com.ho.business.service.HisCurveRelateService;
|
||||
import com.ho.business.vo.req.modelType.ModelTypeQueryReq;
|
||||
import com.ho.business.vo.req.point.HisPointReqVo;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 曲线相关衍生功能
|
||||
* @DateTime: 2023/6/20 10:38
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "hisCurveRelate")
|
||||
@Api(tags = "业务模块-曲线相关衍生功能")
|
||||
public class HisCurveRelateController {
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
HisCurveRelateService hisCurveRelateService;
|
||||
|
||||
//新增(批量)HttpServletRequest request
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增历史曲线字典模板")
|
||||
@LogAnnotation(title = "业务模块-曲线相关衍生功能", action = "新增")
|
||||
//@TokenIgnore
|
||||
public DataResult add(@RequestBody @Valid HisPointReqVo hisPointReqVo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
hisCurveRelateService.add(hisPointReqVo, user);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//查询
|
||||
@PostMapping("pageSelectAll")
|
||||
@ApiOperation(value = "查询全部数据")
|
||||
public DataResult pageSelectAll(@RequestBody ModelTypeQueryReq vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
vo.setUserId(user.getUserId());
|
||||
PageResult<HisCurveRelate> list = hisCurveRelateService.pageSelectAll(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
//删除
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除")
|
||||
@LogAnnotation(title = "业务模块-曲线相关衍生功能", action = "删除")
|
||||
public DataResult deleteRateTemplate(@RequestBody HisCurveRelate hisCurveRelate)
|
||||
{
|
||||
return DataResult.success(hisCurveRelateService.delete(hisCurveRelate.getModelId()));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.HomeConfig;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.HomeConfigService;
|
||||
import com.ho.business.vo.req.HomeConfigAddReqVO;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2023/11/16 14:46
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "homeConfig")
|
||||
@Api(tags = "页面元素配置")
|
||||
public class HomeConfigController {
|
||||
|
||||
@Autowired
|
||||
private HomeConfigService homeConfigService;
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增页面元素配置接口")
|
||||
public DataResult add(@RequestBody @Valid HomeConfigAddReqVO vo) {
|
||||
DataResult<Station> result = new DataResult<>();
|
||||
homeConfigService.inserthomeConfig(vo);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/{stationId}")
|
||||
@ApiOperation(value = "根据电站id查询页面元素信息接口")
|
||||
public DataResult<List<HomeConfig>> selectByStationId(@PathVariable @Valid Integer stationId) {
|
||||
DataResult<List<HomeConfig>> result = DataResult.success();
|
||||
List<HomeConfig> HomeConfig = homeConfigService.selectByStationId(stationId);
|
||||
result.setData(HomeConfig);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,423 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.business.service.IargeScreenShowService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.req.cockpit.CockpitReqVO;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.iargeScreen.AnnualChartValue;
|
||||
import com.ho.business.vo.resp.iargeScreen.AnnualOverviewResp;
|
||||
import com.ho.business.vo.resp.iargeScreen.EnergySavingRespVo;
|
||||
import com.ho.business.vo.resp.iargeScreen.Subdata;
|
||||
import com.ho.common.tools.annotation.CommonLargeScreenToken;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.flow.vo.resp.event.EventDayNum;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.vo.req.QueryDeptReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 大屏展示
|
||||
* @DateTime: 2023/12/13 10:37
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "IargeScreenShow")
|
||||
@Api(tags = "新大屏")
|
||||
public class IargeScreenShowController {
|
||||
@Autowired
|
||||
IargeScreenShowService iargeScreenShowService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
UserFeignClient userFeignClient;
|
||||
|
||||
@Value("${largeScreen.weatherCode}")
|
||||
String adCode;
|
||||
|
||||
private final static Integer maxSize = 30;
|
||||
|
||||
|
||||
@PostMapping("overviewData")
|
||||
@ApiOperation(value = "储能年度概览//年度收益概览接口返回")
|
||||
@TokenIgnore
|
||||
public DataResult<AnnualOverviewResp> getOverviewData(HttpServletRequest request) {
|
||||
AnnualOverviewResp annualOverviewResp = iargeScreenShowService.getOverviewData();
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualOverviewResp);
|
||||
bigDecimalUtil.ifIsNUll(annualOverviewResp);
|
||||
return DataResult.success(annualOverviewResp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("efficiencyDate")
|
||||
@ApiOperation(value = "系统转换率")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getEfficiencyDate() {
|
||||
List<Subdata> efficiencyList = iargeScreenShowService.getEfficiencyDate();
|
||||
return DataResult.success(efficiencyList);
|
||||
}
|
||||
|
||||
// 电站收益率排名
|
||||
@PostMapping("incomeDate")
|
||||
@ApiOperation(value = "电站收益排名")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getIncomeList() {
|
||||
List<Subdata> regionList = new ArrayList<>();
|
||||
regionList = iargeScreenShowService.getProfit(null, null);
|
||||
if (regionList.size() > maxSize) {
|
||||
regionList = regionList.subList(0, maxSize);
|
||||
}
|
||||
for (Subdata subdata : regionList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(subdata);
|
||||
bigDecimalUtil.ifIsNUll(subdata);
|
||||
}
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
|
||||
// 节能减排
|
||||
@PostMapping("getEnergySaving")
|
||||
@ApiOperation(value = "节能减排")
|
||||
@TokenIgnore
|
||||
public DataResult<EnergySavingRespVo> getEnergySaving() {
|
||||
EnergySavingRespVo energySaving = iargeScreenShowService.getEnergySaving();
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(energySaving);
|
||||
bigDecimalUtil.ifIsNUll(energySaving);
|
||||
return DataResult.success(energySaving);
|
||||
}
|
||||
|
||||
|
||||
// 电站区域分布
|
||||
@PostMapping("regionalDistribution")
|
||||
@ApiOperation(value = "电站区域分布")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> regionalDistribution() {
|
||||
List<Subdata> regionList = iargeScreenShowService.getRegionList();
|
||||
regionList.sort(Comparator.comparing((Subdata::getRegionValue)).reversed());
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
// 电站区域分布
|
||||
@PostMapping("getCapacity")
|
||||
@ApiOperation(value = "装机容量倒排")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getCapacity() {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCapacity();
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
//获取电站信息
|
||||
@PostMapping("stationInfo")
|
||||
@ApiOperation(value = "获取电站信息")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Station>> getStationInfo() {
|
||||
List<Station> stations = iargeScreenShowService.getStationInfo();
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
|
||||
// 日充日放对比
|
||||
@PostMapping("getIncomeCurve")
|
||||
@ApiOperation(value = "收益曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<List<AnnualChartValue>> getIncomeCurve(@RequestBody CockpitReqVO vo, HttpServletRequest request) {
|
||||
// List<AnnualChartValue> list = iargeScreenShowService.getIncomeCurve(vo);
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getProfitCurve(vo);
|
||||
for (AnnualChartValue annualChartValue : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualChartValue);
|
||||
bigDecimalUtil.ifIsNUll(annualChartValue);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
// 日充日放对比
|
||||
@PostMapping("chargeDailyChart")
|
||||
@ApiOperation(value = "日充日放对比图")
|
||||
@TokenIgnore
|
||||
public DataResult<List<AnnualChartValue>> getChargeDailyChart(HttpServletRequest request) {
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getChargeDailyChart();
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/newWeather")
|
||||
@ApiOperation(value = "新大屏天气接口")
|
||||
@TokenIgnore
|
||||
public DataResult<WeatherRespVo> newWeather() {
|
||||
String key = RedisKeyConstant.WEATHER_PROVINCE_CITY + adCode;
|
||||
WeatherRespVo info = (WeatherRespVo) redisService.get(key);
|
||||
return DataResult.success(info);
|
||||
}
|
||||
|
||||
|
||||
/**************************以下为通用大屏接口********************************/
|
||||
|
||||
@PostMapping("getCommonOverviewData")
|
||||
@ApiOperation(value = "通用储能年度概览//年度收益概览接口返回")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<AnnualOverviewResp> getCommonOverviewData(HttpServletRequest request) {
|
||||
AnnualOverviewResp annualOverviewResp = iargeScreenShowService.getOverviewData(getSimpleUser(request));
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualOverviewResp);
|
||||
bigDecimalUtil.ifIsNUll(annualOverviewResp);
|
||||
return DataResult.success(annualOverviewResp);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonRegionalDistribution")
|
||||
@ApiOperation(value = "通用电站区域分布")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<Subdata>> getCommonRegionalDistribution(HttpServletRequest request) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonRegionList(getSimpleUser(request));
|
||||
regionList.sort(Comparator.comparing((Subdata::getRegionValue)).reversed());
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonEnergySaving")
|
||||
@ApiOperation(value = "通用节能减排")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<EnergySavingRespVo> getEnergySaving(HttpServletRequest request) {
|
||||
EnergySavingRespVo energySaving = iargeScreenShowService.getEnergySaving(getSimpleUser(request));
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(energySaving);
|
||||
bigDecimalUtil.ifIsNUll(energySaving);
|
||||
return DataResult.success(energySaving);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonIncomeCurve")
|
||||
@ApiOperation(value = "通用收益曲线")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<AnnualChartValue>> getCommonIncomeCurve(@RequestBody CockpitReqVO vo, HttpServletRequest request) {
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getCommonProfitCurve(vo, getSimpleUser(request));
|
||||
for (AnnualChartValue annualChartValue : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualChartValue);
|
||||
bigDecimalUtil.ifIsNUll(annualChartValue);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonChargeDailyChart")
|
||||
@ApiOperation(value = "通用日充日放对比图")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<AnnualChartValue>> getCommonChargeDailyChart(HttpServletRequest request) {
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getCommonChargeDailyChart(getSimpleUser(request));
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
// 电站收益率排名
|
||||
@PostMapping("getCommonIncomeList")
|
||||
@ApiOperation(value = "通用电站收益排名")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<Subdata>> getCommonIncomeList(HttpServletRequest request) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonProfit(null, null, getSimpleUser(request));
|
||||
if (regionList.size() > maxSize) {
|
||||
regionList = regionList.subList(0, maxSize);
|
||||
}
|
||||
for (Subdata subdata : regionList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(subdata);
|
||||
bigDecimalUtil.ifIsNUll(subdata);
|
||||
}
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonEfficiencyDate")
|
||||
@ApiOperation(value = "通用系统转换率")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<Subdata>> getCommonEfficiencyDate(HttpServletRequest request) {
|
||||
List<Subdata> efficiencyList = iargeScreenShowService.getCommonEfficiencyDate(getSimpleUser(request));
|
||||
return DataResult.success(efficiencyList);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonStationInfo")
|
||||
@ApiOperation(value = "通用获取电站信息")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<Station>> getCommonStationInfo(HttpServletRequest request) {
|
||||
List<Integer> ids = getSimpleUser(request);
|
||||
List<Station> stations = new ArrayList<>();
|
||||
if (ids != null) {
|
||||
stations = iargeScreenShowService.getCountStations(ids);
|
||||
}
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonCapacity")
|
||||
@ApiOperation(value = "通用装机容量倒排")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<Subdata>> getCommonCapacity(HttpServletRequest request) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonCapacity(getSimpleUser(request));
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
@PostMapping("getCommonEventCount")
|
||||
@ApiOperation(value = "通用获取告警数目曲线")
|
||||
@TokenIgnore
|
||||
@CommonLargeScreenToken
|
||||
public DataResult<List<EventDayNum>> getCommonEventCount(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByCommonToken(token);
|
||||
List<EventDayNum> commonEventCount = iargeScreenShowService.getCommonEventCount(user);
|
||||
return DataResult.success(commonEventCount);
|
||||
}
|
||||
|
||||
private List<Integer> getSimpleUser(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByCommonToken(token);
|
||||
List<Integer> stationIds = user.getStationIds();
|
||||
return stationIds;
|
||||
}
|
||||
/************************************************************************/
|
||||
|
||||
/**************************以下为中自大屏接口********************************/
|
||||
private List<Integer> getByDeptId(Integer deptId) {
|
||||
List<SysDept> sysDeptList = userFeignClient.getSysDeptByDeptId(deptId);
|
||||
List<Integer> idList = sysDeptList.stream().map(SysDept::getId).collect(Collectors.toList());
|
||||
List<Station> stationList = stationService.selectByDeptIds(idList);
|
||||
List<Integer> stationIds = stationList.stream().map(Station::getId).collect(Collectors.toList());
|
||||
return stationIds;
|
||||
}
|
||||
|
||||
@PostMapping("getByStationId")
|
||||
@ApiOperation(value = "中自根据电站Id查询所属组织机构返回")
|
||||
@TokenIgnore
|
||||
public DataResult<Station> getByStationId(@RequestBody CockpitReqVO vo) {
|
||||
Station station = new Station();
|
||||
if (null == vo.getStationId()) {
|
||||
station.setDeptId(296);
|
||||
} else {
|
||||
station = stationService.selectById(vo.getStationId());
|
||||
}
|
||||
return DataResult.success(station);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiOverviewData")
|
||||
@ApiOperation(value = "中自储能年度概览//年度收益概览接口返回")
|
||||
@TokenIgnore
|
||||
public DataResult<AnnualOverviewResp> getZhongZiOverviewData(@RequestBody CockpitReqVO vo) {
|
||||
AnnualOverviewResp annualOverviewResp = iargeScreenShowService.getOverviewData(getByDeptId(vo.getDeptId()));
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualOverviewResp);
|
||||
bigDecimalUtil.ifIsNUll(annualOverviewResp);
|
||||
return DataResult.success(annualOverviewResp);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiDistribution")
|
||||
@ApiOperation(value = "中自电站区域分布")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getZhongZiDistribution(@RequestBody CockpitReqVO vo) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonRegionList((getByDeptId(vo.getDeptId())));
|
||||
regionList.sort(Comparator.comparing((Subdata::getRegionValue)).reversed());
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiEnergySaving")
|
||||
@ApiOperation(value = "中自节能减排")
|
||||
@TokenIgnore
|
||||
public DataResult<EnergySavingRespVo> getZhongZiEnergySaving(@RequestBody CockpitReqVO vo) {
|
||||
EnergySavingRespVo energySaving = iargeScreenShowService.getEnergySaving(getByDeptId(vo.getDeptId()));
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(energySaving);
|
||||
bigDecimalUtil.ifIsNUll(energySaving);
|
||||
return DataResult.success(energySaving);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiIncomeCurve")
|
||||
@ApiOperation(value = "通用收益曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<List<AnnualChartValue>> getZhongZiIncomeCurve(@RequestBody CockpitReqVO vo) {
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getCommonProfitCurve(vo, getByDeptId(vo.getDeptId()));
|
||||
for (AnnualChartValue annualChartValue : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(annualChartValue);
|
||||
bigDecimalUtil.ifIsNUll(annualChartValue);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiChargeDailyChart")
|
||||
@ApiOperation(value = "中自日充日放对比图")
|
||||
@TokenIgnore
|
||||
public DataResult<List<AnnualChartValue>> getZhongZiChargeDailyChart(@RequestBody CockpitReqVO vo) {
|
||||
List<AnnualChartValue> list = iargeScreenShowService.getCommonChargeDailyChart(getByDeptId(vo.getDeptId()));
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
// 电站收益率排名
|
||||
@PostMapping("getZhongZiIncomeList")
|
||||
@ApiOperation(value = "中自电站收益排名")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getZhongZiIncomeList(@RequestBody CockpitReqVO vo) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonProfit(null, null, getByDeptId(vo.getDeptId()));
|
||||
if (regionList.size() > maxSize) {
|
||||
regionList = regionList.subList(0, maxSize);
|
||||
}
|
||||
for (Subdata subdata : regionList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(subdata);
|
||||
bigDecimalUtil.ifIsNUll(subdata);
|
||||
}
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiEfficiencyDate")
|
||||
@ApiOperation(value = "中自系统转换率")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getZhongZiEfficiencyDate(@RequestBody CockpitReqVO vo) {
|
||||
List<Subdata> efficiencyList = iargeScreenShowService.getCommonEfficiencyDate(getByDeptId(vo.getDeptId()));
|
||||
return DataResult.success(efficiencyList);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiStationInfo")
|
||||
@ApiOperation(value = "获取中自电站信息")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Station>> getZhongZiStationInfo(@RequestBody CockpitReqVO vo) {
|
||||
List<Integer> ids = getByDeptId(vo.getDeptId());
|
||||
List<Station> stations = new ArrayList<>();
|
||||
if (ids != null) {
|
||||
stations = iargeScreenShowService.getCountStations(ids);
|
||||
}
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
|
||||
@PostMapping("getZhongZiCapacity")
|
||||
@ApiOperation(value = "中自装机容量倒排")
|
||||
@TokenIgnore
|
||||
public DataResult<List<Subdata>> getZhongZiCapacity(@RequestBody CockpitReqVO vo) {
|
||||
List<Subdata> regionList = iargeScreenShowService.getCommonCapacity(getByDeptId(vo.getDeptId()));
|
||||
return DataResult.success(regionList);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.entity.IncomeTemplateType;
|
||||
import com.ho.business.entity.RateTemplate;
|
||||
import com.ho.business.service.IncomeMappingService;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "incomeMapping")
|
||||
@Api(tags = "费率配置")
|
||||
public class IncomeMappingController {
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
|
||||
@Autowired
|
||||
private IncomeMappingService incomeMappingService;
|
||||
|
||||
@PostMapping("selectRateTemplates")
|
||||
@ApiOperation(value = "查询费率模板")
|
||||
public DataResult<List<RateTemplate>> selectRateTemplates(@RequestBody RateTemplate rateTemplate)
|
||||
{
|
||||
return DataResult.success(incomeMappingService.selectRateTemplates(rateTemplate));
|
||||
}
|
||||
|
||||
@PostMapping("insertRateTemplate")
|
||||
@ApiOperation(value = "新增费率模板")
|
||||
@LogAnnotation(title = "费率配置", action = "新增费率模板")
|
||||
public DataResult insertRateTemplate(@RequestBody RateTemplate rateTemplate,HttpServletRequest request)
|
||||
{
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMappingService.insertRateTemplate(rateTemplate,simpleUser));
|
||||
}
|
||||
|
||||
@PostMapping("modifyRateTemplate")
|
||||
@ApiOperation(value = "修改费率模板")
|
||||
@LogAnnotation(title = "费率配置", action = "修改费率模板")
|
||||
public DataResult modifyRateTemplate(@RequestBody RateTemplate rateTemplate,HttpServletRequest request)
|
||||
{
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMappingService.modifyRateTemplate(rateTemplate,simpleUser));
|
||||
}
|
||||
|
||||
@PostMapping("deleteRateTemplate")
|
||||
@ApiOperation(value = "删除费率模板")
|
||||
@LogAnnotation(title = "费率配置", action = "删除费率模板")
|
||||
public DataResult deleteRateTemplate(@RequestBody RateTemplate rateTemplate)
|
||||
{
|
||||
return DataResult.success(incomeMappingService.deleteRateTemplate(rateTemplate.getId()));
|
||||
}
|
||||
|
||||
@PostMapping("getIncomeTemplateTypes")
|
||||
@ApiOperation(value = "获取所有模板类型")
|
||||
public DataResult<List<IncomeTemplateType>> getIncomeTemplateTypes()
|
||||
{
|
||||
return DataResult.success(incomeMappingService.getIncomeTemplateTypes());
|
||||
}
|
||||
|
||||
@PostMapping("changeSwitch")
|
||||
@ApiOperation(value = "修改模板启用状态")
|
||||
@LogAnnotation(title = "费率配置", action = "修改模板启用状态")
|
||||
public DataResult<List<IncomeTemplateType>> changeSwitch(@RequestBody RateTemplate rateTemplate)
|
||||
{
|
||||
return DataResult.success(incomeMappingService.changeSwitch(rateTemplate));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,233 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.entity.IncomeQRate;
|
||||
import com.ho.business.entity.IncomeRate;
|
||||
import com.ho.business.entity.IncomeRateMapping;
|
||||
import com.ho.business.entity.IncomeTotal;
|
||||
import com.ho.business.service.IncomeMeasurementService;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "income")
|
||||
@Api(tags = "收益预测")
|
||||
@Slf4j
|
||||
public class IncomeMeasurementController {
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@PostMapping("exportTemplate")
|
||||
@ApiOperation(value = "导出模板")
|
||||
@LogAnnotation(title = "收益预测", action = "导出模板")
|
||||
public void exportTemplate(HttpServletResponse response){
|
||||
ServletOutputStream out =null;
|
||||
try {
|
||||
String fileName = URLEncoder.encode("template.xls", "utf-8");
|
||||
InputStream fis = getResourcesFileInputStream("template/template.xls");
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
response.setHeader("Content-disposition", "attachment;fileName=" + fileName);
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
out = response.getOutputStream();
|
||||
out.write(buffer);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("下载失败");
|
||||
}finally {
|
||||
try {
|
||||
assert out != null;
|
||||
out.flush();
|
||||
out.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private IncomeMeasurementService incomeMeasurementService;
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
// 查询费率模板
|
||||
|
||||
@PostMapping("getRateTemplateList")
|
||||
@ApiOperation(value = "查询费率模板")
|
||||
public DataResult getRateTemplateList( @RequestBody IncomeRate incomeRate)
|
||||
{
|
||||
return DataResult.success(incomeMeasurementService.getRateTemplateList(incomeRate.getStationId()));
|
||||
}
|
||||
// 根据模板查询费率
|
||||
|
||||
@PostMapping("getRateList")
|
||||
@ApiOperation(value = "根据费率模板查询费率")
|
||||
public DataResult getRateList( @RequestBody IncomeRate incomeRate)
|
||||
{
|
||||
return DataResult.success(incomeMeasurementService.getRateList(incomeRate.getTemplateId()));
|
||||
}
|
||||
// 查询费率详情
|
||||
|
||||
@PostMapping("getRateDetails")
|
||||
@ApiOperation(value = "查询费率详情")
|
||||
public DataResult getRateDetails(@RequestBody IncomeRate incomeRate)
|
||||
{
|
||||
return DataResult.success(incomeMeasurementService.getRateDetails(incomeRate.getRateId(),incomeRate.getTemplateId()));
|
||||
}
|
||||
//查询收益测算-企业用电-费率设置表数据
|
||||
|
||||
@PostMapping("selectIncomeRates")
|
||||
@ApiOperation(value = "企业用电费率查询")
|
||||
public DataResult<List<IncomeRate>> selectIncomeRates(@RequestBody IncomeRate incomeRate){
|
||||
return DataResult.success(incomeMeasurementService.selectIncomeRates(incomeRate));
|
||||
}
|
||||
// 查询上网用电数据
|
||||
|
||||
@PostMapping("selectQRate")
|
||||
@ApiOperation(value = "查询上网用电数据")
|
||||
public DataResult<List<IncomeQRate>> selectQRate(@RequestBody IncomeQRate surfQRate){
|
||||
return DataResult.success(incomeMeasurementService.selectQRate(surfQRate));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("insertOrUpdateIncomeRates")
|
||||
@ApiOperation(value = "增删改费率")
|
||||
@LogAnnotation(title = "费率模版", action = "增删改费率")
|
||||
public DataResult insertOrUpdateIncomeRates(@RequestBody List<IncomeRate> incomeRates,HttpServletRequest request){
|
||||
//下一个月才能新增上网用电数据上一个月的收益
|
||||
String dataDate = incomeRates.get(0).getDataDate();
|
||||
DateTime end = DateUtil.parse(dataDate, CommonConstant.DATE_YM);
|
||||
Date now = new Date();
|
||||
if ( DateUtil.isIn(end, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now))){
|
||||
throw new BusinessException(BaseResponseCode.INCOME_ADD_AT_THE_END_OF_THE_MONTH);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMeasurementService.insertOrUpdateIncomeRates(incomeRates,simpleUser));
|
||||
}
|
||||
// 新增上网用电数据
|
||||
|
||||
@PostMapping("insertSurfQRate")
|
||||
@ApiOperation(value = "新增上网用电数据")
|
||||
@LogAnnotation(title = "费率模版", action = "新增上网用电数据")
|
||||
public DataResult insertSurfQRate(@RequestBody IncomeQRate surfQRate,HttpServletRequest request){
|
||||
//下一个月才能新增上网用电数据上一个月的收益
|
||||
String dataDate = surfQRate.getDataDate();
|
||||
DateTime end = DateUtil.parse(dataDate, CommonConstant.DATE_YM);
|
||||
Date now = new Date();
|
||||
if ( DateUtil.isIn(end, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now))){
|
||||
throw new BusinessException(BaseResponseCode.INCOME_ADD_AT_THE_END_OF_THE_MONTH);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMeasurementService.insertSurfQRate(surfQRate,simpleUser));
|
||||
}
|
||||
// 修改上网用电数据
|
||||
@PostMapping("modifySurfRate")
|
||||
@ApiOperation(value = "修改上网用电数据")
|
||||
@LogAnnotation(title = "费率模版", action = "修改上网用电数据")
|
||||
public DataResult modifySurfRate(@RequestBody IncomeQRate surfQRate,HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMeasurementService.modifySurfRate(surfQRate,simpleUser.getUserId()));
|
||||
}
|
||||
// 确认按钮
|
||||
|
||||
@PostMapping("confirm")
|
||||
@ApiOperation(value = "确认按钮")
|
||||
@LogAnnotation(title = "费率模版", action = "确认")
|
||||
public DataResult confirm(@RequestBody IncomeTotal incomeTotal){
|
||||
//下一个月才能新增上网用电数据上一个月的收益
|
||||
String dataDate = incomeTotal.getDataDate();
|
||||
DateTime end = DateUtil.parse(dataDate, CommonConstant.DATE_YM);
|
||||
Date now = new Date();
|
||||
if ( DateUtil.isIn(end, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now))){
|
||||
throw new BusinessException(BaseResponseCode.INCOME_CONFIRMATION_AT_THE_END_OF_THE_MONTH);
|
||||
}
|
||||
return DataResult.success(incomeMeasurementService.confirm(incomeTotal));
|
||||
}
|
||||
// 导出模板
|
||||
private static InputStream getResourcesFileInputStream(String fileName) {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
|
||||
}
|
||||
|
||||
// 导入excel
|
||||
@PostMapping("uploadExcel")
|
||||
@ApiOperation(value = "导入excel")
|
||||
@LogAnnotation(title = "收益预测", action = "导入excel")
|
||||
public DataResult uploadExcel(@RequestBody List<IncomeRate> incomeRates,HttpServletRequest request){
|
||||
//下一个月才能新增上网用电数据上一个月的收益
|
||||
//下一个月才能新增上网用电数据上一个月的收益
|
||||
String dataDate = incomeRates.get(0).getDataDate();
|
||||
DateTime end = DateUtil.parse(dataDate, CommonConstant.DATE_YM);
|
||||
Date now = new Date();
|
||||
if ( DateUtil.isIn(end, DateUtil.beginOfMonth(now), DateUtil.endOfMonth(now))){
|
||||
throw new BusinessException(BaseResponseCode.INCOME_ADD_AT_THE_END_OF_THE_MONTH);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = busiTool.getSimpleUser(token);
|
||||
return DataResult.success(incomeMeasurementService.excelInput(incomeRates,simpleUser));
|
||||
}
|
||||
|
||||
@PostMapping("selectRates")
|
||||
@ApiOperation(value = "查询费率号(下拉框数据)")
|
||||
public DataResult<List<IncomeRateMapping>> selectRates(){
|
||||
return DataResult.success(incomeMeasurementService.selectRates());
|
||||
}
|
||||
|
||||
@PostMapping("selectTotal")
|
||||
@ApiOperation(value = "查询累计收益")
|
||||
public DataResult<IncomeTotal> selectTotal(@RequestBody IncomeTotal incomeTotal){
|
||||
IncomeTotal result = incomeMeasurementService.selectTotal(incomeTotal);
|
||||
if (result != null) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(result);
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("selectIncomeDetails")
|
||||
@ApiOperation(value = "查询企业用电详情")
|
||||
public DataResult<IncomeTotal> selectIncomeDetails(@RequestBody IncomeRate incomeRate) {
|
||||
return DataResult.success(incomeMeasurementService.selectIncomeDetails(incomeRate));
|
||||
}
|
||||
|
||||
@PostMapping("jobDataManage")
|
||||
@TokenIgnore
|
||||
public DataResult jobDataManage(){
|
||||
log.info("15分钟 收益计算开始");
|
||||
|
||||
incomeMeasurementService.jobDataManage();
|
||||
//15分钟收益计算结束
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
|
||||
|
||||
import com.ho.business.entity.IndustrialElecPrice;
|
||||
import com.ho.business.service.IndustrialElecPriceService;
|
||||
import com.ho.business.vo.req.industrialElec.IndustrialElecPriceReqVo;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RequestMapping(ContextConstant.BUSINESS + "industrialElecPrice")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "业务模块-工商业代理电价")
|
||||
public class IndustrialElecPriceController {
|
||||
|
||||
@Autowired
|
||||
private IndustrialElecPriceService industrialElecPriceService;
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "查询所有代理电价-分页")
|
||||
public DataResult<PageResult<IndustrialElecPrice>> page(@RequestBody IndustrialElecPriceReqVo reqVo) {
|
||||
return industrialElecPriceService.getElecPriceList(reqVo);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增代理电价")
|
||||
@HzPermission(PermissionConstant.BUSINESS_INDUSTRIALPRICE_ADD)
|
||||
public DataResult add(@RequestBody @Valid IndustrialElecPrice industrialElecPrice) {
|
||||
industrialElecPrice.setCreateTime(new Date());
|
||||
industrialElecPriceService.add(industrialElecPrice);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/deleteById")
|
||||
@ApiOperation(value = "删除代理电价")
|
||||
@HzPermission(PermissionConstant.BUSINESS_INDUSTRIALPRICE_DEL)
|
||||
public DataResult deleteById(@RequestBody IndustrialElecPriceReqVo industrialElecPriceReqVo) {
|
||||
industrialElecPriceService.deleteById(industrialElecPriceReqVo.getId());
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/findById/{id}")
|
||||
@ApiOperation(value = "根据id显示详情")
|
||||
public DataResult findById(@PathVariable("id")Long id) {
|
||||
IndustrialElecPrice industrialElecPrice = industrialElecPriceService.findById(id);
|
||||
return DataResult.success(industrialElecPrice);
|
||||
}
|
||||
|
||||
@PostMapping("/updateById")
|
||||
@ApiOperation(value = "根据id更新")
|
||||
@HzPermission(PermissionConstant.BUSINESS_INDUSTRIALPRICE_EDIT)
|
||||
public DataResult updateById(@RequestBody @Valid IndustrialElecPrice industrialElecPrice) {
|
||||
industrialElecPrice.setUpdateTime(new Date());
|
||||
industrialElecPriceService.updateById(industrialElecPrice);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/getTouLineById/{id}")
|
||||
@ApiOperation(value = "根据id查询分时电价折线图")
|
||||
public DataResult getTouLineById(@PathVariable("id")Long id) {
|
||||
List<Map<String,Object>> lineData = industrialElecPriceService.getTouLineById(id);
|
||||
return DataResult.success(lineData);
|
||||
}
|
||||
|
||||
@GetMapping("/getTouLineHistoryById/{id}")
|
||||
@ApiOperation(value = "根据id查询分时电价历史数据图表/表格")
|
||||
public DataResult getTouLineHistoryById(@PathVariable("id")Long id) {
|
||||
Map<String,Object> lineData = industrialElecPriceService.getTouLineHistoryById(id);
|
||||
return DataResult.success(lineData);
|
||||
}
|
||||
|
||||
@GetMapping("/getMaxPriceDiffById/{id}")
|
||||
@ApiOperation(value = "根据id查询峰谷电差价折线图/表格")
|
||||
public DataResult getMaxPriceDiffById(@PathVariable("id")Long id) {
|
||||
Map<String,Object> lineData = industrialElecPriceService.getMaxPriceDiffById(id);
|
||||
return DataResult.success(lineData);
|
||||
}
|
||||
|
||||
@PostMapping("/collectPrice")
|
||||
@ApiOperation(value = "通过图片识别采集数据")
|
||||
@HzPermission(PermissionConstant.BUSINESS_INDUSTRIALPRICE_COLLECT)
|
||||
public DataResult collectPrice(@RequestPart("file") MultipartFile file, @RequestParam("regionId") Integer regionId, @RequestParam("executionTime") String executionTime) {
|
||||
DataResult dataResult = industrialElecPriceService.collectPrice(file,regionId,executionTime);
|
||||
return dataResult;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.entity.IndustrialElecRegion;
|
||||
import com.ho.business.mapper.IndustrialElecRegionMapper;
|
||||
import com.ho.business.service.IndustrialElecRegionService;
|
||||
import com.ho.business.vo.req.industrialElec.IndustrialElecRegionReqVo;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequestMapping(ContextConstant.BUSINESS + "industrialElecRegion")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "业务模块-代理电价区域")
|
||||
public class IndustrialElecRegionController {
|
||||
|
||||
@Autowired
|
||||
private IndustrialElecRegionMapper industrialElecRegionMapper;
|
||||
|
||||
@Autowired
|
||||
private IndustrialElecRegionService industrialElecRegionService;
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "查询所有代理电价区域-分页")
|
||||
public DataResult<PageResult<IndustrialElecRegion>> page(@RequestBody IndustrialElecRegionReqVo reqVo) {
|
||||
PageHelper.startPage(reqVo.getPageNum(), reqVo.getPageSize());
|
||||
List<IndustrialElecRegion> industrialElecPrices = industrialElecRegionMapper.selectIndustElecRegion(reqVo);
|
||||
return DataResult.success(PageUtils.getPageResult(new PageInfo<>(industrialElecPrices)));
|
||||
}
|
||||
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "查询所有代理电价区域-列表")
|
||||
public DataResult<IndustrialElecRegion> list() {
|
||||
List<IndustrialElecRegion> industrialElecPrices = industrialElecRegionMapper.findAllList();
|
||||
return DataResult.success(industrialElecPrices);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增代理电价区域")
|
||||
public DataResult add(@RequestBody @Valid IndustrialElecRegion industrialElecRegion) {
|
||||
if(industrialElecRegion!=null){
|
||||
IndustrialElecRegion industrial= industrialElecRegionMapper.findByRegionName(industrialElecRegion.getRegionName());
|
||||
if(industrial==null){
|
||||
industrialElecRegion.setCreateTime(new Date());
|
||||
industrialElecRegionMapper.insert(industrialElecRegion);
|
||||
}else{
|
||||
return DataResult.getResult(BaseResponseCode.REGION_NAME_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/deleteById")
|
||||
@ApiOperation(value = "删除代理电价区域")
|
||||
public DataResult deleteById(@RequestBody IndustrialElecRegion industrialElecRegion) {
|
||||
industrialElecRegionMapper.deleteById(industrialElecRegion.getId());
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/findById/{id}")
|
||||
@ApiOperation(value = "根据id显示详情")
|
||||
public DataResult findById(@PathVariable("id")Integer id) {
|
||||
IndustrialElecRegion industrialElecRegion = industrialElecRegionMapper.findById(id);
|
||||
return DataResult.success(industrialElecRegion);
|
||||
}
|
||||
|
||||
@PostMapping("/updateById")
|
||||
@ApiOperation(value = "根据id更新")
|
||||
public DataResult updateById(@RequestBody @Valid IndustrialElecRegion industrialElecRegion) {
|
||||
industrialElecRegion.setUpdateTime(new Date());
|
||||
industrialElecRegionMapper.updateById(industrialElecRegion);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/addressResolution")
|
||||
@ApiOperation(value = "详细地址识别")
|
||||
public DataResult addressResolution(@RequestParam("address") String address) {
|
||||
DataResult dataResult = industrialElecRegionService.addressResolution(address);
|
||||
return dataResult;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.service.InverterService;
|
||||
import com.ho.business.vo.InverterCurveReqVo;
|
||||
import com.ho.business.vo.req.MonitorQuery;
|
||||
import com.ho.business.vo.req.DeviceAttrbuteReqVO;
|
||||
import com.ho.business.vo.resp.InverterResp.*;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 逆变器
|
||||
* @DateTime: 2023/1/6 9:15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "inverter")
|
||||
@Api(tags = "逆变器模块")
|
||||
public class InverterController {
|
||||
|
||||
@Autowired
|
||||
InverterService inverterService;
|
||||
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
|
||||
@GetMapping("/list/{stationId}")
|
||||
@ApiOperation(value = "根据电站Id查询逆变器")
|
||||
public DataResult<List<InverterTopologyRespVO>> selectByStationId(@PathVariable("stationId") Integer stationId) {
|
||||
List<InverterTopologyRespVO> list = inverterService.selectByStationId(stationId);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("pvData")
|
||||
@ApiOperation(value = "获取PV值")
|
||||
public DataResult<List<InverterPvValueRespVO>> getPvDate(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<InverterPvValueRespVO> list = inverterService.getPvDate(monitorQuery);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (InverterPvValueRespVO inverterPvValueRespVO : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(inverterPvValueRespVO);
|
||||
bigDecimalUtil.ifIsNUll(inverterPvValueRespVO);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("panelData")
|
||||
@ApiOperation(value = "获取面板数据")
|
||||
public DataResult<InverterPanelData> panelData(@RequestBody MonitorQuery monitorQuery) {
|
||||
InverterPanelData inverterPanelData = inverterService.getPanelData(monitorQuery);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(inverterPanelData);
|
||||
bigDecimalUtil.ifIsNUll(inverterPanelData);
|
||||
return DataResult.success(inverterPanelData);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("curve")
|
||||
@ApiOperation(value = "获取电流/电压/有功功率曲线")
|
||||
public DataResult<List<InverterCurveRespVo>> getPvDate(@RequestBody InverterCurveReqVo vo) {
|
||||
List<InverterCurveRespVo> list = inverterService.getCurve(vo);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (InverterCurveRespVo curveRespVo : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(curveRespVo);
|
||||
bigDecimalUtil.ifIsNUll(curveRespVo);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("attribute")
|
||||
@ApiOperation(value = "获取设备属性")
|
||||
public DataResult<PageResult<DeviceAttributeRespVO>> getAttribute(@RequestBody DeviceAttrbuteReqVO vo) {
|
||||
List<DeviceAttributeRespVO> respVOS = inverterService.getAttr(vo);
|
||||
//对数据进行分页处理
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!respVOS.isEmpty()) {
|
||||
List list = PageUtils.dealList(respVOS, vo.getPageNum(), vo.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(respVOS.size());
|
||||
pageResult.setTotalPages(respVOS.size() / vo.getPageSize() + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.CockpitService;
|
||||
import com.ho.business.service.LargeScreenService;
|
||||
import com.ho.business.vo.resp.cockpit.ConditionMonitoringRespVO;
|
||||
import com.ho.business.vo.resp.cockpit.RevenueRespVO;
|
||||
import com.ho.business.vo.resp.largescreen.GroupDataResp;
|
||||
import com.ho.business.vo.resp.largescreen.MainDateResp;
|
||||
import com.ho.business.vo.resp.largescreen.MonthlyStatisticResp;
|
||||
import com.ho.common.tools.annotation.LargeScreenToken;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 大屏展示 智慧管控平台的大屏
|
||||
* Author yule
|
||||
* Date 2023/3/21 10:52
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "largeScreen")
|
||||
@Api(tags = "大屏展示")
|
||||
@Slf4j
|
||||
public class LargeScreenController {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
CockpitService cockpitService;
|
||||
|
||||
@Autowired
|
||||
LargeScreenService largeScreenService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
|
||||
@PostMapping("groupData")
|
||||
@ApiOperation(value = "集团数据")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<GroupDataResp> getGroupData(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
GroupDataResp groupDataResp = largeScreenService.getGroupData(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(groupDataResp);
|
||||
bigDecimalUtil.ifIsNUll(groupDataResp);
|
||||
return DataResult.success(groupDataResp);
|
||||
}
|
||||
|
||||
@PostMapping("/conditionMonitoring")
|
||||
@ApiOperation(value = "站点监测")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<ConditionMonitoringRespVO> conditionMonitoring(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
ConditionMonitoringRespVO respVO = largeScreenService.getConditionMonitoring(user);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("monthlyStatistics")
|
||||
@ApiOperation(value = "当年月累计充放电量统计")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<MonthlyStatisticResp>> getMonthlyStatistics(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<MonthlyStatisticResp> statisticResps = largeScreenService.getMonthlyStatistics(user);
|
||||
for (MonthlyStatisticResp statisticResp : statisticResps) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(statisticResp);
|
||||
bigDecimalUtil.ifIsNUll(statisticResp);
|
||||
}
|
||||
return DataResult.success(statisticResps);
|
||||
}
|
||||
|
||||
@PostMapping("mainData")
|
||||
@ApiOperation(value = "主要数据展示")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<MainDateResp> getMainDate(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
MainDateResp resp = largeScreenService.getMainDate(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(resp);
|
||||
bigDecimalUtil.ifIsNUll(resp);
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("yearIncomeRevenue")
|
||||
@ApiOperation(value = "站年收益排行")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<RevenueRespVO>> getYearIncomeRevenue(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<RevenueRespVO> list = largeScreenService.getYearIncomeRevenue(user);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.MessageInfoService;
|
||||
import com.ho.business.entity.MessageInfoVo;
|
||||
import com.ho.business.vo.req.MessageInfoReqVo;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "messageInfo")
|
||||
@Api(tags = "站内广播消息")
|
||||
@Slf4j
|
||||
public class MessageController {
|
||||
|
||||
@Autowired
|
||||
MessageInfoService messageInfoService;
|
||||
|
||||
|
||||
@PostMapping("/modifyMessageInfo")
|
||||
@ApiOperation(value = "新增广播消息")
|
||||
public DataResult<MessageInfoVo> modifyMessageInfo(@RequestBody MessageInfoReqVo messageInfo){
|
||||
DataResult result = new DataResult();
|
||||
MessageInfoVo newMessageInfo = messageInfoService.modifyMessageInfo(messageInfo);
|
||||
result.setData(newMessageInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/deleteMessage")
|
||||
@ApiOperation(value = "删除广播消息")
|
||||
public DataResult deleteMessage(@RequestBody List<String> messageIds){
|
||||
DataResult result = new DataResult();
|
||||
messageInfoService.deleteMessage(messageIds);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/selectMessageInfo")
|
||||
@ApiOperation(value = "查询广播消息")
|
||||
public DataResult<MessageInfoReqVo> selectMessageInfo(@RequestBody Map<String,Object> condition){
|
||||
DataResult result = new DataResult();
|
||||
List<MessageInfoReqVo> message = messageInfoService.selectMessageInfo(condition);
|
||||
result.setData(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/updateMessageReadStatus")
|
||||
@ApiOperation(value = "更新阅读状态")
|
||||
public DataResult updateMessageReadStatus(@RequestBody Map<String,Object> condition){
|
||||
DataResult result = new DataResult();
|
||||
messageInfoService.updateMessageReadStatus(condition);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/jobUpdateMessageInfo")
|
||||
@TokenIgnore
|
||||
@ApiOperation(value = "定时任务刷新消息数据")
|
||||
public DataResult jobUpdateMessageInfo(){
|
||||
messageInfoService.jobUpdateMessageInfo();
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.DeviceTypeConfig;
|
||||
import com.ho.business.entity.ModelDevice;
|
||||
import com.ho.business.entity.ModelDeviceCol;
|
||||
import com.ho.business.entity.ModelType;
|
||||
import com.ho.business.service.DeviceTypeConfigService;
|
||||
import com.ho.business.service.ModelDeviceColService;
|
||||
import com.ho.business.vo.req.device.DeviceTypeQuery;
|
||||
import com.ho.business.vo.req.deviceModel.*;
|
||||
import com.ho.business.vo.resp.deviceModel.DeviceModelRespVo;
|
||||
import com.ho.business.vo.resp.deviceModel.ModelDeviceColRespVo;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 模型设备字段关联表
|
||||
* @DateTime: 2023/3/7 16:44
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "ModelAndDevice")
|
||||
@Api(tags = "业务模块-设备_模型设备字段关联管理")
|
||||
public class ModelDeviceColController {
|
||||
@Autowired
|
||||
ModelDeviceColService modelDeviceColService;
|
||||
|
||||
@Autowired
|
||||
DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增设备模型关联字段接口")
|
||||
@LogAnnotation(title = "设备模型关联管理", action = "新增设备模型关联字段信息")
|
||||
@HzPermission(PermissionConstant.SYS_EMSDEVICE_ASSOCIATED)
|
||||
public DataResult<ModelDeviceCol> add(@RequestBody @Valid ModelDeviceColAddVo vo) {
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_MODEL_EQUIPMENT_ASSOCIATION);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
modelDeviceColService.add(vo);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "修改设备模型关联字段接口")
|
||||
@LogAnnotation(title = "设备模型关联管理", action = "修改设备模型关联字段信息")
|
||||
public DataResult<ModelDeviceCol> update(@RequestBody @Valid ModelDeviceColAddVo vo) {
|
||||
//modelDeviceColService.update(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteBatch")
|
||||
@ApiOperation(value = "批量删除设备模型关联字段")
|
||||
@LogAnnotation(title = "设备模型关联管理", action = "批量删除设备模型关联字段")
|
||||
@HzPermission(PermissionConstant.SYS_MODELDEVICE_DELETE)
|
||||
public DataResult deleteBatch(@RequestBody @Valid DeviceModelDeleteReqVo vo) {
|
||||
modelDeviceColService.deleteBatch(vo);
|
||||
return DataResult.success();
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperation(value = "分页查询设备模型关联字段接口")
|
||||
//deviceType
|
||||
public DataResult<PageResult<ModelDeviceColRespVo>> page(@RequestBody DeviceColSelectReqVo vo) {
|
||||
List<ModelDeviceColRespVo> modelDeviceColList = modelDeviceColService.page(vo);
|
||||
/*//java内存分页
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!modelDeviceColList.isEmpty()) {
|
||||
List list = PageUtils.dealList(modelDeviceColList, vo.getPageNum(), vo.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(modelDeviceColList.size());
|
||||
pageResult.setTotalPages(modelDeviceColList.size() / vo.getPageSize() + 1);
|
||||
}else{
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}*/
|
||||
return DataResult.success(modelDeviceColList);
|
||||
}
|
||||
|
||||
@PostMapping("/selectDevice")
|
||||
@ApiOperation(value = "查询未被使用的设备字段")
|
||||
public DataResult<List<DeviceModelRespVo>> selectDevice(@RequestBody DeviceColSelectReqVo vo) {
|
||||
List<DeviceModelRespVo> modelDeviceColList = modelDeviceColService.selectDevice(vo);
|
||||
return DataResult.success(modelDeviceColList);
|
||||
}
|
||||
|
||||
@PostMapping("/selectModel")
|
||||
@ApiOperation(value = "查询当前设备未被使用的模型字段")
|
||||
//deviceType
|
||||
public DataResult<List<DeviceModelRespVo>> selectModel(@RequestBody ModelDeviceColAddReqVo vo) {
|
||||
List<DeviceModelRespVo> modelDeviceColList = modelDeviceColService.selectModel(vo.getDeviceType(), vo.getModelType());
|
||||
return DataResult.success(modelDeviceColList);
|
||||
}
|
||||
|
||||
//查询modelType类型
|
||||
@PostMapping("/getModelType")
|
||||
@ApiOperation(value = "查询模型类型")
|
||||
//deviceType
|
||||
public DataResult<List<ModelType>> getModelType() {
|
||||
List<ModelType> modelTypeList = modelDeviceColService.getModelType();
|
||||
return DataResult.success(modelTypeList);
|
||||
}
|
||||
|
||||
//查询deviceType类型
|
||||
@PostMapping("/getDeviceType")
|
||||
@ApiOperation(value = "查询设备类型")
|
||||
//deviceType
|
||||
public DataResult<List<ModelDevice>> getDeviceType(@RequestBody DeviceColSelectReqVo vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
List<ModelDevice> modelTypeList = modelDeviceColService.getDeviceType(vo.getType());
|
||||
List<String> deviceTypes = modelTypeList.stream().map(ModelDevice::getDeviceType)
|
||||
.collect(Collectors.toList());
|
||||
if(deviceTypes==null ||deviceTypes.isEmpty()){
|
||||
return DataResult.success(new ArrayList<>());
|
||||
}
|
||||
//改为从设备类型配置表中查询
|
||||
DeviceTypeQuery deviceTypeQuery = new DeviceTypeQuery();
|
||||
deviceTypeQuery.setGroupId(user.getGroupId());
|
||||
deviceTypeQuery.setDeviceTypeList(deviceTypes);
|
||||
List<DeviceTypeConfig> deviceTypeConfigs = deviceTypeConfigService.queryListByCondition(deviceTypeQuery);
|
||||
for (ModelDevice modelDevice : modelTypeList) {
|
||||
for (DeviceTypeConfig deviceType : deviceTypeConfigs) {
|
||||
if(modelDevice.getDeviceType().equals(deviceType.getDeviceType())){
|
||||
modelDevice.setDeviceTypeName(deviceType.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(modelTypeList);
|
||||
}
|
||||
|
||||
|
||||
//一键同步功能
|
||||
@PostMapping("/getSynchronousM")
|
||||
@ApiOperation(value = "一键同步设备关联模型功能")
|
||||
@LogAnnotation(title = "设备模型关联管理", action = "一键同步设备关联模型功能")
|
||||
//deviceType
|
||||
public DataResult getSynchronousM(@RequestBody SynchronousReqVo vo) {
|
||||
modelDeviceColService.synchronousAdd(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/getSynchronousMNew")
|
||||
@ApiOperation(value = "一键同步设备关联模型功能(不区分设备)")
|
||||
@LogAnnotation(title = "设备模型关联管理", action = "一键同步设备关联模型功能(不区分设备)")
|
||||
//deviceType
|
||||
public DataResult getSynchronousMNew(@RequestBody SynchronousReqVo vo) {
|
||||
if (vo.getStationId() == null) {
|
||||
//请选择同步的设备类型
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_SRC_STATION);
|
||||
}
|
||||
if (vo.getModelStationId() == null) {
|
||||
//请选择同步的模型类型
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_MODEL_STATION);
|
||||
}
|
||||
modelDeviceColService.synchronousAddNew(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.DeviceTypeConfig;
|
||||
import com.ho.business.entity.ModelDevice;
|
||||
import com.ho.business.entity.ModelType;
|
||||
import com.ho.business.service.ModelTypeService;
|
||||
import com.ho.business.vo.req.modelDevice.ModelDeviceAddReq;
|
||||
import com.ho.business.vo.req.modelDevice.ModelDeviceDeleteReq;
|
||||
import com.ho.business.vo.req.modelType.ModelTypeAddReq;
|
||||
import com.ho.business.vo.req.modelType.ModelTypeQueryReq;
|
||||
import com.ho.business.vo.resp.modelType.ModelTypeResp;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xwz
|
||||
* @desc: 模型配置
|
||||
* @DateTime: 2023/4/20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "modelType")
|
||||
@Api(tags = "模型配置")
|
||||
public class ModelTypeController {
|
||||
|
||||
@Autowired
|
||||
ModelTypeService modelTypeService;
|
||||
|
||||
//用于左边列表展示
|
||||
@PostMapping("pageModelType")
|
||||
@ApiOperation(value = "查询模型配置")
|
||||
public DataResult pageModelType(@RequestBody ModelTypeQueryReq vo){
|
||||
PageResult<ModelTypeResp> modelTypeRespPageResult = modelTypeService.selectPage(vo);
|
||||
return DataResult.success(modelTypeRespPageResult);
|
||||
}
|
||||
|
||||
@PostMapping("addModelType")
|
||||
@ApiOperation(value = "新增模型配置")
|
||||
@LogAnnotation(title = "模型配置", action = "新增模型配置")
|
||||
public DataResult addModelType(@RequestBody ModelTypeAddReq vo){
|
||||
ModelType modelType = new ModelType();
|
||||
modelType.setId(vo.getId());
|
||||
modelType.setModelType(vo.getModelType());
|
||||
modelType.setModelName(vo.getModelName());
|
||||
modelTypeService.insetModelType(modelType);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//根据model_type 查询 device_type 所对应的device_type_config 表中的name
|
||||
@PostMapping("selectDeviceType")
|
||||
@ApiOperation(value = "根据model_type查询device_type列表")
|
||||
public DataResult<List<ModelTypeAddReq>> selectDeviceType(@RequestBody ModelTypeAddReq vo){
|
||||
//返回数据包括:model_type device_type name
|
||||
List<ModelTypeAddReq> list= modelTypeService.selectDeviceType(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("updateModelType")
|
||||
@ApiOperation(value = "更新模型配置")
|
||||
public DataResult updateModelType(){
|
||||
return null;
|
||||
}
|
||||
|
||||
//右边新增时 需要传入电站Id modelType 查询 devicetypeconfig的表中所对应的name
|
||||
@PostMapping("selectList")
|
||||
@ApiOperation(value = "查询该电站下的数据类型")
|
||||
public DataResult<List<DeviceTypeConfig>> selectList(@RequestBody ModelTypeAddReq vo){
|
||||
//返回数据包括:model_type device_type name
|
||||
List<DeviceTypeConfig> list= modelTypeService.selectList(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("addModelDevice")
|
||||
@ApiOperation(value = "新增模型设备类型")
|
||||
@LogAnnotation(title = "模型配置", action = "新增模型设备类型")
|
||||
public DataResult addModelDevice(@RequestBody ModelDeviceAddReq vo){
|
||||
//先判断是否有相同value的值
|
||||
ModelDevice modelValue = modelTypeService.selectByDict(vo.getDeviceType(), vo.getModelType());
|
||||
if (modelValue != null) {
|
||||
throw new BusinessException(BaseResponseCode.DICT_ALREADY_EXISTS);
|
||||
}
|
||||
ModelDevice modelDevice = new ModelDevice();
|
||||
modelDevice.setModelType(vo.getModelType());
|
||||
modelDevice.setDeviceType(vo.getDeviceType());
|
||||
modelTypeService.insetModelDevice(modelDevice);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("updateModelDevice")
|
||||
@ApiOperation(value = "更新模型设备类型")
|
||||
@LogAnnotation(title = "模型配置", action = "更新模型设备类型")
|
||||
public DataResult updateModelDevice(@RequestBody ModelDeviceAddReq vo){
|
||||
ModelDevice modelDevice = new ModelDevice();
|
||||
modelDevice.setModelType(vo.getModelType());
|
||||
modelDevice.setDeviceType(vo.getDeviceType());
|
||||
modelDevice.setId(vo.getId());
|
||||
modelTypeService.updateModelDevice(modelDevice);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteModelDevice")
|
||||
@ApiOperation(value = "删除模型设备类型")
|
||||
@LogAnnotation(title = "模型配置", action = "删除模型设备类型")
|
||||
public DataResult deleteModelDevice(@RequestBody ModelDeviceDeleteReq vo){
|
||||
modelTypeService.deleteModelDevice(vo.getIds());
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.OneClickSequentialControl;
|
||||
import com.ho.business.service.OneClickSequentialControlService;
|
||||
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlAddReq;
|
||||
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlDeleteReq;
|
||||
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlQueryReq;
|
||||
import com.ho.business.vo.resp.colCount.ColCountResp;
|
||||
import com.ho.business.vo.resp.oneClickSequentialControl.OneClickSequentialControlResp;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = ContextConstant.BUSINESS + "oneClickSequentialControl")
|
||||
@Api(tags = "一键顺控")
|
||||
public class OneClickSequentialControlController {
|
||||
|
||||
@Autowired
|
||||
OneClickSequentialControlService controlService;
|
||||
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "查询一键顺控配置值")
|
||||
public DataResult<List<OneClickSequentialControl>> list(@RequestBody OneClickSequentialControlQueryReq vo) {
|
||||
List<OneClickSequentialControl> list = controlService.getListByParam(vo,"1");
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("groupList")
|
||||
@ApiOperation(value = "查询一键顺控配置值(策略总览页面使用)")
|
||||
public DataResult<List<OneClickSequentialControlResp>> groupList(@RequestBody OneClickSequentialControlQueryReq vo) {
|
||||
List<OneClickSequentialControlResp> groupList = controlService.getGroupList(vo);
|
||||
return DataResult.success(groupList);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增一键顺控配置值")
|
||||
@LogAnnotation(title = "一键顺控配置值", action = "新增一键顺控配置值")
|
||||
public DataResult add(@RequestBody @Valid OneClickSequentialControlAddReq vo) {
|
||||
controlService.addBatch(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "更新一键顺控配置值")
|
||||
@LogAnnotation(title = "一键顺控配置值", action = "更新一键顺控配置值")
|
||||
public DataResult<ColCountResp> update(@RequestBody @Valid OneClickSequentialControlAddReq vo) {
|
||||
controlService.updateBatch(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除一键顺控配置值")
|
||||
@LogAnnotation(title = "一键顺控配置值", action = "删除一键顺控配置值")
|
||||
public DataResult<ColCountResp> delete(@RequestBody OneClickSequentialControlDeleteReq vo) {
|
||||
controlService.deleteByIds(vo.getIds());
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,622 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.*;
|
||||
import com.ho.business.vo.DeviceTransfer;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.req.dynamicConfig.DynamicConfigQuery;
|
||||
import com.ho.business.vo.req.pcsStation.PcsStationReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.cabin.CircleCtrlResp;
|
||||
import com.ho.business.vo.resp.cabin.EarningsCalculateCountResp;
|
||||
import com.ho.business.vo.resp.openStationHome.OpenStationMiddle;
|
||||
import com.ho.business.vo.resp.openStationHome.OpenStationMiddleOrig;
|
||||
import com.ho.business.vo.resp.openStationHome.StatusMonitorVo;
|
||||
import com.ho.business.vo.resp.pcsStation.HomePageStationDataResp;
|
||||
import com.ho.business.vo.resp.pcsStation.PcsElecData;
|
||||
import com.ho.business.vo.resp.pcsStation.PcsStationData;
|
||||
import com.ho.business.vo.resp.pcsStation.PcsTotalData;
|
||||
import com.ho.business.vo.resp.point.WareHouse;
|
||||
import com.ho.business.vo.resp.station.ActiveReactivePower;
|
||||
import com.ho.business.vo.resp.station.NewRealTimeCurveVo;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.vo.req.StationHomeRespVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: OPEN环境的站首页
|
||||
* @date 2023/4/17
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "openStation")
|
||||
@Api(tags = "一体柜站首页")
|
||||
@Slf4j
|
||||
@Data
|
||||
public class OpenStationController {
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
StationHomeService stationHomeService;
|
||||
|
||||
@Autowired
|
||||
StatusMonitorService statusMonitorService;
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
OpenStationService openStationService;
|
||||
|
||||
@Autowired
|
||||
CommonService commonService;
|
||||
|
||||
@Autowired
|
||||
ColCountService colCountService;
|
||||
|
||||
@Autowired
|
||||
EarningsCalculateService earningsCalculateService;
|
||||
|
||||
@PostMapping("statusMonitor")
|
||||
@ApiOperation(value = "状态监控")
|
||||
public DataResult<StatusMonitorVo> statusMonitor(@RequestBody StationReq stationReq) {
|
||||
StatusMonitorVo statusMonitor = statusMonitorService.getStatusMonitor(stationReq.getStationId());
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(statusMonitor);
|
||||
bigDecimalUtil.ifIsNUll(statusMonitor);
|
||||
return DataResult.success(statusMonitor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/realtimeCurve")
|
||||
@ApiOperation(value = "实时曲线")
|
||||
//@Cacheable(cacheManager = "towMinuteCacheManager", value = "stationRealtimeCurve", key = "#stationReq.stationId", sync = true)
|
||||
public DataResult<List<NewRealTimeCurveVo>> realtimeCurve(@RequestBody StationReq stationReq) {
|
||||
log.info("realtimeCurve.stationRealtimeCurve:" + stationReq);
|
||||
List<NewRealTimeCurveVo> resList = stationHomeService.getRealtimeCurve(stationReq);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (NewRealTimeCurveVo newRealTimeCurveVo : resList) {
|
||||
List<StationHomeRespVo> list = newRealTimeCurveVo.getList();
|
||||
if (list != null && !CommonConstant.ZERO.equals(list.size())) {
|
||||
for (StationHomeRespVo stationHomeRespVo : list) {
|
||||
|
||||
BigDecimal digit = stationHomeRespVo.getDigital();
|
||||
if (digit != null) {
|
||||
String result = String.format("%.3f", digit);
|
||||
stationHomeRespVo.setDigital(new BigDecimal(result));
|
||||
;
|
||||
}
|
||||
if (newRealTimeCurveVo.getDeviceName() == null) {
|
||||
newRealTimeCurveVo.setDeviceName("");
|
||||
}
|
||||
//bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
|
||||
//bigDecimalUtil.ifIsNUll(stationHomeRespVo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@PostMapping("/strategyCurve")
|
||||
@ApiOperation(value = "策略总览曲线")
|
||||
public DataResult<List<NewRealTimeCurveVo>> strategyCurve(@RequestBody StationReq stationReq) {
|
||||
log.info("strategyCurve.stationRealtimeCurve:" + stationReq);
|
||||
List<NewRealTimeCurveVo> resList = stationHomeService.getStrategyCurve(stationReq);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (NewRealTimeCurveVo newRealTimeCurveVo : resList) {
|
||||
List<StationHomeRespVo> list = newRealTimeCurveVo.getList();
|
||||
if (list != null && !CommonConstant.ZERO.equals(list.size())) {
|
||||
for (StationHomeRespVo stationHomeRespVo : list) {
|
||||
BigDecimal digit = stationHomeRespVo.getDigital();
|
||||
if (digit != null) {
|
||||
String result = String.format("%.3f", digit);
|
||||
stationHomeRespVo.setDigital(new BigDecimal(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@PostMapping("/dynamicRealtimeCurve")
|
||||
@ApiOperation(value = "动态配置-实时曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<List<NewRealTimeCurveVo>> dynamicRealtimeCurve(@RequestBody DynamicConfigQuery vo) {
|
||||
//默认隐藏曲线不显示
|
||||
vo.setIsHide(CommonConstant.ZERO);
|
||||
List<NewRealTimeCurveVo> resList = stationHomeService.getDynamicRealtimeCurve(vo);
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (NewRealTimeCurveVo newRealTimeCurveVo : resList) {
|
||||
List<StationHomeRespVo> list = newRealTimeCurveVo.getList();
|
||||
if (list != null && !CommonConstant.ZERO.equals(list.size())) {
|
||||
for (StationHomeRespVo stationHomeRespVo : list) {
|
||||
BigDecimal digit = stationHomeRespVo.getDigital();
|
||||
if (digit != null) {
|
||||
String result = String.format("%.3f", digit);
|
||||
stationHomeRespVo.setDigital(new BigDecimal(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
@PostMapping("/pcsStationData")
|
||||
@ApiOperation(value = "电站信息")
|
||||
public DataResult<PcsStationData> getPcsStationData(@RequestBody StationReq req) {
|
||||
PcsStationData data = stationHomeService.getPcsStationData(req.getStationId());
|
||||
return DataResult.success(data);
|
||||
}
|
||||
|
||||
@PostMapping("/pcsTotalData")
|
||||
@ApiOperation(value = "数据总览")
|
||||
public DataResult<PcsTotalData> pcsTotalData(@RequestBody StationReq req) {
|
||||
if (req.getDeviceType() == null) {
|
||||
String deviceType = colCountService.getDeviceType(req.getStationId());
|
||||
req.setDeviceType(deviceType);
|
||||
}
|
||||
PcsTotalData data = stationHomeService.getPcsTotalData(req);
|
||||
BigDecimal systemEfficiency = data.getSystemEfficiency();
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(data);
|
||||
bigDecimalUtil.ifIsNUll(data);
|
||||
//保持精度
|
||||
data.setSystemEfficiency(systemEfficiency);
|
||||
return DataResult.success(data);
|
||||
}
|
||||
|
||||
@PostMapping("/getEleTotalData")
|
||||
@ApiOperation(value = "数据总览(取电表计算)")
|
||||
public DataResult<PcsTotalData> getEleTotalData(@RequestBody StationReq req) {
|
||||
req.setDeviceType(DeviceTypeConstant.ELE_METER);
|
||||
PcsTotalData data = stationHomeService.getPcsTotalData(req);
|
||||
BigDecimal systemEfficiency = data.getSystemEfficiency();
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(data);
|
||||
bigDecimalUtil.ifIsNUll(data);
|
||||
//保持精度
|
||||
data.setSystemEfficiency(systemEfficiency);
|
||||
return DataResult.success(data);
|
||||
}
|
||||
|
||||
@PostMapping("/getPcsTotalData")
|
||||
@ApiOperation(value = "数据总览(取PCS计算)")
|
||||
@TokenIgnore
|
||||
public DataResult<PcsTotalData> getPcsTotalData(@RequestBody StationReq req) {
|
||||
if (req.getDeviceType() == null) {
|
||||
String deviceType = colCountService.getDeviceType(req.getStationId());
|
||||
if (null == deviceType) {
|
||||
deviceType = DeviceTypeConstant.PCS;
|
||||
}
|
||||
req.setDeviceType(deviceType);
|
||||
}
|
||||
PcsTotalData data = stationHomeService.getPcsTotalData(req);
|
||||
BigDecimal systemEfficiency = data.getSystemEfficiency();
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(data);
|
||||
bigDecimalUtil.ifIsNUll(data);
|
||||
//保持精度
|
||||
data.setSystemEfficiency(systemEfficiency);
|
||||
return DataResult.success(data);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/elecData")
|
||||
@ApiOperation(value = "充放电量")
|
||||
public DataResult<List<PcsElecData>> elecData(@RequestBody PcsStationReq req) throws ParseException {
|
||||
if (req.getDeviceType() == null) {
|
||||
String deviceType = colCountService.getDeviceType(req.getStationId());
|
||||
req.setDeviceType(deviceType);
|
||||
}
|
||||
List<PcsElecData> list = stationHomeService.getPcsElecData(req);
|
||||
for (PcsElecData pcsElecData : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pcsElecData);
|
||||
bigDecimalUtil.ifIsNUll(pcsElecData);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/getElecData")
|
||||
@ApiOperation(value = "充放电量(使用电表计算)")
|
||||
public DataResult<List<PcsElecData>> getElecData(@RequestBody PcsStationReq req) throws ParseException {
|
||||
req.setDeviceType(DeviceTypeConstant.ELE_METER);
|
||||
List<PcsElecData> list = stationHomeService.getPcsElecData(req);
|
||||
for (PcsElecData pcsElecData : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pcsElecData);
|
||||
bigDecimalUtil.ifIsNUll(pcsElecData);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/getPCSElecData")
|
||||
@ApiOperation(value = "充放电量(使用PCS计算)")
|
||||
@TokenIgnore
|
||||
public DataResult<List<PcsElecData>> getPCSElecData(@RequestBody PcsStationReq req) throws ParseException {
|
||||
if (req.getDeviceType() == null) {
|
||||
String deviceType = colCountService.getDeviceType(req.getStationId());
|
||||
if (null == deviceType) {
|
||||
deviceType = DeviceTypeConstant.PCS;
|
||||
}
|
||||
req.setDeviceType(deviceType);
|
||||
}
|
||||
List<PcsElecData> list = stationHomeService.getPcsElecData(req);
|
||||
//获取光伏充电
|
||||
List<PcsElecData> pvList = stationHomeService.getPvChargeElec(req);
|
||||
Map<String, List<PcsElecData>> dataMap = pvList.stream().collect(Collectors.groupingBy(PcsElecData::getDate));
|
||||
|
||||
|
||||
for (PcsElecData pcsElecData : list) {
|
||||
if (dataMap.containsKey(pcsElecData.getDate())) {
|
||||
List<PcsElecData> pcsElecData1 = dataMap.get(pcsElecData.getDate());
|
||||
if (pcsElecData1.get(CommonConstant.ZERO).getPvChargeElec() != null) {
|
||||
pcsElecData.setPvChargeElec(pcsElecData1.get(CommonConstant.ZERO).getPvChargeElec());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PcsElecData pcsElecData : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pcsElecData);
|
||||
bigDecimalUtil.ifIsNUll(pcsElecData);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出累计充放电量数据
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation(value = "多电站导出累计充放电量数据")
|
||||
//@LogAnnotation(title = "累计充放电量", action = "导出累计充放电量数据")
|
||||
//@HzPermission(value = {PermissionConstant.REMOTECONTROL_COMMAND_EXPORT,PermissionConstant.DATA_SHOW_EXPORT,PermissionConstant.REMOTECONTROL_COMMAND_EXPORT})
|
||||
public void exportExcel(@RequestBody @Valid PcsStationReq req, HttpServletResponse response) {
|
||||
//功能描述:把同一个表格多个sheet测试结果重新输出,
|
||||
openStationService.exportEleData(req, response);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getElecMeterValue")
|
||||
@ApiOperation(value = "获取多电站累计充放电量数据(分页)")
|
||||
public DataResult<PageResult<PcsElecData>> getElecMeterValue(@RequestBody PcsStationReq req) throws ParseException {
|
||||
PageResult elecData = openStationService.getElecData(req);
|
||||
return DataResult.success(elecData);
|
||||
}
|
||||
|
||||
@PostMapping("/getElecMeterList")
|
||||
@ApiOperation(value = "获取多电站累计充放电量数据(不分页)")
|
||||
public DataResult<Object> getElecMeterList(@RequestBody PcsStationReq req) {
|
||||
Object obj = openStationService.getElecMeterList(req);
|
||||
return DataResult.success(obj);
|
||||
}
|
||||
|
||||
@PostMapping("/getElecMeterDetailList")
|
||||
@ApiOperation(value = "获取电站累计充放电量详细数据(不分页)")
|
||||
public DataResult<Object> getElecMeterDetailList(@RequestBody PcsStationReq req) {
|
||||
Object obj = openStationService.getElecMeterDetailList(req);
|
||||
return DataResult.success(obj);
|
||||
}
|
||||
|
||||
@PostMapping("/middle")
|
||||
@ApiOperation(value = "站首页的中间部分")
|
||||
public DataResult<OpenStationMiddle> middle(@RequestBody StationReq req) {
|
||||
|
||||
Integer stationId = req.getStationId();
|
||||
//电网几个数据
|
||||
//查EMU
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
|
||||
List<DeviceRespVO> emuList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.EMU);
|
||||
OpenStationMiddle middle = new OpenStationMiddle();
|
||||
if (!emuList.isEmpty()) {
|
||||
//只取第一个
|
||||
DeviceRespVO deviceEmu = emuList.get(0);
|
||||
//查redis缓存
|
||||
String emuKey = deviceEmu.getDeviceType() + ":" + stationId + ":" + deviceEmu.getSrcId();
|
||||
middle.setSrcId(deviceEmu.getSrcId());
|
||||
if (redisService.hasKey(emuKey)) {
|
||||
Map<Object, Object> emuMap = redisService.hgetall(emuKey);
|
||||
if (emuMap != null) {
|
||||
OpenStationMiddleOrig middleOrig = JSON.parseObject(JSON.toJSONString(emuMap), OpenStationMiddleOrig.class);
|
||||
if (middleOrig != null) {
|
||||
//合位
|
||||
middle.setCabinSwitch(middleOrig.getCabinSwitch() == null ? BigDecimal.ZERO : middleOrig.getCabinSwitch().getValue());
|
||||
//有功功率 ,无功功率
|
||||
BigDecimal activeAPowerEMU = middleOrig.getActiveAPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getActiveAPowerEMU().getValue();
|
||||
BigDecimal activeBPowerEMU = middleOrig.getActiveBPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getActiveBPowerEMU().getValue();
|
||||
BigDecimal activeCPowerEMU = middleOrig.getActiveCPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getActiveCPowerEMU().getValue();
|
||||
BigDecimal activePowerEMU = activeAPowerEMU.add(activeBPowerEMU).add(activeCPowerEMU);
|
||||
BigDecimal reactiveAPowerEMU = middleOrig.getReactiveAPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getReactiveAPowerEMU().getValue();
|
||||
BigDecimal reactiveBPowerEMU = middleOrig.getReactiveBPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getReactiveBPowerEMU().getValue();
|
||||
BigDecimal reactiveCPowerEMU = middleOrig.getReactiveCPowerEMU() == null ? BigDecimal.ZERO : middleOrig.getReactiveCPowerEMU().getValue();
|
||||
BigDecimal reactivePowerEMU = reactiveAPowerEMU.add(reactiveBPowerEMU).add(reactiveCPowerEMU);
|
||||
//这个值要除以1000
|
||||
//边端已处理 ,不用除以1000了
|
||||
//activePowerEMU = activePowerEMU.divide(new BigDecimal("1000"), 4, BigDecimal.ROUND_HALF_UP);
|
||||
//reactivePowerEMU = reactivePowerEMU.divide(new BigDecimal("1000"), 4, BigDecimal.ROUND_HALF_UP);
|
||||
middle.setActivePowerEMU(activePowerEMU);
|
||||
middle.setReactivePowerEMU(reactivePowerEMU);
|
||||
//频率
|
||||
middle.setGridEMU(middleOrig.getGridEMU() == null ? BigDecimal.ZERO : middleOrig.getGridEMU().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//pcs总有功,总无功
|
||||
ActiveReactivePower acPower = openStationService.getAcPower(stationId);
|
||||
middle.setActivePowerPCS(acPower.getActivePowerPCS());
|
||||
middle.setReactivePowerPCS(acPower.getReactivePowerPCS());
|
||||
//BMS值 SOC,SOH
|
||||
new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
List<DeviceRespVO> bmsList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.BMS);
|
||||
|
||||
List<WareHouse> wareHouseList = new ArrayList<>();
|
||||
if (!bmsList.isEmpty()) {
|
||||
BigDecimal soc = BigDecimal.ZERO;
|
||||
BigDecimal soh = BigDecimal.ZERO;
|
||||
int num = 0;
|
||||
for (int i = 0; i < bmsList.size(); i++) {
|
||||
DeviceRespVO deviceRespVO = bmsList.get(i);
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
//两个BMS就是两个舱
|
||||
WareHouse wareHouse = new WareHouse();
|
||||
num++;
|
||||
Map<Object, Object> bmsMap = redisService.hgetall(key);
|
||||
if (bmsMap != null) {
|
||||
OpenStationMiddleOrig middleOrig = JSON.parseObject(JSON.toJSONString(bmsMap), OpenStationMiddleOrig.class);
|
||||
if (middleOrig != null) {
|
||||
BigDecimal soc1 = middleOrig.getSoc() == null ? BigDecimal.ZERO : middleOrig.getSoc().getValue();
|
||||
BigDecimal soh1 = middleOrig.getSoh() == null ? BigDecimal.ZERO : middleOrig.getSoh().getValue();
|
||||
//wareHouse.setActivePowerPCS(acPower != null ? acPower.getActivePowerPCS() : BigDecimal.ZERO);
|
||||
//wareHouse.setReactivePowerPCS(acPower != null ? acPower.getReactivePowerPCS() : BigDecimal.ZERO);
|
||||
//wareHouseList.add(wareHouse);
|
||||
soc = soc.add(soc1);
|
||||
soh = soh.add(soh1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//计算两个平均值
|
||||
if (BigDecimal.ZERO.compareTo(soc) != 0) {
|
||||
soc = soc.divide(new BigDecimal(num), 2, BigDecimal.ROUND_UP);
|
||||
soh = soh.divide(new BigDecimal(num), 2, BigDecimal.ROUND_UP);
|
||||
}
|
||||
middle.setSoc(soc);
|
||||
middle.setSoh(soh);
|
||||
}
|
||||
//查舱数据
|
||||
Station station = stationService.selectById(stationId);
|
||||
if (station != null) {
|
||||
Integer cabinNum = station.getCabinNum();
|
||||
middle.setCabinCount(cabinNum);
|
||||
}
|
||||
//负荷功率=电网总有功-储能总有功
|
||||
BigDecimal activePowerEMU = middle.getActivePowerEMU();
|
||||
BigDecimal activePowerPCS = BigDecimal.ZERO;
|
||||
//总有功循环合计
|
||||
/*for (ActiveReactivePower acPower : acPowers) {
|
||||
activePowerPCS = activePowerPCS.add(acPower.getActivePowerPCS());
|
||||
}*/
|
||||
//负荷功率
|
||||
if (activePowerEMU == null) {
|
||||
activePowerEMU = BigDecimal.ZERO;
|
||||
}
|
||||
//负载功率
|
||||
BigDecimal loadPower = activePowerEMU.subtract(activePowerPCS);
|
||||
middle.setLoadPower(loadPower);
|
||||
middle.setWareHouseList(wareHouseList);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(middle);
|
||||
bigDecimalUtil.ifIsNUll(middle);
|
||||
return DataResult.success(middle);
|
||||
}
|
||||
|
||||
@PostMapping("/middlePart")
|
||||
@ApiOperation(value = "站首页的中间部分-分开的")
|
||||
public DataResult<List<WareHouse>> middlePart(@RequestBody StationReq req) {
|
||||
Integer stationId = req.getStationId();
|
||||
//BMS值 SOC,SOH
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
List<DeviceRespVO> bmsList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.BMS);
|
||||
if (bmsList.isEmpty()) {
|
||||
bmsList = deviceService.getListByFuzzyDeviceType(stationId, DeviceTypeConstant.BMS);
|
||||
}
|
||||
List<WareHouse> wareHouseList = new ArrayList<>();
|
||||
for (int i = 0; i < bmsList.size(); i++) {
|
||||
DeviceRespVO deviceRespVO = bmsList.get(i);
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
WareHouse wareHouse = new WareHouse();
|
||||
wareHouse.setBmsSrcId(deviceRespVO.getSrcId());
|
||||
DeviceTransfer soc = (DeviceTransfer) redisService.hget(key, "soc");
|
||||
DeviceTransfer soh = (DeviceTransfer) redisService.hget(key, "soh");
|
||||
Date updateTime = (Date) redisService.hget(key, "updateTime");
|
||||
wareHouse.setUpdateTime(updateTime);
|
||||
if (soc != null) {
|
||||
wareHouse.setSoc(soc.getValue());
|
||||
}
|
||||
if (soh != null) {
|
||||
wareHouse.setSoh(soh.getValue());
|
||||
}
|
||||
wareHouseList.add(wareHouse);
|
||||
}
|
||||
}
|
||||
|
||||
//防逆流电表 有功功率
|
||||
DeviceReqVO devices = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
//防逆流
|
||||
deviceReqVO.setDeviceTypePrefix(DeviceTypeConstant.AMMETER_FNL);
|
||||
List<DeviceRespVO> fnlDeviceList = deviceService.getList(deviceReqVO);
|
||||
for (int i = 0; i < fnlDeviceList.size(); i++) {
|
||||
DeviceRespVO deviceRespVO = fnlDeviceList.get(i);
|
||||
String key = deviceRespVO.getDeviceType() + ":" + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
WareHouse wareHouse = new WareHouse();
|
||||
wareHouse.setBmsSrcId(deviceRespVO.getSrcId());
|
||||
DeviceTransfer activePower = (DeviceTransfer) redisService.hget(key, "activePower");
|
||||
//DeviceTransfer activePower = (DeviceTransfer) redisService.hget(key, "YC0010");
|
||||
Date updateTime = (Date) redisService.hget(key, "updateTime");
|
||||
wareHouse.setUpdateTime(updateTime);
|
||||
if (activePower != null) {
|
||||
wareHouse.setActivePowerFNL(activePower.getValue());
|
||||
}
|
||||
|
||||
wareHouseList.add(wareHouse);
|
||||
}
|
||||
}
|
||||
|
||||
deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
List<DeviceRespVO> pcsList = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.PCS);
|
||||
if (pcsList.isEmpty()) {
|
||||
pcsList = deviceService.getListByFuzzyDeviceType(stationId, DeviceTypeConstant.PCS);
|
||||
}
|
||||
int len = wareHouseList.size() - 1;
|
||||
if (!pcsList.isEmpty()) {
|
||||
//总有功, 总无功
|
||||
for (int i = 0; i < pcsList.size(); i++) {
|
||||
String key = pcsList.get(i).getDeviceType() + ":" + stationId + ":" + pcsList.get(i).getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
Map<Object, Object> redisInfo = redisService.hgetall(key);
|
||||
String pcsState = openStationService.getPcsState(redisInfo);
|
||||
DeviceTransfer outputPower = (DeviceTransfer) redisService.hget(key, "outputPower");
|
||||
DeviceTransfer reactivePowerPCS = (DeviceTransfer) redisService.hget(key, "reactivePowerPCS");
|
||||
Date updateTime = (Date) redisService.hget(key, "updateTime");
|
||||
//根据
|
||||
WareHouse wareHouse = null;
|
||||
if (i > len) {
|
||||
wareHouse = new WareHouse();
|
||||
wareHouseList.add(wareHouse);
|
||||
} else {
|
||||
wareHouse = wareHouseList.get(i);
|
||||
}
|
||||
//以pcs最后更新时间为准,当没有pcs时候,使用bms时间
|
||||
wareHouse.setUpdateTime(updateTime);
|
||||
wareHouse.setPcsSrcId(pcsList.get(i).getSrcId());
|
||||
wareHouse.setPcsState(pcsState);
|
||||
//增加电流流向
|
||||
wareHouse.setFlowDirection(pcsList.get(i).getFlowDirection());
|
||||
if (outputPower != null) {
|
||||
wareHouse.setActivePowerPCS(outputPower.getValue());
|
||||
}
|
||||
if (reactivePowerPCS != null) {
|
||||
wareHouse.setReactivePowerPCS(reactivePowerPCS.getValue());
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(wareHouse);
|
||||
bigDecimalUtil.ifIsNUll(wareHouse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(wareHouseList);
|
||||
}
|
||||
|
||||
@PostMapping("/middlePartInverter")
|
||||
@ApiOperation(value = "站首页的中间部分-光伏")
|
||||
public DataResult<List<Object>> middlePartInverter(@RequestBody StationReq req) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
Integer stationId = req.getStationId();
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setFuzzyDeviceType(DeviceTypeConstant.INVERTER);
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
if (!deviceList.isEmpty()) {
|
||||
int len = deviceList.size();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String key = deviceList.get(i).getDeviceType() + ":" + stationId + ":" + deviceList.get(i).getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
DeviceTransfer outputPower = (DeviceTransfer) redisService.hget(key, "acActivePower");
|
||||
DeviceTransfer acReactivePower = (DeviceTransfer) redisService.hget(key, "acReactivePower");
|
||||
map.put("acActivePower", outputPower == null ? null : outputPower.getValue());
|
||||
map.put("acReactivePower", acReactivePower == null ? null : acReactivePower.getValue());
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/circleCtr")
|
||||
@ApiOperation(value = "环控")
|
||||
public DataResult<List<CircleCtrlResp>> circleCtr(@RequestBody StationReq req) {
|
||||
//查站下的温湿度仪器
|
||||
List<DeviceRespVO> deviceList = deviceService.getListByDeviceType(req.getStationId(), DeviceTypeConstant.TRANSMITTER);
|
||||
deviceList = deviceList.stream().sorted(Comparator.comparing(DeviceRespVO::getPid)).collect(Collectors.toList());
|
||||
List<CircleCtrlResp> circleList = openStationService.getCircle(deviceList);
|
||||
|
||||
return DataResult.success(circleList);
|
||||
}
|
||||
|
||||
@PostMapping("/getEarnings")
|
||||
@ApiOperation(value = "获取电站收益")
|
||||
public DataResult<EarningsCalculateCountResp> getEarnings(@RequestBody StationReq req) {
|
||||
EarningsCalculateCountResp earningsCount = earningsCalculateService.getEarningsCount(req.getStationId());
|
||||
return DataResult.success(earningsCount);
|
||||
}
|
||||
|
||||
@PostMapping("/getStationData")
|
||||
@ApiOperation(value = "站首页电站数据(光伏日发、总发以及本地负载数据)")
|
||||
public DataResult<HomePageStationDataResp> getStationData(@RequestBody StationReq req) {
|
||||
HomePageStationDataResp homePageStationData = openStationService.getHomePageStationData(req);
|
||||
return DataResult.success(homePageStationData);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/incomeData")
|
||||
@ApiOperation(value = "充放电差值")
|
||||
@TokenIgnore
|
||||
public DataResult getPcsIncomeData(@RequestBody PcsStationReq req) {
|
||||
return DataResult.success(openStationService.getPcsIncomeData(req));
|
||||
}
|
||||
|
||||
@PostMapping("/realTimeIncomeData")
|
||||
@ApiOperation(value = "实时充放电差值")
|
||||
@TokenIgnore
|
||||
public DataResult getPcsRealTimeIncomeData(@RequestBody StationReq req) {
|
||||
return DataResult.success(openStationService.getPcsRealTimeIncomeData(req));
|
||||
}
|
||||
|
||||
@PostMapping("jobDataManage")
|
||||
@TokenIgnore
|
||||
public DataResult jobDataManage() {
|
||||
openStationService.jobDataManage();
|
||||
//15分钟收益计算结束
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,360 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Device;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.PvStationService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.StationCurveReq;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.InverterResp.InverterRespVO;
|
||||
import com.ho.business.vo.resp.InverterResp.PVStationPanelRespVO;
|
||||
import com.ho.business.vo.resp.InverterResp.PowerGenerateRespVO;
|
||||
import com.ho.business.vo.resp.InverterResp.RealtimeCurveRespVO;
|
||||
import com.ho.business.vo.resp.cockpit.CockForStationResp;
|
||||
import com.ho.business.vo.resp.station.*;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 光伏电站
|
||||
* @date 2023/1/6
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "pvStation")
|
||||
@Api(tags = "光伏电站")
|
||||
@Slf4j
|
||||
public class PVStationController {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
PvStationService pvStationService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
private StationService stationService;
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@PostMapping("/pvPanel")
|
||||
@ApiOperation(value = "光伏面板数据")
|
||||
@Cacheable(cacheManager = "towMinuteCacheManager", value = "pvPanel", key = "#stationReq.stationId", sync = true)
|
||||
public DataResult<PVStationPanelRespVO> pvPanel(@RequestBody StationReq stationReq) {
|
||||
log.info("进入pvPanel");
|
||||
Integer stationId = stationReq.getStationId();
|
||||
//查电站下的逆变器
|
||||
List<DeviceRespVO> deviceRespVOS = pvStationService.getIntervalsByStationId(stationReq.getStationId());
|
||||
// 电站数据来自于各个逆变器
|
||||
PVStationPanelRespVO pvPanel = pvStationService.getPvPanel(stationId, deviceRespVOS);
|
||||
//返回值的BigDecimal类型保留两位小数,并且把null值赋予0
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pvPanel);
|
||||
bigDecimalUtil.ifIsNUll(pvPanel);
|
||||
//增加3种设备清单 逆变器 inverter ,电表 ,气象仪
|
||||
//根据实际设备来查
|
||||
|
||||
List<StationDeviceEquipment> equipments = new ArrayList<>();
|
||||
//1.查是否有逆变器
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setDeviceTypePrefix(DeviceTypeConstant.INVERTER_PREFIX);
|
||||
List<DeviceRespVO> inverters = deviceService.getList(deviceReqVO);
|
||||
if(!inverters.isEmpty()){
|
||||
StationDeviceEquipment inverter = new StationDeviceEquipment();
|
||||
inverter.setType("inverter");
|
||||
inverter.setName("逆变器");
|
||||
equipments.add(inverter);
|
||||
}
|
||||
//2.电表
|
||||
deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setDeviceType(DeviceTypeConstant.COMMON_ELEMETER);
|
||||
List<DeviceRespVO> meters = deviceService.getList(deviceReqVO);
|
||||
if(!meters.isEmpty()){
|
||||
StationDeviceEquipment eleMeter = new StationDeviceEquipment();
|
||||
eleMeter.setType("elecMeter");
|
||||
eleMeter.setName("电表");
|
||||
equipments.add(eleMeter);
|
||||
}
|
||||
//3气象仪
|
||||
deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setDeviceType(DeviceTypeConstant.WEATHER_STATION);
|
||||
List<DeviceRespVO> weatherStations = deviceService.getList(deviceReqVO);
|
||||
if(!weatherStations.isEmpty()){
|
||||
StationDeviceEquipment weatherStation = new StationDeviceEquipment();
|
||||
weatherStation.setType("weatherInstrument");
|
||||
weatherStation.setName("气象仪");
|
||||
equipments.add(weatherStation);
|
||||
}
|
||||
pvPanel.setEquipments(equipments);
|
||||
return DataResult.success(pvPanel);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/realtimeCurve")
|
||||
@ApiOperation(value = "实时曲线")
|
||||
@Cacheable(cacheManager = "thirtySecondCacheManager", value = "realtimeCurve", key = "#stationReq.stationId", sync = true)
|
||||
public DataResult<List<RealtimeCurveRespVO>> realtimeCurve(@RequestBody StationReq stationReq) {
|
||||
//查电站下逆变器
|
||||
log.info("getIntervalsByStationId start:" + System.currentTimeMillis());
|
||||
List<DeviceRespVO> deviceRespVOS = pvStationService.getIntervalsByStationId(stationReq.getStationId());
|
||||
log.info("getIntervalsByStationId end:" + System.currentTimeMillis());
|
||||
List<RealtimeCurveRespVO> resList = pvStationService.getRealtimeCurve(stationReq.getStationId(), deviceRespVOS);
|
||||
log.info("getRealtimeCurve end:" + System.currentTimeMillis());
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (RealtimeCurveRespVO realtimeCurveRespVO : resList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(realtimeCurveRespVO);
|
||||
bigDecimalUtil.ifIsNUll(realtimeCurveRespVO);
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/powerGenerationCurve")
|
||||
@ApiOperation(value = "发电量和收益曲线")
|
||||
public DataResult<List<PowerGenerateRespVO>> powerGenerationCurve(@RequestBody StationCurveReq stationCurveReq) {
|
||||
//使用redis缓存
|
||||
String key = RedisKeyConstant.PV.POWER_GENERATION_CURVE + stationCurveReq.getStationId() + ":" + stationCurveReq.getType();
|
||||
if (redisService.hasKey(key)) {
|
||||
log.info("发电量和收益曲线:stationId:{},type:{}, 本次走Redis缓存", stationCurveReq.getStationId(), stationCurveReq.getType());
|
||||
List<PowerGenerateRespVO> generateRespVOList = (List<PowerGenerateRespVO>) redisService.get(key);
|
||||
return DataResult.success(generateRespVOList);
|
||||
}
|
||||
//判断电站是否为空,由于admin的账户不传电站id
|
||||
if (stationCurveReq.getStationId() == null) {
|
||||
return DataResult.success(new ArrayList<>());
|
||||
}
|
||||
//日发电量 月发电量 年发电量
|
||||
//日发电量和收益 按小时 ,从时序库查询
|
||||
//不管哪个类型,都要查电站下逆变器
|
||||
List<DeviceRespVO> deviceRespVOS = pvStationService.getIntervalsByStationId(stationCurveReq.getStationId());
|
||||
if (deviceRespVOS.isEmpty()) {
|
||||
return DataResult.success(new ArrayList<>());
|
||||
}
|
||||
List<PowerGenerateRespVO> powerGenerates = new ArrayList<>();
|
||||
//时间类型
|
||||
String queryType = stationCurveReq.getType();
|
||||
Date today = new Date();
|
||||
//如果类型是日 查当日的
|
||||
if (CommonConstant.DAY.equals(queryType)) {
|
||||
powerGenerates = pvStationService.powerGenerationCurrentDay(stationCurveReq.getStationId(), deviceRespVOS, today);
|
||||
}
|
||||
//当月 和当年的
|
||||
if (CommonConstant.MONTH.equals(queryType) || CommonConstant.YEAR.equals(queryType)) {
|
||||
powerGenerates = pvStationService.powerGeneration(stationCurveReq.getStationId(), deviceRespVOS, queryType);
|
||||
}
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (PowerGenerateRespVO powerGenerate : powerGenerates) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(powerGenerate);
|
||||
bigDecimalUtil.ifIsNUll(powerGenerate);
|
||||
}
|
||||
//保存缓存
|
||||
redisService.set(key, powerGenerates, 2, TimeUnit.MINUTES);
|
||||
return DataResult.success(powerGenerates);
|
||||
}
|
||||
|
||||
@PostMapping("/inverterList")
|
||||
@ApiOperation(value = "逆变器列表")
|
||||
@Cacheable(cacheManager = "tenSecondCacheManager", value = "inverterList", key = "#stationReq.stationId", sync = true)
|
||||
public DataResult<List<InverterRespVO>> inverterList(@RequestBody StationReq stationReq) {
|
||||
List<InverterRespVO> list = pvStationService.inverterStatusList(stationReq);
|
||||
for (InverterRespVO inverterRespVO : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(inverterRespVO);
|
||||
bigDecimalUtil.ifIsNUll(inverterRespVO);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/forStationCockpit")
|
||||
@ApiOperation(value = "给电站用的大屏数据")
|
||||
public DataResult<CockForStationResp> forStationCockpit(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
Integer groupId = user.getGroupId();
|
||||
//使用redis缓存
|
||||
String key = RedisKeyConstant.COCKPIT.FOR_STATION_COCKPIT + groupId;
|
||||
if (redisService.hasKey(key)) {
|
||||
log.info("给电站用的大屏数据:groupId:{}, 本次走Redis缓存", groupId);
|
||||
CockForStationResp stationCockpitValue = (CockForStationResp) redisService.get(key);
|
||||
return DataResult.success(stationCockpitValue);
|
||||
}
|
||||
CockForStationResp stationCockpitValue = stationService.getStationCockpitValue(user);
|
||||
bigDecimalUtil.ifIsNUll(stationCockpitValue);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationCockpitValue);
|
||||
//保存缓存
|
||||
redisService.set(key, stationCockpitValue, 5, TimeUnit.MINUTES);
|
||||
return DataResult.success(stationCockpitValue);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/commonElemeterList")
|
||||
@ApiOperation(value = "通用电表列表")
|
||||
public DataResult<List<CommonElemeterResp>> commonElemeterList(@RequestBody @Valid StationReq stationReq) {
|
||||
Integer stationId = stationReq.getStationId();
|
||||
Station station = stationService.selectById(stationId);
|
||||
String address = station.getAddress();
|
||||
//结果集
|
||||
List<CommonElemeterResp> list = new ArrayList<>();
|
||||
//查询站下所有通用电表
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
//设备为通用电表
|
||||
deviceReqVO.setDeviceType(DeviceTypeConstant.COMMON_ELEMETER);
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
//使用redis缓存
|
||||
String key = RedisKeyConstant.COMMON_ELEMETER + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
log.info("通用电表数据: srcId:{}", deviceRespVO.getSrcId());
|
||||
Object o = redisService.hgetall(key);
|
||||
HashMap<String, Object> map = (HashMap) o;
|
||||
ElemeterOrig elemeterOrig = JSON.parseObject(JSON.toJSONString(map), ElemeterOrig.class);
|
||||
CommonElemeterResp elemeter = new CommonElemeterResp();
|
||||
//将点表数据扔到对象中
|
||||
elemeter.setForwardActE0(elemeterOrig.getForwardActE0() == null ? BigDecimal.ZERO : elemeterOrig.getForwardActE0().getValue());
|
||||
elemeter.setForwardActE1(elemeterOrig.getForwardActE1() == null ? BigDecimal.ZERO : elemeterOrig.getForwardActE1().getValue());
|
||||
elemeter.setForwardActE2(elemeterOrig.getForwardActE2() == null ? BigDecimal.ZERO : elemeterOrig.getForwardActE2().getValue());
|
||||
elemeter.setForwardActE3(elemeterOrig.getForwardActE3() == null ? BigDecimal.ZERO : elemeterOrig.getForwardActE3().getValue());
|
||||
elemeter.setForwardActE4(elemeterOrig.getForwardActE4() == null ? BigDecimal.ZERO : elemeterOrig.getForwardActE4().getValue());
|
||||
|
||||
elemeter.setBackwardActE0(elemeterOrig.getBackwardActE0() == null ? BigDecimal.ZERO : elemeterOrig.getBackwardActE0().getValue());
|
||||
elemeter.setBackwardActE1(elemeterOrig.getBackwardActE1() == null ? BigDecimal.ZERO : elemeterOrig.getBackwardActE1().getValue());
|
||||
elemeter.setBackwardActE2(elemeterOrig.getBackwardActE2() == null ? BigDecimal.ZERO : elemeterOrig.getBackwardActE2().getValue());
|
||||
elemeter.setBackwardActE3(elemeterOrig.getBackwardActE3() == null ? BigDecimal.ZERO : elemeterOrig.getBackwardActE3().getValue());
|
||||
elemeter.setBackwardActE4(elemeterOrig.getBackwardActE4() == null ? BigDecimal.ZERO : elemeterOrig.getBackwardActE4().getValue());
|
||||
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(elemeter);
|
||||
//通讯
|
||||
Device deviceReq = new Device();
|
||||
deviceReq.setDeviceType(deviceRespVO.getDeviceType());
|
||||
deviceReq.setStationId(stationId);
|
||||
deviceReq.setSrcId(deviceRespVO.getSrcId());
|
||||
deviceReq.setSerialNo(deviceRespVO.getSerialNo());
|
||||
boolean onLine = deviceService.isOnLine(deviceReq);
|
||||
if (onLine) {
|
||||
elemeter.setCommunicationStatus(1);
|
||||
} else {
|
||||
elemeter.setCommunicationStatus(0);
|
||||
}
|
||||
elemeter.setStationId(stationId);
|
||||
elemeter.setSrcId(deviceRespVO.getSrcId());
|
||||
elemeter.setDeviceName(deviceRespVO.getDeviceName());
|
||||
elemeter.setDeviceType(deviceRespVO.getDeviceType());
|
||||
JSONObject deviceJson = deviceRespVO.getDeviceJson();
|
||||
String deviceAddress = "";
|
||||
String deviceModel = "";
|
||||
if (null != deviceJson) {
|
||||
deviceAddress = deviceJson.getString(DeviceTypeConstant.ADDRESS);
|
||||
deviceModel = deviceJson.getString(DeviceTypeConstant.DEVICE_MODEL);
|
||||
}
|
||||
deviceAddress = (null == deviceAddress ? "" : deviceAddress);
|
||||
elemeter.setAddress(address + deviceAddress);
|
||||
elemeter.setDeviceModel(deviceModel);
|
||||
list.add(elemeter);
|
||||
}
|
||||
}
|
||||
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/weatherStationList")
|
||||
@ApiOperation(value = "气象仪列表")
|
||||
public DataResult<List<WeatherStationResp>> weatherStationList(@RequestBody @Valid StationReq stationReq) {
|
||||
Integer stationId = stationReq.getStationId();
|
||||
Station station = stationService.selectById(stationId);
|
||||
String address = station.getAddress();
|
||||
//结果集
|
||||
List<WeatherStationResp> list = new ArrayList<>();
|
||||
//查询站下所有通用电表
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
//设备为气象仪
|
||||
deviceReqVO.setDeviceType(DeviceTypeConstant.WEATHER_STATION);
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
//使用redis缓存
|
||||
String key = RedisKeyConstant.WEATHER_STATION + stationId + ":" + deviceRespVO.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
log.info("气象仪数据: srcId:{}", deviceRespVO.getSrcId());
|
||||
Object o = redisService.hgetall(key);
|
||||
HashMap<String, Object> map = (HashMap) o;
|
||||
WeatherStationOrig weatherStationOrig = JSON.parseObject(JSON.toJSONString(map), WeatherStationOrig.class);
|
||||
WeatherStationResp weatherStation = new WeatherStationResp();
|
||||
//取那几个点表值
|
||||
weatherStation.setWindSpeed(weatherStationOrig.getVelocity() == null ? BigDecimal.ZERO : weatherStationOrig.getVelocity().getValue());
|
||||
weatherStation.setRainfall(weatherStationOrig.getPrecipitation() == null ? BigDecimal.ZERO : weatherStationOrig.getPrecipitation().getValue());
|
||||
weatherStation.setTemperature(weatherStationOrig.getTemperature() == null ? BigDecimal.ZERO : weatherStationOrig.getTemperature().getValue());
|
||||
weatherStation.setPressure(weatherStationOrig.getBarometric() == null ? BigDecimal.ZERO : weatherStationOrig.getBarometric().getValue());
|
||||
weatherStation.setRadiation(weatherStationOrig.getRadiation() == null ? BigDecimal.ZERO : weatherStationOrig.getRadiation().getValue());
|
||||
weatherStation.setWindDirection(weatherStationOrig.getWind() == null ? BigDecimal.ZERO : weatherStationOrig.getWind().getValue());
|
||||
weatherStation.setHumidity(weatherStationOrig.getHumidity() == null ? BigDecimal.ZERO : weatherStationOrig.getHumidity().getValue());
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(weatherStation);
|
||||
//判断是否在线
|
||||
Device deviceReq = new Device();
|
||||
deviceReq.setDeviceType(deviceRespVO.getDeviceType());
|
||||
deviceReq.setStationId(stationId);
|
||||
deviceReq.setSrcId(deviceRespVO.getSrcId());
|
||||
deviceReq.setSerialNo(deviceRespVO.getSerialNo());
|
||||
boolean onLine = deviceService.isOnLine(deviceReq);
|
||||
if (onLine) {
|
||||
weatherStation.setCommunicationStatus(1);
|
||||
} else {
|
||||
weatherStation.setCommunicationStatus(0);
|
||||
}
|
||||
weatherStation.setStationId(stationId);
|
||||
weatherStation.setSrcId(deviceRespVO.getSrcId());
|
||||
weatherStation.setDeviceName(deviceRespVO.getDeviceName());
|
||||
weatherStation.setDeviceType(deviceRespVO.getDeviceType());
|
||||
JSONObject deviceJson = deviceRespVO.getDeviceJson();
|
||||
String deviceAddress = "";
|
||||
String deviceModel = "";
|
||||
if (null != deviceJson) {
|
||||
deviceAddress = deviceJson.getString(DeviceTypeConstant.ADDRESS);
|
||||
deviceModel = deviceJson.getString(DeviceTypeConstant.DEVICE_MODEL);
|
||||
}
|
||||
deviceAddress = (null == deviceAddress ? "" : deviceAddress);
|
||||
weatherStation.setAddress(address + deviceAddress);
|
||||
weatherStation.setDeviceModel(deviceModel);
|
||||
list.add(weatherStation);
|
||||
}
|
||||
}
|
||||
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.PageConfig;
|
||||
import com.ho.business.service.PageConfigService;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2023/8/8 14:30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "config")
|
||||
@Api(tags = "页面字段配置")
|
||||
@Slf4j
|
||||
public class PageConfigController {
|
||||
@Autowired
|
||||
private PageConfigService pageConfigService;
|
||||
|
||||
//新增
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增页面字段数据配置")
|
||||
@LogAnnotation(title = "页面字段配置", action = "新增页面字段数据配置")
|
||||
public DataResult add(@RequestBody List<PageConfig> configList) {
|
||||
int i = pageConfigService.addBatch(configList);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//查询
|
||||
@PostMapping("selectAll")
|
||||
@ApiOperation(value = "查询")
|
||||
public DataResult<List<PageConfig>> pageModelType(@RequestBody PageConfig vo){
|
||||
List<PageConfig> configList = pageConfigService.selectPage(vo);
|
||||
return DataResult.success(configList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口(支持批量)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除页面字段数据配置")
|
||||
@LogAnnotation(title = "页面字段配置", action = "删除页面字段数据配置")
|
||||
@TokenIgnore
|
||||
public DataResult delete(@RequestBody List<Integer> ids) {
|
||||
pageConfigService.delete(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.PcsService;
|
||||
import com.ho.business.service.StationHomeService;
|
||||
import com.ho.business.vo.req.MonitorQuery;
|
||||
import com.ho.business.vo.req.pcs.PcsReqVo;
|
||||
import com.ho.business.vo.req.pcs.PcsUpdateReqVo;
|
||||
import com.ho.business.vo.resp.AppRealTimeCurveRespVo;
|
||||
import com.ho.business.vo.resp.pcs.PcsRunDataSetting;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description pcs展示页面
|
||||
* Author yule
|
||||
* Date 2023/5/6 16:06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "pcs")
|
||||
@Api(tags = "pcs展示页面")
|
||||
public class PcsController {
|
||||
|
||||
@Autowired
|
||||
PcsService pcsService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
StationHomeService stationHomeService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@PostMapping("runDataSetting")
|
||||
@ApiOperation(value = "查询运行数据")
|
||||
public DataResult<PcsRunDataSetting> getRunDataSetting(@RequestBody PcsReqVo vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("updateRunData")
|
||||
@ApiOperation(value = "修改运行数据")
|
||||
@LogAnnotation(title = "pcs展示页面", action = "修改运行数据")
|
||||
public DataResult updateRunData(@RequestBody List<PcsUpdateReqVo> vo) {
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/pcsCurve")
|
||||
@ApiOperation(value = "psc曲线")
|
||||
public DataResult<List<AppRealTimeCurveRespVo>> pcsCurve(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<AppRealTimeCurveRespVo> resList = stationHomeService.getPcsCurve(monitorQuery);
|
||||
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
|
||||
bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/opticalStorageCurve")
|
||||
@ApiOperation(value = "光储逆变器曲线")
|
||||
public DataResult<List<AppRealTimeCurveRespVo>> opticalStorageCurve(@RequestBody MonitorQuery monitorQuery) {
|
||||
List<AppRealTimeCurveRespVo> resList = stationHomeService.getOpticalStorageCurve(monitorQuery);
|
||||
|
||||
//返回值的BigDecimal类型保留两位小数
|
||||
for (AppRealTimeCurveRespVo realTimeCurveRespVo : resList) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(realTimeCurveRespVo);
|
||||
bigDecimalUtil.ifIsNUll(realTimeCurveRespVo);
|
||||
}
|
||||
return DataResult.success(resList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,449 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.*;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.service.PeakShavingService;
|
||||
import com.ho.business.service.PlanningCurveIssueService;
|
||||
import com.ho.business.service.StationSnService;
|
||||
import com.ho.business.vo.Holiday;
|
||||
import com.ho.business.vo.PolicyConfigPlanVo;
|
||||
import com.ho.business.vo.req.PolicyConfigData;
|
||||
import com.ho.business.vo.resp.planningCurve.PlanningIssueQueryVo;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.*;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* @auther catkins
|
||||
* @Date 10:50 2024/1/8
|
||||
* 削峰填谷
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "peakShaving")
|
||||
@Api(tags = "削峰填谷")
|
||||
@Slf4j
|
||||
public class PeakShavingController {
|
||||
|
||||
@Autowired
|
||||
private PeakShavingService peakShavingService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
PlanningCurveIssueService planningCurveIssueService;
|
||||
|
||||
public static final String JSON_FILE_NAME = "svc_plantemplate.json";
|
||||
|
||||
public static final String TAR_GZ_FILE_PATH = "/usr/temporaryFiles/svc_plantemplate.tar.gz";
|
||||
|
||||
public static final String FILE_PATH = "/deploy/sems/data";
|
||||
|
||||
public static final String DEVICE_TYPE = "plan";
|
||||
|
||||
@Autowired
|
||||
StationSnService stationSnService;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "新增计划曲线模板")
|
||||
@TokenIgnore
|
||||
public DataResult add(HttpServletRequest request, @RequestBody PlanningCurveTemplate template){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
if (null != simpleUser && null != template) {
|
||||
template.setGroupId(simpleUser.getGroupId());
|
||||
}
|
||||
Map<String, Object> result = peakShavingService.addPlanningCurveTemplate(template);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("/modify")
|
||||
@ApiOperation(value = "修改计划曲线模板")
|
||||
@TokenIgnore
|
||||
public DataResult modify(@RequestBody PlanningCurveTemplate planningCurveTemplate){
|
||||
Map<String, Object> result = peakShavingService.modifyPlanningCurveTemplate(planningCurveTemplate);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "删除计划曲线模板")
|
||||
@TokenIgnore
|
||||
@HzPermission(PermissionConstant.BUSINESS_PEAK_DELETE)
|
||||
public DataResult delete(@RequestBody PlanningCurveTemplate planningCurveTemplate){
|
||||
if( planningCurveTemplate == null || planningCurveTemplate.getTemId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
Map<String, Object> result = peakShavingService.deletePlanningCurveTemplates(planningCurveTemplate);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("queryTemplates")
|
||||
@ApiOperation(value = "模板列表查询")
|
||||
@TokenIgnore
|
||||
public DataResult queryTemplates(@RequestBody PlanningCurveTemplate template) {
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = peakShavingService.getPlanningCurveTemplates(template);
|
||||
return DataResult.success(planningCurveTemplates);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("queryTableTemplates")
|
||||
@ApiOperation(value = "模板列表查询")
|
||||
@TokenIgnore
|
||||
public DataResult queryTableTemplates(@RequestBody PlanningCurveTemplate template) {
|
||||
List<PlanningCurveTableTemplate> planningCurveTemplates = peakShavingService.getTableTemplates(template);
|
||||
return DataResult.success(planningCurveTemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面 查看详情接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("queryTemplateDetail")
|
||||
@ApiOperation(value = "计划曲线详情")
|
||||
@TokenIgnore
|
||||
public DataResult planningCurveTemplateDetail(@RequestBody PlanningCurveTemplate template) {
|
||||
PlanningCurveTemplate planningCurveTemplate = peakShavingService.getPlanningCurveTemplate(template);
|
||||
return DataResult.success(planningCurveTemplate);
|
||||
}
|
||||
|
||||
@PostMapping("queryTemplateCurves")
|
||||
@ApiOperation(value = "计划曲线,echarts图数据")
|
||||
@TokenIgnore
|
||||
public DataResult queryTemplateCurves(@RequestBody PlanningCurveTemplate template) {
|
||||
if( null == template || null == template.getStationId() ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
List<List<PlanningCurve>> curves = peakShavingService.queryTemplateCurves(template);
|
||||
return DataResult.success(curves);
|
||||
}
|
||||
|
||||
// @PostMapping("sendTemplateByDay")
|
||||
// @ApiOperation(value = "发送计划曲线模板(此方法为一天执行一次)")
|
||||
// @TokenIgnore
|
||||
// public void sendTemplateByDay(){
|
||||
// log.error("定时任务调用开始>>>>>>>>>>>>>>>>{}","发送计划曲线模板(此方法为一天执行一次)");
|
||||
// int type = 1;
|
||||
// peakShavingService.sendData(type);
|
||||
// }
|
||||
|
||||
// @PostMapping("sendTemplateByMonth")
|
||||
// @ApiOperation(value = "发送计划曲线模板(此方法为一个月执行一次)")
|
||||
// @TokenIgnore
|
||||
// public void sendTemplateByMonth(){
|
||||
// log.error("定时任务调用开始>>>>>>>>>>>>>>>>{}","发送计划曲线模板(此方法为一个月执行一次)");
|
||||
// int type = 2;
|
||||
// peakShavingService.sendData(type);
|
||||
// }
|
||||
|
||||
|
||||
@PostMapping("sendTemplateFile")
|
||||
@ApiOperation(value = "组装json文件并下发到计划曲线设备")
|
||||
@TokenIgnore
|
||||
public DataResult sendTemplateFile(HttpServletRequest request, HttpServletResponse response, @RequestBody PlanningIssueQueryVo vo){
|
||||
if( vo == null || vo.getStationId() == null){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
// 如果对象里的刷新时间都是空的,和前端确定的方式是立即执行,那么则获取服务器时间10分钟之后的时间做为参数
|
||||
if( vo.getPlanRefreshH() == -1 && vo.getPlanRefreshM() == -1 ){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.MINUTE,10);
|
||||
vo.setPlanRefreshH(calendar.get(Calendar.HOUR_OF_DAY));
|
||||
vo.setPlanRefreshM(calendar.get(Calendar.MINUTE));
|
||||
}
|
||||
|
||||
Integer stationId = vo.getStationId();
|
||||
// 根据电站id查询设备srcId
|
||||
Integer srcId = peakShavingService.queryIssueDevice(stationId);
|
||||
// 根据电站id查询电站sn号
|
||||
String sn = peakShavingService.getSnByStationId(stationId);
|
||||
vo.setSrcId(srcId);
|
||||
vo.setSn(sn);
|
||||
// 查询下发参数
|
||||
List<Map<String, Object>> issueDatas = planningCurveIssueService.getPlanCurveIssueData(vo);
|
||||
// 判断下发参数是否为空,如果为空则不继续处理
|
||||
if( issueDatas == null || issueDatas.size() <= 0 ){
|
||||
throw new BusinessException(BaseResponseCode.SEND_DATA_IS_EXISTS);
|
||||
}
|
||||
PlanningTemplateVo planningTemplateVo = new PlanningTemplateVo();
|
||||
planningTemplateVo.setStationId(stationId);
|
||||
List<OrderIssuedVO> orderIssuedVOS = processOrderIssuedVO(issueDatas);
|
||||
planningTemplateVo.setOrderIssuedReqVO(orderIssuedVOS);
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
//当前登陆人
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetail = redisService.getUserDetailByToken(token);
|
||||
String json = peakShavingService.getJson(planningTemplateVo, userDetail);
|
||||
// json字符串写出json文件,方便后面压缩
|
||||
wirteFile(JSON_FILE_NAME,json);
|
||||
// 取得json文件
|
||||
File fileToCompress = new File(JSON_FILE_NAME);
|
||||
// 生成一个空的压缩文件
|
||||
File tarGzFile = new File(TAR_GZ_FILE_PATH);
|
||||
// File tarGzFile = new File("D:/svc_plantemplate.tar.gz");
|
||||
|
||||
// 对json文件进行压缩
|
||||
result = compressFileToTarGz(fileToCompress, tarGzFile);
|
||||
|
||||
if( fileToCompress.exists() ){
|
||||
if (fileToCompress.delete()) {
|
||||
System.out.println("临时文件删除成功!");
|
||||
} else {
|
||||
System.out.println("临时文件删除失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("临时文件不存在!");
|
||||
}
|
||||
result = uploadFile(planningTemplateVo,tarGzFile);
|
||||
if( tarGzFile.exists() ){
|
||||
if (tarGzFile.delete()) {
|
||||
System.out.println("临时压缩包删除成功!");
|
||||
} else {
|
||||
System.out.println("临时压缩包删除失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("临时压缩包不存在!");
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
public static void wirteFile(String filePath,String json){
|
||||
try (FileWriter writer = new FileWriter(filePath, true)) {
|
||||
writer.write(json);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理下发参数,组装成对象
|
||||
private List<OrderIssuedVO> processOrderIssuedVO(List<Map<String, Object>> issueDatas){
|
||||
List<OrderIssuedVO> list = new ArrayList<>();
|
||||
OrderIssuedVO orderIssuedVO = null;
|
||||
for (Map<String, Object> issueData : issueDatas) {
|
||||
orderIssuedVO = new OrderIssuedVO();
|
||||
if( issueData.containsKey("col") && issueData.get("col") != null ){
|
||||
orderIssuedVO.setCol(issueData.get("col").toString());
|
||||
}
|
||||
if( issueData.containsKey("minValue") && issueData.get("minValue") != null ){
|
||||
orderIssuedVO.setMinValue(new BigDecimal(issueData.get("minValue").toString()));
|
||||
}
|
||||
if( issueData.containsKey("maxValue") && issueData.get("maxValue") != null){
|
||||
orderIssuedVO.setMaxValue(new BigDecimal(issueData.get("maxValue").toString()));
|
||||
}
|
||||
if( issueData.containsKey("modifyValue") && issueData.get("modifyValue") != null){
|
||||
orderIssuedVO.setModifyValue(new BigDecimal(issueData.get("modifyValue").toString()));
|
||||
}
|
||||
if( issueData.containsKey("sn") && issueData.get("sn") != null ){
|
||||
orderIssuedVO.setSn(issueData.get("sn").toString());
|
||||
}
|
||||
if( issueData.containsKey("srcId") && issueData.get("srcId") != null ){
|
||||
orderIssuedVO.setSrcId(Integer.parseInt(issueData.get("srcId").toString()));
|
||||
}
|
||||
if( issueData.containsKey("stationId") && issueData.get("stationId") != null ){
|
||||
orderIssuedVO.setStationId(Integer.parseInt(issueData.get("stationId").toString()));
|
||||
}
|
||||
list.add(orderIssuedVO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Map<String, Object> compressFileToTarGz(File fileToCompress, File tarGzFile){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
try (FileInputStream fis = new FileInputStream(fileToCompress);
|
||||
FileOutputStream fos = new FileOutputStream(tarGzFile);
|
||||
GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(fos);
|
||||
TarArchiveOutputStream taos = new TarArchiveOutputStream(gzos)) {
|
||||
TarArchiveEntry entry = new TarArchiveEntry(fileToCompress);
|
||||
entry.setSize(fileToCompress.length());
|
||||
taos.putArchiveEntry(entry);
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
taos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
taos.closeArchiveEntry();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.PeakShaving.TAR_FILE_ISSUE_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> uploadFile(PlanningTemplateVo template,File tarGzFile){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
Integer stationId = template.getStationId();
|
||||
List<StationSn> snList = stationSnService.getSnListByStationId(stationId);
|
||||
String serialNo = "";
|
||||
for (StationSn stationSn : snList) {
|
||||
serialNo = stationSn.getSn();
|
||||
}
|
||||
try {
|
||||
FileInputStream input = new FileInputStream(tarGzFile);
|
||||
MockMultipartFile multipartFile = new MockMultipartFile("file", tarGzFile.getName(), "multipart/form-data", input);
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = fileCenterFeignClient.fileUploadForDevice(multipartFile, stationId, serialNo, FILE_PATH);
|
||||
HeartbeatResp data = heartbeatRespDataResult.getData();
|
||||
List<OrderIssuedVO> list = template.getOrderIssuedReqVO();
|
||||
OrderIssuedReqVO vo = new OrderIssuedReqVO();
|
||||
if( data.getHeartbeatStatus().equals(CommonConstant.ONE) && list != null && list.size() > 0 ){
|
||||
vo.setSn(serialNo);
|
||||
// 进来则表示成功,下发额外的指令
|
||||
vo.setList(list);
|
||||
sendYC(vo);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.FILE_ISSUE_FAIL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.PeakShaving.FILE_ISSUE_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendYC( OrderIssuedReqVO vo ){
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = fileCenterFeignClient.orderIssued(vo);
|
||||
HeartbeatResp data = heartbeatRespDataResult.getData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/policyConfig")
|
||||
@ApiOperation(value = "策略配置")
|
||||
@TokenIgnore
|
||||
public DataResult policyConfig(@RequestBody List<PolicyConfig> policyConfigs){
|
||||
if( policyConfigs == null || policyConfigs.size() == 0 ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
Map<String, Object> result = peakShavingService.policyConfig(policyConfigs);
|
||||
return DataResult.success( result );
|
||||
}
|
||||
|
||||
@PostMapping("/queryPolicyConifgDay")
|
||||
@ApiOperation(value = "策略查询(上面部分,日)")
|
||||
@TokenIgnore
|
||||
public DataResult queryPolicyConifgDay(@RequestBody PolicyConfig policyConfig){
|
||||
if( policyConfig == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
List<PolicyConfigData> policyConfigData = peakShavingService.queryPolicyConifg(policyConfig);
|
||||
return DataResult.success(policyConfigData);
|
||||
}
|
||||
|
||||
@PostMapping("/queryPolicyConifgMonth")
|
||||
@ApiOperation(value = "策略查询(上面部分,月)")
|
||||
@TokenIgnore
|
||||
public DataResult queryPolicyConifgMonth(@RequestBody PolicyConfig policyConfig){
|
||||
if( policyConfig == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
List<PolicyConfig> policyConfigData = peakShavingService.queryPolicyConifgMonth(policyConfig);
|
||||
return DataResult.success(policyConfigData);
|
||||
}
|
||||
|
||||
@PostMapping("queryPlanList")
|
||||
@ApiOperation(value = "查询方案下拉框接口")
|
||||
@TokenIgnore
|
||||
public DataResult queryPlanList(@RequestBody PolicyConfigPlan policyConfigPlan){
|
||||
if( policyConfigPlan == null || policyConfigPlan.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
return DataResult.success(peakShavingService.queryPlanList(policyConfigPlan));
|
||||
}
|
||||
|
||||
@PostMapping("queryPeakPolicyList")
|
||||
@ApiOperation(value = "月下拉框查询接口(计划曲线模板+版本列表整合 用type类型区分)")
|
||||
@TokenIgnore
|
||||
public DataResult queryPeakPolicyList(@RequestBody PolicyConfigPlan policyConfigPlan){
|
||||
if( policyConfigPlan == null || policyConfigPlan.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
return DataResult.success(peakShavingService.queryPeakPolicyList(policyConfigPlan));
|
||||
}
|
||||
|
||||
@PostMapping("generateNewPlan")
|
||||
@ApiOperation(value = "生成新方案接口")
|
||||
@TokenIgnore
|
||||
public DataResult generateNewPlan(@RequestBody PolicyConfigPlanVo vo){
|
||||
// 只有在按日页面才有生成新方案,按月页面只能选择生成出来的方案
|
||||
PolicyConfig policyConfig = vo.getPolicyConfig();
|
||||
if( policyConfig == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
PolicyConfigPlan policyConfigPlan = vo.getPolicyConfigPlan();
|
||||
if( policyConfigPlan == null || policyConfigPlan.getStationId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
policyConfigPlan.setType(0);
|
||||
// 校验名称是否已经存在
|
||||
int i = peakShavingService.checkPlanName(policyConfigPlan);
|
||||
if( i > 0 ){
|
||||
throw new BusinessException(BaseResponseCode.PLAN_NAME_IS_EXISTS);
|
||||
}
|
||||
peakShavingService.generateNewPlan(vo,1);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deletePlan")
|
||||
@ApiOperation(value = "删除方案接口")
|
||||
@TokenIgnore
|
||||
public DataResult deletePlan(@RequestBody PolicyConfigPlan policyConfigPlan){
|
||||
if( policyConfigPlan == null || policyConfigPlan.getId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
peakShavingService.deletePlan(policyConfigPlan);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("queryPolicyConifgDetail")
|
||||
@ApiOperation(value = "查询方案内配置详情接口")
|
||||
@TokenIgnore
|
||||
public DataResult queryPolicyConifgDetail(@RequestBody PolicyConfig policyConfig){
|
||||
if( policyConfig == null || policyConfig.getPlanId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
return DataResult.success(peakShavingService.queryPolicyConifgDetail(policyConfig));
|
||||
}
|
||||
|
||||
@PostMapping("queryHolidayList")
|
||||
@ApiOperation(value = "查询节假日,工作日接口")
|
||||
@TokenIgnore
|
||||
public DataResult queryHolidayList(@RequestBody Holiday holiday){
|
||||
if( holiday == null || holiday.getMonth() == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
return DataResult.success(peakShavingService.queryHolidayList(holiday));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.Picture;
|
||||
import com.ho.business.service.PictureService;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @Description 图片
|
||||
* Author yule
|
||||
* Date 2023/1/4 10:48
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping( "outerApi")
|
||||
public class PictureController {
|
||||
|
||||
@Autowired
|
||||
PictureService pictureService;
|
||||
|
||||
//根据路径新增图片对象数据入库
|
||||
@PostMapping("/addPicture")
|
||||
@LogAnnotation(title = "图片", action = "新增图片对象")
|
||||
@TokenIgnore
|
||||
public Picture addPicture(@RequestBody String url){
|
||||
Picture picture = pictureService.insertPicture(url);
|
||||
return picture;
|
||||
}
|
||||
//根据id查询图片对象
|
||||
@PostMapping("/selectByIdPicture")
|
||||
@TokenIgnore
|
||||
public Picture selectPicture(@RequestBody Integer id){
|
||||
Picture picture = pictureService.selectById(id);
|
||||
return picture;
|
||||
}
|
||||
|
||||
@PostMapping("/deletePicture")
|
||||
@LogAnnotation(title = "图片", action = "删除图片对象")
|
||||
@TokenIgnore
|
||||
public void deletePicture(@RequestBody Integer id){
|
||||
Picture picture = pictureService.selectById(id);
|
||||
//先删除文件
|
||||
File file = new File(picture.getUrl());
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
//在删除数据库中数据
|
||||
pictureService.deletedById(id);
|
||||
}
|
||||
|
||||
@PostMapping("/saveOrUpdatePicture")
|
||||
@LogAnnotation(title = "保存或更新图片", action = "保存或更新图片")
|
||||
@TokenIgnore
|
||||
public Picture saveOrUpdatePicture(@RequestBody Picture vo){
|
||||
Picture picture = pictureService.saveOrUpdatePicture(vo);
|
||||
return picture;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,375 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.*;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.service.PlanningCurveService;
|
||||
import com.ho.business.service.StationSnService;
|
||||
import com.ho.business.vo.resp.planningCurve.PlanningCurveTemplateVo;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.*;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.EasyExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "planning")
|
||||
@Api(tags = "计划曲线")
|
||||
@Slf4j
|
||||
public class PlanningCurveController {
|
||||
|
||||
// 下发文件地址
|
||||
public static final String FILE_PATH = "/deploy/sems/data";
|
||||
|
||||
// 生成的json文件名称
|
||||
public static final String JSON_FILE_NAME = "svc_plantemplate.json";
|
||||
|
||||
// 压缩包保存位置及名称
|
||||
public static final String TAR_GZ_FILE_PATH = "/usr/temporaryFiles/svc_plantemplate.tar.gz";
|
||||
|
||||
@Autowired
|
||||
private PlanningCurveService planningService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
StationSnService stationSnService;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
/**
|
||||
* 查询模板列表接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getPlanningCurveTemplates")
|
||||
@ApiOperation(value = "模板列表查询")
|
||||
@TokenIgnore
|
||||
public DataResult getPlanningCurveTemplates(@RequestBody PlanningCurveTemplate template) {
|
||||
List<Map<String, Object>> planningCurveTemplates = planningService.getPlanningCurveTemplates(template);
|
||||
return DataResult.success(planningCurveTemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面 新增接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addPlanningCurveTemplate")
|
||||
@ApiOperation(value = "新增模板")
|
||||
@LogAnnotation(title = "模板列表查询", action = "新增模板")
|
||||
@TokenIgnore
|
||||
@HzPermission(PermissionConstant.STRATEGY_PLANCURVE_ADD)
|
||||
public DataResult addPlanningCurveTemplate(HttpServletRequest request, @RequestBody PlanningCurveTemplate template) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
if (null != simpleUser && null != template) {
|
||||
template.setGroupId(simpleUser.getGroupId());
|
||||
}
|
||||
Map<String, Object> result = planningService.addPlanningCurveTemplate(template);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面 查看详情接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("planningCurveTemplateDetail")
|
||||
@ApiOperation(value = "查看详情")
|
||||
@TokenIgnore
|
||||
public DataResult planningCurveTemplateDetail(@RequestBody PlanningCurveTemplate template) {
|
||||
if( template == null || template.getTemId() == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = planningService.getPlanningCurveTemplate(template);
|
||||
return DataResult.success(planningCurveTemplates);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("exportPlanningCurveTemplateDetail")
|
||||
@ApiOperation(value = "查看详情")
|
||||
@TokenIgnore
|
||||
public void exportPlanningCurveTemplateDetail(@RequestBody PlanningCurveTemplate template, HttpServletResponse response) {
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = planningService.getPlanningCurveTemplate(template);
|
||||
List<PlanningCurve> planningCurves = planningCurveTemplates.get(0).getPlanningCurves();
|
||||
List<PlanningCurveExport> exportList = new ArrayList<>();
|
||||
for(PlanningCurve planningCurveDetail:planningCurves){
|
||||
PlanningCurveExport planningCurveExport = new PlanningCurveExport();
|
||||
planningCurveExport.setTime(planningCurveDetail.getStartTime()+"--"+planningCurveDetail.getEndTime());
|
||||
planningCurveExport.setP(planningCurveDetail.getP());
|
||||
exportList.add(planningCurveExport);
|
||||
}
|
||||
String fileName = "计划曲线";
|
||||
String sheetName = "计划曲线";
|
||||
try{
|
||||
EasyExcelUtil.writeExcel(response,exportList, fileName, sheetName,PlanningCurveExport.class);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面 编辑接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("modifyPlanningCurveTemplate")
|
||||
@ApiOperation(value = "编辑模板")
|
||||
@LogAnnotation(title = "模板列表查询", action = "编辑模板")
|
||||
@TokenIgnore
|
||||
@HzPermission(PermissionConstant.STRATEGY_PLANCURVE_EDIT)
|
||||
public DataResult modifyPlanningCurveTemplate(@RequestBody PlanningCurveTemplate template) {
|
||||
Map<String, Object> result = planningService.modifyPlanningCurveTemplate(template);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口(支持批量)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("deletePlanningCurveTemplates")
|
||||
@ApiOperation(value = "删除模板")
|
||||
@LogAnnotation(title = "模板列表查询", action = "删除模板")
|
||||
@TokenIgnore
|
||||
@HzPermission(value = {PermissionConstant.STRATEGY_PLANCURVE_DELETE,PermissionConstant.STRATEGY_PLANCURVE_SINGLEDELETE})
|
||||
public DataResult deletePlanningCurveTemplates(@RequestBody List<Integer> ids) {
|
||||
Map<String, Object> result = planningService.deletePlanningCurveTemplates(ids);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
// 导入
|
||||
@PostMapping("uploadData")
|
||||
@ApiOperation(value = "上传文件")
|
||||
@LogAnnotation(title = "模板列表查询", action = "上传文件")
|
||||
@TokenIgnore
|
||||
public DataResult uploadData(HttpServletRequest request, @RequestParam MultipartFile file) {
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
try {
|
||||
if (file != null && file.getSize() > 0) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
result = planningService.batchImport(fileName, file);
|
||||
} else {
|
||||
result.put("code", "400");
|
||||
result.put("msg", DefineConstant.CommonFile.CHOOSE_FILE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.CommonFile.FILE_UPLOAD_ERROR);
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
// 导出
|
||||
|
||||
/**
|
||||
* 导出点表数据
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation(value = "导出计划曲线模板数据")
|
||||
@LogAnnotation(title = "模板列表查询", action = "导出计划曲线模板数据")
|
||||
@TokenIgnore
|
||||
public void exportExcel(@RequestBody PlanningCurveTemplate template, HttpServletResponse response) {
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = planningService.getPlanningCurveTemplate(template);
|
||||
String fileName = "计划曲线模板";
|
||||
// 合并行长度集合
|
||||
List<Integer> exportFieldGroupCountList = new ArrayList<Integer>(0);
|
||||
try {
|
||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
|
||||
List<PlanningCurveTemplateVo> list = new ArrayList<>(0);
|
||||
|
||||
PlanningCurveTemplateVo vo = null;
|
||||
|
||||
// 组装导出数据
|
||||
for (PlanningCurveTemplate planningCurveTemplate : planningCurveTemplates) {
|
||||
List<PlanningCurve> planningCurves = planningCurveTemplate.getPlanningCurves();
|
||||
exportFieldGroupCountList.add(planningCurves.size());
|
||||
for (PlanningCurve planningCurve : planningCurves) {
|
||||
vo = new PlanningCurveTemplateVo();
|
||||
vo.setTemplateNo(planningCurveTemplate.getTemplateNo());
|
||||
vo.setTemplateName(planningCurveTemplate.getTemplateName());
|
||||
vo.setStartTime(planningCurve.getStartTime());
|
||||
vo.setEndTime(planningCurve.getEndTime());
|
||||
vo.setP(planningCurve.getP());
|
||||
vo.setStatus(planningCurveTemplate.getStatus() == 0?"不启用":"启用");
|
||||
vo.setUpdateTime(planningCurveTemplate.getUpdateTime());
|
||||
list.add(vo);
|
||||
}
|
||||
}
|
||||
dataMap.put("list",list);
|
||||
EasyExcelUtil.mergeExport("template/planningCurveTemplate.xlsx", dataMap, fileName, response, exportFieldGroupCountList, Arrays.asList(0,1,5,6));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑页面 查看详情接口
|
||||
*
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("planningCurveTemplateChartData")
|
||||
@ApiOperation(value = "查看详情曲线")
|
||||
@TokenIgnore
|
||||
public DataResult planningCurveTemplateChartData(@RequestBody PlanningCurveTemplate template) {
|
||||
if( template == null || template.getTemId() == null ){
|
||||
return DataResult.success();
|
||||
}
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = planningService.planningCurveTemplateChartData(template);
|
||||
return DataResult.success(planningCurveTemplates);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void wirteFile(String filePath,String json){
|
||||
try (FileWriter writer = new FileWriter(filePath, true)) {
|
||||
writer.write(json);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> compressFileToTarGz(File fileToCompress, File tarGzFile){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
try (FileInputStream fis = new FileInputStream(fileToCompress);
|
||||
FileOutputStream fos = new FileOutputStream(tarGzFile);
|
||||
GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(fos);
|
||||
TarArchiveOutputStream taos = new TarArchiveOutputStream(gzos)) {
|
||||
TarArchiveEntry entry = new TarArchiveEntry(fileToCompress);
|
||||
entry.setSize(fileToCompress.length());
|
||||
taos.putArchiveEntry(entry);
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
taos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
taos.closeArchiveEntry();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.PeakShaving.TAR_FILE_ISSUE_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("planningCurveFile")
|
||||
@ApiOperation(value = "获取计划曲线json文件")
|
||||
@TokenIgnore
|
||||
public DataResult getPlanningCurveJson(HttpServletRequest request,HttpServletResponse response,@RequestBody PlanningTemplateVo template){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
//当前登陆人
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetail = redisService.getUserDetailByToken(token);
|
||||
// 获取到的json字符串
|
||||
String json = planningService.getJson(template, userDetail);
|
||||
// json字符串写出json文件,方便后面压缩
|
||||
wirteFile(JSON_FILE_NAME,json);
|
||||
// 取得json文件
|
||||
File fileToCompress = new File(JSON_FILE_NAME);
|
||||
// 生成一个空的压缩文件
|
||||
File tarGzFile = new File(TAR_GZ_FILE_PATH);
|
||||
// File tarGzFile = new File("D:/svc_plantemplate.tar.gz");
|
||||
|
||||
// 对json文件进行压缩
|
||||
result = compressFileToTarGz(fileToCompress, tarGzFile);
|
||||
|
||||
if( fileToCompress.exists() ){
|
||||
if (fileToCompress.delete()) {
|
||||
System.out.println("临时文件删除成功!");
|
||||
} else {
|
||||
System.out.println("临时文件删除失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("临时文件不存在!");
|
||||
}
|
||||
result = uploadFile(template,tarGzFile);
|
||||
if( tarGzFile.exists() ){
|
||||
if (tarGzFile.delete()) {
|
||||
System.out.println("临时压缩包删除成功!");
|
||||
} else {
|
||||
System.out.println("临时压缩包删除失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("临时压缩包不存在!");
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
private Map<String, Object> uploadFile(PlanningTemplateVo template,File tarGzFile){
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
result.put("code",200);
|
||||
result.put("msg", DefineConstant.PlanningCurve.FILE_ISSUE_SUCCESS);
|
||||
Integer stationId = template.getStationId();
|
||||
List<StationSn> snList = stationSnService.getSnListByStationId(stationId);
|
||||
String serialNo = "";
|
||||
for (StationSn stationSn : snList) {
|
||||
serialNo = stationSn.getSn();
|
||||
}
|
||||
try {
|
||||
FileInputStream input = new FileInputStream(tarGzFile);
|
||||
MockMultipartFile multipartFile = new MockMultipartFile("file", tarGzFile.getName(), "multipart/form-data", input);
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = fileCenterFeignClient.fileUploadForDevice(multipartFile, stationId, serialNo, FILE_PATH);
|
||||
HeartbeatResp data = heartbeatRespDataResult.getData();
|
||||
List<OrderIssuedVO> list = template.getOrderIssuedReqVO();
|
||||
OrderIssuedReqVO vo = new OrderIssuedReqVO();
|
||||
if( data.getHeartbeatStatus().equals(CommonConstant.ONE) && list != null && list.size() > 0 ){
|
||||
vo.setSn(serialNo);
|
||||
// 进来则表示成功,下发额外的指令
|
||||
vo.setList(list);
|
||||
sendYC(vo);
|
||||
} else {
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.PlanningCurve.FILE_ISSUE_FAIL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.PeakShaving.FILE_ISSUE_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendYC( OrderIssuedReqVO vo ){
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = fileCenterFeignClient.orderIssued(vo);
|
||||
HeartbeatResp data = heartbeatRespDataResult.getData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.PlanCurveOperationRecordReq;
|
||||
import com.ho.business.entity.PlanningCurveHistory;
|
||||
import com.ho.business.entity.PlanningIssueDevice;
|
||||
import com.ho.business.service.PlanningCurveIssueService;
|
||||
import com.ho.business.vo.resp.planningCurve.PlanningIssueQueryVo;
|
||||
import com.ho.business.vo.resp.planningCurve.PlanningIssueVo;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "planningIssue")
|
||||
@Api(tags = "计划曲线下发")
|
||||
@Slf4j
|
||||
public class PlanningCurveIssueController {
|
||||
|
||||
@Autowired
|
||||
private PlanningCurveIssueService issueService;
|
||||
|
||||
@PostMapping("getIssueDevices")
|
||||
@ApiOperation(value = "查询下发设备接口")
|
||||
@TokenIgnore
|
||||
public DataResult getIssueDevices(@RequestBody PlanningIssueDevice issueDevice) {
|
||||
return DataResult.success(issueService.getIssueDevices(issueDevice));
|
||||
}
|
||||
|
||||
@PostMapping("getTemplate")
|
||||
@ApiOperation(value = "查询计划曲线模板接口")
|
||||
@TokenIgnore
|
||||
public DataResult getTemplate(@RequestBody PlanningIssueDevice issueDevice) {
|
||||
return DataResult.success(issueService.getTemplate(issueDevice));
|
||||
}
|
||||
|
||||
@PostMapping("getIssueDatas")
|
||||
@ApiOperation(value = "查询下发模型数据")
|
||||
@HzPermission(PermissionConstant.STRATEGY_PLANCURVEDIS_COMMANDISSUANCE)
|
||||
@LogAnnotation(title = "计划曲线下发", action = "命令下发")
|
||||
public DataResult getIssueDatas(@RequestBody PlanningIssueVo issue){
|
||||
List<Map<String, Object>> issueDatas = issueService.getIssueDatas(issue);
|
||||
return DataResult.success(issueDatas);
|
||||
}
|
||||
|
||||
@PostMapping("getPlanCurveIssueData")
|
||||
@ApiOperation(value = "计划曲线投运时间模型数据")
|
||||
@HzPermission(PermissionConstant.STRATEGY_PLANCURVEDIS_COMMANDISSUANCEDATA)
|
||||
@LogAnnotation(title = "计划曲线下发", action = "控制下发")
|
||||
public DataResult getPlanCurveIssueData(@RequestBody PlanningIssueQueryVo issue){
|
||||
List<Map<String, Object>> issueDatas = issueService.getPlanCurveIssueData(issue);
|
||||
return DataResult.success(issueDatas);
|
||||
}
|
||||
|
||||
@PostMapping("insertIssueStatus")
|
||||
@ApiOperation(value = "保存设备下发状态接口")
|
||||
@TokenIgnore
|
||||
public DataResult insertIssueStatus(@RequestBody PlanningIssueDevice issueDevice) {
|
||||
if( issueDevice == null || issueDevice.getPlanTemId() == null ){
|
||||
throw new BusinessException(BaseResponseCode.TEM_NOT_EXISTS);
|
||||
}
|
||||
return DataResult.success(issueService.insertIssueStatus(issueDevice));
|
||||
}
|
||||
|
||||
@PostMapping("queryIssueStatus")
|
||||
@ApiOperation(value = "查看下发状态")
|
||||
@TokenIgnore
|
||||
public DataResult queryIssueStatus(@RequestBody PlanningIssueDevice issueDevice) {
|
||||
return DataResult.success(issueService.queryIssueStatus(issueDevice));
|
||||
}
|
||||
|
||||
@PostMapping("queryCurrentIssue")
|
||||
@ApiOperation(value = "查看正在使用的计划曲线")
|
||||
@TokenIgnore
|
||||
public DataResult queryCurrentIssue(@RequestBody PlanningIssueDevice issue){
|
||||
return DataResult.success(issueService.queryCurrentIssue(issue));
|
||||
}
|
||||
|
||||
@PostMapping("planCurveOperationRecord")
|
||||
@ApiOperation(value = "保存计划曲线下发操作记录")
|
||||
@TokenIgnore
|
||||
public DataResult planCurveOperationRecord(@RequestBody PlanCurveOperationRecordReq planCurveOperationRecordReq){
|
||||
if(planCurveOperationRecordReq.getLatestPlanningCurve() != null){
|
||||
issueService.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("getPlanCurveOperationList")
|
||||
@ApiOperation(value = "查询计划曲线下发操作记录")
|
||||
@TokenIgnore
|
||||
public DataResult<List<PlanCurveOperationRecordReq>> getPlanCurveOperationList(@RequestBody String stationId){
|
||||
List<PlanCurveOperationRecordReq> result = issueService.getPlanCurveOperationList(stationId);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("getPlanningCurveHistory")
|
||||
@ApiOperation(value = "查询操作记录对应计划曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<Map<String,Object>> getPlanningCurveHistory(@RequestBody List<String> planningCurveIds){
|
||||
Map<String,Object> result = issueService.getPlanningCurveHistory(planningCurveIds);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.PlanningCurveTactics;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.business.service.PlanningCurveService;
|
||||
import com.ho.business.service.PlanningCurveTacticsService;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author catkins
|
||||
* @date 2023/10/12 0012 17:33
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "planningTactics")
|
||||
@Api(tags = "计划曲线策略")
|
||||
@Slf4j
|
||||
public class PlanningCurveTacticsController {
|
||||
@Autowired
|
||||
private PlanningCurveTacticsService planningCurveTacticsService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private UserFeignClient userFeignClient;
|
||||
|
||||
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "策略列表查询")
|
||||
@TokenIgnore
|
||||
public DataResult getTacticsList(@RequestBody PlanningCurveTactics tactics) {
|
||||
if( tactics != null && tactics.getPageNum() != null ){
|
||||
tactics.setPageNum(tactics.getPageNum()-1);
|
||||
}
|
||||
List<PlanningCurveTactics> tacticsList = planningCurveTacticsService.getTacticsList(tactics);
|
||||
tacticsList.stream().forEach( t -> {
|
||||
Integer type = t.getType();
|
||||
switch(type){
|
||||
case 1:
|
||||
t.setTypeName("节假日");
|
||||
break;
|
||||
case 2:
|
||||
t.setTypeName("周末");
|
||||
break;
|
||||
default:
|
||||
t.setTypeName("日常");
|
||||
break;
|
||||
}
|
||||
} );
|
||||
return DataResult.success(tacticsList);
|
||||
}
|
||||
|
||||
@PostMapping("details")
|
||||
@ApiOperation(value = "策略查看详情")
|
||||
@TokenIgnore
|
||||
public DataResult getTacticsDetails(@RequestBody PlanningCurveTactics tactics) {
|
||||
PlanningCurveTactics tacticsDetails = planningCurveTacticsService.getTacticsDetails(tactics);
|
||||
return DataResult.success(tacticsDetails);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增")
|
||||
@TokenIgnore
|
||||
public DataResult add(HttpServletRequest request,@RequestBody PlanningCurveTactics tactics) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
SysUser user = null;
|
||||
if( simpleUser != null ){
|
||||
DataResult<SysUser> userById = userFeignClient.getUserById(simpleUser.getUserId());
|
||||
user = userById.getData();
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PARSE_ERROR);
|
||||
}
|
||||
if( tactics != null && user != null ){
|
||||
tactics.setCreator(user.getUsername());
|
||||
}
|
||||
planningCurveTacticsService.add(tactics);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("modify")
|
||||
@ApiOperation(value = "修改")
|
||||
@TokenIgnore
|
||||
public DataResult modify(HttpServletRequest request,@RequestBody PlanningCurveTactics tactics) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
SysUser user = null;
|
||||
if( simpleUser != null ){
|
||||
DataResult<SysUser> userById = userFeignClient.getUserById(simpleUser.getUserId());
|
||||
user = userById.getData();
|
||||
//user = userFeignClient.getUserById(simpleUser.getUserId());
|
||||
}
|
||||
if( tactics != null ){
|
||||
tactics.setModifier(user.getUsername());
|
||||
}
|
||||
planningCurveTacticsService.modify(tactics);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除")
|
||||
@TokenIgnore
|
||||
public DataResult delete(@RequestBody PlanningCurveTactics tactics) {
|
||||
planningCurveTacticsService.delete(tactics);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("getPlanningCurveTemplates")
|
||||
@ApiOperation(value = "查询下拉框数据")
|
||||
@TokenIgnore
|
||||
public DataResult getPlanningCurveTemplates(@RequestBody PlanningCurveTactics tactics){
|
||||
List<PlanningCurveTactics> tacticsList = planningCurveTacticsService.getPlanningCurveTemplates(tactics);
|
||||
return DataResult.success(tacticsList);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,320 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.WriteTable;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.ho.business.entity.DropDownVo;
|
||||
import com.ho.business.entity.PlanningCurveTemplate;
|
||||
import com.ho.business.entity.PlanningPolicy;
|
||||
import com.ho.business.service.PlanningPolicyService;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.DefineConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.EasyExcelUtil;
|
||||
import com.ho.common.tools.util.SelectSheetWriteHandler;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "policy")
|
||||
@Api(tags = "计划曲线策略")
|
||||
@Slf4j
|
||||
public class PlanningPolicyController {
|
||||
|
||||
@Autowired
|
||||
private PlanningPolicyService policyService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
private final String REDIS_KEY = "PLANNING_POLICY";
|
||||
|
||||
private final List<String> HEAD_LIST = Arrays.asList("策略类型","名称","自定义策略名称","自定义策略开始时间","自定义策略结束时间","计划曲线模板","策略优先级","生效类型","生效开始时间","生效结束时间","是否启用","描述");
|
||||
|
||||
public static final Map<Integer, String> EFFECTIVE_TYPE = new HashMap<Integer, String>() {{
|
||||
put(0, "永久生效");
|
||||
put(1, "时间段内生效");
|
||||
}};
|
||||
|
||||
/**
|
||||
* 策略列表查询
|
||||
*
|
||||
* @param policy
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getPlanningPolicys")
|
||||
@ApiOperation(value = "策略列表查询")
|
||||
//@TokenIgnore
|
||||
public DataResult getPlanningPolicys(@RequestBody(required = false) PlanningPolicy policy) {
|
||||
return DataResult.success(policyService.getPlanningPolicys(policy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 策略详情查询(编辑
|
||||
*
|
||||
* @param policy
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getPlanningPolicyDetail4Modify")
|
||||
@ApiOperation(value = "策略详情查询(详情按钮、编辑)")
|
||||
//@TokenIgnore
|
||||
public DataResult getPlanningPolicyDetail4Modify(@RequestBody PlanningPolicy policy) {
|
||||
return DataResult.success(policyService.getPlanningPolicyDetail4Modify(policy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增策略
|
||||
*
|
||||
* @param policy
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addPlanningPolicy")
|
||||
@ApiOperation(value = "新增策略")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "新增策略")
|
||||
//@TokenIgnore
|
||||
public DataResult addPlanningPolicy(@RequestBody PlanningPolicy policy) {
|
||||
return DataResult.success(policyService.addPlanningPolicy(policy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑策略
|
||||
*
|
||||
* @param policy
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("modifyPlanningPolicy")
|
||||
@ApiOperation(value = "编辑策略")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "编辑策略")
|
||||
//@TokenIgnore
|
||||
public DataResult modifyPlanningPolicy(@RequestBody PlanningPolicy policy) {
|
||||
return DataResult.success(policyService.modifyPlanningPolicy(policy));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除策略
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("deletePlanningPolicy")
|
||||
@ApiOperation(value = "删除策略")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "删除策略")
|
||||
//@TokenIgnore
|
||||
public DataResult deletePlanningPolicy(@RequestBody List<Integer> ids) {
|
||||
return DataResult.success(policyService.deletePlanningPolicy(ids));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("queryPolicyTypes")
|
||||
@ApiOperation(value = "查询策略类型列表")
|
||||
//@TokenIgnore
|
||||
public DataResult queryPolicyTypes() {
|
||||
List<DropDownVo> vo = null;
|
||||
if (redisService.hasKey(REDIS_KEY + "TYPE")) {
|
||||
vo = (List<DropDownVo>) redisService.get(REDIS_KEY + "TYPE");
|
||||
} else {
|
||||
vo = policyService.queryPolicyTypes();
|
||||
redisService.set(REDIS_KEY + "TYPE", vo, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
return DataResult.success(vo);
|
||||
}
|
||||
|
||||
@PostMapping("queryPolicyPriority")
|
||||
@ApiOperation(value = "查询策略优先级列表")
|
||||
//@TokenIgnore
|
||||
public DataResult queryPolicyPriority() {
|
||||
List<DropDownVo> vo = null;
|
||||
if (redisService.hasKey(REDIS_KEY + "PRIORITY")) {
|
||||
vo = (List<DropDownVo>) redisService.get(REDIS_KEY + "PRIORITY");
|
||||
} else {
|
||||
vo = policyService.queryPolicyPriority();
|
||||
redisService.set(REDIS_KEY + "PRIORITY", vo, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
return DataResult.success(vo);
|
||||
}
|
||||
|
||||
// 导入
|
||||
@PostMapping("uploadData")
|
||||
@ApiOperation(value = "导入文件")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "导入文件")
|
||||
//@TokenIgnore
|
||||
public DataResult uploadData(HttpServletRequest request, @RequestParam MultipartFile file,Integer stationId) {
|
||||
Map<String, Object> result = new HashMap<String, Object>(0);
|
||||
try {
|
||||
if (file != null && file.getSize() > 0) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
result = policyService.batchImport(fileName, file,stationId);
|
||||
} else {
|
||||
result.put("code", "400");
|
||||
result.put("msg", DefineConstant.CommonFile.CHOOSE_FILE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", DefineConstant.CommonFile.FILE_UPLOAD_ERROR);
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping(value="/exportTemplate",produces = {MediaType.APPLICATION_STREAM_JSON_VALUE})
|
||||
@ApiOperation(value = "导出计划曲线策略模板")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "导出计划曲线策略模板")
|
||||
//@TokenIgnore
|
||||
public void exportTemplate(@RequestBody PlanningPolicy policy, HttpServletResponse response){
|
||||
String templateName = "策略模板";
|
||||
ServletOutputStream out = null;
|
||||
ZipOutputStream zipOutputStream = null;
|
||||
try {
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + URLEncoder.encode(templateName, "UTF-8"));
|
||||
|
||||
out = response.getOutputStream();
|
||||
zipOutputStream = new ZipOutputStream(out);
|
||||
// 定义表头
|
||||
List<List<String>> headList = new ArrayList<>();
|
||||
List<String> temporaryList = null;
|
||||
//headList.add(HEAD_LIST);
|
||||
for (String s : HEAD_LIST) {
|
||||
temporaryList = new ArrayList<>();
|
||||
temporaryList.add(s);
|
||||
headList.add(temporaryList);
|
||||
}
|
||||
|
||||
// 定义数据体
|
||||
List<Object> dataList = new ArrayList<>();
|
||||
|
||||
HashMap<Integer, List<String>> dropDownMap = new HashMap<>();
|
||||
|
||||
// 策略类型、策略级别数据集
|
||||
List<DropDownVo> vo = null;
|
||||
|
||||
List<String> datas = new ArrayList<>(0);
|
||||
|
||||
// 下拉框数据(策略类型)
|
||||
if (redisService.hasKey(REDIS_KEY + "TYPE")) {
|
||||
vo = (List<DropDownVo>) redisService.get(REDIS_KEY + "TYPE");
|
||||
} else {
|
||||
vo = policyService.queryPolicyTypes();
|
||||
}
|
||||
for (DropDownVo dropDownVo : vo) {
|
||||
datas.add(dropDownVo.getName());
|
||||
}
|
||||
// 存储需要下拉框的值,这里的key是需要设置为下拉框的列数,value是下拉框的值,是list
|
||||
if (datas != null && datas.size() > 0) {
|
||||
dropDownMap.put(0, datas);
|
||||
}
|
||||
|
||||
// 下拉框数据(计划曲线模板)
|
||||
List<PlanningCurveTemplate> planningCurveTemplates = policyService.getPlanningCurveTemplates(policy.getStationId());
|
||||
datas = new ArrayList<>(0);
|
||||
for (PlanningCurveTemplate planningCurveTemplate : planningCurveTemplates) {
|
||||
datas.add(planningCurveTemplate.getTemplateName());
|
||||
}
|
||||
// 存储需要下拉框的值,这里的key是需要设置为下拉框的列数,value是下拉框的值,是list
|
||||
if (datas != null && datas.size() > 0) {
|
||||
dropDownMap.put(5, datas);
|
||||
}
|
||||
|
||||
// 下拉框数据(策略级别)
|
||||
datas = new ArrayList<>(0);
|
||||
if (redisService.hasKey(REDIS_KEY + "PRIORITY")) {
|
||||
vo = (List<DropDownVo>) redisService.get(REDIS_KEY + "PRIORITY");
|
||||
} else {
|
||||
vo = policyService.queryPolicyPriority();
|
||||
}
|
||||
for (DropDownVo dropDownVo : vo) {
|
||||
datas.add(dropDownVo.getName());
|
||||
}
|
||||
// 存储需要下拉框的值,这里的key是需要设置为下拉框的列数,value是下拉框的值,是list
|
||||
if (datas != null && datas.size() > 0) {
|
||||
dropDownMap.put(6, datas);
|
||||
}
|
||||
|
||||
datas = new ArrayList<>(0);
|
||||
datas.add("永久生效");
|
||||
datas.add("时间段内生效");
|
||||
dropDownMap.put(7, datas);
|
||||
|
||||
datas = new ArrayList<>(0);
|
||||
datas.add("启用");
|
||||
datas.add("不启用");
|
||||
dropDownMap.put(10, datas);
|
||||
|
||||
ExcelWriter excelWriter = EasyExcel.write().excelType(ExcelTypeEnum.XLS).build();
|
||||
//构建一个sheet页
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
|
||||
// 头的策略
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
// 单元格策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
// 初始化表格样式
|
||||
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
|
||||
// 是设置下拉框的类
|
||||
new SelectSheetWriteHandler(dropDownMap);
|
||||
WriteTable writeTable = EasyExcel.writerTable(0).head(headList).registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new SelectSheetWriteHandler(dropDownMap)).needHead(Boolean.TRUE).build();
|
||||
excelWriter.write(dataList, writeSheet, writeTable);
|
||||
// 开始导出
|
||||
Workbook workbook = excelWriter.writeContext().writeWorkbookHolder().getWorkbook();
|
||||
//创建压缩文件
|
||||
ZipEntry zipEntry = new ZipEntry("策略模板.xls");
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
//将excel对象以流的形式写入压缩流
|
||||
workbook.write(zipOutputStream);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
zipOutputStream.flush();
|
||||
zipOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation("导出计划曲线策略")
|
||||
@LogAnnotation(title = "计划曲线策略", action = "导出计划曲线策略")
|
||||
//@TokenIgnore
|
||||
public void exportExcel(@RequestBody PlanningPolicy policy,HttpServletResponse response) {
|
||||
String fileName = "计划曲线策略";
|
||||
String sheetName = "计划曲线策略";
|
||||
try {
|
||||
List<PlanningPolicy> planningPolicys = policyService.getPlanningPolicys(policy);
|
||||
EasyExcelUtil.writeExcel(response, planningPolicys, fileName, sheetName, PlanningPolicy.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,504 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.*;
|
||||
import com.ho.business.service.*;
|
||||
import com.ho.business.vo.req.ColDetailsReqVo;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.req.device.DeviceStationReqVo;
|
||||
import com.ho.business.vo.req.oneClickSequentialControl.OneClickSequentialControlQueryReq;
|
||||
import com.ho.business.vo.req.point.*;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.point.*;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.*;
|
||||
import com.ho.common.tools.entity.PointCurveSrcCol;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.*;
|
||||
import com.ho.common.tools.vo.req.PointData;
|
||||
import com.ho.common.tools.vo.req.StationHomeRespVo;
|
||||
import com.ho.common.tools.vo.req.StatisticsCurve;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 点表
|
||||
* Author yule
|
||||
* Date 2022/10/13 11:35
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "point")
|
||||
@Api(tags = "一体柜点表模块")
|
||||
@Slf4j
|
||||
public class PointDemoController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
PointDemoService pointDemoService;
|
||||
|
||||
@Autowired
|
||||
ModelDeviceService modelDeviceService;
|
||||
|
||||
@Autowired
|
||||
ColDetailsService colDetailsService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
StationSnService stationSnService;
|
||||
|
||||
@Autowired
|
||||
DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
@Autowired
|
||||
DeviceCallService deviceCallService;
|
||||
|
||||
@ApiOperation(value = "一体柜设备下拉列表,不分页")
|
||||
@PostMapping("findIntegratedCabinets")
|
||||
public DataResult<List<PointDeviceResp>> findIntegratedCabinets(@RequestBody DeviceStationReqVo deviceTypeReq) {
|
||||
//将数据转为PointDeviceResp对象
|
||||
List<PointDeviceResp> targetList = new ArrayList<>();
|
||||
//只查询在设备类型配置表中做配置的
|
||||
//先查设备类型
|
||||
List<String> deviceTypes = deviceTypeConfigService.getStationDeviceTypes(deviceTypeReq.getStationId());
|
||||
//设备类型配置表中没有定义,就返回空数据
|
||||
if (deviceTypes.isEmpty()) {
|
||||
log.info("设备类型表尚未配置设备类型");
|
||||
return DataResult.success(targetList);
|
||||
}
|
||||
//查设备
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(deviceTypeReq.getStationId());
|
||||
deviceReqVO.setDeviceTypeList(deviceTypes);
|
||||
deviceReqVO.setNeedFilter(CommonConstant.ONE);
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
for (DeviceRespVO deviceRespVO : deviceList) {
|
||||
PointDeviceResp pointDevice = new PointDeviceResp();
|
||||
pointDevice.setStationId(deviceRespVO.getStationId());
|
||||
pointDevice.setSrcId(deviceRespVO.getSrcId());
|
||||
pointDevice.setDeviceName(deviceRespVO.getDeviceName());
|
||||
pointDevice.setDeviceType(deviceRespVO.getDeviceType());
|
||||
targetList.add(pointDevice);
|
||||
}
|
||||
return DataResult.success(targetList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "树状结构设备")
|
||||
@PostMapping("treeDevices")
|
||||
public DataResult<List<DevicePointResp>> findTreeDevices(@RequestBody DeviceStationReqVo deviceTypeReq) {
|
||||
List<DeviceRespVO> deviceRespVOS = deviceCallService.selectByIdAndSrcIdNotZero(deviceTypeReq.getStationId());
|
||||
List<DevicePointResp> treeDevices = new ArrayList<>();
|
||||
if (!deviceRespVOS.isEmpty()) {
|
||||
treeDevices = deviceTypeConfigService.getTreeDevices(deviceRespVOS);
|
||||
}
|
||||
return DataResult.success(treeDevices);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "点表列表,分页")
|
||||
public DataResult<PageResult<PointRespVO>> page(@RequestBody @Valid PointReq pointReq) {
|
||||
String name = pointReq.getName();
|
||||
if (name != null) {
|
||||
name = name.trim();
|
||||
pointReq.setName(name);
|
||||
}
|
||||
List<PointRespVO> pointList = pointDemoService.getPointList(pointReq);
|
||||
//java内存分页
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!pointList.isEmpty()) {
|
||||
List list = PageUtils.dealList(pointList, pointReq.getPageNum(), pointReq.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(pointList.size());
|
||||
pageResult.setTotalPages(pointList.size() / pointReq.getPageSize() + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
@PostMapping("getPointList")
|
||||
@ApiOperation(value = "点表列表(可控点)")
|
||||
public DataResult<List<PointRespVO>> getPointList(@RequestBody @Valid PointReq pointReq) {
|
||||
String name = pointReq.getName();
|
||||
if (name != null) {
|
||||
name = name.trim();
|
||||
pointReq.setName(name);
|
||||
}
|
||||
pointReq.setIsSave(1);
|
||||
List<PointRespVO> pointList = pointDemoService.getPointList(pointReq);
|
||||
return DataResult.success(pointList);
|
||||
}
|
||||
|
||||
@PostMapping("pointList")
|
||||
@ApiOperation(value = "点表列表,不分页")
|
||||
public DataResult<List<PointListRespVo>> pointList(@RequestBody @Valid PointReq pointReq) {
|
||||
String name = pointReq.getName();
|
||||
if (name != null) {
|
||||
name = name.trim();
|
||||
pointReq.setName(name);
|
||||
}
|
||||
List<PointListRespVo> pointList = pointDemoService.pointList(pointReq);
|
||||
return DataResult.success(pointList);
|
||||
}
|
||||
|
||||
@PostMapping("queryPoint")
|
||||
@ApiOperation(value = "根据设备查询点表")
|
||||
public DataResult<List<QueryPointRespVo>> queryPoint(@RequestBody @Valid PointVo vo) {
|
||||
List<QueryPointRespVo> pointList = pointDemoService.queryPoint(vo);
|
||||
return DataResult.success(pointList);
|
||||
}
|
||||
|
||||
@PostMapping("queryVirtualPoint")
|
||||
@ApiOperation(value = "根据设备查询虚拟点表")
|
||||
public DataResult<List<QueryPointRespVo>> queryVirtualPoint(@RequestBody @Valid PointVo vo) {
|
||||
List<QueryPointRespVo> pointList = pointDemoService.queryVirtualPoint(vo);
|
||||
return DataResult.success(pointList);
|
||||
}
|
||||
|
||||
@PostMapping("queryControlPoint")
|
||||
@ApiOperation(value = "查询可配置顺控点")
|
||||
public DataResult<List<PointRespVO>> queryControlPoint(@RequestBody @Valid OneClickSequentialControlQueryReq vo) {
|
||||
List<PointRespVO> pointList = pointDemoService.queryControlPoint(vo);
|
||||
return DataResult.success(pointList);
|
||||
}
|
||||
|
||||
@PostMapping("updateOne")
|
||||
@ApiOperation(value = "更新数据")
|
||||
@LogAnnotation(title = "一体柜点表模块", action = "更新数据")
|
||||
//@HzPermission(value = PermissionConstant.REMOTECONTROL_COMMAND_SINGLEREFRESH)
|
||||
public DataResult<PointRespVO> updateOne(@RequestBody @Valid PointOneReq pointReq) {
|
||||
PointRespVO point = pointDemoService.getPointRespVO(pointReq);
|
||||
return DataResult.success(point);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("getSN")
|
||||
@ApiIgnore
|
||||
@ApiOperation(value = "获取电站下面所有的sn")
|
||||
public DataResult<List<StationSn>> getSN(@RequestBody @Valid PointReqVO pointReq) {
|
||||
//根据每一个设备从缓存中拿数据
|
||||
List<StationSn> stationSnList = stationSnService.getSnListByStationId(pointReq.getStationId());
|
||||
return DataResult.success(stationSnList);
|
||||
}
|
||||
|
||||
@PostMapping("getDeviceSN")
|
||||
@ApiOperation(value = "获取对应设备下面的sn")
|
||||
public DataResult<List<DeviceRespVO>> getDeviceSN(@RequestBody @Valid PointReqVO pointReq) {
|
||||
//根据每一个设备从缓存中拿数据
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(pointReq.getStationId());
|
||||
deviceReqVO.setSrcId(pointReq.getSrcId());
|
||||
List<DeviceRespVO> deviceList = deviceService.getList(deviceReqVO);
|
||||
return DataResult.success(deviceList);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@PostMapping("device")
|
||||
public int Devices(@RequestBody Device device) {
|
||||
int i = deviceService.insertSelective(device);
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出点表数据
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/exportExcel")
|
||||
@LogAnnotation(title = "一体柜点表模块", action = "导出点表数据")
|
||||
//@HzPermission(value = {PermissionConstant.REMOTECONTROL_COMMAND_EXPORT,PermissionConstant.DATA_SHOW_EXPORT,PermissionConstant.REMOTECONTROL_COMMAND_EXPORT})
|
||||
public void exportExcel(@RequestBody @Valid PointReq pointReq, HttpServletResponse response) {
|
||||
List<PointRespVO> pointList = pointDemoService.getPointList(pointReq);
|
||||
|
||||
String fileName = "点表";
|
||||
String sheetName = "data";
|
||||
try {
|
||||
EasyExcelUtil.writeExcel(response, pointList, fileName, sheetName, PointRespVO.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出历史数据
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@PostMapping("/hisExportExcel")
|
||||
@LogAnnotation(title = "一体柜点表模块", action = "导出历史数据")
|
||||
@HzPermission(PermissionConstant.DATA_HISCURVE_EXPORT)
|
||||
public void hisExportExcel(@RequestBody @Valid PointCurveReq pointCurveReq, HttpServletResponse response) {
|
||||
pointDemoService.getHisExportExcel(pointCurveReq, response);
|
||||
}
|
||||
|
||||
@PostMapping("pointCurve")
|
||||
@ApiOperation(value = "点表曲线")
|
||||
public DataResult<List<PointCurveResp>> pointCurve(@RequestBody @Valid PointCurveReq pointCurveReq) {
|
||||
List<PointCurveResp> pointCurveRespList = new ArrayList<>();
|
||||
//对开始结束时间进行处理 (对bug129)
|
||||
if (pointCurveReq.getBeginTime() != null) {
|
||||
pointCurveReq.setBeginTime(pointCurveReq.getBeginTime().substring(0, pointCurveReq.getBeginTime().length() - 1) + "1");
|
||||
}
|
||||
if (pointCurveReq.getEndTime() != null) {
|
||||
pointCurveReq.setEndTime(pointCurveReq.getEndTime().substring(0, pointCurveReq.getEndTime().length() - 1) + "1");
|
||||
}
|
||||
//对传输过来的col集合进行判断是否大于10个
|
||||
if (pointCurveReq.getDeviceIdList() != null && pointCurveReq.getDeviceIdList().size() < 50) {
|
||||
pointCurveRespList = pointDemoService.getPointCurve(pointCurveReq);
|
||||
}
|
||||
for (PointCurveResp pointCurveResp : pointCurveRespList) {
|
||||
List<StatisticsCurve> staticCurveList = pointCurveResp.getStaticCurveList();
|
||||
for (StatisticsCurve statisticsRespVO : staticCurveList) {
|
||||
if (null != statisticsRespVO.getDigital()) {
|
||||
statisticsRespVO.setDigital(NumberUtil.round(statisticsRespVO.getDigital(), 2).doubleValue());
|
||||
}
|
||||
}
|
||||
if (pointCurveReq.getIsStrategy() != null && pointCurveReq.getIsStrategy() == 1) {
|
||||
if (!staticCurveList.isEmpty() && staticCurveList.size() < 1440) {
|
||||
int count = 1440 - staticCurveList.size();
|
||||
String date = staticCurveList.get(staticCurveList.size() - 1).getDate();
|
||||
for (int i = 0; i < count; i++) {
|
||||
StatisticsCurve statisticsCurve = new StatisticsCurve();
|
||||
statisticsCurve.setDigital(null);
|
||||
DateTime offset = DateUtil.offset(DateUtil.parse(date, CommonConstant.DATE), DateField.MINUTE, i + 1);
|
||||
statisticsCurve.setDate(DateUtil.format(offset, CommonConstant.DATE));
|
||||
staticCurveList.add(statisticsCurve);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//判断是否为策略总览页面查询
|
||||
if (pointCurveReq.getIsStrategy() != null && pointCurveReq.getIsStrategy() == 1) {
|
||||
PointCurveResp pointCurveResp = pointDemoService.getPlanCurve(pointCurveReq.getStationId());
|
||||
if (pointCurveResp != null) {
|
||||
pointCurveRespList.add(pointCurveResp);
|
||||
}
|
||||
}
|
||||
int size = pointCurveRespList.size();
|
||||
pointCurveRespList = pointCurveRespList.stream().sorted((x, y) -> {
|
||||
if (x.getSrcId() == null || y.getSrcId() == null) {
|
||||
return size;
|
||||
} else {
|
||||
return x.getSrcId() - y.getSrcId();
|
||||
}
|
||||
|
||||
}).collect(Collectors.toList());
|
||||
return DataResult.success(pointCurveRespList);
|
||||
}
|
||||
|
||||
@PostMapping("pointDataShow")
|
||||
@ApiOperation(value = "点表数据展示")
|
||||
public DataResult<PageResult<List<Object>>> pointDataShow(@RequestBody @Valid PointCurveReq pointCurveReq) {
|
||||
PageResult<List<Object>> pointCurveRespList = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
//对传输过来的col集合进行判断是否大于10个
|
||||
if (pointCurveReq.getDeviceIdList().size() < 50) {
|
||||
pointCurveRespList = pointDemoService.pointDataShow(pointCurveReq);
|
||||
}
|
||||
return DataResult.success(pointCurveRespList);
|
||||
}
|
||||
|
||||
@PostMapping("pointDataShowList")
|
||||
@ApiOperation(value = "点表真实数据展示(每个点位分开)")
|
||||
public DataResult<List<PageResult>> pointDataShowList(@RequestBody @Valid PointCurveReq pointCurveReq) {
|
||||
List<PageResult> pointCurveRespList = new ArrayList<>();
|
||||
//对传输过来的col集合进行判断是否大于10个
|
||||
if (pointCurveReq.getDeviceIdList().size() < 50) {
|
||||
pointCurveRespList = pointDemoService.pointDataShowList(pointCurveReq);
|
||||
}
|
||||
return DataResult.success(pointCurveRespList);
|
||||
}
|
||||
|
||||
@PostMapping("colHistoricalDetails")
|
||||
@ApiOperation(value = "点表col字段历史数据展示")
|
||||
public DataResult<List<PointData>> colHistoricalDetails(@RequestBody @Valid ColDetailsReqVo colDetailsReqVo) {
|
||||
List<PointData> list = colDetailsService.getColCurve(colDetailsReqVo);
|
||||
for (PointData pointData : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(pointData);
|
||||
bigDecimalUtil.ifIsNUll(pointData);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("colHistoricalList")
|
||||
@ApiOperation(value = "点表col字段历史数据列表展示")
|
||||
public DataResult<PageResult<StationHomeRespVo>> colHistoricalList(@RequestBody @Valid ColDetailsReqVo colDetailsReqVo) {
|
||||
PageResult<StationHomeRespVo> list = new PageResult<>();
|
||||
list = colDetailsService.getColList(colDetailsReqVo);
|
||||
if (list.getList() != null) {
|
||||
for (StationHomeRespVo stationHomeRespVo : list.getList()) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationHomeRespVo);
|
||||
bigDecimalUtil.ifIsNUll(stationHomeRespVo);
|
||||
}
|
||||
}
|
||||
list.setList(list.getList());
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("beforeQueryPoint")
|
||||
@ApiOperation(value = "默认查点表的输入条件查询")
|
||||
public DataResult<BeforeQueryPointResp> beforeQueryPoint(@RequestBody @Valid StationReq stationReq) {
|
||||
Integer stationId = stationReq.getStationId();
|
||||
BeforeQueryPointResp beforeQueryPointResp = new BeforeQueryPointResp();
|
||||
//先查询第一个PCS设备
|
||||
List<DeviceRespVO> listByDeviceType = deviceService.getListByDeviceType(stationId, DeviceTypeConstant.PCS);
|
||||
beforeQueryPointResp.setHasPcs(false);
|
||||
if (listByDeviceType.isEmpty()) {
|
||||
return DataResult.success(beforeQueryPointResp);
|
||||
}
|
||||
DeviceRespVO device = listByDeviceType.get(0);
|
||||
beforeQueryPointResp.setSrcId(device.getSrcId());
|
||||
|
||||
//9个指标,得转换为映射的deviceCol
|
||||
List<String> cols = Arrays.asList("activeAPower", "activeBPower", "activeCPower",
|
||||
"currentA", "currentB", "currentC",
|
||||
"volA", "volB", "volC");
|
||||
List<String> refCols = new ArrayList<>();
|
||||
for (String col : cols) {
|
||||
String deviceCol = getDeviceCol(device.getDeviceType(), col);
|
||||
if (deviceCol != null) {
|
||||
refCols.add(deviceCol);
|
||||
}
|
||||
}
|
||||
if (!refCols.isEmpty()) {
|
||||
beforeQueryPointResp.setHasPcs(true);
|
||||
}
|
||||
beforeQueryPointResp.setCols(refCols);
|
||||
//默认生成一个昨天到今天的时间跨度
|
||||
Date now = new Date();
|
||||
DateTime dateTime = DateUtil.offsetDay(now, -1);
|
||||
String beginTime = DateUtil.format(dateTime, CommonConstant.DATE);
|
||||
String endTime = DateUtil.format(now, CommonConstant.DATE);
|
||||
|
||||
beforeQueryPointResp.setBeginTime(beginTime);
|
||||
beforeQueryPointResp.setEndTime(endTime);
|
||||
return DataResult.success(beforeQueryPointResp);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "返回一个存在点表的设备id(命令下发界面专用)")
|
||||
@PostMapping("beforeOrderSend")
|
||||
public DataResult<BeforeSendOrderResp> beforeOrderSend(@RequestBody StationReq stationReq) {
|
||||
BeforeSendOrderResp beforeSendOrderResp = deviceService.beforeOrderSend(stationReq);
|
||||
return DataResult.success(beforeSendOrderResp);
|
||||
}
|
||||
|
||||
//字段映射
|
||||
private String getDeviceCol(String deviceType, String modelCol) {
|
||||
String colReflex = null;
|
||||
List<ModelDeviceColComp> cIaCompList = modelDeviceService.getCompListByType("device", deviceType, modelCol);
|
||||
if (!cIaCompList.isEmpty()) {
|
||||
ModelDeviceColComp cIaModelDeviceCol = cIaCompList.get(0);
|
||||
String deviceCol = cIaModelDeviceCol.getDeviceCol();
|
||||
log.info("deviceCol:" + deviceCol);
|
||||
colReflex = deviceCol;
|
||||
}
|
||||
return colReflex;
|
||||
}
|
||||
|
||||
@PostMapping("getPointCurve")
|
||||
@ApiOperation(value = "首页根据映射值获取曲线(app界面使用)")
|
||||
public DataResult<List<PointCurveResp>> getPointCurve(@RequestBody HomePageReqVo vo) {
|
||||
PointCurveReq pointCurveReq = pointDemoService.getPointCurveReq(vo);
|
||||
List<PointCurveResp> pointCurveRespList = pointCurve(pointCurveReq).getData();
|
||||
List<PointCurveSrcCol> deviceIdList = pointCurveReq.getDeviceIdList();
|
||||
if (!deviceIdList.isEmpty()) {
|
||||
Map<String, BigDecimal> map = deviceIdList.get(0).getMap();
|
||||
if (map != null) {
|
||||
BigDecimal factor;
|
||||
for (PointCurveResp p : pointCurveRespList) {
|
||||
factor = map.get(p.getCol());
|
||||
if (null != factor) {
|
||||
List<StatisticsCurve> staticCurveList = p.getStaticCurveList();
|
||||
for (StatisticsCurve curve : staticCurveList) {
|
||||
if (curve.getDigital() != null) {
|
||||
curve.setDigital(new BigDecimal(curve.getDigital()).multiply(factor).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(pointCurveRespList);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
UserHabitService userHabitService;
|
||||
|
||||
@PostMapping("addUserHabit")
|
||||
@ApiOperation(value = "增加用户习惯")
|
||||
public DataResult addUserHabit(@RequestBody UserHabitReqVo vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
UserHabit userHabit = new UserHabit();
|
||||
userHabit.setUserId(user.getUserId());
|
||||
userHabit.setUserData(vo.getDeviceJson().toJSONString());
|
||||
userHabitService.insertUserHabit(userHabit);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("updateUserHabit")
|
||||
@ApiOperation(value = "更新用户习惯")
|
||||
public DataResult updateUserHabit(@RequestBody UserHabitReqVo vo) {
|
||||
UserHabit userHabit = new UserHabit();
|
||||
userHabit.setId(vo.getId());
|
||||
userHabit.setUserData(vo.getDeviceJson().toString());
|
||||
userHabitService.updateById(userHabit);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("queryUserHabit")
|
||||
@ApiOperation(value = "查询用户习惯")
|
||||
public DataResult<UserHabitRespVo> queryUserHabit(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
UserHabit userHabit = userHabitService.selectByUserId(user.getUserId());
|
||||
UserHabitRespVo userHabitRespVo = null;
|
||||
if (null != userHabit) {
|
||||
userHabitRespVo = new UserHabitRespVo();
|
||||
String userData = userHabit.getUserData();
|
||||
JSONArray objects = JSONArray.parseArray(userData);
|
||||
userHabitRespVo.setDeviceJson(objects);
|
||||
userHabitRespVo.setId(userHabit.getId());
|
||||
}
|
||||
return DataResult.success(userHabitRespVo);
|
||||
}
|
||||
|
||||
@PostMapping("modifyHistoryData")
|
||||
@ApiOperation(value = "更改历史值")
|
||||
@HzPermission(PermissionConstant.MODIFY_HISTORY_DATA)
|
||||
public DataResult modifyHistoryData(@RequestBody PointCurveReq pointCurveReq) {
|
||||
pointDemoService.modifyHistoryData(pointCurveReq);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,183 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.feignclient.FileCenterFeignClient;
|
||||
import com.ho.business.service.CockpitService;
|
||||
import com.ho.business.service.ReallyCockpitService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.vo.resp.StationRespVO;
|
||||
import com.ho.business.vo.resp.cockpit.*;
|
||||
import com.ho.common.tools.annotation.LargeScreenToken;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.EnvConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.util.IPUtils;
|
||||
import com.ho.common.tools.vo.req.WeatherReq;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 驾驶舱的真实数据界面
|
||||
* Author yule
|
||||
* Date 2023/4/12 13:47
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "reallyCockpit")
|
||||
@Api(tags = "真实驾驶舱")
|
||||
@Slf4j
|
||||
public class ReallyCockpitController {
|
||||
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
CockpitService cockpitService;
|
||||
|
||||
@Autowired
|
||||
ReallyCockpitService reallyCockpitService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
FileCenterFeignClient fileCenterFeignClient;
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
@Value("${event.currentMaxDay}")
|
||||
Integer currentMaxDay;
|
||||
|
||||
|
||||
@PostMapping("/weather")
|
||||
@ApiOperation(value = "大屏天气接口")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<WeatherRespVo> weather(HttpServletRequest request) {
|
||||
String ipAddr = IPUtils.getIpAddr(request);
|
||||
log.info("获取到IP: {}", ipAddr);
|
||||
if (env.equals("dev") || env.equals("exp")) {
|
||||
ipAddr = "114.222.185.168";
|
||||
}
|
||||
//通合的先显示南通的地址IP,后续再优化
|
||||
else if(EnvConstant.TONG_HE.equals(env)){
|
||||
ipAddr = "221.227.154.59";
|
||||
}
|
||||
//调用file-center的天气接口
|
||||
WeatherReq weatherReq = new WeatherReq();
|
||||
weatherReq.setIp(ipAddr);
|
||||
DataResult<WeatherRespVo> weatherResult = fileCenterFeignClient.queryWeather(weatherReq);
|
||||
log.info("天气接口数据:" + weatherResult);
|
||||
return DataResult.success(weatherResult.getData());
|
||||
}
|
||||
|
||||
@PostMapping("/groupData")
|
||||
@ApiOperation(value = "集团数据")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<GroupDataRespVo> groupData(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
GroupDataRespVo groupDataRespVo = reallyCockpitService.getGroupData(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(groupDataRespVo);
|
||||
bigDecimalUtil.ifIsNUll(groupDataRespVo);
|
||||
return DataResult.success(groupDataRespVo);
|
||||
}
|
||||
|
||||
@PostMapping("/cumulative")
|
||||
@ApiOperation(value = "累计总和")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<CumulativeRespVO> cumulative(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
CumulativeRespVO respVO = reallyCockpitService.getCumulative(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(respVO);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/stationMap")
|
||||
@ApiOperation(value = "电站地图")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationMapRespVO>> stationMap(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<StationMapRespVO> respVO = cockpitService.getStationMap(user);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/conditionMonitoring")
|
||||
@ApiOperation(value = "状态监测")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<ConditionMonitoringRespVO> conditionMonitoring(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
ConditionMonitoringRespVO respVO = cockpitService.getConditionMonitoring(user);
|
||||
bigDecimalUtil.ifIsNUll(respVO);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/stationOperation")
|
||||
@ApiOperation(value = "电站运行数据")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationOperationRespVO>> stationOperation(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<StationOperationRespVO> list = cockpitService.getStationOperation(user);
|
||||
for (StationOperationRespVO stationOperationRespVO : list) {
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(stationOperationRespVO);
|
||||
bigDecimalUtil.ifIsNUll(stationOperationRespVO);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/capacityProportion")
|
||||
@ApiOperation(value = "装机占比")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<CapacityProportionResp> capacityProportion(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
CapacityProportionResp capacityProportionResp = reallyCockpitService.capacityProportion(user);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(capacityProportionResp);
|
||||
bigDecimalUtil.ifIsNUll(capacityProportionResp);
|
||||
return DataResult.success(capacityProportionResp);
|
||||
}
|
||||
|
||||
@PostMapping("/monitoringStation")
|
||||
@ApiOperation(value = "电站实时监控")
|
||||
@TokenIgnore
|
||||
@LargeScreenToken
|
||||
public DataResult<List<StationRespVO>> monitoringStation(HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByBigScreenToken(token);
|
||||
List<StationRespVO> list = cockpitService.monitoringStation(user);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,326 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.service.ReportFormService;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.util.AdaptiveWidthUtils;
|
||||
import com.ho.business.vo.req.reduceemissions.ReduceEmissionsReqVO;
|
||||
import com.ho.business.vo.req.report.ReportReqVO;
|
||||
import com.ho.business.vo.resp.ReportFromReqVo;
|
||||
import com.ho.business.vo.resp.report.CurrentMonthReportRespVO;
|
||||
import com.ho.business.vo.resp.report.HistoryReportRespVO;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.apache.poi.ss.usermodel.Drawing;
|
||||
import org.apache.poi.ss.usermodel.Picture;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 报表
|
||||
* @DateTime: 2022/11/9 8:49
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "report")
|
||||
@Api(tags = "报表模块")
|
||||
@Slf4j
|
||||
public class ReportFormController {
|
||||
|
||||
@Autowired
|
||||
ReportFormService reportFormService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
StationService stationService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
|
||||
@PostMapping("report")
|
||||
@ApiOperation(value = "报表查询")
|
||||
public DataResult<List<ReportFromReqVo>> getReportForm(@RequestBody @Valid ReduceEmissionsReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//如果 stationId没传 要查所辖电站的数据
|
||||
if (StringUtils.isEmpty(vo.getStationId())) {
|
||||
vo.setStationIds(simpleUser.getStationIds());
|
||||
}
|
||||
|
||||
List<ReportFromReqVo> ReportFromReqVo = reportFormService.getReportForm(vo);
|
||||
return DataResult.success(ReportFromReqVo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("exportStationReport")
|
||||
@ApiOperation(value = "电站电量报表下载")
|
||||
@LogAnnotation(title = "报表模块", action = "电站电量报表下载")
|
||||
public void exportStationReport(@RequestBody @Valid ReduceEmissionsReqVO vo, HttpServletRequest request, HttpServletResponse response) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//如果 stationId没传 要查所辖电站的数据
|
||||
if (StringUtils.isEmpty(vo.getStationId())) {
|
||||
vo.setStationIds(simpleUser.getStationIds());
|
||||
}
|
||||
//查询数据
|
||||
List<ReportFromReqVo> list = reportFormService.getReportForm(vo);
|
||||
//在内存操作,写到浏览器
|
||||
ExcelWriter writer = ExcelUtil.getWriter(true);
|
||||
|
||||
//自定义标题别名
|
||||
writer.addHeaderAlias("day", "日期");
|
||||
writer.addHeaderAlias("totalDischargeCapacity", "总放电量");
|
||||
writer.addHeaderAlias("totalChargeCapacity", "总充电量");
|
||||
writer.addHeaderAlias("tipCharge", "尖充电量");
|
||||
writer.addHeaderAlias("peakCharge", "峰充电量");
|
||||
writer.addHeaderAlias("dailyCharge", "平充电量");
|
||||
writer.addHeaderAlias("valleyCharge", "谷充电量");
|
||||
writer.addHeaderAlias("tipDischarge", "尖放电量");
|
||||
writer.addHeaderAlias("peakDischarge", "峰放电量");
|
||||
writer.addHeaderAlias("dailyDischarge", "平放电量");
|
||||
writer.addHeaderAlias("valleyDischarge", "谷放电量");
|
||||
writer.addHeaderAlias("totalProfit", "收益(元)");
|
||||
|
||||
//默认配置
|
||||
writer.write(list, true);
|
||||
//自适应宽度
|
||||
AdaptiveWidthUtils.setSizeColumn(writer.getSheet(), 4);
|
||||
//设置content—type
|
||||
//response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
response.addHeader("Access-Control-Expose-Headers", "Content-disposition");
|
||||
response.setHeader("Pragma", "No-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
response.setDateHeader("Expires", 0);
|
||||
//设置标题
|
||||
String fileName = null;
|
||||
ServletOutputStream outputStream = null;
|
||||
try {
|
||||
fileName = "stationReport_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".xlsx";
|
||||
//fileName = "站级充电量统计报表.xlsx";
|
||||
//Content-disposition是MIME协议的扩展,MIME协议指示MIME用户代理如何显示附加的文件。
|
||||
//response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
outputStream = response.getOutputStream();
|
||||
|
||||
//将Writer刷新到OutPut
|
||||
writer.flush(outputStream, true);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("currentMonthReport")
|
||||
@ApiOperation("当月报表数据")
|
||||
public DataResult<List<CurrentMonthReportRespVO>> getCurrentMonthReport(@RequestBody @Valid ReportReqVO vo) {
|
||||
List<CurrentMonthReportRespVO> currentMonthReportRespVOList = new ArrayList<>();
|
||||
if (vo.getStationId() != null) {
|
||||
//查询电站的装机容量
|
||||
Station station = stationService.selectById(vo.getStationId());
|
||||
if (station != null) {
|
||||
currentMonthReportRespVOList = reportFormService.getCurrentMonthReport(station.getCapacity(), vo);
|
||||
for (CurrentMonthReportRespVO reportRespVO : currentMonthReportRespVOList) {
|
||||
bigDecimalUtil.ifIsNUll(reportRespVO);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(reportRespVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
return DataResult.success(currentMonthReportRespVOList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("exportCurrentMonthReport")
|
||||
@ApiOperation(value = "当月报表下载")
|
||||
@LogAnnotation(title = "报表模块", action = "当月报表下载")
|
||||
public void exportCurrentMonthReport(@RequestBody @Valid ReportReqVO vo, HttpServletResponse response) {
|
||||
List<CurrentMonthReportRespVO> list = new ArrayList<>();
|
||||
if (vo.getStationId() != null) {
|
||||
//查询电站的装机容量
|
||||
Station station = stationService.selectById(vo.getStationId());
|
||||
if (station != null) {
|
||||
list = reportFormService.getCurrentMonthReport(station.getCapacity(), vo);
|
||||
for (CurrentMonthReportRespVO reportRespVO : list) {
|
||||
bigDecimalUtil.ifIsNUll(reportRespVO);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(reportRespVO);
|
||||
}
|
||||
}
|
||||
//在内存操作,写到浏览器
|
||||
ExcelWriter writer = ExcelUtil.getBigWriter();
|
||||
|
||||
//自定义标题别名
|
||||
writer.addHeaderAlias("date", "日期");
|
||||
writer.addHeaderAlias("powerGeneration", "日发电量");
|
||||
writer.addHeaderAlias("income", "上网电量");
|
||||
writer.addHeaderAlias("ele", "企业用电量");
|
||||
writer.addHeaderAlias("equivalentHours", "等效小时");
|
||||
|
||||
writer.write(list, true);
|
||||
|
||||
if (vo.getBytes() != null) {
|
||||
//图片位置放在list数据下2行
|
||||
int y = list.size() + 2;
|
||||
//写图片字节流
|
||||
String[] split = vo.getBytes().split(",");
|
||||
byte[] decode = Base64.decode(split[1]);
|
||||
writePic(writer, 0, y, decode, HSSFWorkbook.PICTURE_TYPE_PNG);
|
||||
//自适应宽度
|
||||
AdaptiveWidthUtils.setSizeColumn(writer.getSheet(), 4);
|
||||
}
|
||||
String excelName = "excel.xls";
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + new String(excelName.getBytes("gb2312"), "ISO8859-1"));
|
||||
out = response.getOutputStream();
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
} finally {
|
||||
writer.flush(out, true);
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
//此处记得关闭输出Servlet流
|
||||
IoUtil.close(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("historyReport")
|
||||
@ApiOperation("历史报表数据")
|
||||
public DataResult<List<HistoryReportRespVO>> getHistoryReport(@RequestBody @Valid ReportReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//如果 stationId没传 要查所辖电站的数据
|
||||
if (StringUtils.isEmpty(vo.getStationId())) {
|
||||
vo.setGroupId(simpleUser.getGroupId());
|
||||
}
|
||||
List<HistoryReportRespVO> list = reportFormService.getHistoryReport(vo);
|
||||
for (HistoryReportRespVO reportRespVO : list) {
|
||||
bigDecimalUtil.ifIsNUll(reportRespVO);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(reportRespVO);
|
||||
}
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("exportHistoryReport")
|
||||
@ApiOperation(value = "历史报表下载")
|
||||
@LogAnnotation(title = "报表模块", action = "历史报表下载")
|
||||
public void exportHistoryReport(@RequestBody @Valid ReportReqVO vo, HttpServletRequest request, HttpServletResponse response) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//如果 stationId没传 要查所辖电站的数据
|
||||
if (StringUtils.isEmpty(vo.getStationId())) {
|
||||
vo.setStationId(simpleUser.getGroupId());
|
||||
}
|
||||
List<HistoryReportRespVO> list = reportFormService.getHistoryReport(vo);
|
||||
for (HistoryReportRespVO reportRespVO : list) {
|
||||
bigDecimalUtil.ifIsNUll(reportRespVO);
|
||||
bigDecimalUtil.keepTwoDecimalPlaces(reportRespVO);
|
||||
}
|
||||
//在内存操作,写到浏览器
|
||||
ExcelWriter writer = ExcelUtil.getBigWriter();
|
||||
//自定义标题别名
|
||||
writer.addHeaderAlias("date", "日期");
|
||||
writer.addHeaderAlias("powerGeneration", "发电量");
|
||||
writer.addHeaderAlias("eleTotalFee", "企业用电收益");
|
||||
writer.addHeaderAlias("incomeFee", "余电上网收益");
|
||||
writer.addHeaderAlias("totalFee", "总收益/元");
|
||||
|
||||
writer.write(list, true);
|
||||
|
||||
if (vo.getBytes() != null && !vo.getBytes().equals("")) {
|
||||
//图片位置放在list数据下2行
|
||||
int y = list.size() + 2;
|
||||
//写图片字节流
|
||||
String[] split = vo.getBytes().split(",");
|
||||
byte[] decode = Base64.decode(split[1]);
|
||||
writePic(writer, 0, y, decode, HSSFWorkbook.PICTURE_TYPE_PNG);
|
||||
//自适应宽度
|
||||
AdaptiveWidthUtils.setSizeColumn(writer.getSheet(), 4);
|
||||
}
|
||||
String excelName = "excel.xls";
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + new String(excelName.getBytes("gb2312"), "ISO8859-1"));
|
||||
out = response.getOutputStream();
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
} finally {
|
||||
writer.flush(out, true);
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
//此处记得关闭输出Servlet流
|
||||
IoUtil.close(out);
|
||||
}
|
||||
}
|
||||
|
||||
public void writePic(ExcelWriter writer, int x, int y, byte[] pictureData, int picType) {
|
||||
|
||||
Sheet sheet = writer.getSheet();
|
||||
Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
|
||||
|
||||
//设置图片单元格位置
|
||||
ClientAnchor anchor = drawingPatriarch.createAnchor(0, 0, 255, 255, x, y, x + 1, y + 1);
|
||||
|
||||
//随单元格改变位置和大小
|
||||
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
|
||||
|
||||
//添加图片
|
||||
int pictureIndex = sheet.getWorkbook().addPicture(pictureData, picType);
|
||||
Picture picture = drawingPatriarch.createPicture(anchor, pictureIndex);
|
||||
|
||||
//按比例调整图像大小
|
||||
picture.resize(0.6);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,121 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
||||
import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.service.EarningsCalculateService;
|
||||
import com.ho.business.vo.req.report.ReportReqVO;
|
||||
import com.ho.business.vo.resp.income.RevenueOverview;
|
||||
import com.ho.business.vo.resp.income.RevenueOverviewData;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author yule
|
||||
* @Date 2024/2/28 9:15
|
||||
* @desc ${}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "revenueOverview")
|
||||
@Api(tags = "收益总览")
|
||||
@Slf4j
|
||||
public class RevenueOverviewController {
|
||||
|
||||
@Autowired
|
||||
EarningsCalculateService earningsCalculateService;
|
||||
|
||||
@PostMapping("chargingAndDischargingData")
|
||||
@ApiOperation("充放电数据")
|
||||
public DataResult<PageResult<RevenueOverviewData>> getRevenueOverviewData(@RequestBody @Valid ReportReqVO vo) {
|
||||
List<RevenueOverviewData> dataList = earningsCalculateService.getRevenueOverviewData(vo);
|
||||
//java内存分页
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!dataList.isEmpty()) {
|
||||
List list = new ArrayList(0);
|
||||
// 如果别的电站数量比较多,翻到最后一页切换电站会出现页码超过现有数组长度
|
||||
Integer pageNum = vo.getPageNum();
|
||||
Integer pageSize = vo.getPageSize();
|
||||
if ( pageNum <= dataList.size() / pageSize + 1 ) {
|
||||
list = PageUtils.dealList(dataList, pageNum, pageSize);
|
||||
}
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(dataList.size());
|
||||
pageResult.setTotalPages(dataList.size() / pageSize + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
@PostMapping("incomeFromInvestment")
|
||||
@ApiOperation("投资收益")
|
||||
public DataResult<RevenueOverview> getInvestment(@RequestBody @Valid ReportReqVO vo) {
|
||||
RevenueOverview revenueOverview = earningsCalculateService.getInvestment(vo);
|
||||
return DataResult.success(revenueOverview);
|
||||
}
|
||||
|
||||
@GetMapping("elecPrice")
|
||||
@ApiOperation(value = "电价曲线")
|
||||
public DataResult getElecPrice(Integer stationId) {
|
||||
List<Map<String,Object>> list = earningsCalculateService.getElecPrice(stationId);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("revenue")
|
||||
@ApiOperation("收益曲线")
|
||||
public DataResult<List<RevenueOverviewData>> getRevenue(@RequestBody @Valid ReportReqVO vo) {
|
||||
List<RevenueOverviewData> dataList = earningsCalculateService.getRevenueOverviewData(vo);
|
||||
return DataResult.success(dataList);
|
||||
}
|
||||
|
||||
@PostMapping("export")
|
||||
@ApiOperation(value = "导出")
|
||||
public void export(@RequestBody @Valid ReportReqVO vo, HttpServletResponse response) {
|
||||
List<RevenueOverviewData> revenueOverviewData = earningsCalculateService.getRevenueOverviewData(vo);
|
||||
RevenueOverview investment = earningsCalculateService.getInvestment(vo);
|
||||
//在内存操作,写到浏览器
|
||||
String fileName = "demo.xlsx";
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
response.setContentType("multipart/form-data");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("UTF-8")));
|
||||
//文件模板输入流
|
||||
InputStream inputStream = new ClassPathResource("template/RevenueOverview.xlsx").getInputStream();
|
||||
|
||||
ExcelWriter writer = EasyExcel.write(out).withTemplate(inputStream).build();
|
||||
WriteSheet sheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
|
||||
|
||||
writer.fill(new FillWrapper("data", revenueOverviewData), fillConfig, sheet);
|
||||
//填充数据
|
||||
writer.fill(investment,fillConfig,sheet);
|
||||
//填充完成
|
||||
writer.finish();
|
||||
out.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,577 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.common.BusiTool;
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.constant.StationYcTypeConstant;
|
||||
import com.ho.business.entity.DeviceType;
|
||||
import com.ho.business.entity.Picture;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.entity.StationSn;
|
||||
import com.ho.business.feignclient.FlowFeignClient;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.business.service.*;
|
||||
import com.ho.business.vo.req.*;
|
||||
import com.ho.business.vo.req.device.DeviceTypeConfigAddReq;
|
||||
import com.ho.business.vo.req.picture.PictureQueryReq;
|
||||
import com.ho.business.vo.req.station.StationStatusReq;
|
||||
import com.ho.business.vo.resp.*;
|
||||
import com.ho.business.vo.resp.station.NationStation;
|
||||
import com.ho.business.vo.resp.station.StationResp;
|
||||
import com.ho.business.vo.resp.station.StationStatus;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.vo.req.QueryDeptReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description 电站管理
|
||||
* Author yule
|
||||
* Date 2022/8/29 16:37
|
||||
*/
|
||||
@RequestMapping(ContextConstant.BUSINESS + "station")
|
||||
@RestController
|
||||
@Api(tags = "业务模块-电站管理")
|
||||
public class StationController {
|
||||
|
||||
@Autowired
|
||||
private StationService stationService;
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DeviceTypeConfigService deviceTypeConfigService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private StationSnService stationSnService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private PictureService pictureService;
|
||||
|
||||
@Autowired
|
||||
private UserFeignClient userFeignClient;
|
||||
|
||||
@Autowired
|
||||
FlowFeignClient flowFeignClient;
|
||||
|
||||
@Autowired
|
||||
BusiTool busiTool;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String env;
|
||||
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增电站接口")
|
||||
@LogAnnotation(title = "电站管理", action = "新增电站信息")
|
||||
//@HzPermission(PermissionConstant.SYS_STATIONMANAGE_ADD)
|
||||
public DataResult<Station> add(@RequestBody @Valid StationReqVO vo, HttpServletRequest request) {
|
||||
DataResult<Station> result = new DataResult<>();
|
||||
Station station = stationService.selectByName(vo.getName());
|
||||
if (station != null) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_ALREADY_EXISTS);
|
||||
}
|
||||
QueryDeptReqVO queryDeptReqVO = new QueryDeptReqVO();
|
||||
queryDeptReqVO.setDeptId(vo.getDeptId());
|
||||
DataResult<SysDept> dataResult = userFeignClient.getTopDept(queryDeptReqVO);
|
||||
SysDept data = dataResult.getData();
|
||||
vo.setGroupId(data.getId());
|
||||
Station add = stationService.insertStation(vo);
|
||||
vo.setId(add.getId());
|
||||
result.setData(add);
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
ids.add(add.getId());
|
||||
redisService.updateSimpleUserByToken(token, CommonConstant.UpdateMethod.ADD, ids);
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("id")
|
||||
@ApiOperation(value = "删除电站接口")
|
||||
@LogAnnotation(title = "电站管理", action = "删除电站信息")
|
||||
//@HzPermission(PermissionConstant.SYS_STATIONMANAGE_DELETE)
|
||||
public DataResult deleteByIds(@RequestBody List<Integer> ids, HttpServletRequest request) {
|
||||
for (Integer id : ids) {
|
||||
//如果电站下有拓扑数据不给删除
|
||||
List<DeviceRespVO> deviceRespVOS = deviceService.selectByStationIdAndPId(id, null);
|
||||
if (!deviceRespVOS.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_NO_DELETED);
|
||||
}
|
||||
//如果有工单数据不给删除
|
||||
DataResult<Integer> result = flowFeignClient.selectWorkOrderByStationId(id);
|
||||
if (result.getData() != null) {
|
||||
Integer orderNum = result.getData();
|
||||
if (orderNum > 0) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_NO_DELETED);
|
||||
}
|
||||
}
|
||||
}
|
||||
//删除电站数据及其先关数据
|
||||
stationService.deletedByIds(ids);
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
redisService.updateSimpleUserByToken(token, CommonConstant.UpdateMethod.DELETE, ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新电站接口")
|
||||
@LogAnnotation(title = "电站管理", action = "更新电站信息")
|
||||
//@HzPermission(PermissionConstant.SYS_STATIONMANAGE_EDIT)
|
||||
public DataResult update(@RequestBody @Valid StationPutReqVO vo, HttpServletRequest request) {
|
||||
Station stationValue = stationService.selectById(vo.getId());
|
||||
Station station = stationService.selectByNameAndId(vo.getName(), vo.getId(), vo.getDeptId());
|
||||
if (station != null) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_ALREADY_EXISTS);
|
||||
}
|
||||
if (stationValue != null) {
|
||||
if (stationValue.getName() != vo.getName()) {
|
||||
//对数据进行处理
|
||||
DeviceTypeConfigAddReq reqVo = new DeviceTypeConfigAddReq();
|
||||
reqVo.setStationId(vo.getId());
|
||||
reqVo.setName(vo.getName());
|
||||
deviceTypeConfigService.update(reqVo);
|
||||
}
|
||||
}
|
||||
//vo.setGroupId(user.getGroupId());
|
||||
stationService.update(vo);
|
||||
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/{id}")
|
||||
@ApiOperation(value = "根据id查询电站接口")
|
||||
public DataResult<StationRespVO> selectByIds(@PathVariable @Valid Integer id) {
|
||||
DataResult<StationRespVO> result = DataResult.success();
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
ids.add(id);
|
||||
List<StationRespVO> stations = stationService.selectByIds(ids);
|
||||
StationRespVO stationRespVO = new StationRespVO();
|
||||
if (!stations.isEmpty()) {
|
||||
stationRespVO = stations.get(0);
|
||||
//查询图片对象
|
||||
List<PictureRespVO> pictureResps = pictureService.selectBySrcId(id);
|
||||
stationRespVO.setPictureResps(pictureResps);
|
||||
//根据类型和电站查询,有数据则返回logo图片信息
|
||||
Picture pictureRespVO = pictureService.selectByStationAndType(id, CommonConstant.PICTURE.LOGO);
|
||||
stationRespVO.setLogoPicture(pictureRespVO);
|
||||
//查询sn编码对象
|
||||
List<StationSn> stationSnList = stationSnService.getSnListByStationId(id);
|
||||
List<String> snList = stationSnList.stream().map(s -> {
|
||||
return s.getSn();
|
||||
}).collect(Collectors.toList());
|
||||
stationRespVO.setSnList(snList);
|
||||
result.setData(stationRespVO);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("getLogo/{id}")
|
||||
@ApiOperation(value = "根据id获取电站Logo接口")
|
||||
public DataResult<Picture> getLogo(@PathVariable @Valid Integer id) {
|
||||
Picture pictureRespVO = pictureService.selectByStationAndType(id, CommonConstant.PICTURE.LOGO);
|
||||
return DataResult.success(pictureRespVO);
|
||||
}
|
||||
|
||||
//根据dept_id查询电站信息
|
||||
@PostMapping("selectByDeptId")
|
||||
public DataResult<List<Station>> selectByDeptId(@RequestBody QueryDeptReqVO queryDeptReqVO) {
|
||||
DataResult<List<Station>> result = DataResult.success();
|
||||
List<Station> stations = stationService.selectByDeptId(queryDeptReqVO);
|
||||
result.setData(stations);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperation(value = "分页查询电站接口")
|
||||
public DataResult<PageResult<StationRespVO>> page(@RequestBody @Valid StationPageReqVO stationPageReqVO, HttpServletRequest request) {
|
||||
DataResult<PageResult<StationRespVO>> result = DataResult.success();
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//如果登录人为超级管理员则返回空数据
|
||||
if (user.getPlatSuper()) {
|
||||
PageResult<StationRespVO> pageResult = new PageResult<>();
|
||||
pageResult.setList(new ArrayList<>());
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
PageResult<StationRespVO> stationRespVOPageVO = stationService.selectPage(stationPageReqVO, user);
|
||||
result.setData(stationRespVOPageVO);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/all")
|
||||
@ApiOperation(value = "查询所有电站接口")
|
||||
public DataResult<List<Station>> all() {
|
||||
DataResult<List<Station>> result = DataResult.success();
|
||||
List<Station> stations = stationService.selectAll();
|
||||
result.setData(stations);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
@ApiOperation(value = "查询电站类型接口")
|
||||
public DataResult<List<DeviceType>> getTypes() {
|
||||
DataResult<List<DeviceType>> result = DataResult.success();
|
||||
List<DeviceType> deviceTypeList = stationService.selectType();
|
||||
result.setData(deviceTypeList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@ApiOperation(value = "根据登录人员查询所属电站")
|
||||
public DataResult<List<Station>> belongingToStation(HttpServletRequest request) {
|
||||
List<Station> stationsList = new ArrayList<>();
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (user.getPlatSuper()) {
|
||||
return DataResult.success(stationsList);
|
||||
}
|
||||
List<Station> stations = new ArrayList<>();
|
||||
List<Integer> stationIds = user.getStationIds();
|
||||
//OPEN环境需要只显示人员所属电站
|
||||
// if (EnvConstant.DEV.equals(env) || EnvConstant.OPEN.equals(env)) {
|
||||
if (stationIds != null && !stationIds.isEmpty()) {
|
||||
List<StationRespVO> stationRespVOS = stationService.selectByIds(stationIds);
|
||||
for (StationRespVO stationRespVO : stationRespVOS) {
|
||||
Station station = new Station();
|
||||
BeanUtil.copyProperties(stationRespVO, station);
|
||||
stations.add(station);
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// stations = stationService.selectByGroupId(user.getGroupId());
|
||||
// }
|
||||
if (stations == null || stations.isEmpty()) {
|
||||
return DataResult.success(stationsList);
|
||||
}
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
|
||||
@PostMapping("/provinceStation")
|
||||
@ApiOperation(value = "根据省份分组")
|
||||
public DataResult<List<ProvinceStation>> getProvinceStationList(HttpServletRequest request) {
|
||||
List<ProvinceStation> stationsList = new ArrayList<>();
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (user.getPlatSuper()) {
|
||||
return DataResult.success(stationsList);
|
||||
}
|
||||
stationsList = stationService.getProvinceStationList(user);
|
||||
return DataResult.success(stationsList);
|
||||
}
|
||||
|
||||
@PostMapping("/nationStation")
|
||||
@ApiOperation(value = "根据国家分组")
|
||||
public DataResult<StationResp> getNationStationList(HttpServletRequest request) {
|
||||
StationResp resp = new StationResp();
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (user.getPlatSuper()) {
|
||||
List<NationStation> stationsList = new ArrayList<>();
|
||||
resp.setList(stationsList);
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
resp = stationService.getNationStationList(user);
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/getProvince")
|
||||
@ApiOperation(value = "根据id查询电站省份")
|
||||
public DataResult<PrvinceRespVO> getProvince(@RequestBody @Valid StationPutReqVO vo) {
|
||||
Station station = stationService.selectById(vo.getId());
|
||||
PrvinceRespVO respVO = new PrvinceRespVO();
|
||||
if (station == null) {
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
BeanUtils.copyProperties(station, respVO);
|
||||
respVO.setName(station.getProvince().replace(CommonConstant.ChineseProvinces.PROVINCE, "").replace(CommonConstant.ChineseProvinces.CITY, ""));
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@PostMapping("/selectByName")
|
||||
@ApiOperation(value = "根据电站名称查询电站")
|
||||
public DataResult<List<Station>> selectByName(@RequestBody @Valid WorkOrderStationReqVO vo, HttpServletRequest request) {
|
||||
List<Station> stations = new ArrayList<>();
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (user.getPlatSuper()) {
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
stations = stationService.selectByDimName(vo, user);
|
||||
return DataResult.success(stations);
|
||||
}
|
||||
|
||||
@PostMapping("/findStationStatus")
|
||||
@ApiOperation(value = "集团下电站状态查询(APP新增)")
|
||||
public DataResult<List<StationStatus>> findStationStatus(HttpServletRequest request) {
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
List<StationStatus> stationStatusList = new ArrayList<>();
|
||||
//先设置3种类型的数据
|
||||
StationStatus stationStatusNormal = new StationStatus();
|
||||
stationStatusNormal.setStatusType("normal");
|
||||
stationStatusNormal.setStatusName("正常");
|
||||
stationStatusList.add(stationStatusNormal);
|
||||
StationStatus stationStatusOffline = new StationStatus();
|
||||
stationStatusOffline.setStatusType("offline");
|
||||
stationStatusOffline.setStatusName("离线");
|
||||
stationStatusList.add(stationStatusOffline);
|
||||
StationStatus stationStatusFault = new StationStatus();
|
||||
stationStatusFault.setStatusType("fault");
|
||||
stationStatusFault.setStatusName("故障");
|
||||
stationStatusList.add(stationStatusFault);
|
||||
return DataResult.success(stationStatusList);
|
||||
}
|
||||
|
||||
@PostMapping("/findListByStationStatus")
|
||||
@ApiOperation(value = "根据电站状态查询电站接口 (分页)(APP新增)")
|
||||
public DataResult<PageResult<Station>> findListByStationStatus(@RequestBody StationStatusReq stationStatusReq, HttpServletRequest request) {
|
||||
//根据所属集团查询电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String status = stationStatusReq.getStationStatus();
|
||||
//查所有电站
|
||||
List<Station> stations = stationService.selectByGroupId(user.getGroupId());
|
||||
//结果电站集合
|
||||
List<Station> resultList = new ArrayList<>();
|
||||
//包含3种 ,正常、离线、故障;其中:离线可以从SN心跳缓存中直接拿到并对比最后更新时间,故障电站可以根据告警模块接口直接拿到
|
||||
//如果是正常电站,那么就用总电站数 - (离线+故障)
|
||||
//离线电站,如果电站对应sn的缓存时间超过5分钟认为是离线
|
||||
if (StationYcTypeConstant.OFFLINE.equals(status)) {
|
||||
resultList = stationService.getOfflineStations(stations);
|
||||
}
|
||||
//故障电站,调用告警模块接口
|
||||
else if (StationYcTypeConstant.FAULT.equals(status)) {
|
||||
//故障电站暂时设置为0
|
||||
|
||||
|
||||
/*AlarmConfigQueryVo alarmConfigQueryVo = new AlarmConfigQueryVo();
|
||||
alarmConfigQueryVo.setGroupId(user.getGroupId());
|
||||
DataResult<List<StationStatusRespVO>> listDataResult = flowFeignClient.normalStation(alarmConfigQueryVo);
|
||||
if (listDataResult.isSuccess() && listDataResult.getData() != null) {
|
||||
List<StationStatusRespVO> stationStatusList = listDataResult.getData();
|
||||
Map<Integer, Boolean> stationStatusMap = stationStatusList.stream()
|
||||
.collect(Collectors.toMap(StationStatusRespVO::getStationId, StationStatusRespVO::getStationStatus));
|
||||
for (Station station : stations) {
|
||||
if (stationStatusMap.containsKey(station.getId())) {
|
||||
//status是 false就是故障
|
||||
if (!stationStatusMap.get(station.getId())) {
|
||||
resultList.add(station);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
//正常的: 全部的 - 离线的 - 故障的
|
||||
else if (StationYcTypeConstant.NORMAL.equals(status)) {
|
||||
//先找离线的
|
||||
List<Station> offlineStations = stationService.getOfflineStations(stations);
|
||||
Map<Integer, Station> offlineMap = offlineStations.stream().collect(Collectors.toMap(Station::getId, Station -> Station));
|
||||
Map<Integer, Boolean> stationStatusMap = new HashMap<>();
|
||||
//故障的map
|
||||
/*AlarmConfigQueryVo alarmConfigQueryVo = new AlarmConfigQueryVo();
|
||||
alarmConfigQueryVo.setGroupId(user.getGroupId());
|
||||
DataResult<List<StationStatusRespVO>> listDataResult = flowFeignClient.normalStation(alarmConfigQueryVo);
|
||||
if (listDataResult.isSuccess() && listDataResult.getData() != null) {
|
||||
List<StationStatusRespVO> stationStatusList = listDataResult.getData();
|
||||
stationStatusMap = stationStatusList.stream()
|
||||
.collect(Collectors.toMap(StationStatusRespVO::getStationId, StationStatusRespVO::getStationStatus));
|
||||
}*/
|
||||
for (Station station : stations) {
|
||||
//是否离线的
|
||||
if (offlineMap.containsKey(station.getId())) {
|
||||
continue;
|
||||
}
|
||||
//是否故障的
|
||||
/*if (stationStatusMap.containsKey(station.getId())) {
|
||||
if (!stationStatusMap.get(station.getId())) {
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
resultList.add(station);
|
||||
}
|
||||
}
|
||||
//不传状态 ,就查所有电站
|
||||
else if (status == null) {
|
||||
resultList = stations;
|
||||
}
|
||||
//内存分页
|
||||
PageResult<Station> pageResult = new PageResult<>();
|
||||
if (!resultList.isEmpty()) {
|
||||
List list = PageUtils.dealList(resultList, stationStatusReq.getPageNum(), stationStatusReq.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(resultList.size());
|
||||
pageResult.setTotalPages(resultList.size() / stationStatusReq.getPageSize() + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
@PostMapping("/pageList")
|
||||
@ApiOperation(value = "分页查询电站接口(同步电站筛选时使用)")
|
||||
public DataResult<PageResult<StationRespVO>> pageList(@RequestBody @Valid StationPageListReqVO stationPageReqVO, HttpServletRequest request) {
|
||||
DataResult<PageResult<StationRespVO>> result = DataResult.success();
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//如果登录人为超级管理员则返回空数据
|
||||
if (user.getPlatSuper()) {
|
||||
PageResult<StationRespVO> pageResult = new PageResult<>();
|
||||
pageResult.setList(new ArrayList<>());
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
stationPageReqVO.setGroupId(user.getGroupId());
|
||||
PageResult<StationRespVO> stationRespVOPageVO = stationService.selectPageList(stationPageReqVO);
|
||||
result.setData(stationRespVOPageVO);
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************************以下为apk升级包相关的代码begin*************************************/
|
||||
@ApiOperation(value = "获取文件列表")
|
||||
@PostMapping("/filePage")
|
||||
public DataResult<List<PictureRespVO>> filePage() {
|
||||
List<PictureRespVO> list = pictureService.selectAllFile();
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取最新的文件")
|
||||
@PostMapping("/selectLastOne")
|
||||
@TokenIgnore
|
||||
public DataResult<PictureRespVO> selectLastOne(@Param("version") String version) {
|
||||
PictureRespVO respVO = pictureService.selectLastOne(version);
|
||||
return DataResult.success(respVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传文件")
|
||||
@PostMapping("/uploadFile")
|
||||
public DataResult<Picture> uploadFile(@RequestParam MultipartFile file, @Param("version") String version, @Param("updateLog") String updateLog, @Param("ownerOrg") String ownerOrg, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String bucket = DeviceTypeConstant.GROUP + user.getGroupId();
|
||||
Picture picture = pictureService.uploadFile(file, version, updateLog, ownerOrg, bucket);
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
/********************************apk升级包相关的代码end*************************************/
|
||||
|
||||
@ApiOperation(value = "上传logo文件")
|
||||
@PostMapping("/uploadLogoFile")
|
||||
public DataResult<Picture> uploadLogoFile(@RequestParam MultipartFile file, @Param("ownerOrg") String ownerOrg, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String bucket = DeviceTypeConstant.GROUP + user.getGroupId();
|
||||
Picture picture = pictureService.uploadLogoFile(file, ownerOrg, bucket);
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除文件")
|
||||
@PostMapping("/deleteFile")
|
||||
public DataResult deleteFile(@Param("pictureId") Integer pictureId, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//集团id拼接桶名称
|
||||
//桶使用固定minio
|
||||
String bucket = "filestore";
|
||||
pictureService.deletedFile(bucket, user.getGroupId(), pictureId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
/**
|
||||
* 上传文件到minio服务器
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadFileToMinIo")
|
||||
@ApiOperation(value = "上传文件到minio服务器")
|
||||
public DataResult<Picture> uploadFile(@RequestBody StationReq vo, HttpServletRequest request) {
|
||||
Picture picture = pictureService.insertPicture(vo, request);
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/queryFile")
|
||||
@ApiOperation(value = "查询上传minio文件服务器的文件")
|
||||
public DataResult<List<Picture>> queryFile(@RequestBody PictureQueryReq vo) {
|
||||
List<Picture> pictures = pictureService.selectAllFileByParams(vo);
|
||||
return DataResult.success(pictures);
|
||||
}
|
||||
/**********************************************************/
|
||||
|
||||
/***********************组态上传图片*********************/
|
||||
@ApiOperation(value = "上传组态缩率图文件")
|
||||
@PostMapping("/uploadPicture")
|
||||
public DataResult<Picture> uploadPicture(@RequestParam MultipartFile file, @Param("isPrivate") Integer isPrivate, @Param("type") Integer type, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO user = redisService.getUserDetailByToken(token);
|
||||
//isPrivate(1:私有 2:公有)
|
||||
Picture picture = pictureService.uploadPicture(file, type, user, isPrivate);
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
|
||||
@PostMapping("/queryPicture")
|
||||
@ApiOperation(value = "查询上传文件")
|
||||
public DataResult<List<Picture>> queryPicture(@RequestBody PictureQueryReq vo, HttpServletRequest request) {
|
||||
if (vo.getNeedUser() != null && CommonConstant.ONE.equals(vo.getNeedUser())) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO user = redisService.getUserDetailByToken(token);
|
||||
vo.setOwnerUser(user.getUsername());
|
||||
}
|
||||
List<Picture> pictures = pictureService.selectAllFileByParam(vo);
|
||||
return DataResult.success(pictures);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除文件")
|
||||
@PostMapping("/deletePicture")
|
||||
public DataResult deletePicture(@Param("pictureId") Integer pictureId) {
|
||||
pictureService.deletePicture(pictureId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
|
||||
|
||||
@ApiOperation(value = "获取术语词典")
|
||||
@TokenIgnore
|
||||
@PostMapping("/getTermDictionary")
|
||||
public DataResult getTermDictionary(@RequestBody(required = false) String language) {
|
||||
List<Map<String,String>> result =stationService.getTermDictionary(language);
|
||||
return DataResult.success(result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,206 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.RepairFile;
|
||||
import com.ho.business.entity.StationNotepad;
|
||||
import com.ho.business.feignclient.UserFeignClient;
|
||||
import com.ho.business.service.StationNoteAndRepairService;
|
||||
import com.ho.business.vo.req.StationNotepadReq;
|
||||
import com.ho.business.vo.req.StationRepairReqVo;
|
||||
import com.ho.business.vo.resp.StationRepairRespVo;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.EasyExcelUtil;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author wp
|
||||
* @desc: 电站备忘录及维修记录
|
||||
* @DateTime: 2024/10/11 10:57
|
||||
*/
|
||||
@RequestMapping(ContextConstant.BUSINESS + "noteAndRepair")
|
||||
@RestController
|
||||
@Api(tags = "业务模块-电站备忘录及维修记录")
|
||||
public class StationNoteAndRepairController {
|
||||
|
||||
@Autowired
|
||||
private UserFeignClient userFeignClient;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private StationNoteAndRepairService stationNoteAndRepairService;
|
||||
|
||||
@PostMapping("addStationNote")
|
||||
@ApiOperation("新增电站备忘录数据")
|
||||
public DataResult addStationNote(@RequestBody StationNotepad stationNotepad){
|
||||
//获取创建人名称
|
||||
SysUser userInfo = userFeignClient.getUserById(stationNotepad.getCreateUser()).getData();
|
||||
if(userInfo == null){
|
||||
throw new BusinessException(BaseResponseCode.ROLE_INFO_NOT_FOUND);
|
||||
}else{
|
||||
stationNotepad.setCreateUserName(userInfo.getRealName());
|
||||
}
|
||||
stationNoteAndRepairService.addStationNote(stationNotepad);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteStationNote")
|
||||
@ApiOperation("删除电站备忘录数据")
|
||||
public DataResult deleteStationNote(@RequestBody List<Integer> noteIds){
|
||||
if(noteIds.size() ==0){
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
stationNoteAndRepairService.deleteStationNote(noteIds.get(0));
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("updateStationNote")
|
||||
@ApiOperation("更新电站备忘录数据")
|
||||
public DataResult updateStationNote(@RequestBody StationNotepad stationNotepad){
|
||||
if(stationNotepad.getId()==null || stationNotepad.getUpdateUser() == null){
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
//获取创建人名称
|
||||
SysUser userInfo = userFeignClient.getUserById(stationNotepad.getUpdateUser()).getData();
|
||||
if(userInfo == null){
|
||||
throw new BusinessException(BaseResponseCode.ROLE_INFO_NOT_FOUND);
|
||||
}else{
|
||||
stationNotepad.setUpdateUserName(userInfo.getRealName());
|
||||
}
|
||||
stationNoteAndRepairService.updateStationNote(stationNotepad);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("selectStationNote")
|
||||
@ApiOperation("查询电站备忘录数据")
|
||||
public DataResult selectStationNote(@RequestBody StationNotepadReq stationNotepadReq){
|
||||
List<StationNotepad> stationNotepadList = stationNoteAndRepairService.selectStationNote(stationNotepadReq);
|
||||
if(stationNotepadReq.getPageSize() != null && stationNotepadReq.getPageNum() != null){
|
||||
//分页处理
|
||||
Integer totalNum = stationNotepadList.size();
|
||||
Integer pageSize = stationNotepadReq.getPageSize();
|
||||
Integer pageNum = stationNotepadReq.getPageNum();
|
||||
Integer totalSize = totalNum/pageSize+(totalNum%pageSize>0?1:0);
|
||||
stationNotepadList = stationNotepadList.stream().skip((pageNum-1)*pageSize).limit(pageSize).collect(Collectors.toList());
|
||||
PageResult pageResult = new PageResult();
|
||||
pageResult.setList(stationNotepadList);
|
||||
pageResult.setTotalRows(totalNum);
|
||||
pageResult.setTotalPages(totalSize);
|
||||
pageResult.setPageNum(pageNum);
|
||||
pageResult.setPageSize(pageSize);
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
return DataResult.success(stationNotepadList);
|
||||
}
|
||||
|
||||
@PostMapping("exportStationNote")
|
||||
@ApiOperation("导出电站备忘录数据列表")
|
||||
public void exportStationNote(@RequestBody StationNotepadReq stationNotepadReq, HttpServletResponse response){
|
||||
String fileName = "电站信息";
|
||||
String sheetName = "电站信息";
|
||||
List<StationNotepad> stationNotepadList = stationNoteAndRepairService.selectStationNote(stationNotepadReq);
|
||||
if(stationNotepadList.size()>0){
|
||||
try {
|
||||
EasyExcelUtil.writeExcel(response, stationNotepadList, fileName, sheetName, StationNotepad.class);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("addStationRepair")
|
||||
@ApiOperation("新增电站维修记录数据")
|
||||
public DataResult addStationRepair(@RequestBody StationRepairReqVo stationRepairReqVo){
|
||||
stationNoteAndRepairService.addStationRepair(stationRepairReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("deleteStationRepair")
|
||||
@ApiOperation("删除电站维修记录数据")
|
||||
public DataResult deleteStationRepair(@RequestBody List<Integer> repaidId,HttpServletRequest request){
|
||||
if(repaidId.size() ==0){
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String bucket = DeviceTypeConstant.GROUP + user.getGroupId();
|
||||
stationNoteAndRepairService.deleteStationRepair(repaidId.get(0),bucket);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("updateStationRepair")
|
||||
@ApiOperation("修改电站维修记录数据")
|
||||
public DataResult updateStationRepair(@RequestBody StationRepairReqVo stationRepairReqVo){
|
||||
if(stationRepairReqVo.getId()==null ){
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
stationNoteAndRepairService.updateStationRepair(stationRepairReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("selectStationRepair")
|
||||
@ApiOperation("查询电站维修记录数据")
|
||||
public DataResult selectStationRepair(@RequestBody StationRepairReqVo stationRepairReqVo){
|
||||
List<StationRepairRespVo> result = stationNoteAndRepairService.selectStationRepair(stationRepairReqVo);
|
||||
if(stationRepairReqVo.getPageNum() != null && stationRepairReqVo.getPageSize() != null){
|
||||
//分页处理
|
||||
Integer totalNum = result.size();
|
||||
Integer pageSize = stationRepairReqVo.getPageSize();
|
||||
Integer pageNum = stationRepairReqVo.getPageNum();
|
||||
Integer totalSize = totalNum/pageSize+(totalNum%pageSize>0?1:0);
|
||||
result = result.stream().skip((pageNum-1)*pageSize).limit(pageSize).collect(Collectors.toList());
|
||||
PageResult pageResult = new PageResult();
|
||||
pageResult.setList(result);
|
||||
pageResult.setTotalRows(totalNum);
|
||||
pageResult.setTotalPages(totalSize);
|
||||
pageResult.setPageNum(pageNum);
|
||||
pageResult.setPageSize(pageSize);
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
return DataResult.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("exportStationRepair")
|
||||
@ApiOperation("导出电站维修记录数据列表")
|
||||
public void exportStationRepair(@RequestBody StationRepairReqVo stationRepairReqVo, HttpServletResponse response){
|
||||
String fileName = "维修记录";
|
||||
String sheetName = "维修记录";
|
||||
List<StationRepairRespVo> result = stationNoteAndRepairService.selectStationRepair(stationRepairReqVo);
|
||||
if(result.size()>0){
|
||||
try {
|
||||
EasyExcelUtil.writeExcel(response, result, fileName, sheetName, StationRepairRespVo.class);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("uploadRepairFile")
|
||||
@ApiOperation("上传维修记录文件")
|
||||
public DataResult<RepairFile> uploadRepairFile(@RequestParam MultipartFile file,HttpServletRequest request){
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
String bucket = DeviceTypeConstant.GROUP + user.getGroupId();
|
||||
RepairFile repairFile = stationNoteAndRepairService.uploadRepairFile(file,bucket);
|
||||
return DataResult.success(repairFile);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.StrategyOverviewUserSet;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.StationHomeService;
|
||||
import com.ho.business.service.StrategyOverviewUserSetService;
|
||||
import com.ho.business.vo.req.OperatingStatistic;
|
||||
import com.ho.business.vo.req.device.DeviceTreeReq;
|
||||
import com.ho.business.vo.req.device.StrategyOverviewUserSetVo;
|
||||
import com.ho.business.vo.req.point.PointCurveReq;
|
||||
import com.ho.business.vo.resp.cabin.TemperatureVoltageResp;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author yule
|
||||
* @Date 2024/3/4 15:32
|
||||
* @desc ${}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "strategyOverview")
|
||||
@Api(tags = "策略总览")
|
||||
@Slf4j
|
||||
public class StrategyOverviewController {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
StationHomeService stationHomeService;
|
||||
|
||||
@Autowired
|
||||
StrategyOverviewUserSetService setService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@PostMapping("cellVoltageAndTemperature")
|
||||
@ApiOperation("电芯电压/温度分布")
|
||||
public DataResult<TemperatureVoltageResp> getCellVoltageAndTemperature(@RequestBody @Valid DeviceTreeReq vo) {
|
||||
TemperatureVoltageResp temperatureVoltageResp = deviceService.getCellVoltageAndTemperature(vo);
|
||||
return DataResult.success(temperatureVoltageResp);
|
||||
}
|
||||
|
||||
@PostMapping("cellVoltageAndTemperatureNum")
|
||||
@ApiOperation("电芯电压/温度分布按序号")
|
||||
public DataResult<TemperatureVoltageResp> getCellVoltageAndTemperatureNum(@RequestBody @Valid DeviceTreeReq vo) {
|
||||
TemperatureVoltageResp temperatureVoltageResp = deviceService.getCellVoltageAndTemperatureNum(vo);
|
||||
return DataResult.success(temperatureVoltageResp);
|
||||
}
|
||||
|
||||
@PostMapping("defaultValue")
|
||||
@ApiOperation("默认值查询(soc,有功功率等)")
|
||||
public DataResult<PointCurveReq> getDefaultValue(@RequestBody @Valid DeviceTreeReq vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
PointCurveReq pointCurveReq = deviceService.getDefaultValue(vo.getStationId(),user);
|
||||
return DataResult.success(pointCurveReq);
|
||||
}
|
||||
|
||||
@PostMapping("operatingStatistic")
|
||||
@ApiOperation("运行统计")
|
||||
public DataResult<List<OperatingStatistic>> getOperatingStatistic(@RequestBody @Valid DeviceTreeReq vo) {
|
||||
List<OperatingStatistic> list = deviceService.getOperatingStatistic(vo.getStationId());
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("operatingStatistic2")
|
||||
@ApiOperation("运行统计(soc,soh)")
|
||||
public DataResult<List<OperatingStatistic>> getOperatingStatistic2(@RequestBody @Valid DeviceTreeReq vo) {
|
||||
List<OperatingStatistic> list = deviceService.getOperatingStatistic2(vo.getStationId());
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("getUserSet")
|
||||
@ApiOperation("策略总览-获取用户设置值")
|
||||
public DataResult<StrategyOverviewUserSet> getUserSet(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
StrategyOverviewUserSet strategyOverviewUserSet = setService.selectByUserId(user.getUserId());
|
||||
return DataResult.success(strategyOverviewUserSet);
|
||||
}
|
||||
|
||||
@PostMapping("setUserSet")
|
||||
@ApiOperation("策略总览-保存用户设置值")
|
||||
public DataResult<StrategyOverviewUserSet> setUserSet(@RequestBody StrategyOverviewUserSetVo vo,HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
StrategyOverviewUserSet userSet = new StrategyOverviewUserSet();
|
||||
BeanUtils.copyProperties(vo,userSet);
|
||||
userSet.setUserId(user.getUserId());
|
||||
Integer count = setService.setStrategyOverviewUserSet(userSet);
|
||||
return DataResult.success(count);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,144 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.business.entity.TabSort;
|
||||
import com.ho.business.entity.TabTag;
|
||||
import com.ho.business.service.TabSortWebService;
|
||||
import com.ho.business.vo.req.TabReqVo;
|
||||
import com.ho.business.vo.req.TabSortReqVo;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "tabSortWeb")
|
||||
@Api(tags = "策略模块配置")
|
||||
@Slf4j
|
||||
public class TabSortWebController {
|
||||
|
||||
@Autowired
|
||||
private TabSortWebService tabSortWebService;
|
||||
|
||||
|
||||
@PostMapping("/addTabSort")
|
||||
@ApiOperation(value = "新增页签内容")
|
||||
public DataResult addTabSort(@RequestBody @Valid TabSortReqVo tabSortReqVo) {
|
||||
tabSortWebService.addTabSort(tabSortReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/editTabSort")
|
||||
@ApiOperation(value = "编辑页签内容")
|
||||
public DataResult editTabSort(@RequestBody @Valid TabSortReqVo tabSortReqVo) {
|
||||
tabSortWebService.updateByTabId(tabSortReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/deleteTabSort")
|
||||
@ApiOperation(value = "删除页签内容")
|
||||
public DataResult deleteTabSort(@RequestParam("tabId") Integer tabId) {
|
||||
// 主要是删除整个页签
|
||||
tabSortWebService.deleteTabSort(tabId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/queryTabSortList")
|
||||
@ApiOperation(value = "查询页签列表")
|
||||
public DataResult<List<TabSort>> queryTabSortList(@RequestParam("stationId") Integer stationId) {
|
||||
DataResult<List<TabSort>> result = DataResult.success();
|
||||
List<TabSort> tabSorts = tabSortWebService.queryTabSortList(stationId);
|
||||
result.setData(tabSorts);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/queryTabTagList")
|
||||
@ApiOperation(value = "查询标签列表")
|
||||
public DataResult<List<TabTag>> queryTabTags(@RequestParam("tabId") Integer tabId,@RequestParam("stationId") Integer stationId) {
|
||||
DataResult<List<TabTag>> result = DataResult.success();
|
||||
List<TabTag> tabTagList = tabSortWebService.queryTabTags(tabId,stationId);
|
||||
result.setData(tabTagList);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/operateTabTag")
|
||||
@ApiOperation(value = "操作标签")
|
||||
public DataResult operateTabTag(@RequestBody TabSort tabSort) {
|
||||
tabSortWebService.operateTabTag(tabSort);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/oneKeyCopy")
|
||||
@ApiOperation(value = "一键复制")
|
||||
public DataResult oneKeyCopy(@RequestParam("stationId") Integer stationId, @RequestParam("copyStationId") Integer copyStationId) {
|
||||
tabSortWebService.oneKeyCopy(stationId,copyStationId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/queryVersion")
|
||||
@ApiOperation(value = "查看版本号列表")
|
||||
public DataResult<List<Map<String,Object>>> queryVersion(@Param("stationId") Integer stationId) {
|
||||
DataResult<List<Map<String,Object>>> result = DataResult.success();
|
||||
List<Map<String,Object>> list=tabSortWebService.queryVersion(stationId);
|
||||
result.setData(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/showVersion")
|
||||
@ApiOperation(value = "版本预览")
|
||||
public DataResult<List<TabSort>> showVersion(@RequestBody TabReqVo tabReqVo) {
|
||||
DataResult<List<TabSort>> result = DataResult.success();
|
||||
List<TabSort> list=tabSortWebService.showVersion(tabReqVo);
|
||||
result.setData(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/toggleVersion")
|
||||
@ApiOperation(value = "切换版本")
|
||||
public DataResult toggleVersion(@RequestBody TabReqVo tabReqVo) {
|
||||
tabSortWebService.toggleVersion(tabReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/getStationStatus")
|
||||
@ApiOperation(value = "获取电站状态")
|
||||
public DataResult<Integer> getStationStatus(@RequestParam("stationId") Integer stationId) {
|
||||
JSONObject stationStatus = tabSortWebService.getStationStatus(stationId);
|
||||
return DataResult.success(stationStatus);
|
||||
}
|
||||
|
||||
@PostMapping("/chooseState")
|
||||
@ApiOperation(value = "选择投退状态")
|
||||
public DataResult chooseState(@RequestParam("tagId") String tagId,@RequestParam("tabId") Integer tabId){
|
||||
if( tabId == null ){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
int i = tabSortWebService.queryTabTagIsChangeover(tabId);
|
||||
if( i == 0 && tagId.equals("null") ){
|
||||
throw new BusinessException(BaseResponseCode.CHANGEOVER_IS_NON);
|
||||
}
|
||||
if( tagId != null && !tagId.equals("null")){
|
||||
tabSortWebService.chooseState(Integer.parseInt(tagId),tabId);
|
||||
} else {
|
||||
tabSortWebService.chooseState(null,tabId);
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,125 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.entity.Topology;
|
||||
import com.ho.business.service.StationService;
|
||||
import com.ho.business.service.TopologyService;
|
||||
import com.ho.business.vo.req.TopologyInReqVo;
|
||||
import com.ho.business.vo.req.TopologyReqVo;
|
||||
import com.ho.business.vo.req.TopologyType;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RequestMapping(ContextConstant.BUSINESS + "topology")
|
||||
@RestController
|
||||
@Api(tags = "业务模块-拓扑管理")
|
||||
@Slf4j
|
||||
public class TopologyController {
|
||||
|
||||
@Autowired
|
||||
private TopologyService topologyService;
|
||||
|
||||
@Autowired
|
||||
private StationService stationService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
//根据电站id查询
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据id查询拓扑信息")
|
||||
//@LogAnnotation(title = "拓扑管理", action = "根据id查询拓扑信息")
|
||||
public DataResult<List<Topology>> selectByIds(@PathVariable @Valid Integer id) {
|
||||
DataResult<List<Topology>> result = DataResult.success();
|
||||
List<Topology> topology = topologyService.selectByStationId(id);
|
||||
result.setData(topology);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据电站id查询
|
||||
@PostMapping
|
||||
@ApiOperation(value = "查询所有拓扑信息")
|
||||
public DataResult<List<Topology>> selectTopologys(@RequestBody @Valid TopologyType topologyType, HttpServletRequest request) {
|
||||
//获取该用户所有在部门下的所有电站
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
//如果是超级管理员,提示 平台用户管理员不能直接查看监控页面,请使用集团用户登陆
|
||||
if (user.getPlatSuper()) {
|
||||
return DataResult.getResult(BaseResponseCode.PLAT_USER_CANNOT_MONITOR);
|
||||
}
|
||||
List<Station> list = stationService.selectByDeptIds(user.getDepts());
|
||||
log.info("station list:" + list);
|
||||
if (list == null || list.isEmpty()){
|
||||
return DataResult.getResult(BaseResponseCode.STATION_NO_FOUND);
|
||||
}
|
||||
List<Topology> topologyList = new ArrayList<>();
|
||||
//判断是否有参数
|
||||
if(topologyType.getType()==null){
|
||||
topologyType.setType(DeviceTypeConstant.PACK);
|
||||
topologyList = topologyService.selectByType(topologyType,list);
|
||||
}else{
|
||||
topologyList = topologyService.selectByType(topologyType,list);
|
||||
}
|
||||
|
||||
log.info("topology list:" + topologyList);
|
||||
return DataResult.success(topologyList);
|
||||
}
|
||||
|
||||
//新增
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增拓扑接口")
|
||||
@LogAnnotation(title = "拓扑管理", action = "新增拓扑信息")
|
||||
public DataResult<Topology> add(@RequestBody @Valid TopologyReqVo vo) {
|
||||
DataResult<Topology> result = new DataResult<>();
|
||||
Topology topo = topologyService.selectBysev(vo);
|
||||
if (topo != null) {
|
||||
return result;
|
||||
}
|
||||
Topology topology = new Topology();
|
||||
BeanUtils.copyProperties(vo, topology);
|
||||
int num = topologyService.insertSelective(topology);
|
||||
result.setData(topology);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除
|
||||
@DeleteMapping("del/{id}")
|
||||
@ApiOperation(value = "删除拓扑接口")
|
||||
@LogAnnotation(title = "拓扑管理", action = "删除拓扑信息")
|
||||
public DataResult deleteBytopologyId(@PathVariable @Valid Integer id) {
|
||||
topologyService.deleteBytopologyId(id);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//修改
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新拓扑接口")
|
||||
@LogAnnotation(title = "拓扑管理", action = "更新拓扑信息")
|
||||
public DataResult update(@RequestBody @Valid TopologyInReqVo vo) {
|
||||
topologyService.updateByPrimaryKeySelective(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.TopologyJumpConfig;
|
||||
import com.ho.business.service.TopologyJumpConfigService;
|
||||
import com.ho.business.vo.req.topologyJumpConfig.TopologyJumpConfigReq;
|
||||
import com.ho.business.vo.resp.colCount.ColCountResp;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Description 拓扑跳转配置
|
||||
* @Author xwz
|
||||
* @Date 2024/5/14
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "topologyJumpConfig")
|
||||
@Api(tags = "拓扑跳转配置")
|
||||
public class TopologyJumpConfigController {
|
||||
|
||||
@Autowired
|
||||
TopologyJumpConfigService topologyJumpConfigService;
|
||||
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "查询拓扑跳转配置")
|
||||
public DataResult<TopologyJumpConfig> list(@RequestBody TopologyJumpConfigReq vo) {
|
||||
List<TopologyJumpConfig> list = topologyJumpConfigService.selectByParam(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增拓扑跳转配置")
|
||||
@LogAnnotation(title = "拓扑跳转配置", action = "新增/更新拓扑跳转配置")
|
||||
public DataResult add(@RequestBody TopologyJumpConfig vo) {
|
||||
int count = topologyJumpConfigService.saveOrUpdateTopologyJumpConfig(vo);
|
||||
return DataResult.success(count);
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除拓扑跳转配置")
|
||||
@LogAnnotation(title = "拓扑跳转配置", action = "删除拓扑跳转配置")
|
||||
public DataResult<ColCountResp> delte(@RequestBody List<Integer> ids) {
|
||||
int count = topologyJumpConfigService.deleteByList(ids);
|
||||
return DataResult.success(count);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.service.VirtualDeviceConfigService;
|
||||
import com.ho.business.vo.VirtuallyModel;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2024/3/5 14:49
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "virtual")
|
||||
@Api(tags = "虚拟设备点一键绑定模块")
|
||||
@Slf4j
|
||||
public class VirtualDeviceConfigController {
|
||||
@Autowired
|
||||
VirtualDeviceConfigService virtualDeviceConfigService;
|
||||
|
||||
@PostMapping("getVirtualList")
|
||||
@ApiOperation(value = "新增虚拟设备点一键关联接口")
|
||||
@LogAnnotation(title = "虚拟设备关系模块", action = "新增虚拟设备点一键关联接口")
|
||||
public DataResult getVirtualList(@RequestBody @Valid VirtuallyModel model) {
|
||||
virtualDeviceConfigService.getVirtualList(model);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
import com.ho.business.entity.VirtualDeviceCol;
|
||||
import com.ho.business.service.VirtualDeviceColService;
|
||||
import com.ho.business.vo.req.VirtualDeviceColReq;
|
||||
import com.ho.business.vo.req.deviceModel.SynchronousReqVo;
|
||||
import com.ho.business.vo.resp.VirtualDeviceColResp;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 虚拟设备关系controller
|
||||
* @DateTime: 2023/6/29 9:45
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "virtual")
|
||||
@Api(tags = "虚拟设备关系模块")
|
||||
public class VirtualTypeController {
|
||||
@Autowired
|
||||
VirtualDeviceColService virtualDeviceColService;
|
||||
|
||||
// 增
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增虚拟设备关联接口")
|
||||
@LogAnnotation(title = "虚拟设备关系模块", action = "新增虚拟设备关联接口")
|
||||
public DataResult<VirtualDeviceCol> add(@RequestBody @Valid List<VirtualDeviceCol> list) {
|
||||
if(list.isEmpty()){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
DataResult<VirtualDeviceCol> result = new DataResult<>();
|
||||
virtualDeviceColService.insertList(list);
|
||||
return result;
|
||||
}
|
||||
// 改
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "更新虚拟设备关系")
|
||||
@LogAnnotation(title = "虚拟设备关系模块", action = "更新虚拟设备关系")
|
||||
public DataResult update(@RequestBody @Valid VirtualDeviceCol vo) {
|
||||
virtualDeviceColService.updateVirtualDeviceCol(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
// 查
|
||||
@PostMapping("/page")
|
||||
@ApiOperation(value = "分页查接口")
|
||||
public DataResult<PageResult<VirtualDeviceColResp>> page(@RequestBody @Valid VirtualDeviceColReq vo) {
|
||||
DataResult<PageResult<VirtualDeviceColResp>> result = DataResult.success();
|
||||
PageResult<VirtualDeviceColResp> pageList = virtualDeviceColService.getPageList(vo);
|
||||
result.setData(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 删
|
||||
@DeleteMapping("id")
|
||||
@ApiOperation(value = "删除接口")
|
||||
@LogAnnotation(title = "虚拟设备关系模块", action = "删除接口")
|
||||
public DataResult deleteByIds(@RequestBody List<Integer> ids) {
|
||||
//删除电站数据及其先关数据
|
||||
if (ids.isEmpty()){
|
||||
throw new BusinessException(BaseResponseCode.NON_DATA);
|
||||
}
|
||||
virtualDeviceColService.deleteByList(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//一键同步功能
|
||||
@PostMapping("/getSynchronousV")
|
||||
@ApiOperation(value = "一键同步虚拟设备关系功能")
|
||||
@LogAnnotation(title = "虚拟设备关系模块", action = "一键同步虚拟设备关系功能")
|
||||
//deviceType
|
||||
public DataResult getSynchronousV(@RequestBody SynchronousReqVo vo) {
|
||||
virtualDeviceColService.getSynchronousV(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.ho.business.controller;
|
||||
|
||||
|
||||
import com.ho.business.service.ZhouZiHuanBaoService;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.resp.zhongzi.ZhouZiHuanBaoPV;
|
||||
import com.ho.business.vo.resp.zhongzi.ZhouZiHuanBaoStatus;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xwz
|
||||
* @desc: 中自环保定制化首页
|
||||
* @date 2023/12/13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.BUSINESS + "zhongZiHuanBao")
|
||||
@Api(tags = "中自环保定制化首页")
|
||||
@Slf4j
|
||||
@Data
|
||||
public class ZhongZiHuanBaoController {
|
||||
|
||||
@Autowired
|
||||
ZhouZiHuanBaoService zhouZiHuanBaoService;
|
||||
|
||||
@PostMapping("/status")
|
||||
@ApiOperation(value = "站首页的中间部分")
|
||||
public DataResult<ZhouZiHuanBaoStatus> getStatus(@RequestBody StationReq req) {
|
||||
ZhouZiHuanBaoStatus middlePart = zhouZiHuanBaoService.getMiddlePart(req);
|
||||
return DataResult.success(middlePart);
|
||||
}
|
||||
|
||||
@PostMapping("/getStationData")
|
||||
@ApiOperation(value = "站首页的电站数据")
|
||||
public DataResult<ZhouZiHuanBaoPV> getStationData(@RequestBody StationReq req) {
|
||||
ZhouZiHuanBaoPV stationData = zhouZiHuanBaoService.getStationData(req);
|
||||
return DataResult.success(stationData);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package com.ho.business.task;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.business.config.WebSocketServer;
|
||||
import com.ho.business.controller.BoZhouController;
|
||||
import com.ho.business.controller.OpenStationController;
|
||||
import com.ho.business.service.DeviceService;
|
||||
import com.ho.business.service.OpenStationService;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.business.vo.resp.bozhou.BoZhouStationStatus;
|
||||
import com.ho.business.vo.resp.point.WareHouse;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.datacollect.api.constant.DataCollectConstant;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
public class TimeTask {
|
||||
|
||||
@Autowired
|
||||
DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Autowired
|
||||
WebSocketServer webSocketServer;
|
||||
|
||||
@Autowired
|
||||
OpenStationService openStationService;
|
||||
|
||||
@Scheduled(cron = "0/30 * * * * ?")
|
||||
public void sendMessage(){
|
||||
ConcurrentHashMap<String, String> map = WebSocketServer.map;
|
||||
Integer stationId;
|
||||
Integer method;
|
||||
for (Map.Entry<String, String> m:map.entrySet()) {
|
||||
try {
|
||||
StationReq stationReq = new StationReq();
|
||||
String str = m.getValue();
|
||||
String[] split = str.split(",");
|
||||
stationId = Integer.valueOf(split[0]);
|
||||
method = Integer.valueOf(split[1]);
|
||||
stationReq.setStationId(stationId);
|
||||
if(CommonConstant.ONE.equals(method)){
|
||||
OpenStationController controller = new OpenStationController();
|
||||
controller.setDeviceService(deviceService);
|
||||
controller.setBigDecimalUtil(bigDecimalUtil);
|
||||
controller.setRedisService(redisService);
|
||||
controller.setOpenStationService(openStationService);
|
||||
DataResult<List<WareHouse>> listDataResult = controller.middlePart(stationReq);
|
||||
WebSocketServer.sendInfo(m.getKey(),JSONObject.toJSONString(listDataResult));
|
||||
}else{
|
||||
BoZhouController controller = new BoZhouController();
|
||||
controller.setDeviceService(deviceService);
|
||||
controller.setBigDecimalUtil(bigDecimalUtil);
|
||||
controller.setRedisService(redisService);
|
||||
DataResult<BoZhouStationStatus> status = controller.getStatus(stationReq);
|
||||
WebSocketServer.sendInfo(m.getKey(),JSONObject.toJSONString(status));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
73
business-service/src/main/resources/application-dev.yml
Normal file
73
business-service/src/main/resources/application-dev.yml
Normal file
@ -0,0 +1,73 @@
|
||||
server:
|
||||
port: 8011
|
||||
servlet:
|
||||
context-path: /api
|
||||
|
||||
#swagger2配置
|
||||
swagger2:
|
||||
enable: true #开启swagger
|
||||
projectName: 云平台--business-前端接口
|
||||
controllerPath: com.ho.business.controller
|
||||
|
||||
spring:
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
name: business-service
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.100.244:3306/business_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||
username: root
|
||||
password: 123456
|
||||
druid:
|
||||
initialSize: 5
|
||||
minIdle: 5
|
||||
maxActive: 5
|
||||
keepAlive: true #保持长连接
|
||||
connection-error-retry-attempts: 3
|
||||
#Redis
|
||||
redis:
|
||||
port: 6379 #端口
|
||||
timeout: 50000ms #连接超时
|
||||
host: 192.168.100.242 #单机
|
||||
password: 123456
|
||||
database: 0
|
||||
|
||||
#port: 6379 #端口
|
||||
#timeout: 5000ms #连接超时
|
||||
#host: 127.0.0.1 #单机
|
||||
#password:
|
||||
#database: 0
|
||||
#集群 真实环境开启
|
||||
# record:
|
||||
# nodes:
|
||||
# - 127.0.0.1:6379
|
||||
# - 127.0.0.1:6380
|
||||
# - 127.0.0.1:6381
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8 #连接池最大连接 默认8
|
||||
max-idle: 8 #连接池中最大空闲连接 默认8
|
||||
min-idle: 1 #连接池中最小空闲连接 默认0
|
||||
max-wait: 2000ms #连接池最大阻塞等待时间 使用负值表示没有限制
|
||||
|
||||
|
||||
|
||||
boot:
|
||||
admin:
|
||||
client:
|
||||
url: http://localhost:8019/boot
|
||||
|
||||
minio:
|
||||
accessKey: admin
|
||||
secretKey: zzkj@688737
|
||||
endpoint: http://192.168.0.236:9000
|
||||
prefixUrl: http://192.168.0.236:9000
|
||||
|
||||
formula:
|
||||
fieldmap:
|
||||
RT_FIELD_BEAN: RT_FIELD_BEAN
|
||||
3
business-service/src/main/resources/application.yml
Normal file
3
business-service/src/main/resources/application.yml
Normal file
@ -0,0 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
94
business-service/src/main/resources/bootstrap.yml
Normal file
94
business-service/src/main/resources/bootstrap.yml
Normal file
@ -0,0 +1,94 @@
|
||||
spring:
|
||||
#caffeine缓存
|
||||
# 缓存改为使用配置类
|
||||
# cache:
|
||||
# type: caffeine
|
||||
# caffeine:
|
||||
# spec: initialCapacity=50,maximumSize=500,expireAfterWrite=10s
|
||||
# cache-names: stationBySn,device,modelConfigList,pvPanel,realtimeCurve
|
||||
#禁止servlet懒加载
|
||||
mvc:
|
||||
servlet:
|
||||
load-on-startup: 1
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 100MB
|
||||
max-request-size: 1024MB
|
||||
#mybatis配置
|
||||
mybatis:
|
||||
type-aliases-package: com.ho.business.entity
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
# 映射处理类
|
||||
type-handlers-package: com.ho.business.handler
|
||||
configuration:
|
||||
#驼峰
|
||||
mapUnderscoreToCamelCase: true
|
||||
|
||||
#Logging
|
||||
logging:
|
||||
config: classpath:logback.xml
|
||||
level:
|
||||
com.ho.user.mapper: debug
|
||||
|
||||
#ribbon的超时时间
|
||||
ribbon:
|
||||
ReadTimeout: 10000
|
||||
ConnectTimeout: 10000
|
||||
|
||||
#开放端点用于SpringBoot Admin的监控
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: '*'
|
||||
|
||||
#水电气转换系数 todo 转换系数
|
||||
energy:
|
||||
convertFactor:
|
||||
elec: 2
|
||||
water: 2
|
||||
gas: 2
|
||||
#二氧化碳到煤的转换系数
|
||||
co2ToCole: 0.4
|
||||
#二氧化碳到树的转化系数
|
||||
co2ToTree: 1800
|
||||
#二氧化碳到汽油的转化系数
|
||||
co2ToGasoline: 2.30
|
||||
#树到平方公里的转化系数
|
||||
treeToSquareKilometer: 40000
|
||||
|
||||
#对比电站下的采集点时间差值
|
||||
station:
|
||||
timeDifference: 5
|
||||
|
||||
|
||||
#告警配置
|
||||
event:
|
||||
#当前告警查询的时间跨度 (天)
|
||||
currentMaxDay: -10
|
||||
#大屏最大告警条数
|
||||
bigScreenEventLimit: 200
|
||||
|
||||
#逆变器配置
|
||||
inverter:
|
||||
#查询逆变器发电量的时间间隔 分钟
|
||||
timeInterval: 15
|
||||
co2Factor: 0.997
|
||||
|
||||
# 大屏配置
|
||||
largeScreen:
|
||||
#收益系数
|
||||
income: 0.6
|
||||
weatherCode: 510105
|
||||
|
||||
#线上环境redis密码
|
||||
openRedis:
|
||||
host: 10.0.0.3
|
||||
port: 6379
|
||||
pass: HZNJ2025^03&24
|
||||
|
||||
#183redis密码
|
||||
openTestRedis:
|
||||
host: 192.168.1.183
|
||||
port: 6379
|
||||
pass: 123456
|
||||
BIN
business-service/src/main/resources/lib/business-src-1.0.jar
Normal file
BIN
business-service/src/main/resources/lib/business-src-1.0.jar
Normal file
Binary file not shown.
71
business-service/src/main/resources/logback.xml
Normal file
71
business-service/src/main/resources/logback.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS,CTT} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/home/hocloud/logs/business-service/business-service.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/home/hocloud/logs/business-service/business-service.%d{yyyy-MM-dd}-%i.log
|
||||
</fileNamePattern>
|
||||
<!--180天-->
|
||||
<maxHistory>10</maxHistory>
|
||||
<!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始,
|
||||
命名日志文件,例如log-error-2013-12-21.0.log -->
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>256MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS,CTT} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--Error级别-->
|
||||
<appender name="errorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/home/hocloud/logs/business-service/business-service-error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/home/hocloud/logs/business-service/business-service-error.%d{yyyy-MM-dd}-%i.log
|
||||
</fileNamePattern>
|
||||
<!--180天-->
|
||||
<maxHistory>10</maxHistory>
|
||||
<!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始,
|
||||
命名日志文件,例如log-error-2013-12-21.0.log -->
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>256MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
<!-- 此filter过滤debug级别以下的日志-->
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
<!-- 级别过滤器,根据日志级别进行过滤。-->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- project default level -->
|
||||
<logger name="com.ho.business" level="DEBUG"/>
|
||||
|
||||
<!--log4jdbc -->
|
||||
<logger name="jdbc.sqltiming" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="rollingFile"/>
|
||||
<appender-ref ref="errorFile"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
business-service/src/main/resources/template/planTemplate.xls
Normal file
BIN
business-service/src/main/resources/template/planTemplate.xls
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
business-service/src/main/resources/template/template.xls
Normal file
BIN
business-service/src/main/resources/template/template.xls
Normal file
Binary file not shown.
60
business-service/src/main/resources/template/test.sql
Normal file
60
business-service/src/main/resources/template/test.sql
Normal file
@ -0,0 +1,60 @@
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-01 00:00:00', 1, 6595.00, '2023-01-01');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-01 00:00:00', 2, 6495.00, '2023-01-01');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-02 00:00:00', 1, 6995.00, '2023-01-02');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-02 00:00:00', 2, 6895.00, '2023-01-02');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-03 08:55:49', 1, 6895.00, '2023-01-03');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-03 08:55:49', 2, 6795.00, '2023-01-03');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-04 00:00:00', 1, 6795.00, '2023-01-04');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-04 00:00:00', 2, 6695.00, '2023-01-04');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-05 00:00:00', 1, 6795.00, '2023-01-05');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-05 00:00:00', 2, 6595.00, '2023-01-05');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-06 00:00:00', 1, 6595.00, '2023-01-06');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-06 00:00:00', 2, 6495.00, '2023-01-06');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-07 00:00:00', 1, 6395.00, '2023-01-07');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-07 00:00:00', 2, 6295.00, '2023-01-07');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-08 00:00:00', 1, 6495.00, '2023-01-08');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-08 00:00:00', 2, 6395.00, '2023-01-08');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-09 06:06:15', 1, 6595.00, '2023-01-09');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-09 13:33:42', 2, 6395.00, '2023-01-09');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-10 13:33:59', 1, 6595.00, '2023-01-10');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-10 13:34:12', 2, 6495.00, '2023-01-10');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-11 13:35:23', 1, 6995.00, '2023-01-11');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-11 13:35:58', 2, 6895.00, '2023-01-11');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-12 13:36:12', 1, 6895.00, '2023-01-12');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-12 13:36:17', 2, 6795.00, '2023-01-12');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-13 13:36:29', 1, 6795.00, '2023-01-13');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-13 13:36:45', 2, 6695.00, '2023-01-13');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-14 13:36:53', 1, 6795.00, '2023-01-14');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-14 13:37:02', 2, 6595.00, '2023-01-14');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-15 13:37:12', 1, 6595.00, '2023-01-15');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-15 13:37:25', 2, 6495.00, '2023-01-15');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-16 00:00:00', 1, 6395.00, '2023-01-16');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-16 19:51:27', 2, 6295.00, '2023-01-16');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-17 17:51:33', 1, 6495.00, '2023-01-17');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-17 17:51:42', 2, 6395.00, '2023-01-17');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-18 13:51:48', 1, 6595.00, '2023-01-18');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-18 21:51:59', 2, 6395.00, '2023-01-18');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-19 17:51:42', 1, 6595.00, '2023-01-19');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-19 17:51:42', 2, 6095.00, '2023-01-19');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-20 17:51:42', 1, 6195.00, '2023-01-20');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-20 17:51:42', 2, 6095.00, '2023-01-20');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-21 17:51:42', 1, 6595.00, '2023-01-21');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-21 17:51:42', 2, 6495.00, '2023-01-21');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-22 17:51:42', 1, 6795.00, '2023-01-22');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-22 17:51:42', 2, 6595.00, '2023-01-22');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-23 17:51:42', 1, 6595.00, '2023-01-23');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-23 17:51:42', 2, 6495.00, '2023-01-23');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-24 17:51:42', 1, 6395.00, '2023-01-24');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-24 17:51:42', 2, 6295.00, '2023-01-24');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-25 17:51:42', 1, 6495.00, '2023-01-25');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-25 17:51:42', 2, 6395.00, '2023-01-25');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-26 17:51:42', 1, 6595.00, '2023-01-26');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-26 19:55:31', 2, 6395.00, '2023-01-26');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-27 19:55:40', 1, 6595.00, '2023-01-27');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-27 19:55:50', 2, 6495.00, '2023-01-27');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-28 19:01:17', 1, 6595.00, '2023-01-28');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-28 19:01:21', 2, 6495.00, '2023-01-28');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-29 00:01:28', 1, 6595.00, '2023-01-29');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-29 00:00:00', 2, 6495.00, '2023-01-29');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-30 00:00:00', 1, 6895.00, '2023-01-30');
|
||||
INSERT INTO `yc_value` (group_id,dept_id,station_id,create_time,type,digital,`day`) VALUES ( 1, 6, 1, '2023-01-30 00:00:00', 2, 6695.00, '2023-01-30');
|
||||
Reference in New Issue
Block a user