Browse Source

【部门列表】——【只显示党工委层级】-lipf-20200618

feature/dangjian
李鹏飞 6 years ago
parent
commit
e11f8d7eac
  1. 11
      esua-epdc/epdc-admin/epdc-admin-server/pom.xml
  2. 23
      esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/SysUserController.java
  3. 2
      esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml
  4. 109
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/pom.xml
  5. 8
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/db/update.sql
  6. 15
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeConstant.java
  7. 44
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java
  8. 30
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/feign/OptOssFeignClient.java
  9. 22
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/feign/fallback/OptOssFeignClientFallback.java
  10. 55
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java
  11. 73
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/dao/OptSysDeptDao.java
  12. 72
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/entity/OptSysDeptEntity.java
  13. 62
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java
  14. 375
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java
  15. 122
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/controller/OptDeptMaCodeController.java
  16. 58
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dao/OptDeptMaCodeDao.java
  17. 111
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/OptDeptMaCodeDTO.java
  18. 19
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/UploadToOssDTO.java
  19. 60
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/entity/OptDeptMaCodeEntity.java
  20. 124
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/OptDeptMaCodeService.java
  21. 237
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/impl/OptDeptMaCodeServiceImpl.java
  22. 66
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/utils/DeptUtils.java
  23. 48
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/utils/FileUtils.java
  24. 24
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/application.yml
  25. 31
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/logback-spring.xml
  26. 64
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/mapper/deptlevel/OptSysDeptDao.xml
  27. 46
      esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/mapper/macode/OptDeptMaCodeDao.xml
  28. 20
      esua-epdc/epdc-admin/epdc-cloud-optimize/pom.xml
  29. 1
      esua-epdc/epdc-admin/pom.xml
  30. 4
      esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/constant/StrConstant.java
  31. 2
      esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/UserDetailRedis.java

11
esua-epdc/epdc-admin/epdc-admin-server/pom.xml

@ -18,6 +18,11 @@
<artifactId>epdc-admin-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-cloud-optimize</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-mybatis</artifactId>
@ -80,6 +85,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-optimize-department</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

23
esua-epdc/epdc-admin/epdc-admin-server/src/main/java/com/elink/esua/epdc/controller/SysUserController.java

@ -10,6 +10,7 @@ package com.elink.esua.epdc.controller;
import com.elink.esua.epdc.commons.tools.annotation.LogOperation;
import com.elink.esua.epdc.commons.tools.constant.Constant;
import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant;
import com.elink.esua.epdc.commons.tools.exception.ErrorCode;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.security.bo.ResourceBO;
@ -29,6 +30,7 @@ import com.elink.esua.epdc.dto.epdc.GridLeaderRegisterDTO;
import com.elink.esua.epdc.dto.epdc.result.UserWorkAndAnalyOpenIdDTO;
import com.elink.esua.epdc.dto.form.SendMessageFormDTO;
import com.elink.esua.epdc.excel.SysUserExcel;
import com.elink.esua.epdc.optimize.modules.deptlevel.service.OptSysDeptService;
import com.elink.esua.epdc.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -63,6 +65,9 @@ public class SysUserController {
@Autowired
private SysDeptService sysDeptService;
@Autowired
private OptSysDeptService optSysDeptService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ -397,6 +402,24 @@ public class SysUserController {
DeptOption option = sysDeptService.getAllDeptOptionByLoginUser();
return new Result().ok(option);
}
/**
* 获取用户部门多层结构用户前端显示请求需携带token
* <p>调接口从redis获取{@link SysUserController#packageUserDeptOption(Long)}接口生成的数据</p>
* <p>此接口展示三级机构层级街道-社区-网格不包括区级</p>
*
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.DeptOption>
* @author work@yujt.net.cn
* @date 2019/11/27 14:31
*/
@GetMapping("deptOptions/getDeptAuthByUser")
public Result<DeptOption> getDeptPartyByUser() {
UserDetail user = SecurityUser.getUser();
DeptOption deptOption = optSysDeptService.getDeptOption(user.getId(), user.getDeptIdList(),
OrganizationTypeConstant.ORG_TYPE_STREET_PARTY,
OrganizationTypeConstant.ORG_TYPE_COMMUNITY_PARTY,
OrganizationTypeConstant.ORG_TYPE_GRID_PARTY);
return new Result().ok(deptOption);
}
/**
* pc端页面获取用户街道-社区层级关系前端显示请求需携带token

2
esua-epdc/epdc-admin/epdc-admin-server/src/main/resources/application.yml

@ -45,7 +45,7 @@ management:
show-details: ALWAYS
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
mapper-locations: classpath*:/mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.elink.esua.epdc.entity
global-config:

109
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/pom.xml

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>epdc-cloud-optimize</artifactId>
<groupId>com.esua.epdc</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epdc-optimize-department</artifactId>
<description>小程序码维护功能优化</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-admin-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-mybatis</artifactId>
<version>1.0.0</version>
</dependency>
<!--微信小程序-->
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-tools-wx-ma</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-commons-api-version-control</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
</plugin>
</plugins>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/application*.yml</include>
<include>**/*.properties</include>
<include>logback-spring.xml</include>
<include>registry.conf</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>**/application*.yml</exclude>
<exclude>**/*.properties</exclude>
<exclude>logback-spring.xml</exclude>
<exclude>registry.conf</exclude>
</excludes>
</resource>
</resources>
</build>
</project>

8
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/db/update.sql

@ -0,0 +1,8 @@
-- 小程序码维护功能,新增表字段,不影响原本的代码及功能
ALTER TABLE epdc_dept_ma_code ADD COLUMN `GRID` VARCHAR ( 128 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '网格名称';
ALTER TABLE epdc_dept_ma_code ADD COLUMN `PARENT_DEPT_IDS` VARCHAR ( 512 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '父所有部门';
ALTER TABLE epdc_dept_ma_code ADD COLUMN `PARENT_DEPT_NAMES` VARCHAR ( 512 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '父所有部门';
ALTER TABLE epdc_dept_ma_code ADD COLUMN `ALL_DEPT_IDS` VARCHAR ( 512 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '所有部门ID';
ALTER TABLE epdc_dept_ma_code ADD COLUMN `ALL_DEPT_NAMES` VARCHAR ( 512 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '所有部门名称';

15
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeConstant.java

@ -0,0 +1,15 @@
package com.elink.esua.epdc.optimize.constant;
/**
* 常量
*
* @author work@yujt.net.cn
* @date 2020/5/26 10:39
*/
public class OptimizeConstant {
/**
* 组装全部机构层级时rediskey标识
*/
public final static String COMPLETE_DEPT_LEVEL_KEY = "COMPLETE_DEPT_LEVEL_KEY";
}

44
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java

@ -0,0 +1,44 @@
package com.elink.esua.epdc.optimize.constant;
import com.elink.esua.epdc.commons.tools.constant.StrConstant;
import com.elink.esua.epdc.commons.tools.redis.RedisKeys;
/**
* 优化功能所用到的redis key
*
* @author work@yujt.net.cn
* @date 2020/5/25 15:04
*/
public class OptimizeRedisKeys {
/**
* 用于存放用户部门层级关系
*
* @param userId 用户id
* @param keyStr 关键字
* @return java.lang.String
* @author work@yujt.net.cn
* @date 2020/5/25 15:05
*/
public static String getUserDeptLevelOptionKey(Long userId, String keyStr) {
return RedisKeys.getAdminUserDeptOptionKey(userId).concat(StrConstant.COLON).concat(keyStr);
}
/**
* 用于存放用户部门数据权限
*
* @param userId 用户id
* @param keyStr 关键字
* @return java.lang.String
* @author work@yujt.net.cn
* @date 2020/5/29 15:07
*/
public static String getUserDeptScopeKey(Long userId, String keyStr) {
return RedisKeys.getAdminUserDeptOptionKey(userId)
.concat(StrConstant.COLON)
.concat("scope")
.concat(StrConstant.COLON)
.concat(keyStr);
}
}

30
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/feign/OptOssFeignClient.java

@ -0,0 +1,30 @@
package com.elink.esua.epdc.optimize.feign;
import com.elink.esua.epdc.optimize.feign.fallback.OptOssFeignClientFallback;
import com.elink.esua.epdc.optimize.modules.macode.dto.UploadToOssDTO;
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
import com.elink.esua.epdc.commons.tools.utils.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
/**
* @author work@yujt.net.cn
* @date 19/9/19 10:12
*/
@FeignClient(name = ServiceConstant.EPDC_OSS_SERVER, fallback = OptOssFeignClientFallback.class)
public interface OptOssFeignClient {
/**
* File文件上传到文件服务器
*
* @param dto
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.lang.String>
* @author work@yujt.net.cn
* @date 2019/9/19 10:15
*/
@PostMapping(value = "oss/file/uploadFile", consumes = MediaType.APPLICATION_JSON_VALUE)
Result<String> uploadFile(UploadToOssDTO dto);
}

22
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/feign/fallback/OptOssFeignClientFallback.java

@ -0,0 +1,22 @@
package com.elink.esua.epdc.optimize.feign.fallback;
import com.elink.esua.epdc.optimize.feign.OptOssFeignClient;
import com.elink.esua.epdc.optimize.modules.macode.dto.UploadToOssDTO;
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant;
import com.elink.esua.epdc.commons.tools.utils.ModuleUtils;
import com.elink.esua.epdc.commons.tools.utils.Result;
import org.springframework.stereotype.Component;
/**
* @author work@yujt.net.cn
* @date 19/9/19 10:12
*/
@Component
public class OptOssFeignClientFallback implements OptOssFeignClient {
@Override
public Result<String> uploadFile(UploadToOssDTO dto) {
return ModuleUtils.feignConError(ServiceConstant.EPDC_OSS_SERVER, "uploadFile", dto.getFileName());
}
}

55
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java

@ -0,0 +1,55 @@
package com.elink.esua.epdc.optimize.modules.deptlevel.controller;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.elink.esua.epdc.optimize.modules.deptlevel.service.OptSysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 部门层级相关调用
*
* @author work@yujt.net.cn
* @date 2020/5/21 09:58
*/
@RestController
@RequestMapping("optimize")
public class OptDeptLevelController {
@Autowired
private OptSysDeptService optSysDeptService;
/**
* 通过部门id获取所有下级机构(包括冗余字段)
*
* @param typeKey 部门类别关键字{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @param deptId 部门id
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.util.List < com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO>>
* @author work@yujt.net.cn
* @date 2020/5/22 09:13
*/
@GetMapping("deptlevel/listByParent/{typeKey}/{deptId}")
public Result<List<DeptLevelAndLeaderDTO>> listChildDeptLevelById(@PathVariable("typeKey") String typeKey, @PathVariable("deptId") Long deptId) {
List<DeptLevelAndLeaderDTO> childDeptLevelList = optSysDeptService.listChildDeptLevelById(typeKey, deptId);
return new Result().ok(childDeptLevelList);
}
/**
* 根据部门类别过滤部门权限
*
* @param userId 用户id
* @param typeKeys 部门类别关键字{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.util.List < java.lang.Long>>
* @author work@yujt.net.cn
* @date 2020/5/29 15:42
*/
@PostMapping("deptScope/listByTypeKey/{userId}")
public Result<List<Long>> getUserDeptScope(@PathVariable("userId") Long userId, @RequestBody String[] typeKeys) {
List<Long> userDeptScope = optSysDeptService.getUserDeptScope(userId, typeKeys);
return new Result().ok(userDeptScope);
}
}

73
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/dao/OptSysDeptDao.java

@ -0,0 +1,73 @@
package com.elink.esua.epdc.optimize.modules.deptlevel.dao;
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 部门相关
*
* @author work@yujt.net.cn
* @date 2020/5/21 10:11
*/
@Mapper
public interface OptSysDeptDao extends BaseDao<OptSysDeptEntity> {
/**
* 根据父级部门id获取单一类别的子部门
*
* @param typeKey 类别关键字
* @param deptId 父部门id
* @return java.util.List<com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity>
* @author work@yujt.net.cn
* @date 2020/5/22 09:33
*/
List<OptSysDeptEntity> selectListChildDept(@Param("typeKey") String typeKey, @Param("deptId") Long deptId);
/**
* 根据机构id和机构父id查询机构及父机构名称
*
* @param deptId 机构id
* @param parentIds 父机构id
* @return java.util.List<DeptLevelAndLeaderDTO>
* @author work@yujt.net.cn
* @date 2020/5/15 14:10
*/
List<DeptLevelAndLeaderDTO> selectListDeptAndParents(@Param("deptId") Long deptId, @Param("parentIds") String[] parentIds);
/**
* 从数据权限筛选指定类别的部门id
*
* @param dataScopeDeptIdList 数据权限
* @param typeKeys 部门类别关键字
* @return java.util.List<java.lang.Long>
* @author work@yujt.net.cn
* @date 2020/5/25 15:28
*/
List<Long> selectListDeptIdByTypeKeyAndScope(@Param("dataScopeDeptIdList") List<Long> dataScopeDeptIdList, @Param("typeKeys") String[] typeKeys);
/**
* 通过数据权限查询顶级部门
*
* @param dataScopeDeptList
* @return java.util.List<com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity>
* @author work@yujt.net.cn
* @date 2020/5/26 09:26
*/
List<OptSysDeptEntity> selectListHeadDeptNode(@Param("dataScopeDeptList") List<Long> dataScopeDeptList);
/**
* 通过数据权限及上级部门查询下级部门
*
* @param dataScopeDeptList
* @param parentDeptIdList
* @return java.util.List<com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity>
* @author work@yujt.net.cn
* @date 2020/5/26 09:26
*/
List<OptSysDeptEntity> selectChildrenDeptNode(@Param("dataScopeDeptList") List<Long> dataScopeDeptList, @Param("parentDeptIdList") List<Long> parentDeptIdList);
}

72
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/entity/OptSysDeptEntity.java

@ -0,0 +1,72 @@
package com.elink.esua.epdc.optimize.modules.deptlevel.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.elink.esua.epdc.commons.mybatis.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @author work@yujt.net.cn
* @date
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_dept")
public class OptSysDeptEntity extends BaseEntity {
private static final long serialVersionUID = -6288907401246811269L;
/**
* 上级ID
*/
private Long pid;
/**
* 所有上级ID用逗号分开
*/
private String pids;
/**
* 部门名称
*/
private String name;
/**
* 排序
*/
private Integer sort;
/**
* 删除标识 0未删除 1删除
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
/**
* 上级部门名称
*/
@TableField(exist = false)
private String parentName;
/**
* 部门类型键值
*/
private String typeKey;
/**
* 部门编码
*/
private String partyCode;
}

62
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java

@ -0,0 +1,62 @@
package com.elink.esua.epdc.optimize.modules.deptlevel.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.elink.esua.epdc.dto.DeptOption;
import com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity;
import java.util.List;
/**
* 部门相关
*
* @author work@yujt.net.cn
* @date 2020/5/21 10:11
*/
public interface OptSysDeptService extends BaseService<OptSysDeptEntity> {
/**
* 通过部门id获取所有下级机构(包括冗余字段)
*
* @param typeKey 部门类别关键字{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @param deptId 部门id
* @return java.util.List<com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO>
* @author work@yujt.net.cn
* @date 2020/5/22 09:13
*/
List<DeptLevelAndLeaderDTO> listChildDeptLevelById(String typeKey, Long deptId);
/**
* 通过部门id获取部门信息及冗余字段
*
* @param deptId 部门id
* @return com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO
* @author work@yujt.net.cn
* @date 2020/5/22 09:13
*/
DeptLevelAndLeaderDTO getDeptLevelById(Long deptId);
/**
* 根据数据权限获取用户部门层级关系
*
* @param userId 用户主键
* @param dataScopeDeptIdList 用户数据权限部门id集合
* @param typeKeys 需要组装的部门类别的关键字 {@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/5/25 15:17
*/
DeptOption getDeptOption(Long userId, List<Long> dataScopeDeptIdList, String... typeKeys);
/**
* 按部门类别二次过滤用户部门数据权限
*
* @param userId 用户主键
* @param typeKeys 需要部门类别的关键字 {@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @return java.util.List<java.lang.Long>
* @author work@yujt.net.cn
* @date 2020/5/29 15:16
*/
List<Long> getUserDeptScope(Long userId, String... typeKeys);
}

375
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java

@ -0,0 +1,375 @@
package com.elink.esua.epdc.optimize.modules.deptlevel.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.constant.NumConstant;
import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant;
import com.elink.esua.epdc.commons.tools.constant.StrConstant;
import com.elink.esua.epdc.commons.tools.exception.RenException;
import com.elink.esua.epdc.commons.tools.redis.RedisUtils;
import com.elink.esua.epdc.commons.tools.redis.UserDetailRedis;
import com.elink.esua.epdc.commons.tools.security.user.UserDetail;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.elink.esua.epdc.dto.DeptOption;
import com.elink.esua.epdc.optimize.constant.OptimizeConstant;
import com.elink.esua.epdc.optimize.constant.OptimizeRedisKeys;
import com.elink.esua.epdc.optimize.modules.deptlevel.dao.OptSysDeptDao;
import com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity;
import com.elink.esua.epdc.optimize.modules.deptlevel.service.OptSysDeptService;
import com.elink.esua.epdc.optimize.utils.DeptUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 部门相关业务实现
*
* @author work@yujt.net.cn
* @date 2020/5/21 10:12
*/
@Service
public class OptSysDeptServiceImpl extends BaseServiceImpl<OptSysDeptDao, OptSysDeptEntity> implements OptSysDeptService {
@Autowired
private RedisUtils redisUtils;
@Autowired
private UserDetailRedis userDetailRedis;
@Override
public List<DeptLevelAndLeaderDTO> listChildDeptLevelById(String typeKey, Long deptId) {
OptSysDeptEntity parentDept = baseDao.selectById(deptId);
List<OptSysDeptEntity> childDeptList = baseDao.selectListChildDept(typeKey, deptId);
// 直属子部门
List<OptSysDeptEntity> sonNodeDepts = Lists.newArrayList();
// 非直属子部门,可能是子部门的子部门
List<OptSysDeptEntity> grandsonNodeDepts = Lists.newArrayList();
childDeptList.forEach(
childDept -> {
if (childDept.getPid().equals(deptId)) {
sonNodeDepts.add(childDept);
} else {
grandsonNodeDepts.add(childDept);
}
}
);
List<DeptLevelAndLeaderDTO> result = packSonNodeDeptLevelList(parentDept, sonNodeDepts);
if (CollUtil.isNotEmpty(grandsonNodeDepts)) {
grandsonNodeDepts.forEach(dept -> {
DeptLevelAndLeaderDTO dto = packCompleteDeptLevel(dept.getId(), dept.getPids());
if (null != dto) {
result.add(dto);
}
});
}
return result;
}
@Override
public DeptLevelAndLeaderDTO getDeptLevelById(Long deptId) {
OptSysDeptEntity dept = baseDao.selectById(deptId);
return packCompleteDeptLevel(dept.getId(), dept.getPids());
}
@Override
public DeptOption getDeptOption(Long userId, List<Long> dataScopeDeptIdList, String... typeKeys) {
if (null == userId || CollUtil.isEmpty(dataScopeDeptIdList)) {
return new DeptOption();
}
// 是否需要对数据权限部门进行二次筛选
boolean filterDataScope = false;
if (ArrayUtil.isEmpty(typeKeys)) {
typeKeys = new String[]{OptimizeConstant.COMPLETE_DEPT_LEVEL_KEY};
} else {
filterDataScope = true;
}
// 先从redis获取,减少重复查询
String redisKey = OptimizeRedisKeys.getUserDeptLevelOptionKey(userId, StringUtils.join(escapeDeptTypeKey(typeKeys), StrConstant.HYPHEN));
Object obj = redisUtils.get(redisKey);
if (null != obj) {
return (DeptOption) obj;
}
// 根据部门类型,二次筛选数据权限部门
if (filterDataScope) {
dataScopeDeptIdList = baseDao.selectListDeptIdByTypeKeyAndScope(dataScopeDeptIdList, typeKeys);
if (CollUtil.isEmpty(dataScopeDeptIdList)) {
return new DeptOption();
}
}
// 组装部门层级结构
DeptOption deptOption = packageDeptOptionByUser(dataScopeDeptIdList);
// 存入redis,超时时长设置为一小时
redisUtils.set(redisKey, deptOption, RedisUtils.HOUR_ONE_EXPIRE);
return deptOption;
}
@Override
public List<Long> getUserDeptScope(Long userId, String... typeKeys) {
UserDetail userDetail = userDetailRedis.get(userId);
if (null == userDetail) {
return Lists.newArrayList();
}
List<Long> deptScope = userDetail.getDeptIdList();
if (null == userDetail.getId() || CollUtil.isEmpty(deptScope)) {
return Lists.newArrayList();
}
// 是否需要对数据权限部门进行二次筛选
boolean filterDataScope = false;
if (ArrayUtil.isEmpty(typeKeys)) {
typeKeys = new String[]{OptimizeConstant.COMPLETE_DEPT_LEVEL_KEY};
} else {
filterDataScope = true;
}
// 先从redis获取,减少重复查询
String redisKey = OptimizeRedisKeys.getUserDeptScopeKey(userId, StringUtils.join(escapeDeptTypeKey(typeKeys), StrConstant.HYPHEN));
Object obj = redisUtils.get(redisKey);
if (null != obj) {
return (List<Long>) obj;
}
// 根据部门类型,二次筛选数据权限部门
if (filterDataScope) {
deptScope = baseDao.selectListDeptIdByTypeKeyAndScope(deptScope, typeKeys);
}
// 存入redis,超时时长设置为一小时
redisUtils.set(redisKey, deptScope, RedisUtils.HOUR_ONE_EXPIRE);
return deptScope;
}
/**
* 根据部门数据权限组装部门层级结构
*
* @param dataScopeDeptList
* @return com.elink.esua.epdc.dto.DeptOption
* @author work@yujt.net.cn
* @date 2020/5/26 10:27
*/
private DeptOption packageDeptOptionByUser(List<Long> dataScopeDeptList) {
// 通过用户部门权限 获取第一级部门节点
List<OptSysDeptEntity> headDepts = baseDao.selectListHeadDeptNode(dataScopeDeptList);
if (CollUtil.isEmpty(headDepts)) {
return new DeptOption();
}
List<Long> holdDataScope = dataScopeDeptList.stream().filter(id -> null != id).collect(Collectors.toList());
// 某个部门id 声明变量,方便操作数据
Long deptId;
// 取第几级机构
int startLevel = NumConstant.ONE_NEG;
// 用于循环计数
int loopIndex = NumConstant.ZERO;
// 存放上级节点的主键,查询下级节点用
List<Long> parentDeptIdList = Lists.newArrayList();
// 所有父级节点 此处为第一次获取,为顶级节点
JSONArray parentNodeArray = new JSONArray();
JSONObject node;
for (int i = 0; i < headDepts.size(); i++) {
// 父节点主键
deptId = headDepts.get(i).getId();
if (holdDataScope.contains(deptId)) {
startLevel = NumConstant.ZERO;
}
parentDeptIdList.add(deptId);
node = new JSONObject();
node.put("label", headDepts.get(i).getName());
node.put("value", String.valueOf(deptId));
parentNodeArray.add(node);
}
// 用于存放 每次组装好的 某一级节点。
List<JSONArray> cache = Lists.newArrayList();
cache.add(parentNodeArray);
Map<String, Object> object;
while (CollUtil.isNotEmpty(dataScopeDeptList) && CollUtil.isNotEmpty(parentDeptIdList)) {
loopIndex++;
// 通过上级节点组装所有下级节点
object = this.packageChildrenNodeArray(parentNodeArray, dataScopeDeptList, parentDeptIdList);
parentDeptIdList = (List<Long>) object.get("pids");
if (startLevel == NumConstant.ONE_NEG) {
List<Long> collect = parentDeptIdList.stream().filter(id -> holdDataScope.contains(id)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
startLevel = loopIndex;
}
}
dataScopeDeptList = (List<Long>) object.get("scope");
parentNodeArray = (JSONArray) object.get("node");
cache.add(parentNodeArray);
}
DeptOption option = new DeptOption();
option.setOptions(cache.get(startLevel));
return option;
}
/**
* 将数组内元素进行一对一替换用于拼接rediskey时缩短字符串长度
*
* @param typeKeys 一个以上的机构类别关键字
* @return java.lang.String[]
* @author work@yujt.net.cn
* @date 2020/5/26 10:45
*/
private String[] escapeDeptTypeKey(String[] typeKeys) {
String[] escapeTypeKeys = new String[typeKeys.length];
for (int i = 0; i < typeKeys.length; i++) {
String typeKey = typeKeys[i];
switch (typeKey) {
case OrganizationTypeConstant.ORG_TYPE_DISTRICT_DEPT:
escapeTypeKeys[i] = NumConstant.ZERO_STR;
break;
case OrganizationTypeConstant.ORG_TYPE_DISTRICT_PARTY:
escapeTypeKeys[i] = NumConstant.ONE_STR;
break;
case OrganizationTypeConstant.ORG_TYPE_STREET_DEPT:
escapeTypeKeys[i] = NumConstant.THREE_STR;
break;
case OrganizationTypeConstant.ORG_TYPE_STREET_PARTY:
escapeTypeKeys[i] = NumConstant.FOUR_STR;
break;
case OrganizationTypeConstant.ORG_TYPE_COMMUNITY_PARTY:
escapeTypeKeys[i] = NumConstant.FIVE_STR;
break;
case OrganizationTypeConstant.ORG_TYPE_GRID_PARTY:
escapeTypeKeys[i] = String.valueOf(NumConstant.SIX);
break;
case OptimizeConstant.COMPLETE_DEPT_LEVEL_KEY:
escapeTypeKeys[i] = String.valueOf(NumConstant.ONE_HUNDRED);
break;
default:
throw new RenException("非法的机构类别");
}
}
return escapeTypeKeys;
}
/**
* 组装下级结构节点
*
* @param allParentNode 所有的上级机构节点
* @param dataScopeDeptList 拥有数据权限的部门
* @param parentDeptIdList 上级部门id
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author work@yujt.net.cn
* @date 2019/11/29 10:27
*/
private Map<String, Object> packageChildrenNodeArray(JSONArray allParentNode, List<Long> dataScopeDeptList, List<Long> parentDeptIdList) {
List<OptSysDeptEntity> childDepts = baseDao.selectChildrenDeptNode(dataScopeDeptList, parentDeptIdList);
List newParentDeptIdList = Lists.newArrayList();
// 用于存储所有子节点
JSONArray allChildrenNodeList = new JSONArray();
// 某个父节点下所有的子节点
JSONArray childrenNodeList;
// 单个 子节点
JSONObject nodeChild;
// 单个 父节点
JSONObject nodeParent;
Long deptId;
for (int i = 0; i < allParentNode.size(); i++) {
nodeParent = allParentNode.getJSONObject(i);
// 用于存储 一个父节点的所有下级节点
childrenNodeList = new JSONArray();
for (int j = 0; j < childDepts.size(); j++) {
deptId = childDepts.get(j).getId();
if (nodeParent.get("value").equals(String.valueOf(childDepts.get(j).getPid()))) {
nodeChild = new JSONObject();
nodeChild.put("label", childDepts.get(j).getName());
nodeChild.put("value", String.valueOf(deptId));
childrenNodeList.add(nodeChild);
allChildrenNodeList.add(nodeChild);
newParentDeptIdList.add(deptId);
}
}
if (childrenNodeList.size() > 0) {
nodeParent.put("children", childrenNodeList);
}
}
List<Long> newDataScopeList = dataScopeDeptList.stream()
.filter(did -> !newParentDeptIdList.contains(did))
.collect(Collectors.toList());
Map<String, Object> result = Maps.newHashMap();
result.put("node", allChildrenNodeList);
result.put("scope", newDataScopeList);
result.put("pids", newParentDeptIdList);
return result;
}
/**
* 组装所有子部门(父部门直属)的层级关系
*
* @param parentDept 父部门
* @param sonNodeDepts 所有子部门
* @return java.util.List<com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO>
* @author work@yujt.net.cn
* @date 2020/5/22 11:09
*/
private List<DeptLevelAndLeaderDTO> packSonNodeDeptLevelList(OptSysDeptEntity parentDept, List<OptSysDeptEntity> sonNodeDepts) {
List<DeptLevelAndLeaderDTO> result = Lists.newArrayList();
if (CollUtil.isEmpty(sonNodeDepts)) {
return result;
}
DeptLevelAndLeaderDTO baseDeptLevel = packCompleteDeptLevel(parentDept.getId(), parentDept.getPids());
sonNodeDepts.forEach(dept -> result.add(packSonNodeDeptLevel(dept, baseDeptLevel)));
return result;
}
/**
* 组装子部门(父部门直属)的层级关系
*
* @param dept 子部门
* @param baseDeptLevel 父部门及层级关系
* @return com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO
* @author work@yujt.net.cn
* @date 2020/5/22 11:02
*/
private DeptLevelAndLeaderDTO packSonNodeDeptLevel(OptSysDeptEntity dept, DeptLevelAndLeaderDTO baseDeptLevel) {
DeptLevelAndLeaderDTO dto = new DeptLevelAndLeaderDTO();
dto.setDeptId(dept.getId());
dto.setDeptName(dept.getName());
dto.setTypeKey(dept.getTypeKey());
dto.setParentDeptIds(baseDeptLevel.getAllDeptIds());
dto.setParentDeptNames(baseDeptLevel.getAllDeptNames());
dto.setAllDeptIds(baseDeptLevel.getAllDeptIds().concat(StrConstant.COMMA).concat(String.valueOf(dept.getId())));
dto.setAllDeptNames(baseDeptLevel.getAllDeptNames().concat(StrConstant.HYPHEN).concat(dept.getName()));
return dto;
}
/**
* 获取部门及父部门信息拼接部门id部门名称
*
* @param deptId 本部门id
* @param pids 所有父部门id
* @return OptDeptMaCodeEntity
* @author work@yujt.net.cn
* @date 2020/5/18 14:06
*/
private DeptLevelAndLeaderDTO packCompleteDeptLevel(Long deptId, String pids) {
String[] deptPids = pids.split(StrConstant.COMMA);
// 查询机构及父级机构
List<DeptLevelAndLeaderDTO> deptList = baseDao.selectListDeptAndParents(deptId, deptPids);
return DeptUtils.packageDeptLevelDto(deptPids, deptList);
}
}

122
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/controller/OptDeptMaCodeController.java

@ -0,0 +1,122 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.controller;
import com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO;
import com.elink.esua.epdc.optimize.modules.macode.service.OptDeptMaCodeService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.commons.tools.validator.AssertUtils;
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
@RestController
@RequestMapping("optimize/deptmacode")
public class OptDeptMaCodeController {
@Autowired
private OptDeptMaCodeService deptMaCodeService;
@GetMapping("page")
public Result<PageData<OptDeptMaCodeDTO>> page(@RequestParam Map<String, Object> params) {
PageData<OptDeptMaCodeDTO> page = deptMaCodeService.page(params);
return new Result<PageData<OptDeptMaCodeDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<OptDeptMaCodeDTO> get(@PathVariable("id") String id) {
OptDeptMaCodeDTO data = deptMaCodeService.get(id);
return new Result<OptDeptMaCodeDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody OptDeptMaCodeDTO dto) {
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
deptMaCodeService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody OptDeptMaCodeDTO dto) {
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
deptMaCodeService.update(dto);
return new Result();
}
@DeleteMapping
public Result delete(@RequestBody String[] ids) {
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
deptMaCodeService.delete(ids);
return new Result();
}
/**
* 将网格机构信息同步到小程序码表只是同步机构信息不会创建小程序码
*
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2020/5/18 15:18
*/
@PostMapping("initDeptForMaCode")
public Result initDeptForMaCode() {
deptMaCodeService.initDeptForMaCode();
return new Result();
}
/**
* 生成指定网格小程序码
*
* @param gridId
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2019/9/19 11:04
*/
@PostMapping("create/{gridId}")
public Result createDeptMaCode(@PathVariable("gridId") String gridId) {
return deptMaCodeService.createDeptMaCode(gridId);
}
/**
* 创建网格长注册小程序码
*
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2019/10/22 09:59
*/
@PostMapping("gridLeader")
public Result createGridLeaderMaCode() {
return deptMaCodeService.createGridLeaderMaCode();
}
}

58
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dao/OptDeptMaCodeDao.java

@ -0,0 +1,58 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.dao;
import com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO;
import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity;
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
@Mapper
public interface OptDeptMaCodeDao extends BaseDao<OptDeptMaCodeEntity> {
/**
* 根据机构类型查询机构id及pids
*
* @param dataScopeDeptIds 用户部门数据权限
* @param typeKey 机构类型{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant}
* @return java.util.List<OptDeptMaCodeEntity>
* @author work@yujt.net.cn
* @date 2020/5/15 13:58
*/
List<OptDeptMaCodeEntity> selectListDeptIdByTypeKey(@Param("dataScopeDeptIds") List<Long> dataScopeDeptIds, @Param("typeKey") String typeKey);
/**
* 小程序码维护 - 分页查询
*
* @param params
* @return java.util.List<OptDeptMaCodeDTO>
* @author work@yujt.net.cn
* @date 2020/5/18 14:35
*/
List<OptDeptMaCodeDTO> selectListDeptMaCode(Map<String, Object> params);
}

111
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/OptDeptMaCodeDTO.java

@ -0,0 +1,111 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.dto;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
@Data
public class OptDeptMaCodeDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 网格ID
*/
private Long gridId;
/**
* 小程序码URL
*/
private String codeUrl;
/**
* 乐观锁
*/
private Integer revision;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
/**
* 删除标记
*/
private String delFlag;
/**
* 是否是网格长码,0否 1是
*/
private String leaderFlag;
/**
* 网格名称
*/
private String grid;
/**
* 父所有部门
*/
private String parentDeptIds;
/**
* 父所有部门
*/
private String parentDeptNames;
/**
* 所有部门ID
*/
private String allDeptIds;
/**
* 所有部门名称
*/
private String allDeptNames;
}

19
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/dto/UploadToOssDTO.java

@ -0,0 +1,19 @@
package com.elink.esua.epdc.optimize.modules.macode.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: zy
* @Date: 2020-03-17
*/
@Data
public class UploadToOssDTO implements Serializable {
private static final long serialVersionUID = 6136753578748343389L;
private String fileName;
private byte[] fileByte;
}

60
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/entity/OptDeptMaCodeEntity.java

@ -0,0 +1,60 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.elink.esua.epdc.commons.mybatis.entity.DeptScope;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("epdc_dept_ma_code")
public class OptDeptMaCodeEntity extends DeptScope {
private static final long serialVersionUID = -6665011097985008073L;
/**
* 网格ID
*/
private Long gridId;
/**
* 小程序码URL
*/
private String codeUrl;
/**
* 是否是网格长码,0否 1是
*/
private String leaderFlag;
/**
* 网格名称
*/
private String grid;
}

124
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/OptDeptMaCodeService.java

@ -0,0 +1,124 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.service;
import com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO;
import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.Result;
import java.util.List;
import java.util.Map;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
public interface OptDeptMaCodeService extends BaseService<OptDeptMaCodeEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<OptDeptMaCodeDTO>
* @author generator
* @date 2020-05-15
*/
PageData<OptDeptMaCodeDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<OptDeptMaCodeDTO>
* @author generator
* @date 2020-05-15
*/
List<OptDeptMaCodeDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return OptDeptMaCodeDTO
* @author generator
* @date 2020-05-15
*/
OptDeptMaCodeDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2020-05-15
*/
void save(OptDeptMaCodeDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2020-05-15
*/
void update(OptDeptMaCodeDTO dto);
/**
* 批量删除
*
* @param ids
* @return void
* @author generator
* @date 2020-05-15
*/
void delete(String[] ids);
/**
* 根据部门权限同步部门信息
*
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2020/5/15 15:27
*/
Result initDeptForMaCode();
/**
* 生成指定网格小程序码
*
* @param gridId
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2020/5/18 15:19
*/
Result createDeptMaCode(String gridId);
/**
* 创建网格长注册小程序码
*
* @return com.elink.esua.epdc.commons.tools.utils.Result
* @author work@yujt.net.cn
* @date 2020/5/18 15:34
*/
Result createGridLeaderMaCode();
}

237
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/macode/service/impl/OptDeptMaCodeServiceImpl.java

@ -0,0 +1,237 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.elink.esua.epdc.optimize.modules.macode.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.elink.esua.epdc.optimize.modules.deptlevel.dao.OptSysDeptDao;
import com.elink.esua.epdc.optimize.feign.OptOssFeignClient;
import com.elink.esua.epdc.optimize.modules.macode.dao.OptDeptMaCodeDao;
import com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO;
import com.elink.esua.epdc.optimize.modules.macode.dto.UploadToOssDTO;
import com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity;
import com.elink.esua.epdc.optimize.modules.macode.service.OptDeptMaCodeService;
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl;
import com.elink.esua.epdc.commons.tools.constant.NumConstant;
import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant;
import com.elink.esua.epdc.commons.tools.constant.StrConstant;
import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum;
import com.elink.esua.epdc.commons.tools.exception.RenException;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser;
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
import com.elink.esua.epdc.commons.tools.constant.FieldConstant;
import com.elink.esua.epdc.commons.tools.utils.Result;
import com.elink.esua.epdc.optimize.utils.DeptUtils;
import com.elink.esua.epdc.optimize.utils.FileUtils;
import com.elink.esua.epdc.utils.WxMaServiceUtils;
import com.google.common.collect.Lists;
import me.chanjar.weixin.common.error.WxErrorException;
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 java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 网格小程序码
*
* @author elink elink@elink-cn.com
* @since v1.0.0 2020-05-15
*/
@Service
public class OptDeptMaCodeServiceImpl extends BaseServiceImpl<OptDeptMaCodeDao, OptDeptMaCodeEntity> implements OptDeptMaCodeService {
@Autowired
private OptSysDeptDao sysDeptDao;
@Autowired
private WxMaServiceUtils wxMaServiceUtils;
@Autowired
private OptOssFeignClient ossFeignClient;
/**
* 小程序首页
*/
private final static String MA_FRONT_PAGE_URL = "pages/index/index";
@Override
public PageData<OptDeptMaCodeDTO> page(Map<String, Object> params) {
params.put("dataScopeDeptIds", SecurityUser.getUser().getDeptIdList());
IPage<OptDeptMaCodeDTO> page = getPage(params);
List<OptDeptMaCodeDTO> pageDataList = baseDao.selectListDeptMaCode(params);
return new PageData<>(pageDataList, page.getTotal());
}
@Override
public Result initDeptForMaCode() {
List<Long> dataScopeList = SecurityUser.getUser().getDeptIdList();
List<OptDeptMaCodeEntity> deptIdList = baseDao.selectListDeptIdByTypeKey(dataScopeList, OrganizationTypeConstant.ORG_TYPE_GRID_PARTY);
if (CollUtil.isEmpty(deptIdList)) {
return new Result();
}
List<OptDeptMaCodeEntity> insertList = Lists.newArrayList();
for (OptDeptMaCodeEntity deptMaCodeEntity : deptIdList) {
OptDeptMaCodeEntity entity = packDeptBaseInfo(deptMaCodeEntity.getGridId(), deptMaCodeEntity.getParentDeptIds());
if (null != entity) {
insertList.add(entity);
}
}
insertBatch(insertList, NumConstant.FIFTY);
return new Result();
}
@Override
public Result createDeptMaCode(String gridId) {
OptDeptMaCodeEntity entity = new OptDeptMaCodeEntity();
entity.setCodeUrl(this.createMaCode(gridId, MA_FRONT_PAGE_URL));
this.baseDao.insert(entity);
UpdateWrapper<OptDeptMaCodeEntity> wrapper = new UpdateWrapper<>();
wrapper.eq(FieldConstant.GRID_ID, gridId);
baseDao.update(entity, wrapper);
return new Result();
}
@Override
public Result createGridLeaderMaCode() {
QueryWrapper<OptDeptMaCodeEntity> wrapper = new QueryWrapper<>();
wrapper.eq("leader_flag", YesOrNoEnum.YES.value());
Integer selectCount = this.baseDao.selectCount(wrapper);
if (selectCount > NumConstant.ZERO) {
return new Result();
}
OptDeptMaCodeEntity entity = new OptDeptMaCodeEntity();
entity.setAllDeptNames("全平台通用");
entity.setCodeUrl(this.createMaCode("gridLeader", MA_FRONT_PAGE_URL));
entity.setLeaderFlag(YesOrNoEnum.YES.value());
this.baseDao.insert(entity);
return new Result();
}
/**
* 创建微信小程序码并上传到oss
*
* @param param 小程序码的参数
* @param pageUrl 小程序码的跳转链接
* @return java.lang.String 小程序码的下载抵制
* @author work@yujt.net.cn
* @date 2019/10/22 10:14
*/
private String createMaCode(String param, String pageUrl) {
File wxaCodeUnlimit;
try {
wxaCodeUnlimit = wxMaServiceUtils.normalWxMaService().getQrcodeService()
.createWxaCodeUnlimit(param, pageUrl, 1280, true, null, false);
} catch (WxErrorException e) {
throw new RenException("请求微信接口失败");
}
UploadToOssDTO dto = new UploadToOssDTO();
dto.setFileByte(FileUtils.fileToByteArray(wxaCodeUnlimit));
dto.setFileName(wxaCodeUnlimit.getName());
Result<String> ossResult = ossFeignClient.uploadFile(dto);
if (null == ossResult || !ossResult.success() || null == ossResult.getData()) {
throw new RenException("小程序码上传失败");
}
return ossResult.getData();
}
/**
* 获取部门及父部门信息拼接部门id部门名称
*
* @param deptId 本部门id
* @param pids 所有父部门id
* @return OptDeptMaCodeEntity
* @author work@yujt.net.cn
* @date 2020/5/18 14:06
*/
private OptDeptMaCodeEntity packDeptBaseInfo(Long deptId, String pids) {
String[] deptPids = pids.split(StrConstant.COMMA);
// 查询机构及父级机构
List<DeptLevelAndLeaderDTO> deptList = sysDeptDao.selectListDeptAndParents(deptId, deptPids);
DeptLevelAndLeaderDTO deptLevel = DeptUtils.packageDeptLevelDto(deptPids, deptList);
OptDeptMaCodeEntity deptMaCodeEntity = ConvertUtils.sourceToTarget(deptLevel, OptDeptMaCodeEntity.class);
if (null == deptMaCodeEntity) {
return null;
}
deptMaCodeEntity.setGrid(deptLevel.getDeptName());
deptMaCodeEntity.setGridId(deptLevel.getDeptId());
deptMaCodeEntity.setLeaderFlag(YesOrNoEnum.NO.value());
return deptMaCodeEntity;
}
@Override
public List<OptDeptMaCodeDTO> list(Map<String, Object> params) {
List<OptDeptMaCodeEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, OptDeptMaCodeDTO.class);
}
private QueryWrapper<OptDeptMaCodeEntity> getWrapper(Map<String, Object> params) {
String id = (String) params.get(FieldConstant.ID_HUMP);
QueryWrapper<OptDeptMaCodeEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
return wrapper;
}
@Override
public OptDeptMaCodeDTO get(String id) {
OptDeptMaCodeEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, OptDeptMaCodeDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(OptDeptMaCodeDTO dto) {
OptDeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, OptDeptMaCodeEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(OptDeptMaCodeDTO dto) {
OptDeptMaCodeEntity entity = ConvertUtils.sourceToTarget(dto, OptDeptMaCodeEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
baseDao.deleteBatchIds(Arrays.asList(ids));
}
}

66
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/utils/DeptUtils.java

@ -0,0 +1,66 @@
package com.elink.esua.epdc.optimize.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import com.elink.esua.epdc.commons.tools.constant.NumConstant;
import com.elink.esua.epdc.commons.tools.constant.StrConstant;
import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/**
* 部门相关静态方法工具类
*
* @author work@yujt.net.cn
* @date 2020/5/22 10:21
*/
public class DeptUtils {
public static DeptLevelAndLeaderDTO packageDeptLevelDto(String[] deptPids,List<DeptLevelAndLeaderDTO> deptList){
if (CollUtil.isEmpty(deptList)) {
return null;
}
// 按上下级顺序组装部门集合
List<DeptLevelAndLeaderDTO> newDeptIdList = Lists.newArrayList();
if (ArrayUtil.isEmpty(deptPids)) {
// 父级部门为空,则只有部门本身,没有上级
newDeptIdList = deptList;
} else {
// 按部门顺序开始组装
for (int i = 0; i < deptPids.length; i++) {
for (DeptLevelAndLeaderDTO entity : deptList) {
if (String.valueOf(entity.getDeptId()).equals(deptPids[i])) {
newDeptIdList.add(entity);
deptList.remove(entity);
break;
}
}
}
// 所有父级部门处理完成,最后剩下部门本身
newDeptIdList.addAll(deptList);
}
int size = newDeptIdList.size();
int maxIndex = size - NumConstant.ONE;
String[] allDeptIds = new String[size];
String[] allDeptNames = new String[size];
String[] parentDeptIds = new String[maxIndex];
String[] parentDeptNames = new String[maxIndex];
for (int i = 0; i < size; i++) {
allDeptIds[i] = String.valueOf(newDeptIdList.get(i).getDeptId());
allDeptNames[i] = newDeptIdList.get(i).getDeptName();
if (i < maxIndex) {
parentDeptIds[i] = String.valueOf(newDeptIdList.get(i).getDeptId());
parentDeptNames[i] = newDeptIdList.get(i).getDeptName();
}
}
DeptLevelAndLeaderDTO deptLevelDto = newDeptIdList.get(maxIndex);
deptLevelDto.setAllDeptIds(StringUtils.join(allDeptIds, StrConstant.COMMA));
deptLevelDto.setParentDeptIds(StringUtils.join(parentDeptIds, StrConstant.COMMA));
deptLevelDto.setAllDeptNames(StringUtils.join(allDeptNames, StrConstant.HYPHEN));
deptLevelDto.setParentDeptNames(StringUtils.join(parentDeptNames, StrConstant.HYPHEN));
return deptLevelDto;
}
}

48
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/utils/FileUtils.java

@ -0,0 +1,48 @@
package com.elink.esua.epdc.optimize.utils;
import com.elink.esua.epdc.commons.tools.constant.NumConstant;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
/**
* 文件操作工具
*
* @author work@yujt.net.cn
* @date 2020/5/18 15:27
*/
public class FileUtils {
/**
* File文件转为byte[]
*
* @param file
* @return byte[]
* @author work@yujt.net.cn
* @date 2019/9/19 15:56
*/
public static byte[] fileToByteArray(File file) {
try {
//获取输入流
FileInputStream fis = new FileInputStream(file);
//新的 byte 数组输出流,缓冲区容量1024byte
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
//缓存
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != NumConstant.ONE_NEG) {
bos.write(b, NumConstant.ZERO, n);
}
fis.close();
//改变为byte[]
byte[] data = bos.toByteArray();
bos.close();
return data;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

24
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/application.yml

@ -0,0 +1,24 @@
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.elink.esua.epdc.optimize.modules.*.entity
global-config:
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: ID_WORKER
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
field-strategy: NOT_NULL
#驼峰下划线转换
column-underline: true
#db-type: mysql
#刷新mapper 调试神器
refresh-mapper: true
banner: false
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'

31
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/logback-spring.xml

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 开发、测试环境 -->
<springProfile name="dev,test">
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="INFO"/>
<logger name="com.elink.esua.epdc" level="INFO"/>
<logger name="com.elink.esua.epdc.optimize.modules.macode.dao" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="DEBUG_FILE"/>
<appender-ref ref="INFO_FILE"/>
<appender-ref ref="WARN_FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>
</springProfile>
<!-- 生产环境 -->
<springProfile name="prod">
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="INFO"/>
<logger name="com.elink.esua.epdc" level="INFO"/>
<root level="INFO">
<appender-ref ref="DEBUG_FILE"/>
<appender-ref ref="INFO_FILE"/>
<appender-ref ref="WARN_FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>
</springProfile>
</configuration>

64
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/mapper/deptlevel/OptSysDeptDao.xml

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.elink.esua.epdc.optimize.modules.deptlevel.dao.OptSysDeptDao">
<select id="selectListChildDept"
resultType="com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity">
SELECT * FROM sys_dept d
WHERE d.pids LIKE '%${deptId}%' AND d.type_key = #{typeKey} and d.del_flag = '0'
</select>
<select id="selectListDeptAndParents" resultType="com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO">
SELECT
t.id as deptId, t.`name` as deptName, t.type_key as typeKey
FROM
sys_dept t
WHERE
t.id = #{deptId}
<if test="parentIds != null and parentIds.length > 0">
OR t.id IN <foreach collection="parentIds" open="(" separator="," close=")" item="parentId">#{parentId}</foreach>
</if>
ORDER BY t.update_date ASC;
</select>
<select id="selectListDeptIdByTypeKeyAndScope" resultType="java.lang.Long">
SELECT id FROM sys_dept where del_flag = 0
<if test="dataScopeDeptIdList != null and dataScopeDeptIdList.size() > 0">
and id in <foreach collection="dataScopeDeptIdList" open="(" separator="," close=")" item="deptId">#{deptId}</foreach>
</if>
<if test="typeKeys != null and typeKeys.length > 0">
and type_key in <foreach collection="typeKeys" open="(" separator="," close=")" item="typeKey">#{typeKey}</foreach>
</if>
</select>
<select id="selectListHeadDeptNode" resultType="com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity">
SELECT
d1.id, d1.`name`
FROM
sys_dept d
LEFT JOIN sys_dept d1 ON d.pids LIKE CONCAT( '%', d1.id, '%' )
WHERE
d.id IN <foreach collection="dataScopeDeptList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
AND d1.pid = 0
GROUP BY d1.id
ORDER BY d1.create_date ASC
</select>
<select id="selectChildrenDeptNode"
resultType="com.elink.esua.epdc.optimize.modules.deptlevel.entity.OptSysDeptEntity">
SELECT
tem2.*
FROM
( SELECT * FROM sys_dept d1 WHERE d1.id IN <foreach collection="dataScopeDeptList" item="item" open="(" separator="," close=")">#{item}</foreach> ) tem1,
( SELECT * FROM sys_dept d2 WHERE d2.pid IN <foreach collection="parentDeptIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>) tem2
WHERE
( tem1.PIDS LIKE CONCAT( '%', tem2.id, '%' ) OR tem1.PID = tem2.ID )
OR ( tem2.ID = tem1.ID )
AND tem2.ID != ''
GROUP BY tem2.ID
ORDER BY tem2.create_date ASC
</select>
</mapper>

46
esua-epdc/epdc-admin/epdc-cloud-optimize/epdc-optimize-department/src/main/resources/mapper/macode/OptDeptMaCodeDao.xml

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.elink.esua.epdc.optimize.modules.macode.dao.OptDeptMaCodeDao">
<select id="selectListDeptIdByTypeKey"
resultType="com.elink.esua.epdc.optimize.modules.macode.entity.OptDeptMaCodeEntity">
SELECT
t.id as gridId,t.pids as parentDeptIds
FROM
sys_dept t
WHERE
t.type_key = #{typeKey} AND t.del_flag = '0'
AND NOT EXISTS (SELECT 1 FROM epdc_dept_ma_code c WHERE c.GRID_ID = t.id AND c.del_flag = '0')
<if test="dataScopeDeptIds != null and dataScopeDeptIds.size() > 0">
AND t.id IN <foreach collection="dataScopeDeptIds" open="(" separator="," close=")" item="deptId">#{deptId}</foreach>
</if>
ORDER BY t.update_date ASC;
</select>
<select id="selectListDeptMaCode"
resultType="com.elink.esua.epdc.optimize.modules.macode.dto.OptDeptMaCodeDTO">
select * from epdc_dept_ma_code ma
where ma.del_flag = '0'
<choose>
<when test='leaderFlag != null and leaderFlag != "" and leaderFlag == "1"'>and ma.leader_flag = '1'</when>
<otherwise>
and ma.leader_flag = '0'
<if test="gridId != null and gridId != ''">
and ma.grid_id = #{gridId}
</if>
<if test="communityId != null and communityId != ''">
and ma.all_dept_ids like '%${communityId}%'
</if>
<if test="streetId != null and streetId != ''">
and ma.all_dept_ids like '%${streetId}%'
</if>
<if test='dataScopeDeptIds != null and dataScopeDeptIds.size() > 0'>
AND ma.grid_id IN <foreach collection="dataScopeDeptIds" open="(" separator="," close=")" item="deptId">#{deptId}</foreach>
</if>
</otherwise>
</choose>
</select>
</mapper>

20
esua-epdc/epdc-admin/epdc-cloud-optimize/pom.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.esua.epdc</groupId>
<artifactId>epdc-admin</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epdc-cloud-optimize</artifactId>
<packaging>pom</packaging>
<description>党群e家部门机构优化微服务模块</description>
<modules>
<module>epdc-optimize-department</module>
</modules>
</project>

1
esua-epdc/epdc-admin/pom.xml

@ -16,6 +16,7 @@
<modules>
<module>epdc-admin-client</module>
<module>epdc-admin-server</module>
<module>epdc-cloud-optimize</module>
</modules>
</project>

4
esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/constant/StrConstant.java

@ -43,4 +43,8 @@ public interface StrConstant {
* 问号
*/
String QUESTION_MARK = "?";
/**
* 星号
*/
String ASTERISK = "*";
}

2
esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/UserDetailRedis.java

@ -10,6 +10,7 @@ package com.elink.esua.epdc.commons.tools.redis;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.elink.esua.epdc.commons.tools.constant.StrConstant;
import com.elink.esua.epdc.commons.tools.security.enums.UserKillEnum;
import com.elink.esua.epdc.commons.tools.security.user.UserDetail;
import com.elink.esua.epdc.commons.tools.security.enums.UserKillEnum;
@ -72,5 +73,6 @@ public class UserDetailRedis {
redisUtils.delete(RedisKeys.getUserPermissionsKey(id));
redisUtils.delete(RedisKeys.getAdminUserDeptOptionKey(id));
redisUtils.delete(RedisKeys.getAllAdminUserDeptOptionKey(id));
redisUtils.deleteByPattern(RedisKeys.getAdminUserDeptOptionKey(id).concat(StrConstant.ASTERISK));
}
}

Loading…
Cancel
Save