# InternalGroupPickupController.java

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

    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.dto.rateshop.internal.InternalGroupPickupDTO;
    import cloud.wconnect.rateshop.service.rateshop.IGroupPickupService;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.*;

    import java.text.MessageFormat;
    import java.time.LocalDate;
    import java.time.temporal.ChronoUnit;
    import java.util.Collections;
    import java.util.Map;

    /**
     * Internal Controller: 采集 Group Pickup 数据
     *
     * @author zc
     * @date 2024/03/25
     */
    @Slf4j
    @Validated
    @RestController
    @RequestMapping("/internal/group-pickup/collect")
    public class InternalGroupPickupController extends BaseInternalController {

        @Autowired
        private PropertyInternalService propertyInternalService;
        @Autowired
        private IGroupPickupService groupPickupService;
        @Value("${internal.service.auth-key.basic}")
        private String authKey;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

        /**
         * 保存采集运营数据
         *
         * @param tenant         租户标识
         * @param property       资产标识
         * @param sign           签名
         * @param groupPickupDTO group pickup 数据
         * @return empty map
         * @author zc
         * @date 2024/3/25
         */
        @PostMapping
        public Map<Object, Object> saveCollectGroupPickup(String tenant, String property, @RequestHeader String sign,
                                                          @RequestBody InternalGroupPickupDTO groupPickupDTO) {
            log.info("Rate shop internal - save group pickup start, tenant:{}, property:{}", tenant, property);

            // 校验签名
            checkIntranetParams(authKey, sign, tenant, property);

            //校验日期范围
            LocalDate startLocalDate = DateTimeUtils.strToLocalDate(groupPickupDTO.getStartDate().toString(), BaseConstant.DATE_FORMAT_YYYYMMDD);
            LocalDate endLocalDate = DateTimeUtils.strToLocalDate(groupPickupDTO.getEndDate().toString(), BaseConstant.DATE_FORMAT_YYYYMMDD);
            if (startLocalDate.isAfter(endLocalDate)) {
                throw new BadRequestException(CommonErrorI18nConstant.START_DATE_CANNOT_GREATER_THAN_END_DATE,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The startDate cannot be greater than the endDate");
            }

            //校验日期间隔不能大于100天
            long daysBetween = startLocalDate.until(endLocalDate, ChronoUnit.DAYS);
            if (daysBetween > 100) {
                throw new BadRequestException(CommonErrorI18nConstant.SELECT_DATE_LIMIT,
                        i18nMessageUtils.getErrorParamMapNotNeedTranslate(100),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        MessageFormat.format("The startDate and endDate intervals cannot exceed 100 days; startDate:{0}, endDate:{1}",
                                groupPickupDTO.getStartDate(), groupPickupDTO.getEndDate()));
            }

            PropertyDTO propertyDTO = propertyInternalService.getOne(property, tenant);

            groupPickupService.saveCollectGroupPickup(propertyDTO, groupPickupDTO);

            log.info("Rate shop internal - save group pickup end, tenant:{}, property:{}", tenant, property);

            return Collections.emptyMap();
        }
    }