Compare commits

...

10 Commits

Author SHA1 Message Date
review512jwy@163.com b8ebbd0a7e 完善代码 2 weeks ago
review512jwy@163.com 768698d2e0 TrendLog 2 weeks ago
review512jwy@163.com 06e0ed15cf 概览层级树 2 weeks ago
review512jwy@163.com 761a41a806 Merge branch 'ppt-20260120' into jwy 2 weeks ago
review512jwy@163.com 5a8f290586 修改权限,改为【全部 拒绝 只读】 2 weeks ago
review512jwy@163.com 8d578e825d 收藏分页 4 weeks ago
review512jwy@163.com 6c21b23e42 Merge branch 'ppt-20260120' into jwy 1 month ago
review512jwy@163.com b0f65a9091 Merge branch 'zhc' into jwy 2 months ago
review512jwy@163.com c77a58b174 合并冲突 3 months ago
review512jwy@163.com 4f6f2b1581 getOverviewInfo改为物件层级 4 months ago
  1. 7
      document/db/20260327.sql
  2. 5
      dongjian-dashboard-back-common/src/main/java/com/dongjian/dashboard/back/common/Constants.java
  3. 2
      dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml
  4. 2
      dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml
  5. 2
      dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml
  6. 2
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataBaStatusController.java
  7. 2
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataMeasureController.java
  8. 181
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataTrendLogController.java
  9. 13
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/OverviewController.java
  10. 46
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/RoleController.java
  11. 6
      dongjian-dashboard-back-controller/src/test/java/com/dongjian/dashboard/back/controller/AdminRoleControllerTest.java
  12. 16
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/BasicRoleMenuRelationMapperExt.java
  13. 2
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/BasicUserMapperExt.java
  14. 14
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/DeviceInfoMapperExt.java
  15. 7
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelMapperExt.java
  16. 60
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/BasicRoleMenuRelationMapperExt.xml
  17. 10
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/BasicUserMapperExt.xml
  18. 43
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/DeviceInfoMapperExt.xml
  19. 1
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/FavoritedDeviceMapperExt.xml
  20. 148
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml
  21. 12
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/data/TrendLogDataSearchParam.java
  22. 6
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/role/OptRoleParam.java
  23. 10
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/role/RoleMenuPermissionDTO.java
  24. 45
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/easyexcel/ExportDeviceTrendLogDataDTO.java
  25. 20
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/data/DeviceTrendLogData.java
  26. 18
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/BuildingPathDTO.java
  27. 32
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/DashboardTreeMenusDTO.java
  28. 13
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/MenuEntity.java
  29. 14
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/MenuTreeVO.java
  30. 13
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/RoleMenuPermissionEntity.java
  31. 22
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/DeviceDataTrendLogService.java
  32. 3
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/OverviewService.java
  33. 11
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/RoleService.java
  34. 23
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/common/CommonOpt.java
  35. 70
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/common/DashboardMenuTree.java
  36. 199
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceDataTrendLogServiceImpl.java
  37. 13
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/FavoritedDeviceServiceImpl.java
  38. 58
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OverviewServiceImpl.java
  39. 186
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java

7
document/db/20260327.sql

@ -0,0 +1,7 @@
CREATE TABLE basic_role_menu_relation_dashboard (
role_id BIGINT,
menu_id BIGINT,
permission_type INT COMMENT '0-拒绝 1-只读 2-全部',
creator_id BIGINT,
create_time BIGINT
);

5
dongjian-dashboard-back-common/src/main/java/com/dongjian/dashboard/back/common/Constants.java

@ -40,6 +40,7 @@ public class Constants {
public static final int CATEGORY_ACCUMULATE = 2;//累积
public static final int CATEGORY_MEASURE = 3;//计测
public static final int CATEGORY_STATUS= 4;//状态
public static final int CATEGORY_TRENDLOG= 5;//TrendLog
// // 所有设备类型ID的总集合
// public static final List<Integer> ALL_DEVICE_TYPE_IDS = new ArrayList<>();
@ -79,10 +80,12 @@ public class Constants {
CATEGORY_MAP.put(CATEGORY_MEASURE, new ArrayList<>(List.of(1003L)));
CATEGORY_MAP.put(CATEGORY_ACCUMULATE, new ArrayList<>(List.of(1002L,1006L)));
CATEGORY_MAP.put(CATEGORY_ACCUMULATE, new ArrayList<>(List.of(1002L)));
CATEGORY_MAP.put(CATEGORY_STATUS, new ArrayList<>(List.of(1004L)));
CATEGORY_MAP.put(CATEGORY_TRENDLOG, new ArrayList<>(List.of(1006L)));
// 收集所有的设备类型ID
for (List<Long> ids : CATEGORY_MAP.values()) {
ALL_CATEGORY_IDS.addAll(ids);

2
dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml

@ -146,5 +146,7 @@ msgcn:
editNotification: 编辑通知
delNotification: 删除通知
editDeviceField: 编辑设备属性
getTrendLogDataList: 获取TrendLog数据列表
exportTrendLogData: 导出TrendLog数据

2
dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml

@ -146,6 +146,8 @@ msgen:
editNotification: Edit notification
delNotification: Delete notification
editDeviceField: Edit device attributes
getTrendLogDataList: Get TrendLog data list
exportTrendLogData: Export TrendLog data

2
dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml

@ -146,6 +146,8 @@ msgjp:
editNotification: お知らせ管理
delNotification: お知らせ管理
editDeviceField: デバイス属性を編集
getTrendLogDataList: TrendLog
exportTrendLogData: TrendLog

2
dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataBaStatusController.java

@ -52,7 +52,7 @@ import java.util.List;
@SuppressWarnings("unchecked")
public class DeviceDataBaStatusController {
private static final Logger logger = LoggerFactory.getLogger(DeviceDataAccumulateController.class);
private static final Logger logger = LoggerFactory.getLogger(DeviceDataBaStatusController.class);
@Value("${export.page.size}")
private Integer EXPORT_PAGE_SIZE;

2
dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataMeasureController.java

@ -52,7 +52,7 @@ import java.util.List;
@SuppressWarnings("unchecked")
public class DeviceDataMeasureController {
private static final Logger logger = LoggerFactory.getLogger(DeviceDataAccumulateController.class);
private static final Logger logger = LoggerFactory.getLogger(DeviceDataMeasureController.class);
@Value("${export.page.size}")
private Integer EXPORT_PAGE_SIZE;

181
dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/DeviceDataTrendLogController.java

@ -0,0 +1,181 @@
package com.dongjian.dashboard.back.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.dongjian.dashboard.back.common.exception.BusinessException;
import com.dongjian.dashboard.back.common.response.PageInfo;
import com.dongjian.dashboard.back.common.response.PageResponse;
import com.dongjian.dashboard.back.common.response.ResponseCode;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.configurator.aspect.OperationLog;
import com.dongjian.dashboard.back.configurator.interceptor.AccessRequired;
import com.dongjian.dashboard.back.dto.data.TrendLogDataSearchParam;
import com.dongjian.dashboard.back.dto.device.LineDataSearchParams;
import com.dongjian.dashboard.back.easyexcel.ExportDeviceTrendLogDataDTO;
import com.dongjian.dashboard.back.easyexcel.LanguageDynamicHeaderAdapter;
import com.dongjian.dashboard.back.service.DeviceDataTrendLogService;
import com.dongjian.dashboard.back.service.common.CommonOpt;
import com.dongjian.dashboard.back.util.CommonUtil;
import com.dongjian.dashboard.back.vo.data.DeviceTrendLogData;
import com.dongjian.dashboard.back.vo.device.LineData;
import com.github.pagehelper.PageHelper;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
*
* @author jwy-style
*
*/
@RestController//代表返回的是json格式的数据,这个注解是Spring4之后新加的注解
@AccessRequired //注解标识是否需要验证token
@RequestMapping("/deviceTrendLog") //http请求路径映射
@Tag(name = "TrendLog设备的相关接口",description = "TrendLog设备的相关接口")
@SuppressWarnings("unchecked")
public class DeviceDataTrendLogController {
private static final Logger logger = LoggerFactory.getLogger(DeviceDataTrendLogController.class);
@Value("${export.page.size}")
private Integer EXPORT_PAGE_SIZE;
@Autowired
private DeviceDataTrendLogService deviceDataTrendLogService;
@Autowired
private CommonOpt commonOpt;
@OperationLog(operation = "getTrendLogDataList", remark = "")
@Operation(summary = "获取TrendLog数据列表")
@RequestMapping(value = "/getDataList",method = RequestMethod.GET)
public PageResponse<PageInfo<DeviceTrendLogData>> getListPage(
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required=true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required=false) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType,
TrendLogDataSearchParam pageSearchParam
) throws BusinessException {
pageSearchParam.setUserId(UserId);
// pageSearchParam.setCompanyId(CompanyId);
PageResponse<PageInfo<DeviceTrendLogData>> pageResponse = new PageResponse<PageInfo<DeviceTrendLogData>>();
try{
pageResponse.setData(deviceDataTrendLogService.getDataList(pageSearchParam, CompanyId, UserId, LanguageType));
pageResponse.setCode(ResponseCode.SUCCESS);
pageResponse.setMsg("success");
}catch (Exception e){
logger.error("查询列表报错",e);
pageResponse.setCode(ResponseCode.SERVER_ERROR);
pageResponse.setMsg("service error");
}
return pageResponse;
}
@OperationLog(operation = "exportTrendLogData", remark = "")
@Operation(summary = "导出TrendLog数据列表")
@GetMapping("/exportData")
public void exportDeviceTrendLog(HttpServletResponse response,
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required=true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required=false) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType,
TrendLogDataSearchParam pageSearchParam
) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode("TrendLog"+CommonUtil.generateExcelSuffix(), StandardCharsets.UTF_8).replace("+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
// ===== 固定导出分页大小=====
pageSearchParam.setPageSize(EXPORT_PAGE_SIZE);
// ===== 构建 Excel =====
List<List<String>> head = LanguageDynamicHeaderAdapter.buildHead(ExportDeviceTrendLogDataDTO.class, LanguageType);
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).head(head).build();
WriteSheet sheet = EasyExcel.writerSheet("sheet1").build();
// ===== 循环分页查询并写 Excel =====
int pageNum = 1;
try {
while (true) {
pageSearchParam.setPageNum(pageNum);
PageInfo<DeviceTrendLogData> pageData = deviceDataTrendLogService.getDataList(pageSearchParam, CompanyId, UserId, LanguageType);
List<DeviceTrendLogData> list = pageData.getList();
if (CollectionUtils.isEmpty(list)) {
break; // 没数据了,结束
}
for (DeviceTrendLogData item : list) {
ExportDeviceTrendLogDataDTO dto = new ExportDeviceTrendLogDataDTO();
BeanUtils.copyProperties(item, dto);
// dto.setLastYearRatio(CommonUtil.ratio(item.getCumulativeValue(), item.getLastYearValue()));
// dto.setYesterdayRatio(CommonUtil.ratio(item.getCumulativeValue(), item.getYesterdayValue()));
dto.setStatus111(commonOpt.status111Mapping(item.getStatus111()));
excelWriter.write(List.of(dto), sheet);
// 手动置空,提醒 GC 回收
dto = null;
item = null;
}
// 手动清理分页数据和缓存
list.clear();
PageHelper.clearPage();
// 最后一页判断(加这个更安全)
if (pageNum >= pageData.getPages()) {
break;
}
pageNum++;
}
} catch (Exception e) {
logger.error("export error", e);
throw e;
} finally {
excelWriter.finish();
PageHelper.clearPage();
}
}
@Hidden
@OperationLog(operation = "getLineData", remark = "")
@Operation(summary = "获取7日趋势数据")
@RequestMapping(value = "/getLineData",method = RequestMethod.POST)
public SimpleDataResponse<List<LineData>> getLineData(
@Parameter(name = "searchType", description = "1-按小时,2-全部数据", required = true) Integer searchType,
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required=true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required=false) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType,
@RequestBody LineDataSearchParams lineDataSearchParams
) throws BusinessException {
return deviceDataTrendLogService.getLineData(searchType, lineDataSearchParams, CompanyId, UserId, LanguageType);
}
}

13
dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/OverviewController.java

@ -3,6 +3,7 @@ package com.dongjian.dashboard.back.controller;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.configurator.interceptor.AccessRequired;
import com.dongjian.dashboard.back.service.OverviewService;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.dashboardnotification.DashboardNotificationPageVO;
import com.dongjian.dashboard.back.vo.data.OverviewVO;
import com.dongjian.dashboard.back.weather.JpMeshHourlyForecasts;
@ -66,4 +67,16 @@ public class OverviewController {
@Parameter(name = "UTCOffset", description = "Time zone offset in minutes from GMT, e.g., +480 for UTC+8", required = true, schema = @Schema(defaultValue = "-480")) @RequestHeader(required = true) Integer UTCOffset) {
return overviewService.getNotification(UserId, CompanyId, LanguageType, UTCOffset);
}
@Operation(summary = "获取当前登录用户绑定的层级树结构", description = "用于管理设置勾选层级ID")
@GetMapping("/bound/getOverallBoundLevel")
public SimpleDataResponse<List<TreeMenusDTO>> getOverallBoundLevel(
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required = true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required = true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required = true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required = false) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required = true) Integer LanguageType
){
return overviewService.getOverallBoundLevel(CompanyId, UserId, LanguageType);
}
}

46
dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/RoleController.java

