parent
8862f60ea3
commit
886e034aae
@ -1,19 +0,0 @@
|
||||
package com.hw;
|
||||
|
||||
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
|
||||
// then press Enter. You can now see whitespace characters in your code.
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// Press Alt+Enter with your caret at the highlighted text to see how
|
||||
// IntelliJ IDEA suggests fixing it.
|
||||
System.out.printf("Hello and welcome!");
|
||||
|
||||
// Press Shift+F10 or click the green arrow button in the gutter to run the code.
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
|
||||
// Press Shift+F9 to start debugging your code. We have set one breakpoint
|
||||
// for you, but you can always add more by pressing Ctrl+F8.
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.hw.ems.report.service;
|
||||
|
||||
|
||||
import com.hw.common.core.domain.R;
|
||||
import com.hw.ems.base.domain.CbsMonitorReport;
|
||||
import com.hw.ems.base.domain.vo.CbsMonitorReportVo;
|
||||
import com.hw.ems.report.domain.EmsApiVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EMS与hw业态Service接口
|
||||
*
|
||||
* @author YinQ
|
||||
* @date 2023-04-05
|
||||
*/
|
||||
public interface IEmsApiService {
|
||||
|
||||
|
||||
/**
|
||||
* cbs获取抄表数据
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
List<CbsMonitorReportVo> getMeterReadingData(EmsApiVo emsApiVo);
|
||||
|
||||
|
||||
/**
|
||||
* CBS获取抄表数据定时任务
|
||||
* @return
|
||||
*/
|
||||
R<Boolean> meterReadingDataTimingTask();
|
||||
|
||||
|
||||
/**
|
||||
* cbs获取抄表数据返回接口
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
List<CbsMonitorReportVo> getMeterReadingDataInterface(EmsApiVo emsApiVo);
|
||||
|
||||
/**
|
||||
* 增删改cbs设备信息
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
String modifyDeviceInformation(EmsApiVo emsApiVo);
|
||||
}
|
@ -1,292 +0,0 @@
|
||||
package com.hw.ems.report.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import com.hw.common.core.domain.R;
|
||||
import com.hw.common.core.exception.ServiceException;
|
||||
import com.hw.common.core.exception.base.BaseException;
|
||||
import com.hw.common.core.utils.DateUtils;
|
||||
import com.hw.common.core.utils.StringUtils;
|
||||
import com.hw.common.security.utils.SecurityUtils;
|
||||
import com.hw.ems.base.domain.BaseMonitorInfo;
|
||||
import com.hw.ems.base.domain.CbsMonitorReport;
|
||||
import com.hw.ems.base.domain.SysDatasource;
|
||||
import com.hw.ems.base.domain.vo.CbsMonitorReportVo;
|
||||
import com.hw.ems.base.mapper.BaseMonitorInfo1Mapper;
|
||||
import com.hw.ems.base.mapper.CbsMonitorReportMapper;
|
||||
import com.hw.ems.base.service.ISysDatasourceService;
|
||||
import com.hw.ems.report.domain.EmsApiVo;
|
||||
import com.hw.ems.report.service.IEmsApiService;
|
||||
import com.hw.system.api.model.LoginUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* EMS与hw业态Service业务层处理
|
||||
*
|
||||
* @author YinQ
|
||||
* @date 2023-04-09
|
||||
*/
|
||||
@Service
|
||||
public class EmsAPIServiceImpl implements IEmsApiService {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private ISysDatasourceService datasourceService;
|
||||
|
||||
@Autowired
|
||||
private CbsMonitorReportMapper cbsMonitorReportMapper;
|
||||
|
||||
@Autowired
|
||||
private BaseMonitorInfo1Mapper monitorInfo1Mapper;
|
||||
|
||||
/**
|
||||
* cbs获取抄表数据
|
||||
*
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CbsMonitorReportVo> getMeterReadingData(EmsApiVo emsApiVo) {
|
||||
ArrayList<CbsMonitorReportVo> monitorReportVoArrayList = new ArrayList<>();
|
||||
//抄表时间(时间为空则默认当前时间
|
||||
if (StringUtils.isEmpty(emsApiVo.getMeterReadingTime())) {
|
||||
emsApiVo.setMeterReadingTime(DateUtils.getTime());
|
||||
}
|
||||
String poolName = null;
|
||||
if (StringUtils.isNotEmpty(emsApiVo.getParkCode())) {
|
||||
// 加载hw-cloud库的sys_datasource
|
||||
SysDatasource datasource = datasourceService.selectSysDatasourceByCbsParkCode(emsApiVo.getParkCode());
|
||||
poolName = datasource.getPoolName();
|
||||
} else {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
poolName = loginUser.getPoolName();
|
||||
}
|
||||
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
||||
// 多房间抄表, roomCode逗号分割
|
||||
if (StringUtils.isNotEmpty(emsApiVo.getRoomCode())) {
|
||||
CbsMonitorReport monitorReport = new CbsMonitorReport();
|
||||
monitorReport.setRoomCode(emsApiVo.getRoomCode());
|
||||
List<CbsMonitorReport> cbsMonitorReports = cbsMonitorReportMapper.selectCbsMonitorReportList(monitorReport);
|
||||
List<String> monitorIdList = cbsMonitorReports.stream().map(CbsMonitorReport::getMonitorId).collect(Collectors.toList());
|
||||
emsApiVo.setMonitorIdList(monitorIdList);
|
||||
}
|
||||
|
||||
try {
|
||||
//获取水电实时数据
|
||||
List<CbsMonitorReport> cbsMonitorReportList = this.getRealTimeData(emsApiVo);
|
||||
Date nowDate = DateUtils.getNowDate();
|
||||
for (CbsMonitorReport cbsMonitorReport : cbsMonitorReportList) {
|
||||
//查询上次抄表数据
|
||||
CbsMonitorReport lastTimeCbsMonitorReport = cbsMonitorReportMapper.selectLastTimeCbsMonitorReport(cbsMonitorReport);
|
||||
if (StringUtils.isNull(lastTimeCbsMonitorReport)) {
|
||||
cbsMonitorReport.setLastFlag("1");
|
||||
} else {
|
||||
cbsMonitorReport.setLastMonitorTime(lastTimeCbsMonitorReport.getThisMonitorTime());
|
||||
if (StringUtils.isNull(lastTimeCbsMonitorReport.getThisMonitorExpend())) {
|
||||
cbsMonitorReport.setLastFlag("1");
|
||||
} else {
|
||||
cbsMonitorReport.setLastFlag("0");
|
||||
cbsMonitorReport.setLastMonitorExpend(lastTimeCbsMonitorReport.getThisMonitorExpend());
|
||||
}
|
||||
}
|
||||
cbsMonitorReport.setCreateTime(nowDate);
|
||||
cbsMonitorReportMapper.insertCbsMonitorReport(cbsMonitorReport);
|
||||
}
|
||||
logger.info("service == getMeterReadingData == Info:" + emsApiVo + cbsMonitorReportList);
|
||||
|
||||
for (CbsMonitorReport reportOne : cbsMonitorReportList) {
|
||||
CbsMonitorReportVo cbsMonitorReportVo = new CbsMonitorReportVo();
|
||||
cbsMonitorReportVo.setRoomCode(reportOne.getRoomCode());
|
||||
cbsMonitorReportVo.setRoomName(reportOne.getRoomName());
|
||||
cbsMonitorReportVo.setPhysicalCode(reportOne.getPhysicalCode());
|
||||
cbsMonitorReportVo.setLoadingPosition(reportOne.getLoadingPosition());
|
||||
cbsMonitorReportVo.setMonitorType(reportOne.getMonitorType().equals("2") ? "电表" : "水表");
|
||||
if (reportOne.getPublicShareType().equals("0")){
|
||||
cbsMonitorReportVo.setPublicShareType("公共表");
|
||||
}else if (reportOne.getPublicShareType().equals("1")){
|
||||
cbsMonitorReportVo.setPublicShareType("单元表");
|
||||
}else {
|
||||
cbsMonitorReportVo.setPublicShareType("无");
|
||||
}
|
||||
cbsMonitorReportVo.setLastMonitorTime(reportOne.getLastMonitorTime());
|
||||
cbsMonitorReportVo.setLastMonitorExpend(reportOne.getLastMonitorExpend());
|
||||
cbsMonitorReportVo.setThisMonitorTime(reportOne.getThisMonitorTime());
|
||||
cbsMonitorReportVo.setThisMonitorExpend(reportOne.getThisMonitorExpend());
|
||||
monitorReportVoArrayList.add(cbsMonitorReportVo);
|
||||
}
|
||||
return monitorReportVoArrayList;
|
||||
} catch (Exception e) {
|
||||
logger.error("service == getMeterReadingData == exception:", e);
|
||||
throw new BaseException("service == getMeterReadingData == exception:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取水电实时数据
|
||||
*
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
@DS("#header.poolName")
|
||||
private List<CbsMonitorReport> getRealTimeData(EmsApiVo emsApiVo) {
|
||||
return cbsMonitorReportMapper.selectRealTimeMonitorList(emsApiVo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CBS获取抄表数据定时任务
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<Boolean> meterReadingDataTimingTask() {
|
||||
// 加载hw-cloud库的sys_datasource
|
||||
List<SysDatasource> dateSources = datasourceService.selectSysDatasource();
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(dateSources.size());
|
||||
try{
|
||||
dateSources.forEach(dateSource ->{
|
||||
logger.info("++++++++++++"+dateSource.getPoolName() +"++++开始++++++++++");
|
||||
EmsApiVo emsApiVo = new EmsApiVo();
|
||||
emsApiVo.setPoolName(dateSource.getPoolName());
|
||||
Runnable run = () -> getMeterReadingData(emsApiVo);
|
||||
executorService.execute(run);
|
||||
});
|
||||
}catch (Exception e){
|
||||
logger.error("service == dailyConsumptionTimingTask == exception", e);
|
||||
return R.fail("service == dailyConsumptionTimingTask == exception");
|
||||
}finally {
|
||||
executorService.shutdown();
|
||||
}
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抄表数据
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CbsMonitorReportVo> getMeterReadingDataInterface(EmsApiVo emsApiVo){
|
||||
List<CbsMonitorReportVo> monitorReportVoList = this.getMeterReadingData(emsApiVo);
|
||||
|
||||
ArrayList<CbsMonitorReportVo> monitorReportVoArrayList = new ArrayList<>();
|
||||
|
||||
// 使用 Collectors.groupingBy 收集具有相同 roomCode 值的对象
|
||||
Map<String, List<CbsMonitorReportVo>> groupedReports = monitorReportVoList.stream().collect(Collectors.groupingBy(CbsMonitorReportVo::getRoomCode));
|
||||
|
||||
// String result = null;
|
||||
try {
|
||||
for (String roomCode : groupedReports.keySet()) {
|
||||
CbsMonitorReportVo cbsMonitorReportVo = new CbsMonitorReportVo();
|
||||
List<CbsMonitorReportVo> cbsMonitorReports = groupedReports.get(roomCode);
|
||||
BigDecimal thisMonitorExpend = new BigDecimal(0);
|
||||
BigDecimal lastMonitorExpend = new BigDecimal(0);
|
||||
CbsMonitorReportVo reportOne = cbsMonitorReports.get(0);
|
||||
for (CbsMonitorReportVo report : cbsMonitorReports) {
|
||||
if (StringUtils.isNotNull(report.getThisMonitorExpend())){
|
||||
thisMonitorExpend = thisMonitorExpend.add(report.getThisMonitorExpend());
|
||||
|
||||
}
|
||||
if (StringUtils.isNotNull(report.getLastMonitorExpend())){
|
||||
lastMonitorExpend = lastMonitorExpend.add(report.getLastMonitorExpend());
|
||||
}
|
||||
}
|
||||
cbsMonitorReportVo.setRoomCode(reportOne.getRoomCode());
|
||||
cbsMonitorReportVo.setRoomName(reportOne.getRoomName());
|
||||
cbsMonitorReportVo.setPhysicalCode(reportOne.getPhysicalCode());
|
||||
cbsMonitorReportVo.setLoadingPosition(reportOne.getLoadingPosition());
|
||||
cbsMonitorReportVo.setMonitorType(reportOne.getMonitorType().equals("2") ? "电表" : "水表");
|
||||
if (reportOne.getPublicShareType().equals("0")){
|
||||
cbsMonitorReportVo.setPublicShareType("公共表");
|
||||
}else if (reportOne.getPublicShareType().equals("1")){
|
||||
cbsMonitorReportVo.setPublicShareType("单元表");
|
||||
}else {
|
||||
cbsMonitorReportVo.setPublicShareType("无");
|
||||
}
|
||||
cbsMonitorReportVo.setLastMonitorTime(reportOne.getLastMonitorTime());
|
||||
cbsMonitorReportVo.setLastMonitorExpend(lastMonitorExpend);
|
||||
cbsMonitorReportVo.setThisMonitorTime(reportOne.getThisMonitorTime());
|
||||
cbsMonitorReportVo.setThisMonitorExpend(thisMonitorExpend);
|
||||
monitorReportVoArrayList.add(cbsMonitorReportVo);
|
||||
}
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 将对象转换为 JSON 字符串
|
||||
// result = objectMapper.writeValueAsString(monitorReportVoArrayList);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
return monitorReportVoArrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增删改cbs设备信息
|
||||
* @param emsApiVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String modifyDeviceInformation(EmsApiVo emsApiVo) {
|
||||
Long modifyType = emsApiVo.getModifyType();
|
||||
String physicalCode = emsApiVo.getPhysicalCode();
|
||||
|
||||
String poolName = null;
|
||||
if (StringUtils.isNotEmpty(emsApiVo.getParkCode())) {
|
||||
// 加载hw-cloud库的sys_datasource
|
||||
SysDatasource datasource = datasourceService.selectSysDatasourceByCbsParkCode(emsApiVo.getParkCode());
|
||||
poolName = datasource.getPoolName();
|
||||
} else {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
poolName = loginUser.getPoolName();
|
||||
}
|
||||
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
||||
|
||||
BaseMonitorInfo monitorInfo = new BaseMonitorInfo();
|
||||
monitorInfo.setPhysicalCode(physicalCode);
|
||||
List<BaseMonitorInfo> monitorInfoList = monitorInfo1Mapper.selectBaseMonitorInfoList(monitorInfo);
|
||||
if (monitorInfoList.size() == 0){
|
||||
throw new ServiceException("service == modifyDeviceInformation == exception:该物理编号:" + physicalCode + "能源系统未维护!");
|
||||
}
|
||||
BaseMonitorInfo monitor = monitorInfoList.get(0);
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
//0-新增
|
||||
if (modifyType == 0L){
|
||||
monitor.setRoomCode(emsApiVo.getRoomCode());
|
||||
monitor.setRoomName(emsApiVo.getRoomName());
|
||||
monitorInfo1Mapper.updateBaseMonitorInfo(monitor);
|
||||
buffer.append("新增CBS设备信息接口|物理编号:").append(physicalCode);
|
||||
}
|
||||
|
||||
//1-删除
|
||||
if (modifyType == 1L){
|
||||
monitor.setRoomCode("");
|
||||
monitor.setRoomName("");
|
||||
monitorInfo1Mapper.updateBaseMonitorInfo(monitor);
|
||||
buffer.append("删除CBS设备信息接口|物理编号:").append(physicalCode);
|
||||
}
|
||||
|
||||
//2-修改
|
||||
if (modifyType == 2L){
|
||||
monitor.setRoomCode(emsApiVo.getRoomCode());
|
||||
monitor.setRoomName(emsApiVo.getRoomName());
|
||||
monitorInfo1Mapper.updateBaseMonitorInfo(monitor);
|
||||
buffer.append("修改CBS设备信息接口|物理编号:").append(physicalCode);
|
||||
}
|
||||
logger.info("service == modifyDeviceInformation == Info:" + emsApiVo + monitor);
|
||||
|
||||
return buffer.append("|调用成功!").toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue