feige
2025-07-08 f1831ec9329d0fb5e424b35064ca8e5f05a7920a
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
113
114
115
116
117
118
119
120
121
122
package com.ruoyi.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.domain.MarrySelf;
import com.ruoyi.domain.MarryUser;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZSelfNote;
import com.ruoyi.domain.dto.MarryInfoDto;
import com.ruoyi.domain.dto.MarryUserDto;
import com.ruoyi.mapper.MarrySelfMapper;
import com.ruoyi.service.MarrySelfService;
import com.ruoyi.service.MarryUserService;
import com.ruoyi.service.ZInfoUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @Author Jinquan_Ou
 * @Description
 * @Date 2023-08-07 21:25
 * @Version 1.0.0
 **/
@Service
public class MarrySelfServiceImpl extends ServiceImpl<MarrySelfMapper, MarrySelf> implements MarrySelfService {
 
    @Resource
    MarryUserService marryUserService;
 
    @Resource
    ZInfoUserService zInfoUserService;
 
//    @Resource
//    MarrySelfService marrySelfService;
 
 
 
    @Override
    public AjaxResult getInfo() {
 
        //先查询自己的信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
 
        LambdaQueryWrapper<MarrySelf> marrySelfLQW = new LambdaQueryWrapper<>();
        marrySelfLQW.eq(MarrySelf::getUid,userId);
        MarrySelf myself = getOne(marrySelfLQW);
 
        if(myself == null){
            throw new RuntimeException("请先编辑信息");
        }
 
        //再查询前任的信息
        LambdaQueryWrapper<MarryUser> marryUserLQW = new LambdaQueryWrapper<>();
 
 
        //根据userId查询到infouser的uaid
        ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId);
        //拿到所有的sysid
        List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList());
 
 
        marryUserLQW.in(MarryUser::getUid, fms);
      //  marryUserLQW.eq(MarryUser::getUid,userId);
        List<MarryUser> spouseList = marryUserService.list(marryUserLQW);
        List<MarryUserDto> frontList = spouseList.stream().map(s -> {
            System.out.println(s);
            MarryUserDto marryUserDto = new MarryUserDto();
            BeanUtils.copyProperties(s, marryUserDto);
            return marryUserDto;
        }).collect(Collectors.toList());
        System.out.println("++++++++++++----------------");
        System.out.println(frontList);
        //最终返回数据模型
        MarryInfoDto result = new MarryInfoDto();
        BeanUtils.copyProperties(myself,result);
        result.setOldSpouseList(frontList);
 
        return AjaxResult.success(result);
    }
 
    @Override
    public Boolean updateData(MarryInfoDto marryInfoDto) {
 
//        SysUser user = SecurityUtils.getLoginUser().getUser();
//        Long userId = user.getUserId();
 
        MarrySelf marrySelf = new MarrySelf();
        BeanUtils.copyProperties(marryInfoDto,marrySelf);
        marrySelf.setUid(marryInfoDto.getUid());
 
        //先查询数据库中有没有本用户的数据
        LambdaQueryWrapper<MarrySelf> lqw = new LambdaQueryWrapper<>();
        lqw.eq(MarrySelf::getUid,marryInfoDto.getUid());
        List<MarrySelf> list = list(lqw);
 
 
        if(list.isEmpty()){
            //如果是空的,那就是新增
            save(marrySelf);
 
        }else {
 
            //否则就是修改
            marrySelf.setId(list.get(0).getId());
            updateById(marrySelf);
        }
 
 
 
 
        return true;
    }
}