459242451@qq.com 3 роки тому
батько
коміт
0ca0683847

+ 25 - 41
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java

@@ -1,10 +1,7 @@
 package com.ruoyi.web.controller.system;
 
 import cn.hutool.core.util.ArrayUtil;
-import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
@@ -16,12 +13,18 @@ import com.ruoyi.system.service.ISysDeptService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -32,8 +35,7 @@ import java.util.Map;
  */
 @RestController
 @RequestMapping("/system/dept")
-public class SysDeptController extends BaseController
-{
+public class SysDeptController extends BaseController {
     @Autowired
     private ISysDeptService deptService;
 
@@ -42,8 +44,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:list')")
     @GetMapping("/list")
-    public AjaxResult list(SysDept dept)
-    {
+    public AjaxResult list(SysDept dept) {
         List<SysDept> depts = deptService.selectDeptList(dept);
         return AjaxResult.success(depts);
     }
@@ -53,8 +54,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:list')")
     @GetMapping("/list/exclude/{deptId}")
-    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId)
-    {
+    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId) {
         List<SysDept> depts = deptService.selectDeptList(new SysDept());
         depts.removeIf(d -> d.getDeptId().equals(deptId)
             || ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
@@ -66,8 +66,7 @@ public class SysDeptController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:dept:query')")
     @GetMapping(value = "/{deptId}")
-    public AjaxResult getInfo(@PathVariable String deptId)
-    {
+    public AjaxResult getInfo(@PathVariable String deptId) {
         deptService.checkDeptDataScope(deptId);
         return AjaxResult.success(deptService.selectDeptById(deptId));
     }
@@ -76,8 +75,7 @@ public class SysDeptController extends BaseController
      * 获取部门下拉树列表
      */
     @GetMapping("/treeselect")
-    public AjaxResult treeselect(SysDept dept)
-    {
+    public AjaxResult treeselect(SysDept dept) {
         List<SysDept> depts = deptService.selectDeptList(dept);
         return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
     }
@@ -86,10 +84,9 @@ public class SysDeptController extends BaseController
      * 加载对应角色部门列表树
      */
     @GetMapping(value = "/roleDeptTreeselect/{roleId}")
-    public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId)
-    {
+    public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId) {
         List<SysDept> depts = deptService.selectDeptList(new SysDept());
-		Map<String,Object> ajax = new HashMap<>();
+        Map<String, Object> ajax = new HashMap<>();
         ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
         ajax.put("depts", deptService.buildDeptTreeSelect(depts));
         return AjaxResult.success(ajax);
@@ -101,10 +98,8 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:add')")
     @Log(title = "部门管理", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@Validated @RequestBody SysDept dept)
-    {
-        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
-        {
+    public AjaxResult add(@Validated @RequestBody SysDept dept) {
+        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
             return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
         }
         dept.setCreateBy(getUsername());
@@ -117,19 +112,13 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:edit')")
     @Log(title = "部门管理", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@Validated @RequestBody SysDept dept)
-    {
-        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
-        {
+    public AjaxResult edit(@Validated @RequestBody SysDept dept) {
+        if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
             return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
-        }
-        else if (dept.getParentId().equals(dept.getDeptId()))
-        {
+        } else if (dept.getParentId().equals(dept.getDeptId())) {
             return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
-        }
-        else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
-                && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
-        {
+        } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
+            && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0) {
             return AjaxResult.error("该部门包含未停用的子部门!");
         }
         dept.setUpdateBy(getUsername());
@@ -142,14 +131,11 @@ public class SysDeptController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:dept:remove')")
     @Log(title = "部门管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{deptId}")
-    public AjaxResult remove(@PathVariable String deptId)
-    {
-        if (deptService.hasChildByDeptId(deptId))
-        {
+    public AjaxResult remove(@PathVariable String deptId) {
+        if (deptService.hasChildByDeptId(deptId)) {
             return AjaxResult.error("存在下级部门,不允许删除");
         }
-        if (deptService.checkDeptExistUser(deptId))
-        {
+        if (deptService.checkDeptExistUser(deptId)) {
             return AjaxResult.error("部门存在用户,不允许删除");
         }
         return toAjax(deptService.deleteDeptById(deptId));
@@ -168,8 +154,6 @@ public class SysDeptController extends BaseController
             sysDept.setUpdateBy("system");
             sysDept.setCreateTime(new Date());
             sysDept.setUpdateTime(new Date());
-            sysDept.setOrgId(jsonObject.getStr("orgId"));
-            sysDept.setDeptShortName(jsonObject.getStr("deptShortName"));
             sysDepts.add(sysDept);
         }
         deptService.saveBatch(sysDepts);

+ 34 - 71
ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/SysGatewayUserTask.java

@@ -9,16 +9,12 @@ import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysDictData;
-import com.ruoyi.common.core.domain.entity.SysUser;
-import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.framework.websocket.WebSocketServer;
 import com.ruoyi.framework.websocket.WebsocketConst;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysDictTypeService;
 import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.zhdd.domain.GatewayDept;
-import com.ruoyi.zhdd.domain.GatewayOrg;
-import com.ruoyi.zhdd.domain.GatewaySUser;
 import com.ruoyi.zhdd.domain.SingleDevice;
 import com.ruoyi.zhdd.domain.bo.SingleDeviceBo;
 import com.ruoyi.zhdd.service.ISingleDeviceService;
@@ -27,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.kafka.annotation.KafkaListener;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
 import java.util.List;
 
 @Component
@@ -49,7 +44,7 @@ public class SysGatewayUserTask {
     @Autowired
     private WebSocketServer webSocketServer;
 
-    @KafkaListener(topics = "t_uc_user")
+    /*@KafkaListener(topics = "t_uc_user")
     public void onUserMessage(String message) {
         log.info("kafka用户信息消费:{}", message);
         try {
@@ -62,7 +57,7 @@ public class SysGatewayUserTask {
                     //插入
                     SysUser user = new SysUser();
                     user.setUserId(gatewaySUser.getUserId());
-                    /*{
+                    *//*{
                         SysDept qdept = new SysDept();
                         qdept.setOtherId(gatewaySUser.getDeptId());
                         List<SysDept> deptList = deptService.selectDeptList(qdept);
@@ -71,7 +66,7 @@ public class SysGatewayUserTask {
                         } else {
                             //还未有部门暂不设置  //需要先同步部门
                         }
-                    }*/
+                    }*//*
                     user.setPhonenumber(gatewaySUser.getMobile());
                     user.setNickName(gatewaySUser.getName());
                     user.setUserName(gatewaySUser.getUserName());
@@ -92,7 +87,7 @@ public class SysGatewayUserTask {
                 } else {
                     //更新
                     SysUser user = userList.get(0);
-                    /*{
+                    *//*{
                         SysDept qdept = new SysDept();
                         qdept.setOtherId(gatewaySUser.getDeptId());
                         List<SysDept> deptList = deptService.selectDeptList(qdept);
@@ -102,7 +97,7 @@ public class SysGatewayUserTask {
                             //还未有部门暂不设置  //需要先同步部门
 
                         }
-                    }*/
+                    }*//*
                     user.setPhonenumber(gatewaySUser.getMobile());
                     user.setNickName(gatewaySUser.getName());
                     user.setUserName(gatewaySUser.getUserName());
@@ -125,55 +120,22 @@ public class SysGatewayUserTask {
         } catch (Exception e) {
             log.error("t_uc_use的kafka消费异常:{}", e.getMessage());
         }
-    }
+    }*/
 
-    @KafkaListener(topics = "t_uc_org")
-    public void onOrgMessage(String message) {
-        log.info("kafka组织信息消费:{}", message);
-        //默认组织是0   组织间的层级先不考虑
-        try {
-            GatewayOrg gatewayOrg = JSONUtil.toBean(message, GatewayOrg.class);
-            if (gatewayOrg != null) {
-                SysDept qdept = new SysDept();
-                qdept.setOrgId(gatewayOrg.getOrgId());
-                List<SysDept> deptList = deptService.selectDeptList(qdept);
-                if (deptList.isEmpty()) {
-                    //插入
-                    SysDept dept = new SysDept();
-//                    dept.setOtherId(gatewayOrg.getOrgId());
-                    dept.setParentId(StrUtil.isBlank(gatewayOrg.getParentId()) ? "0" : gatewayOrg.getParentId());
-                    dept.setDeptName(gatewayOrg.getOrgName());
-                    dept.setCreateBy("kafka");
-                    dept.setCreateTime(new Date());
-                    dept.setUpdateBy("kafka");
-                    dept.setUpdateTime(new Date());
-                    dept.setDelFlag(gatewayOrg.getDelFlag());
-                    deptService.insertDept(dept);
-                } else {
-                    //更新
-                    SysDept dept = deptList.get(0);
-//                    dept.setOtherId(gatewayOrg.getOrgId());
-                    dept.setParentId(StrUtil.isBlank(gatewayOrg.getParentId()) ? "0" : gatewayOrg.getParentId());
-                    dept.setDeptName(gatewayOrg.getOrgName());
-                    dept.setUpdateBy("kafka");
-                    dept.setUpdateTime(new Date());
-                    dept.setDelFlag(gatewayOrg.getDelFlag());
-                    deptService.updateDept(dept);
-                }
-            }
-        } catch (Exception e) {
-            log.error("t_uc_org的kafka消费异常:{}", e.getMessage());
-        }
-    }
-
-    @KafkaListener(topics = "t_uc_dept")
+    /**
+     * 四维组织部门数据消费
+     * {"id":"f124bfe4b43c49c5b7451b11355cc499","name":"市运输服务中心","parentId":null,"parentName":null,"flag":0,"createTime":"2021-10-21 14:02:28","createUser":"admin","updateTime":"2021-10-21 14:02:28","updateUser":"admin","delFlag":"0"}
+     *
+     * @param message
+     */
+    @KafkaListener(topics = "t_uc_orgdept")
     public void onDeptMessage(String message) {
         log.info("kafka部门信息消费:{}", message);
         try {
             GatewayDept gatewayDept = JSONUtil.toBean(message, GatewayDept.class);
             if (gatewayDept != null) {
                 SysDept qdept = new SysDept();
-                qdept.setDeptId(gatewayDept.getDeptId());
+                qdept.setDeptId(gatewayDept.getId());
                 List<SysDept> deptList = deptService.selectDeptList(qdept);
                 if (deptList.isEmpty()) {
                     //插入
@@ -194,19 +156,18 @@ public class SysGatewayUserTask {
                             //无父组织或部门 暂不处理吧
                         }
                     }*/
-                    dept.setParentId(gatewayDept.getOrgId());
-//                    dept.setOtherId(gatewayDept.getDeptId());
-                    dept.setDeptName(gatewayDept.getDeptName());
-                    dept.setUpdateBy("kafka");
-                    dept.setUpdateTime(new Date());
-                    dept.setCreateBy("kafka");
-                    dept.setCreateTime(new Date());
-                    dept.setDelFlag(gatewayDept.getDelFlag());
-                    dept.setOrgId(gatewayDept.getOrgId());
-                    deptService.insertDept(dept);
+                    qdept.setParentId(StrUtil.emptyToDefault(gatewayDept.getParentId(), "0"));
+                    qdept.setDeptName(gatewayDept.getName());
+                    qdept.setUpdateBy(gatewayDept.getUpdateUser());
+                    qdept.setUpdateTime(DateUtil.parseDateTime(gatewayDept.getUpdateTime()));
+                    qdept.setCreateBy(gatewayDept.getCreateUser());
+                    qdept.setCreateTime(DateUtil.parseDateTime(gatewayDept.getCreateTime()));
+                    qdept.setDelFlag(gatewayDept.getDelFlag());
+                    qdept.setFlag(gatewayDept.getFlag());
+                    deptService.insertDept(qdept);
                 } else {
                     //更新
-                    SysDept dept = deptList.get(0);
+                    qdept = deptList.get(0);
                     //查询父部门
                     /*{
                         SysDept qdept1 = new SysDept();
@@ -223,17 +184,19 @@ public class SysGatewayUserTask {
                             //无父组织或部门 暂不处理吧
                         }
                     }*/
-                    dept.setParentId(gatewayDept.getOrgId());
-                    dept.setDeptName(gatewayDept.getDeptName());
-                    dept.setUpdateBy("kafka");
-                    dept.setUpdateTime(new Date());
-                    dept.setDelFlag(gatewayDept.getDelFlag());
-                    dept.setOrgId(gatewayDept.getOrgId());
-                    deptService.updateDept(dept);
+                    qdept.setParentId(StrUtil.emptyToDefault(gatewayDept.getParentId(), "0"));
+                    qdept.setDeptName(gatewayDept.getName());
+                    qdept.setUpdateBy(gatewayDept.getUpdateUser());
+                    qdept.setUpdateTime(DateUtil.parseDateTime(gatewayDept.getUpdateTime()));
+                    qdept.setCreateBy(gatewayDept.getCreateUser());
+                    qdept.setCreateTime(DateUtil.parseDateTime(gatewayDept.getCreateTime()));
+                    qdept.setDelFlag(gatewayDept.getDelFlag());
+                    qdept.setFlag(gatewayDept.getFlag());
+                    deptService.updateDept(qdept);
                 }
             }
         } catch (Exception e) {
-            log.error("t_uc_dept的kafka消费异常:{}", e.getMessage());
+            log.error("t_uc_orgdept的kafka消费异常:{}", e.getMessage());
         }
     }
 

+ 114 - 113
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java

@@ -1,6 +1,11 @@
 package com.ruoyi.common.core.domain.entity;
 
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
@@ -9,7 +14,11 @@ import javax.validation.constraints.Email;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.Size;
 import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 部门表 sys_dept
@@ -22,116 +31,108 @@ import java.util.*;
 @Accessors(chain = true)
 @TableName("sys_dept")
 public class SysDept implements Serializable {
-	private static final long serialVersionUID = 1L;
-
-	/**
-	 * 部门ID
-	 */
-	@TableId(value = "dept_id", type = IdType.ASSIGN_ID)
-	private String deptId;
-
-	/**
-	 * 父部门ID
-	 */
-	private String parentId;
-
-	/**
-	 * 祖级列表
-	 */
-	private String ancestors;
-
-	/**
-	 * 部门名称
-	 */
-	@NotBlank(message = "部门名称不能为空")
-	@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
-	private String deptName;
-
-	/**
-	 * 显示顺序
-	 */
-	@NotBlank(message = "显示顺序不能为空")
-	private String orderNum;
-
-	/**
-	 * 负责人
-	 */
-	private String leader;
-
-	/**
-	 * 联系电话
-	 */
-	@Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
-	private String phone;
-
-	/**
-	 * 邮箱
-	 */
-	@Email(message = "邮箱格式不正确")
-	@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
-	private String email;
-
-	/**
-	 * 部门状态:0正常,1停用
-	 */
-	private String status;
-
-	/**
-	 * 删除标志(0代表存在 2代表删除)
-	 */
-	@TableLogic
-	private String delFlag;
-
-	/**
-	 * 父部门名称
-	 */
-	@TableField(exist = false)
-	private String parentName;
-
-	/**
-	 * 创建者
-	 */
-	@TableField(fill = FieldFill.INSERT)
-	private String createBy;
-
-	/**
-	 * 创建时间
-	 */
-	@TableField(fill = FieldFill.INSERT)
-	private Date createTime;
-
-	/**
-	 * 更新者
-	 */
-	@TableField(fill = FieldFill.INSERT_UPDATE)
-	private String updateBy;
-
-	/**
-	 * 更新时间
-	 */
-	@TableField(fill = FieldFill.INSERT_UPDATE)
-	private Date updateTime;
-
-	/**
-	 * 子部门
-	 */
-	@TableField(exist = false)
-	private List<SysDept> children = new ArrayList<SysDept>();
-
-	/**
-	 * 请求参数
-	 */
-	@TableField(exist = false)
-	private Map<String, Object> params = new HashMap<>();
-
-    private String otherId;
-
-    private String code;
-
-    private String description;
-
-    private String deptShortName;
-
-    private String orgId;
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 部门ID
+     */
+    @TableId(value = "dept_id", type = IdType.ASSIGN_ID)
+    private String deptId;
+
+    /**
+     * 父部门ID
+     */
+    private String parentId;
+
+    /**
+     * 祖级列表
+     */
+    private String ancestors;
+
+    /**
+     * 部门名称
+     */
+    @NotBlank(message = "部门名称不能为空")
+    @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
+    private String deptName;
+
+    /**
+     * 显示顺序
+     */
+    @NotBlank(message = "显示顺序不能为空")
+    private String orderNum;
+
+    /**
+     * 负责人
+     */
+    private String leader;
+
+    /**
+     * 联系电话
+     */
+    @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
+    private String phone;
+
+    /**
+     * 邮箱
+     */
+    @Email(message = "邮箱格式不正确")
+    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
+    private String email;
+
+    /**
+     * 部门状态:0正常,1停用
+     */
+    private String status;
+
+    /**
+     * 删除标志(0代表存在 2代表删除)
+     */
+    @TableLogic
+    private String delFlag;
+
+    /**
+     * 父部门名称
+     */
+    @TableField(exist = false)
+    private String parentName;
+
+    /**
+     * 创建者
+     */
+    @TableField(fill = FieldFill.INSERT)
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    @TableField(fill = FieldFill.INSERT)
+    private Date createTime;
+
+    /**
+     * 更新者
+     */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String updateBy;
+
+    /**
+     * 更新时间
+     */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateTime;
+
+    /**
+     * 子部门
+     */
+    @TableField(exist = false)
+    private List<SysDept> children = new ArrayList<SysDept>();
+
+    /**
+     * 请求参数
+     */
+    @TableField(exist = false)
+    private Map<String, Object> params = new HashMap<>();
+
+    private Integer flag;
 
 }

+ 8 - 8
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/domain/GatewayDept.java

@@ -4,16 +4,16 @@ import lombok.Data;
 
 @Data
 public class GatewayDept {
-    private String createTime;
-    private String createUser;
-    private String delFlag;
-    private String deptId;
-    private String deptName;
-    private String deptShortName;
-    private String orgId;
-    private String orgName;
+    private String id;
+    private String name;
     private String parentId;
     private String parentName;
+    // 0机构;1部门
+    private Integer flag;
+    private String createTime;
+    private String createUser;
     private String updateTime;
     private String updateUser;
+    // 0有效;2删除
+    private String delFlag;
 }