Browse Source

1、添加菜单管理接口;

2、优化日志管理接口;
3、优化springsecurity权限设置;
4、优化前端关于菜单权限管理接口;
5、能耗实时数据监控导出excel;
dev
mh 2 days ago
parent
commit
a2c6b0e17f
  1. 7
      user-service/pom.xml
  2. 2
      user-service/src/main/java/com/mh/user/aspect/DictDataTranslateAsp.java
  3. 58
      user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java
  4. 122
      user-service/src/main/java/com/mh/user/controller/DataResultController.java
  5. 6
      user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
  6. 5
      user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
  7. 9
      user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
  8. 3
      user-service/src/main/java/com/mh/user/controller/MeterManageController.java
  9. 5
      user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
  10. 41
      user-service/src/main/java/com/mh/user/dto/ExportBaseResultDTO.java
  11. 2
      user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java
  12. 2
      user-service/src/main/java/com/mh/user/model/SysMenu.java
  13. 3
      user-service/src/main/java/com/mh/user/service/DataResultService.java
  14. 2
      user-service/src/main/java/com/mh/user/service/SysDictService.java
  15. 4
      user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java
  16. 48
      user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java
  17. 28
      user-service/src/main/java/com/mh/user/service/impl/SysDictServiceImpl.java
  18. 6
      user-service/src/main/java/com/mh/user/service/impl/SysMenuServiceImpl.java
  19. 12
      user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml
  20. 40
      user-service/src/main/java/com/mh/user/utils/CenterCellStyleWriteHandler.java
  21. 2
      user-service/src/main/java/com/mh/user/utils/JwtTokenUtils.java
  22. 4
      user-service/src/main/java/com/mh/user/utils/SecurityUtils.java
  23. 26
      user-service/src/test/java/com/mh/user/DealDataTest.java

7
user-service/pom.xml

@ -174,6 +174,13 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

