| | |
| | | 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.ZHealthBase; |
| | | import com.ruoyi.domain.dto.ZHealthBaseDto; |
| | | import com.ruoyi.domain.health.AllergyHistory; |
| | | import com.ruoyi.domain.health.BloodType; |
| | | import com.ruoyi.domain.health.GeneticDisease; |
| | | import com.ruoyi.mapper.ZHealthBaseMapper; |
| | | import com.ruoyi.service.ZHealthBaseService; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Service |
| | | public class ZHealthBaseServiceImpl extends ServiceImpl<ZHealthBaseMapper, ZHealthBase> implements ZHealthBaseService { |
| | | |
| | | @Override |
| | | public ZHealthBaseDto selectData() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthBase> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthBase::getUid,userId); |
| | | ZHealthBase zHealthBase = getOne(lqw); |
| | | |
| | | //如果是第一次进来,之前没有这个用户的数据,抛异常让用户先插入数据 |
| | | if(zHealthBase == null){ |
| | | throw new RuntimeException("第一次进来,请先填写好数据"); |
| | | } |
| | | |
| | | //封装要返回的数据 |
| | | ZHealthBaseDto returnData = new ZHealthBaseDto(); |
| | | BeanUtils.copyProperties(zHealthBase,returnData); |
| | | |
| | | // returnData.setName(zHealthBase.getName()); |
| | | // returnData.setSex(zHealthBase.getSex()); |
| | | // returnData.setEducationLevel(zHealthBase.getEducationLevel()); |
| | | // returnData.setWork(zHealthBase.getWork()); |
| | | // returnData.setPhone(zHealthBase.getPhone()); |
| | | // returnData.setEmail(zHealthBase.getEmail()); |
| | | // returnData.setMedicine(zHealthBase.getMedicine()); |
| | | // returnData.setBaseDisease(zHealthBase.getBaseDisease()); |
| | | |
| | | //将json数组转换成对象 |
| | | returnData.setBloodClass(JSON.parseObject(zHealthBase.getBlood(), BloodType.class)); |
| | | returnData.setAllergyClass(JSON.parseObject(zHealthBase.getAllergy(), AllergyHistory.class)); |
| | | returnData.setGeneticDiseaseClass(JSON.parseObject(zHealthBase.getGeneticDisease(), GeneticDisease.class)); |
| | | |
| | | return returnData; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult saveOrUpdateData(ZHealthBaseDto zHealthBaseDto) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthBase> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthBase::getUid,userId); |
| | | ZHealthBase getResult = getOne(lqw); |
| | | |
| | | ZHealthBase zHealthBase = new ZHealthBase(); |
| | | |
| | | BeanUtils.copyProperties(zHealthBaseDto,zHealthBase); |
| | | zHealthBase.setUid(userId); |
| | | zHealthBase.setBlood(JSON.toJSONString(zHealthBaseDto.getBloodClass())); |
| | | zHealthBase.setAllergy(JSON.toJSONString(zHealthBaseDto.getAllergyClass())); |
| | | zHealthBase.setGeneticDisease(JSON.toJSONString(zHealthBaseDto.getGeneticDiseaseClass())); |
| | | |
| | | if(getResult == null){ |
| | | //如果是第一次进来,那么是新增数据 |
| | | save(zHealthBase); |
| | | }else { |
| | | //如果不是第一次,那就是修改数据了 |
| | | zHealthBase.setId(getResult.getId()); |
| | | updateById(zHealthBase); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | } |