Browse Source

部门 用户信息返回部门名称

Reiskuchen 5 years ago
parent
commit
53a13bed4a

+ 19 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/UserMapper.java

@@ -1,16 +1,33 @@
 package com.management.platform.mapper;
 
-import com.management.platform.entity.User;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.management.platform.entity.User;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
- *  Mapper 接口
+ * Mapper 接口
  * </p>
  *
  * @author 吴涛涛
  * @since 2019-12-31
  */
 public interface UserMapper extends BaseMapper<User> {
+    List<Map<String, Object>> getUserByDepartment(Page page,
+                                                  @Param("companyId") Integer companyId,
+                                                  @Param("departmentId") Integer departmentId);
+
+    Integer countUserByDepartment(@Param("companyId") Integer companyId,
+                                  @Param("departmentId") Integer departmentId);
+
+    List<Map<String, Object>> getUserByDepartmentList(Page page,
+                                                      @Param("companyId") Integer companyId,
+                                                      @Param("departmentIds") List departmentIds);
 
+    Integer countUserByDepartmentList(@Param("companyId") Integer companyId,
+                                      @Param("departmentIds") List departmentIds);
 }

+ 5 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DepartmentServiceImpl.java

@@ -191,11 +191,13 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
                     List<DepartmentVO> targetList = new ArrayList<>();
                     //有父部门的话 那么下方很可能也是相同的父部门 所以要把类似的它们存入最终栈中
                     targetList.add(first);
-                    //首先把副栈中所有相同父部门的部门存入最终栈
-                    while (stack2.peek().getParentId() != null && stack2.peek().getParentId().equals(superiorId)) {
+                    //把副栈中所有相同父部门的部门存入最终栈
+                    while (!stack2.isEmpty() &&
+                            stack2.peek().getParentId() != null &&
+                            stack2.peek().getParentId().equals(superiorId)) {
                         targetList.add(stack2.pop());
                     }
-                    //首先把主栈中所有相同父部门的部门存入最终栈
+                    //把主栈中所有相同父部门的部门存入最终栈
                     while (stack1.peek().getParentId() != null && stack1.peek().getParentId().equals(superiorId)) {
                         targetList.add(stack1.pop());
                     }

+ 21 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -30,7 +30,9 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -184,13 +186,26 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         try {
 //            Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
             Integer companyId = 6;
-            QueryWrapper<User> queryWrapper = new QueryWrapper<User>().eq("company_id", companyId);
-            if (departmentId == 0) {
-                queryWrapper.eq("department_id", departmentId);
-            } else if (departmentId != -1) {
-                queryWrapper.in("department_id", getBranchDepartment(departmentId, companyId));
+            Integer total = 0;
+            List<Map<String, Object>> list = new ArrayList<>();
+            Page<User> page = new Page<>(pageIndex, pageSize);
+            if (departmentId == -1) {
+                //单独查找全部
+                list = userMapper.getUserByDepartment(page, companyId, null);
+                total = userMapper.countUserByDepartment(companyId, null);
+            } else if (departmentId == 0) {
+                //单独查找0
+                list = userMapper.getUserByDepartment(page, companyId, departmentId);
+                total = userMapper.countUserByDepartment(companyId, departmentId);
+            } else {
+                //范围查找
+                list = userMapper.getUserByDepartmentList(page, companyId, getBranchDepartment(departmentId, companyId));
+                total = userMapper.countUserByDepartmentList(companyId, getBranchDepartment(departmentId, companyId));
             }
-            httpRespMsg.data = userMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
+            Map<String, Object> resultMap = new HashMap<>();
+            resultMap.put("records", list);
+            resultMap.put("total", total);
+            httpRespMsg.data = resultMap;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
             return httpRespMsg;

+ 53 - 10
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/UserMapper.xml

@@ -4,16 +4,16 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.management.platform.entity.User">
-        <id column="id" property="id" />
-        <result column="name" property="name" />
-        <result column="phone" property="phone" />
-        <result column="password" property="password" />
-        <result column="portrait_url" property="portraitUrl" />
-        <result column="create_time" property="createTime" />
-        <result column="role" property="role" />
-        <result column="company_id" property="companyId" />
-        <result column="cost" property="cost" />
-        <result column="department_id" property="departmentId" />
+        <id column="id" property="id"/>
+        <result column="name" property="name"/>
+        <result column="phone" property="phone"/>
+        <result column="password" property="password"/>
+        <result column="portrait_url" property="portraitUrl"/>
+        <result column="create_time" property="createTime"/>
+        <result column="role" property="role"/>
+        <result column="company_id" property="companyId"/>
+        <result column="cost" property="cost"/>
+        <result column="department_id" property="departmentId"/>
     </resultMap>
 
     <!-- 通用查询结果列 -->
@@ -21,4 +21,47 @@
         id, name, phone, password, portrait_url, create_time, role, company_id, cost, department_id
     </sql>
 
+    <!--单独分页获取人员-->
+    <select id="getUserByDepartment" resultType="java.util.Map">
+        SELECT a.id, a.name, a.phone, a.portrait_url AS portraitUrl, a.role, a.company_id AS companyId, a.cost,
+        a.department_id AS departmentId, b.department_name AS departmentName
+        FROM user AS a
+        LEFT JOIN department AS b ON a.department_id = b.department_id
+        WHERE a.company_id = #{companyId}
+        <if test="departmentId != null and companyId != ''">
+            AND a.department_id = #{departmentId}
+        </if>
+    </select>
+
+    <!--单独分页获取人员数量-->
+    <select id="countUserByDepartment" resultType="java.lang.Integer">
+        SELECT COUNT(a.id) AS count
+        FROM user AS a
+        WHERE a.company_id = #{companyId}
+        <if test="departmentId != null and companyId != ''">
+            AND a.department_id = #{departmentId}
+        </if>
+    </select>
+
+    <!--范围分页获取人员-->
+    <select id="getUserByDepartmentList" resultType="java.util.Map">
+        SELECT a.id, a.name, a.phone, a.portrait_url AS portraitUrl, a.role, a.company_id AS companyId, a.cost,
+        a.department_id AS departmentId, b.department_name AS departmentName
+        FROM user AS a
+        LEFT JOIN department AS b ON a.department_id = b.department_id
+        WHERE a.company_id = #{companyId} AND a.department_id IN
+        <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
+            #{departmentId}
+        </foreach>
+    </select>
+
+    <!--范围分页获取人员数量-->
+    <select id="countUserByDepartmentList" resultType="java.lang.Integer">
+        SELECT COUNT(a.id) AS count
+        FROM user AS a
+        WHERE a.company_id = #{companyId} AND a.department_id IN
+        <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
+            #{departmentId}
+        </foreach>
+    </select>
 </mapper>