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

import cn.iocoder.yudao.module.system.controller.admin.biz.vo.CommunicationRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.CommunicationRecordRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyInfoDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.FamilyCommunicationRecordDO;
import cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyInfoMapper;
import cn.iocoder.yudao.module.system.dal.mysql.biz.FamilyCommunicationRecordMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;



/**
 * 家属沟通记录 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class FamilyCommunicationRecordServiceImpl implements FamilyCommunicationRecordService {

    @Resource
    private FamilyCommunicationRecordMapper communicationRecordMapper;
    @Resource
    private BuildService buildService;
    @Resource
    private ElderlyInfoMapper elderlyInfoMapper;

    @Override
    public void createCommunicationRecord(FamilyCommunicationRecordDO createReqVO) {

        communicationRecordMapper.insert(createReqVO);

    }

    @Override
    public void updateCommunicationRecord(FamilyCommunicationRecordDO updateReqVO) {
        // 更新
        communicationRecordMapper.updateById(updateReqVO);
    }

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



    @Override
    public FamilyCommunicationRecordDO getCommunicationRecord(Integer id) {
        FamilyCommunicationRecordDO familyCommunicationRecordDO = communicationRecordMapper.selectById(id);
        ElderlyInfoDO elderlyInfoDO = elderlyInfoMapper.selectById(familyCommunicationRecordDO.getElderId());
        familyCommunicationRecordDO.setElderlyInfo(elderlyInfoDO);
        familyCommunicationRecordDO.setBedInfo(buildService.getFullBedName(Long.valueOf(familyCommunicationRecordDO.getElderId())));
        return familyCommunicationRecordDO;
    }

    @Override
    public PageResult<CommunicationRecordRespVO> getCommunicationRecordPage(CommunicationRecordPageReqVO pageReqVO) {
        PageResult<FamilyCommunicationRecordDO> result = communicationRecordMapper.selectPage(pageReqVO);
        PageResult<CommunicationRecordRespVO> pageResult = BeanUtils.toBean(result, CommunicationRecordRespVO.class);
        for (CommunicationRecordRespVO communicationRecordRespVO : pageResult.getList()) {
            communicationRecordRespVO.setBedInfo(buildService.getFullBedName(communicationRecordRespVO.getElderId()));
        }
        return pageResult;
    }

}