package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfEvent;
import com.ruoyi.domain.ZfRelation;
import com.ruoyi.domain.dto.UserRelationDto;
import com.ruoyi.mapper.ZInfoUserMapper;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 服务实现类
*
*
* @author ojq
* @since 2023-03-14
*/
@Service
@Slf4j
public class ZInfoUserServiceImpl extends ServiceImpl implements ZInfoUserService {
@Autowired
private ZfRelationService zfRelationService;
@Override
public AjaxResult selectInfoList(ZInfoUser zInfoUser, Integer pageNum, Integer pageSize) {
LambdaQueryWrapper lqw = buildCondition(zInfoUser);
Page zInfoUserPage = new Page<>(pageNum,pageSize);
Page pageResult = page(zInfoUserPage, lqw);
HashMap data = MapUtils.getResult(pageResult);
return AjaxResult.success(data);
}
private LambdaQueryWrapper buildCondition(ZInfoUser zInfoUser) {
LambdaQueryWrapper lqw = new LambdaQueryWrapper<>();
lqw.eq(zInfoUser.getUserId()!=null,ZInfoUser::getUserId,zInfoUser.getUserId());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getAlwaysAddress()),ZInfoUser::getAlwaysAddress,zInfoUser.getAlwaysAddress());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getAlwaysPolice()),ZInfoUser::getAlwaysPolice,zInfoUser.getAlwaysPolice());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getIdNum()),ZInfoUser::getIdNum,zInfoUser.getIdNum());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getLocationAddress()),ZInfoUser::getLocationAddress,zInfoUser.getLocationAddress());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getLocationPolice()),ZInfoUser::getLocationPolice,zInfoUser.getLocationPolice());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getNation()),ZInfoUser::getNation,zInfoUser.getNation());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getNationality()),ZInfoUser::getNationality,zInfoUser.getNationality());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getNickName()),ZInfoUser::getNickName,zInfoUser.getNickName());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getOldName()),ZInfoUser::getOldName,zInfoUser.getOldName());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getPhoneNumber()),ZInfoUser::getPhoneNumber,zInfoUser.getPhoneNumber());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getPoliticalOutlook()),ZInfoUser::getPoliticalOutlook,zInfoUser.getPoliticalOutlook());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getPosition()),ZInfoUser::getPosition,zInfoUser.getPosition());
lqw.like(StringUtils.isNotEmpty(zInfoUser.getUnit()),ZInfoUser::getUnit,zInfoUser.getUnit());
lqw.like(zInfoUser.getSex()!=null,ZInfoUser::getSex,zInfoUser.getSex());
lqw.like(zInfoUser.getMaritalStatus()!=null,ZInfoUser::getMaritalStatus,zInfoUser.getMaritalStatus());
lqw.like(zInfoUser.getBirth()!=null,ZInfoUser::getBirth,zInfoUser.getBirth());
return lqw;
}
@Override
public List selectByCondition(ZInfoUser zInfoUser) {
LambdaQueryWrapper lambdaQueryWrapper = buildCondition(zInfoUser);
List list = list(lambdaQueryWrapper);
log.info("返回的数据为:{}",list);
return list;
}
@Override
public AjaxResult searchMyRelation(Long userId) {
LambdaQueryWrapper lqw = new LambdaQueryWrapper<>();
lqw.eq(ZfRelation::getMyId,userId);
List relationList = zfRelationService.list(lqw);
ArrayList otherUserList = new ArrayList<>();
relationList.stream().map(
(relation)->{
Long otherId = relation.getOtherId();
ZInfoUser otherUser = getById(otherId);
UserRelationDto userRelationDto = new UserRelationDto();
BeanUtils.copyProperties(otherUser,userRelationDto);
userRelationDto.setRelation(relation.getRelation());
otherUserList.add(userRelationDto);
return relation;
}
).collect(Collectors.toList());
return AjaxResult.success(otherUserList);
}
}