@ -11,10 +11,15 @@ import com.dongjian.dashboard.back.configurator.interceptor.AccessRequired;
import com.dongjian.dashboard.back.dto.role.DeleteRoleParam;
import com.dongjian.dashboard.back.dto.role.OptRoleParam;
import com.dongjian.dashboard.back.dto.role.PageSearchParam;
import com.dongjian.dashboard.back.dto.role.RoleMenuPermissionDTO;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.DashboardTreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.MenuTreeVO;
import com.dongjian.dashboard.back.vo.role.RoleMenuPermissionEntity;
import com.dongjian.dashboard.back.vo.role.RolePageDTO;
import com.dongjian.dashboard.back.service.RoleService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
@ -110,7 +115,8 @@ public class RoleController {
}
return pageResponse;
}
@Hidden
@Operation(summary = "获取当前登录用户拥有的权限菜单树")
@RequestMapping(value = "/getOwnMenuIds",method = RequestMethod.GET)
public SimpleDataResponse<List<TreeMenusDTO>> getOwnMenuIds(
@ -121,7 +127,8 @@ public class RoleController {
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType){
return roleService.getOwnMenuIds(CompanyId, UserId, LanguageType);
}
@Hidden
@Operation(summary = "获取对应角色拥有的权限菜单ID")
@RequestMapping(value = "/getMenuIdsByRoleId",method = RequestMethod.GET)
public SimpleDataResponse<String> getMenuIdsByRoleId(
@ -133,5 +140,40 @@ public class RoleController {
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType){
return roleService.getMenuIdsByRoleId(roleId, CompanyId, UserId, LanguageType);
}
/**
* 获取菜单树 + 权限
*/
@GetMapping("/getOwnMenuTree")
public SimpleDataResponse<List<DashboardTreeMenusDTO>> getTree(
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required=true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType){
return roleService.getOwnMenuTree(CompanyId, UserId, LanguageType);
}
@Operation(summary = "获取对应角色拥有的权限菜单ID")
@RequestMapping(value = "/getMenuIdListByRoleId",method = RequestMethod.GET)
public SimpleDataResponse<List<RoleMenuPermissionEntity>> getMenuIdListByRoleId(
@Parameter(name="roleId",description="角色ID",required=true, schema = @Schema(defaultValue = "28")) @RequestParam Long roleId,
@Parameter(name = "LoginName", description = "Login name", required = true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,
@Parameter(name = "AccessToken", description = "Authentication token", required = true) @RequestHeader(required=true) String AccessToken,
@Parameter(name = "UserId", description = "User ID", required = true, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long UserId,
@Parameter(name = "CompanyId", description = "ID of the company to which the user belongs", required = false, schema = @Schema(defaultValue = "1")) @RequestHeader(required=true) Long CompanyId,
@Parameter(name = "LanguageType", description = "Language type (0: Chinese, 1: English, 2: Japanese)", required = true, schema = @Schema(defaultValue = "2")) @RequestHeader(required=true) Integer LanguageType){
return roleService.getMenuIdListByRoleId(roleId, CompanyId, UserId, LanguageType);
}
/**
* 保存权限
*/
@Hidden
@PostMapping("/save")
public void save(@RequestParam Long roleId,
@RequestBody List<RoleMenuPermissionDTO> list) {
roleService.saveRolePermission(roleId, list);
}
}

6
dongjian-dashboard-back-controller/src/test/java/com/dongjian/dashboard/back/controller/AdminRoleControllerTest.java

@ -30,6 +30,8 @@ import org.springframework.web.context.WebApplicationContext;
import jakarta.annotation.Resource;
import java.util.ArrayList;
@RunWith(SpringRunner.class)
@SpringBootTest
@ -134,7 +136,7 @@ public class AdminRoleControllerTest {
OptRoleParam param = new OptRoleParam();
param.setRoleName(ROLE_NAME);
param.setDescription("Description");
param.setMenuIds("1,2");
param.setMenuIds(new ArrayList<>());
return param;
}
@ -204,7 +206,7 @@ public class AdminRoleControllerTest {
param.setRoleId(getMockDataId());
param.setRoleName(ROLE_NAME);
param.setDescription("Description-edit");
param.setMenuIds("1,2,3");
param.setMenuIds(new ArrayList<>());
String content = (new ObjectMapper()).writeValueAsString(param);
System.out.println("testEdit params:"+content);

16
dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/BasicRoleMenuRelationMapperExt.java

@ -1,10 +1,14 @@
package com.dongjian.dashboard.back.dao.ex;
import java.util.List;
import java.util.Map;
import com.dongjian.dashboard.back.vo.role.DashboardTreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.RoleMenuPermissionEntity;
import org.apache.ibatis.annotations.Mapper;
import com.dongjian.dashboard.back.dao.auto.BasicRoleMenuRelationMapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface BasicRoleMenuRelationMapperExt extends BasicRoleMenuRelationMapper {
@ -14,4 +18,16 @@ public interface BasicRoleMenuRelationMapperExt extends BasicRoleMenuRelationMap
String getMenuIdsByRoleId(Long roleId);
void deleteDashboardRelation(Map<String, Object> deleteMap);
List<DashboardTreeMenusDTO> selectAllMenu(Map<String, Object> allMenusParamMap);
List<RoleMenuPermissionEntity> selectByRoleId(@Param("roleId") Long roleId);
int deleteByRoleId(@Param("roleId") Long roleId);
int dashboardBatchInsert(@Param("list") List<RoleMenuPermissionEntity> list);
Long getRoleIdByUserId(@Param("userId") Long userId);
List<RoleMenuPermissionEntity> getMenuIdListByRoleId(Long roleId);
}

2
dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/BasicUserMapperExt.java

@ -23,4 +23,6 @@ public interface BasicUserMapperExt extends BasicUserMapper{
UserInfoVO getAccountInfo(Map<String, Object> paramMap);
Integer checkBuildingManager(Long userId);
Integer checkLevelManager(Long userId);
}

14
dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/DeviceInfoMapperExt.java

@ -2,15 +2,9 @@ package com.dongjian.dashboard.back.dao.ex;
import com.dongjian.dashboard.back.dao.auto.DeviceInfoMapper;
import com.dongjian.dashboard.back.dto.data.AccumulateDataSearchParam;
import com.dongjian.dashboard.back.dto.data.AlarmDataSearchParam;
import com.dongjian.dashboard.back.dto.data.BaStatusDataSearchParam;
import com.dongjian.dashboard.back.dto.data.MeasureDataSearchParam;
import com.dongjian.dashboard.back.dto.data.*;
import com.dongjian.dashboard.back.dto.device.DeviceSearchParams;
import com.dongjian.dashboard.back.vo.data.DeviceAccumulateData;
import com.dongjian.dashboard.back.vo.data.DeviceAlarmData;
import com.dongjian.dashboard.back.vo.data.DeviceBaStatusData;
import com.dongjian.dashboard.back.vo.data.DeviceMeasureData;
import com.dongjian.dashboard.back.vo.data.*;
import com.dongjian.dashboard.back.vo.device.DeviceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -40,5 +34,7 @@ public interface DeviceInfoMapperExt extends DeviceInfoMapper {
List<DeviceAlarmData> getDevice4AlarmDataByGroup(AlarmDataSearchParam pageSearchParam);
List<String> selectAlertingDeviceIds(@Param("deviceIds") List<String> deviceIds);
List<DeviceTrendLogData> getDevice4TrendLogData(TrendLogDataSearchParam pageSearchParam);
List<DeviceTrendLogData> getDevice4TrendLogDataByGroup(TrendLogDataSearchParam pageSearchParam);
}

7
dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelMapperExt.java

@ -4,6 +4,8 @@ import com.dongjian.dashboard.back.dto.level.LevelEntity;
import com.dongjian.dashboard.back.dto.level.LevelRelationEntity;
import com.dongjian.dashboard.back.dto.level.OptLevelParam;
import com.dongjian.dashboard.back.dto.level.PageLevelSearchParam;
import com.dongjian.dashboard.back.vo.building.BindedBuildingVO;
import com.dongjian.dashboard.back.vo.level.BuildingPathDTO;
import com.dongjian.dashboard.back.vo.level.LevelPageDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -32,4 +34,9 @@ public interface LevelMapperExt {
void deleteLevelRelationByIdList(@Param("param") LevelRelationEntity param, @Param("idList") List<Long> idList);
List<LevelPageDTO> getListPage(PageLevelSearchParam pageSearchParam);
List<Long> getBoundBuilding(Long userId);
List<BuildingPathDTO> selectBuildingFullPath(@Param("bindBuildingIdList") List<Long> bindBuildingIdList);
}

60
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/BasicRoleMenuRelationMapperExt.xml

@ -30,5 +30,65 @@
r.role_id = #{roleId} AND m.used_by_dashboard = 1
</delete>
<select id="selectAllMenu" resultType="com.dongjian.dashboard.back.vo.role.DashboardTreeMenusDTO">
SELECT
bmenu.`id` AS `menuId`,
bmenu.parent_menu_id AS parentMenuId,
bmenu.menu_name AS title,
bmenu.dashboard_lowest_node AS dashboardLowestNode
FROM
basic_menu bmenu
<if test="superRole != null and superRole == 0">
inner join basic_role_menu_relation_dashboard brmrd on bmenu.id = brmrd.menu_id and brmrd.role_id = #{roleId}
</if>
WHERE
bmenu.flag = 0 AND bmenu.used_by_dashboard = 1
</select>
<select id="selectByRoleId" resultType="com.dongjian.dashboard.back.vo.role.RoleMenuPermissionEntity">
SELECT
role_id,
menu_id,
permission_type,
create_time
FROM basic_role_menu_relation_dashboard
WHERE role_id = #{roleId}
</select>
<delete id="deleteByRoleId">
DELETE FROM basic_role_menu_relation_dashboard
WHERE role_id = #{roleId}
</delete>
<insert id="dashboardBatchInsert">
INSERT INTO basic_role_menu_relation_dashboard (role_id, menu_id, permission_type, create_time)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.roleId},
#{item.menuId},
#{item.permissionType},
#{item.createTime})
</foreach>
</insert>
<select id="getRoleIdByUserId" resultType="long">
SELECT role_id
FROM basic_role_user_relation
WHERE user_id = #{userId}
LIMIT 1
</select>
<select id="getMenuIdListByRoleId" resultType="com.dongjian.dashboard.back.vo.role.RoleMenuPermissionEntity">
SELECT
brmrd.role_id,
brmrd.menu_id,
brmrd.permission_type,
brmrd.create_time
FROM
basic_role_menu_relation_dashboard brmrd
INNER JOIN basic_menu bmenu ON bmenu.id = brmrd.menu_id
WHERE
bmenu.flag != 1 AND brmrd.role_id = #{roleId} AND bmenu.used_by_dashboard = 1
</select>
</mapper>

10
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/BasicUserMapperExt.xml

@ -114,5 +114,15 @@
INNER JOIN data_center_aeon_admin.basic_role_menu_relation rmr ON br.id = rmr.role_id
WHERE rmr.menu_id = 52 AND br.flag != 1 AND rru.user_id = #{userId}
</select>
<select id="checkLevelManager" resultType="java.lang.Integer">
SELECT
count(1)
FROM
data_center_aeon_admin.basic_role_user_relation rru
INNER JOIN data_center_aeon_admin.basic_role br ON br.id = rru.role_id
INNER JOIN data_center_aeon_admin.basic_role_menu_relation rmr ON br.id = rmr.role_id
WHERE rmr.menu_id = 88 AND br.flag != 1 AND rru.user_id = #{userId}
</select>
</mapper>

43
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/DeviceInfoMapperExt.xml

@ -429,14 +429,41 @@
<include refid="alertHistoryOrder"/>
</select>
<select id="selectAlertingDeviceIds" resultType="java.lang.String">
SELECT DISTINCT LOWER(device_id) AS device_id
FROM alert_history
WHERE device_id IN
<foreach collection="deviceIds" item="deviceId" open="(" close=")" separator=",">
#{deviceId}
</foreach>
AND (<include refid="Where_In_Alarm"/>)
<select id="getDevice4TrendLogData" resultType="com.dongjian.dashboard.back.vo.data.DeviceTrendLogData">
select
<include refid="deviceDataSelect"/>
,drr.raw_data,
drr.receive_ts uploadTimestamp,
5 as classId
<include refid="deviceDataFromAndJoin"/>
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
<where>
<if test="buildingId != null">
and basic_building.building_id = #{buildingId}
</if>
<include refid="deviceDataCommonWhere"/>
</where>
<include refid="drrOrder"/>
</select>
<select id="getDevice4TrendLogDataByGroup" resultType="com.dongjian.dashboard.back.vo.data.DeviceTrendLogData">
select
<include refid="deviceDataSelect"/>
,drr.raw_data,
drr.receive_ts uploadTimestamp,
5 as classId
<include refid="deviceDataFromAndJoin"/>
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
left join dashboard_device_group_relation ddgr on ddgr.device_info_id = device_info.id
<where>
<if test="buildingId != null">
and basic_building.building_id = #{buildingId}
</if>
and ddgr.device_group_id = #{deviceGroupId}
<include refid="deviceDataCommonWhere"/>
</where>
<include refid="drrOrder"/>
</select>
<!-- 公共字段 -->

1
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/FavoritedDeviceMapperExt.xml

@ -19,6 +19,7 @@
left join type ty on ty.id = dinfo.type_id
WHERE
dinfo.flag != 1 AND basic_monitoring_asset.flag != 1
AND (dinfo.device_id LIKE '%\_85' or dinfo.device_id LIKE '%\_85_9003' or dinfo.device_id LIKE '%\_131_5')
AND basic_space.flag != 1 AND basic_floor.flag != 1 AND basic_building.flag != 1
<if test="buildingId != null">
AND basic_building.building_id = #{buildingId}

148
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml

@ -180,4 +180,152 @@
order BY base.`id` desc
</select>
<select id="getBoundBuilding" resultType="java.lang.Long">
SELECT DISTINCT building_id
FROM (
-- BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
ON ru.level_role_id = ro.level_role_id
JOIN basic_building b
ON ro.ref_id = b.building_id
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'BUILDING'
AND b.flag = 0
UNION ALL
-- SITE → BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
ON ru.level_role_id = ro.level_role_id
JOIN dashboard_level_site s
ON ro.ref_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_site_building rsb
ON s.id = rsb.site_id
JOIN basic_building b
ON rsb.building_id = b.building_id AND b.flag = 0
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'SITE'
UNION ALL
-- AREA → SITE → BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
ON ru.level_role_id = ro.level_role_id
JOIN dashboard_level_area a
ON ro.ref_id = a.id AND a.flag = 0
JOIN dashboard_level_relation_area_site ras
ON a.id = ras.area_id
JOIN dashboard_level_site s
ON ras.site_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_site_building rsb
ON s.id = rsb.site_id
JOIN basic_building b
ON rsb.building_id = b.building_id AND b.flag = 0
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'AREA'
UNION ALL
-- STORE → AREA → SITE → BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
ON ru.level_role_id = ro.level_role_id
JOIN dashboard_level_store st
ON ro.ref_id = st.id AND st.flag = 0
JOIN dashboard_level_relation_store_area rsa
ON st.id = rsa.store_id
JOIN dashboard_level_area a
ON rsa.area_id = a.id AND a.flag = 0
JOIN dashboard_level_relation_area_site ras
ON a.id = ras.area_id
JOIN dashboard_level_site s
ON ras.site_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_site_building rsb
ON s.id = rsb.site_id
JOIN basic_building b
ON rsb.building_id = b.building_id AND b.flag = 0
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'STORE'
UNION ALL
-- BRANCH → STORE → AREA → SITE → BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
ON ru.level_role_id = ro.level_role_id
JOIN dashboard_level_branch br
ON ro.ref_id = br.id AND br.flag = 0
JOIN dashboard_level_relation_branch_store rbs
ON br.id = rbs.branch_id
JOIN dashboard_level_store st
ON rbs.store_id = st.id AND st.flag = 0
JOIN dashboard_level_relation_store_area rsa
ON st.id = rsa.store_id
JOIN dashboard_level_area a
ON rsa.area_id = a.id AND a.flag = 0
JOIN dashboard_level_relation_area_site ras
ON a.id = ras.area_id
JOIN dashboard_level_site s
ON ras.site_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_site_building rsb
ON s.id = rsb.site_id
JOIN basic_building b
ON rsb.building_id = b.building_id AND b.flag = 0
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'BRANCH'
) t;
</select>
<select id="selectBuildingFullPath" resultType="com.dongjian.dashboard.back.vo.level.BuildingPathDTO">
SELECT
br.id AS branch_id,
br.name AS branch_name,
st.id AS store_id,
st.name AS store_name,
a.id AS area_id,
a.name AS area_name,
s.id AS site_id,
s.name AS site_name,
b.building_id,
b.name AS building_name
FROM basic_building b
JOIN dashboard_level_relation_site_building rsb ON b.building_id = rsb.building_id
JOIN dashboard_level_site s ON rsb.site_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_area_site ras ON s.id = ras.site_id
JOIN dashboard_level_area a ON ras.area_id = a.id AND a.flag = 0
JOIN dashboard_level_relation_store_area rsa ON a.id = rsa.area_id
JOIN dashboard_level_store st ON rsa.store_id = st.id AND st.flag = 0
JOIN dashboard_level_relation_branch_store rbs ON st.id = rbs.store_id
JOIN dashboard_level_branch br ON rbs.branch_id = br.id AND br.flag = 0
WHERE b.building_id IN
<foreach collection="bindBuildingIdList" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND b.flag = 0;
</select>
</mapper>

12
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/data/TrendLogDataSearchParam.java

@ -0,0 +1,12 @@
package com.dongjian.dashboard.back.dto.data;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class TrendLogDataSearchParam extends DataSearchParam {
}

6
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/role/OptRoleParam.java

@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author zhc
* @time 2022年6月14日10:56:38
@ -22,8 +24,8 @@ public class OptRoleParam {
@Schema(description = "描述",example = "这是管理员描述", required = true)
private String description;
@Schema(description = "菜单权限ID,使用逗号连接",example = "1,4,5,6", required = true)
private String menuIds;
@Schema(description = "菜单权限ID,使用逗号连接",example = "[]", required = true)
private List<RoleMenuPermissionDTO> menuIds;
@Schema(description = "所属企业ID",example = "2", hidden = true)
private Long companyId;

10
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/role/RoleMenuPermissionDTO.java

@ -0,0 +1,10 @@
package com.dongjian.dashboard.back.dto.role;
import lombok.Data;
@Data
public class RoleMenuPermissionDTO {
private Long menuId;
private Integer permissionType;
}

45
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/easyexcel/ExportDeviceTrendLogDataDTO.java

@ -0,0 +1,45 @@
package com.dongjian.dashboard.back.easyexcel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class ExportDeviceTrendLogDataDTO {
@ExcelProperty(value = {"上传时间", "Upload Time", "計測日時"}, converter = TimestampConverter.class)
private Long uploadTimestamp;
@ExcelProperty({"设施名", "Facility Name", "施設名"})
private String buildingName;
@ExcelProperty({"监视点名称", "Monitoring Point Name", "監視点名称"})
private String monitoringPointName;
@ExcelProperty({"楼层名称", "Floor", "フロア"})
private String floorName;
@ExcelProperty({"监控点分类名称", "Category", "分類"})
private String monitoringPointCategoryName;
// @ExcelProperty({"网关信息名称", "Gateway Info Name", "接続先情報"})
// private String gatewayInfoName;
// @ExcelProperty({"数据提供方名称", "Data Provider Name", "データソース"})
// private String dataProviderName;
@ExcelProperty({"设备状态", "Device Status", "ステータスフラグ"})
private String status111;
@ExcelProperty({"积算值", "Accumulated Value", "積算値"})
private String cumulativeValue;
// @ExcelProperty({"前日比(%)", "Previous Day Ratio(%)", "前日比(%)"})
// private String yesterdayRatio;
//
// @ExcelProperty({"前年比(%)", "Previous Year Ratio(%)", "前年比(%)"})
// private String lastYearRatio;
@ExcelProperty({"单位", "Unit", "単位"})
private String unit;
}

20
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/data/DeviceTrendLogData.java

@ -0,0 +1,20 @@
package com.dongjian.dashboard.back.vo.data;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class DeviceTrendLogData extends BaseData{
@Schema(description = "cumulative value", example = "12.557")
private String cumulativeValue;
@Schema(description = "raw data", example = "", hidden = true)
private String rawData;
@Schema(description = "device status", example = "障害")
private String status111;
}

18
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/BuildingPathDTO.java

@ -0,0 +1,18 @@
package com.dongjian.dashboard.back.vo.level;
import lombok.Data;
@Data
public class BuildingPathDTO {
private Long branchId;
private Long storeId;
private Long areaId;
private Long siteId;
private Long buildingId;
private String branchName;
private String storeName;
private String areaName;
private String siteName;
private String buildingName;
}

32
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/DashboardTreeMenusDTO.java

@ -0,0 +1,32 @@
package com.dongjian.dashboard.back.vo.role;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* @author Mr.Jiang
* @time 2022年7月29日 下午4:37:50
*/
@Data
public class DashboardTreeMenusDTO {
@Schema(description = "节点ID",example = "11", required = true)
private Long menuId;
@Schema(description = "父节点ID",example = "2", hidden = true)
private Long parentMenuId;
@Schema(description = "节点名称",example = "添加", required = true)
private String title;
@Schema(description = "子节点",example = "[]", required = false)
private List<DashboardTreeMenusDTO> children;
private Integer permissionType; // 0-拒绝 1-只读 2-全部 null=半选
private Integer dashboardLowestNode; // 0-否 1-是
}

13
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/MenuEntity.java

@ -0,0 +1,13 @@
package com.dongjian.dashboard.back.vo.role;
import lombok.Data;
@Data
public class MenuEntity {
private Long id;
private Long parentMenuId;
private String menuName;
private Integer menuLevel;
private Integer flag;
}

14
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/MenuTreeVO.java

@ -0,0 +1,14 @@
package com.dongjian.dashboard.back.vo.role;
import lombok.Data;
import java.util.List;
@Data
public class MenuTreeVO {
private Long id;
private String name;
private Integer permissionType;
private List<MenuTreeVO> children;
}

13
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/role/RoleMenuPermissionEntity.java

@ -0,0 +1,13 @@
package com.dongjian.dashboard.back.vo.role;
import lombok.Data;
@Data
public class RoleMenuPermissionEntity {
private Long roleId;
private Long menuId;
private Integer permissionType;
private Long createTime;
}

22
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/DeviceDataTrendLogService.java

@ -0,0 +1,22 @@
package com.dongjian.dashboard.back.service;
import com.dongjian.dashboard.back.common.response.PageInfo;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.dto.data.TrendLogDataSearchParam;
import com.dongjian.dashboard.back.dto.device.LineDataSearchParams;
import com.dongjian.dashboard.back.vo.data.DeviceTrendLogData;
import com.dongjian.dashboard.back.vo.device.LineData;
import java.util.List;
/**
* Service.
*/
public interface DeviceDataTrendLogService {
PageInfo<DeviceTrendLogData> getDataList(TrendLogDataSearchParam pageSearchParam, Long companyId, Long userId, Integer languageType);
List<DeviceTrendLogData> handleDeviceAccumulateData(TrendLogDataSearchParam pageSearchParam);
SimpleDataResponse<List<LineData>> getLineData(Integer searchType, LineDataSearchParams lineDataSearchParams, Long companyId, Long userId, Integer languageType);
}

3
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/OverviewService.java

@ -1,6 +1,7 @@
package com.dongjian.dashboard.back.service;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.dashboardnotification.DashboardNotificationPageVO;
import com.dongjian.dashboard.back.vo.data.OverviewVO;
import com.dongjian.dashboard.back.weather.JpMeshHourlyForecasts;
@ -18,4 +19,6 @@ public interface OverviewService {
SimpleDataResponse<JpMeshHourlyForecasts> getWeatherInfo(QueryWeather queryWeather, Long userId, Long companyId, Integer languageType, Integer utcOffset);
SimpleDataResponse<List<DashboardNotificationPageVO>> getNotification(Long userId, Long companyId, Integer languageType, Integer utcOffset);
SimpleDataResponse<List<TreeMenusDTO>> getOverallBoundLevel(Long companyId, Long userId, Integer languageType);
}

11
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/RoleService.java

@ -6,7 +6,11 @@ import com.dongjian.dashboard.back.common.response.PageInfo;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.dto.role.DeleteRoleParam;
import com.dongjian.dashboard.back.dto.role.OptRoleParam;
import com.dongjian.dashboard.back.dto.role.RoleMenuPermissionDTO;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.DashboardTreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.MenuTreeVO;
import com.dongjian.dashboard.back.vo.role.RoleMenuPermissionEntity;
import com.dongjian.dashboard.back.vo.role.RolePageDTO;
/**
@ -26,6 +30,11 @@ public interface RoleService {
PageInfo<RolePageDTO> getListPage(com.dongjian.dashboard.back.dto.role.PageSearchParam pageSearchParam,
Long companyId, Long userId, Integer languageType);
SimpleDataResponse<List<DashboardTreeMenusDTO>> getOwnMenuTree(Long companyId, Long userId, Integer languageType);
void saveRolePermission(Long roleId, List<RoleMenuPermissionDTO> list);
SimpleDataResponse<List<RoleMenuPermissionEntity>> getMenuIdListByRoleId(Long roleId, Long companyId, Long userId, Integer languageType);
}

23
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/common/CommonOpt.java

@ -71,6 +71,8 @@ public class CommonOpt {
@Autowired
private UserBuildingRelationMapperExt userBuildingRelationMapperExt;
@Autowired
private LevelMapperExt levelMapperExt;
@Autowired
private DeviceRawdataRealtimeMapperExt deviceRawdataRealtimeMapperExt;
@Autowired
private DeviceInfoMapperExt deviceInfoMapperExt;
@ -239,16 +241,29 @@ public class CommonOpt {
return result;
}
// public List<Long> getBindBuildingIdList(Long userId) {
// Integer buildingManager = basicUserMapperExt.checkBuildingManager(userId);
// if (buildingManager > 0) {
// return null;//null表示不限制, sql里面判定bindedBuildingList=null的话,就不限制楼宇
// } else {
// List<BindedBuildingVO> bindedBuildingList = userBuildingRelationMapperExt.getBindedBuilding(userId);
// if (CollectionUtils.isEmpty(bindedBuildingList)) {
// return Collections.singletonList(-1L);//-1的话,表示没有绑定
// } else {
// return bindedBuildingList.stream().map(BindedBuildingVO::getBuildingId).collect(Collectors.toList());
// }
// }
// }
public List<Long> getBindBuildingIdList(Long userId) {
Integer buildingManager = basicUserMapperExt.checkBuildingManager(userId);
if (buildingManager > 0) {
Integer levelManager = basicUserMapperExt.checkLevelManager(userId);
if (levelManager > 0) {
return null;//null表示不限制, sql里面判定bindedBuildingList=null的话,就不限制楼宇
} else {
List<BindedBuildingVO> bindedBuildingList = userBuildingRelationMapperExt.getBindedBuilding(userId);
List<Long> bindedBuildingList = levelMapperExt.getBoundBuilding(userId);
if (CollectionUtils.isEmpty(bindedBuildingList)) {
return Collections.singletonList(-1L);//-1的话,表示没有绑定
} else {
return bindedBuildingList.stream().map(BindedBuildingVO::getBuildingId).collect(Collectors.toList());
return bindedBuildingList;
}
}
}

70
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/common/DashboardMenuTree.java

@ -0,0 +1,70 @@
package com.dongjian.dashboard.back.service.common;
import com.dongjian.dashboard.back.vo.role.DashboardTreeMenusDTO;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class DashboardMenuTree {
private List<DashboardTreeMenusDTO> menuList = new ArrayList<>();
public DashboardMenuTree(List<DashboardTreeMenusDTO> menuList) {
this.menuList = menuList;
}
/**
* 构建树
*/
public List<DashboardTreeMenusDTO> buildTree(String rootNodeKey) {
List<DashboardTreeMenusDTO> treeMenus = new ArrayList<>();
for (DashboardTreeMenusDTO node : getRootNode(rootNodeKey)) {
treeMenus.add(buildChildTree(node));
}
return treeMenus;
}
/**
* 构建子树核心修改点
*/
private DashboardTreeMenusDTO buildChildTree(DashboardTreeMenusDTO parent) {
// 如果是最小节点 → 直接终止
if (parent.getDashboardLowestNode() != null
&& parent.getDashboardLowestNode() == 1) {
parent.setChildren(new ArrayList<>());
return parent;
}
List<DashboardTreeMenusDTO> children = new ArrayList<>();
for (DashboardTreeMenusDTO node : menuList) {
if (node.getParentMenuId().equals(parent.getMenuId())) {
children.add(buildChildTree(node));
}
}
parent.setChildren(children);
return parent;
}
/**
* 获取根节点
*/
private List<DashboardTreeMenusDTO> getRootNode(String rootNodeKey) {
List<DashboardTreeMenusDTO> roots = new ArrayList<>();
for (DashboardTreeMenusDTO node : menuList) {
if (Objects.equals(String.valueOf(node.getParentMenuId()), rootNodeKey)) {
roots.add(node);
}
}
return roots;
}
}

199
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceDataTrendLogServiceImpl.java

@ -0,0 +1,199 @@
package com.dongjian.dashboard.back.service.impl;
import com.dongjian.dashboard.back.common.Constants;
import com.dongjian.dashboard.back.common.language.msg.MsgLanguageChange;
import com.dongjian.dashboard.back.common.response.PageInfo;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.dao.aurora.DashboardRecordAccumulateMapperExt;
import com.dongjian.dashboard.back.dao.ex.DeviceInfoMapperExt;
import com.dongjian.dashboard.back.dao.ex.DeviceRawdataRealtimeMapperExt;
import com.dongjian.dashboard.back.dao.ex.FavoritedDeviceMapperExt;
import com.dongjian.dashboard.back.dto.data.TrendLogDataSearchParam;
import com.dongjian.dashboard.back.dto.device.LineDataSearchParams;
import com.dongjian.dashboard.back.model.DeviceRawdataRealtime;
import com.dongjian.dashboard.back.service.DeviceDataTrendLogService;
import com.dongjian.dashboard.back.service.common.CommonOpt;
import com.dongjian.dashboard.back.util.CommonUtil;
import com.dongjian.dashboard.back.util.DateUtil;
import com.dongjian.dashboard.back.vo.data.DeviceTrendLogData;
import com.dongjian.dashboard.back.vo.device.DeviceIncrement;
import com.dongjian.dashboard.back.vo.device.LineData;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class DeviceDataTrendLogServiceImpl implements DeviceDataTrendLogService {
private static final Logger logger = LoggerFactory.getLogger(DeviceDataTrendLogServiceImpl.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
@Autowired
private DeviceInfoMapperExt deviceInfoMapperExt;
@Autowired
private FavoritedDeviceMapperExt favoritedDeviceMapperExt;
@Autowired
private DashboardRecordAccumulateMapperExt dashboardRecordAccumulateMapperExt;
@Autowired
private DeviceRawdataRealtimeMapperExt deviceRawdataRealtimeMapperExt;
@Autowired
private MsgLanguageChange msgLanguageChange;
@Autowired
private CommonOpt commonOpt;
@Override
public PageInfo<DeviceTrendLogData> getDataList(TrendLogDataSearchParam pageSearchParam, Long companyId, Long userId, Integer languageType) {
// if (null == pageSearchParam.getBuildingId()) {
// return new PageInfo<>(new ArrayList<>());
// }
//list防${}注入
if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) {
pageSearchParam.setCompanyIdList(List.of(companyId));
} else {
pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds()));
}
PageHelper.startPage(pageSearchParam.getPageNum() == null ? 1 : pageSearchParam.getPageNum(), pageSearchParam.getPageSize() == null ? 20 : pageSearchParam.getPageSize());
return new PageInfo<>(handleDeviceAccumulateData(pageSearchParam));
}
public List<DeviceTrendLogData> handleDeviceAccumulateData(TrendLogDataSearchParam pageSearchParam) {
List<DeviceTrendLogData> resultList;
if (StringUtils.isNotBlank(pageSearchParam.getKeyword())) {
try {
pageSearchParam.setKeyword(URLDecoder.decode(pageSearchParam.getKeyword(), StandardCharsets.UTF_8));
} catch (Exception e) {
logger.error("URLDecoder.decode error", e);
}
}
pageSearchParam.setCategoryIdList(Constants.CATEGORY_MAP.get(Constants.CATEGORY_TRENDLOG));
if (null != pageSearchParam.getDeviceGroupId()){
resultList = deviceInfoMapperExt.getDevice4TrendLogDataByGroup(pageSearchParam);
} else {
resultList = deviceInfoMapperExt.getDevice4TrendLogData(pageSearchParam);
}
if (CollectionUtils.isNotEmpty(resultList)) {
// 查询 favorited_device 表中所有设备的 device_id,转为 Set 提高 contains 性能
Set<String> favoritedDeviceIds = new HashSet<>(favoritedDeviceMapperExt.getFavoritedDeviceIds());
List<String> deviceIds = resultList.stream()
.map(DeviceTrendLogData::getDeviceId)
.toList();
// 查询 111状态 数据
Map<String, String> deviceId85To111Map = commonOpt.buildDeviceId85To111Map(deviceIds);
List<String> deviceIdList_111 = deviceId85To111Map.values()
.stream()
.toList();
Map<String, DeviceRawdataRealtime> realtime111Map = commonOpt.queryRealtimeMap(deviceIdList_111);
// Map<String, DeviceInfo> deviceInfo111Map = commonOpt.queryDeviceInfoMap(deviceIdList_111);
// 查询S备用设备的数据,因为先看备用S设备,有S的话优先用这个
Map<String, String> deviceId85ToSMap = commonOpt.buildDeviceId85ToSMap(deviceIds);
List<String> deviceIdList_S = deviceId85ToSMap.values()
.stream()
.toList();
Map<String, DeviceRawdataRealtime> realtimeSMap = commonOpt.queryRealtimeMap(deviceIdList_S);
// 筛选出S后缀里数据更新的设备,用于查今天的积算值
List<String> todayDeviceIds = new ArrayList<>(deviceIds);
for (DeviceTrendLogData data : resultList) {
String rawDeviceId = data.getDeviceId();
String sDeviceId = deviceId85ToSMap.get(rawDeviceId.toLowerCase());
DeviceRawdataRealtime sRealtime = realtimeSMap.get(sDeviceId);
if (sRealtime == null || sRealtime.getReceiveTs() == null) {
continue;
}
//sRealtime存在且有receive_ts时
Long uploadTs = data.getUploadTimestamp();
if (uploadTs == null || sRealtime.getReceiveTs() > uploadTs) {
todayDeviceIds.remove(rawDeviceId);
todayDeviceIds.add(sDeviceId);
}
}
LocalDateTime now = LocalDateTime.now(Constants.ZONE_TOKYO);
LocalDate today = now.toLocalDate();
LocalDate yesterday = today.minusDays(1);
LocalDate lastYear = DateUtil.getLastYearSameIsoWeekDay(today);
int targetSeconds = now.toLocalTime().toSecondOfDay();
// 批量查询增量数据并构建 Map
Map<String, DeviceIncrement> todayMap = dashboardRecordAccumulateMapperExt.selectTodayIncrement(todayDeviceIds, today.getYear(), today.getMonthValue(), today.getDayOfMonth())
.stream().collect(Collectors.toMap(di -> di.getDeviceId().toLowerCase(), Function.identity()));
// List<RecordAccumulateDto> yesterdayRecords = dashboardRecordAccumulateMapperExt.selectByDay(deviceIds, yesterday.getYear(), yesterday.getMonthValue(), yesterday.getDayOfMonth());
// Map<String, DeviceIncrement> yesterdayMap = commonOpt.toDeviceIncrementMap(yesterdayRecords, targetSeconds, "yesterday");
//
// List<RecordAccumulateDto> lastYearRecords = dashboardRecordAccumulateMapperExt.selectByDay(deviceIds, lastYear.getYear(), lastYear.getMonthValue(), lastYear.getDayOfMonth());
// Map<String, DeviceIncrement> lastYearMap = commonOpt.toDeviceIncrementMap(lastYearRecords, targetSeconds, "lastYear");
resultList.forEach(data -> {
String deviceId = data.getDeviceId().toLowerCase();
String sDeviceId = deviceId85ToSMap.get(deviceId);
//*** 填充今天/昨天/去年值 **//
// 今天值,要先看备用S设备,有S的话优先用这个
data.setCumulativeValue(CommonUtil.formatDecimal(
getIncrement(todayDeviceIds.contains(sDeviceId) ? todayMap.get(sDeviceId) : todayMap.get(deviceId), DeviceIncrement::getTodayIncrement),
data.getDashboardDecimalPlaces())
);
// data.setYesterdayValue(CommonUtil.formatDecimal(getIncrement(yesterdayMap.get(deviceId), DeviceIncrement::getYesterdayIncrement), data.getDashboardDecimalPlaces()));
// data.setLastYearValue(CommonUtil.formatDecimal(getIncrement(lastYearMap.get(deviceId), DeviceIncrement::getLastYearIncrement), data.getDashboardDecimalPlaces()));
//处理111状态映射
// data.setStatus111(commonOpt.buildStatus111(deviceId, deviceId85To111Map, deviceInfo111Map, realtime111Map, objectMapper));
data.setStatus111(commonOpt.buildRawFirstValue(deviceId, deviceId85To111Map, realtime111Map, objectMapper));
// favorited 判断
data.setCollected(favoritedDeviceIds.contains(deviceId) ? 1 : 0);
});
}
return resultList;
}
//统一处理 null 判断和转字符串
private String getIncrement(DeviceIncrement inc, Function<DeviceIncrement, Number> getter) {
if (inc == null || getter.apply(inc) == null) return null;
return getter.apply(inc).toString();
}
@Override
public SimpleDataResponse<List<LineData>> getLineData(Integer searchType, LineDataSearchParams lineDataSearchParams,
Long companyId, Long userId, Integer languageType) {
if (null == searchType) {
searchType = 2;//默认全部数据
}
List<LineData> lineDataList = commonOpt.getAccumulateLineData(companyId, searchType, lineDataSearchParams);
return SimpleDataResponse.success(lineDataList);
}
}

13
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/FavoritedDeviceServiceImpl.java

@ -125,7 +125,18 @@ public class FavoritedDeviceServiceImpl implements FavoritedDeviceService {
resultList.add(data);
}
return new PageInfo<>(resultList);
// -------------------- 保留 PageHelper 分页信息 --------------------
PageInfo<FavoritedDeviceVO> pageInfo = new PageInfo<>(favoritedDeviceVOList);
PageInfo<Object> resultPageInfo = new PageInfo<>();
resultPageInfo.setList(resultList);
resultPageInfo.setPageNum(pageInfo.getPageNum());
resultPageInfo.setPageSize(pageInfo.getPageSize());
resultPageInfo.setTotal(pageInfo.getTotal());
resultPageInfo.setPages(pageInfo.getPages());
resultPageInfo.setHasNextPage(pageInfo.isHasNextPage());
resultPageInfo.setHasPreviousPage(pageInfo.isHasPreviousPage());
return resultPageInfo;
}
private Map<String, DeviceAlarmData> buildAlarmDataMap(Long companyId, Integer languageType, List<String> deviceIds) {

58
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OverviewServiceImpl.java

@ -4,15 +4,19 @@ import com.dongjian.dashboard.back.common.Constants;
import com.dongjian.dashboard.back.common.response.ResponseCode;
import com.dongjian.dashboard.back.common.response.SimpleDataResponse;
import com.dongjian.dashboard.back.dao.ex.DashboardNotificationMapperExt;
import com.dongjian.dashboard.back.dao.ex.LevelMapperExt;
import com.dongjian.dashboard.back.dao.ex.MonitoringPointCategoryMapperExt;
import com.dongjian.dashboard.back.dao.ex.OverviewInfoMapperExt;
import com.dongjian.dashboard.back.dto.monitoringpointcategory.MonitoringPointCategorySearchParams;
import com.dongjian.dashboard.back.service.OverviewService;
import com.dongjian.dashboard.back.service.common.CommonOpt;
import com.dongjian.dashboard.back.service.common.MenuTree;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.dashboardnotification.DashboardNotificationPageVO;
import com.dongjian.dashboard.back.vo.data.OverviewCategoryVO;
import com.dongjian.dashboard.back.vo.data.OverviewInfo;
import com.dongjian.dashboard.back.vo.data.OverviewVO;
import com.dongjian.dashboard.back.vo.level.BuildingPathDTO;
import com.dongjian.dashboard.back.vo.monitoringpointcategory.MonitoringPointCategoryPageVO;
import com.dongjian.dashboard.back.weather.JpMeshHourlyForecasts;
import com.dongjian.dashboard.back.weather.QueryWeather;
@ -53,6 +57,10 @@ public class OverviewServiceImpl implements OverviewService {
private DashboardNotificationMapperExt dashboardNotificationMapperExt;
@Autowired
private MonitoringPointCategoryMapperExt monitoringPointCategoryMapperExt;
@Autowired
private LevelMapperExt levelMapperExt;
@Autowired
private CommonOpt commonOpt;
@ -264,4 +272,54 @@ public class OverviewServiceImpl implements OverviewService {
return SimpleDataResponse.success(dashboardNotificationMapperExt.getNotification(companyId));
}
@Override
public SimpleDataResponse<List<TreeMenusDTO>> getOverallBoundLevel(Long companyId, Long userId, Integer languageType) {
List<Long> bindBuildingIdList = commonOpt.getBindBuildingIdList(userId);
List<BuildingPathDTO> selectBuildingFullPath = levelMapperExt.selectBuildingFullPath(bindBuildingIdList);
// 构建节点
Map<String, TreeMenusDTO> nodeMap = new HashMap<>();
for (BuildingPathDTO row : selectBuildingFullPath) {
String branchKey = "BRANCH-" + row.getBranchId();
String storeKey = "STORE-" + row.getStoreId() + "-" + branchKey;
String areaKey = "AREA-" + row.getAreaId() + "-" + storeKey;
String siteKey = "SITE-" + row.getSiteId() + "-" + areaKey;
String buildingKey = "BUILDING-" + row.getBuildingId() + "-" + siteKey;
nodeMap.putIfAbsent(branchKey,
createNode(branchKey, "ROOT", row.getBranchName()));
nodeMap.putIfAbsent(storeKey,
createNode(storeKey, branchKey, row.getStoreName()));
nodeMap.putIfAbsent(areaKey,
createNode(areaKey, storeKey, row.getAreaName()));
nodeMap.putIfAbsent(siteKey,
createNode(siteKey, areaKey, row.getSiteName()));
nodeMap.putIfAbsent(buildingKey,
createNode(buildingKey, siteKey, row.getBuildingName()));
}
List<TreeMenusDTO> allNodes = new ArrayList<>(nodeMap.values());
// 原来的 MenuTree
MenuTree tree = new MenuTree(allNodes);
List<TreeMenusDTO> result = tree.buildTree("ROOT");
return SimpleDataResponse.success(result);
}
private TreeMenusDTO createNode(String key, String parentKey, String label) {
TreeMenusDTO node = new TreeMenusDTO();
node.setKey(key);
node.setParentKey(parentKey);
node.setLabel(label);
return node;
}
}

186
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java

@ -1,5 +1,8 @@
package com.dongjian.dashboard.back.service.impl;
import com.dongjian.dashboard.back.dto.role.RoleMenuPermissionDTO;
import com.dongjian.dashboard.back.service.common.DashboardMenuTree;
import com.dongjian.dashboard.back.vo.role.*;
import com.github.pagehelper.PageHelper;
import com.dongjian.dashboard.back.common.exception.MsgCodeException;
import com.dongjian.dashboard.back.common.language.msg.MsgLanguageChange;
@ -19,7 +22,6 @@ import com.dongjian.dashboard.back.service.common.CommonOpt;
import com.dongjian.dashboard.back.service.common.MenuTree;
import com.dongjian.dashboard.back.util.CommonUtil;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.role.RolePageDTO;
import java.util.*;
import java.util.stream.Collectors;
@ -94,26 +96,23 @@ public class RoleServiceImpl implements RoleService {
private void insertRoleMenuRelation(Long companyId, Long userId, long currentUnix, Long roleId, String menuIds) {
if (StringUtils.isNoneBlank(menuIds)) {
//把无效的id去掉
menuIds = filterMenuIds(companyId, userId, menuIds);
if (StringUtils.isBlank(menuIds)) {
return;
}
//先删除原有的角色ID
Map<String, Object> deleteMap = new HashMap<>();
deleteMap.put("roleId", roleId);
basicRoleMenuRelationMapperExt.deleteDashboardRelation(deleteMap);
//重新插入关联关系
List<Long> idList = Arrays.asList(menuIds.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("roleId", roleId);
paramMap.put("menuIds", idList);
paramMap.put("creatorId", userId);
paramMap.put("createTime", currentUnix);
basicRoleMenuRelationMapperExt.batchInsert(paramMap);
private void insertRoleMenuRelation(Long companyId, Long userId, long currentUnix, Long roleId, List<RoleMenuPermissionDTO> menuIds) {
basicRoleMenuRelationMapperExt.deleteByRoleId(roleId);
if (menuIds == null || menuIds.isEmpty()) {
return;
}
List<RoleMenuPermissionEntity> entities = menuIds.stream().map(item -> {
RoleMenuPermissionEntity entity = new RoleMenuPermissionEntity();
entity.setRoleId(roleId);
entity.setMenuId(item.getMenuId());
entity.setPermissionType(item.getPermissionType());
entity.setCreateTime(currentUnix);
return entity;
}).collect(Collectors.toList());
basicRoleMenuRelationMapperExt.dashboardBatchInsert(entities);
}
@ -143,7 +142,7 @@ public class RoleServiceImpl implements RoleService {
if(StringUtils.isBlank(param.getRoleName()) || param.getRoleName().length() > 100){
return new SimpleDataResponse(ResponseCode.MSG_ERROR, "Parameter [roleName] error");
}
if(StringUtils.isBlank(param.getMenuIds())){
if(CollectionUtils.isEmpty(param.getMenuIds())){
return new SimpleDataResponse(ResponseCode.MSG_ERROR, "menuIds can not be null");
}
return SimpleDataResponse.success();
@ -315,4 +314,149 @@ public class RoleServiceImpl implements RoleService {
return new PageInfo<>(resultList);
}
@Override
public SimpleDataResponse<List<DashboardTreeMenusDTO>> getOwnMenuTree(Long companyId, Long userId, Integer languageType) {
// 1查询用户信息
BasicUser basicUser = basicUserMapperExt.selectByPrimaryKey(userId);
int superRole = basicUser.getSuperRole() == null ? 0 : basicUser.getSuperRole();
// 获取角色权限(非超级管理员)
Map<Long, Integer> permissionMap = new HashMap<>();
if (superRole != 1) {
Long roleId = basicRoleMenuRelationMapperExt.getRoleIdByUserId(userId);
List<RoleMenuPermissionEntity> permissions = basicRoleMenuRelationMapperExt.selectByRoleId(roleId);
permissionMap = permissions.stream()
.collect(Collectors.toMap(
RoleMenuPermissionEntity::getMenuId,
RoleMenuPermissionEntity::getPermissionType
));
}
// 查询全量菜单
List<DashboardTreeMenusDTO> allMenus = basicRoleMenuRelationMapperExt.selectAllMenu(Collections.emptyMap());
Map<Long, DashboardTreeMenusDTO> fullMenuMap = allMenus.stream()
.collect(Collectors.toMap(DashboardTreeMenusDTO::getMenuId, m -> m));
// 获取用户可见菜单(叶子或有权限的节点)
List<DashboardTreeMenusDTO> visibleMenus;
if (superRole == 1) {
// 超级管理员可见所有
visibleMenus = new ArrayList<>(allMenus);
} else {
Long roleId = basicRoleMenuRelationMapperExt.getRoleIdByUserId(userId);
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("superRole", superRole);
paramMap.put("roleId", roleId);
visibleMenus = basicRoleMenuRelationMapperExt.selectAllMenu(paramMap);
}
// 补全父节点
visibleMenus = fillMissingParents(visibleMenus, fullMenuMap);
// 构建树
DashboardMenuTree tree = new DashboardMenuTree(visibleMenus);
List<DashboardTreeMenusDTO> result = tree.buildTree("-1");
// 叶子权限赋值
fillLeafPermission(result, permissionMap, superRole);
// 父节点统一赋值=2
fillParentPermission(result);
return SimpleDataResponse.success(result);
}
/**
* 补全父节点一次传入全量菜单 map
*/
private List<DashboardTreeMenusDTO> fillMissingParents(List<DashboardTreeMenusDTO> menuList,
Map<Long, DashboardTreeMenusDTO> fullMenuMap) {
Set<Long> allIds = menuList.stream().map(DashboardTreeMenusDTO::getMenuId).collect(Collectors.toSet());
Set<Long> missingParentIds = new HashSet<>();
for (DashboardTreeMenusDTO menu : menuList) {
Long pid = menu.getParentMenuId();
while (pid != null && !Objects.equals(pid, -1L) && !allIds.contains(pid)) {
missingParentIds.add(pid);
DashboardTreeMenusDTO parentMenu = fullMenuMap.get(pid);
if (parentMenu == null) break; // 防止死循环
pid = parentMenu.getParentMenuId();
}
}
for (Long pid : missingParentIds) {
DashboardTreeMenusDTO parentMenu = fullMenuMap.get(pid);
if (parentMenu != null) {
menuList.add(parentMenu);
}
}
return menuList;
}
/**
* 叶子赋权
*/
private void fillLeafPermission(List<DashboardTreeMenusDTO> nodes,
Map<Long, Integer> permissionMap, Integer superRole) {
for (DashboardTreeMenusDTO node : nodes) {
if (node.getDashboardLowestNode() != null && node.getDashboardLowestNode() == 1) {
if (superRole == 1) {
node.setPermissionType(2);
} else {
node.setPermissionType(permissionMap.getOrDefault(node.getMenuId(), 0));
}
}
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
fillLeafPermission(node.getChildren(), permissionMap, superRole);
}
}
}
/**
* 父节点权限统一赋值 2
*/
private void fillParentPermission(List<DashboardTreeMenusDTO> nodes) {
for (DashboardTreeMenusDTO node : nodes) {
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
fillParentPermission(node.getChildren());
node.setPermissionType(2);
}
}
}
@Override
@Transactional
public void saveRolePermission(Long roleId, List<RoleMenuPermissionDTO> list) {
basicRoleMenuRelationMapperExt.deleteByRoleId(roleId);
if (list == null || list.isEmpty()) {
return;
}
List<RoleMenuPermissionEntity> entities = list.stream().map(item -> {
RoleMenuPermissionEntity entity = new RoleMenuPermissionEntity();
entity.setRoleId(roleId);
entity.setMenuId(item.getMenuId());
entity.setPermissionType(item.getPermissionType());
entity.setCreateTime(System.currentTimeMillis());
return entity;
}).collect(Collectors.toList());
basicRoleMenuRelationMapperExt.dashboardBatchInsert(entities);
}
@Override
public SimpleDataResponse<List<RoleMenuPermissionEntity>> getMenuIdListByRoleId(Long roleId, Long companyId, Long userId, Integer languageType) {
try {
return SimpleDataResponse.success(basicRoleMenuRelationMapperExt.getMenuIdListByRoleId(roleId));
} catch (Exception e) {
logger.error("获取角色菜单出错", e);
return new SimpleDataResponse(ResponseCode.SERVER_ERROR, e.getMessage());
}
}
}

Loading…
Cancel
Save