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.ZHealthNote;
|
import com.ruoyi.domain.ZHealthNow;
|
import com.ruoyi.domain.ZHealthNow;
|
import com.ruoyi.domain.ZInfoUser;
|
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 com.ruoyi.service.ZInfoUserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.sql.rowset.BaseRowSet;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Author Jinquan_Ou
|
* @Description
|
* @Date 2023-07-17 13:28
|
* @Version 1.0.0
|
**/
|
@Service
|
public class ZHealthNowServiceImpl extends ServiceImpl<ZHealthNowMapper, ZHealthNow> implements ZHealthNowService {
|
|
@Autowired
|
ZInfoUserService zInfoUserService;
|
@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)
|
{
|
//根据userId查询到infouser的uaid
|
ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId);
|
// System.out.println("sdfsdf999000550");
|
|
//拿到所有的sysid
|
List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList());
|
System.out.println(fms.size());
|
|
for(Long id:fms)
|
{
|
LambdaQueryWrapper<ZHealthNow> lqw1 = new LambdaQueryWrapper<>();
|
|
if(!id.equals(userId))
|
{
|
lqw1.eq(ZHealthNow::getUid, id);
|
zHealthNow = getOne(lqw1);
|
break;
|
}
|
}
|
System.out.println(zHealthNow);
|
System.out.println("sdfsdf9990000");
|
System.out.println("sdfsdf9990000");
|
System.out.println("sdfsdf9990000");
|
}
|
//如果是第一次进来,之前没有这个用户的数据,抛异常让用户先插入数据
|
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();
|
|
|
}
|
}
|