zqy
2025-06-22 ec4733f0c90a88f2266731d16c94e6e2fada7528
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
package com.ruoyi.web.controller.zhang;
 
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.poi.ExcelUtil;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfDoctor;
import com.ruoyi.domain.dto.MarryInfoDto;
import com.ruoyi.service.MarrySelfService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * @Author Jinquan_Ou
 * @Description
 * @Date 2023-08-07 21:26
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/marrySelf")
public class MarrySelfController {
    @Resource
    MarrySelfService marrySelfService;
 
    @Resource
    ZInfoUserService zInfoUserService;
 
    @Autowired
    private ISysUserService userService;
 
    //获取所有信息
    @GetMapping()
    public AjaxResult getInfo(){
        return marrySelfService.getInfo();
    }
 
    //新增或修改基本信息
    @PostMapping()
    public AjaxResult updateData(@RequestBody MarryInfoDto marryInfoDto){
        try{
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
 
        ZInfoUser infoBysysId = zInfoUserService.getInfoBysysId(userId);
        if(infoBysysId!=null) {
            ZInfoUser zInfoUser = new ZInfoUser();
            Long spouseId = infoBysysId.getSpouseId();
            zInfoUser.setUserId(spouseId);
            zInfoUser.setNickName(marryInfoDto.getSpouseName());
            if(!marryInfoDto.getSpouseSex().isEmpty()) zInfoUser.setSex(marryInfoDto.getSpouseSex().equals("男")?0:1);
            zInfoUser.setBirth(marryInfoDto.getSpouseBirthday());
            zInfoUser.setNation(marryInfoDto.getSpouseNation());
            zInfoUser.setIdNum(marryInfoDto.getSpouseIdNo());
            zInfoUser.setPhoneNumber(marryInfoDto.getSpousePhone());
            zInfoUser.setMaritalStatus(marryInfoDto.getSpouseMarryStatus());
            zInfoUser.setLocationAddress(marryInfoDto.getSpouseAddress());
            zInfoUserService.updateById(zInfoUser);
 
            ZInfoUser spouseBysysId = zInfoUserService.getInfoById(spouseId);
            if(spouseBysysId !=null) {
                Long spouseUId = spouseBysysId.getSysId();
                SysUser sysUser = new SysUser();
                sysUser.setUserId(spouseUId);
                sysUser.setNickName(marryInfoDto.getSpouseName());
                if (!marryInfoDto.getSpouseSex().isEmpty())
                    sysUser.setSex(marryInfoDto.getSpouseSex().equals("男") ? "0" : "1");
                userService.updateUser(sysUser);
            }
 
        }} catch (Exception e) {
            e.printStackTrace();
            System.out.println("报错"+e.getMessage());
            return AjaxResult.error("更新失败");
        }
        return AjaxResult.success( marrySelfService.updateData(marryInfoDto));
    }
 
    //导出
    @PostMapping("/export")
    public void export(HttpServletResponse response){
        MarryInfoDto data = (MarryInfoDto)marrySelfService.getInfo().get("data");
        List<MarryInfoDto> marryInfoDtos = new ArrayList<>();
        marryInfoDtos.add(data);
        ExcelUtil<MarryInfoDto> util = new ExcelUtil<>(MarryInfoDto.class);
        util.exportExcel(response, marryInfoDtos, "个人婚姻数据");
    }
}