Jinquan_Ou
2023-03-27 b6fd093def92b3a538932c6cb808c94fa6275fa1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ojq
 * @since 2023-03-14
 */
@Service
@Slf4j
public class ZInfoUserServiceImpl extends ServiceImpl<ZInfoUserMapper, ZInfoUser> implements ZInfoUserService {
 
    @Autowired
    private ZfRelationService zfRelationService;
 
    @Override
    public AjaxResult selectInfoList(ZInfoUser zInfoUser, Integer pageNum, Integer pageSize) {
 
        LambdaQueryWrapper<ZInfoUser> lqw = buildCondition(zInfoUser);
 
        Page<ZInfoUser> zInfoUserPage = new Page<>(pageNum,pageSize);
        Page<ZInfoUser> pageResult = page(zInfoUserPage, lqw);
 
        HashMap<String, Object> data = MapUtils.getResult(pageResult);
        return AjaxResult.success(data);
 
    }
 
    private LambdaQueryWrapper<ZInfoUser> buildCondition(ZInfoUser zInfoUser) {
 
        LambdaQueryWrapper<ZInfoUser> 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<ZInfoUser> selectByCondition(ZInfoUser zInfoUser) {
        LambdaQueryWrapper<ZInfoUser> lambdaQueryWrapper = buildCondition(zInfoUser);
        List<ZInfoUser> list = list(lambdaQueryWrapper);
        log.info("返回的数据为:{}",list);
        return list;
 
    }
 
    @Override
    public AjaxResult searchMyRelation(Long userId) {
 
        LambdaQueryWrapper<ZfRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfRelation::getMyId,userId);
        List<ZfRelation> relationList = zfRelationService.list(lqw);
 
        ArrayList<UserRelationDto> 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);
    }
}