package cn.iocoder.yudao.module.system.service.biz;

import cn.iocoder.yudao.module.system.controller.admin.biz.vo.NutritionRecordPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyInfoDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NutritionRecordDO;
import cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyInfoMapper;
import cn.iocoder.yudao.module.system.dal.mysql.biz.NutritionRecordMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.framework.common.pojo.PageResult;


/**
 * 营养记录 Service 实现类
 *
 * @author 系统管理员
 */
@Service("nutritionRecordService")
@Validated
public class NutritionRecordServiceImpl implements NutritionRecordService {

    @Resource
    private NutritionRecordMapper recordMapper;
    @Resource
    private ElderlyInfoMapper elderlyInfoMapper;
    @Resource
    private BuildService buildService;

    @Override
    public void createRecord(NutritionRecordDO createReqVO) {
        // 插入
        recordMapper.insert(createReqVO);
    }

    @Override
    public void updateRecord(NutritionRecordDO updateReqVO) {
        // 更新
        recordMapper.updateById(updateReqVO);
    }

    @Override
    public void deleteRecord(Integer id) {
        // 删除
        recordMapper.deleteById(id);
    }

    @Override
    public NutritionRecordDO getRecord(Integer id) {
        NutritionRecordDO nutritionRecordDO = recordMapper.selectById(id);

        ElderlyInfoDO elderlyInfoDO = elderlyInfoMapper.selectById(nutritionRecordDO.getElderId());
        nutritionRecordDO.setElderlyInfo(elderlyInfoDO);
        nutritionRecordDO.setBedInfo(buildService.getFullBedName(Long.valueOf(nutritionRecordDO.getElderId())));

        return nutritionRecordDO;
    }

    @Override
    public PageResult<NutritionRecordDO> getRecordPage(NutritionRecordPageReqVO pageReqVO) {
        PageResult<NutritionRecordDO> pageResult = recordMapper.selectPage(pageReqVO);
        for (NutritionRecordDO nutritionRecordDO : pageResult.getList()) {
            nutritionRecordDO.setBedInfo(buildService.getFullBedName(Long.valueOf(nutritionRecordDO.getElderId())));
        }
        return pageResult;
    }

}