浏览代码

更新版本

liyabo 3 年之前
父节点
当前提交
f1c1f73b40
共有 20 个文件被更改,包括 182 次插入47 次删除
  1. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/dm/user/rest/DmUserController.java
  2. 2 2
      eladmin-system/src/main/java/me/zhengjie/modules/dm/user/service/dto/DmUserQueryCriteria.java
  3. 114 0
      eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ErpDataSyncTask.java
  4. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java
  5. 15 3
      eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java
  6. 4 4
      eladmin-system/src/main/java/me/zhengjie/modules/system/repository/DeptRepository.java
  7. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/repository/RoleRepository.java
  8. 2 2
      eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java
  9. 4 4
      eladmin-system/src/main/java/me/zhengjie/modules/system/rest/DeptController.java
  10. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
  11. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/DataService.java
  12. 3 3
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/DeptService.java
  13. 5 2
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptDto.java
  14. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptQueryCriteria.java
  15. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptSmallDto.java
  16. 1 1
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java
  17. 2 2
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserQueryCriteria.java
  18. 3 3
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java
  19. 16 12
      eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java
  20. 4 2
      eladmin-system/src/main/resources/config/application.yml

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/dm/user/rest/DmUserController.java

@@ -77,7 +77,7 @@ public class DmUserController {
             criteria.getDeptIds().addAll(deptService.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
         }
         // 数据权限
-        List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
+        List<String> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
         // criteria.getDeptIds() 不为空并且数据权限不为空则取交集
         if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
             // 取交集

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/dm/user/service/dto/DmUserQueryCriteria.java

@@ -36,12 +36,12 @@ public class DmUserQueryCriteria{
     private Long id;
 
     @Query(propName = "id", type = Query.Type.IN, joinName = "dept")
-    private Set<Long> deptIds = new HashSet<>();
+    private Set<String> deptIds = new HashSet<>();
 
     @Query(blurry = "name,contacts,email")
     private String blurry;
 
-    private Long deptId;
+    private String deptId;
 
     @Query(type = Query.Type.BETWEEN)
     private List<Timestamp> createTime;

+ 114 - 0
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ErpDataSyncTask.java

@@ -0,0 +1,114 @@
+/*
+ *  Copyright 2019-2020 Zheng Jie
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package me.zhengjie.modules.quartz.task;
+
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.system.domain.Dept;
+import me.zhengjie.modules.system.service.DeptService;
+import me.zhengjie.modules.system.service.dto.DeptDto;
+import org.springframework.stereotype.Component;
+
+/**
+ * ERP 数据同步
+ * @author Sky
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Component
+public class ErpDataSyncTask {
+
+    private final String erpApiUrl = "http://222.84.157.37:30170";
+    private final String sign = "e34b2f59-0e9d-45ed-a32a-f4abd4381000";
+    private final String header_key = "X_AUTO_USER_INFO_HEAD";
+    private final String header_value = "{\"id\":\"anonymous\",\"tenantId\":\"caih\"}";
+
+    private final DeptService deptService;
+
+    public void run() {
+        log.info("deptsync 执行开始");
+        deptsync();
+        log.info("deptsync 执行结束");
+    }
+
+    /**
+     * 部门数据同步
+     */
+    private void deptsync() {
+
+        String res = HttpRequest.get(erpApiUrl + "/api-third-party/busi/comm/usky/queryGroup")
+                .header(header_key, header_value)
+                .body("{\n" +
+                        "    \"formData\":{\n" +
+                        "        \"pageNum\":1,\n" +
+                        "        \"pageSize\":100\n" +
+                        "    },\n" +
+                        "    \"product\":\"17\",\n" +
+                        "    \"sign\":\"" + sign + "\"\n" +
+                        "}").execute().body();
+        JSONObject json = JSONObject.parseObject(res);
+        JSONArray datas = json.getJSONArray("data");
+        JSONObject item;
+        Dept dept;
+        for (int i = 0; i < datas.size(); i++) {
+            item = datas.getJSONObject(i);
+            dept = new Dept();
+            dept.setId(item.getString("groupId"));
+            dept.setName(item.getString("groupName"));
+
+            if(item.getString("parentId").equals("~")){
+                dept.setPid(null);
+            }else{
+                dept.setPid(item.getString("parentId"));
+            }
+            dept.setDeptSort(item.getInteger("sort"));
+            dept.setEnabled(item.getBoolean("groupStatus"));
+            dept.setTreeNames(item.getString("groupNamePath"));
+            dept.setTreeIds(item.getString("groupIdPath"));
+            dept.setDeptType(item.getInteger("groupType"));
+
+            DeptDto deptDto = deptService.findById(item.getString("groupId"));
+
+            if (deptDto != null) {
+                deptService.update(dept);
+            } else {
+                deptService.create(dept);
+            }
+        }
+    }
+
+    /**
+     * 人员数据同步
+     */
+    private void usersyncbydepid(String depid) {
+        String res = HttpRequest.get(erpApiUrl + "/api-third-party/busi/comm/usky/queryUser")
+                .header(header_key, header_value)
+                .body("{\n" +
+                        "    \"formData\":{\n" +
+                        "        \"pageNum\":1,\n" +
+                        "        \"pageSize\":100\n" +
+                        "    },\n" +
+                        "    \"product\":\"17\",\n" +
+                        "    \"sign\":\"" + sign + "\"\n" +
+                        "}").execute().body();
+        JSONObject json = JSONObject.parseObject(res);
+        JSONArray datas = json.getJSONArray("data");
+
+    }
+}

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java

@@ -35,7 +35,7 @@ public class JwtUserDto implements UserDetails {
 
     private final UserDto user;
 
-    private final List<Long> dataScopes;
+    private final List<String> dataScopes;
 
     @JSONField(serialize = false)
     private final List<GrantedAuthority> authorities;

+ 15 - 3
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java

@@ -41,8 +41,7 @@ public class Dept extends BaseEntity implements Serializable {
     @Column(name = "dept_id")
     @NotNull(groups = Update.class)
     @ApiModelProperty(value = "ID", hidden = true)
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Long id;
+    private String id;
 
     @JSONField(serialize = false)
     @ManyToMany(mappedBy = "depts")
@@ -52,6 +51,19 @@ public class Dept extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "排序")
     private Integer deptSort;
 
+    @Column(name = "dept_type")
+    @ApiModelProperty(value = "部门类型")
+    private Integer deptType;
+
+    @Column(name = "tree_names")
+    @ApiModelProperty(value = "树形目录名称")
+    private String treeNames;
+
+
+    @Column(name = "tree_ids")
+    @ApiModelProperty(value = "树形目录编号")
+    private String treeIds;
+
     @NotBlank
     @ApiModelProperty(value = "部门名称")
     private String name;
@@ -67,7 +79,7 @@ public class Dept extends BaseEntity implements Serializable {
     private Boolean enabled;
 
     @ApiModelProperty(value = "上级部门")
-    private Long pid;
+    private String pid;
 
     @ApiModelProperty(value = "子节点数目", hidden = true)
     private Integer subCount = 0;

+ 4 - 4
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/DeptRepository.java

@@ -27,14 +27,14 @@ import java.util.Set;
 * @author Zheng Jie
 * @date 2019-03-25
 */
-public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificationExecutor<Dept> {
+public interface DeptRepository extends JpaRepository<Dept, String>, JpaSpecificationExecutor<Dept> {
 
     /**
      * 根据 PID 查询
      * @param id pid
      * @return /
      */
-    List<Dept> findByPid(Long id);
+    List<Dept> findByPid(String id);
 
     /**
      * 获取顶级部门
@@ -56,7 +56,7 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
      * @param pid /
      * @return /
      */
-    int countByPid(Long pid);
+    int countByPid(String pid);
 
     /**
      * 根据ID更新sub_count
@@ -65,5 +65,5 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
      */
     @Modifying
     @Query(value = " update sys_dept set sub_count = ?1 where dept_id = ?2 ",nativeQuery = true)
-    void updateSubCntById(Integer count, Long id);
+    void updateSubCntById(Integer count, String id);
 }

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/RoleRepository.java

@@ -68,7 +68,7 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
      */
     @Query(value = "select count(1) from sys_role r, sys_roles_depts d where " +
             "r.role_id = d.role_id and d.dept_id in ?1",nativeQuery = true)
-    int countByDepts(Set<Long> deptIds);
+    int countByDepts(Set<String> deptIds);
 
     /**
      * 根据菜单Id查询

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java

@@ -88,7 +88,7 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
      */
     @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d WHERE " +
             "u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = ?1 group by u.user_id", nativeQuery = true)
-    List<User> findByRoleDeptId(Long deptId);
+    List<User> findByRoleDeptId(String deptId);
 
     /**
      * 根据菜单查询
@@ -119,7 +119,7 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
      * @return /
      */
     @Query(value = "SELECT count(1) FROM sys_user u WHERE u.dept_id IN ?1", nativeQuery = true)
-    int countByDepts(Set<Long> deptIds);
+    int countByDepts(Set<String> deptIds);
 
     /**
      * 根据角色查询

+ 4 - 4
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/DeptController.java

@@ -73,9 +73,9 @@ public class DeptController {
     @ApiOperation("查询部门:根据ID获取同级与上级数据")
     @PostMapping("/superior")
     @PreAuthorize("@el.check('user:list','dept:list')")
-    public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
+    public ResponseEntity<Object> getSuperior(@RequestBody List<String> ids) {
         Set<DeptDto> deptDtos  = new LinkedHashSet<>();
-        for (Long id : ids) {
+        for (String id : ids) {
             DeptDto deptDto = deptService.findById(id);
             List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>());
             deptDtos.addAll(depts);
@@ -108,9 +108,9 @@ public class DeptController {
     @ApiOperation("删除部门")
     @DeleteMapping
     @PreAuthorize("@el.check('dept:del')")
-    public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
+    public ResponseEntity<Object> delete(@RequestBody Set<String> ids){
         Set<DeptDto> deptDtos = new HashSet<>();
-        for (Long id : ids) {
+        for (String id : ids) {
             List<Dept> deptList = deptService.findByPid(id);
             deptDtos.add(deptService.findById(id));
             if(CollectionUtil.isNotEmpty(deptList)){

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java

@@ -88,7 +88,7 @@ public class UserController {
             criteria.getDeptIds().addAll(deptService.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
         }
         // 数据权限
-        List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
+        List<String> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
         // criteria.getDeptIds() 不为空并且数据权限不为空则取交集
         if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
             // 取交集

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DataService.java

@@ -30,5 +30,5 @@ public interface DataService {
      * @param user /
      * @return /
      */
-    List<Long> getDeptIds(UserDto user);
+    List<String> getDeptIds(UserDto user);
 }

+ 3 - 3
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DeptService.java

@@ -72,7 +72,7 @@ public interface DeptService {
      * @param id /
      * @return /
      */
-    DeptDto findById(Long id);
+    DeptDto findById(String id);
 
     /**
      * 创建
@@ -98,7 +98,7 @@ public interface DeptService {
      * @param pid /
      * @return /
      */
-    List<Dept> findByPid(long pid);
+    List<Dept> findByPid(String pid);
 
     /**
      * 根据角色ID查询
@@ -143,7 +143,7 @@ public interface DeptService {
      * @param deptList
      * @return
      */
-    List<Long> getDeptChildren(List<Dept> deptList);
+    List<String> getDeptChildren(List<Dept> deptList);
 
     /**
      * 验证是否被角色或用户关联

+ 5 - 2
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptDto.java

@@ -31,13 +31,16 @@ import java.util.Objects;
 @Setter
 public class DeptDto extends BaseDTO implements Serializable {
 
-    private Long id;
+    private String id;
 
     private String name;
 
     private String description;
 
     private String remark;
+    private String treeNames;
+    private String treeIds;
+    private Integer deptType;
 
     private Boolean enabled;
 
@@ -46,7 +49,7 @@ public class DeptDto extends BaseDTO implements Serializable {
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
     private List<DeptDto> children;
 
-    private Long pid;
+    private String pid;
 
     private Integer subCount;
 

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptQueryCriteria.java

@@ -46,7 +46,7 @@ public class DeptQueryCriteria{
     private Boolean enabled;
 
     @Query
-    private Long pid;
+    private String pid;
 
     @Query(type = Query.Type.IS_NULL, propName = "pid")
     private Boolean pidIsNull;

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptSmallDto.java

@@ -25,7 +25,7 @@ import java.io.Serializable;
 @Data
 public class DeptSmallDto implements Serializable {
 
-    private Long id;
+    private String id;
 
     private String name;
 

+ 1 - 1
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java

@@ -48,7 +48,7 @@ public class UserDto extends BaseDTO implements Serializable {
 
     private DmCompanyDto dmCompany;
 
-    private Long deptId;
+    private String deptId;
 
     private String username;
 

+ 2 - 2
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserQueryCriteria.java

@@ -34,7 +34,7 @@ public class UserQueryCriteria implements Serializable {
     private Long id;
 
     @Query(propName = "id", type = Query.Type.IN, joinName = "dept")
-    private Set<Long> deptIds = new HashSet<>();
+    private Set<String> deptIds = new HashSet<>();
 
     @Query(blurry = "email,username,nickName")
     private String blurry;
@@ -42,7 +42,7 @@ public class UserQueryCriteria implements Serializable {
     @Query
     private Boolean enabled;
 
-    private Long deptId;
+    private String deptId;
 
     @Query(type = Query.Type.BETWEEN)
     private List<Timestamp> createTime;

+ 3 - 3
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java

@@ -49,9 +49,9 @@ public class DataServiceImpl implements DataService {
      */
     @Override
     @Cacheable(key = "'user:' + #p0.id")
-    public List<Long> getDeptIds(UserDto user) {
+    public List<String> getDeptIds(UserDto user) {
         // 用于存储部门id
-        Set<Long> deptIds = new HashSet<>();
+        Set<String> deptIds = new HashSet<>();
         // 查询用户角色
         List<RoleSmallDto> roleSet = roleService.findByUsersId(user.getId());
         // 获取对应的部门ID
@@ -77,7 +77,7 @@ public class DataServiceImpl implements DataService {
      * @param role 角色
      * @return 数据权限ID
      */
-    public Set<Long> getCustomize(Set<Long> deptIds, RoleSmallDto role){
+    public Set<String> getCustomize(Set<String> deptIds, RoleSmallDto role){
         Set<Dept> depts = deptService.findByRoleId(role.getId());
         for (Dept dept : depts) {
             deptIds.add(dept.getId());

+ 16 - 12
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java

@@ -145,14 +145,18 @@ public class DeptServiceImpl implements DeptService {
 
     @Override
     @Cacheable(key = "'id:' + #p0")
-    public DeptDto findById(Long id) {
-        Dept dept = deptRepository.findById(id).orElseGet(Dept::new);
-        ValidationUtil.isNull(dept.getId(),"Dept","id",id);
-        return deptMapper.toDto(dept);
+    public DeptDto findById(String id) {
+        Optional<Dept> dept = deptRepository.findById(id);
+        if (!dept.isPresent()) {
+            return null;
+        } else {
+            ValidationUtil.isNull(dept.get().getId(), "Dept", "id", id);
+            return deptMapper.toDto(dept.get());
+        }
     }
 
     @Override
-    public List<Dept> findByPid(long pid) {
+    public List<Dept> findByPid(String pid) {
         return deptRepository.findByPid(pid);
     }
 
@@ -175,8 +179,8 @@ public class DeptServiceImpl implements DeptService {
     @Transactional(rollbackFor = Exception.class)
     public void update(Dept resources) {
         // 旧的部门
-        Long oldPid = findById(resources.getId()).getPid();
-        Long newPid = resources.getPid();
+        String oldPid = findById(resources.getId()).getPid();
+        String newPid = resources.getPid();
         if(resources.getPid() != null && resources.getId().equals(resources.getPid())) {
             throw new BadRequestException("上级不能为自己");
         }
@@ -228,8 +232,8 @@ public class DeptServiceImpl implements DeptService {
     }
 
     @Override
-    public List<Long> getDeptChildren(List<Dept> deptList) {
-        List<Long> list = new ArrayList<>();
+    public List<String> getDeptChildren(List<Dept> deptList) {
+        List<String> list = new ArrayList<>();
         deptList.forEach(dept -> {
                     if (dept!=null && dept.getEnabled()) {
                         List<Dept> depts = deptRepository.findByPid(dept.getId());
@@ -291,7 +295,7 @@ public class DeptServiceImpl implements DeptService {
 
     @Override
     public void verification(Set<DeptDto> deptDtos) {
-        Set<Long> deptIds = deptDtos.stream().map(DeptDto::getId).collect(Collectors.toSet());
+        Set<String> deptIds = deptDtos.stream().map(DeptDto::getId).collect(Collectors.toSet());
         if(userRepository.countByDepts(deptIds) > 0){
             throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
         }
@@ -300,7 +304,7 @@ public class DeptServiceImpl implements DeptService {
         }
     }
 
-    private void updateSubCnt(Long deptId){
+    private void updateSubCnt(String deptId){
         if(deptId != null){
             int count = deptRepository.countByPid(deptId);
             deptRepository.updateSubCntById(count, deptId);
@@ -328,7 +332,7 @@ public class DeptServiceImpl implements DeptService {
      * 清理缓存
      * @param id /
      */
-    public void delCaches(Long id){
+    public void delCaches(String id){
         List<User> users = userRepository.findByRoleDeptId(id);
         // 删除数据权限
         redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));

+ 4 - 2
eladmin-system/src/main/resources/config/application.yml

@@ -25,8 +25,10 @@ spring:
   redis:
     #数据库索引
     database: ${REDIS_DB:2}
-    host: ${REDIS_HOST:172.16.159.48}
-    port: ${REDIS_PORT:6386}
+#    host: ${REDIS_HOST:172.16.159.48}
+#    port: ${REDIS_PORT:6386}
+    host: ${REDIS_HOST:127.0.0.1}
+    port: ${REDIS_PORT:6379}
     password: ${REDIS_PWD:}
     #连接超时时间
     timeout: 5000ms