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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.FirstServiceConfirmationPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraFirstServiceConfirmationDO;
import cn.iocoder.yudao.module.system.dal.mysql.extra.ElderlyExtraFirstServiceConfirmationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ELDERLY_EXTRA_FIRST_SERVICE_CONFIRMATION_NOT_EXISTS;

@Service @Slf4j
public class ElderlyExtraFirstServiceConfirmationServiceImpl implements ElderlyExtraFirstServiceConfirmationService {
    @Resource private ElderlyExtraFirstServiceConfirmationMapper mapper;
    @Override public Long create(ElderlyExtraFirstServiceConfirmationDO c) { mapper.insert(c); return c.getId(); }
    @Override public void update(ElderlyExtraFirstServiceConfirmationDO u) { validateExists(u.getId()); mapper.updateById(u); }
    @Override public void delete(Long id) { validateExists(id); mapper.deleteById(id); }
    @Override public PageResult<ElderlyExtraFirstServiceConfirmationDO> findPage(FirstServiceConfirmationPageReqVO reqVO) { return mapper.selectPage(reqVO); }
    @Override public ElderlyExtraFirstServiceConfirmationDO getDetail(Long id) { return validateExists(id); }
    @Override public List<ElderlyExtraFirstServiceConfirmationDO> getListByElderId(Long elderId) { return mapper.selectList(new LambdaQueryWrapperX<ElderlyExtraFirstServiceConfirmationDO>().eqIfPresent(ElderlyExtraFirstServiceConfirmationDO::getElderId, elderId).orderByDesc(ElderlyExtraFirstServiceConfirmationDO::getCreateTime)); }
    private ElderlyExtraFirstServiceConfirmationDO validateExists(Long id) { ElderlyExtraFirstServiceConfirmationDO r = mapper.selectById(id); if (r == null) throw exception(ELDERLY_EXTRA_FIRST_SERVICE_CONFIRMATION_NOT_EXISTS); return r; }
}
