# CbCaseApproveLevelUserServiceImpl.java

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

    import cloud.wconnect.finance.entity.chargeback.CbCaseApproveLevelUser;
    import cloud.wconnect.finance.mapper.chargeback.CbCaseApproveLevelUserMapper;
    import cloud.wconnect.finance.pojo.dto.chargeback.SaveApproveLevelDTO;
    import cloud.wconnect.finance.service.chargeback.ICbCaseApproveLevelUserService;
    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 java.util.List;
    import java.util.stream.Collectors;

    /**
     * <p>
     * case 审批配置表 服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-08-22
     */
    @Service
    @DS("finance")
    public class CbCaseApproveLevelUserServiceImpl extends ServiceImpl<CbCaseApproveLevelUserMapper, CbCaseApproveLevelUser> implements ICbCaseApproveLevelUserService {

        /**
         * 批量新增
         *
         * @param levelId         审批层级 id
         * @param propertyId      资产 id
         * @param approveLevelDTO 审批人信息
         * @author yyt
         * @date 2023/8/25
         */
        @Override
        public void saveBatch(Long levelId, Integer propertyId, SaveApproveLevelDTO approveLevelDTO) {
            if (CollectionUtils.isEmpty(approveLevelDTO.getUsers())) {
                return;
            }

            Integer stage = approveLevelDTO.getStage();
            Integer approveIndex = approveLevelDTO.getApproveIndex();
            saveBatch(approveLevelDTO.getUsers().stream().map(item -> new CbCaseApproveLevelUser()
                    .setPropertyId(propertyId).setStage(stage).setLevelId(levelId).setApproveIndex(approveIndex)
                    .setUserId(item)).collect(Collectors.toList()));
        }

        /**
         * 删除节点下的审批人
         *
         * @param propertyId 资产 id
         * @param levelId    审批节点 id
         * @author yyt
         * @date 2023/8/25
         */
        @Override
        public void clearLeveUser(Integer propertyId, Long levelId) {
            remove(new QueryWrapper<CbCaseApproveLevelUser>().lambda().eq(CbCaseApproveLevelUser::getPropertyId, propertyId)
                    .eq(CbCaseApproveLevelUser::getLevelId, levelId));
        }

        /**
         * 查询审批节点下的 审批人
         *
         * @param propertyId 资产 id
         * @param stage      阶段
         * @param levelId    审批节点 id
         * @return 审批人
         * @author yyt
         * @date 2023/8/31
         */
        @Override
        public List<CbCaseApproveLevelUser> listApproveUser(Integer propertyId, Integer stage, Long levelId) {
            return list(new QueryWrapper<CbCaseApproveLevelUser>().lambda()
                    .eq(CbCaseApproveLevelUser::getPropertyId, propertyId).eq(CbCaseApproveLevelUser::getStage, stage)
                    .eq(CbCaseApproveLevelUser::getLevelId, levelId));
        }

        /**
         * 查询审批节点下的 审批人
         *
         * @param propertyId 资产 id
         * @param levelIds   审批节点 id
         * @return 审批人
         * @author yyt
         * @date 2023/9/9
         */
        @Override
        public List<CbCaseApproveLevelUser> listApproveUser(Integer propertyId, List<Long> levelIds) {
            return list(new QueryWrapper<CbCaseApproveLevelUser>().lambda()
                    .eq(CbCaseApproveLevelUser::getPropertyId, propertyId).in(CbCaseApproveLevelUser::getLevelId, levelIds));
        }

    }