diff --git a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml index e0a0045..866d528 100644 --- a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml +++ b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_cn.yml @@ -74,6 +74,9 @@ msgcn: handleStatus_4: 自动恢复 canNotProcessed: 无法再处理 processOwnRole: 不能处理自身角色 + levelNameExist: 层级名称已存在 + invalidParentLevel: 无效的父级层级 + levelReferencedByChildren: 已被下级层级绑定,请先解绑后再删除 operationLogMap: addRole: 新增角色 editRole: 编辑角色 @@ -129,5 +132,10 @@ msgcn: addDeviceForGroup: 给设备组设置绑定的设备 delDeviceForGroup: 删除设备组绑定的指定设备 editBuildingField: 编辑楼宇属性 + setLngLat: 设置天气经纬度 + addLevel: 新增层级 + editLevel: 编辑层级 + deleteLevel: 删除层级 + queryLevel: 获取层级列表 diff --git a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml index 311ba4c..8aaa156 100644 --- a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml +++ b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_en.yml @@ -74,6 +74,9 @@ msgen: handleStatus_4: Auto Recovered canNotProcessed: Can not be processed further processOwnRole: Can not process own role. + levelNameExist: Level name already exists + invalidParentLevel: Invalid parent level + levelReferencedByChildren: It is bound by child levels. Please unbind them before deleting. operationLogMap: addRole: Add Role editRole: Edit Role @@ -129,6 +132,11 @@ msgen: addDeviceForGroup: Set bound devices for the device group delDeviceForGroup: Remove the specified devices bound to the device group editBuildingField: Edit Building Attributes + setLngLat: Set weather longitude and latitude + addLevel: Add Level + editLevel: Edit Level + deleteLevel: Delete Level + queryLevel: Get Level List diff --git a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml index 1146e00..52c08e6 100644 --- a/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml +++ b/dongjian-dashboard-back-common/src/main/resources/config/language/msg/msg_jp.yml @@ -74,6 +74,9 @@ msgjp: handleStatus_4: 自動復旧 canNotProcessed: これ以上の処理はできません processOwnRole: 自分のロールを操作することはできません + levelNameExist: 階層名は既に存在しています + invalidParentLevel: 無効な上位階層です + levelReferencedByChildren: 下位階層に紐づいています。削除する前に紐付けを解除してください。 operationLogMap: addRole: ロールを追加 editRole: ロールを編集 @@ -129,6 +132,11 @@ msgjp: addDeviceForGroup: デバイスグループにバインドされたデバイスを設定する delDeviceForGroup: デバイスグループにバインドされた指定されたデバイスを削除する editBuildingField: 建物の属性を編集 + setLngLat: 天気の経度と緯度を設定 + addLevel: レベルを追加 + editLevel: レベルを編集 + deleteLevel: レベルを削除 + queryLevel: レベル一覧を取得 diff --git a/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/LevelController.java b/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/LevelController.java new file mode 100644 index 0000000..b3096a2 --- /dev/null +++ b/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/LevelController.java @@ -0,0 +1,112 @@ +package com.dongjian.dashboard.back.controller; + +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.level.DeleteLevelParam; +import com.dongjian.dashboard.back.dto.level.OptLevelParam; +import com.dongjian.dashboard.back.dto.level.PageLevelSearchParam; +import com.dongjian.dashboard.back.service.LevelService; +import com.dongjian.dashboard.back.vo.level.LevelPageDTO; + +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 物件级别管理Controller + * 实现物件级别的增删改查功能 + */ +@Hidden +@RestController +@AccessRequired +@RequestMapping("/level") +@Tag(name = "物件级别管理的相关接口", description = "物件级别的增删改查操作") +@SuppressWarnings("unchecked") +public class LevelController { + + private static Logger logger = LoggerFactory.getLogger(LevelController.class); + + @Autowired + private LevelService levelService; + + @AccessRequired + @OperationLog(operation = "addLevel", remark = "添加物件级别") + @Operation(summary = "添加物件级别") + @RequestMapping(value = "/add", method = RequestMethod.POST) + public SimpleDataResponse add( + @RequestBody OptLevelParam optLevelParam, + @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 levelService.add(optLevelParam, CompanyId, UserId, LanguageType); + } + + @AccessRequired + @OperationLog(operation = "editLevel", remark = "编辑物件级别") + @Operation(summary = "编辑物件级别") + @RequestMapping(value = "/edit", method = RequestMethod.POST) + public SimpleDataResponse edit( + @RequestBody OptLevelParam optLevelParam, + @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 levelService.edit(optLevelParam, CompanyId, UserId, LanguageType); + } + + @AccessRequired + @OperationLog(operation = "deleteLevel", remark = "删除物件级别") + @Operation(summary = "删除物件级别") + @RequestMapping(value = "/batchDelete", method = RequestMethod.POST) + public SimpleDataResponse batchDelete( + @RequestBody DeleteLevelParam deleteLevelParam, + @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 levelService.batchDelete(deleteLevelParam, CompanyId, UserId, LanguageType); + } + + @AccessRequired + @OperationLog(operation = "queryLevel", remark = "获取物件级别列表") + @Operation(summary = "获取物件级别列表") + @RequestMapping(value = "/getListPage", method = RequestMethod.GET) + public PageResponse> 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, + PageLevelSearchParam pageLevelSearchParam + ) throws BusinessException { + + pageLevelSearchParam.setUserId(UserId); + PageResponse> pageResponse = new PageResponse<>(); + try { + pageResponse.setData(levelService.getListPage(pageLevelSearchParam, 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; + } +} \ No newline at end of file diff --git a/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelMapperExt.java b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelMapperExt.java new file mode 100644 index 0000000..9fd8346 --- /dev/null +++ b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelMapperExt.java @@ -0,0 +1,35 @@ +package com.dongjian.dashboard.back.dao.ex; + +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.level.LevelPageDTO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface LevelMapperExt { + + long checkExist(OptLevelParam param); + + void saveLevel(LevelEntity levelEntity); + + void saveLevelRelation(LevelRelationEntity levelRelationEntity); + + long countParentLevel(OptLevelParam param); + + void updateLevel(LevelEntity levelEntity); + + void deleteLevelRelation(LevelRelationEntity param); + + long checkIfReferencedByChildren(@Param("param") LevelRelationEntity param, @Param("idList") List idList); + + void deleteLevelByIdList(@Param("tableName") String tableName, @Param("idList") List idList); + + void deleteLevelRelationByIdList(@Param("param") LevelRelationEntity param, @Param("idList") List idList); + + List getListPage(PageLevelSearchParam pageSearchParam); +} \ No newline at end of file diff --git a/dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml b/dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml new file mode 100644 index 0000000..077bfbc --- /dev/null +++ b/dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelMapperExt.xml @@ -0,0 +1,183 @@ + + + + + + + + dashboard_level_branch + dashboard_level_store + dashboard_level_area + dashboard_level_site + + + + + + dashboard_level_branch + dashboard_level_store + dashboard_level_area + + + + + + + + + + + INSERT INTO + + (company_id, name, remark, created_by, created_at) + VALUES + (#{companyId}, #{name}, #{remark}, #{createdBy}, #{createdAt}) + + + + + INSERT INTO + ${tableName} + (${parentField}, ${childField}, created_by, created_at) + VALUES + (#{parentId}, #{childId}, #{createdBy}, #{createdAt}) + + + + delete from ${tableName} WHERE ${childField} = #{childId} + + + + + UPDATE + + SET + name = #{name}, + remark = #{remark}, + updated_at = #{updatedAt}, + updated_by = #{updatedBy} + WHERE id = #{id} + + + + + + UPDATE + ${tableName} + SET + `flag` = 1 + WHERE id IN #{item} + + + + delete from ${param.tableName} + WHERE ${param.childField} + IN #{item} + + + + base.`id`, + base.company_id, + base.`name` AS levelName, + base.remark, + base.created_by, + base.created_at, + base.updated_by, + base.updated_at + + + + base.flag =0 + + AND base.`id` IN #{item} + + + AND base.`name` like CONCAT('%',#{levelName},'%') + + + AND pa.id IN #{item} + + + + + + + \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/DeleteLevelParam.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/DeleteLevelParam.java new file mode 100644 index 0000000..db7601b --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/DeleteLevelParam.java @@ -0,0 +1,26 @@ +package com.dongjian.dashboard.back.dto.level; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +/** + * 物件级别删除参数类 + * 用于批量删除物件级别 + */ +@Setter +@Getter +public class DeleteLevelParam { + + /** + * 要删除的物件级别ID列表 + */ + @Schema(description = "Id,多个使用逗号连接",example = "3,5", required = true) + private String ids; + + /** + * 物件级别类型(1-支社、2-各支店、3-area、4-site) + */ + @Schema(description = "物件级别类型(1-支社、2-各支店、3-area、4-site)",example = "2", required = true) + private Integer levelType; +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelEntity.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelEntity.java new file mode 100644 index 0000000..58f8895 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelEntity.java @@ -0,0 +1,56 @@ +package com.dongjian.dashboard.back.dto.level; + +import lombok.Getter; +import lombok.Setter; + +/** + * 物件级别实体类 + */ +@Setter +@Getter +public class LevelEntity { + + private Long companyId; + + /** + * 主键ID + */ + private Long id; + + /** + * 物件级别名称 + */ + private String name; + + /** + * 物件级别类型:1-支社 2-各支店 3-area 4-site + */ + private Integer levelType; + + /** + * 描述 + */ + private String remark; + + /** + * 创建时间 + */ + private Long createdAt; + + /** + * 创建人ID + */ + private Long createdBy; + + /** + * 更新时间 + */ + private Long updatedAt; + + /** + * 更新人ID + */ + private Long updatedBy; + + +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelRelationEntity.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelRelationEntity.java new file mode 100644 index 0000000..251f317 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/LevelRelationEntity.java @@ -0,0 +1,27 @@ +package com.dongjian.dashboard.back.dto.level; + +import lombok.Getter; +import lombok.Setter; + +/** + * 物件级别关系操作实体类 + */ +@Setter +@Getter +public class LevelRelationEntity { + + private String parentField; + + private String childField; + + private Long parentId; + + private Long childId; + + private String tableName; + + private Long createdAt; + + private Long createdBy; + +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/OptLevelParam.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/OptLevelParam.java new file mode 100644 index 0000000..79e5cae --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/OptLevelParam.java @@ -0,0 +1,50 @@ +package com.dongjian.dashboard.back.dto.level; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * 物件级别操作参数类 + * 用于添加和编辑物件级别 + */ +@Setter +@Getter +public class OptLevelParam { + + /** + * 主键ID(编辑时必填) + */ + @Schema(description = "物件级别id,新增时不需要)",example = "2", required = true) + private Long id; + + /** + * 物件级别名称 + */ + @Schema(description = "名称)",example = "2", required = true) + private String levelName; + + /** + * 物件级别类型:1-支社 2-各支店 3-area 4-site + */ + @Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true) + private Integer levelType; + + /** + * 父级ID + */ + @Schema(description = "上一层级ID,可以属于多个上级层级, levelType=1时不需要传",example = "[]", required = true) + private List parentIdList; + + /** + * 描述 + */ + @Schema(description = "备注",example = "2") + private String remark; + + + @Schema(description = "所属企业ID",example = "2", hidden = true) + private Long companyId; +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/PageLevelSearchParam.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/PageLevelSearchParam.java new file mode 100644 index 0000000..a27a100 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/level/PageLevelSearchParam.java @@ -0,0 +1,36 @@ +package com.dongjian.dashboard.back.dto.level; + +import com.dongjian.dashboard.back.dto.BaseSearchParams; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * 物件级别分页查询参数类 + * 用于分页查询物件级别列表 + */ +@Setter +@Getter +public class PageLevelSearchParam extends BaseSearchParams { + + @Schema(description = "层级id") + private String ids; + + @Schema(description = "层级id", hidden = true) + private List idList; + + @Schema(description = "父级层级id") + private String parentIds; + + @Schema(description = "父级层级id", hidden = true) + private List parentIdList; + + @Schema(description = "名称",example = "jyk2") + private String levelName; + + @Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true) + private Integer levelType; + +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/LevelPageDTO.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/LevelPageDTO.java new file mode 100644 index 0000000..f627f47 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/level/LevelPageDTO.java @@ -0,0 +1,55 @@ +package com.dongjian.dashboard.back.vo.level; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +/** + * 物件级别分页查询DTO类 + * 用于返回物件级别分页查询结果 + */ +@Setter +@Getter +public class LevelPageDTO { + + /** + * 主键ID(编辑时必填) + */ + @Schema(description = "物件级别id,新增时不需要)",example = "2", required = true) + private Long id; + + /** + * 物件级别名称 + */ + @Schema(description = "名称)",example = "2", required = true) + private String levelName; + + /** + * 物件级别类型:1-支社 2-各支店 3-area 4-site + */ + @Schema(description = "级别类型:1-支社 2-各支店 3-area 4-site",example = "2", required = true) + private Integer levelType; + + /** + * 父级ID + */ + @Schema(description = "上一层级ID",example = "2", required = true) + private String parentIds; + + /** + * 父级名称 + */ + @Schema(description = "上一层级名称",example = "2") + private String parentNames; + + /** + * 描述 + */ + @Schema(description = "备注",example = "2") + private String remark; + + + @Schema(description = "创建时间,毫秒级时间戳",example = "2") + private Long createdAt; + +} \ No newline at end of file diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/LevelService.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/LevelService.java new file mode 100644 index 0000000..cf94f42 --- /dev/null +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/LevelService.java @@ -0,0 +1,23 @@ +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.level.DeleteLevelParam; +import com.dongjian.dashboard.back.dto.level.OptLevelParam; +import com.dongjian.dashboard.back.dto.level.PageLevelSearchParam; +import com.dongjian.dashboard.back.vo.level.LevelPageDTO; + +/** + * 物件级别Service接口 + * 定义物件级别的增删改查操作 + */ +public interface LevelService { + + SimpleDataResponse add(OptLevelParam optLevelParam, Long companyId, Long userId, Integer languageType); + + SimpleDataResponse edit(OptLevelParam optLevelParam, Long companyId, Long userId, Integer languageType); + + SimpleDataResponse batchDelete(DeleteLevelParam deleteLevelParam, Long companyId, Long userId, Integer languageType); + + PageInfo getListPage(PageLevelSearchParam pageLevelSearchParam, Long companyId, Long userId, Integer languageType); +} \ No newline at end of file diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceServiceImpl.java index b69eaef..44bc79d 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/DeviceServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; +import java.util.Collections; import java.util.List; @Service @@ -41,7 +42,7 @@ public class DeviceServiceImpl implements DeviceService { public PageInfo getListPage(DeviceSearchParams pageSearchParam, Long companyId, Long userId, Integer languageType) { //list防${}注入 if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { - pageSearchParam.setCompanyIdList(commonOpt.getSelfAndSubCompanyId(companyId)); + pageSearchParam.setCompanyIdList(Collections.singletonList(companyId)); } else { pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); } diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelServiceImpl.java new file mode 100644 index 0000000..6c5a149 --- /dev/null +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelServiceImpl.java @@ -0,0 +1,297 @@ +package com.dongjian.dashboard.back.service.impl; + +import com.dongjian.dashboard.back.common.language.msg.MsgLanguageChange; +import com.dongjian.dashboard.back.common.response.PageInfo; +import com.dongjian.dashboard.back.common.response.ResponseCode; +import com.dongjian.dashboard.back.common.response.SimpleDataResponse; +import com.dongjian.dashboard.back.dao.ex.LevelMapperExt; +import com.dongjian.dashboard.back.dto.level.*; +import com.dongjian.dashboard.back.service.LevelService; +import com.dongjian.dashboard.back.service.common.CommonOpt; +import com.dongjian.dashboard.back.vo.level.LevelPageDTO; +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.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 物件级别Service实现类 + * 实现物件级别的业务逻辑 + */ +@Service +public class LevelServiceImpl implements LevelService { + + private static Logger logger = LoggerFactory.getLogger(LevelServiceImpl.class); + + + @Autowired + private CommonOpt commonOpt; + @Autowired + private MsgLanguageChange msgLanguageChange; + + @Autowired + private LevelMapperExt levelMapperExt; + + + @Override + @Transactional + public SimpleDataResponse add(OptLevelParam param, Long companyId, Long userId, Integer languageType) { + try { + param.setCompanyId(companyId); + param.setId(null); + //校验参数 + SimpleDataResponse checkResult = checkParam(param, languageType); + if (200 != checkResult.getCode()) { + return checkResult; + } + //重复校验 + if (checkExist(param) > 0) { + return new SimpleDataResponse(ResponseCode.MSG_ERROR, msgLanguageChange.getParameterMapByCode(languageType, "levelNameExist")); + } + //父级id是否有效 + if (1 != param.getLevelType() && isParentLevelInvalid(param)){ + return new SimpleDataResponse(ResponseCode.MSG_ERROR, msgLanguageChange.getParameterMapByCode(languageType, "invalidParentLevel")); + } + + long currentUnix = System.currentTimeMillis(); + LevelEntity levelEntity = new LevelEntity(); + BeanUtils.copyProperties(param, levelEntity); + levelEntity.setName(param.getLevelName()); + levelEntity.setCreatedBy(userId); + levelEntity.setCreatedAt(currentUnix); + levelEntity.setCompanyId(companyId); + levelMapperExt.saveLevel(levelEntity); + + if (1 != param.getLevelType()) { + //插入关联 + insertLevelRelation(param, levelEntity, 1); + } + + return SimpleDataResponse.success(); + } catch (Exception e) { + logger.error("添加层级报错", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return new SimpleDataResponse(ResponseCode.SERVER_ERROR, e.getMessage()); + } + } + + private void insertLevelRelation(OptLevelParam param, LevelEntity levelEntity, int optType) { + for (Long parentId : param.getParentIdList()){ + LevelRelationEntity levelRelationEntity =new LevelRelationEntity(); + switch (param.getLevelType()){ + case 2: + levelRelationEntity.setParentField("branch_id"); + levelRelationEntity.setChildField("store_id"); + levelRelationEntity.setTableName("dashboard_level_relation_branch_store"); + 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.setChildField("site_id"); + levelRelationEntity.setTableName("dashboard_level_relation_area_site"); + break; + } + levelRelationEntity.setParentId(parentId); + levelRelationEntity.setChildId(levelEntity.getId()); + if (1 == optType){ + levelRelationEntity.setCreatedBy(levelEntity.getCreatedBy()); + levelRelationEntity.setCreatedAt(levelEntity.getCreatedAt()); + } else if (2 == optType){ + levelRelationEntity.setCreatedBy(levelEntity.getUpdatedBy()); + levelRelationEntity.setCreatedAt(levelEntity.getUpdatedAt()); + } + + levelMapperExt.saveLevelRelation(levelRelationEntity); + } + } + + private boolean isParentLevelInvalid(OptLevelParam param) { + long checkSize = levelMapperExt.countParentLevel(param); + return checkSize != param.getParentIdList().size(); + } + + private long checkExist(OptLevelParam param) { + return levelMapperExt.checkExist(param); + } + + private SimpleDataResponse checkParam(OptLevelParam param, Integer languageType) { + 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){ + return new SimpleDataResponse(ResponseCode.MSG_ERROR, "Parameter [levelType] error"); + } + if(1 != param.getLevelType() && CollectionUtils.isEmpty(param.getParentIdList())){ + return new SimpleDataResponse(ResponseCode.MSG_ERROR, "parentIdList can not be null"); + } + return SimpleDataResponse.success(); + } + + @Override + public SimpleDataResponse edit(OptLevelParam param, Long companyId, Long userId, Integer languageType) { + try { + param.setCompanyId(companyId); + //校验参数 + SimpleDataResponse checkResult = checkParam(param, languageType); + if (200 != checkResult.getCode()) { + return checkResult; + } + //重复校验 + if (checkExist(param) > 0) { + return new SimpleDataResponse(ResponseCode.MSG_ERROR, msgLanguageChange.getParameterMapByCode(languageType, "levelNameExist")); + } + //父级id是否有效 + if (1 != param.getLevelType() && isParentLevelInvalid(param)){ + return new SimpleDataResponse(ResponseCode.MSG_ERROR, msgLanguageChange.getParameterMapByCode(languageType, "invalidParentLevel")); + } + + long currentUnix = System.currentTimeMillis(); + LevelEntity levelEntity = new LevelEntity(); + BeanUtils.copyProperties(param, levelEntity); + levelEntity.setName(param.getLevelName()); + levelEntity.setUpdatedBy(userId); + levelEntity.setUpdatedAt(currentUnix); + levelMapperExt.updateLevel(levelEntity); + + if (1 != param.getLevelType()){ + //先删除关联关系 + LevelRelationEntity deleteLevelRelationEntity = new LevelRelationEntity(); + deleteLevelRelationEntity.setChildId(param.getId()); + switch (param.getLevelType()){ + case 2: + deleteLevelRelationEntity.setChildField("store_id"); + deleteLevelRelationEntity.setTableName("dashboard_level_relation_branch_store"); + 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"); + break; + } + levelMapperExt.deleteLevelRelation(deleteLevelRelationEntity); + //插入关联 + insertLevelRelation(param, levelEntity, 2); + } + + return SimpleDataResponse.success(); + } catch (Exception e) { + logger.error("编辑层级报错", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return new SimpleDataResponse(ResponseCode.SERVER_ERROR, e.getMessage()); + } + } + + @Override + public SimpleDataResponse batchDelete(DeleteLevelParam deleteLevelParam, Long companyId, Long userId, Integer languageType) { + try { + List idList = Arrays.asList(deleteLevelParam.getIds().split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); + + // 检查是否有下级引用(支社、支店、area级别需要检查,site级别没有下级) + Integer levelType = deleteLevelParam.getLevelType(); + LevelRelationEntity levelRelationEntity =new LevelRelationEntity(); + switch (levelType){ + case 1: + levelRelationEntity.setParentField("branch_id"); + levelRelationEntity.setTableName("dashboard_level_relation_branch_store"); + break; + case 2: + levelRelationEntity.setParentField("store_id"); + levelRelationEntity.setTableName("dashboard_level_relation_store_area"); + 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; + } + if (levelMapperExt.checkIfReferencedByChildren(levelRelationEntity, idList) > 0){ + return new SimpleDataResponse(ResponseCode.MSG_ERROR, msgLanguageChange.getParameterMapByCode(languageType, "levelReferencedByChildren")); + } + + //基础表删除 + String tableName = switch (levelType) { + case 1 -> "dashboard_level_branch"; + case 2 -> "dashboard_level_store"; + case 3 -> "dashboard_level_area"; + case 4 -> "dashboard_level_site"; + default -> ""; + }; + levelMapperExt.deleteLevelByIdList(tableName, idList); + + //删除关联表 + LevelRelationEntity deleteEntity =new LevelRelationEntity(); + switch (levelType){ + case 1: + deleteEntity.setChildField("branch_id"); + deleteEntity.setTableName("dashboard_level_relation_branch_store"); + break; + case 2: + deleteEntity.setChildField("store_id"); + deleteEntity.setTableName("dashboard_level_relation_branch_store"); + 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"); + break; + } + levelMapperExt.deleteLevelRelationByIdList(deleteEntity, idList); + + return SimpleDataResponse.success(); + } catch (Exception e) { + logger.error("删除层级报错", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return new SimpleDataResponse(ResponseCode.SERVER_ERROR, e.getMessage()); + } + } + + @Override + public PageInfo getListPage(PageLevelSearchParam pageSearchParam, Long companyId, Long userId, Integer languageType) { + Integer levelType = pageSearchParam.getLevelType(); + if (null == levelType){ + logger.error("leveType required........"); + return PageInfo.emptyPageInfo(); + } + //list防${}注入 + if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { + pageSearchParam.setCompanyIdList(Collections.singletonList(companyId)); + } else { + pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); + } + if (StringUtils.isNotBlank(pageSearchParam.getIds())) { + pageSearchParam.setIdList(Arrays.asList(pageSearchParam.getIds().split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList())); + } + if (1 != levelType && StringUtils.isNotBlank(pageSearchParam.getParentIds())){ + pageSearchParam.setParentIdList(Arrays.asList(pageSearchParam.getParentIds().split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList())); + } + + PageHelper.startPage(pageSearchParam.getPageNum() == null ? 1 : pageSearchParam.getPageNum(), pageSearchParam.getPageSize() == null ? 20 : pageSearchParam.getPageSize()); + List resultList = levelMapperExt.getListPage(pageSearchParam); + + return new PageInfo<>(resultList); + } +} \ No newline at end of file diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OperationLogServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OperationLogServiceImpl.java index f5cdfa9..9de43b4 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OperationLogServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/OperationLogServiceImpl.java @@ -52,7 +52,7 @@ public class OperationLogServiceImpl implements OperationLogService { public PageInfo getListPage(LogSearchParam pageSearchParam, Long companyId, Long userId, Integer languageType) { //list防${}注入 if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { - pageSearchParam.setCompanyIdList(commonOpt.getSelfAndSubCompanyId(companyId)); + pageSearchParam.setCompanyIdList(Collections.singletonList(companyId)); } else { pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); } diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java index 0645fc6..5604ee4 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/RoleServiceImpl.java @@ -21,11 +21,7 @@ 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.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; @@ -308,7 +304,7 @@ public class RoleServiceImpl implements RoleService { Integer languageType) { //list防${}注入 if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { - pageSearchParam.setCompanyIdList(commonOpt.getSelfAndSubCompanyId(companyId)); + pageSearchParam.setCompanyIdList(Collections.singletonList(companyId)); } else { pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); } diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/UserServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/UserServiceImpl.java index 7c48c94..39217f6 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/UserServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/UserServiceImpl.java @@ -32,6 +32,7 @@ import com.dongjian.dashboard.back.vo.user.UserPageDTO; import java.text.MessageFormat; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; @@ -289,7 +290,7 @@ public class UserServiceImpl implements UserService { Integer languageType) { //list防${}注入 if (StringUtils.isBlank(pageSearchParam.getCompanyIds())) { - pageSearchParam.setCompanyIdList(commonOpt.getSelfAndSubCompanyId(companyId)); + pageSearchParam.setCompanyIdList(Collections.singletonList(companyId)); } else { pageSearchParam.setCompanyIdList(commonOpt.filterCompanyIds(companyId, pageSearchParam.getCompanyIds())); }