diff --git a/hw-modules/hw-dms/src/main/java/com/hw/Main.java b/hw-modules/hw-dms/src/main/java/com/hw/Main.java deleted file mode 100644 index 6f6e053..0000000 --- a/hw-modules/hw-dms/src/main/java/com/hw/Main.java +++ /dev/null @@ -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); - } - } -} diff --git a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/controller/EmsApiController.java b/hw-modules/hw-ems/src/main/java/com/hw/ems/report/controller/EmsApiController.java deleted file mode 100644 index 5da2ade..0000000 --- a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/controller/EmsApiController.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.hw.ems.report.controller; - -import com.hw.common.core.domain.R; -import com.hw.common.core.exception.base.BaseException; -import com.hw.common.core.utils.StringUtils; -import com.hw.common.core.web.controller.BaseController; -import com.hw.common.core.web.domain.AjaxResult; -import com.hw.common.log.annotation.Log; -import com.hw.common.log.enums.BusinessType; -import com.hw.ems.report.domain.EmsApiVo; -import com.hw.ems.report.service.IEmsApiService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -/** - * EMS与hw业态接口 - * @Author Yinq - * @create 2023-07-26 17:58 - */ -@RestController -@RequestMapping("/emsApi") -public class EmsApiController extends BaseController { - - @Autowired - private IEmsApiService emsApiService; - - - /** - * cbs获取抄表数据 - * @param emsApiVo - * @return - */ - @PostMapping("/getMeterReadingData") - @Log(title = "CBS获取抄表数据", businessType = BusinessType.OTHER) - public AjaxResult getMeterReadingData(@RequestBody EmsApiVo emsApiVo) - { - return success(emsApiService.getMeterReadingData(emsApiVo)); - } - - /** - * cbs获取抄表数据返回接口 - * @param emsApiVo - * @return - */ - @PostMapping("/getMeterReadingDataInterface") - @Log(title = "cbs获取抄表数据返回接口", businessType = BusinessType.OTHER) - public AjaxResult getMeterReadingDataInterface(@RequestBody EmsApiVo emsApiVo) - { - return success(emsApiService.getMeterReadingDataInterface(emsApiVo)); - } - - - /** - * CBS获取抄表数据定时任务 - * @return - */ - @PostMapping("/meterReadingDataTimingTask") - @Log(title = "CBS获取抄表数据定时任务", businessType = BusinessType.OTHER) - public R meterReadingDataTimingTask() { - return emsApiService.meterReadingDataTimingTask(); - } - - /** - * 增删改cbs设备信息 - * @param emsApiVo - * @return - */ - @PostMapping("/modifyDeviceInformation") - @Log(title = "cbs获取抄表数据返回接口", businessType = BusinessType.OTHER) - public AjaxResult modifyDeviceInformation(@RequestBody EmsApiVo emsApiVo) - { - if (StringUtils.isNull(emsApiVo.getModifyType())){ - return error("service == modifyDeviceInformation == exception:请传修改类型(0-新增;1-删除;2-修改)!"); - } - if (StringUtils.isNull(emsApiVo.getPhysicalCode())){ - return error("service == modifyDeviceInformation == exception:请传物理编号!"); - } - return success(emsApiService.modifyDeviceInformation(emsApiVo)); - } - - - -} diff --git a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/domain/EmsApiVo.java b/hw-modules/hw-ems/src/main/java/com/hw/ems/report/domain/EmsApiVo.java deleted file mode 100644 index 1bc05d4..0000000 --- a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/domain/EmsApiVo.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.hw.ems.report.domain; - -import com.hw.common.core.web.domain.BaseEntity; - -import java.util.List; - -/** - * cbs接口传参 EmsApiVo - * - * @author YinQ - * @date 2023-09-13 - */ -public class EmsApiVo extends BaseEntity -{ - - private static final long serialVersionUID = 1L; - - - /** - * 抄表时间(时间为空则默认当前时间) - */ - private String meterReadingTime; - - /** - * cbs园区编号 - */ - private String parkCode; - - /** - * cbs单一抄表 - */ - private String roomCode; - - - /** - * cbs房间名称 - */ - private String roomName; - - /** - * ems园区编号 - */ - private String poolName; - - /** - * cbs单一抄表List - */ - private List monitorIdList; - - /** - * 修改类型(0-新增;1-删除;2-修改) - */ - private Long modifyType; - - /** - * CBS物理编号 - */ - private String physicalCode; - - public String getRoomName() { - return roomName; - } - - public void setRoomName(String roomName) { - this.roomName = roomName; - } - - public String getPhysicalCode() { - return physicalCode; - } - - public void setPhysicalCode(String physicalCode) { - this.physicalCode = physicalCode; - } - - public Long getModifyType() { - return modifyType; - } - - public void setModifyType(Long modifyType) { - this.modifyType = modifyType; - } - - @Override - public String getPoolName() { - return poolName; - } - - @Override - public void setPoolName(String poolName) { - this.poolName = poolName; - } - - public List getMonitorIdList() { - return monitorIdList; - } - - public void setMonitorIdList(List monitorIdList) { - this.monitorIdList = monitorIdList; - } - - public String getMeterReadingTime() { - return meterReadingTime; - } - - public void setMeterReadingTime(String meterReadingTime) { - this.meterReadingTime = meterReadingTime; - } - - public String getParkCode() { - return parkCode; - } - - public void setParkCode(String parkCode) { - this.parkCode = parkCode; - } - - public String getRoomCode() { - return roomCode; - } - - public void setRoomCode(String roomCode) { - this.roomCode = roomCode; - } - - @Override - public String toString() { - return "EmsApiVo{" + - "meterReadingTime='" + meterReadingTime + '\'' + - ", parkCode='" + parkCode + '\'' + - ", roomCode='" + roomCode + '\'' + - ", poolName='" + poolName + '\'' + - ", monitorIdList=" + monitorIdList + - ", modifyType=" + modifyType + - ", physicalCode='" + physicalCode + '\'' + - '}'; - } -} diff --git a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/IEmsApiService.java b/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/IEmsApiService.java deleted file mode 100644 index 1716b04..0000000 --- a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/IEmsApiService.java +++ /dev/null @@ -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 getMeterReadingData(EmsApiVo emsApiVo); - - - /** - * CBS获取抄表数据定时任务 - * @return - */ - R meterReadingDataTimingTask(); - - - /** - * cbs获取抄表数据返回接口 - * @param emsApiVo - * @return - */ - List getMeterReadingDataInterface(EmsApiVo emsApiVo); - - /** - * 增删改cbs设备信息 - * @param emsApiVo - * @return - */ - String modifyDeviceInformation(EmsApiVo emsApiVo); -} diff --git a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/impl/EmsAPIServiceImpl.java b/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/impl/EmsAPIServiceImpl.java deleted file mode 100644 index b9e7733..0000000 --- a/hw-modules/hw-ems/src/main/java/com/hw/ems/report/service/impl/EmsAPIServiceImpl.java +++ /dev/null @@ -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 getMeterReadingData(EmsApiVo emsApiVo) { - ArrayList 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 cbsMonitorReports = cbsMonitorReportMapper.selectCbsMonitorReportList(monitorReport); - List monitorIdList = cbsMonitorReports.stream().map(CbsMonitorReport::getMonitorId).collect(Collectors.toList()); - emsApiVo.setMonitorIdList(monitorIdList); - } - - try { - //获取水电实时数据 - List 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 getRealTimeData(EmsApiVo emsApiVo) { - return cbsMonitorReportMapper.selectRealTimeMonitorList(emsApiVo); - } - - - /** - * CBS获取抄表数据定时任务 - * @return - */ - @Override - public R meterReadingDataTimingTask() { - // 加载hw-cloud库的sys_datasource - List 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 getMeterReadingDataInterface(EmsApiVo emsApiVo){ - List monitorReportVoList = this.getMeterReadingData(emsApiVo); - - ArrayList monitorReportVoArrayList = new ArrayList<>(); - - // 使用 Collectors.groupingBy 收集具有相同 roomCode 值的对象 - Map> groupedReports = monitorReportVoList.stream().collect(Collectors.groupingBy(CbsMonitorReportVo::getRoomCode)); - - // String result = null; - try { - for (String roomCode : groupedReports.keySet()) { - CbsMonitorReportVo cbsMonitorReportVo = new CbsMonitorReportVo(); - List 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 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(); - } - - -}