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.OrgServiceScopeFeePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraOrgServiceScopeFeeDO;
import cn.iocoder.yudao.module.system.dal.mysql.extra.ElderlyExtraOrgServiceScopeFeeMapper;
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_ORG_SERVICE_SCOPE_FEE_NOT_EXISTS;

@Service @Slf4j
public class ElderlyExtraOrgServiceScopeFeeServiceImpl implements ElderlyExtraOrgServiceScopeFeeService {
    @Resource private ElderlyExtraOrgServiceScopeFeeMapper mapper;

    @Override public Long create(ElderlyExtraOrgServiceScopeFeeDO c) { mapper.insert(c); return c.getId(); }
    @Override public void update(ElderlyExtraOrgServiceScopeFeeDO u) { validateExists(u.getId()); mapper.updateById(u); }
    @Override public void delete(Long id) { validateExists(id); mapper.deleteById(id); }
    @Override public PageResult<ElderlyExtraOrgServiceScopeFeeDO> findPage(OrgServiceScopeFeePageReqVO reqVO) { return mapper.selectPage(reqVO); }
    @Override public ElderlyExtraOrgServiceScopeFeeDO getDetail(Long id) { return validateExists(id); }
    @Override public List<ElderlyExtraOrgServiceScopeFeeDO> getListByElderId(Long elderId) { return mapper.selectList(new LambdaQueryWrapperX<ElderlyExtraOrgServiceScopeFeeDO>().eqIfPresent(ElderlyExtraOrgServiceScopeFeeDO::getElderId, elderId).orderByDesc(ElderlyExtraOrgServiceScopeFeeDO::getCreateTime)); }
    private ElderlyExtraOrgServiceScopeFeeDO validateExists(Long id) { ElderlyExtraOrgServiceScopeFeeDO r = mapper.selectById(id); if (r == null) throw exception(ELDERLY_EXTRA_ORG_SERVICE_SCOPE_FEE_NOT_EXISTS); return r; }
}
