소스 검색

-优化sql

jiangbiao 2 년 전
부모
커밋
cb465acaa8

+ 43 - 37
master/src/main/java/com/ruoyi/project/production/service/impl/TSaiApplyServiceImpl.java

@@ -1,32 +1,26 @@
 package com.ruoyi.project.production.service.impl;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.framework.security.service.TokenService;
 import com.ruoyi.project.production.controller.vo.SaiApplyQueryVO;
-import com.ruoyi.project.system.domain.*;
+import com.ruoyi.project.production.domain.TSaiApply;
+import com.ruoyi.project.production.mapper.TSaiApplyMapper;
+import com.ruoyi.project.production.service.ITSaiApplyService;
+import com.ruoyi.project.system.domain.SysDictData;
+import com.ruoyi.project.system.domain.SysRole;
+import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
-import com.ruoyi.project.system.mapper.SysRoleMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.project.system.mapper.SysUserRoleMapper;
 import com.ruoyi.project.system.service.ISysDictTypeService;
-import com.ruoyi.project.system.service.ISysRoleService;
 import com.ruoyi.project.system.service.ISysUserService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.ruoyi.project.production.mapper.TSaiApplyMapper;
-import com.ruoyi.project.production.domain.TSaiApply;
-import com.ruoyi.project.production.service.ITSaiApplyService;
 
 import javax.annotation.Resource;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.Size;
+import java.util.List;
 
 /**
  * SAI开项管理Service业务层处理
@@ -81,11 +75,11 @@ public class TSaiApplyServiceImpl implements ITSaiApplyService
     public List<TSaiApply> selectTSaiApplyList(SaiApplyQueryVO tSaiApply)
     {
         List<TSaiApply> tSaiApplies = tSaiApplyMapper.selectTSaiApplyList(tSaiApply);
-        List<SysUser> userList = userService.selectUserList(new SysUser());
-        Map<Long, String> nameMap = new HashMap<Long, String>();
-        for (SysUser sysUser : userList) {
-            nameMap.put(sysUser.getUserId(), sysUser.getNickName());
-        }
+//        List<SysUser> userList = userService.selectUserList(new SysUser());
+//        Map<Long, String> nameMap = new HashMap<Long, String>();
+//        for (SysUser sysUser : userList) {
+//            nameMap.put(sysUser.getUserId(), sysUser.getNickName());
+//        }
 
         List<SysDictData> staffUnitDict = iSysDictTypeService.selectDictDataByType("STAFF_UNIT");
         for (TSaiApply saiApply : tSaiApplies) {
@@ -102,47 +96,59 @@ public class TSaiApplyServiceImpl implements ITSaiApplyService
             }
             if (applicant != null) {
 //                saiApply.setApplicantName(sysUserMapper.selectUserById(Long.parseLong(applicant)).getNickName());
-                String applicantName = nameMap.get(Long.parseLong(applicant));
-                if (applicantName != null && !"null".equals(applicantName)) {
-                    saiApply.setApplicantName(applicantName);
+                SysUser sysUser = sysUserMapper.selectNickNameById(Long.parseLong(applicant));
+                if (sysUser!=null) {
+                    String applicantName = sysUser.getNickName();
+                    if (applicantName != null && !"null".equals(applicantName)) {
+                        saiApply.setApplicantName(applicantName);
+                    }
                 }
             }
             if (handler != null) {
-                if (handler.indexOf(",") != -1) {
+                if (handler.contains(",")) {
                     String[] split = handler.split(",");
-                    String handlerName = "";
+                    StringBuilder handlerName = new StringBuilder();
                     for (int i = 0; i < split.length; i++) {
 //                        handlerName += sysUserMapper.selectUserById(Long.parseLong(split[i])).getNickName();
-                        String name = nameMap.get(Long.parseLong(split[i]));
-                        if (name != null && !"null".equals(name)) {
-                            handlerName += name;
-                            if (i < split.length - 1) {
-                                handlerName += ",";
+                        SysUser sysUser = sysUserMapper.selectNickNameById(Long.parseLong(split[i]));
+                        if (sysUser!=null) {
+                            String name = sysUser.getNickName();
+                            if (name != null && !"null".equals(name)) {
+                                handlerName.append(name);
+                                if (i < split.length - 1) {
+                                    handlerName.append(",");
+                                }
                             }
                         }
                     }
-                    saiApply.setHandlerName(handlerName);
+                    saiApply.setHandlerName(handlerName.toString());
                 } else {
 //                    saiApply.setHandlerName(sysUserMapper.selectUserById(Long.parseLong(handler)).getNickName());
-                    String handlerName = nameMap.get(Long.parseLong(handler));
-                    if (handlerName != null && !"null".equals(handlerName)) {
-                        saiApply.setHandlerName(handlerName);
+                    SysUser sysUser = sysUserMapper.selectNickNameById(Long.parseLong(handler));
+                    if (sysUser!=null) {
+                        String handlerName = sysUser.getNickName();
+                        if (handlerName != null && !"null".equals(handlerName)) {
+                            saiApply.setHandlerName(handlerName);
+                        }
                     }
                 }
             }
             if (executor != null) {
 //                saiApply.setExecutorName(sysUserMapper.selectUserById(Long.parseLong(executor)).getNickName());
-                String executorName = nameMap.get(Long.parseLong(executor));
-                if (executorName != null && !"null".equals(executorName)) {
-                    saiApply.setExecutorName(executorName);
+                SysUser sysUser = sysUserMapper.selectNickNameById(Long.parseLong(executor));
+                if (sysUser!=null) {
+                    String executorName = sysUser.getNickName();
+                    if (executorName != null && !"null".equals(executorName)) {
+                        saiApply.setExecutorName(executorName);
+                    }
                 }
             }
         }
         boolean specialRole = this.isSpecialRole();
         if (specialRole) {  // 当前登录用户是特殊角色
             for (TSaiApply saiApply : tSaiApplies) {
-                Long applyStatus = saiApply.getApplyStatus();
-                if (applyStatus.toString().equals("5")) {   // 申请状态为“已取消”的数据
+                long applyStatus = saiApply.getApplyStatus();
+                if (Long.toString(applyStatus).equals("5")) {   // 申请状态为“已取消”的数据
                     tSaiApplies.remove(saiApply);   // 从列表中移除
                 }
             }

+ 2 - 0
master/src/main/java/com/ruoyi/project/system/mapper/SysUserMapper.java

@@ -56,6 +56,8 @@ public interface SysUserMapper
      */
     public SysUser selectUserById(Long userId);
 
+    public SysUser selectNickNameById(Long userId);
+
     /**
      * 通过staffid查询用户
      *

+ 5 - 0
master/src/main/resources/mybatis/system/SysUserMapper.xml

@@ -239,6 +239,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		where u.user_id = #{userId}
 	</select>
 
+	<select id="selectNickNameById" parameterType="Long" resultMap="SysUserResult">
+		select u.nick_name from SYS_USER u
+		where u.user_id = #{userId}
+	</select>
+
 	<select id="selectUserByStaffId" parameterType="String" resultMap="SysUserResult">
 		<include refid="selectUserVo"/>
 		where u.staffid = #{staffid}