2
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) { private void translateDict(FieldParam fieldParam, Pattern fieldPattern, Matcher fieldMatcher, StringBuffer sb) {
//从缓存中一次性取值 //从缓存中一次性取值
List<SysDict> dictNames = sysDictService.findByType(fieldParam.type()); List<SysDict> dictNames = sysDictService.findCacheByType(fieldParam.type());
while (fieldMatcher.find()) { while (fieldMatcher.find()) {
//取出要翻译字段对应的值 //取出要翻译字段对应的值
Matcher dictValueMatcher = fieldPattern.matcher(fieldMatcher.group()); Matcher dictValueMatcher = fieldPattern.matcher(fieldMatcher.group());

58
user-service/src/main/java/com/mh/user/config/WebSecurityConfig.java

@ -42,36 +42,36 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf // 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf
// System.out.println("test0"); System.out.println("test0");
// http.cors().and().csrf().disable() http.cors().and().csrf().disable()
// .authorizeRequests() .authorizeRequests()
// // 跨域预检请求 // 跨域预检请求
// .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
// // web jars // web jars
// .antMatchers("/webjars/**").permitAll() .antMatchers("/webjars/**").permitAll()
// // 查看SQL监控(druid) // 查看SQL监控(druid)
// .antMatchers("/druid/**").permitAll() .antMatchers("/druid/**").permitAll()
// // 首页和登录页面 // 首页和登录页面
// .antMatchers("/").permitAll() .antMatchers("/").permitAll()
// .antMatchers("/login").permitAll() .antMatchers("/login").permitAll()
// // swagger // swagger
// .antMatchers("/swagger-ui.html").permitAll() .antMatchers("/swagger-ui.html").permitAll()
// .antMatchers("/swagger-resources/**").permitAll() .antMatchers("/swagger-resources/**").permitAll()
// .antMatchers("/v2/api-docs").permitAll() .antMatchers("/v2/api-docs").permitAll()
// .antMatchers("/webjars/springfox-swagger-ui/**").permitAll() .antMatchers("/webjars/springfox-swagger-ui/**").permitAll()
// // 验证码 // 验证码
// .antMatchers("/captcha.jpg**").permitAll() .antMatchers("/captcha.jpg**").permitAll()
// // 服务监控 // 服务监控
// .antMatchers("/actuator/**").permitAll() .antMatchers("/actuator/**").permitAll()
// // 其他所有请求需要身份认证 // 其他所有请求需要身份认证
// .anyRequest().authenticated(); .anyRequest().authenticated();
// // 退出登录处理器 // 退出登录处理器
// http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()); http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
// // token验证过滤器 // token验证过滤器
// http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class); http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
// System.out.println("test0_1"); System.out.println("test0_1");
// 禁用token验证 // 禁用token验证
http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll(); // http.csrf().disable().authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
} }
@Bean @Bean

122
user-service/src/main/java/com/mh/user/controller/DataResultController.java

@ -1,17 +1,27 @@
package com.mh.user.controller; package com.mh.user.controller;
import com.alibaba.excel.EasyExcel;
import com.mh.common.http.HttpResult; import com.mh.common.http.HttpResult;
import com.mh.user.annotation.SysLogger; import com.mh.user.annotation.SysLogger;
import com.mh.user.dto.ExportBaseResultDTO;
import com.mh.user.entity.DataResultChEntity; import com.mh.user.entity.DataResultChEntity;
import com.mh.user.entity.DataResultEntity; import com.mh.user.entity.DataResultEntity;
import com.mh.user.service.BuildingService; import com.mh.user.service.BuildingService;
import com.mh.user.service.DataResultService; 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 com.mh.user.utils.ExchangeStringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@RestController @RestController
@RequestMapping("dataResult") @RequestMapping("dataResult")
public class DataResultController { public class DataResultController {
@ -51,47 +61,77 @@ public class DataResultController {
@RequestParam(value= "curDate", required=false)String curDate, @RequestParam(value= "curDate", required=false)String curDate,
@RequestParam(value="page", required=false) int page, @RequestParam(value="page", required=false) int page,
@RequestParam(value="limit", required=false) int limit) { @RequestParam(value="limit", required=false) int limit) {
try{ return dataResultService.queryDataResultMiData(projectId,curDate,page,limit,0,dateType);
if(projectId!=null && projectId.length()>0){ // try{
String startDate=""; // if(projectId!=null && projectId.length()>0){
curDate=curDate.substring(0,16)+":00"; // String startDate="";
if (dateType.equals("1小时")){ // curDate=curDate.substring(0,16)+":00";
startDate= ExchangeStringUtil.dateRoll(1,curDate); // if (dateType.equals("1小时")){
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0); // startDate= ExchangeStringUtil.dateRoll(1,curDate);
int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
}else if (dateType.equals("2小时")){ // return HttpResult.ok(count,records);
startDate=ExchangeStringUtil.dateRoll(2,curDate); // }else if (dateType.equals("2小时")){
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0); // startDate=ExchangeStringUtil.dateRoll(2,curDate);
int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
}else if (dateType.equals("8小时")){ // return HttpResult.ok(count,records);
startDate=ExchangeStringUtil.dateRoll(8,curDate); // }else if (dateType.equals("8小时")){
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1); // startDate=ExchangeStringUtil.dateRoll(8,curDate);
int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
}else if (dateType.equals("12小时")){ // return HttpResult.ok(count,records);
startDate=ExchangeStringUtil.dateRoll(12,curDate); // }else if (dateType.equals("12小时")){
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1); // startDate=ExchangeStringUtil.dateRoll(12,curDate);
int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,1);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultFiveMiCount(projectId,startDate,curDate);
}else if (dateType.equals("24小时")){ // return HttpResult.ok(count,records);
startDate=ExchangeStringUtil.dateRoll(24,curDate); // }else if (dateType.equals("24小时")){
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,2); // startDate=ExchangeStringUtil.dateRoll(24,curDate);
int count=dataResultService.dataResultFifteenMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,2);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultFifteenMiCount(projectId,startDate,curDate);
}else{ //1小时 // return HttpResult.ok(count,records);
startDate=ExchangeStringUtil.dateRoll(1,curDate); // }else{ //1小时
List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0); // startDate=ExchangeStringUtil.dateRoll(1,curDate);
int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate); // List<DataResultChEntity> records=dataResultService.queryDataResultMi(projectId,startDate,curDate,page,limit,0);
return HttpResult.ok(count,records); // int count=dataResultService.dataResultOneMiCount(projectId,startDate,curDate);
} // return HttpResult.ok(count,records);
}else{ // }
return HttpResult.error(); // }else{
} // return HttpResult.error();
}catch (Exception e){ // }
// e.printStackTrace(); // }catch (Exception e){
return HttpResult.error(); //// 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<DataResultChEntity> records = (List<DataResultChEntity>) dataResultService.queryDataResultMiData(projectId,curDate,page,limit,0, dateType).getData();
List<ExportBaseResultDTO> 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("下载报表异常");
} }
} }

