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.PartyBCertificatePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraPartyBCertificateDO;
import cn.iocoder.yudao.module.system.dal.mysql.extra.ElderlyExtraPartyBCertificateMapper;
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_PARTY_B_CERTIFICATE_NOT_EXISTS;

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