From 739778a8fa18cc6708b12bc8ffc09b6e2edccea5 Mon Sep 17 00:00:00 2001 From: lhc Date: Thu, 10 Jun 2021 09:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8A=BD=E8=B1=A1=E5=8C=96=EF=BC=8C=E6=9C=BA=E6=9E=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8A=BD=E8=B1=A1=E5=8C=96=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hcframe/base/common/utils/ObjectUtil.java | 22 +++ .../base/common/utils/StringUtils.java | 4 +- .../user/common/config/UserConstant.java | 21 +++ .../auth/service/impl/MenuServiceImpl2.java | 30 +-- .../controller/UserConfigController.java | 38 ++++ .../user/module/config/entity/UserConfig.java | 50 +++++ .../config/service/UserConfigService.java | 17 ++ .../service/impl/UserConfigServiceImpl.java | 61 ++++++ .../service/impl/ManageGwServiceImpl.java | 1 + .../service/impl/ManageServiceDataImpl.java | 27 +-- .../userinfo/controller/DeptController.java | 1 - .../userinfo/controller/OrgController.java | 17 +- .../module/userinfo/service/OrgService.java | 9 +- .../userinfo/service/impl/OrgServiceImpl.java | 177 ++++++++++++++++-- hcframe-parent/pom.xml | 4 +- 15 files changed, 429 insertions(+), 50 deletions(-) create mode 100644 hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/common/config/UserConstant.java create mode 100644 hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/controller/UserConfigController.java create mode 100644 hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/entity/UserConfig.java create mode 100644 hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/UserConfigService.java create mode 100644 hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/impl/UserConfigServiceImpl.java diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/ObjectUtil.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/ObjectUtil.java index 5168d73..99044f4 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/ObjectUtil.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/ObjectUtil.java @@ -10,6 +10,7 @@ import tk.mybatis.mapper.annotation.ColumnType; import javax.persistence.Id; import javax.persistence.Table; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -151,4 +152,25 @@ public class ObjectUtil { } } + public static T mapToObj(Map map, Class clazz) { + try { + Object obj = clazz.newInstance(); + Field[] fields = obj.getClass().getDeclaredFields(); + for (Field field : fields) { + int mod = field.getModifiers(); + if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) { + continue; + } + field.setAccessible(true); + String key = StringUtils.toUnderScoreUpperCase(field.getName()); + if (map.containsKey(key)) { + field.set(obj, map.get(key)); + } + } + return (T) obj; + } catch (InstantiationException | IllegalAccessException e) { + throw new ServiceException(e); + } + } + } diff --git a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/StringUtils.java b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/StringUtils.java index f50521d..cf2ec46 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/StringUtils.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/hcframe/base/common/utils/StringUtils.java @@ -411,7 +411,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { } public static void main(String[] args) { - Long l = 1l; - System.out.println(l.toString()); + String str = "USER_ID"; + System.out.println(toCamelCase(str)); } } diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/common/config/UserConstant.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/common/config/UserConstant.java new file mode 100644 index 0000000..5101195 --- /dev/null +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/common/config/UserConstant.java @@ -0,0 +1,21 @@ +package com.hcframe.user.common.config; + +/** + * @author lhc + * @version 1.0 + * @className UserConstrant + * @date 2021年05月31日 10:14 上午 + * @description 描述 + */ +public class UserConstant { + + // redis 哈希key + public static final String USER = "user"; + + // redis 哈希中的item key + public static final String USER_CONFIG = "userConfig"; + + // 机构树缓存 + public static final String ORG_TREE = "orgTree"; + +} diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/auth/service/impl/MenuServiceImpl2.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/auth/service/impl/MenuServiceImpl2.java index be52192..acc6944 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/auth/service/impl/MenuServiceImpl2.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/auth/service/impl/MenuServiceImpl2.java @@ -1,24 +1,23 @@ package com.hcframe.user.module.auth.service.impl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringJoiner; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import com.github.pagehelper.PageInfo; import com.hcframe.base.common.ResultVO; import com.hcframe.base.common.WebPageInfo; +import com.hcframe.base.module.cache.CacheService; +import com.hcframe.base.module.cache.impl.TableCache; import com.hcframe.base.module.data.module.BaseMapper; import com.hcframe.base.module.data.module.Condition; import com.hcframe.base.module.data.service.TableService; import com.hcframe.base.module.tableconfig.entity.OsSysTable; +import com.hcframe.redis.RedisUtil; import com.hcframe.user.module.auth.service.MenuService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; /** * @author wewe @@ -35,6 +34,11 @@ public class MenuServiceImpl2 implements MenuService { @Autowired BaseMapper baseMapper; @Autowired TableService tableService; + @Autowired + RedisUtil redisUtil; + @Autowired + @Qualifier(TableCache.TABLE) + CacheService tableCache; @Override public ResultVO addMenu(Map data) { @@ -56,6 +60,7 @@ public class MenuServiceImpl2 implements MenuService { return ResultVO.getFailed("PATH不能重复"); } tableService.saveWithDate(OS_SYS_MENU, data); + tableCache.delete("menu"); return ResultVO.getSuccess(); } @@ -72,6 +77,7 @@ public class MenuServiceImpl2 implements MenuService { tableService.logicDelete(OS_REL_ROLE_MENU, rmIds); } }); + tableCache.delete("menu"); return ResultVO.getSuccess(); } @@ -97,6 +103,7 @@ public class MenuServiceImpl2 implements MenuService { @Override public ResultVO updateMenu(Map data, Integer version) { + tableCache.delete("menu"); return tableService.updateWithDate(OS_SYS_MENU, data, version); } @@ -111,7 +118,6 @@ public class MenuServiceImpl2 implements MenuService { if (null == roleId) { return ResultVO.getFailed("授权角色不能为空"); } - baseMapper.deleteByCondition(OS_REL_ROLE_OS.getTableName(), Condition.creatCriteria().andEqual("ROLE_ID", roleId).build()); baseMapper.deleteByCondition(OS_REL_ROLE_MENU.getTableName(), Condition.creatCriteria().andEqual("ROLE_ID", roleId).build()); if (menuIds != null) { diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/controller/UserConfigController.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/controller/UserConfigController.java new file mode 100644 index 0000000..13fb718 --- /dev/null +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/controller/UserConfigController.java @@ -0,0 +1,38 @@ +package com.hcframe.user.module.config.controller; + +import com.hcframe.base.common.ResultVO; +import com.hcframe.user.module.config.entity.UserConfig; +import com.hcframe.user.module.config.service.UserConfigService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author lhc + * @version 1.0 + * @className UserConfigController + * @date 2021年05月26日 9:55 上午 + * @description 描述 + */ +@RestController +@RequestMapping("config") +public class UserConfigController { + + final UserConfigService userConfigService; + + public UserConfigController(UserConfigService userConfigService) { + this.userConfigService = userConfigService; + } + + @PostMapping("saveConfig") + public ResultVO saveUserConfig(UserConfig userConfig) { + return userConfigService.saveUserConfig(userConfig); + } + + @GetMapping("") + public ResultVO getUserConfig() { + return ResultVO.getSuccess(userConfigService.getUserConfig()); + } + +} diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/entity/UserConfig.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/entity/UserConfig.java new file mode 100644 index 0000000..331f6bf --- /dev/null +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/entity/UserConfig.java @@ -0,0 +1,50 @@ +package com.hcframe.user.module.config.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * @author lhc + * @version 1.0 + * @className UserConfig + * @date 2021年05月26日 10:33 上午 + * @description 描述 + */ +@NoArgsConstructor +@AllArgsConstructor +@Builder(toBuilder = true) +@Data +@Table(name = "OS_SYS_USER_CONFIG") +public class UserConfig implements Serializable { + private static final long serialVersionUID = 1553490676930061444L; + // 主键 + @Id + private Integer userConfigId; + + // 用户表表名 + private String userTableName; + + // 机构表表名 + private String orgTableName; + + // 用户表主键 + private String userKey; + + // 机构表主键 + private String orgKey; + + // 机构表自关联主键,用于生成机构树及从属关系 + private String orgParentId; + + // 用户关联机构字段,暂时支持机构一对用户多,此字段需要在用户表中提现 + private String orgUserCode; + + // 机构表与用户表所关联字段,此字段处于机构表中 + private String orgRelCode; +} diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/UserConfigService.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/UserConfigService.java new file mode 100644 index 0000000..78aa46e --- /dev/null +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/UserConfigService.java @@ -0,0 +1,17 @@ +package com.hcframe.user.module.config.service; + +import com.hcframe.base.common.ResultVO; +import com.hcframe.user.module.config.entity.UserConfig; + +/** + * @author lhc + * @version 1.0 + * @className UserConfigService + * @date 2021年05月26日 9:56 上午 + * @description 描述 + */ +public interface UserConfigService { + ResultVO saveUserConfig(UserConfig userConfig); + + UserConfig getUserConfig(); +} diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/impl/UserConfigServiceImpl.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/impl/UserConfigServiceImpl.java new file mode 100644 index 0000000..0603931 --- /dev/null +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/config/service/impl/UserConfigServiceImpl.java @@ -0,0 +1,61 @@ +package com.hcframe.user.module.config.service.impl; + +import com.hcframe.base.common.ResultVO; +import com.hcframe.base.common.utils.JudgeException; +import com.hcframe.base.common.utils.ObjectUtil; +import com.hcframe.base.module.data.module.BaseMapper; +import com.hcframe.base.module.data.module.BaseMapperImpl; +import com.hcframe.redis.RedisUtil; +import com.hcframe.user.common.config.UserConstant; +import com.hcframe.user.module.config.entity.UserConfig; +import com.hcframe.user.module.config.service.UserConfigService; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * @author lhc + * @version 1.0 + * @className UserConfigServiceImpl + * @date 2021年05月26日 9:56 上午 + * @description 描述 + */ +@Service +public class UserConfigServiceImpl implements UserConfigService { + + final BaseMapper baseMapper; + + final RedisUtil redisUtil; + + public UserConfigServiceImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper, + RedisUtil redisUtil) { + this.baseMapper = baseMapper; + this.redisUtil = redisUtil; + } + + @Override + public ResultVO saveUserConfig(UserConfig userConfig) { + redisUtil.hdel(UserConstant.USER,UserConstant.USER_CONFIG); + JudgeException.isNull(userConfig.getUserTableName(), "userTableAlias不能为null"); + if (StringUtils.isEmpty(userConfig.getUserConfigId())) { + baseMapper.save(userConfig); + } else { + baseMapper.updateByPk(userConfig); + } + return ResultVO.getSuccess(); + } + + @Override + public UserConfig getUserConfig() { + UserConfig userConfig = (UserConfig) redisUtil.hget("user","userConfig"); + if (userConfig == null) { + List> list = baseMapper.selectAll("OS_SYS_USER_CONFIG"); + userConfig = ObjectUtil.mapToObj(list.get(0), UserConfig.class); + redisUtil.hset("user","userConfig", userConfig); + } + return userConfig; + } +} diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageGwServiceImpl.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageGwServiceImpl.java index 9431389..7da487a 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageGwServiceImpl.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageGwServiceImpl.java @@ -46,6 +46,7 @@ public class ManageGwServiceImpl implements ManageGwService { @Autowired TableService tableService; + @Override public ResultVO> addUser(Map user) { JudgeException.isNull(user.get("PASSWORD"), "密码不能为空"); diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageServiceDataImpl.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageServiceDataImpl.java index 828f8da..f38978d 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageServiceDataImpl.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/manage/service/impl/ManageServiceDataImpl.java @@ -17,8 +17,11 @@ import com.hcframe.base.module.data.service.TableService; import com.hcframe.base.module.tableconfig.entity.OsSysTable; import com.hcframe.user.common.utils.MD5Utils; import com.hcframe.user.common.utils.POIUtil; +import com.hcframe.user.module.config.entity.UserConfig; +import com.hcframe.user.module.config.service.UserConfigService; import com.hcframe.user.module.manage.mapper.ManageMapper; import com.hcframe.user.module.manage.service.ManageService; +import com.hcframe.user.module.userinfo.service.OrgService; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -57,15 +60,22 @@ public class ManageServiceDataImpl implements ManageService { final POIUtil poiUtil; + final OrgService orgService; + + final UserConfigService userConfigService; public ManageServiceDataImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper, TableService tableService, ManageMapper manageMapper, - POIUtil poiUtil) { + POIUtil poiUtil, + OrgService orgService, + UserConfigService userConfigService) { this.baseMapper = baseMapper; this.tableService = tableService; this.manageMapper = manageMapper; this.poiUtil = poiUtil; + this.orgService = orgService; + this.userConfigService = userConfigService; } @Override @@ -111,17 +121,12 @@ public class ManageServiceDataImpl implements ManageService { @Override public ResultVO>> getUserList(String data, WebPageInfo webPageInfo, String orgId) { + UserConfig userConfig = userConfigService.getUserConfig(); DataMap dataMap = DataMap.builder().sysOsTable(TABLE_INFO).build(); Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap); - if (!StringUtils.isEmpty(orgId) && !orgId.equals("guobo")) { - orgId = orgId.replaceAll("\"", ""); - String sql = "select CODE from GB_CAS_DEPT where CODE like '" + orgId + "%'"; - List> list = baseMapper.selectSql(sql); - List idList = new ArrayList<>(); - for (Map code : list) { - idList.add(code.get("CODE")); - } - builder.andIn("DEPT_CODE", idList); + if (!StringUtils.isEmpty(orgId)) { + Long parentId = Long.valueOf(orgId.replaceAll("\"", "")); + builder.andIn(userConfig.getOrgUserCode(), orgService.getOrgChildIdList(parentId)); } builder.andEqual("USER_TYPE", "GN"); if (!StringUtils.isEmpty(data)) { @@ -140,7 +145,7 @@ public class ManageServiceDataImpl implements ManageService { map.remove("PASSWORD"); map.put("PASSWORD", "******"); } - page.setList(list); +// page.setList(list); return ResultVO.getSuccess(page); } diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/DeptController.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/DeptController.java index 0e18df3..e789510 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/DeptController.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/DeptController.java @@ -23,7 +23,6 @@ public class DeptController { final DeptService deptService; - public DeptController(DeptService deptService) { this.deptService = deptService; } diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/OrgController.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/OrgController.java index 1cc372b..52040ac 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/OrgController.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/controller/OrgController.java @@ -43,8 +43,19 @@ public class OrgController { } @GetMapping() - @ApiOperation(value = "获取机构列表", notes = "删除后职位也会被删除") - public ResultVO>> getOrgList(String data, WebPageInfo webPageInfo) { - return orgService.getOrgList(data, webPageInfo); + @ApiOperation(value = "获取机构列表", notes = "删除后职位也会被删除(职位暂未实现)") + public ResultVO>> getOrgList(String data, WebPageInfo webPageInfo,String parentId) { + return orgService.getOrgList(data, webPageInfo , parentId); + } + + @GetMapping(value = "tree") + @ApiOperation(value = "获取机构树") + public ResultVO getOrgTree() { + return ResultVO.getSuccess(orgService.getOrgTree()); + } + + @GetMapping(value = "format") + public ResultVO formatOrg() { + return orgService.getFormat(); } } diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/OrgService.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/OrgService.java index 6a6a157..2dc7886 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/OrgService.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/OrgService.java @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; import com.hcframe.base.common.ResultVO; import com.hcframe.base.common.WebPageInfo; +import java.util.List; import java.util.Map; public interface OrgService { @@ -13,5 +14,11 @@ public interface OrgService { ResultVO deleteOrg(String ids); - ResultVO>> getOrgList(String data, WebPageInfo webPageInfo); + ResultVO>> getOrgList(String data, WebPageInfo webPageInfo, String parentId); + + List> getOrgTree(); + + ResultVO getFormat(); + + List getOrgChildIdList(Long parentId); } diff --git a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/impl/OrgServiceImpl.java b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/impl/OrgServiceImpl.java index d55908f..39d043d 100644 --- a/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/impl/OrgServiceImpl.java +++ b/hcframe-parent/hcframe-user/src/main/java/com/hcframe/user/module/userinfo/service/impl/OrgServiceImpl.java @@ -1,20 +1,31 @@ package com.hcframe.user.module.userinfo.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageInfo; import com.hcframe.base.common.ResultVO; +import com.hcframe.base.common.ServiceException; import com.hcframe.base.common.WebPageInfo; +import com.hcframe.base.common.utils.MyPageHelper; import com.hcframe.base.module.data.module.BaseMapper; import com.hcframe.base.module.data.module.BaseMapperImpl; import com.hcframe.base.module.data.module.Condition; +import com.hcframe.base.module.data.module.DataMap; import com.hcframe.base.module.data.service.TableService; import com.hcframe.base.module.tableconfig.entity.OsSysTable; +import com.hcframe.redis.RedisUtil; +import com.hcframe.user.common.config.UserConstant; +import com.hcframe.user.module.config.entity.UserConfig; +import com.hcframe.user.module.config.service.UserConfigService; import com.hcframe.user.module.userinfo.service.OrgService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; -import java.util.Arrays; -import java.util.Map; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.*; /** * @author lhc @@ -22,47 +33,177 @@ import java.util.Map; @Service public class OrgServiceImpl implements OrgService { - private static final String ORG_ID = "ORG_ID"; - private static final String OS_SYS_ORG = "OS_SYS_ORG"; - private static final String OS_SYS_POSITION = "OS_SYS_POSITION"; - private static final OsSysTable TABLE_INFO = OsSysTable.builder().tableName(OS_SYS_ORG).tablePk(ORG_ID).build(); final BaseMapper baseMapper; final TableService tableService; + final UserConfigService userConfigService; + + final RedisUtil redisUtil; + public OrgServiceImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper, - TableService tableService) { + TableService tableService, + UserConfigService userConfigService, + RedisUtil redisUtil) { this.baseMapper = baseMapper; this.tableService = tableService; + this.userConfigService = userConfigService; + this.redisUtil = redisUtil; } + @Override public ResultVO addOrg(Map org) { - return ResultVO.getSuccess(tableService.saveWithDate(TABLE_INFO, org)); + UserConfig userConfig = userConfigService.getUserConfig(); + OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build(); + return ResultVO.getSuccess(tableService.saveWithDate(osSysTable, org)); } @Override public ResultVO updateOrg(Map org, Integer version) { - return tableService.updateWithDate(TABLE_INFO,org,version); + UserConfig userConfig = userConfigService.getUserConfig(); + OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build(); + return tableService.updateWithDate(osSysTable, org, version); } @Override @Transactional(rollbackFor = Exception.class) public ResultVO deleteOrg(String ids) { - String[] idArr = ids.split(","); - Condition condition = Condition - .creatCriteria() - .andIn(ORG_ID,Arrays.asList(idArr)) - .build(); - baseMapper.deleteByCondition(OS_SYS_POSITION,condition); - tableService.delete(TABLE_INFO, ids); + UserConfig userConfig = userConfigService.getUserConfig(); + OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build(); + tableService.logicDelete(osSysTable, ids); return ResultVO.getSuccess(); } @Override - public ResultVO>> getOrgList(String data, WebPageInfo webPageInfo) { - PageInfo> pageInfo = tableService.searchSingleTables(data, TABLE_INFO, webPageInfo); + public ResultVO>> getOrgList(String data, WebPageInfo webPageInfo, String parentId) { + UserConfig userConfig = userConfigService.getUserConfig(); + OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build(); + DataMap dataMap = DataMap.builder().sysOsTable(osSysTable).build(); + Condition.ConditionBuilder builder = Condition.creatCriteria(dataMap); + if (!StringUtils.isEmpty(data)) { + try { + data = URLDecoder.decode(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new ServiceException(e); + } + JSONArray jsonArray = JSON.parseArray(data); + builder = tableService.getQueryBuilder(jsonArray, builder); + } + builder.andEqual("DELETED", 1); + if (!StringUtils.isEmpty(parentId)) { + builder.andIn("ID", getOrgChildIdList(Long.valueOf(parentId.replaceAll("\"", "")))); + } + PageInfo> pageInfo = baseMapper.selectByCondition(builder.build(), webPageInfo); return ResultVO.getSuccess(pageInfo); } + + @Override + public List getOrgChildIdList(Long parentId) { + Set ids = new HashSet<>(); + getOrgChilidIds(parentId, ids, getOrgTree()); + return new ArrayList<>(ids); + } + + // 递归获取所有下属ID + private void getOrgChilidIds(Long parentId, Set ids, List> treeList) { + ids.add(parentId); + Long childParentId; + for (Map map : treeList) { + if (map.get("PARENT_ID").equals(parentId)) { + ids.add((Long) map.get("ID")); + childParentId = (Long) map.get("ID"); + } else { + childParentId = parentId; + } + if (map.get("children") != null && ((List>) map.get("children")).size() > 0) { + getOrgChilidIds(childParentId, ids, (List>) map.get("children")); + } + } + } + + @Override + public List> getOrgTree() { + List> results = (List>) redisUtil.hget(UserConstant.USER, UserConstant.ORG_TREE); + UserConfig userConfig = userConfigService.getUserConfig(); + if (results == null) { + Condition condition = Condition.creatCriteria().andEqual("DELETED", 1).build(); + MyPageHelper.orderBy("SORT_ID", "ASC"); + List> list = baseMapper.selectByCondition(userConfig.getOrgTableName(), condition); + results = getChildPerms(list, 0, userConfig); + redisUtil.hset(UserConstant.USER, UserConstant.ORG_TREE, results); + } + return results; + } + + @Override + public ResultVO getFormat() { + UserConfig userConfig = userConfigService.getUserConfig(); + List> list = baseMapper.selectAll(userConfig.getOrgTableName()); + OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build(); + for (Map map : list) { + if (!"guobo".equals(map.get("CODE"))) { + if (String.valueOf(map.get("CODE")).length() == 4) { + map.put("PARENT_ID", -3858082048188003782L); + baseMapper.updateByPk(osSysTable, map); + } else { + String parentCode = String.valueOf(map.get("CODE")).substring(0, 4); + for (Map parent : list) { + if (parentCode.equals(parent.get("CODE"))) { + map.put("PARENT_ID", parent.get("ID")); + baseMapper.updateByPk(osSysTable, map); + } + } + } + } + } + return null; + } + + public List> getChildPerms(List> list, long parentId, UserConfig userConfig) { + List> returnList = new ArrayList<>(); + for (Map t : list) { + // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 + if (t.get(userConfig.getOrgParentId()).equals(parentId)) { + recursionFn(list, t, userConfig); + returnList.add(t); + } + } + return returnList; + } + + /** + * 递归列表 + * + * @param list + * @param t + */ + private void recursionFn(List> list, Map t, UserConfig userConfig) { + // 得到子节点列表 + List> childList = getChildList(list, t, userConfig); + t.put("children", childList); + for (Map tChild : childList) { + if (hasChild(list, tChild, userConfig)) { + recursionFn(list, tChild, userConfig); + } + } + } + + /** + * 得到子节点列表 + */ + private List> getChildList(List> list, Map t, UserConfig userConfig) { + List> tlist = new ArrayList<>(); + for (Map n : list) { + if (n.get(userConfig.getOrgParentId()).equals(t.get(userConfig.getOrgKey()))) { + tlist.add(n); + } + } + return tlist; + } + + private boolean hasChild(List> list, Map t, UserConfig userConfig) { + return getChildList(list, t, userConfig).size() > 0; + } } diff --git a/hcframe-parent/pom.xml b/hcframe-parent/pom.xml index eb3f27b..558b882 100644 --- a/hcframe-parent/pom.xml +++ b/hcframe-parent/pom.xml @@ -26,8 +26,8 @@ hcframe-spider - 8 - 8 + 1.8 + 1.8 2.2.5.RELEASE Hoxton.SR7 2.3.2.RELEASE