PersonInfoServiceImpl.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.ruoyi.web.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.ruoyi.common.utils.bean.BeanUtils;
  9. import com.ruoyi.web.domain.dto.person.PersonInfoQueryRequest;
  10. import com.ruoyi.web.domain.entity.PersonInfo;
  11. import com.ruoyi.web.mapper.PersonInfoMapper;
  12. import com.ruoyi.web.service.PersonInfoService;
  13. import com.ruoyi.web.domain.vo.PersonInfoVO;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.stream.Collectors;
  19. /**
  20. *
  21. */
  22. @Service
  23. public class PersonInfoServiceImpl extends ServiceImpl<PersonInfoMapper, PersonInfo>
  24. implements PersonInfoService {
  25. /**
  26. * 查询人员信息列表
  27. * @param personInfoQueryRequest
  28. * @return
  29. */
  30. @Override
  31. public List<PersonInfoVO> getPersonInfo(PersonInfoQueryRequest personInfoQueryRequest) {
  32. PersonInfo personInfoQuery = new PersonInfo();
  33. if (personInfoQueryRequest != null) {
  34. BeanUtils.copyProperties(personInfoQueryRequest, personInfoQuery);
  35. }
  36. QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>(personInfoQuery);
  37. List<PersonInfo> personInfoList = this.list(queryWrapper);
  38. return personInfoList.stream().map(personInfo -> {
  39. PersonInfoVO personInfoVO = new PersonInfoVO();
  40. BeanUtils.copyProperties(personInfo, personInfoVO);
  41. return personInfoVO;
  42. }).collect(Collectors.toList());
  43. }
  44. /**
  45. * 分页获取人员列表
  46. * @param personInfoQueryRequest
  47. * @return
  48. */
  49. @Override
  50. public Page<PersonInfo> getListPersonInfoByPage(PersonInfoQueryRequest personInfoQueryRequest) {
  51. long current = personInfoQueryRequest.getCurrent();
  52. long size = personInfoQueryRequest.getPageSize();
  53. return this.page(new Page<>(current, size),
  54. getQueryWrapper(personInfoQueryRequest));
  55. }
  56. /**
  57. * 获取查询条件
  58. *
  59. * @param personInfoQueryRequest
  60. * @return
  61. */
  62. @Override
  63. public QueryWrapper<PersonInfo> getQueryWrapper(PersonInfoQueryRequest personInfoQueryRequest) {
  64. QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>();
  65. if (personInfoQueryRequest == null) {
  66. return queryWrapper;
  67. }
  68. // 从对象中取值
  69. Integer id = personInfoQueryRequest.getId();
  70. String realname = personInfoQueryRequest.getRealname();
  71. String idCard = personInfoQueryRequest.getIdCard();
  72. String ethnic = personInfoQueryRequest.getEthnic();
  73. Integer age = personInfoQueryRequest.getAge();
  74. Integer gender = personInfoQueryRequest.getGender();
  75. Date birthDate = personInfoQueryRequest.getBirthDate();
  76. Integer populationCategory = personInfoQueryRequest.getPopulationCategory();
  77. String phone = personInfoQueryRequest.getPhone();
  78. List<String> populationTags = personInfoQueryRequest.getPopulationTags();
  79. String occupationId = personInfoQueryRequest.getOccupationId();
  80. Integer villageId = personInfoQueryRequest.getVillageId();
  81. String specialIdentityCode = personInfoQueryRequest.getSpecialIdentityCode();
  82. String specialIdentity = personInfoQueryRequest.getSpecialIdentity();
  83. String sortField = personInfoQueryRequest.getSortField();
  84. String sortOrder = personInfoQueryRequest.getSortOrder();
  85. // 姓名、民族、房屋门牌号、特殊身份、人口标签
  86. queryWrapper.eq(ObjectUtil.isNotEmpty(id), "id", id);
  87. queryWrapper.eq(StrUtil.isNotBlank(realname), "realname", realname);
  88. queryWrapper.eq(StrUtil.isNotBlank(idCard), "id_card", idCard);
  89. queryWrapper.eq(StrUtil.isNotBlank(ethnic), "ethnic", ethnic);
  90. queryWrapper.eq(ObjectUtil.isNotEmpty(age), "age", age);
  91. queryWrapper.eq(ObjectUtil.isNotEmpty(gender), "gender", gender);
  92. queryWrapper.eq(ObjectUtil.isNotEmpty(populationCategory), "population_category", populationCategory);
  93. queryWrapper.eq(StrUtil.isNotBlank(phone), "phone", phone);
  94. queryWrapper.eq(StrUtil.isNotBlank(occupationId), "occupation_id", occupationId);
  95. queryWrapper.eq(StrUtil.isNotBlank(specialIdentity), "special_identity", specialIdentity);
  96. // 人口标签 JSON 数组查询
  97. if(CollUtil.isNotEmpty(populationTags)){
  98. for (String tag : populationTags) {
  99. queryWrapper.like("population_tags", "\"" + tag + "\"");
  100. }
  101. }
  102. // 排序
  103. queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
  104. return queryWrapper;
  105. }
  106. }