Browse Source

修复根据姓名或用户名查询人员列表的bug

lixing 4 years ago
parent
commit
95d31c6400

+ 20 - 0
fm-person/src/main/java/com/persagy/fm/person/dao/PersonMapper.java

@@ -40,6 +40,26 @@ public interface PersonMapper extends BaseMapper<Person> {
     int queryCount(PageQueryPersonDTO pageQueryPersonDTO);
     int queryCount(PageQueryPersonDTO pageQueryPersonDTO);
 
 
     /**
     /**
+     * 根据人员姓名或用户名查询人员列表
+     *
+     * @param pageQueryPersonDTO 分页查询条件
+     * @return 人员列表
+     * @author lixing
+     * @version V1.0 2021/4/14 5:53 下午
+     */
+    List<Person> queryPersonListByNameOrUserName(PageQueryPersonByNameOrUserNameDTO pageQueryPersonDTO);
+
+    /**
+     * 根据人员姓名或用户名查询人员数量
+     *
+     * @param pageQueryPersonDTO 分页查询条件
+     * @return 人员列表
+     * @author lixing
+     * @version V1.0 2021/4/14 5:53 下午
+     */
+    int queryCountByNameOrUserName(PageQueryPersonByNameOrUserNameDTO pageQueryPersonDTO);
+
+    /**
      * 快速查询人员姓名
      * 快速查询人员姓名
      *
      *
      * @param nameQuickSearchDTO 快速查询人员姓名入参
      * @param nameQuickSearchDTO 快速查询人员姓名入参

+ 35 - 12
fm-person/src/main/java/com/persagy/fm/person/service/impl/PersonServiceImpl.java

@@ -12,7 +12,6 @@ import com.persagy.fm.common.model.vo.SimpleObjVO;
 import com.persagy.fm.common.utils.ListUtil;
 import com.persagy.fm.common.utils.ListUtil;
 import com.persagy.fm.department.model.vo.DepSimpleObjVO;
 import com.persagy.fm.department.model.vo.DepSimpleObjVO;
 import com.persagy.fm.department.service.IDepartmentService;
 import com.persagy.fm.department.service.IDepartmentService;
-import com.persagy.fm.depproject.model.DepProject;
 import com.persagy.fm.person.dao.PersonMapper;
 import com.persagy.fm.person.dao.PersonMapper;
 import com.persagy.fm.person.model.ConvertPersonTool;
 import com.persagy.fm.person.model.ConvertPersonTool;
 import com.persagy.fm.person.model.Person;
 import com.persagy.fm.person.model.Person;
@@ -834,9 +833,10 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
      * @author lixing
      * @author lixing
      * @version V1.0 2021/4/14 5:51 下午
      * @version V1.0 2021/4/14 5:51 下午
      */
      */
-    private IPage<ResponsePersonListItemVO> packagePageResult(List<Person> people, int total){
+    private IPage<ResponsePersonListItemVO> packagePageResult(List<Person> people, int total) {
         return packagePageResult(people, total, null);
         return packagePageResult(people, total, null);
     }
     }
+
     /**
     /**
      * 组装分页查询结果
      * 组装分页查询结果
      *
      *
@@ -848,6 +848,23 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
      * @version V1.0 2021/4/14 5:51 下午
      * @version V1.0 2021/4/14 5:51 下午
      */
      */
     private IPage<ResponsePersonListItemVO> packagePageResult(List<Person> people, int total, String depId) {
     private IPage<ResponsePersonListItemVO> packagePageResult(List<Person> people, int total, String depId) {
+        return packagePageResult(people, total, depId, null, null);
+    }
+
+    /**
+     * 组装分页查询结果
+     *
+     * @param people      人员列表(单页)
+     * @param total       人员总数量
+     * @param depId       部门id,如果不根据部门id查询这里传null
+     * @param hiredState  在职状态,如果不为空,只返回人员对应在职状态的工作信息
+     * @param enableState 禁用状态,如果不为空,只返回人员对应禁用状态的工作信息
+     * @return 分页结果
+     * @author lixing
+     * @version V1.0 2021/4/14 5:51 下午
+     */
+    private IPage<ResponsePersonListItemVO> packagePageResult(
+            List<Person> people, int total, String depId, String hiredState, String enableState) {
         List<String> accountIds = people.stream().map(Person::getAccountId).collect(Collectors.toList());
         List<String> accountIds = people.stream().map(Person::getAccountId).collect(Collectors.toList());
         Map<String, AccountRoleVO> accountRoleVoMap = saasAccountRoleService.
         Map<String, AccountRoleVO> accountRoleVoMap = saasAccountRoleService.
                 queryAccountRoleVoMapByAccountIdList(accountIds);
                 queryAccountRoleVoMapByAccountIdList(accountIds);
@@ -886,9 +903,16 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
             // 设置所属部门
             // 设置所属部门
             List<WorkResume> workResumes = workResumeService.queryWorkResumeListByPersonIdList(
             List<WorkResume> workResumes = workResumeService.queryWorkResumeListByPersonIdList(
                     Lists.newArrayList(responsePersonListItem.getId()));
                     Lists.newArrayList(responsePersonListItem.getId()));
+            workResumes = workResumes.stream().
+                    filter(workResume -> StringUtils.isBlank(hiredState)
+                            || hiredState.equals(workResume.getHiredState())).
+                    filter(workResume -> StringUtils.isBlank(enableState)
+                            || enableState.equals(workResume.getEnableState())).
+                    collect(Collectors.toList());
             if (StringUtils.isNotBlank(depId)) {
             if (StringUtils.isNotBlank(depId)) {
-                List<WorkResume> currentWorkResumes = workResumes.stream().filter(workResume -> depId.equals(workResume.getDepId())
-                        && responsePersonListItem.getId().equals(workResume.getPersonId())).
+                List<WorkResume> currentWorkResumes = workResumes.stream().
+                        filter(workResume -> depId.equals(workResume.getDepId())
+                                && responsePersonListItem.getId().equals(workResume.getPersonId())).
                         collect(Collectors.toList());
                         collect(Collectors.toList());
                 if (!CollectionUtils.isEmpty(currentWorkResumes)) {
                 if (!CollectionUtils.isEmpty(currentWorkResumes)) {
                     WorkResume currentWorkResume = currentWorkResumes.get(0);
                     WorkResume currentWorkResume = currentWorkResumes.get(0);
@@ -1290,14 +1314,13 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
 
 
     @Override
     @Override
     public IPage<ResponsePersonListItemVO> pageQueryByNameOrUserName(PageQueryPersonByNameOrUserNameDTO pageQueryPersonDTO) {
     public IPage<ResponsePersonListItemVO> pageQueryByNameOrUserName(PageQueryPersonByNameOrUserNameDTO pageQueryPersonDTO) {
-        QueryWrapper<Person> queryWrapper = getDefaultPersonQueryWrapper();
-        queryWrapper.like(Person.PROP_USERNAME, pageQueryPersonDTO.getName()).or(
-                wrapper -> wrapper.like(Person.PROP_NAME, pageQueryPersonDTO.getName())
-        );
-        IPage<Person> pageParam = new Page<>(pageQueryPersonDTO.getPage(), pageQueryPersonDTO.getSize(),true);
-        IPage<Person> result = getBaseMapper().selectPage(pageParam, queryWrapper);
-
-        return packagePageResult(result.getRecords(), Integer.parseInt(String.valueOf(result.getTotal())));
+        List<Person> people = personMapper.queryPersonListByNameOrUserName(pageQueryPersonDTO);
+        int total = personMapper.queryCountByNameOrUserName(pageQueryPersonDTO);
+        String hiredState = pageQueryPersonDTO.getHiredState() == null ?
+                "" : pageQueryPersonDTO.getHiredState().toString();
+        String enableState = pageQueryPersonDTO.getEnableState() == null ?
+                "" : pageQueryPersonDTO.getEnableState().toString();
+        return packagePageResult(people, total, null, hiredState, enableState);
     }
     }
 
 
     @Override
     @Override

+ 30 - 0
fm-person/src/main/resources/mapper/PersonMapper.xml

@@ -79,6 +79,36 @@
         p.name_pinyin
         p.name_pinyin
     </sql>
     </sql>
 
 
+    <sql id="queryPersonListByNameOrUserName">
+        select max(pw.id) as id,
+        pw.name as name,
+        pw.profession as profession,
+        pw.account_id as account_id,
+        pw.person_type as
+        person_type,
+        pw.username as username from (
+        <include refid="selectPersonInfo"/>
+        <include refid="queryPersonByNameOrUsernameExpression"/>
+        <include refid="orderBy"/>) as pw group by pw.id
+    </sql>
+
+    <select id="queryPersonListByNameOrUserName"
+            parameterType="com.persagy.fm.person.model.dto.PageQueryPersonByNameOrUserNameDTO"
+            resultType="com.persagy.fm.person.model.Person">
+        <include refid="queryPersonListByNameOrUserName"/>
+        limit #{startIndex}, #{size}
+    </select>
+
+    <select id="queryCountByNameOrUserName"
+            parameterType="com.persagy.fm.person.model.dto.PageQueryPersonByNameOrUserNameDTO"
+            resultType="int">
+        select count(*) total
+        from (
+        <include refid="queryPersonListByNameOrUserName"/>
+        ) tmp
+    </select>
+
+
     <select id="queryPersonList" parameterType="com.persagy.fm.person.model.dto.PageQueryPersonDTO"
     <select id="queryPersonList" parameterType="com.persagy.fm.person.model.dto.PageQueryPersonDTO"
             resultType="com.persagy.fm.person.model.Person">
             resultType="com.persagy.fm.person.model.Person">
         <include refid="selectPersonInfo"/>
         <include refid="selectPersonInfo"/>