123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package com.ruoyi.web.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ruoyi.common.utils.bean.BeanUtils;
- import com.ruoyi.web.domain.dto.person.PersonInfoQueryRequest;
- import com.ruoyi.web.domain.entity.PersonInfo;
- import com.ruoyi.web.mapper.PersonInfoMapper;
- import com.ruoyi.web.service.PersonInfoService;
- import com.ruoyi.web.domain.vo.PersonInfoVO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- *
- */
- @Service
- public class PersonInfoServiceImpl extends ServiceImpl<PersonInfoMapper, PersonInfo>
- implements PersonInfoService {
- /**
- * 查询人员信息列表
- * @param personInfoQueryRequest
- * @return
- */
- @Override
- public List<PersonInfoVO> getPersonInfo(PersonInfoQueryRequest personInfoQueryRequest) {
- PersonInfo personInfoQuery = new PersonInfo();
- if (personInfoQueryRequest != null) {
- BeanUtils.copyProperties(personInfoQueryRequest, personInfoQuery);
- }
- QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>(personInfoQuery);
- List<PersonInfo> personInfoList = this.list(queryWrapper);
- return personInfoList.stream().map(personInfo -> {
- PersonInfoVO personInfoVO = new PersonInfoVO();
- BeanUtils.copyProperties(personInfo, personInfoVO);
- return personInfoVO;
- }).collect(Collectors.toList());
- }
- /**
- * 分页获取人员列表
- * @param personInfoQueryRequest
- * @return
- */
- @Override
- public Page<PersonInfo> getListPersonInfoByPage(PersonInfoQueryRequest personInfoQueryRequest) {
- long current = personInfoQueryRequest.getCurrent();
- long size = personInfoQueryRequest.getPageSize();
- return this.page(new Page<>(current, size),
- getQueryWrapper(personInfoQueryRequest));
- }
- /**
- * 获取查询条件
- *
- * @param personInfoQueryRequest
- * @return
- */
- @Override
- public QueryWrapper<PersonInfo> getQueryWrapper(PersonInfoQueryRequest personInfoQueryRequest) {
- QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>();
- if (personInfoQueryRequest == null) {
- return queryWrapper;
- }
- // 从对象中取值
- Integer id = personInfoQueryRequest.getId();
- String realname = personInfoQueryRequest.getRealname();
- String idCard = personInfoQueryRequest.getIdCard();
- String ethnic = personInfoQueryRequest.getEthnic();
- Integer age = personInfoQueryRequest.getAge();
- Integer gender = personInfoQueryRequest.getGender();
- Date birthDate = personInfoQueryRequest.getBirthDate();
- Integer populationCategory = personInfoQueryRequest.getPopulationCategory();
- String phone = personInfoQueryRequest.getPhone();
- List<String> populationTags = personInfoQueryRequest.getPopulationTags();
- String occupationId = personInfoQueryRequest.getOccupationId();
- Integer villageId = personInfoQueryRequest.getVillageId();
- String specialIdentityCode = personInfoQueryRequest.getSpecialIdentityCode();
- String specialIdentity = personInfoQueryRequest.getSpecialIdentity();
- String sortField = personInfoQueryRequest.getSortField();
- String sortOrder = personInfoQueryRequest.getSortOrder();
- // 姓名、民族、房屋门牌号、特殊身份、人口标签
- queryWrapper.eq(ObjectUtil.isNotEmpty(id), "id", id);
- queryWrapper.eq(StrUtil.isNotBlank(realname), "realname", realname);
- queryWrapper.eq(StrUtil.isNotBlank(idCard), "id_card", idCard);
- queryWrapper.eq(StrUtil.isNotBlank(ethnic), "ethnic", ethnic);
- queryWrapper.eq(ObjectUtil.isNotEmpty(age), "age", age);
- queryWrapper.eq(ObjectUtil.isNotEmpty(gender), "gender", gender);
- queryWrapper.eq(ObjectUtil.isNotEmpty(populationCategory), "population_category", populationCategory);
- queryWrapper.eq(StrUtil.isNotBlank(phone), "phone", phone);
- queryWrapper.eq(StrUtil.isNotBlank(occupationId), "occupation_id", occupationId);
- queryWrapper.eq(StrUtil.isNotBlank(specialIdentity), "special_identity", specialIdentity);
- // 人口标签 JSON 数组查询
- if(CollUtil.isNotEmpty(populationTags)){
- for (String tag : populationTags) {
- queryWrapper.like("population_tags", "\"" + tag + "\"");
- }
- }
- // 排序
- queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
- return queryWrapper;
- }
- }
|