Explorar el Código

部门树结构拼接部门领导功能修改

zhaoxian hace 4 años
padre
commit
523c7ae3b4

+ 18 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java

@@ -7,6 +7,7 @@ import cn.com.ctop.common.module.service.ISysBaseApi;
 import cn.com.ctop.common.module.service.ISysDepartService;
 import cn.com.ctop.common.module.service.ISysUserDepartService;
 import cn.com.ctop.common.module.service.ISysUserService;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.QueryGenerator;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -27,7 +28,12 @@ import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
@@ -35,7 +41,13 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * <p>
@@ -138,11 +150,14 @@ public class SysDepartController {
         String username = JwtUtil.getUserNameByToken(request);
         sysDepart.setUpdateBy(username);
         Result<SysDepart> result = new Result<SysDepart>();
+        if (!Check.isNull(sysDepart.getLeaderName())) {
+            sysDepart.setLeaderName(sysDepart.getLeaderName().trim());
+        }
         SysDepart sysDepartEntity = sysDepartService.getById(sysDepart.getId());
         if (sysDepartEntity == null) {
             result.error500("未找到对应实体");
         } else {
-            boolean ok = sysDepartService.updateDepartDataById(sysDepart, username);
+            boolean ok = sysDepartService.updateDepartDataById(sysDepart, "");
             // TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");

+ 120 - 76
module-common/src/main/java/cn/com/ctop/common/module/entity/SysDepart.java

@@ -2,6 +2,7 @@ package cn.com.ctop.common.module.entity;
 
 import cn.com.ctop.common.module.annotation.Dict;
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -19,94 +20,137 @@ import java.util.Objects;
  * <p>
  *
  * @Author Steve
- * @Since  2019-01-22
+ * @Since 2019-01-22
  */
 @Data
 @TableName("sys_depart")
 public class SysDepart implements Serializable {
     private static final long serialVersionUID = 1L;
 
-	/**ID*/
-	@TableId(type = IdType.ID_WORKER_STR)
-	private String id;
-	/**父机构ID*/
-	private String parentId;
-	/**机构/部门名称*/
-	@Excel(name="机构/部门名称",width=15)
-	private String departName;
-	/**英文名*/
-	@Excel(name="英文名",width=15)
-	private String departNameEn;
-	/**缩写*/
-	private String departNameAbbr;
-	/**排序*/
-	@Excel(name="排序",width=15)
-	private Integer departOrder;
-	/**描述*/
-	@Excel(name="描述",width=15)
-	private String description;
-	/**机构类别 1组织机构,2岗位*/
-	@Excel(name="机构类别",width=15,dicCode="org_category")
-	private String orgCategory;
-	/**机构类型*/
-	private String orgType;
-	/**机构编码*/
-	@Excel(name="机构编码",width=15)
-	private String orgCode;
-	/**手机号*/
-	@Excel(name="手机号",width=15)
-	private String mobile;
-	/**传真*/
-	@Excel(name="传真",width=15)
-	private String fax;
-	/**地址*/
-	@Excel(name="地址",width=15)
-	private String address;
-	/**备注*/
-	@Excel(name="备注",width=15)
-	private String memo;
-	/**状态(1启用,0不启用)*/
-	@Dict(dicCode = "depart_status")
+    /**
+     * ID
+     */
+    @TableId(type = IdType.ID_WORKER_STR)
+    private String id;
+    /**
+     * 父机构ID
+     */
+    private String parentId;
+    /**
+     * 机构/部门名称
+     */
+    @Excel(name = "机构/部门名称", width = 15)
+    private String departName;
+    /**
+     * 英文名
+     */
+    @Excel(name = "英文名", width = 15)
+    private String departNameEn;
+    /**
+     * 缩写
+     */
+    private String departNameAbbr;
+    /**
+     * 排序
+     */
+    @Excel(name = "排序", width = 15)
+    private Integer departOrder;
+    /**
+     * 描述
+     */
+    @Excel(name = "描述", width = 15)
+    private String description;
+    /**
+     * 机构类别 1组织机构,2岗位
+     */
+    @Excel(name = "机构类别", width = 15, dicCode = "org_category")
+    private String orgCategory;
+    /**
+     * 机构类型
+     */
+    private String orgType;
+    /**
+     * 机构编码
+     */
+    @Excel(name = "机构编码", width = 15)
+    private String orgCode;
+    /**
+     * 手机号
+     */
+    @Excel(name = "手机号", width = 15)
+    private String mobile;
+    /**
+     * 传真
+     */
+    @Excel(name = "传真", width = 15)
+    private String fax;
+    /**
+     * 地址
+     */
+    @Excel(name = "地址", width = 15)
+    private String address;
+    /**
+     * 备注
+     */
+    @Excel(name = "备注", width = 15)
+    private String memo;
+    /**
+     * 状态(1启用,0不启用)
+     */
+    @Dict(dicCode = "depart_status")
     private String status;
-	/**删除状态(0,正常,1已删除)*/
-	@Dict(dicCode = "del_flag")
+    /**
+     * 删除状态(0,正常,1已删除)
+     */
+    @Dict(dicCode = "del_flag")
     private String delFlag;
-	/**创建人*/
-	private String createBy;
-	/**创建日期*/
-	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
-	private Date createTime;
-	/**更新人*/
-	private String updateBy;
-	/**更新日期*/
-	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
-	private Date updateTime;
-	/**
-	 * 领导 ID
-	 */
-	private String leaderId;
+    /**
+     * 创建人
+     */
+    private String createBy;
+    /**
+     * 创建日期
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    /**
+     * 更新人
+     */
+    private String updateBy;
+    /**
+     * 更新日期
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+    /**
+     * 领导 ID
+     */
+    private String leaderId;
 
-	/**
-	 * 领导姓名
-	 */
-	private String leaderName;
+    @TableField(exist = false)
+    private String title;
 
-	/**
-	 * 重写equals方法
-	 */
+    /**
+     * 领导姓名
+     */
+    private String leaderName;
+
+    /**
+     * 重写equals方法
+     */
     @Override
     public boolean equals(Object o) {
         if (this == o) {
-			return true;
-		}
+            return true;
+        }
         if (o == null || getClass() != o.getClass()) {
-			return false;
-		}
+            return false;
+        }
         if (!super.equals(o)) {
-			return false;
-		}
+            return false;
+        }
         SysDepart depart = (SysDepart) o;
         return Objects.equals(id, depart.id) &&
                 Objects.equals(parentId, depart.parentId) &&
@@ -135,8 +179,8 @@ public class SysDepart implements Serializable {
     @Override
     public int hashCode() {
         return Objects.hash(super.hashCode(), id, parentId, departName,
-        		departNameEn, departNameAbbr, departOrder, description,
-        		orgType, orgCode, mobile, fax, address, memo, status,
-        		delFlag, createBy, createTime, updateBy, updateTime);
+                departNameEn, departNameAbbr, departOrder, description,
+                orgType, orgCode, mobile, fax, address, memo, status,
+                delFlag, createBy, createTime, updateBy, updateTime);
     }
 }

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/model/DepartIdModel.java

