# CbCaseIwcAdRequestCommentServiceImpl.java

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

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.bo.adj.AdjCommentBO;
    import cloud.wconnect.commonlib.pojo.bo.adj.AdjCommentDetailBO;
    import cloud.wconnect.finance.entity.chargeback.CbCaseIwcAdRequestComment;
    import cloud.wconnect.finance.mapper.chargeback.CbCaseIwcAdRequestCommentMapper;
    import cloud.wconnect.finance.service.chargeback.ICbCaseIwcAdRequestCommentService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.google.common.collect.Lists;
    import lombok.RequiredArgsConstructor;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.Collections;
    import java.util.List;

    /**
     * <p>
     * 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2026-02-09
     */
    @Service
    @DS("finance")
    @RequiredArgsConstructor
    public class CbCaseIwcAdRequestCommentServiceImpl extends ServiceImpl<CbCaseIwcAdRequestCommentMapper, CbCaseIwcAdRequestComment> implements ICbCaseIwcAdRequestCommentService {

        private final BeanMapper beanMapper;

        /**
         * 批量删除
         *
         * @param propertyId    资产id
         * @param adjustmentIds 调账id列表
         * @author lichen
         * @date 2026/2/9
         */
        @Override
        public void removeByAdjustmentIds(int propertyId, List<Long> adjustmentIds) {
            remove(new QueryWrapper<CbCaseIwcAdRequestComment>().lambda()
                    .eq(CbCaseIwcAdRequestComment::getPropertyId, propertyId)
                    .in(CbCaseIwcAdRequestComment::getArId, adjustmentIds));
        }

        /**
         * 批量保存
         *
         * @param adjCommentBO 调账数据BO
         * @author lichen
         * @date 2026/2/9
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(AdjCommentBO adjCommentBO) {
            Integer propertyId = adjCommentBO.getPropertyId();
            Long adjustmentId = adjCommentBO.getAdjustmentId();

            // 删除评论列表
            removeByAdjustmentIds(propertyId, Lists.newArrayList(adjustmentId));

            List<AdjCommentDetailBO> commentBOS = adjCommentBO.getComments();
            if (CollectionUtils.isNotEmpty(commentBOS)) {
                // 新增评论列表
                List<CbCaseIwcAdRequestComment> comments = beanMapper.mapList(commentBOS, CbCaseIwcAdRequestComment.class, (bo, entity) -> {
                    entity.setPropertyId(propertyId);
                });
                saveBatch(comments);
            }
        }

        /**
         * 查询评论
         *
         * @param propertyId    资产id
         * @param adjustmentIds 调账id列表
         * @return java.util.List<cloud.wconnect.finance.entity.chargeback.CbCaseIwcAdRequestComment>
         * @author lichen
         * @date 2026/2/10
         */
        @Override
        public List<CbCaseIwcAdRequestComment> listByAdjustmentIds(Integer propertyId, List<Long> adjustmentIds) {
            if (CollectionUtils.isEmpty(adjustmentIds)) return Collections.emptyList();
            return list(new LambdaQueryWrapper<CbCaseIwcAdRequestComment>()
                    .eq(CbCaseIwcAdRequestComment::getPropertyId, propertyId)
                    .in(CbCaseIwcAdRequestComment::getArId, adjustmentIds));
        }
    }