# CbCaseApproveLogServiceImpl.java

    package cloud.wconnect.finance.service.chargeback.impl;

    import cloud.wconnect.finance.entity.chargeback.CbCase;
    import cloud.wconnect.finance.entity.chargeback.CbCaseApproveLog;
    import cloud.wconnect.finance.entity.chargeback.CbCasePublishLog;
    import cloud.wconnect.finance.mapper.chargeback.CbCaseApproveLogMapper;
    import cloud.wconnect.finance.service.chargeback.ICbCaseApproveLogService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Nullable;
    import java.util.Collections;
    import java.util.List;

    /**
     * <p>
     * case 审批日志表 服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-08-22
     */
    @Service
    @DS("finance")
    public class CbCaseApproveLogServiceImpl extends ServiceImpl<CbCaseApproveLogMapper, CbCaseApproveLog> implements ICbCaseApproveLogService {

        /**
         * 查询指定用户审批 case 的记录
         *
         * @param cases  case
         * @param userId 指定用户
         * @return case 审批记录
         * @author yyt
         * @date 2023/8/23
         */
        @Override
        public List<Long> listCaseIdByCaseAndTargetUser(List<CbCase> cases, Integer userId) {
            return baseMapper.listCaseIdByCaseAndTargetUser(cases, userId);
        }

        /**
         * 查询 case 对应的审批记录
         *
         * @param cases case
         * @return 审批记录
         * @author yyt
         * @date 2023/8/25
         */
        @Override
        public List<CbCaseApproveLog> listByCases(List<CbCase> cases) {
            return baseMapper.listByCases(cases);
        }

        /**
         * 清空日志
         *
         * @param caseId case id
         * @param stages 阶段
         * @author yyt
         * @date 2023/9/7
         */
        @Override
        public void clearLog(Long caseId, @Nullable List<Integer> stages) {
            remove(new QueryWrapper<CbCaseApproveLog>().lambda().eq(CbCaseApproveLog::getCaseId, caseId)
                    .in(CollectionUtils.isNotEmpty(stages), CbCaseApproveLog::getStage, stages));
        }

        /**
         * 查询 case 当前阶段审批日志
         *
         * @param cs case
         * @return 审批日志
         * @author yyt
         * @date 2023/9/9
         */
        @Override
        public List<CbCaseApproveLog> listStageApproveLog(CbCase cs) {
            return list(new QueryWrapper<CbCaseApproveLog>().lambda().eq(CbCaseApproveLog::getCaseId, cs.getId())
                    .eq(CbCaseApproveLog::getStage, cs.getStage()).eq(CbCaseApproveLog::getBatchId, cs.getBatchId()));
        }

        /**
         * 获取指定阶段及批次 的审批日志
         *
         * @param publishLogs 推送日志
         * @return 审批日志
         * @author yyt
         * @date 2024/2/21
         **/
        @Override
        public List<CbCaseApproveLog> listByStageAndBatchId(List<CbCasePublishLog> publishLogs) {
            if (CollectionUtils.isEmpty(publishLogs)) {
                return Collections.emptyList();
            }

            return baseMapper.listByStageAndBatchId(publishLogs);
        }

    }