Quellcode durchsuchen

【CHG】修改领导选择车间接口

ZhaoMn vor 3 Jahren
Ursprung
Commit
457f2c7789

+ 21 - 4
railway-admin/src/main/java/com/railway/web/controller/system/SysProfileController.java

@@ -4,6 +4,7 @@ import com.railway.common.annotation.Log;
 import com.railway.common.constant.Constants;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.domain.AjaxResult;
+import com.railway.common.core.domain.entity.SysDept;
 import com.railway.common.core.domain.entity.SysRole;
 import com.railway.common.core.domain.entity.SysUser;
 import com.railway.common.core.domain.model.LoginUser;
@@ -13,12 +14,14 @@ import com.railway.common.enums.BusinessType;
 import com.railway.common.utils.SecurityUtils;
 import com.railway.common.utils.StringUtils;
 import com.railway.framework.web.service.TokenService;
+import com.railway.system.service.ISysDeptService;
 import com.railway.system.service.ISysFileService;
 import com.railway.system.service.ISysRoleService;
 import com.railway.system.service.ISysUserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -45,15 +48,18 @@ public class SysProfileController extends BaseController {
   private final ISysRoleService roleService;
   private final TokenService tokenService;
   private final ISysFileService sysFileService;
+  private final ISysDeptService deptService;
   private final RedisCache redisCache;
 
   public SysProfileController(ISysUserService userService,
       ISysRoleService roleService, TokenService tokenService,
-      ISysFileService sysFileService, RedisCache redisCache) {
+      ISysFileService sysFileService, ISysDeptService deptService,
+      RedisCache redisCache) {
     this.userService = userService;
     this.roleService = roleService;
     this.tokenService = tokenService;
     this.sysFileService = sysFileService;
+    this.deptService = deptService;
     this.redisCache = redisCache;
   }
 
@@ -82,11 +88,22 @@ public class SysProfileController extends BaseController {
   @GetMapping("/getSelectedDept")
   public AjaxResult getSelectedDept() {
     LoginUser loginUser = getLoginUser();
+    // 从缓存中取本个所选车间
     List<Long> deptIds = redisCache.getCacheList(getCacheKey(loginUser.getUserId()));
-    AjaxResult ajax = AjaxResult.success();
-    if(CollectionUtils.isNotEmpty(deptIds)) {
-      ajax.put("selectedDeptIds", deptIds);
+    if(CollectionUtils.isEmpty(deptIds)) {
+      // 取默认选择的车间
+      deptIds = redisCache.getCacheList(Constants.LEADER_VIEW_DEPT_INIT_KEY);
+      if(CollectionUtils.isEmpty(deptIds)){
+        // 从数据库中查默认选择的车间
+        SysDept dept = deptService.selectInitDept();
+        if(null != dept) {
+          deptIds = Collections.singletonList(dept.getDeptId());
+          redisCache.setCacheList(Constants.LEADER_VIEW_DEPT_INIT_KEY, deptIds);
+        }
+      }
     }
+    AjaxResult ajax = AjaxResult.success();
+    ajax.put("selectedDeptIds", deptIds);
     return ajax;
   }
 

+ 5 - 0
railway-common/src/main/java/com/railway/common/constant/Constants.java

@@ -144,6 +144,11 @@ public class Constants {
    */
   public static final String LEADER_VIEW_DEPT_KEY = "view_dept:";
 
+  /**
+   * 大领导查看数据所选车间
+   */
+  public static final String LEADER_VIEW_DEPT_INIT_KEY = "view_dept:init";
+
   /**
    * 资源映射路径 前缀
    */

+ 6 - 0
railway-system/src/main/java/com/railway/system/mapper/SysDeptMapper.java

@@ -13,6 +13,12 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface SysDeptMapper {
 
+  /**
+   * 查询中心领导未选择车间时可以查看数据的车间
+   * @return 长春高铁综合车间
+   */
+  SysDept selectInitDept();
+
   /**
    * 查询部门管理数据
    *

+ 6 - 0
railway-system/src/main/java/com/railway/system/service/ISysDeptService.java

@@ -11,6 +11,12 @@ import java.util.List;
  */
 public interface ISysDeptService {
 
+  /**
+   * 查询中心领导未选择车间时可以查看数据的车间
+   * @return 长春高铁综合车间
+   */
+  SysDept selectInitDept();
+
   /**
    * 查询部门管理数据
    *

+ 11 - 5
railway-system/src/main/java/com/railway/system/service/impl/SysDeptServiceImpl.java

@@ -14,7 +14,6 @@ import com.railway.common.utils.TreeSelectUtil;
 import com.railway.common.utils.spring.SpringUtils;
 import com.railway.system.mapper.SysDeptMapper;
 import com.railway.system.mapper.SysRoleMapper;
-import com.railway.system.mapper.SysUserMapper;
 import com.railway.system.service.ISysDeptService;
 import java.util.ArrayList;
 import java.util.List;
@@ -31,13 +30,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
 
   private final SysDeptMapper deptMapper;
   private final SysRoleMapper roleMapper;
-  private final SysUserMapper userMapper;
 
-  public SysDeptServiceImpl(SysDeptMapper deptMapper,
-      SysRoleMapper roleMapper, SysUserMapper userMapper) {
+  public SysDeptServiceImpl(SysDeptMapper deptMapper, SysRoleMapper roleMapper) {
     this.deptMapper = deptMapper;
     this.roleMapper = roleMapper;
-    this.userMapper = userMapper;
+  }
+
+  /**
+   * 查询中心领导未选择车间时可以查看数据的车间
+   *
+   * @return 长春高铁综合车间
+   */
+  @Override
+  public SysDept selectInitDept() {
+    return deptMapper.selectInitDept();
   }
 
   /**

+ 7 - 0
railway-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -98,6 +98,13 @@
     where dept_name=#{deptName} and parent_id = #{parentId} limit 1
   </select>
 
+  <select id="selectInitDept" resultMap="SysDeptResult">
+    select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone,
+    d.email, d.status, d.del_flag, d.create_by, d.create_time, d.remark, t.user_count, d.dept_type
+    from sys_dept d
+    where dept_name like '%长春高铁综合%' limit 1
+  </select>
+
   <insert id="insertDept" parameterType="SysDept">
     insert into sys_dept(
     <if test="deptId != null and deptId != 0">dept_id,</if>