| | |
| | | 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 |
| | |
| | | **/ |
| | | @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(); |
| | | |
| | | |
| | | } |
| | | } |