Compare commits

...

7 Commits

  1. 2
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/BasicUserMapperExt.java
  2. 2
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelRoleMapperExt.java
  3. 9
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/BasicUserMapperExt.xml
  4. 6
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/DeviceInfoMapperExt.xml
  5. 160
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml
  6. 44
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelRoleMapperExt.xml
  7. 2
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/OverviewInfoMapperExt.xml
  8. 4
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/DeleteLevelParam.java
  9. 6
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelEntity.java
  10. 11
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/OptLevelParam.java
  11. 8
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/PageLevelSearchParam.java
  12. 7
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/BuildingPathDTO.java
  13. 8
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/LevelPageDTO.java
  14. 5
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/common/CommonOpt.java
  15. 33
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelRoleServiceImpl.java
  16. 58
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelServiceImpl.java
  17. 60
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OverviewServiceImpl.java
  18. 30
      dongjian-dashboard-back-util/src/main/java/com/dongjian/dashboard/back/util/DateUtil.java

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

@ -25,4 +25,6 @@ public interface BasicUserMapperExt extends BasicUserMapper{
Integer checkBuildingManager(Long userId);
Integer checkLevelManager(Long userId);
Integer getAdscFlagByUserId(@Param("userId") Long userId);
}

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

@ -40,4 +40,6 @@ public interface LevelRoleMapperExt extends DashboardLevelRoleMapper {
List<UserBindLevelRoleVO> getCanBeBoundUserPage(BaseSearchParams pageSearchParam);
Integer checkLevelManager(Long userId);
List<RefKey> selectAllStoreAreas(Map<String, Object> levelMap);
}

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

@ -125,5 +125,12 @@
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>
<select id="getAdscFlagByUserId" resultType="java.lang.Integer">
SELECT adsc_flag
FROM data_center_aeon_admin.basic_user
WHERE id = #{userId}
AND flag = 0
LIMIT 1
</select>
</mapper>

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

@ -320,7 +320,7 @@
</when>
<otherwise>
alert_history
left join device_info on alert_history.device_id = device_info.device_id
left join device_info on alert_history.device_id = device_info.device_id and alert_history.source_type = 1
</otherwise>
</choose>
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
@ -334,7 +334,6 @@
<where>
and device_info.flag = 0 and basic_monitoring_asset.flag != 1
and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
and alert_history.source_type = 1
<include refid="deviceDataCommonWhere"/>
<choose>
<when test="searchType == 1">
@ -381,7 +380,7 @@
</when>
<otherwise>
alert_history
left join device_info on alert_history.device_id = device_info.device_id
left join device_info on alert_history.device_id = device_info.device_id and alert_history.source_type = 1
</otherwise>
</choose>
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
@ -397,7 +396,6 @@
and device_info.flag = 0 and basic_monitoring_asset.flag != 1
and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
and ddgr.device_group_id = #{deviceGroupId}
and alert_history.source_type = 1
<include refid="deviceDataCommonWhere"/>
<choose>
<when test="searchType == 1">

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

