| | |
| | | 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.*; |
| | | import com.ruoyi.domain.ZHealthInfo; |
| | | import com.ruoyi.domain.ZHealthInfo; |
| | | import com.ruoyi.domain.dto.ZHealthInfoDto; |
| | | import com.ruoyi.domain.dto.ZHealthInfoDto; |
| | | import com.ruoyi.domain.health.*; |
| | | import com.ruoyi.mapper.ZHealthInfoMapper; |
| | | import com.ruoyi.service.ZHealthInfoService; |
| | | import com.ruoyi.service.ZInfoUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Service |
| | | public class ZHealthInfoServiceImpl extends ServiceImpl<ZHealthInfoMapper, ZHealthInfo> implements ZHealthInfoService { |
| | | @Autowired |
| | | ZInfoUserService zInfoUserService; |
| | | @Override |
| | | public AjaxResult selectData() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthInfo> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthInfo::getUid,userId); |
| | | ZHealthInfo zHealthInfo = getOne(lqw); |
| | | |
| | | |
| | | |
| | | if(zHealthInfo==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<ZHealthInfo> lqw1 = new LambdaQueryWrapper<>(); |
| | | |
| | | if(!id.equals(userId)) |
| | | { |
| | | lqw1.eq(ZHealthInfo::getUid, id); |
| | | zHealthInfo = getOne(lqw1); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | //如果是第一次进来,之前没有这个用户的数据,抛异常让用户先插入数据 |
| | | if(zHealthInfo == null){ |
| | | throw new RuntimeException("第一次进来,请先填写好数据"); |
| | | } |
| | | |
| | | //封装要返回的数据 |
| | | ZHealthInfoDto returnData = new ZHealthInfoDto(); |
| | | BeanUtils.copyProperties(zHealthInfo,returnData); |
| | | |
| | | // returnData.setName(zHealthInfo.getName()); |
| | | // returnData.setSex(zHealthInfo.getSex()); |
| | | // returnData.setEducationLevel(zHealthInfo.getEducationLevel()); |
| | | // returnData.setWork(zHealthInfo.getWork()); |
| | | // returnData.setPhone(zHealthInfo.getPhone()); |
| | | // returnData.setEmail(zHealthInfo.getEmail()); |
| | | // returnData.setMedicine(zHealthInfo.getMedicine()); |
| | | // returnData.setBaseDisease(zHealthInfo.getBaseDisease()); |
| | | |
| | | //将json数组转换成对象 |
| | | returnData.setSkinTypeClass(JSON.parseObject(zHealthInfo.getSkinType(), SkinType.class)); |
| | | returnData.setPsychologyTypeClass(JSON.parseObject(zHealthInfo.getPsychologyType(), PsychologyType.class)); |
| | | returnData.setAttitudeClass(JSON.parseObject(zHealthInfo.getAttitude(), AttitudeType.class)); |
| | | returnData.setNutritionClass(JSON.parseObject(zHealthInfo.getNutrition(), NutritionType.class)); |
| | | |
| | | return AjaxResult.success(returnData); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveOrUpdateData(ZHealthInfoDto zHealthInfoDto) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthInfo> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthInfo::getUid,userId); |
| | | ZHealthInfo getResult = getOne(lqw); |
| | | |
| | | ZHealthInfo zHealthInfo = new ZHealthInfo(); |
| | | |
| | | BeanUtils.copyProperties(zHealthInfoDto,zHealthInfo); |
| | | zHealthInfo.setUid(userId); |
| | | zHealthInfo.setSkinType(JSON.toJSONString(zHealthInfoDto.getSkinTypeClass())); |
| | | zHealthInfo.setPsychologyType(JSON.toJSONString(zHealthInfoDto.getPsychologyTypeClass())); |
| | | zHealthInfo.setAttitude(JSON.toJSONString(zHealthInfoDto.getAttitudeClass())); |
| | | zHealthInfo.setNutrition(JSON.toJSONString(zHealthInfoDto.getNutritionClass())); |
| | | |
| | | |
| | | if(getResult == null){ |
| | | //如果是第一次进来,那么是新增数据 |
| | | save(zHealthInfo); |
| | | }else { |
| | | //如果不是第一次,那就是修改数据了 |
| | | zHealthInfo.setId(getResult.getId()); |
| | | updateById(zHealthInfo); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | } |