Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 9 months ago
parent
commit
aada63b54e
  1. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java
  2. 8
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java
  3. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  4. 58
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  5. 46
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  6. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java
  7. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  8. 22
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java
  9. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java
  10. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java
  11. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java
  12. 36
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java
  13. 45
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java
  14. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java

@ -13,6 +13,7 @@ import java.util.Optional;
@AllArgsConstructor
public enum FuncRouteEnum {
OPEN_SCADA("open_scada","打开实时画面"),
OPEN_VIDEO("open_video","打开视频监控"),
;
@Getter
private String funcCode;

8
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java

@ -39,8 +39,8 @@ public class InteractiveController {
@ApiOperation("提问")
@ApiOperationSupport(order = 2)
@GetMapping("/ask")
public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId) {
return interactiveService.ask(question, sessionId);
public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId,@RequestParam @ApiParam("用户Id") String userId) {
return interactiveService.ask(question, sessionId, userId);
}
@ApiOperation("站点、菜单鉴权")
@ -48,8 +48,8 @@ public class InteractiveController {
@RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST})
public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId,
@RequestParam @ApiParam("用户ID") String userId,
@RequestParam(required = false) @ApiParam("菜单ID") String menuId) {
return R.status(interactiveService.authentication(stationId,userId,menuId));
@RequestParam(required = false) @ApiParam("菜单ID") String funcCode) {
return R.status(interactiveService.authentication(stationId,userId,funcCode));
}
@ApiOperation("获取问答sessionId")

4
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java

@ -17,10 +17,10 @@ public interface IInteractiveService {
R resolve(ModelFunctionReq req);
R ask(String question,String sessionId);
R ask(String question,String sessionId,String userId);
List<AnswerVO> getAnswerBySessionIds(String sessionIds);
Boolean authentication(String stationId, String userId, String menuId);
Boolean authentication(String stationId, String userId, String funcCode);
}

58
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -16,10 +16,14 @@ import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.feign.IDeptClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@ -46,12 +50,15 @@ public class InteractiveServiceImpl implements IInteractiveService {
private final IJumpPageService jumpPageService;
private final IFunctionService functionService;
private final BigModelInvokeUrl bigModelInvokeUrl;
private final BladeLogger logger;
private final IDeptClient deptClient;
private final IUserClient userClient;
@Value("${fdp.host}")
private String fdpHost;
@Override
public R resolve(ModelFunctionReq req) {
//TODO 数据鉴权
logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req));
FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName());
TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType());
switch (typeEnum) {
@ -68,8 +75,7 @@ public class InteractiveServiceImpl implements IInteractiveService {
}
@Override
public R ask(String question,String sessionId) {
Long userId = AuthUtil.getUserId();
public R ask(String question,String sessionId,String userId) {
//TODO 保存问题
Map<String,String> params = new HashMap<>();
params.put("id",sessionId);
@ -77,28 +83,50 @@ public class InteractiveServiceImpl implements IInteractiveService {
params.put("query",question);
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk())
.body(JSON.toJSONString(params)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> {
throw new ServiceException("远程调用大模型【发起问答】接口失败!");
});
return R.data(JSONObject.parseObject(response.body()).getString("data"));
if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【发起问答】接口失败!");
return R.fail("远程调用大模型【发起问答】接口失败!");
}
return R.success("消息发送成功");
}
@Override
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,String> params = new HashMap<>();
params.put("ids",sessionIds);
Map<String,Object> params = new HashMap<>();
params.put("ids",Func.toStrList(",",sessionIds).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus())
.body(JSON.toJSONString(params)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> {
throw new ServiceException("远程调用大模型【发起问答】接口失败!");
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型【获取问题答案】接口失败!");
});
String data = JSONObject.parseObject(response.body()).getString("data");
return JSONArray.parseArray(data,AnswerVO.class);
return JSONArray.parseArray(response.body(),AnswerVO.class);
}
@Override
public Boolean authentication(String stationId, String userId, String menuId) {
//TODO 鉴权逻辑完善
public Boolean authentication(String stationId, String userId, String funcCode) {
// 站点鉴权
if(StringUtil.isNotBlank(stationId)) {
R<List<String>> stationsR = deptClient.getStationPermissionsById(Long.valueOf(userId));
Assert.isTrue(stationsR.isSuccess() && CollectionUtil.isNotEmpty(stationsR.getData()),() -> {
throw new ServiceException("获取人员站点权限失败!");
});
List<String> stations = stationsR.getData();
Assert.isTrue(stations.contains(stationId),() -> {
throw new ServiceException("人员站点鉴权失败!");
});
}
// 菜单鉴权
if(StringUtil.isNotBlank(funcCode)) {
FunctionEntity function = functionService.getFunctionByCode(funcCode);
Assert.isTrue(Func.isNotEmpty(function) && StringUtil.isNotBlank(function.getRoute()),() -> {
throw new ServiceException("传入函数未获取到菜单,鉴权失败!");
});
R<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute());
Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> {
throw new ServiceException("人员菜单鉴权失败!");
});
}
return true;
}

