# WeeklyMonthlyRevenueInternalController.java

    package cloud.wconnect.rateshop.controller.weeklymonthlyrevenue.internal;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.controller.BaseInternalController;
    import cloud.wconnect.commonlib.exception.InternalServerErrorException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.rateshop.cons.weeklymonthlyrevenue.MonthlyRevenueCons;
    import cloud.wconnect.rateshop.pojo.dto.weeklymonthlyrevenue.internal.grouppickup.MonthlyRevenueGrcInternalDTO;
    import cloud.wconnect.rateshop.pojo.dto.weeklymonthlyrevenue.internal.MonthlyRevenueInternalDTO;
    import cloud.wconnect.rateshop.service.weeklymonthlyrevenue.internal.IWeeklyMonthlyRevenueInternalService;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.*;

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

    /**
     * 控制器类：内部调用
     *
     * @author zc
     * @date 2024/10/17
     */
    @Slf4j
    @RestController
    @RequestMapping("/internal/weekly-monthly-revenue")
    public class WeeklyMonthlyRevenueInternalController extends BaseInternalController {
        @Resource
        private IWeeklyMonthlyRevenueInternalService monthlyRevenueInternalService;
        @Resource
        private PropertyInternalService propertyInternalService;
        @Resource
        private ObjectMapper objectMapper;

        @Value("${internal.service.auth-key.basic}")
        private String authKey;

        /**
         * 获取指定日期范围的数据
         *
         * @param sign        签名
         * @param propertyId  资产 id
         * @param versionDate 版本日期(yyyyMMdd)
         * @param startDate   开始日期(yyyyMMdd)
         * @param endDate     结束日期(yyyyMMdd)
         * @return MonthlyRevenueInternalDTO 集合
         * @author zc
         * @date 2025/5/23
         */
        @GetMapping
        public List<MonthlyRevenueInternalDTO> list(@RequestHeader String sign, @RequestParam int propertyId,
                                                    @RequestParam long versionDate, @RequestParam long startDate,
                                                    @RequestParam long endDate) {
            // 校验参数签名
            checkIntranetParams(authKey, sign, propertyId, versionDate, startDate, endDate);
            return monthlyRevenueInternalService.listByDateRange(propertyId, versionDate, startDate, endDate);
        }

        /**
         * 采集 GRC 数据
         *
         * @param tenant      租户标识
         * @param property    资产标识
         * @param internalDTO 数据
         * @param sign        签名
         * @return empty map
         * @author zc
         * @date 2025/7/9
         */
        @PostMapping("/grc")
        public Map<Object, Object> crawlGrc(@RequestParam String tenant, @RequestParam String property,
                                            @RequestBody @Valid MonthlyRevenueGrcInternalDTO internalDTO,
                                            @RequestHeader String sign) {
            try {
                log.info("MonthlyRevenueInternal - Save crawl GRC start, tenant:{}, property:{}", tenant, property);

                // 校验参数签名
                checkIntranetParams(authKey, sign, tenant, property);
                PropertyDTO propertyDTO = propertyInternalService.getOne(property, tenant);
                if (MonthlyRevenueCons.GROUP_CONTRACTED.equals(internalDTO.getType())) {
                    monthlyRevenueInternalService.saveGroupContractedRooms(propertyDTO, internalDTO.getList());
                } else {
                    monthlyRevenueInternalService.saveGroupCancelledRooms(propertyDTO, internalDTO.getList());
                }

                log.info("MonthlyRevenueInternal - Save crawl GRC end, tenant:{}, property:{}", tenant, property);
                return Collections.emptyMap();
            } catch (Exception e) {
                log.error("MonthlyRevenueInternal - Save crawl GRC error, tenant:{}, property:{}, dataJson:{}, exception:{}",
                        tenant, property, JsonUtils.convertObjToString(objectMapper, internalDTO), e);

                throw new InternalServerErrorException(BaseErrorCodeEnum.INTERNAL_SERVICE_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.INTERNAL_SERVICE_ERROR.getCode(),
                        "Save crawl GRC error", e);
            }
        }
    }