feige
2024-10-27 bc74ffaaa0074a96d7e7e60838845d020f94f347
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
package com.ruoyi.service.impl;
 
import com.alibaba.fastjson2.JSON;
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.ZHealthNow;
import com.ruoyi.domain.ZHealthNow;
import com.ruoyi.domain.dto.ZHealthNowDto;
import com.ruoyi.domain.dto.ZHealthNowDto;
import com.ruoyi.domain.health.*;
import com.ruoyi.mapper.ZHealthNowMapper;
import com.ruoyi.service.ZHealthNowService;
import org.springframework.stereotype.Service;
 
import javax.sql.rowset.BaseRowSet;
 
/**
 * @Author Jinquan_Ou
 * @Description
 * @Date 2023-07-17 13:28
 * @Version 1.0.0
 **/
@Service
public class ZHealthNowServiceImpl extends ServiceImpl<ZHealthNowMapper, ZHealthNow> implements ZHealthNowService {
    @Override
    public AjaxResult selectData() {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
 
        LambdaQueryWrapper<ZHealthNow> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZHealthNow::getUid,userId);
        ZHealthNow zHealthNow = getOne(lqw);
 
        //如果是第一次进来,之前没有这个用户的数据,抛异常让用户先插入数据
        if(zHealthNow == null){
            throw new RuntimeException("第一次进来,请先填写好数据");
        }
 
        //封装要返回的数据
        ZHealthNowDto returnData = new ZHealthNowDto();
        BeanUtils.copyProperties(zHealthNow,returnData);
 
//        returnData.setName(zHealthNow.getName());
//        returnData.setSex(zHealthNow.getSex());
//        returnData.setEducationLevel(zHealthNow.getEducationLevel());
//        returnData.setWork(zHealthNow.getWork());
//        returnData.setPhone(zHealthNow.getPhone());
//        returnData.setEmail(zHealthNow.getEmail());
//        returnData.setMedicine(zHealthNow.getMedicine());
//        returnData.setBaseDisease(zHealthNow.getBaseDisease());
 
        //将json数组转换成对象
        returnData.setBrainDiseaseClass(JSON.parseObject(zHealthNow.getBrain(), BrainDisease.class));
        returnData.setHeartDiseaseClass(JSON.parseObject(zHealthNow.getHeart(), HeartDisease.class));
        returnData.setVascularDiseaseClass(JSON.parseObject(zHealthNow.getBlood(), VascularDisease.class));
        returnData.setDigestiveSystemDiseaseClass(JSON.parseObject(zHealthNow.getDigestiveSystem(), DigestiveSystemDisease.class));
        returnData.setRespiratorySystemDiseaseClass(JSON.parseObject(zHealthNow.getDigestiveSystem(), RespiratorySystemDisease.class));
        returnData.setKidneyDiseaseClass(JSON.parseObject(zHealthNow.getKidney(), KidneyDisease.class));
        returnData.setOtherDiseaseClass(JSON.parseObject(zHealthNow.getOther(), OtherDisease.class));
 
        return AjaxResult.success(returnData);
 
 
    }
 
    @Override
    public AjaxResult saveOrUpdateData(ZHealthNowDto zHealthNowDto) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
 
        LambdaQueryWrapper<ZHealthNow> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZHealthNow::getUid,userId);
        ZHealthNow getResult = getOne(lqw);
 
        ZHealthNow zHealthNow = new ZHealthNow();
 
        BeanUtils.copyProperties(zHealthNowDto,zHealthNow);
        zHealthNow.setUid(userId);
        zHealthNow.setBrain(JSON.toJSONString(zHealthNowDto.getBrainDiseaseClass()));
        zHealthNow.setHeart(JSON.toJSONString(zHealthNowDto.getHeartDiseaseClass()));
        zHealthNow.setBlood(JSON.toJSONString(zHealthNowDto.getVascularDiseaseClass()));
        zHealthNow.setDigestiveSystem(JSON.toJSONString(zHealthNowDto.getDigestiveSystemDiseaseClass()));
        zHealthNow.setBreathSystem(JSON.toJSONString(zHealthNowDto.getRespiratorySystemDiseaseClass()));
        zHealthNow.setKidney(JSON.toJSONString(zHealthNowDto.getKidneyDiseaseClass()));
        zHealthNow.setOther(JSON.toJSONString(zHealthNowDto.getOtherDiseaseClass()));
 
 
        if(getResult == null){
            //如果是第一次进来,那么是新增数据
            save(zHealthNow);
        }else {
            //如果不是第一次,那就是修改数据了
            zHealthNow.setId(getResult.getId());
            updateById(zHealthNow);
        }
 
        return AjaxResult.success();
 
 
    }
}