6
user-service/src/main/java/com/mh/user/controller/DevicesManageController.java

@ -27,7 +27,11 @@ public class DevicesManageController {
@SysLogger(value = "资产管理信息", optDesc = "查询资产管理信息") @SysLogger(value = "资产管理信息", optDesc = "查询资产管理信息")
@PostMapping("/findByPage") @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) { public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {
return devicesManageService.queryByPage(pageRequest); return devicesManageService.queryByPage(pageRequest);
} }

5
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.http.HttpResult;
import com.mh.common.page.PageRequest; import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult; import com.mh.common.page.PageResult;
import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger; import com.mh.user.annotation.SysLogger;
import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.DeviceParamsEntity; import com.mh.user.entity.DeviceParamsEntity;
import com.mh.user.service.DeviceParamsService; import com.mh.user.service.DeviceParamsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +25,9 @@ public class DevicesParamsController {
@Autowired @Autowired
private DeviceParamsService deviceParamsService; private DeviceParamsService deviceParamsService;
@TranslationDict({
@FieldParam(type = "mt_type", targetField = "mtType", targetFieldValueClazz = Integer.class)
})
@SysLogger(value="设备参数管理",optDesc = "查询设备参数管理") @SysLogger(value="设备参数管理",optDesc = "查询设备参数管理")
@PostMapping("/findByPage") @PostMapping("/findByPage")
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) { public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {

9
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.http.HttpResult;
import com.mh.common.page.PageRequest; import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult; import com.mh.common.page.PageResult;
import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger; import com.mh.user.annotation.SysLogger;
import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.GatewayManageEntity; import com.mh.user.entity.GatewayManageEntity;
import com.mh.user.service.GatewayManageService; import com.mh.user.service.GatewayManageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -23,7 +25,12 @@ public class GatewayManageController {
@Autowired @Autowired
private GatewayManageService gatewayManageService; 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 = "查询网关管理信息") @SysLogger(value="网关管理信息",optDesc = "查询网关管理信息")
@PostMapping("/findByPage") @PostMapping("/findByPage")
public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) { public PageResult queryGatewayManage(@RequestBody PageRequest pageRequest) {

3
user-service/src/main/java/com/mh/user/controller/MeterManageController.java

@ -25,10 +25,11 @@ public class MeterManageController {
@Autowired @Autowired
private MeterManageService meterManageService; 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 = "communication_type", targetField = "communicationType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "data_type", targetField = "dataType", targetFieldValueClazz = Integer.class), @FieldParam(type = "data_type", targetField = "dataType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "protocol_type", targetField = "protocolType", targetFieldValueClazz = Integer.class), @FieldParam(type = "protocol_type", targetField = "protocolType", targetFieldValueClazz = Integer.class),
@FieldParam(type = "project_name", targetField = "projectId", targetFieldValueClazz = Integer.class),
}) })
@SysLogger(value="仪表管理信息",optDesc = "查询仪表管理信息") @SysLogger(value="仪表管理信息",optDesc = "查询仪表管理信息")
@PostMapping("/findByPage") @PostMapping("/findByPage")

5
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.http.HttpResult;
import com.mh.common.page.PageRequest; import com.mh.common.page.PageRequest;
import com.mh.common.page.PageResult; import com.mh.common.page.PageResult;
import com.mh.user.annotation.FieldParam;
import com.mh.user.annotation.SysLogger; import com.mh.user.annotation.SysLogger;
import com.mh.user.annotation.TranslationDict;
import com.mh.user.entity.ProjectInfoEntity; import com.mh.user.entity.ProjectInfoEntity;
import com.mh.user.service.ProjectInfoService; import com.mh.user.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -26,6 +28,9 @@ public class ProjectInfoController {
return HttpResult.ok(list); return HttpResult.ok(list);
} }
@TranslationDict({
@FieldParam(type = "system_type", targetField = "systemId", targetFieldValueClazz = Integer.class)
})
@SysLogger(value="项目信息",optDesc = "查询项目信息") @SysLogger(value="项目信息",optDesc = "查询项目信息")
@PostMapping("/findByPage") @PostMapping("/findByPage")
public PageResult queryProject(@RequestBody PageRequest pageRequest) { public PageResult queryProject(@RequestBody PageRequest pageRequest) {

41
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;
}
}

2
user-service/src/main/java/com/mh/user/mapper/DataResultChMapper.java