@ -6,17 +6,15 @@
<sql id="selectTable">
<choose>
<when test="levelType == 1">dashboard_level_branch</when>
<when test="levelType == 2">dashboard_level_store</when>
<when test="levelType == 3">dashboard_level_area</when>
<when test="levelType == 4">dashboard_level_site</when>
<when test="levelType == 2">dashboard_level_store_area_merge</when>
<when test="levelType == 3">dashboard_level_site</when>
</choose>
</sql>
<sql id="selectParentTable">
<choose>
<when test="levelType == 2">dashboard_level_branch</when>
<when test="levelType == 3">dashboard_level_store</when>
<when test="levelType == 4">dashboard_level_area</when>
<when test="levelType == 3">dashboard_level_store_area_merge</when>
</choose>
</sql>
@ -46,9 +44,22 @@
<insert id="saveLevel" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
INSERT INTO
<include refid="selectTable" />
(company_id, name, remark, created_by, created_at)
(company_id, name, `code`, remark, created_by, created_at)
VALUES
(#{companyId}, #{name}, #{remark}, #{createdBy}, #{createdAt})
(
#{companyId},
#{name},
<choose>
<when test="code != null and code != ''">#{code}</when>
<otherwise>NULL</otherwise>
</choose>,
<choose>
<when test="remark != null and remark != ''">#{remark}</when>
<otherwise>NULL</otherwise>
</choose>,
#{createdBy},
#{createdAt}
)
</insert>
<!-- 保存级别信息到对应表 -->
@ -70,6 +81,7 @@
<include refid="selectTable" />
SET
name = #{name},
`code` = #{code},
remark = #{remark},
updated_at = #{updatedAt},
updated_by = #{updatedBy}
@ -102,6 +114,7 @@
base.`id`,
base.company_id,
base.`name` AS levelName,
base.`code` AS levelCode,
base.remark,
base.created_by,
base.created_at,
@ -117,6 +130,9 @@
<if test="levelName != null and levelName != ''">
AND base.`name` like CONCAT('%',#{levelName},'%')
</if>
<if test="levelCode != null and levelCode != ''">
AND base.`code` like CONCAT('%',#{levelCode},'%')
</if>
<if test="parentIdList != null and parentIdList.size() > 0">
AND pa.id IN <foreach collection="parentIdList" item="item" open="(" separator="," close=")">#{item}</foreach>
</if>
@ -144,8 +160,8 @@
GROUP_CONCAT(pa.`name`) AS parentNames,
<include refid="commonField" />
FROM
dashboard_level_store base
LEFT JOIN dashboard_level_relation_branch_store rela ON base.`id` = rela.store_id
dashboard_level_store_area_merge base
LEFT JOIN dashboard_level_relation_branch_store_area rela ON base.`id` = rela.store_area_id
LEFT JOIN dashboard_level_branch pa ON rela.branch_id = pa.`id`
WHERE
<include refid="commonWhere" />
@ -157,24 +173,10 @@
GROUP_CONCAT(pa.id) AS parentIds,
GROUP_CONCAT(pa.`name`) AS parentNames,
<include refid="commonField" />
FROM
dashboard_level_area base
LEFT JOIN dashboard_level_relation_store_area rela ON base.`id` = rela.area_id
LEFT JOIN dashboard_level_store pa ON rela.store_id = pa.`id`
WHERE
<include refid="commonWhere" />
GROUP BY base.`id`
</when>
<when test="levelType == 4">
SELECT
4 AS levelType,
GROUP_CONCAT(pa.id) AS parentIds,
GROUP_CONCAT(pa.`name`) AS parentNames,
<include refid="commonField" />
FROM
dashboard_level_site base
LEFT JOIN dashboard_level_relation_area_site rela ON base.`id` = rela.site_id
LEFT JOIN dashboard_level_area pa ON rela.area_id = pa.`id`
LEFT JOIN dashboard_level_relation_store_area_site rela ON base.`id` = rela.site_id
LEFT JOIN dashboard_level_store_area_merge pa ON rela.store_area_id = pa.`id`
WHERE
<include refid="commonWhere" />
GROUP BY base.`id`
@ -187,6 +189,7 @@
SELECT DISTINCT building_id
FROM (
-- BUILDING(直接绑定)
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
@ -199,6 +202,7 @@
UNION ALL
-- SITE → BUILDING
SELECT b.building_id
FROM dashboard_level_role_user ru
JOIN dashboard_level_role_object ro
@ -214,66 +218,41 @@
UNION ALL
-- STORE_AREA → SITE → BUILDING(核心替代 AREA / STORE)
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
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_store_area_merge sam
ON ro.ref_id = sam.id AND sam.flag = 0
JOIN dashboard_level_relation_store_area_site rsas
ON sam.id = rsas.store_area_id
JOIN dashboard_level_site s
ON ras.site_id = s.id AND s.flag = 0
ON rsas.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'
AND ro.ref_type = 'STORE_AREA'
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_relation_branch_store_area rbsa
ON br.id = rbsa.branch_id
JOIN dashboard_level_store_area_merge sam
ON rbsa.store_area_id = sam.id AND sam.flag = 0
JOIN dashboard_level_relation_store_area_site rsas
ON sam.id = rsas.store_area_id
JOIN dashboard_level_site s
ON ras.site_id = s.id AND s.flag = 0
ON rsas.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
@ -281,7 +260,7 @@
WHERE ru.user_id = #{userId}
AND ro.ref_type = 'BRANCH'
) t;
) t
</select>
<select id="selectBuildingFullPath" resultType="com.dongjian.dashboard.back.vo.level.BuildingPathDTO">
@ -289,41 +268,52 @@
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,
sam.id AS store_area_id,
sam.name AS store_area_name,
s.id AS site_id,
s.name AS site_name,
b.building_id,
b.name AS building_name
<choose>
<when test="isADSC != null and isADSC">
FROM dashboard_level_branch br
LEFT JOIN dashboard_level_relation_branch_store_area rbsa ON rbsa.branch_id = br.id AND br.flag = 0 AND br.company_id = #{companyId}
FROM basic_building b
LEFT JOIN dashboard_level_store_area_merge sam ON sam.id = rbsa.store_area_id AND sam.flag = 0
JOIN dashboard_level_relation_site_building rsb ON b.building_id = rsb.building_id
LEFT JOIN dashboard_level_relation_store_area_site rsas ON rsas.store_area_id = sam.id
JOIN dashboard_level_site s ON rsb.site_id = s.id AND s.flag = 0
LEFT JOIN dashboard_level_site s ON s.id = rsas.site_id AND s.flag = 0
JOIN dashboard_level_relation_area_site ras ON s.id = ras.site_id
LEFT JOIN dashboard_level_relation_site_building rsb ON rsb.site_id = s.id
JOIN dashboard_level_area a ON ras.area_id = a.id AND a.flag = 0
LEFT JOIN basic_building b ON b.building_id = rsb.building_id AND b.flag = 0
</when>
<otherwise>
FROM basic_building b
JOIN dashboard_level_relation_store_area rsa ON a.id = rsa.area_id
JOIN dashboard_level_relation_site_building rsb ON b.building_id = rsb.building_id AND b.flag = 0 AND b.company_id = #{companyId}
JOIN dashboard_level_store st ON rsa.store_id = st.id AND st.flag = 0
JOIN dashboard_level_site s ON rsb.site_id = s.id AND s.flag = 0
JOIN dashboard_level_relation_branch_store rbs ON st.id = rbs.store_id
JOIN dashboard_level_relation_store_area_site rsas ON s.id = rsas.site_id
JOIN dashboard_level_branch br ON rbs.branch_id = br.id AND br.flag = 0
JOIN dashboard_level_store_area_merge sam ON rsas.store_area_id = sam.id AND sam.flag = 0
WHERE b.flag = 0
AND b.company_id = #{companyId}
<if test="bindBuildingIdList != null">
AND b.building_id IN <foreach collection="bindBuildingIdList" item="item" open="(" separator="," close=")">#{item}</foreach>
</if>
JOIN dashboard_level_relation_branch_store_area rbsa ON sam.id = rbsa.store_area_id
JOIN dashboard_level_branch br ON rbsa.branch_id = br.id AND br.flag = 0
</otherwise>
</choose>
<where>
<if test="bindBuildingIdList != null">
AND b.building_id IN <foreach collection="bindBuildingIdList" item="item" open="(" separator="," close=")">#{item}</foreach>
</if>
</where>
order by br.id
</select>
<delete id="deleteSiteBuildingRelation">

44
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelRoleMapperExt.xml

@ -97,28 +97,42 @@
WHERE b.flag = 0 and b.company_id = #{companyId}
</select>
<select id="selectAllStoreAreas" resultType="com.dongjian.dashboard.back.vo.levelrole.RefKey">
SELECT s.id,
s.name,
r.branch_id AS parentId,
'STORE_AREA' AS type
FROM dashboard_level_store_area_merge s
LEFT JOIN dashboard_level_relation_branch_store_area r
ON s.id = r.store_area_id
WHERE s.flag = 0 and s.company_id = #{companyId}
</select>
<!-- 查用户绑定节点 -->
<select id="selectUserRefs" resultType="com.dongjian.dashboard.back.vo.levelrole.RefKey">
SELECT o.ref_type AS type,
o.ref_id AS id
SELECT
o.ref_type AS type,
o.ref_id AS id
FROM dashboard_level_role_user u
INNER JOIN dashboard_level_role_object o
ON u.level_role_id = o.level_role_id
LEFT JOIN dashboard_level_branch b
ON o.ref_type = 'BRANCH' AND o.ref_id = b.id
LEFT JOIN dashboard_level_store s
ON o.ref_type = 'STORE' AND o.ref_id = s.id
LEFT JOIN dashboard_level_area a
ON o.ref_type = 'AREA' AND o.ref_id = a.id
LEFT JOIN dashboard_level_store_area_merge sam
ON o.ref_type = 'STORE_AREA' AND o.ref_id = sam.id
LEFT JOIN dashboard_level_site si
ON o.ref_type = 'SITE' AND o.ref_id = si.id
LEFT JOIN basic_building bu
ON o.ref_type = 'BUILDING' AND o.ref_id = bu.building_id
WHERE u.user_id = #{userId}
AND CASE o.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
END = 0
@ -131,22 +145,24 @@
FROM dashboard_level_role_object dlro
INNER JOIN dashboard_level_role dlr
ON dlr.id = dlro.level_role_id
LEFT JOIN dashboard_level_branch b
ON dlro.ref_type = 'BRANCH' AND dlro.ref_id = b.id
LEFT JOIN dashboard_level_store s
ON dlro.ref_type = 'STORE' AND dlro.ref_id = s.id
LEFT JOIN dashboard_level_area a
ON dlro.ref_type = 'AREA' AND dlro.ref_id = a.id
LEFT JOIN dashboard_level_store_area_merge sam
ON dlro.ref_type = 'STORE_AREA' AND dlro.ref_id = sam.id
LEFT JOIN dashboard_level_site si
ON dlro.ref_type = 'SITE' AND dlro.ref_id = si.id
LEFT JOIN basic_building bu
ON dlro.ref_type = 'BUILDING' AND dlro.ref_id = bu.building_id
WHERE dlr.flag != 1
AND dlr.id = #{roleId}
AND CASE dlro.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
END = 0

2
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/OverviewInfoMapperExt.xml

@ -27,7 +27,7 @@
WHERE
bbuilding.company_id = #{companyId} AND bbuilding.flag = 0 AND basic_floor.flag = 0 AND basic_space.flag = 0
AND basic_monitoring_asset.flag = 0 AND dinfo.flag = 0
AND ah.confirm_status = 0 AND ah.handle_status = 1
AND ah.receive_ts >= #{midnightTimestamp}
</select>
<select id="getBuildingInfo" resultType="com.dongjian.dashboard.back.vo.data.OverviewVO">

4
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/DeleteLevelParam.java

@ -19,8 +19,8 @@ public class DeleteLevelParam {
private String ids;
/**
* 物件级别类型1-支社2-各支店3-area4-site
* 物件级别类型 1-支社 2-各支店·area 3-site
*/
@Schema(description = "物件级别类型(1-支社、2-各支店、3-area、4-site)",example = "2", required = true)
@Schema(description = "级别类型:1-支社 2-各支店·area 3-site ",example = "2", required = true)
private Integer levelType;
}

6
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelEntity.java

@ -1,5 +1,6 @@
package com.dongjian.dashboard.back.dto.level;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@ -32,6 +33,11 @@ public class LevelEntity {
*/
private String remark;
/**
* 编码
*/
private String code;
/**
* 创建时间
*/

11
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/OptLevelParam.java

@ -27,9 +27,9 @@ public class OptLevelParam {
private String levelName;
/**
* 物件级别类型1-支社 2-各支店 3-area 4-site
* 物件级别类型 1-支社 2-各支店·area 3-site
*/
@Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true)
@Schema(description = "级别类型:1-支社 2-各支店·area 3-site ",example = "2", required = true)
private Integer levelType;
/**
@ -48,6 +48,13 @@ public class OptLevelParam {
private List<Long> buildingIdList;
/**
* 编码
*/
@Schema(description = "编码",example = "2cc")
private String code;
@Schema(description = "所属企业ID",example = "2", hidden = true)
private Long companyId;
}

8
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/PageLevelSearchParam.java

@ -30,7 +30,13 @@ public class PageLevelSearchParam extends BaseSearchParams {
@Schema(description = "名称",example = "jyk2")
private String levelName;
@Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true)
@Schema(description = "编码",example = "2cc")
private String levelCode;
/**
* 物件级别类型 1-支社 2-各支店·area 3-site
*/
@Schema(description = "级别类型:1-支社 2-各支店·area 3-site ",example = "2", required = true)
private Integer levelType;
}

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

@ -4,15 +4,14 @@ import lombok.Data;
@Data
public class BuildingPathDTO {
private Long branchId;
private Long storeId;
private Long areaId;
private Long storeAreaId;
private Long siteId;
private Long buildingId;
private String branchName;
private String storeName;
private String areaName;
private String storeAreaName;
private String siteName;
private String buildingName;
}

8
dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/LevelPageDTO.java

@ -26,10 +26,16 @@ public class LevelPageDTO {
@Schema(description = "名称)",example = "2", required = true)
private String levelName;
/**
* 物件级别名称
*/
@Schema(description = "编码)",example = "2cc", required = false)
private String levelCode;
/**
* 物件级别类型1-支社 2-各支店 3-area 4-site
*/
@Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true)
@Schema(description = "级别类型:1-支社 2-各支店·area 3-site ",example = "2", required = true)
private Integer levelType;
/**

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

@ -825,4 +825,9 @@ public class CommonOpt {
};
}
public boolean isADSC(Long userId) {
Integer flag = basicUserMapperExt.getAdscFlagByUserId(userId);
return flag != null && flag == 1;
}
}

33
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelRoleServiceImpl.java

@ -332,8 +332,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
Map<String, Object> levelMap = new HashMap<>();
levelMap.put("companyId", companyId);
List<RefKey> branches = levelRoleMapperExt.selectAllBranches(levelMap);
List<RefKey> stores = levelRoleMapperExt.selectAllStores(levelMap);
List<RefKey> areas = levelRoleMapperExt.selectAllAreas(levelMap);
List<RefKey> storeAreas = levelRoleMapperExt.selectAllStoreAreas(levelMap);
List<RefKey> sites = levelRoleMapperExt.selectAllSites(levelMap);
List<RefKey> buildings = levelRoleMapperExt.selectAllBuildings(levelMap);
@ -341,8 +340,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
List<RefKey> userRefs = new ArrayList<>();
if (levelRoleMapperExt.checkLevelManager(userId) > 0){
userRefs.addAll(branches);
userRefs.addAll(stores);
userRefs.addAll(areas);
userRefs.addAll(storeAreas);
userRefs.addAll(sites);
userRefs.addAll(buildings);
} else {
@ -350,12 +348,11 @@ public class LevelRoleServiceImpl implements LevelRoleService {
paramMap.put("userId", userId);
userRefs = levelRoleMapperExt.selectUserRefs(paramMap);
// 名称填充
fillNames(userRefs, branches, stores, areas, sites, buildings);
fillNames(userRefs, branches, storeAreas, sites, buildings);
}
// 构建 parentId → List<RefKey> 的多值 Map
Map<Long, List<RefKey>> storeMap = groupByParent(stores);
Map<Long, List<RefKey>> areaMap = groupByParent(areas);
Map<Long, List<RefKey>> storeAreaMap = groupByParent(storeAreas);
Map<Long, List<RefKey>> siteMap = groupByParent(sites);
Map<Long, List<RefKey>> buildingMap = groupByParent(buildings);
@ -380,7 +377,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
// 构建该节点下的子树
root.setChildren(buildTree(
ref.getType(), ref.getId(), rootKey,
storeMap, areaMap, siteMap, buildingMap, visitedKeys
storeAreaMap, siteMap, buildingMap, visitedKeys
));
result.add(root);
}
@ -398,22 +395,19 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private void fillNames(List<RefKey> userRefs,
List<RefKey> branches,
List<RefKey> stores,
List<RefKey> areas,
List<RefKey> storeAreas,
List<RefKey> sites,
List<RefKey> buildings) {
Map<Long, String> branchName = toNameMap(branches);
Map<Long, String> storeName = toNameMap(stores);
Map<Long, String> areaName = toNameMap(areas);
Map<Long, String> storeAreaName = toNameMap(storeAreas);
Map<Long, String> siteName = toNameMap(sites);
Map<Long, String> buildingName = toNameMap(buildings);
userRefs.removeIf(r -> {
String name = switch (r.getType()) {
case "BRANCH" -> branchName.get(r.getId());
case "STORE" -> storeName.get(r.getId());
case "AREA" -> areaName.get(r.getId());
case "STORE_AREA" -> storeAreaName.get(r.getId());
case "SITE" -> siteName.get(r.getId());
case "BUILDING" -> buildingName.get(r.getId());
default -> null;
@ -443,19 +437,18 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private List<TreeMenusDTO> buildTree(String type,
Long parentId,
String parentKey,
Map<Long, List<RefKey>> storeMap,
Map<Long, List<RefKey>> areaMap,
Map<Long, List<RefKey>> storeAreaMap,
Map<Long, List<RefKey>> siteMap,
Map<Long, List<RefKey>> buildingMap,
Set<String> visitedKeys) {
Map<Long, List<RefKey>> childMap = switch (type) {
case "BRANCH" -> storeMap;
case "STORE" -> areaMap;
case "AREA" -> siteMap;
case "BRANCH" -> storeAreaMap;
case "STORE_AREA" -> siteMap;
case "SITE" -> buildingMap;
default -> null;
};
if (childMap == null) return Collections.emptyList();
// 直接取 parentId 的子节点
@ -477,7 +470,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
node.setChildren(buildTree(
c.getType(), c.getId(), key,
storeMap, areaMap, siteMap, buildingMap, visitedKeys
storeAreaMap, siteMap, buildingMap, visitedKeys
));
list.add(node);

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

@ -79,7 +79,7 @@ public class LevelServiceImpl implements LevelService {
//插入关联
insertLevelRelation(param, levelEntity, 1);
//单独插入楼宇和site关系
if (4 == param.getLevelType()) {
if (3 == param.getLevelType()) {
insertSiteBuildingRelation(param, levelEntity, 1);
}
}
@ -127,18 +127,13 @@ public class LevelServiceImpl implements LevelService {
switch (param.getLevelType()){
case 2:
levelRelationEntity.setParentField("branch_id");
levelRelationEntity.setChildField("store_id");
levelRelationEntity.setTableName("dashboard_level_relation_branch_store");
levelRelationEntity.setChildField("store_area_id");
levelRelationEntity.setTableName("dashboard_level_relation_branch_store_area");
break;
case 3:
levelRelationEntity.setParentField("store_id");
levelRelationEntity.setChildField("area_id");
levelRelationEntity.setTableName("dashboard_level_relation_store_area");
break;
case 4:
levelRelationEntity.setParentField("area_id");
levelRelationEntity.setParentField("store_area_id");
levelRelationEntity.setChildField("site_id");
levelRelationEntity.setTableName("dashboard_level_relation_area_site");
levelRelationEntity.setTableName("dashboard_level_relation_store_area_site");
break;
}
levelRelationEntity.setParentId(parentId);
@ -168,7 +163,7 @@ public class LevelServiceImpl implements LevelService {
if(StringUtils.isBlank(param.getLevelName()) || param.getLevelName().length() > 255){
return new SimpleDataResponse(ResponseCode.MSG_ERROR, "Parameter [levelName] error");
}
if(null == param.getLevelType() || param.getLevelType() < 1 || param.getLevelType() > 4){
if(null == param.getLevelType() || param.getLevelType() < 1 || param.getLevelType() > 3){
return new SimpleDataResponse(ResponseCode.MSG_ERROR, "Parameter [levelType] error");
}
if(1 != param.getLevelType() && CollectionUtils.isEmpty(param.getParentIdList())){
@ -209,23 +204,19 @@ public class LevelServiceImpl implements LevelService {
deleteLevelRelationEntity.setChildId(param.getId());
switch (param.getLevelType()){
case 2:
deleteLevelRelationEntity.setChildField("store_id");
deleteLevelRelationEntity.setTableName("dashboard_level_relation_branch_store");
deleteLevelRelationEntity.setChildField("store_area_id");
deleteLevelRelationEntity.setTableName("dashboard_level_relation_branch_store_area");
break;
case 3:
deleteLevelRelationEntity.setChildField("area_id");
deleteLevelRelationEntity.setTableName("dashboard_level_relation_store_area");
break;
case 4:
deleteLevelRelationEntity.setChildField("site_id");
deleteLevelRelationEntity.setTableName("dashboard_level_relation_area_site");
deleteLevelRelationEntity.setTableName("dashboard_level_relation_store_area_site");
break;
}
levelMapperExt.deleteLevelRelation(deleteLevelRelationEntity);
//插入关联
insertLevelRelation(param, levelEntity, 2);
//单独插入楼宇和site关系
if (4 == param.getLevelType()) {
if (3 == param.getLevelType()) {
insertSiteBuildingRelation(param, levelEntity, 2);
}
}
@ -249,17 +240,13 @@ public class LevelServiceImpl implements LevelService {
switch (levelType){
case 1:
levelRelationEntity.setParentField("branch_id");
levelRelationEntity.setTableName("dashboard_level_relation_branch_store");
levelRelationEntity.setTableName("dashboard_level_relation_branch_store_area");
break;
case 2:
levelRelationEntity.setParentField("store_id");
levelRelationEntity.setTableName("dashboard_level_relation_store_area");
levelRelationEntity.setParentField("store_area_id");
levelRelationEntity.setTableName("dashboard_level_relation_store_area_site");
break;
case 3:
levelRelationEntity.setParentField("area_id");
levelRelationEntity.setTableName("dashboard_level_relation_area_site");
break;
case 4:
levelRelationEntity.setParentField("site_id");
levelRelationEntity.setTableName("dashboard_level_relation_site_building");
break;
@ -271,9 +258,8 @@ public class LevelServiceImpl implements LevelService {
//基础表删除
String tableName = switch (levelType) {
case 1 -> "dashboard_level_branch";
case 2 -> "dashboard_level_store";
case 3 -> "dashboard_level_area";
case 4 -> "dashboard_level_site";
case 2 -> "dashboard_level_store_area_merge";
case 3 -> "dashboard_level_site";
default -> "";
};
levelMapperExt.deleteLevelByIdList(tableName, idList);
@ -283,19 +269,15 @@ public class LevelServiceImpl implements LevelService {
switch (levelType){
case 1:
deleteEntity.setChildField("branch_id");
deleteEntity.setTableName("dashboard_level_relation_branch_store");
deleteEntity.setTableName("dashboard_level_relation_branch_store_area");
break;
case 2:
deleteEntity.setChildField("store_id");
deleteEntity.setTableName("dashboard_level_relation_branch_store");
deleteEntity.setChildField("store_area_id");
deleteEntity.setTableName("dashboard_level_relation_branch_store_area");
break;
case 3:
deleteEntity.setChildField("area_id");
deleteEntity.setTableName("dashboard_level_relation_store_area");
break;
case 4:
deleteEntity.setChildField("site_id");
deleteEntity.setTableName("dashboard_level_relation_area_site");
deleteEntity.setTableName("dashboard_level_relation_store_area_site");
break;
}
levelMapperExt.deleteLevelRelationByIdList(deleteEntity, idList);
@ -330,7 +312,7 @@ public class LevelServiceImpl implements LevelService {
PageHelper.startPage(pageSearchParam.getPageNum() == null ? 1 : pageSearchParam.getPageNum(), pageSearchParam.getPageSize() == null ? 20 : pageSearchParam.getPageSize());
List<LevelPageDTO> resultList = levelMapperExt.getListPage(pageSearchParam);
if (4 == levelType && CollectionUtils.isNotEmpty(resultList)){
if (3 == levelType && CollectionUtils.isNotEmpty(resultList)){
for (LevelPageDTO levelPageDTO : resultList) {
List<BuildingPageVO> buildingList = basicBuildingMapperExt.getBuildingListBySiteId(levelPageDTO.getId());
if (CollectionUtils.isNotEmpty(buildingList)) {

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

@ -11,6 +11,7 @@ import com.dongjian.dashboard.back.dto.monitoringpointcategory.MonitoringPointCa
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.util.DateUtil;
import com.dongjian.dashboard.back.vo.TreeMenusDTO;
import com.dongjian.dashboard.back.vo.dashboardnotification.DashboardNotificationPageVO;
import com.dongjian.dashboard.back.vo.data.OverviewCategoryVO;
@ -76,6 +77,7 @@ public class OverviewServiceImpl implements OverviewService {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("companyId", companyId);
paramMap.put("categoryIdList", Constants.CATEGORY_MAP.get(Constants.CATEGORY_ALARM));
paramMap.put("midnightTimestamp", DateUtil.getTodayZeroMillisByOffset(utcOffset));
List<OverviewInfo> alarmInfoList = overviewInfoMapperExt.getOverviewInfo(paramMap);
List<OverviewVO> overviewVOList = convert(alarmInfoList, utcOffset);
@ -274,37 +276,57 @@ public class OverviewServiceImpl implements OverviewService {
@Override
public SimpleDataResponse<List<TreeMenusDTO>> getOverallBoundLevel(Long companyId, Long userId, Integer languageType) {
// 20260429需求:ADSC用户,楼宇以上能看全部,到了楼宇这一级,还是要看绑定的角色对应的楼宇
boolean isADSC = commonOpt.isADSC(userId);
List<Long> bindBuildingIdList = commonOpt.getBindBuildingIdList(userId, List.of(companyId));
Set<Long> bindBuildingIdSet =
bindBuildingIdList == null || bindBuildingIdList.isEmpty()
? Collections.emptySet()
: new HashSet<>(bindBuildingIdList);
Map<String, Object> buildingMap = new HashMap<>();
buildingMap.put("companyId", companyId);
buildingMap.put("bindBuildingIdList", commonOpt.getBindBuildingIdList(userId, List.of(companyId)));
List<BuildingPathDTO> selectBuildingFullPath = levelMapperExt.selectBuildingFullPath(buildingMap);
if (isADSC) {
buildingMap.put("isADSC", true);
} else {
// 普通用户:全链路限制 building
buildingMap.put("isADSC", false);
buildingMap.put("bindBuildingIdList", bindBuildingIdList);
}
// 构建节点
Map<String, TreeMenusDTO> nodeMap = new HashMap<>();
List<BuildingPathDTO> list = levelMapperExt.selectBuildingFullPath(buildingMap);
for (BuildingPathDTO row : selectBuildingFullPath) {
Map<String, TreeMenusDTO> nodeMap = new LinkedHashMap<>();
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;
for (BuildingPathDTO row : list) {
String branchKey = "BRANCH-" + row.getBranchId();
nodeMap.putIfAbsent(branchKey,
createNode(branchKey, "ROOT", row.getBranchName()));
nodeMap.putIfAbsent(storeKey,
createNode(storeKey, branchKey, row.getStoreName()));
nodeMap.putIfAbsent(areaKey,
createNode(areaKey, storeKey, row.getAreaName()));
if (row.getStoreAreaId() == null) {
continue;
}
String storeAreaKey = "STORE_AREA-" + row.getStoreAreaId() + "-" + branchKey;
nodeMap.putIfAbsent(storeAreaKey,
createNode(storeAreaKey, branchKey, row.getStoreAreaName()));
if (row.getSiteId() == null) {
continue;
}
String siteKey = "SITE-" + row.getSiteId() + "-" + storeAreaKey;
nodeMap.putIfAbsent(siteKey,
createNode(siteKey, areaKey, row.getSiteName()));
createNode(siteKey, storeAreaKey, row.getSiteName()));
nodeMap.putIfAbsent(buildingKey,
createNode(buildingKey, siteKey, row.getBuildingName()));
boolean isAllowedBuilding = !isADSC || bindBuildingIdSet.contains(row.getBuildingId());
if (isAllowedBuilding) {
String buildingKey = "BUILDING-" + row.getBuildingId() + "-" + siteKey;
nodeMap.putIfAbsent(buildingKey,
createNode(buildingKey, siteKey, row.getBuildingName()));
}
}
List<TreeMenusDTO> allNodes = new ArrayList<>(nodeMap.values());

30
dongjian-dashboard-back-util/src/main/java/com/dongjian/dashboard/back/util/DateUtil.java

@ -2,10 +2,7 @@ package com.dongjian.dashboard.back.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.IsoFields;
import java.util.*;
@ -95,4 +92,29 @@ public class DateUtil {
.minusDays(1);
return japanYesterday.format(FORMATTER);
}
/**
* 根据前端传来的时区偏移分钟获取该时区当天 0 点的毫秒时间戳
* @param offsetMinutes 前端传递的偏移量例如东八区为 -480
* @return 当天 0 点的毫秒级时间戳UTC
*/
public static long getTodayZeroMillisByOffset(Integer offsetMinutes) {
// 若未传偏移,可使用默认时区(如系统默认或东八区)
if (offsetMinutes == null) {
// 默认日本时区(+9)
offsetMinutes = -540;
}
// 将前端 offset 转换为 ZoneOffset(例如 -480 -> +08:00)
int offsetSeconds = -offsetMinutes * 60; // 注意负负得正
ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds);
// 当前时刻在该偏移下的当天0点
ZonedDateTime todayZero = ZonedDateTime.now(zoneOffset)
.toLocalDate()
.atStartOfDay(zoneOffset);
// 返回毫秒时间戳
return todayZero.toInstant().toEpochMilli();
}
}

Loading…
Cancel
Save