46
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java

@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.IntStream;
/**
* @Author: huangxing
@ -35,6 +36,8 @@ public class JumpRouteJoinStrategy {
switch(routeEnum) {
case OPEN_SCADA:
return this.getScadaExtra(args,function);
case OPEN_VIDEO:
return this.getVideoExtra(args,function);
default:
break;
}
@ -77,28 +80,41 @@ public class JumpRouteJoinStrategy {
return extraVO;
}
private ExtraVO getVideoExtra(Map<String,String> args,FunctionEntity function) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
Map<String, String> params = this.videoResolve(args);
String path = this.replacePath(function.getPath(), params);
extraVO.setRoute(path);
return extraVO;
}
/**
* 打开实时画面
* 解析实时画面参数
* @param args 大模型解析参数
* @return 实时画面路径拼接所需参数
*/
private Map<String,String> scadaResolve(Map<String,String> args) {
Map<String,String> result = new HashMap<>();
Assert.isTrue(args.containsKey("params"), () -> {
throw new ServiceException("大模型传参缺少params参数");
});
String params = args.get("canvas_id");
// 参数格式为:picResource^context^stationNum^projectId^taskId^name^id
List<String> params = Func.toStrList("\\^", args.get("params"));
Assert.isTrue(params.size() == 7,() -> {
throw new ServiceException("大模型传参params长度错误,传参为:" + args.get("params"));
String[] keys = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
return this.resolve(params,keys);
}
private Map<String,String> videoResolve(Map<String,String> args) {
String params = args.get("canvas_id");
// 参数格式为:id^name^stationCode^pointCode^host^appKey^appSecret
String[] keys = new String[]{"id","name","stationCode","pointCode","host","appKey","appSecret"};
return this.resolve(params,keys);
}
private Map<String,String> resolve(String paramsStr,String... keys) {
Map<String,String> result = new HashMap<>();
List<String> params = Func.toStrList("\\^", paramsStr);
Assert.isTrue(params.size() == keys.length, () -> {
throw new ServiceException("大模型传参params长度错误,传参为:" + paramsStr);
});
result.put("picResource",params.get(0));
result.put("context",params.get(1));
result.put("stationNum",params.get(2));
result.put("projectId",params.get(3));
result.put("taskId",params.get(4));
result.put("name",params.get(5));
result.put("id",params.get(6));
IntStream.iterate(0,index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index)));
return result;
}

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java

@ -44,4 +44,7 @@ public class AnswerVO implements Serializable {
@ApiModelProperty("query对应的答案")
private String answer;
@ApiModelProperty("其它调用的参数")
private String[] extra;
}

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

@ -68,16 +68,15 @@ public class InteractiveSchedule {
@XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT execute(String params) {
List<String> sessionIds = InteractiveSessionManager.getSessionIds();
XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(",")));
List<AnswerVO> AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(",")));
XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList));
AnswerList.parallelStream().forEach(answerVO -> {
CompletableFuture.runAsync(() -> {
XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!");
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = new TextMessage(JSON.toJSONString(answerVO));
try {
session.sendMessage(message);
} catch (IOException e) {
XxlJobLogger.log("消息中心推送失败,推送内容为:" + JSON.toJSONString(answerVO));
}
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message);
}, getAnswerPoolExecutor);
});
return ReturnT.SUCCESS;

22
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

@ -1,6 +1,7 @@
package com.hnac.hzims.bigmodel.websocket.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import lombok.extern.slf4j.Slf4j;
@ -13,6 +14,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@ -46,8 +48,22 @@ public class InteractiveHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) {
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
R askResult = interactiveService.ask(message.getPayload(), InteractiveSessionManager.getEntryBySession(session).getKey());
log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult));
JSONObject messageJSON = JSONObject.parseObject(message.getPayload());
if("0".equals(messageJSON.getString("type"))) {
// 接收心跳消息,返回一条心跳消息
try {
session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else {
// 发送问题
String context = messageJSON.getString("context");
String userId = messageJSON.getString("userId");
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey(), userId);
log.info("返回结果为:"+ JSON.toJSONString(askResult));
}
}
}

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java

