# RevenueInternalController.java

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

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.controller.BaseInternalController;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.rateshop.pojo.bo.revenue.BanquetAndFBOTBRevenueBO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.GroupPickupDTO;
    import cloud.wconnect.rateshop.pojo.query.revenue.RuleDateQuery;
    import cloud.wconnect.rateshop.service.revenue.IRevenueDailySummaryGroupPickupService;
    import cloud.wconnect.rateshop.service.revenue.IRevenueOtbRevenueService;
    import com.google.common.collect.ImmutableMap;
    import jakarta.validation.Valid;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    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;

    /**
     * 控制层：Revenue
     *
     * @author: yyt
     * 2024-04-09
     */
    @RestController
    @RequestMapping("/internal/revenue")
    public class RevenueInternalController extends BaseInternalController {

        @Autowired
        private PropertyInternalService propertyInternalService;
        @Autowired
        private IRevenueOtbRevenueService revenueOtbRevenueService;
        @Autowired
        private IRevenueDailySummaryGroupPickupService revenueDailySummaryGroupPickupService;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

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

        /**
         * 保存采集的 Banquet 和 F&B OTB Revenue
         *
         * @param tenant   租户标识
         * @param property 资产标识
         * @param data    采集数据
         * @param sign     签名
         * @return {}
         * @author yyt
         * @date 2024/4/9
         **/
        @PutMapping("/banquet-fb")
        public Map saveBanquetAndFBOTBRevenue(@RequestParam String tenant, @RequestParam String property,
                                              @RequestBody List<@Valid BanquetAndFBOTBRevenueBO> data, @RequestHeader String sign) {
            if (CollectionUtils.isEmpty(data)) {
                throw new BadRequestException(CommonErrorI18nConstant.CANNOT_EMPTY,
                        i18nMessageUtils.getErrorParamMapNotNeedTranslate("data"),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the data must not be empty");
            }

            checkIntranetParams(authKey, sign, tenant, property);

            // 处理数据
            PropertyDTO propertyDTO = propertyInternalService.getOne(property, tenant);
            revenueOtbRevenueService.saveBanquetAndFBOTBRevenue(propertyDTO, data, 0);

            return Collections.emptyMap();
        }

        /**
         * 保存采集 Group Pickup
         *
         * @param sign               签名（租户，资产，密钥）
         * @param tenant             租户标识
         * @param property           资产标识
         * @param groupPickupDTOList group pickup 数据
         * @return {}
         * @author yyt
         * @date 2025/7/7
         **/
        @PostMapping("/group-pickup")
        public Map<String, Object> saveGroupPickup(@RequestHeader String sign, @RequestParam String tenant, @RequestParam String property,
                                                   @RequestBody List<@Valid GroupPickupDTO> groupPickupDTOList) {
            if (CollectionUtils.isEmpty(groupPickupDTOList)) {
                throw new BadRequestException(CommonErrorI18nConstant.CANNOT_EMPTY,
                        i18nMessageUtils.getErrorParamMapNotNeedTranslate("groupPickupDTOList"),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the groupPickupDTOList must not be empty");
            }

            checkIntranetParams(authKey, sign, tenant, property);

            // 处理数据
            PropertyDTO propertyDTO = propertyInternalService.getOne(property, tenant);
            revenueDailySummaryGroupPickupService.saveGroupPickupData(propertyDTO, groupPickupDTOList);

            return Collections.emptyMap();
        }

        /**
         * 获取指定规则的日期（去年同期、来年同期）
         *
         * @param sign     签名（租户，资产，密钥）
         * @param tenant   租户标识
         * @param property 资产标识
         * @param query    查询条件
         * @return 指定规则的日期（去年同期、来年同期）
         * @author yyt
         * @date 2025/7/7
         **/
        @GetMapping("/rule-date")
        public Map<String, Object> getRuleDate(@RequestHeader String sign, @RequestParam String tenant, @RequestParam String property, @Valid RuleDateQuery query) {
            checkIntranetParams(authKey, sign, tenant, property);

            Integer type = query.getType();
            if (type == RuleDateQuery.TYPE_LAST_YEAR) {
                return ImmutableMap.of("ruleDate", Integer.parseInt(DateTimeUtils.localDateToStr(DateTimeUtils.getSameDateLastYear(DateTimeUtils.strToLocalDate(query.getDate(),
                        BaseConstant.DATE_FORMAT_YYYYMMDD)), BaseConstant.DATE_FORMAT_YYYYMMDD)));
            } else {
                return ImmutableMap.of("ruleDate", Integer.parseInt(DateTimeUtils.localDateToStr(DateTimeUtils.getSameDateNextYear(DateTimeUtils.strToLocalDate(query.getDate(),
                        BaseConstant.DATE_FORMAT_YYYYMMDD)), BaseConstant.DATE_FORMAT_YYYYMMDD)));
            }
        }

    }