diff --git a/user-service/pom.xml b/user-service/pom.xml
index 854ea4b..7843d51 100644
--- a/user-service/pom.xml
+++ b/user-service/pom.xml
@@ -174,6 +174,13 @@
org.springframework.boot
spring-boot-starter-amqp
+
+
+ com.alibaba
+ easyexcel
+ 3.2.1
+
+
diff --git a/user-service/src/main/java/com/mh/user/aspect/DictDataTranslateAsp.java b/user-service/src/main/java/com/mh/user/aspect/DictDataTranslateAsp.java
index fe51199..b2d70ac 100644
--- a/user-service/src/main/java/com/mh/user/aspect/DictDataTranslateAsp.java
+++ b/user-service/src/main/java/com/mh/user/aspect/DictDataTranslateAsp.java
@@ -86,7 +86,7 @@ public class DictDataTranslateAsp {
*/
private void translateDict(FieldParam fieldParam, Pattern fieldPattern, Matcher fieldMatcher, StringBuffer sb) {
//从缓存中一次性取值
- List dictNames = sysDictService.findByType(fieldParam.type());
+ List dictNames = sysDictService.findCacheByType(fieldParam.type());
while (fieldMatcher.find()) {
//取出要翻译字段对应的值
Matcher dictValueMatcher = fieldPattern.matcher(fieldMatcher.group());
diff --git a/user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java b/user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java
index 637a2f6..6732f53 100644
--- a/user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java
+++ b/user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java
@@ -42,36 +42,36 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf
-// System.out.println("test0");
-// http.cors().and().csrf().disable()
-// .authorizeRequests()
-// // 跨域预检请求
-// .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
-// // web jars
-// .antMatchers("/webjars/**").permitAll()
-// // 查看SQL监控(druid)
-// .antMatchers("/druid/**").permitAll()
-// // 首页和登录页面
-// .antMatchers("/").permitAll()
-// .antMatchers("/login").permitAll()
-// // swagger
-// .antMatchers("/swagger-ui.html").permitAll()
-// .antMatchers("/swagger-resources/**").permitAll()
-// .antMatchers("/v2/api-docs").permitAll()
-// .antMatchers("/webjars/springfox-swagger-ui/**").permitAll()
-// // 验证码
-// .antMatchers("/captcha.jpg**").permitAll()
-// // 服务监控
-// .antMatchers("/actuator/**").permitAll()
-// // 其他所有请求需要身份认证
-// .anyRequest().authenticated();
-// // 退出登录处理器
-// http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
-// // token验证过滤器
-// http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
-// System.out.println("test0_1");
+ System.out.println("test0");
+ http.cors().and().csrf().disable()
+ .authorizeRequests()
+ // 跨域预检请求
+ .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
+ // web jars
+ .antMatchers("/webjars/**").permitAll()
+ // 查看SQL监控(druid)
+ .antMatchers("/druid/**").permitAll()
+ // 首页和登录页面
+ .antMatchers("/").permitAll()
+ .antMatchers("/login").permitAll()
+ // swagger
+ .antMatchers("/swagger-ui.html").permitAll()
+ .antMatchers("/swagger-resources/**").permitAll()
+ .antMatchers("/v2/api-docs").permitAll()
+ .antMatchers("/webjars/springfox-swagger-ui/**").permitAll()
+ // 验证码
+ .antMatchers("/captcha.jpg**").permitAll()
+ // 服务监控
+ .antMatchers("/actuator/**").permitAll()
+ // 其他所有请求需要身份认证
+ .anyRequest().authenticated();
+ // 退出登录处理器
+ http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
+ // token验证过滤器
+ http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
+ System.out.println("test0_1");
// 禁用token验证
- http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
+// http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
}
@Bean
diff --git a/user-service/src/main/java/com/mh/user/controller/DataResultController.java b/user-service/src/main/java/com/mh/user/controller/DataResultController.java
index 6ad5d4b..b86598b 100644
--- a/user-service/src/main/java/com/mh/user/controller/DataResultController.java
+++ b/user-service/src/main/java/com/mh/user/controller/DataResultController.java
@@ -1,17 +1,27 @@
package com.mh.user.controller;
+import com.alibaba.excel.EasyExcel;
import com.mh.common.http.HttpResult;
import com.mh.user.annotation.SysLogger;
+import com.mh.user.dto.ExportBaseResultDTO;
import com.mh.user.entity.DataResultChEntity;
import com.mh.user.entity.DataResultEntity;
import com.mh.user.service.BuildingService;
import com.mh.user.service.DataResultService;
+import com.mh.user.utils.CenterCellStyleWriteHandler;
+import com.mh.user.utils.DateUtil;
import com.mh.user.utils.ExchangeStringUtil;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.stream.Collectors;
+@Slf4j
@RestController
@RequestMapping("dataResult")
public class DataResultController {
@@ -51,47 +61,77 @@ public class DataResultController {
@RequestParam(value= "curDate", required=false)String curDate,
@RequestParam(value="page", required=false) int page,
@RequestParam(value="limit", required=false) int limit) {
- try{
- if(projectId!=null && projectId.length()>0){
- String startDate="";
- curDate=curDate.substring(0,16)+":00";
- if (dateType.equals("1小时")){
- startDate= ExchangeStringUtil.dateRoll(1,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
- int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }else if (dateType.equals("2小时")){
- startDate=ExchangeStringUtil.dateRoll(2,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
- int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }else if (dateType.equals("8小时")){
- startDate=ExchangeStringUtil.dateRoll(8,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
- int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }else if (dateType.equals("12小时")){
- startDate=ExchangeStringUtil.dateRoll(12,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
- int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }else if (dateType.equals("24小时")){
- startDate=ExchangeStringUtil.dateRoll(24,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,2);
- int count=dataResultService.dataResultFifteenMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }else{ //1小时
- startDate=ExchangeStringUtil.dateRoll(1,curDate);
- List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
- int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
- return HttpResult.ok(count,records);
- }
- }else{
- return HttpResult.error();
- }
- }catch (Exception e){
-// e.printStackTrace();
- return HttpResult.error();
+ return dataResultService.queryDataResultMiData(projectId,curDate,page,limit,0,dateType);
+// try{
+// if(projectId!=null && projectId.length()>0){
+// String startDate="";
+// curDate=curDate.substring(0,16)+":00";
+// if (dateType.equals("1小时")){
+// startDate= ExchangeStringUtil.dateRoll(1,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+// int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }else if (dateType.equals("2小时")){
+// startDate=ExchangeStringUtil.dateRoll(2,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+// int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }else if (dateType.equals("8小时")){
+// startDate=ExchangeStringUtil.dateRoll(8,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
+// int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }else if (dateType.equals("12小时")){
+// startDate=ExchangeStringUtil.dateRoll(12,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
+// int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }else if (dateType.equals("24小时")){
+// startDate=ExchangeStringUtil.dateRoll(24,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,2);
+// int count=dataResultService.dataResultFifteenMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }else{ //1小时
+// startDate=ExchangeStringUtil.dateRoll(1,curDate);
+// List records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+// int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
+// return HttpResult.ok(count,records);
+// }
+// }else{
+// return HttpResult.error();
+// }
+// }catch (Exception e){
+//// e.printStackTrace();
+// return HttpResult.error();
+// }
+ }
+
+ @SysLogger(value="中央空调",optDesc = "能效监测导出excel")
+ @PostMapping(value="/hour/export")
+ public void exportDataResultMi(@RequestParam(value = "projectId", required=false)String projectId,
+ @RequestParam(value= "dateType", required=false)String dateType,
+ @RequestParam(value= "curDate", required=false)String curDate,
+ @RequestParam(value="page", required=false) int page,
+ @RequestParam(value="limit", required=false) int limit, HttpServletResponse response) {
+ try {
+ // 文件名
+ String fileName = "能效监测实时记录表.xlsx";
+ // 设置响应格式
+ response.setContentType("application/vdn.ms-excel;charset=utf-8");
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileName, "UTF-8") + "\"");
+ response.setCharacterEncoding("UTF-8");
+ // 从数据库获取数据
+ List records = (List) dataResultService.queryDataResultMiData(projectId,curDate,page,limit,0, dateType).getData();
+ List anotherEntities = records.stream()
+ .map(entity -> new ExportBaseResultDTO(entity.getProjectName(), DateUtil.dateToString(entity.getCurDate(), "yyyy-MM-dd HH:mm:ss"), entity.getCurValue()))
+ .collect(Collectors.toList());
+ EasyExcel.write(response.getOutputStream(), ExportBaseResultDTO.class)
+ .registerWriteHandler(new CenterCellStyleWriteHandler())
+ .sheet("能效监测实时记录表")
+ .doWrite(anotherEntities);
+ } catch (Exception e) {
+ log.error("导出异常==>", e);
+ throw new RuntimeException("下载报表异常");
}
}
diff --git a/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java b/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
index d047ac4..461cfee 100644
--- a/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
@@ -27,7 +27,11 @@ public class DevicesManageController {
@SysLogger(value = "资产管理信息", optDesc = "查询资产管理信息")
@PostMapping("/findByPage")
- @TranslationDict({@FieldParam(type = "device_type", targetField = "deviceType", targetFieldValueClazz = Integer.class)})
+ @TranslationDict({
+ @FieldParam(type = "device_type", targetField = "deviceType", targetFieldValueClazz = Integer.class),
+ @FieldParam(type = "project_name", targetField = "projectId", targetFieldValueClazz = Integer.class),
+ @FieldParam(type = "system_type", targetField = "systemId", targetFieldValueClazz = Integer.class)
+ })
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {
return devicesManageService.queryByPage(pageRequest);
}
diff --git a/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java b/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
index 6819291..9887c78 100644
--- a/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
+++ b/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
@@ -3,7 +3,9 @@ package com.mh.user.controller;
import com.mh.common.http.HttpResult;
import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult;
+import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger;
+import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.DeviceParamsEntity;
import com.mh.user.service.DeviceParamsService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +25,9 @@ public class DevicesParamsController {
@Autowired
private DeviceParamsService deviceParamsService;
+ @TranslationDict({
+ @FieldParam(type = "mt_type", targetField = "mtType", targetFieldValueClazz = Integer.class)
+ })
@SysLogger(value="设备参数管理",optDesc = "查询设备参数管理")
@PostMapping("/findByPage")
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {
diff --git a/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java b/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
index 39e4e15..7635cc5 100644
--- a/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
@@ -3,7 +3,9 @@ package com.mh.user.controller;
import com.mh.common.http.HttpResult;
import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult;
+import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger;
+import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.GatewayManageEntity;
import com.mh.user.service.GatewayManageService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +25,12 @@ public class GatewayManageController {
@Autowired
private GatewayManageService gatewayManageService;
-
+
+ @TranslationDict({
+ @FieldParam(type = "operator_type", targetField = "operatorType", targetFieldValueClazz = Integer.class),
+ @FieldParam(type = "communication_type", targetField = "communicationType", targetFieldValueClazz = Integer.class),
+ @FieldParam(type = "project_name", targetField = "projectId", targetFieldValueClazz = Integer.class),
+ })
@SysLogger(value="网关管理信息",optDesc = "查询网关管理信息")
@PostMapping("/findByPage")
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {
diff --git a/user-service/src/main/java/com/mh/user/controller/MeterManageController.java b/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
index 9f07915..517b936 100644
--- a/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
@@ -25,10 +25,11 @@ public class MeterManageController {
@Autowired
private MeterManageService meterManageService;
- @TranslationDict({@FieldParam(type = "device_type", targetField = "deviceType", targetFieldValueClazz = Integer.class),
+ @TranslationDict({@FieldParam(type = "mt_type", targetField = "mtType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "communication_type", targetField = "communicationType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "data_type", targetField = "dataType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "protocol_type", targetField = "protocolType", targetFieldValueClazz = Integer.class),
+ @FieldParam(type = "project_name", targetField = "projectId", targetFieldValueClazz = Integer.class),
})
@SysLogger(value="仪表管理信息",optDesc = "查询仪表管理信息")
@PostMapping("/findByPage")
diff --git a/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java b/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
index b057267..5135868 100644
--- a/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
+++ b/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
@@ -3,7 +3,9 @@ package com.mh.user.controller;
import com.mh.common.http.HttpResult;
import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult;
+import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger;
+import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.ProjectInfoEntity;
import com.mh.user.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +28,9 @@ public class ProjectInfoController {
return HttpResult.ok(list);
}
+ @TranslationDict({
+ @FieldParam(type = "system_type", targetField = "systemId", targetFieldValueClazz = Integer.class)
+ })
@SysLogger(value="项目信息",optDesc = "查询项目信息")
@PostMapping("/findByPage")
public PageResult queryProject(@RequestBody PageRequest pageRequest) {
diff --git a/user-service/src/main/java/com/mh/user/dto/ExportBaseResultDTO.java b/user-service/src/main/java/com/mh/user/dto/ExportBaseResultDTO.java
new file mode 100644
index 0000000..45c89a8
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/dto/ExportBaseResultDTO.java
@@ -0,0 +1,41 @@
+package com.mh.user.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentStyle;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 数据结果集基本类
+ * @date 2024-07-10 16:49:24
+ */
+@Data
+@HeadRowHeight(value = 20)
+@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)//内容样式
+public class ExportBaseResultDTO {
+
+ @ColumnWidth(value = 18)
+ @ExcelProperty(value = "时间", index = 1)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+ private String curDate;
+
+ @ColumnWidth(value = 18)
+ @ExcelProperty(value = "瞬时流量", index = 2)
+ private String curValue;
+
+ @ColumnWidth(value = 18)
+ @ExcelProperty(value = "项目名称", index = 0)
+ private String projectName;
+
+ public ExportBaseResultDTO(String projectName, String curDate, String curValue) {
+ this.projectName = projectName;
+ this.curDate = curDate;
+ this.curValue = curValue;
+ }
+}
diff --git a/user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java b/user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java
index e4be0da..3e27e4b 100644
--- a/user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java
+++ b/user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java
@@ -51,7 +51,7 @@ public interface DataResultChMapper extends BaseMapper {
@Select("select " +
" t1.project_id, " +
- " sum(cast (t1.curValue AS decimal(18, 2)))as cur_value, " +
+ " sum(cast (t1.cur_value AS decimal(18, 2)))as cur_value, " +
" t1.cur_date, " +
" t2.project_name " +
"from " +
diff --git a/user-service/src/main/java/com/mh/user/model/SysMenu.java b/user-service/src/main/java/com/mh/user/model/SysMenu.java
index 6ad15bc..488fdf5 100644
--- a/user-service/src/main/java/com/mh/user/model/SysMenu.java
+++ b/user-service/src/main/java/com/mh/user/model/SysMenu.java
@@ -15,7 +15,7 @@ public class SysMenu extends BaseModel {
private String title;
- private String menu_name;
+ private String menuName;
private String component;
diff --git a/user-service/src/main/java/com/mh/user/service/DataResultService.java b/user-service/src/main/java/com/mh/user/service/DataResultService.java
index 56416bd..a5a10e2 100644
--- a/user-service/src/main/java/com/mh/user/service/DataResultService.java
+++ b/user-service/src/main/java/com/mh/user/service/DataResultService.java
@@ -1,5 +1,6 @@
package com.mh.user.service;
+import com.mh.common.http.HttpResult;
import com.mh.user.entity.DataResultClEntity;
import com.mh.user.entity.DataResultEntity;
import com.mh.user.entity.DataResultChEntity;
@@ -47,6 +48,8 @@ public interface DataResultService {
//查询按分钟的时间间隔
List queryDataResultMi(String projectId,String startDate,String curDate,int page,int limit, int type);
+ HttpResult queryDataResultMiData(String projectId, String curDate, int page, int limit, int type, String dateType);
+
int dataResultOneMiCount(String projectId,String startDate,String curDate);
int dataResultFiveMiCount(String projectId,String startDate,String curDate);
diff --git a/user-service/src/main/java/com/mh/user/service/SysDictService.java b/user-service/src/main/java/com/mh/user/service/SysDictService.java
index 7955424..1f68cad 100644
--- a/user-service/src/main/java/com/mh/user/service/SysDictService.java
+++ b/user-service/src/main/java/com/mh/user/service/SysDictService.java
@@ -27,4 +27,6 @@ public interface SysDictService extends CurdService {
List findByType(String type);
void createDictDataCache();
+
+ List findCacheByType(String type);
}
diff --git a/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java b/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java
index 5a46ac1..e639ed1 100644
--- a/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java
+++ b/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java
@@ -323,7 +323,6 @@ public class ChillersServiceImpl implements ChillersService {
deviceQueryWrapper.eq("device_type", 0);
List devicesManageEntityList = devicesManageMapper.selectList(deviceQueryWrapper.orderByAsc("id"));
if (devicesManageEntityList != null && !devicesManageEntityList.isEmpty()) {
- HostListVO hostListVO = new HostListVO();
// 根据projectId进行分组
Map> proDevicesMap =
devicesManageEntityList.stream().collect(Collectors.groupingBy(DevicesManageEntity::getProjectId));
@@ -351,6 +350,7 @@ public class ChillersServiceImpl implements ChillersService {
if (meterManageEntities == null || meterManageEntities.isEmpty()) {
continue;
}
+ HostListVO hostListVO = new HostListVO();
matchingChillersData(meterManageEntities, hostListVO);
// 额定制冷量
hostListVO.setRatedRef(String.valueOf(devicesManageEntity.getRatedRefrigerationCapacity()));
@@ -371,7 +371,7 @@ public class ChillersServiceImpl implements ChillersService {
}
private void matchingChillersData(List meterManageEntities, HostListVO hostListVO) {
- hostListVO.reset();
+// hostListVO.reset();
for (MeterManageEntity meterManageEntity : meterManageEntities) {
// 匹配HostListVO展示给前端
String funCode = ExchangeStringUtil.addZeroForNum(meterManageEntity.getFuncCode(), 2);
diff --git a/user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java
index 8c780d8..1b8b0fb 100644
--- a/user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java
+++ b/user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java
@@ -1,10 +1,12 @@
package com.mh.user.service.impl;
+import com.mh.common.http.HttpResult;
import com.mh.user.entity.*;
import com.mh.user.mapper.*;
import com.mh.user.service.DataResultService;
import com.mh.user.service.DeviceInstallService;
import com.mh.user.utils.DateUtil;
+import com.mh.user.utils.ExchangeStringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -237,6 +239,52 @@ public class DataResultServiceImpl implements DataResultService {
return dataResultOneMiMapper.dataResultOneMiCount(projectId, startDate, curDate);
}
+ @Override
+ public HttpResult queryDataResultMiData(String projectId, String curDate, int page, int limit, int type, String dateType) {
+ try{
+ if(projectId!=null && !projectId.isEmpty()){
+ String startDate="";
+ curDate=curDate.substring(0,16)+":00";
+ if (dateType.equals("1小时")){
+ startDate= ExchangeStringUtil.dateRoll(1,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+ int count=dataResultOneMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }else if (dateType.equals("2小时")){
+ startDate=ExchangeStringUtil.dateRoll(2,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+ int count=dataResultOneMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }else if (dateType.equals("8小时")){
+ startDate=ExchangeStringUtil.dateRoll(8,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,1);
+ int count=dataResultFiveMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }else if (dateType.equals("12小时")){
+ startDate=ExchangeStringUtil.dateRoll(12,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,1);
+ int count=dataResultFiveMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }else if (dateType.equals("24小时")){
+ startDate=ExchangeStringUtil.dateRoll(24,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,2);
+ int count=dataResultFifteenMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }else{ //1小时
+ startDate=ExchangeStringUtil.dateRoll(1,curDate);
+ List records=queryDataResultMi(projectId,startDate,curDate,page,limit,0);
+ int count=dataResultOneMiCount(projectId,startDate,curDate);
+ return HttpResult.ok(count,records);
+ }
+ }else{
+ return HttpResult.error();
+ }
+ }catch (Exception e){
+ log.error("查询数据异常", e);
+ return HttpResult.error();
+ }
+ }
+
@Override
public int dataResultFiveMiCount(String projectId, String startDate, String curDate) {
return dataResultFiveMiMapper.dataResultFiveMiCount(projectId, startDate, curDate);
diff --git a/user-service/src/main/java/com/mh/user/service/impl/SysDictServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/SysDictServiceImpl.java
index cfcb4f5..2f180d8 100644
--- a/user-service/src/main/java/com/mh/user/service/impl/SysDictServiceImpl.java
+++ b/user-service/src/main/java/com/mh/user/service/impl/SysDictServiceImpl.java
@@ -9,6 +9,8 @@ import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult;
import com.mh.common.utils.StringUtils;
import com.mh.user.constants.Constant;
+import com.mh.user.entity.ProjectInfoEntity;
+import com.mh.user.mapper.ProjectInfoMapper;
import com.mh.user.mapper.SysDictMapper;
import com.mh.user.model.SysDict;
import com.mh.user.service.SysDictService;
@@ -22,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
/**
* @author LJF
@@ -36,6 +39,9 @@ public class SysDictServiceImpl implements SysDictService {
@Autowired
private SysDictMapper sysDictMapper;
+ @Autowired
+ private ProjectInfoMapper projectInfoMapper;
+
@Autowired
@Qualifier("caffeineCache")
private Cache caffeineCache;
@@ -102,8 +108,30 @@ public class SysDictServiceImpl implements SysDictService {
public void createDictDataCache() {
List sysDictList = sysDictMapper.selectList(
new QueryWrapper().orderByDesc("create_time"));
+ // 把项目列表放到缓存中
+ List projectInfoEntities = projectInfoMapper.selectList(
+ new QueryWrapper().orderByAsc("create_time")
+ );
+ // 转换成SysDict,然后插入到sysDictList中
+ for (ProjectInfoEntity projectInfoEntity : projectInfoEntities) {
+ SysDict sysDict = new SysDict();
+ sysDict.setLabel(projectInfoEntity.getProjectName());
+ sysDict.setValue(String.valueOf(projectInfoEntity.getId()));
+ sysDict.setType("project_name");
+ sysDictList.add(sysDict);
+ }
if (caffeineCache.getIfPresent(Constant.SYS_DICT) == null) {
caffeineCache.put("sys_dict", sysDictList);
}
}
+
+ @Override
+ public List findCacheByType(String type) {
+ List sysDictList = (List) caffeineCache.getIfPresent("sys_dict");
+ if (sysDictList == null || sysDictList.size() == 0) {
+ createDictDataCache();
+ sysDictList = (List) caffeineCache.getIfPresent("sys_dict");
+ }
+ return sysDictList.stream().filter(item -> item.getType().equals(type)).collect(Collectors.toList());
+ }
}
diff --git a/user-service/src/main/java/com/mh/user/service/impl/SysMenuServiceImpl.java b/user-service/src/main/java/com/mh/user/service/impl/SysMenuServiceImpl.java
index 15d5159..da87378 100644
--- a/user-service/src/main/java/com/mh/user/service/impl/SysMenuServiceImpl.java
+++ b/user-service/src/main/java/com/mh/user/service/impl/SysMenuServiceImpl.java
@@ -2,6 +2,7 @@ package com.mh.user.service.impl;
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import com.mh.common.page.MybatisPageHelper;
@@ -11,6 +12,7 @@ import com.mh.user.constants.SysConstants;
import com.mh.user.mapper.SysMenuMapper;
import com.mh.user.model.SysMenu;
import com.mh.user.service.SysMenuService;
+import com.mh.user.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -23,11 +25,15 @@ public class SysMenuServiceImpl implements SysMenuService {
@Override
public int save(SysMenu record) {
if(record.getId() == null || record.getId() == 0) {
+ record.setCreateBy(SecurityUtils.getUsername());
+ record.setCreateTime(new Date());
return sysMenuMapper.insertSelective(record);
}
if(record.getParentId() == null) {
record.setParentId(0L);
}
+ record.setLastUpdateBy(SecurityUtils.getUsername());
+ record.setLastUpdateTime(new Date());
return sysMenuMapper.updateByPrimaryKeySelective(record);
}
diff --git a/user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml b/user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml
index f038930..82f25b2 100644
--- a/user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml
+++ b/user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml
@@ -5,7 +5,7 @@
-
+
@@ -35,12 +35,12 @@
insert into sys_menu (id, parent_id, title,menu_name,
component, path, menu_type, icon,
order_num, create_by, create_time,
- last_update_by, last_update_time
+ last_update_by, last_update_time,system_id
)
values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR},#{menuName,jdbcType=VARCHAR},
#{component,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{menuType,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR},
#{orderNum,jdbcType=INTEGER}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
- #{lastUpdateBy,jdbcType=BIGINT}, #{lastUpdateTime,jdbcType=TIMESTAMP}}
+ #{lastUpdateBy,jdbcType=BIGINT}, #{lastUpdateTime,jdbcType=TIMESTAMP}, #{systemId, jdbcType=VARCHAR}
)
@@ -85,6 +85,9 @@
last_update_time,
+
+ system_id,
+
@@ -126,6 +129,9 @@
#{lastUpdateTime,jdbcType=TIMESTAMP},
+
+ #{systemId, jdbcType=VARCHAR},
+
diff --git a/user-service/src/main/java/com/mh/user/utils/CenterCellStyleWriteHandler.java b/user-service/src/main/java/com/mh/user/utils/CenterCellStyleWriteHandler.java
new file mode 100644
index 0000000..ec02e7f
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/utils/CenterCellStyleWriteHandler.java
@@ -0,0 +1,40 @@
+package com.mh.user.utils;
+
+import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.write.handler.CellWriteHandler;
+import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
+import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
+import org.apache.poi.ss.usermodel.*;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 表格居中设置
+ * @date 2024-11-13 15:51:21
+ */
+public class CenterCellStyleWriteHandler implements CellWriteHandler {
+
+ @Override
+ public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
+ Workbook workbook = cell.getSheet().getWorkbook();
+ CellStyle cellStyle = workbook.createCellStyle();
+
+ // 设置边框样式
+ cellStyle.setBorderTop(BorderStyle.THIN);
+ cellStyle.setBorderBottom(BorderStyle.THIN);
+ cellStyle.setBorderLeft(BorderStyle.THIN);
+ cellStyle.setBorderRight(BorderStyle.THIN);
+
+ // 设置水平居中对齐
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
+
+ // 设置垂直居中对齐
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+
+ cell.setCellStyle(cellStyle);
+
+ System.out.println("进入到格式化表格");
+ }
+
+}
diff --git a/user-service/src/main/java/com/mh/user/utils/JwtTokenUtils.java b/user-service/src/main/java/com/mh/user/utils/JwtTokenUtils.java
index c45dc1b..3f4b8a3 100644
--- a/user-service/src/main/java/com/mh/user/utils/JwtTokenUtils.java
+++ b/user-service/src/main/java/com/mh/user/utils/JwtTokenUtils.java
@@ -203,7 +203,7 @@ public class JwtTokenUtils implements Serializable {
String token = request.getHeader("Authorization");
String tokenHead = "Bearer ";
if(token == null) {
- token = request.getHeader("token");
+ token = request.getHeader("X-Token");
} else if(token.contains(tokenHead)){
token = token.substring(tokenHead.length());
}
diff --git a/user-service/src/main/java/com/mh/user/utils/SecurityUtils.java b/user-service/src/main/java/com/mh/user/utils/SecurityUtils.java
index 8a392b8..a04a2a8 100644
--- a/user-service/src/main/java/com/mh/user/utils/SecurityUtils.java
+++ b/user-service/src/main/java/com/mh/user/utils/SecurityUtils.java
@@ -35,7 +35,7 @@ public class SecurityUtils {
SecurityContextHolder.getContext().setAuthentication(authentication);
// 生成令牌并返回给客户端
token.setToken(JwtTokenUtils.generateToken(authentication));
-// System.out.println("返回token到前端!");
+ System.out.println("获取当前用户==>" + SecurityUtils.getUsername());
return token;
}
@@ -62,6 +62,8 @@ public class SecurityUtils {
Object principal = authentication.getPrincipal();
if(principal != null && principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
+ } else {
+ username = (String) principal;
}
}
return username;
diff --git a/user-service/src/test/java/com/mh/user/DealDataTest.java b/user-service/src/test/java/com/mh/user/DealDataTest.java
index 6da1458..b2dfd97 100644
--- a/user-service/src/test/java/com/mh/user/DealDataTest.java
+++ b/user-service/src/test/java/com/mh/user/DealDataTest.java
@@ -1,9 +1,14 @@
package com.mh.user;
import com.mh.user.mapper.chillers.DealDataMapper;
+import com.mh.user.service.chillers.DealDataService;
+import com.mh.user.utils.ExchangeStringUtil;
+import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.List;
+
/**
* @author ljf
* @title :
@@ -11,13 +16,30 @@ import org.springframework.beans.factory.annotation.Autowired;
* @updateTime 2020-07-28
* @throws :
*/
+@Slf4j
public class DealDataTest extends UserServiceApplicationTests {
@Autowired
- private DealDataMapper dealDataMapper;
+ private DealDataService dealDataService;
@Test
public void dealChillersData() {
-// dealDataMapper.dealChillersData();
+ try {
+ for (int i = 1; i < 60; i++) {
+ String curDate = "2024-10-10 00:" + ExchangeStringUtil.addZeroForNum(String.valueOf(i), 2) + ":00";
+
+ System.out.println(curDate);
+ List list=dealDataService.queryProjectId("1");
+ if (!list.isEmpty()){
+ for(String projectId:list){
+ dealDataService.proDataResult(curDate,projectId); //1珠江酒店,2广合,3广大
+ }
+ }
+ log.info("---------能效监测定时汇总,每一分钟!{}", curDate);
+ }
+
+ } catch (Exception e) {
+ log.error("能效监测定时汇总异常", e);
+ }
}
}