新增用户配置抽象化,机构配置抽象化完成
This commit is contained in:
@@ -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> T mapToObj(Map<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
}
|
||||
@@ -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<Object> addMenu(Map<String, Object> 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<Integer> updateMenu(Map<String, Object> 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) {
|
||||
|
||||
@@ -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<Object> saveUserConfig(UserConfig userConfig) {
|
||||
return userConfigService.saveUserConfig(userConfig);
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public ResultVO<Object> getUserConfig() {
|
||||
return ResultVO.getSuccess(userConfigService.getUserConfig());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<Object> saveUserConfig(UserConfig userConfig);
|
||||
|
||||
UserConfig getUserConfig();
|
||||
}
|
||||
@@ -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<Object> 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<Map<String, Object>> list = baseMapper.selectAll("OS_SYS_USER_CONFIG");
|
||||
userConfig = ObjectUtil.mapToObj(list.get(0), UserConfig.class);
|
||||
redisUtil.hset("user","userConfig", userConfig);
|
||||
}
|
||||
return userConfig;
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ public class ManageGwServiceImpl implements ManageGwService {
|
||||
@Autowired
|
||||
TableService tableService;
|
||||
|
||||
|
||||
@Override
|
||||
public ResultVO<Map<String, Object>> addUser(Map<String, Object> user) {
|
||||
JudgeException.isNull(user.get("PASSWORD"), "密码不能为空");
|
||||
|
||||
@@ -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<PageInfo<Map<String, Object>>> getUserList(String data, WebPageInfo webPageInfo, String orgId) {
|
||||
UserConfig userConfig = userConfigService.getUserConfig();
|
||||
DataMap<Object> 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<Map<String, Object>> list = baseMapper.selectSql(sql);
|
||||
List<Object> idList = new ArrayList<>();
|
||||
for (Map<String, Object> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ public class DeptController {
|
||||
|
||||
final DeptService deptService;
|
||||
|
||||
|
||||
public DeptController(DeptService deptService) {
|
||||
this.deptService = deptService;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,19 @@ public class OrgController {
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
@ApiOperation(value = "获取机构列表", notes = "删除后职位也会被删除")
|
||||
public ResultVO<PageInfo<Map<String,Object>>> getOrgList(String data, WebPageInfo webPageInfo) {
|
||||
return orgService.getOrgList(data, webPageInfo);
|
||||
@ApiOperation(value = "获取机构列表", notes = "删除后职位也会被删除(职位暂未实现)")
|
||||
public ResultVO<PageInfo<Map<String,Object>>> getOrgList(String data, WebPageInfo webPageInfo,String parentId) {
|
||||
return orgService.getOrgList(data, webPageInfo , parentId);
|
||||
}
|
||||
|
||||
@GetMapping(value = "tree")
|
||||
@ApiOperation(value = "获取机构树")
|
||||
public ResultVO<Object> getOrgTree() {
|
||||
return ResultVO.getSuccess(orgService.getOrgTree());
|
||||
}
|
||||
|
||||
@GetMapping(value = "format")
|
||||
public ResultVO<Object> formatOrg() {
|
||||
return orgService.getFormat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Object> deleteOrg(String ids);
|
||||
|
||||
ResultVO<PageInfo<Map<String, Object>>> getOrgList(String data, WebPageInfo webPageInfo);
|
||||
ResultVO<PageInfo<Map<String, Object>>> getOrgList(String data, WebPageInfo webPageInfo, String parentId);
|
||||
|
||||
List<Map<String,Object>> getOrgTree();
|
||||
|
||||
ResultVO<Object> getFormat();
|
||||
|
||||
List<Long> getOrgChildIdList(Long parentId);
|
||||
}
|
||||
|
||||
@@ -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<Object> addOrg(Map<String, Object> 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<Integer> updateOrg(Map<String, Object> 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<Object> 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<PageInfo<Map<String, Object>>> getOrgList(String data, WebPageInfo webPageInfo) {
|
||||
PageInfo<Map<String,Object>> pageInfo = tableService.searchSingleTables(data, TABLE_INFO, webPageInfo);
|
||||
public ResultVO<PageInfo<Map<String, Object>>> 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<Map<String, Object>> pageInfo = baseMapper.selectByCondition(builder.build(), webPageInfo);
|
||||
return ResultVO.getSuccess(pageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getOrgChildIdList(Long parentId) {
|
||||
Set<Long> ids = new HashSet<>();
|
||||
getOrgChilidIds(parentId, ids, getOrgTree());
|
||||
return new ArrayList<>(ids);
|
||||
}
|
||||
|
||||
// 递归获取所有下属ID
|
||||
private void getOrgChilidIds(Long parentId, Set<Long> ids, List<Map<String, Object>> treeList) {
|
||||
ids.add(parentId);
|
||||
Long childParentId;
|
||||
for (Map<String, Object> 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<String, Object>>) map.get("children")).size() > 0) {
|
||||
getOrgChilidIds(childParentId, ids, (List<Map<String, Object>>) map.get("children"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getOrgTree() {
|
||||
List<Map<String, Object>> results = (List<Map<String, Object>>) 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<Map<String, Object>> list = baseMapper.selectByCondition(userConfig.getOrgTableName(), condition);
|
||||
results = getChildPerms(list, 0, userConfig);
|
||||
redisUtil.hset(UserConstant.USER, UserConstant.ORG_TREE, results);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO<Object> getFormat() {
|
||||
UserConfig userConfig = userConfigService.getUserConfig();
|
||||
List<Map<String, Object>> list = baseMapper.selectAll(userConfig.getOrgTableName());
|
||||
OsSysTable osSysTable = OsSysTable.builder().tableName(userConfig.getOrgTableName()).tablePk(userConfig.getOrgKey()).build();
|
||||
for (Map<String, Object> 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<String, Object> parent : list) {
|
||||
if (parentCode.equals(parent.get("CODE"))) {
|
||||
map.put("PARENT_ID", parent.get("ID"));
|
||||
baseMapper.updateByPk(osSysTable, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getChildPerms(List<Map<String, Object>> list, long parentId, UserConfig userConfig) {
|
||||
List<Map<String, Object>> returnList = new ArrayList<>();
|
||||
for (Map<String, Object> 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<Map<String, Object>> list, Map<String, Object> t, UserConfig userConfig) {
|
||||
// 得到子节点列表
|
||||
List<Map<String, Object>> childList = getChildList(list, t, userConfig);
|
||||
t.put("children", childList);
|
||||
for (Map<String, Object> tChild : childList) {
|
||||
if (hasChild(list, tChild, userConfig)) {
|
||||
recursionFn(list, tChild, userConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<Map<String, Object>> getChildList(List<Map<String, Object>> list, Map<String, Object> t, UserConfig userConfig) {
|
||||
List<Map<String, Object>> tlist = new ArrayList<>();
|
||||
for (Map<String, Object> n : list) {
|
||||
if (n.get(userConfig.getOrgParentId()).equals(t.get(userConfig.getOrgKey()))) {
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
private boolean hasChild(List<Map<String, Object>> list, Map<String, Object> t, UserConfig userConfig) {
|
||||
return getChildList(list, t, userConfig).size() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
<module>hcframe-spider</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<spring-alibaba.version>2.2.5.RELEASE</spring-alibaba.version>
|
||||
<spring-cloud.version>Hoxton.SR7</spring-cloud.version>
|
||||
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
|
||||
|
||||
Reference in New Issue
Block a user