@ -19,13 +19,18 @@ import java.io.IOException;
public class InteractiveWsService implements WebSocketService {
@Override
public Boolean sendMessage(String signage, TextMessage message) {
WebSocketSession session = InteractiveSessionManager.get(signage);
public Boolean sendMessage(String sessionId, TextMessage message) {
WebSocketSession session = InteractiveSessionManager.get(sessionId);
return this.sendMessage(session,message);
}
@Override
public Boolean sendMessage(WebSocketSession session, TextMessage message) {
try {
session.sendMessage(message);
return true;
} catch (IOException e) {
log.error("消息推送失败,推送sessionId为:" + signage + ";消息体为:" + JSON.toJSONString(message));
log.error("消息推送失败;消息体为:" + JSON.toJSONString(message));
return false;
}
}

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java

@ -1,6 +1,7 @@
package com.hnac.hzims.bigmodel.websocket.service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
/**
* @Author: huangxing
@ -10,4 +11,6 @@ public interface WebSocketService {
Boolean sendMessage(String signage, TextMessage message);
Boolean sendMessage(WebSocketSession session, TextMessage message);
}

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java

@ -1,7 +1,10 @@
package com.hnac.hzims.bigmodel.websocket.sessionManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
@ -23,8 +26,6 @@ public class InteractiveSessionManager {
/** ws会话池 **/
public static ConcurrentHashMap<String, WebSocketSession> SESSION_POOL = new ConcurrentHashMap<>();
private static final Lock lock = new ReentrantLock();
/**
* 获取sessionIds
* @return sessionIds
@ -42,7 +43,7 @@ public class InteractiveSessionManager {
public static Map.Entry<String, WebSocketSession> getEntryBySession(WebSocketSession session) {
Set<Map.Entry<String, WebSocketSession>> sessionEntrySet = InteractiveSessionManager.SESSION_POOL.entrySet();
Optional<Map.Entry<String, WebSocketSession>> sessionIdOptional = sessionEntrySet.stream().filter(sessionEntry -> session.equals(sessionEntry.getValue())).findFirst();
if(sessionIdOptional.isPresent()) {
if(!sessionIdOptional.isPresent()) {
log.error("当前Session Pool未查询到相关session,消息推送失败");
throw new ServiceException("当前Session Pool未查询到相关session,消息推送失败");
}
@ -85,4 +86,11 @@ public class InteractiveSessionManager {
}
SESSION_POOL.remove(sessionId);
}
public static TextMessage getTextMessage(String type,String context) {
JSONObject message = new JSONObject();
message.put("type",type);
message.put("context",context);
return new TextMessage(JSON.toJSONString(message));
}
}

36
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainSystemMonitoringServiceImpl.java

@ -64,6 +64,8 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static com.hnac.hzims.operational.util.ObjectUtils.objDivide;
@Service
@Slf4j
@RequiredArgsConstructor
@ -1369,37 +1371,37 @@ public class MainSystemMonitoringServiceImpl implements IMainSystemMonitoringSer
Map<String, Float> value = deviceMap.getValue();
//当月发电量
BigDecimal powerMon = value.entrySet().stream().filter(s -> currentMon.equals(s.getKey())).map(s -> BigDecimal.valueOf(s.getValue()).setScale(1, RoundingMode.UP)).reduce(BigDecimal.ZERO, BigDecimal::add);
stationReportVO.setFinishPowerMon(powerMon.toString());
stationReportVO.setFinishPowerMon(objDivide(String.valueOf(powerMon)).toString());
//获取计划月发电量
R<Float> planPowerMonR = planGenertionClient.planGenerationMonthCount(stationEntity.getCode(), month);
double planPowerMon =0;
if (planPowerMonR.isSuccess()&&ObjectUtil.isNotEmpty(planPowerMonR.getData())) {
planPowerMon = planPowerMonR.getData().doubleValue();
}
stationReportVO.setPowerMonPlan(planPowerMon);
stationReportVO.setPowerMonPlan(objDivide(String.valueOf(planPowerMon)).doubleValue());
//当年发电量
BigDecimal powerYear = value.entrySet().stream().filter(s -> listByYear.contains(s.getKey())).map(s -> BigDecimal.valueOf(s.getValue()).setScale(1, RoundingMode.UP)).reduce(BigDecimal.ZERO, BigDecimal::add);
stationReportVO.setFinishPowerYear(powerYear.toString());
stationReportVO.setFinishPowerYear(objDivide(String.valueOf(powerYear)).toString());
//获取计划年发电量
Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationEntity.getId().toString()), yearMon[0]);
stationReportVO.setPowerYearPlan(planPowerYear);
Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationEntity.getCode()), yearMon[0]);
stationReportVO.setPowerYearPlan(objDivide(String.valueOf(planPowerYear)).doubleValue());
if (ObjectUtil.isNotEmpty(stationReportVO.getPowerMonPlan())
&&ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerMon())
&& BigDecimal.valueOf(stationReportVO.getPowerMonPlan()).compareTo(BigDecimal.ZERO)!=0){
BigDecimal monRate = new BigDecimal(stationReportVO.getFinishPowerMon()).multiply(new BigDecimal(100))
.divide(BigDecimal.valueOf(stationReportVO.getPowerMonPlan()), 2, RoundingMode.UP);
stationReportVO.setPowerMonRate(monRate.doubleValue()+"%");
stationReportVO.setPowerMonRate(String.valueOf(monRate.doubleValue()));
}else {
stationReportVO.setPowerMonRate(new Double(0)+"%");
stationReportVO.setPowerMonRate(new Double(0).toString());
}
if (ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerYear())
&&ObjectUtil.isNotEmpty(stationReportVO.getPowerYearPlan())
&& BigDecimal.valueOf(stationReportVO.getPowerYearPlan()).compareTo(BigDecimal.ZERO)!=0){
BigDecimal yearRate = new BigDecimal(stationReportVO.getFinishPowerYear()).multiply(new BigDecimal(100))
.divide(BigDecimal.valueOf(stationReportVO.getPowerYearPlan()), 2, RoundingMode.UP);
stationReportVO.setPowerYearRate(yearRate.doubleValue()+"%");
stationReportVO.setPowerYearRate(String.valueOf(yearRate.doubleValue()));
}else {
stationReportVO.setPowerYearRate(new Double(0)+"%");
stationReportVO.setPowerYearRate(new Double(0).toString());
}
reportVOS.add(stationReportVO);
}
@ -1474,33 +1476,33 @@ public class MainSystemMonitoringServiceImpl implements IMainSystemMonitoringSer
}
}
Double finishPowerMon = BigDecimal.valueOf(powerCount.get()).doubleValue();
stationReportVO.setFinishPowerMon(finishPowerMon.toString());
stationReportVO.setFinishPowerMon(objDivide(String.valueOf(finishPowerMon)).toString());
Double finishPowerYear = BigDecimal.valueOf(powerCountYear.get()).doubleValue();
stationReportVO.setFinishPowerYear(finishPowerYear.toString());
stationReportVO.setFinishPowerYear(objDivide(String.valueOf(finishPowerYear)).toString());
//当年的计划发电量
Double planPowerYear = planGenertionClient.getPlanPowerYear(Collections.singletonList(stationId), year);
stationReportVO.setPowerYearPlan(planPowerYear);
stationReportVO.setPowerYearPlan(objDivide(String.valueOf(planPowerYear)).doubleValue());
//当月的计划发电量
R<Float> planPowerMonR = planGenertionClient.planGenerationMonthCount(stationId, month);
Double planPowerMon = planPowerMonR.getData().doubleValue();
stationReportVO.setPowerMonPlan(planPowerMon);
stationReportVO.setPowerMonPlan(objDivide(String.valueOf(planPowerMon)).doubleValue());
if (ObjectUtil.isNotEmpty(stationReportVO.getPowerMonPlan())
&&ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerMon())
&& BigDecimal.valueOf(stationReportVO.getPowerMonPlan()).compareTo(BigDecimal.ZERO)!=0){
BigDecimal monRate = new BigDecimal(stationReportVO.getFinishPowerMon()).multiply(new BigDecimal(100))
.divide(BigDecimal.valueOf(stationReportVO.getPowerMonPlan()), 2, RoundingMode.UP);
stationReportVO.setPowerMonRate(monRate.doubleValue()+"%");
stationReportVO.setPowerMonRate(String.valueOf(monRate.doubleValue()));
}else {
stationReportVO.setPowerMonRate(new Double(0)+"%");
stationReportVO.setPowerMonRate(new Double(0).toString());
}
if (ObjectUtil.isNotEmpty(stationReportVO.getFinishPowerYear())
&&ObjectUtil.isNotEmpty(stationReportVO.getPowerYearPlan())
&& BigDecimal.valueOf(stationReportVO.getPowerYearPlan()).compareTo(BigDecimal.ZERO)!=0){
BigDecimal yearRate = new BigDecimal(stationReportVO.getFinishPowerYear()).multiply(new BigDecimal(100))
.divide(BigDecimal.valueOf(stationReportVO.getPowerYearPlan()), 2, RoundingMode.UP);
stationReportVO.setPowerYearRate(yearRate.doubleValue()+"%");
stationReportVO.setPowerYearRate(String.valueOf(yearRate.doubleValue()));
}else {
stationReportVO.setPowerYearRate(new Double(0)+"%");
stationReportVO.setPowerYearRate(new Double(0).toString());
}
stationReportVOList.add(stationReportVO);
return stationReportVOList;

45
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/OperStationMonthReportServiceImpl.java

@ -57,6 +57,7 @@ import org.springblade.system.vo.DeptVO;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -349,6 +350,7 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor
reportVOS.addAll(stationReportVOList);
});
}
getSumStationRunReport(reportVOS);
stationReportAllVo.setStationReportVOList(reportVOS);
}catch (Exception e){
log.error("", e);
@ -510,6 +512,49 @@ public class OperStationMonthReportServiceImpl implements IOperStationMonthRepor
return stationReportAllVo;
}
private static void getSumStationRunReport(List<StationRunReportVO> reportVOS) {
//合计
StationRunReportVO stationRunReportVO=new StationRunReportVO();
stationRunReportVO.setStationName("合计");
if (CollectionUtil.isNotEmpty(reportVOS)){
double sumPowerMonPlan = reportVOS.stream().mapToDouble(StationRunReportVO::getPowerMonPlan).sum();
stationRunReportVO.setPowerMonPlan(sumPowerMonPlan);
double sumFinishPowerMon = reportVOS.stream().map(StationRunReportVO::getFinishPowerMon).mapToDouble(s -> Double.valueOf(s)).sum();
stationRunReportVO.setFinishPowerMon(String.valueOf(sumFinishPowerMon));
if (!ObjectUtils.isEmpty(sumPowerMonPlan)) {
BigDecimal powerMonRate = new BigDecimal(sumFinishPowerMon).divide(new BigDecimal(sumPowerMonPlan)).setScale(2, BigDecimal.ROUND_UP);
stationRunReportVO.setPowerMonRate(String.valueOf(powerMonRate));
}else {
stationRunReportVO.setPowerMonRate("0.0");
}
double sumPowerYearPlan = reportVOS.stream().mapToDouble(StationRunReportVO::getPowerYearPlan).sum();
stationRunReportVO.setPowerYearPlan(sumPowerYearPlan);
double sumFinishPowerYear = reportVOS.stream().map(StationRunReportVO::getFinishPowerYear).mapToDouble(s -> Double.valueOf(s)).sum();
stationRunReportVO.setFinishPowerYear(String.valueOf(sumFinishPowerYear));
if (!ObjectUtils.isEmpty(sumPowerYearPlan)){
BigDecimal powerYearRate = new BigDecimal(sumFinishPowerYear).divide(new BigDecimal(sumPowerYearPlan)).setScale(2, BigDecimal.ROUND_UP);
stationRunReportVO.setPowerYearRate(String.valueOf(powerYearRate));
}else {
stationRunReportVO.setPowerYearRate("0.0");
}
stationRunReportVO.setIndex(reportVOS.size()+1);
}else {
stationRunReportVO.setPowerMonPlan(0.0d);
stationRunReportVO.setFinishPowerMon("0.0");
stationRunReportVO.setPowerYearPlan(0.0d);
stationRunReportVO.setFinishPowerYear("0.0");
stationRunReportVO.setPowerMonRate("0.0");
stationRunReportVO.setPowerYearRate("0.0");
stationRunReportVO.setIndex(1);
}
reportVOS.add(stationRunReportVO);
reportVOS = reportVOS.stream().map(s -> {
s.setPowerMonRate(s.getPowerMonRate()+"%");
s.setPowerYearRate(s.getPowerYearRate()+"%");
return s;
}).collect(Collectors.toList());
}
/**
* 导出统计月报
* @param response

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java

@ -10,6 +10,7 @@ import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -81,4 +82,10 @@ public class ObjectUtils {
}
return result;
}
public static BigDecimal objDivide(String s){
BigDecimal bigDecimal = new BigDecimal(s);
BigDecimal res = bigDecimal.divide(new BigDecimal(10000)).setScale(2, BigDecimal.ROUND_UP);
return res;
}
}

Loading…
Cancel
Save