@@ -47,7 +47,7 @@ public class DepartIdModel implements Serializable {
     public DepartIdModel convert(SysDepartTreeModel treeModel) {
         this.key = treeModel.getId();
         this.value = treeModel.getId();
-        this.title = treeModel.getDepartName();
+        this.title = treeModel.getTitle();
         this.orgCode = treeModel.getOrgCode();
         return this;
     }

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/model/SysDepartTreeModel.java

@@ -88,7 +88,7 @@ public class SysDepartTreeModel implements Serializable{
 	public SysDepartTreeModel(SysDepart sysDepart) {
 		this.key = sysDepart.getId();
         this.value = sysDepart.getId();
-        this.title = sysDepart.getDepartName();
+        this.title = sysDepart.getTitle();
         this.id = sysDepart.getId();
         this.parentId = sysDepart.getParentId();
         this.departName = sysDepart.getDepartName();

+ 15 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/SysDepartServiceImpl.java

@@ -63,6 +63,11 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
         List<SysDepart> listDepts = this.list(query);
         for (int i = 0; i < codeArr.length; i++) {
             for (SysDepart dept : listDepts) {
+                if (!Check.isNull(dept.getLeaderName())) {
+                    dept.setTitle(dept.getDepartName().concat("(").concat(dept.getLeaderName()).concat(")"));
+                } else {
+                    dept.setTitle(dept.getDepartName());
+                }
                 if (dept.getOrgCode().equals(codeArr[i])) {
                     dept.setParentId(null);
                 }
@@ -85,7 +90,9 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
         List<SysDepart> list = this.list(query);
         for (SysDepart sysDepart : list) {
             if (!Check.isNull(sysDepart.getLeaderName())) {
-                sysDepart.setDepartName(sysDepart.getDepartName().concat("(").concat(sysDepart.getLeaderName()).concat(")"));
+                sysDepart.setTitle(sysDepart.getDepartName().concat("(").concat(sysDepart.getLeaderName()).concat(")"));
+            } else {
+                sysDepart.setTitle(sysDepart.getDepartName());
             }
         }
 
@@ -101,6 +108,13 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
         query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
         query.orderByAsc(SysDepart::getDepartOrder);
         List<SysDepart> list = this.list(query);
+        for (SysDepart sysDepart : list) {
+            if (!Check.isNull(sysDepart.getLeaderName())) {
+                sysDepart.setTitle(sysDepart.getDepartName().concat("(").concat(sysDepart.getLeaderName()).concat(")"));
+            } else {
+                sysDepart.setTitle(sysDepart.getDepartName());
+            }
+        }
         // 调用wrapTreeDataToTreeList方法生成树状数据
         List<DepartIdModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToDepartIdTreeList(list);
         return listResult;