
package com.tmerclub.cloud.platform.controller.multishop;

import com.tmerclub.cloud.api.platform.constant.OfflineHandleEventType;
import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.platform.service.OfflineHandleEventService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Author lth
 * @Date 2021/5/24 18:26
 */
@RestController("multishopOfflineHandleEventController")
@RequestMapping("/m/offline_handle_event")
@Tag(name = "multishop-下线处理事件信息")
public class OfflineHandleEventController {

    @Autowired
    private OfflineHandleEventService offlineHandleEventService;

    @GetMapping("/get_event_info")
    @Operation(summary = "通过店铺id获取下线信息", description = "通过店铺id获取下线信息")
    public ServerResponseEntity<OfflineHandleEventVO> getOfflineHandleEventByShopId() {
        Long shopId = AuthUserContext.get().getTenantId();
        if (Objects.equals(shopId, Constant.DEFAULT_SHOP_ID)) {
            return ServerResponseEntity.success();
        }
        Integer sysType = AuthUserContext.get().getSysType();
        OfflineHandleEventVO offlineHandleEvent = offlineHandleEventService.getProcessingEventByHandleTypeAndHandleId(OfflineHandleEventType.SHOP.getValue(), shopId, sysType);
        return ServerResponseEntity.success(offlineHandleEvent);
    }
}
