# CbCaseWidgetController.java

    package cloud.wconnect.finance.controller.chargeback;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.commonlib.pojo.dto.group.Addition;
    import cloud.wconnect.commonlib.pojo.dto.group.Edition;
    import cloud.wconnect.finance.pojo.dto.chargeback.widget.*;
    import cloud.wconnect.finance.pojo.query.chargeback.widget.DisputeAmountStatisticsQuery;
    import cloud.wconnect.finance.pojo.query.chargeback.widget.OverdueUnprocessStatisticsQuery;
    import cloud.wconnect.finance.pojo.query.chargeback.widget.PendingOverdueStatisticsQuery;
    import cloud.wconnect.finance.pojo.query.chargeback.widget.ResultStatisticsQuery;
    import cloud.wconnect.finance.service.chargeback.ICbCaseWidgetService;
    import jakarta.validation.Valid;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import java.util.List;
    import java.util.stream.Collectors;

    /**
     * 组件
     *
     * @author: yyt
     * 2025-12-08
     */
    @RestController
    @RequestMapping("/charge-back/widget")
    public class CbCaseWidgetController {

        @Autowired
        private ICbCaseWidgetService cbCaseWidgetService;
        @Autowired
        private SessionContext sessionContext;

        /**
         * 1661 - 获取当前资产待处理统计
         *
         * @param property 资产标识
         * @return 待处理统计
         * @author yyt
         * @date 2025/12/8
         **/
        @ApiId(1661)
        @GetMapping("/pending-statistics")
        public PendingStatisticsDTO listPendingStatistics(String property) {
            int propertyId = sessionContext.getPropertyId(property);
            int userId = sessionContext.getLoginUserId();
            return cbCaseWidgetService.listPendingStatistics(propertyId, userId);
        }

        /**
         * 1662 - 获取资产待处理逾期统计
         *
         * @param query 检索条件
         * @return 待处理逾期统计
         * @author yyt
         * @date 2025/12/8
         **/
        @ApiId(1662)
        @GetMapping("/pending-overdue-statistics")
        public List<PendingOverdueStatisticsDTO> listPendingOverdueStatistics(@Valid PendingOverdueStatisticsQuery query) {
            List<Integer> propertyIds = query.getPropertyIds();
            checkPropertyIds(propertyIds);
            return cbCaseWidgetService.listPendingOverdueStatistics(propertyIds);
        }

        /**
         * 检查资产 id 是否有效
         *
         * @param propertyIds 资产 id
         * @author yyt
         * @date 2025/12/8
         **/
        private void checkPropertyIds(List<Integer> propertyIds) {
            List<Integer> effectivePropertyIds = sessionContext.getPropertyIds()
                    .stream().filter(propertyIds::contains).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(effectivePropertyIds) || effectivePropertyIds.size() != propertyIds.size()) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(), "the property is not in the current user's property");
            }
        }

        /**
         * 1663 - 获取资产结果统计
         *
         * @param query 检索条件
         * @return 结果统计
         * @author yyt
         * @date 2025/12/8
         **/
        @ApiId(1663)
        @GetMapping("/result-statistics")
        public List<ResultStatisticsDTO> listResultStatistics(@Valid ResultStatisticsQuery query) {
            List<Integer> propertyIds = query.getPropertyIds();
            checkPropertyIds(propertyIds);

            if (query.getType() == ResultStatisticsQuery.FIXED_DATE_RANGE) {
                return cbCaseWidgetService.listResultStatisticsForFixedDateRange(propertyIds);
            } else {
                query.setPropertyIds(propertyIds);
                return cbCaseWidgetService.listResultStatisticsForDynamicDateRange(query);
            }
        }

        /**
         * 1664 - 获取当前资产争议金额统计
         *
         * @param property 资产标识
         * @param query    检索条件
         * @return 争议金额统计
         * @author yyt
         * @date 2025/12/8
         **/
        @ApiId(1664)
        @GetMapping("/current-property/dispute-amount-statistics")
        public DisputeAmountStatisticsDTO listCurrentPropertyDisputeAmountStatistics(String property, @Validated(Addition.class) DisputeAmountStatisticsQuery query) {
            return cbCaseWidgetService.listCurrentPropertyDisputeAmountStatistics(sessionContext.getPropertyId(property), query);
        }

        /**
         * 1665 - 获取各个资产争议金额统计
         *
         * @param query 检索条件
         * @return 争议金额统计
         * @author yyt
         * @date 2025/12/9
         **/
        @ApiId(1665)
        @GetMapping("/multiple-property/dispute-amount-statistics")
        public List<MultiplePropertyDisputeAmountStatisticsDTO> listDisputeAmountStatistics(@Validated(Edition.class) DisputeAmountStatisticsQuery query) {
            List<Integer> propertyIds = query.getPropertyIds();
            checkPropertyIds(propertyIds);
            return cbCaseWidgetService.listMultiplePropertyDisputeAmountStatistics(query);
        }

        /**
         * 1666 - 获取资产超期未处理统计
         *
         * @param query 检索条件
         * @return 超期未处理统计
         * @author yyt
         * @date 2025/12/9
         **/
        @ApiId(1666)
        @GetMapping("/overdue-unprocess-statistics")
        public List<OverdueUnprocessStatisticsDTO> listOverdueUnprocessStatistics(@Valid OverdueUnprocessStatisticsQuery query) {
            List<Integer> propertyIds = query.getPropertyIds();
            checkPropertyIds(propertyIds);

            return cbCaseWidgetService.listOverdueUnprocessStatistics(propertyIds);
        }

    }