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

import cn.iocoder.yudao.module.system.controller.admin.biz.vo.AssessmentsPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyInfoDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.RehabilitationAssessmentsDO;
import cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyInfoMapper;
import cn.iocoder.yudao.module.system.dal.mysql.biz.RehabilitationAssessmentsMapper;
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
@Validated
public class RehabilitationAssessmentsServiceImpl implements RehabilitationAssessmentsService {

    @Resource
    private RehabilitationAssessmentsMapper assessmentsMapper;
    @Resource
    private ElderlyInfoMapper elderlyInfoMapper;
    @Resource
    private BuildService buildService;

    @Override
    public Integer createAssessments(RehabilitationAssessmentsDO createReqVO) {
        // 插入
        assessmentsMapper.insert(createReqVO);
        // 返回
        return createReqVO.getAssessmentId();
    }

    @Override
    public void updateAssessments(RehabilitationAssessmentsDO updateReqVO) {
        // 更新
        assessmentsMapper.updateById(updateReqVO);
    }

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


    @Override
    public RehabilitationAssessmentsDO getAssessments(Integer id) {
        RehabilitationAssessmentsDO rehabilitationAssessmentsDO = assessmentsMapper.selectById(id);
        ElderlyInfoDO elderlyInfoDO = elderlyInfoMapper.selectById(rehabilitationAssessmentsDO.getElderId());
        rehabilitationAssessmentsDO.setElderlyInfo(elderlyInfoDO);
        rehabilitationAssessmentsDO.setBedInfo(buildService.getFullBedName(Long.valueOf(rehabilitationAssessmentsDO.getElderId())));
        return rehabilitationAssessmentsDO;
    }

    @Override
    public PageResult<RehabilitationAssessmentsDO> getAssessmentsPage(AssessmentsPageReqVO pageReqVO) {
        PageResult<RehabilitationAssessmentsDO> pageResult = assessmentsMapper.selectPage(pageReqVO);
        for (RehabilitationAssessmentsDO rehabilitationAssessmentsDO : pageResult.getList()) {
            rehabilitationAssessmentsDO.setBedInfo(buildService.getFullBedName(Long.valueOf(rehabilitationAssessmentsDO.getElderId())));
        }
        return pageResult;
    }

}