# TaWidgetServiceImpl.java

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

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.ReportImportResultCons;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.finance.cons.ta.TaRecordsStatusEnum;
    import cloud.wconnect.finance.entity.ta.TaRecordsStatus;
    import cloud.wconnect.finance.pojo.dto.ta.widget.TaExceptionRecordDTO;
    import cloud.wconnect.finance.service.ta.ITaImportLogService;
    import cloud.wconnect.finance.service.ta.ITaRecordsStatusService;
    import cloud.wconnect.finance.service.ta.ITaWidgetService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.google.common.collect.Lists;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Resource;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    /**
     * Service: widget
     *
     * @author zc
     * @date 2023/12/11
     */
    @Service
    @DS("finance")
    public class TaWidgetServiceImpl implements ITaWidgetService {
        @Resource
        private ITaRecordsStatusService recordsStatusService;
        @Resource
        private ITaImportLogService importLogService;

        /**
         * 统计比对异常数据的数量
         *
         * @param propertyDTO 资产
         * @return TaExceptionRecordDTO
         * @author zc
         * @date 2023/12/11
         */
        @Override
        public TaExceptionRecordDTO getExceptionRecordNumber(PropertyDTO propertyDTO) {
            List<TaRecordsStatus> recordsStatusList =
                    recordsStatusService.list(new QueryWrapper<TaRecordsStatus>().lambda()
                            .eq(TaRecordsStatus::getPropertyId, propertyDTO.getId())
                            .in(TaRecordsStatus::getStatus, Lists.newArrayList(
                                    TaRecordsStatusEnum.MISS_PMS.getCode(),
                                    TaRecordsStatusEnum.MISS_TA.getCode(),
                                    TaRecordsStatusEnum.PRICE_VARIANCE.getCode()))
                            .select(TaRecordsStatus::getId, TaRecordsStatus::getStatus));
            Map<Integer, Long> status2Number = recordsStatusList.stream()
                    .collect(Collectors.groupingBy(TaRecordsStatus::getStatus,
                            Collectors.counting()));

            long exceptionTotal = importLogService.count(propertyDTO.getTenantId(), propertyDTO.getId(),
                    null, null, List.of(ReportImportResultCons.IMPORT_RESULT_FAIL,
                            ReportImportResultCons.IMPORT_RESULT_MISSED));
            return TaExceptionRecordDTO.builder()
                    .missPms(status2Number.getOrDefault(TaRecordsStatusEnum.MISS_PMS.getCode(),
                            BaseConstant.LONG_ZERO))
                    .missTa(status2Number.getOrDefault(TaRecordsStatusEnum.MISS_TA.getCode(),
                            BaseConstant.LONG_ZERO))
                    .priceDiscrepancy(status2Number.getOrDefault(TaRecordsStatusEnum.PRICE_VARIANCE.getCode(),
                            BaseConstant.LONG_ZERO))
                    .exceptionTotal(exceptionTotal)
                    .build();
        }
    }