| | |
| | | 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.ZHealthHabit; |
| | | import com.ruoyi.domain.dto.ZHealthHabitDto; |
| | | import com.ruoyi.domain.dto.ZHealthHabitDto; |
| | | import com.ruoyi.domain.health.*; |
| | | import com.ruoyi.mapper.ZHealthHabitMapper; |
| | | import com.ruoyi.service.ZHealthHabitService; |
| | | 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 ZHealthHabitServiceImpl extends ServiceImpl<ZHealthHabitMapper, ZHealthHabit> implements ZHealthHabitService { |
| | | @Autowired |
| | | ZInfoUserService zInfoUserService; |
| | | @Override |
| | | public AjaxResult selectData() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthHabit> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthHabit::getUid,userId); |
| | | ZHealthHabit zHealthHabit = getOne(lqw); |
| | | System.out.println("+++++++6676+++++++++++"); |
| | | |
| | | if(zHealthHabit==null) |
| | | { |
| | | //根据userId查询到infouser的uaid |
| | | ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId); |
| | | System.out.println("++++++++++++++++++"); |
| | | |
| | | //拿到所有的sysid |
| | | List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList()); |
| | | for(Long id:fms) |
| | | { |
| | | LambdaQueryWrapper<ZHealthHabit> lqw1 = new LambdaQueryWrapper<>(); |
| | | if(!id.equals(userId)) |
| | | { |
| | | System.out.println("++++++++++++++++++"); |
| | | System.out.println(id); |
| | | lqw1.eq(ZHealthHabit::getUid, id); |
| | | zHealthHabit = getOne(lqw1); |
| | | break; |
| | | } |
| | | } |
| | | System.out.println("sdfsdf9990000"); |
| | | } |
| | | //如果是第一次进来,之前没有这个用户的数据,抛异常让用户先插入数据 |
| | | if(zHealthHabit == null){ |
| | | throw new RuntimeException("第一次进来,请先填写好数据"); |
| | | } |
| | | |
| | | //封装要返回的数据 |
| | | ZHealthHabitDto returnData = new ZHealthHabitDto(); |
| | | BeanUtils.copyProperties(zHealthHabit,returnData); |
| | | |
| | | // returnData.setName(zHealthHabit.getName()); |
| | | // returnData.setSex(zHealthHabit.getSex()); |
| | | // returnData.setEducationLevel(zHealthHabit.getEducationLevel()); |
| | | // returnData.setWork(zHealthHabit.getWork()); |
| | | // returnData.setPhone(zHealthHabit.getPhone()); |
| | | // returnData.setEmail(zHealthHabit.getEmail()); |
| | | // returnData.setMedicine(zHealthHabit.getMedicine()); |
| | | // returnData.setBaseDisease(zHealthHabit.getBaseDisease()); |
| | | |
| | | //将json数组转换成对象 |
| | | returnData.setSleepClass(JSON.parseObject(zHealthHabit.getSleep(), Sleep.class)); |
| | | returnData.setStoolStatusClass(JSON.parseObject(zHealthHabit.getStoolStatus(), StoolStatus.class)); |
| | | returnData.setUrineStatusClass(JSON.parseObject(zHealthHabit.getUrineStatus(), UrineStatus.class)); |
| | | returnData.setEatingHabitsClass(JSON.parseObject(zHealthHabit.getEatType(), EatingHabits.class)); |
| | | returnData.setLifeEventClass(JSON.parseObject(zHealthHabit.getLifeType(), LifeEvent.class)); |
| | | |
| | | return AjaxResult.success(returnData); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult saveOrUpdateData(ZHealthHabitDto zHealthHabitDto) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | LambdaQueryWrapper<ZHealthHabit> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZHealthHabit::getUid,userId); |
| | | ZHealthHabit getResult = getOne(lqw); |
| | | |
| | | ZHealthHabit zHealthHabit = new ZHealthHabit(); |
| | | |
| | | BeanUtils.copyProperties(zHealthHabitDto,zHealthHabit); |
| | | zHealthHabit.setUid(userId); |
| | | zHealthHabit.setSleep(JSON.toJSONString(zHealthHabitDto.getSleepClass())); |
| | | zHealthHabit.setStoolStatus(JSON.toJSONString(zHealthHabitDto.getStoolStatusClass())); |
| | | zHealthHabit.setUrineStatus(JSON.toJSONString(zHealthHabitDto.getUrineStatusClass())); |
| | | zHealthHabit.setEatType(JSON.toJSONString(zHealthHabitDto.getEatingHabitsClass())); |
| | | zHealthHabit.setLifeType(JSON.toJSONString(zHealthHabitDto.getLifeEventClass())); |
| | | |
| | | if(getResult == null){ |
| | | //如果是第一次进来,那么是新增数据 |
| | | save(zHealthHabit); |
| | | }else { |
| | | //如果不是第一次,那就是修改数据了 |
| | | zHealthHabit.setId(getResult.getId()); |
| | | updateById(zHealthHabit); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | } |