From 13c17e7ec8a6475664ff8c6561ba9d588b5aceed Mon Sep 17 00:00:00 2001 From: bobol Date: Thu, 6 Jun 2024 09:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E8=B0=83=E7=94=A8IOT?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=A4=A9=E6=B0=94=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-test.yml | 8 +- .../common/config/IotServerApiConfig.java | 4 + .../asset/domain/dto/ChargeSystemDTO.java | 21 +++++ .../asset/service/ChargeSystemService.java | 74 +++++++++++++++-- .../DcBusiDataScreenMainController.java | 63 +++----------- .../service/DcBusiDataScreenMainService.java | 83 +++++++++++++------ .../mapper/DcBusiDataScreenMainMapper.xml | 37 +++++---- 7 files changed, 189 insertions(+), 101 deletions(-) create mode 100644 lzbi-module/src/main/java/com/lzbi/asset/domain/dto/ChargeSystemDTO.java diff --git a/lzbi-admin/src/main/resources/application-test.yml b/lzbi-admin/src/main/resources/application-test.yml index 9d26470..1416754 100644 --- a/lzbi-admin/src/main/resources/application-test.yml +++ b/lzbi-admin/src/main/resources/application-test.yml @@ -177,7 +177,7 @@ wechat: # 外部服务 goal-server: # iot平台服务地址 - iot: http://localhost:9010 + iot: http://10.10.10.56:9010 magic: http://10.10.10.56:9012/magic/api # 巡检系统服务 patrol: http://10.10.10.22:16882 @@ -202,8 +202,12 @@ iot-server-api: updateUser: ${goal-server.iot}/interior/sign/system/user # 删除用户 deleteUser: ${goal-server.iot}/interior/sign/system/user + # 获取天气 + weather: ${goal-server.iot}/biz/common/weather/oneLast -# magic api + +# + # 获取部门列表magic api magic-server-api: # 获取收费系统参数 chargeSystemParams: ${goal-server.magic}/charge/sqaure diff --git a/lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java b/lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java index 8e8d753..40e6f23 100644 --- a/lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java +++ b/lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java @@ -41,5 +41,9 @@ public class IotServerApiConfig { * 删除用户 */ private String deleteUser; + /** + * 天气 + */ + private String weather; } diff --git a/lzbi-module/src/main/java/com/lzbi/asset/domain/dto/ChargeSystemDTO.java b/lzbi-module/src/main/java/com/lzbi/asset/domain/dto/ChargeSystemDTO.java new file mode 100644 index 0000000..a68c174 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/asset/domain/dto/ChargeSystemDTO.java @@ -0,0 +1,21 @@ +package com.lzbi.asset.domain.dto; + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class ChargeSystemDTO { + + private String GUANLIDANWEI; + + private String REYUAN; + + private String HUANREZHAN; + + private String HUANREZHANID; + + private BigDecimal GONGNUANMIANJI; + + private BigDecimal KAISHUANYIZHIXING; +} diff --git a/lzbi-module/src/main/java/com/lzbi/asset/service/ChargeSystemService.java b/lzbi-module/src/main/java/com/lzbi/asset/service/ChargeSystemService.java index cfcc228..e1e9277 100644 --- a/lzbi-module/src/main/java/com/lzbi/asset/service/ChargeSystemService.java +++ b/lzbi-module/src/main/java/com/lzbi/asset/service/ChargeSystemService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.lzbi.asset.domain.ChargeSystemParamsDTO; import com.lzbi.asset.domain.DcBaseAssetContrastConfig; +import com.lzbi.asset.domain.dto.ChargeSystemDTO; import com.lzbi.asset.mapper.DcBaseAssetContrastConfigMapper; import com.lzbi.code.domain.DcBaseCoderuleDefineDao; import com.lzbi.code.domain.DcBusiCoderuleConfigDao; @@ -28,14 +29,12 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; +import java.math.BigDecimal; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -89,8 +88,8 @@ public class ChargeSystemService { Integer code = jsonObject.getInteger("code"); if (1 == code) { JSONArray jsonArray = jsonObject.getJSONArray("data"); +// new Thread(() -> parseData(jsonArray)).start(); if (!CollectionUtils.isEmpty(jsonArray)) { - log.info("收费系统换热站参数:{}", jsonArray.toJSONString()); this.createParamBill(jsonArray); } } else { @@ -101,6 +100,71 @@ public class ChargeSystemService { } } + private void parseData(JSONArray data) { + if (CollectionUtils.isEmpty(data)) { + log.error("收费系统返回数据为空"); + return; + } + List chargeSystemDTOList = JSONArray.parseArray(data.toJSONString(), ChargeSystemDTO.class); + Iterator iterator = chargeSystemDTOList.iterator(); + while (iterator.hasNext()) { + ChargeSystemDTO chargeSystemDTO = iterator.next(); + String guanlidanwei = chargeSystemDTO.getGUANLIDANWEI(); + String reyuan = chargeSystemDTO.getREYUAN(); + if (StringUtils.isNotBlank(guanlidanwei) && StringUtils.isNotBlank(reyuan)) { + String[] split = guanlidanwei.split(">"); + chargeSystemDTO.setGUANLIDANWEI(split[0]); + } else { + iterator.remove(); + } + } + JSONArray jituanArray = new JSONArray(); + JSONObject jituanObject = new JSONObject(); + jituanObject.put("name", "集团"); + BigDecimal jituanGongnuanmianjiSum = new BigDecimal(0D); + BigDecimal jituanKaisuanyizhixingmianjiSum = new BigDecimal(0D); + JSONArray guanlidanweiArray = new JSONArray(); + Map> guanlidanweiGroupMap = chargeSystemDTOList.stream().collect(Collectors.groupingBy(ChargeSystemDTO::getGUANLIDANWEI)); + Set guanlidanweiSet = guanlidanweiGroupMap.keySet(); + for (String guanlidanwei : guanlidanweiSet) { + List guanlidanweiList = guanlidanweiGroupMap.get(guanlidanwei); + JSONObject guanlidanweiObject = new JSONObject(); + guanlidanweiObject.put("name", guanlidanwei); + JSONArray reyuanArray = new JSONArray(); + BigDecimal guanlidanweiGongnuanmianjiSum = new BigDecimal(0D); + BigDecimal guanlidanweiKaisuanyizhixingmianjiSum = new BigDecimal(0D); + Map> reyuanGroupMap = guanlidanweiList.stream().collect(Collectors.groupingBy(ChargeSystemDTO::getREYUAN)); + Set reyuanSet = reyuanGroupMap.keySet(); + for (String reyuan : reyuanSet) { + List reyuanList = reyuanGroupMap.get(reyuan); + JSONObject reyuanObject = new JSONObject(); + reyuanObject.put("name", reyuan); + BigDecimal reyuanGongnuanmianjiSum = new BigDecimal(0); + BigDecimal reyuanKaisuanyizhixingmianjiSum = new BigDecimal(0); + for (ChargeSystemDTO chargeSystemDTO : reyuanList) { + reyuanGongnuanmianjiSum = reyuanGongnuanmianjiSum.add(chargeSystemDTO.getGONGNUANMIANJI()); + reyuanKaisuanyizhixingmianjiSum = reyuanKaisuanyizhixingmianjiSum.add(chargeSystemDTO.getKAISHUANYIZHIXING()); + } + guanlidanweiGongnuanmianjiSum = guanlidanweiGongnuanmianjiSum.add(reyuanGongnuanmianjiSum); + guanlidanweiKaisuanyizhixingmianjiSum = guanlidanweiKaisuanyizhixingmianjiSum.add(reyuanKaisuanyizhixingmianjiSum); + reyuanObject.put("gongnuanmianji", reyuanGongnuanmianjiSum); + reyuanObject.put("kaishuanyizhixingmianji", reyuanKaisuanyizhixingmianjiSum); + reyuanArray.add(reyuanObject); + } + guanlidanweiObject.put("gongnuanmianji", guanlidanweiGongnuanmianjiSum); + guanlidanweiObject.put("kaishuanyizhixingmianji", guanlidanweiKaisuanyizhixingmianjiSum); + guanlidanweiObject.put("children", reyuanArray); + guanlidanweiArray.add(guanlidanweiObject); + jituanGongnuanmianjiSum = jituanGongnuanmianjiSum.add(guanlidanweiGongnuanmianjiSum); + jituanKaisuanyizhixingmianjiSum = jituanKaisuanyizhixingmianjiSum.add(guanlidanweiKaisuanyizhixingmianjiSum); + } + jituanObject.put("gongnuanmianji", jituanGongnuanmianjiSum); + jituanObject.put("kaishuanyizhixingmianji", jituanKaisuanyizhixingmianjiSum); + jituanObject.put("children", guanlidanweiArray); + jituanArray.add(jituanObject); + log.info("收费系统返回数据:{}", jituanArray.toJSONString()); + } + private void createParamBill(JSONArray jsonArray) { LocalDateTime localDateTime = LocalDateTime.now(); int hour = localDateTime.getHour(); diff --git a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java index 5fd7b0c..89bf5e7 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java @@ -1,27 +1,23 @@ package com.lzbi.bi.controller; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.lzbi.bi.domain.req.ReportDataReq; import com.lzbi.bi.service.DcBusiDataScreenMainService; - +import com.lzbi.common.config.IotServerApiConfig; import com.lzbi.common.core.controller.BaseController; import com.lzbi.common.core.domain.AjaxResult; import com.lzbi.common.core.domain.TreeSelect; import com.lzbi.common.core.domain.entity.SysDept; -import com.lzbi.bi.domain.req.ReportDataReq; import com.lzbi.system.service.impl.SysDeptServiceImpl; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.lang.Nullable; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; import java.util.List; -import java.util.Optional; /** * 主数据大屏的页面接口 @@ -41,6 +37,12 @@ public class DcBusiDataScreenMainController extends BaseController { @Autowired private SysDeptServiceImpl sysDeptService; + @Autowired + private IotServerApiConfig iotServerApiConfig; + + @Autowired + private RestTemplate restTemplate; + /** * 获取某个组织某天的某个图表数据 * @@ -151,52 +153,9 @@ public class DcBusiDataScreenMainController extends BaseController { return AjaxResult.success(dcBusiDataScreenMainService.selectSomeReportDataRankingList(reportDataReq)); } - /** - * 获取天气信息 - */ - @Value("${luenmeilz.baiduWeatherURL}") - String weatherUrl; - @Value("${luenmeilz.baiduWeatherAK}") - String weathAK; - @Value("${luenmeilz.yikeapiAppid}") - String yikeapiAppid; - @Value("${luenmeilz.yikeapiAppsecret}") - String yikeapiAppsecret; - @GetMapping("/weather/{areaCode}") - public AjaxResult getWeather(@PathVariable String areaCode) { - JSONObject ret = new JSONObject(); - String url = StrUtil.format("https://v1.yiketianqi.com/free/week?city=沈阳&unescape=1&appid={}&appsecret={}", yikeapiAppid, yikeapiAppsecret); - JSONObject weather = JSONObject.parseObject(HttpUtil.get(url)); - log.debug("天气接口返回数据:{}", weather); - JSONArray weatherInfo = Optional.ofNullable(weather.getJSONArray("data")).orElse(new JSONArray()); - if (null != weatherInfo && !weatherInfo.isEmpty()) { - JSONArray we_date = new JSONArray(); - JSONArray we_name = new JSONArray(); - JSONArray tem_day = new JSONArray(); - JSONArray tem_night = new JSONArray(); - we_date.add("天气日期:"); - we_name.add("天气情况:"); - tem_day.add("日间气温:"); - tem_night.add("夜间气温:"); - weatherInfo.forEach(item -> { - JSONObject jsb = JSONObject.from(item); - we_date.add(jsb.getString("date")); - tem_day.add(jsb.getString("tem_day")); - tem_night.add(jsb.getString("tem_night")); - we_name.add(jsb.getString("wea")); - }); - JSONArray list = new JSONArray(); - list.add(we_date); - list.add(tem_day); - list.add(tem_night); - list.add(we_name); - ret.put("source", list); - ret.put("realwe", weatherInfo.get(0)); - } else { - log.error("天气接口未返回数据"); - } - return AjaxResult.success(ret); + public JSONObject getWeather(@PathVariable String areaCode) { + return restTemplate.getForObject(iotServerApiConfig.getWeather(), JSONObject.class, areaCode); } @PostMapping("/mapInfo") diff --git a/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenMainService.java b/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenMainService.java index 76f828a..c4a9610 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenMainService.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenMainService.java @@ -9,20 +9,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lzbi.bi.domain.DcBusiDataScreenDto; import com.lzbi.bi.domain.SysDeptLocation; import com.lzbi.bi.domain.dto.MultiOrgSomeReportEverydayData; -import com.lzbi.bi.domain.dto.SomeOrgSomedaySomeParamSummarizingDataDTO; +import com.lzbi.bi.domain.dto.SomeOrgSomedayMultiReportDataDTO; +import com.lzbi.bi.domain.dto.SomeTypeChildrenOrgSomedayMultiReportDataDTO; import com.lzbi.bi.domain.req.ParamSummarizingDataReq; +import com.lzbi.bi.domain.req.ReportDataReq; import com.lzbi.bi.domain.vo.*; import com.lzbi.bi.mapper.DcBusiDataScreenMainMapper; -import com.lzbi.bi.mapper.ScreenMockDataMapper; import com.lzbi.common.constant.BizConstants; import com.lzbi.common.constant.ParamsModelCodeConstants; import com.lzbi.common.core.domain.entity.SysDept; import com.lzbi.common.enums.ReportNameEnum; -import com.lzbi.bi.domain.dto.SomeOrgSomedayMultiReportDataDTO; -import com.lzbi.bi.domain.dto.SomeTypeChildrenOrgSomedayMultiReportDataDTO; -import com.lzbi.bi.domain.req.ReportDataReq; import com.lzbi.common.utils.bean.BeanUtils; -import com.lzbi.draft.domain.vo.*; +import com.lzbi.draft.domain.vo.TargetDraftDaynewResVo; import com.lzbi.draft.service.DcBusiTargetDraftDaynewService; import com.lzbi.system.service.ISysDeptService; import lombok.extern.slf4j.Slf4j; @@ -35,7 +33,9 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -87,12 +87,12 @@ public class DcBusiDataScreenMainService extends ServiceImpl(); - SPECIAL_REPORT_LIST.add(GRMJ); - SPECIAL_REPORT_LIST.add(LWMJ); +// SPECIAL_REPORT_LIST.add(GRMJ); +// SPECIAL_REPORT_LIST.add(LWMJ); SPECIAL_REPORT_LIST.add(AQGR); SPECIAL_REPORT_LIST.add(RY); SPECIAL_REPORT_LIST.add(HRZ); - SPECIAL_REPORT_LIST.add(ZMJ); +// SPECIAL_REPORT_LIST.add(ZMJ); } /** @@ -100,16 +100,31 @@ public class DcBusiDataScreenMainService extends ServiceImpl selectChildrenOrgSomedaySomeReportDataList(ReportDataReq reportDataReq) { this.buildChildrenOrgReportDataReq(reportDataReq); - return baseMapper.selectChildrenOrgSomedaySomeReportDataList(reportDataReq); + List result = baseMapper.selectChildrenOrgSomedaySomeReportDataList(reportDataReq); + if (CollectionUtils.isEmpty(result)) { + return null; + } + return result; } public List selectChildrenOrgSomedaySomeReportDataEchart(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result = null; List data = this.selectChildrenOrgSomedaySomeReportDataList(reportDataReq); if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); JSONArray head = new JSONArray(); head.add("name"); JSONArray body = new JSONArray(); @@ -194,9 +214,10 @@ public class DcBusiDataScreenMainService extends ServiceImpl selectChildrenOrgSomedaySomeReportDataEchartHaveOrgId(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result = null; List data = this.selectChildrenOrgSomedaySomeReportDataList(reportDataReq); if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); JSONArray head = new JSONArray(); head.add("name"); JSONArray body = new JSONArray(); @@ -216,9 +237,10 @@ public class DcBusiDataScreenMainService extends ServiceImpl selectChildrenOrgSomedaySomeReportDataEchartStacking(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result = null; List data = this.selectChildrenOrgSomedaySomeReportDataList(reportDataReq); - if (!CollectionUtils.isEmpty(data)) {; + if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); JSONArray head = new JSONArray(); head.add("name"); result.add(head); @@ -247,13 +269,14 @@ public class DcBusiDataScreenMainService extends ServiceImpl(); + return null; } public List selectChildrenOrgSomedayMultiReportDataBar(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result; List data = this.selectSomeTypeChildrenOrgSomedayMultiReportDataDTOList(reportDataReq); if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); List reportNames = reportDataReq.getReportNames(); JSONArray head = new JSONArray(); head.add("name"); @@ -271,15 +294,18 @@ public class DcBusiDataScreenMainService extends ServiceImpl selectSomeOrgSomeMultiReportYearlyDataMultiEchart(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result; List reportNames = reportDataReq.getReportNames(); List data = this.selectSomeOrgSomeReportYearlyDataList(reportDataReq); if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); JSONArray head = new JSONArray(); head.add("name"); result.add(head); @@ -300,22 +326,29 @@ public class DcBusiDataScreenMainService extends ServiceImpl selectMapOrgList(ReportDataReq reportDataReq) { this.buildChildrenOrgReportDataReq(reportDataReq); - return baseMapper.selectMapOrgList(reportDataReq); + List result = baseMapper.selectMapOrgList(reportDataReq); + if (CollectionUtils.isEmpty(result)) { + return null; + } + return result; } public List selectSomeReportDataRankingList(ReportDataReq reportDataReq) { - List result = new ArrayList<>(); + List result; this.buildChildrenOrgReportDataReq(reportDataReq); this.buildHeatingDate(reportDataReq); List data = baseMapper.selectChildOrgSomeReportEverydayDataList(reportDataReq); log.info("排名数据:{}", JSONArray.toJSONString(data)); if (!CollectionUtils.isEmpty(data)) { + result = new ArrayList<>(); // 排序后的日期列表 List dateSoredList = data.stream().map(MultiOrgSomeReportEverydayData::getDate).collect(Collectors.toSet()).stream().sorted().collect(Collectors.toList()); // 排序后的组织id列表 @@ -343,6 +376,8 @@ public class DcBusiDataScreenMainService extends ServiceImpl SELECT - t1.value_result, - t1.value_plan + concat(t1.value_result, '') AS "valueResult", + concat(t1.value_plan, '') AS "valuePlan" FROM dc_busi_target_draft_daynew t1 INNER JOIN dc_base_asset_target t2 ON t1.target_code = t2.target_code @@ -341,7 +341,8 @@ SELECT t5.dept_id as "orgId", t5.dept_name as "orgName", - t1.value_result + t1.value_result, + t1.value_plan FROM dc_busi_target_draft_daynew t1 INNER JOIN dc_base_asset_target t2 ON t1.target_code = t2.target_code @@ -454,28 +455,28 @@ tt.number FROM sys_dept t - LEFT JOIN ( + LEFT JOIN ( SELECT - t5.dept_id, - SUM( t1.val_last ) as "number" + t4.dept_id, + t1.value_result AS "number" FROM - dc_busi_param_draft_day t1 - INNER JOIN dc_base_asset_target t2 ON t1.param_code = t2.target_code - AND t2.column_type = "P" - AND t2.target_model_code = "P00001" + dc_busi_target_draft_daynew t1 + INNER JOIN dc_base_asset_target t2 ON t1.target_code = t2.target_code + AND t2.column_type = "T" + AND t2.target_model_code = "00086" INNER JOIN dc_base_asset_info t3 ON t2.asset_code = t3.asset_code INNER JOIN sys_dept t4 ON t3.org_id = t4.dept_id - AND t3.asset_level = "30" - AND t3.asset_type = "1" - INNER JOIN sys_dept t5 ON FIND_IN_SET( t5.dept_id, concat( t4.ancestors, ",", t4.dept_id ) ) + AND t3.asset_level = #{assetLevel} + AND t3.asset_type = #{assetType} WHERE - t5.parent_id = #{orgId} - AND t1.count_date = CONCAT( #{dateYear}, '-', #{dateMonth}, '-', #{dateDay} ) - GROUP BY - t5.dept_id + FIND_IN_SET( #{orgId}, concat( t4.ancestors ) ) + AND t4.org_type = #{orgType} + AND t1.date_year = #{dateYear} + AND t1.date_month = #{dateMonth} + AND t1.date_day = #{dateDay} ) tt ON t.dept_id = tt.dept_id WHERE - t.parent_id = #{orgId} + FIND_IN_SET( #{orgId}, concat( t.ancestors ) ) AND t.org_type = #{orgType}