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.ChangeConfirmationPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraChangeConfirmationDO;
import cn.iocoder.yudao.module.system.dal.mysql.extra.ElderlyExtraChangeConfirmationMapper;
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_CHANGE_CONFIRMATION_NOT_EXISTS;

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