@ -51,7 +51,7 @@ public interface DataResultChMapper extends BaseMapper<DataResultChEntity> {
@Select("select " + @Select("select " +
" t1.project_id, " + " 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, " + " t1.cur_date, " +
" t2.project_name " + " t2.project_name " +
"from " + "from " +

2
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 title;
private String menu_name; private String menuName;
private String component; private String component;

3
user-service/src/main/java/com/mh/user/service/DataResultService.java

@ -1,5 +1,6 @@
package com.mh.user.service; package com.mh.user.service;
import com.mh.common.http.HttpResult;
import com.mh.user.entity.DataResultClEntity; import com.mh.user.entity.DataResultClEntity;
import com.mh.user.entity.DataResultEntity; import com.mh.user.entity.DataResultEntity;
import com.mh.user.entity.DataResultChEntity; import com.mh.user.entity.DataResultChEntity;
@ -47,6 +48,8 @@ public interface DataResultService {
//查询按分钟的时间间隔 //查询按分钟的时间间隔
List<DataResultChEntity> queryDataResultMi(String projectId,String startDate,String curDate,int page,int limit, int type); List<DataResultChEntity> 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 dataResultOneMiCount(String projectId,String startDate,String curDate);
int dataResultFiveMiCount(String projectId,String startDate,String curDate); int dataResultFiveMiCount(String projectId,String startDate,String curDate);

2
user-service/src/main/java/com/mh/user/service/SysDictService.java

@ -27,4 +27,6 @@ public interface SysDictService extends CurdService<SysDict> {
List<SysDict> findByType(String type); List<SysDict> findByType(String type);
void createDictDataCache(); void createDictDataCache();
List<SysDict> findCacheByType(String type);
} }

4
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); deviceQueryWrapper.eq("device_type", 0);
List<DevicesManageEntity> devicesManageEntityList = devicesManageMapper.selectList(deviceQueryWrapper.orderByAsc("id")); List<DevicesManageEntity> devicesManageEntityList = devicesManageMapper.selectList(deviceQueryWrapper.orderByAsc("id"));
if (devicesManageEntityList != null && !devicesManageEntityList.isEmpty()) { if (devicesManageEntityList != null && !devicesManageEntityList.isEmpty()) {
HostListVO hostListVO = new HostListVO();
// 根据projectId进行分组 // 根据projectId进行分组
Map<Long, List<DevicesManageEntity>> proDevicesMap = Map<Long, List<DevicesManageEntity>> proDevicesMap =
devicesManageEntityList.stream().collect(Collectors.groupingBy(DevicesManageEntity::getProjectId)); devicesManageEntityList.stream().collect(Collectors.groupingBy(DevicesManageEntity::getProjectId));
@ -351,6 +350,7 @@ public class ChillersServiceImpl implements ChillersService {
if (meterManageEntities == null || meterManageEntities.isEmpty()) { if (meterManageEntities == null || meterManageEntities.isEmpty()) {
continue; continue;
} }
HostListVO hostListVO = new HostListVO();
matchingChillersData(meterManageEntities, hostListVO); matchingChillersData(meterManageEntities, hostListVO);
// 额定制冷量 // 额定制冷量
hostListVO.setRatedRef(String.valueOf(devicesManageEntity.getRatedRefrigerationCapacity())); hostListVO.setRatedRef(String.valueOf(devicesManageEntity.getRatedRefrigerationCapacity()));
@ -371,7 +371,7 @@ public class ChillersServiceImpl implements ChillersService {
} }
private void matchingChillersData(List<MeterManageEntity> meterManageEntities, HostListVO hostListVO) { private void matchingChillersData(List<MeterManageEntity> meterManageEntities, HostListVO hostListVO) {
hostListVO.reset(); // hostListVO.reset();
for (MeterManageEntity meterManageEntity : meterManageEntities) { for (MeterManageEntity meterManageEntity : meterManageEntities) {
// 匹配HostListVO展示给前端 // 匹配HostListVO展示给前端
String funCode = ExchangeStringUtil.addZeroForNum(meterManageEntity.getFuncCode(), 2); String funCode = ExchangeStringUtil.addZeroForNum(meterManageEntity.getFuncCode(), 2);

48
user-service/src/main/java/com/mh/user/service/impl/DataResultServiceImpl.java

@ -1,10 +1,12 @@
package com.mh.user.service.impl; package com.mh.user.service.impl;
import com.mh.common.http.HttpResult;
import com.mh.user.entity.*; import com.mh.user.entity.*;
import com.mh.user.mapper.*; import com.mh.user.mapper.*;
import com.mh.user.service.DataResultService; import com.mh.user.service.DataResultService;
import com.mh.user.service.DeviceInstallService; import com.mh.user.service.DeviceInstallService;
import com.mh.user.utils.DateUtil; import com.mh.user.utils.DateUtil;
import com.mh.user.utils.ExchangeStringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -237,6 +239,52 @@ public class DataResultServiceImpl implements DataResultService {
return dataResultOneMiMapper.dataResultOneMiCount(projectId, startDate, curDate); 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<DataResultChEntity> 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<DataResultChEntity> 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<DataResultChEntity> 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<DataResultChEntity> 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<DataResultChEntity> 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<DataResultChEntity> 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 @Override
public int dataResultFiveMiCount(String projectId, String startDate, String curDate) { public int dataResultFiveMiCount(String projectId, String startDate, String curDate) {
return dataResultFiveMiMapper.dataResultFiveMiCount(projectId, startDate, curDate); return dataResultFiveMiMapper.dataResultFiveMiCount(projectId, startDate, curDate);

28
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.page.PageResult;
import com.mh.common.utils.StringUtils; import com.mh.common.utils.StringUtils;
import com.mh.user.constants.Constant; 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.mapper.SysDictMapper;
import com.mh.user.model.SysDict; import com.mh.user.model.SysDict;
import com.mh.user.service.SysDictService; import com.mh.user.service.SysDictService;
@ -22,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author LJF * @author LJF
@ -36,6 +39,9 @@ public class SysDictServiceImpl implements SysDictService {
@Autowired @Autowired
private SysDictMapper sysDictMapper; private SysDictMapper sysDictMapper;
@Autowired
private ProjectInfoMapper projectInfoMapper;
@Autowired @Autowired
@Qualifier("caffeineCache") @Qualifier("caffeineCache")
private Cache caffeineCache; private Cache caffeineCache;
@ -102,8 +108,30 @@ public class SysDictServiceImpl implements SysDictService {
public void createDictDataCache() { public void createDictDataCache() {
List<SysDict> sysDictList = sysDictMapper.selectList( List<SysDict> sysDictList = sysDictMapper.selectList(
new QueryWrapper<SysDict>().orderByDesc("create_time")); new QueryWrapper<SysDict>().orderByDesc("create_time"));
// 把项目列表放到缓存中
List<ProjectInfoEntity> projectInfoEntities = projectInfoMapper.selectList(
new QueryWrapper<ProjectInfoEntity>().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) { if (caffeineCache.getIfPresent(Constant.SYS_DICT) == null) {
caffeineCache.put("sys_dict", sysDictList); caffeineCache.put("sys_dict", sysDictList);
} }
} }
@Override
public List<SysDict> findCacheByType(String type) {
List<SysDict> sysDictList = (List<SysDict>) caffeineCache.getIfPresent("sys_dict");
if (sysDictList == null || sysDictList.size() == 0) {
createDictDataCache();
sysDictList = (List<SysDict>) caffeineCache.getIfPresent("sys_dict");
}
return sysDictList.stream().filter(item -> item.getType().equals(type)).collect(Collectors.toList());
}
} }

6
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.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.List; import java.util.List;
import com.mh.common.page.MybatisPageHelper; 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.mapper.SysMenuMapper;
import com.mh.user.model.SysMenu; import com.mh.user.model.SysMenu;
import com.mh.user.service.SysMenuService; import com.mh.user.service.SysMenuService;
import com.mh.user.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -23,11 +25,15 @@ public class SysMenuServiceImpl implements SysMenuService {
@Override @Override
public int save(SysMenu record) { public int save(SysMenu record) {
if(record.getId() == null || record.getId() == 0) { if(record.getId() == null || record.getId() == 0) {
record.setCreateBy(SecurityUtils.getUsername());
record.setCreateTime(new Date());
return sysMenuMapper.insertSelective(record); return sysMenuMapper.insertSelective(record);
} }
if(record.getParentId() == null) { if(record.getParentId() == null) {
record.setParentId(0L); record.setParentId(0L);
} }
record.setLastUpdateBy(SecurityUtils.getUsername());
record.setLastUpdateTime(new Date());
return sysMenuMapper.updateByPrimaryKeySelective(record); return sysMenuMapper.updateByPrimaryKeySelective(record);
} }

12
user-service/src/main/java/com/mh/user/sqlmapper/SysMenuMapper.xml

@ -5,7 +5,7 @@
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="parent_id" jdbcType="BIGINT" property="parentId" /> <result column="parent_id" jdbcType="BIGINT" property="parentId" />
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title" />
<result column="menu_name" jdbcType="VARCHAR" property="menu_name" /> <result column="menu_name" jdbcType="VARCHAR" property="menuName" />
<result column="component" jdbcType="VARCHAR" property="component" /> <result column="component" jdbcType="VARCHAR" property="component" />
<result column="path" jdbcType="VARCHAR" property="path" /> <result column="path" jdbcType="VARCHAR" property="path" />
<result column="menu_type" jdbcType="INTEGER" property="menuType" /> <result column="menu_type" jdbcType="INTEGER" property="menuType" />
@ -35,12 +35,12 @@
insert into sys_menu (id, parent_id, title,menu_name, insert into sys_menu (id, parent_id, title,menu_name,
component, path, menu_type, icon, component, path, menu_type, icon,
order_num, create_by, create_time, 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}, 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}, #{component,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{menuType,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR},
#{orderNum,jdbcType=INTEGER}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{orderNum,jdbcType=INTEGER}, #{createBy,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
#{lastUpdateBy,jdbcType=BIGINT}, #{lastUpdateTime,jdbcType=TIMESTAMP}} #{lastUpdateBy,jdbcType=BIGINT}, #{lastUpdateTime,jdbcType=TIMESTAMP}, #{systemId, jdbcType=VARCHAR}
) )
</insert> </insert>
<insert id="insertSelective" parameterType="com.mh.user.model.SysMenu"> <insert id="insertSelective" parameterType="com.mh.user.model.SysMenu">
@ -85,6 +85,9 @@
<if test="lastUpdateTime != null"> <if test="lastUpdateTime != null">
last_update_time, last_update_time,
</if> </if>
<if test="systemId != null">
system_id,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -126,6 +129,9 @@
<if test="lastUpdateTime != null"> <if test="lastUpdateTime != null">
#{lastUpdateTime,jdbcType=TIMESTAMP}, #{lastUpdateTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="systemId != null">
#{systemId, jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="com.mh.user.model.SysMenu"> <update id="updateByPrimaryKeySelective" parameterType="com.mh.user.model.SysMenu">

40
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("进入到格式化表格");
}
}

2
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 token = request.getHeader("Authorization");
String tokenHead = "Bearer "; String tokenHead = "Bearer ";
if(token == null) { if(token == null) {
token = request.getHeader("token"); token = request.getHeader("X-Token");
} else if(token.contains(tokenHead)){ } else if(token.contains(tokenHead)){
token = token.substring(tokenHead.length()); token = token.substring(tokenHead.length());
} }

4
user-service/src/main/java/com/mh/user/utils/SecurityUtils.java

@ -35,7 +35,7 @@ public class SecurityUtils {
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
// 生成令牌并返回给客户端 // 生成令牌并返回给客户端
token.setToken(JwtTokenUtils.generateToken(authentication)); token.setToken(JwtTokenUtils.generateToken(authentication));
// System.out.println("返回token到前端!"); System.out.println("获取当前用户==>" + SecurityUtils.getUsername());
return token; return token;
} }
@ -62,6 +62,8 @@ public class SecurityUtils {
Object principal = authentication.getPrincipal(); Object principal = authentication.getPrincipal();
if(principal != null && principal instanceof UserDetails) { if(principal != null && principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername(); username = ((UserDetails) principal).getUsername();
} else {
username = (String) principal;
} }
} }
return username; return username;

26
user-service/src/test/java/com/mh/user/DealDataTest.java

@ -1,9 +1,14 @@
package com.mh.user; package com.mh.user;
import com.mh.user.mapper.chillers.DealDataMapper; 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.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/** /**
* @author ljf * @author ljf
* @title * @title
@ -11,13 +16,30 @@ import org.springframework.beans.factory.annotation.Autowired;
* @updateTime 2020-07-28 * @updateTime 2020-07-28
* @throws * @throws
*/ */
@Slf4j
public class DealDataTest extends UserServiceApplicationTests { public class DealDataTest extends UserServiceApplicationTests {
@Autowired @Autowired
private DealDataMapper dealDataMapper; private DealDataService dealDataService;
@Test @Test
public void dealChillersData() { 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<String> 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);
}
} }
} }

Loading…
Cancel
Save