package com.tourism.webadmin.app.website.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.tourism.common.additional.config.ApplicationConfig;
import com.tourism.common.additional.utils.UrlConvertUtils;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.CallResult;
import com.tourism.common.core.object.MyOrderParam;
import com.tourism.common.core.object.ResponseResult;
import com.tourism.common.core.object.TokenData;
import com.tourism.common.core.util.MyCommonUtil;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.common.log.annotation.OperationLog;
import com.tourism.common.log.model.constant.SysOperationLogType;
import com.tourism.webadmin.app.website.dto.PageDto;
import com.tourism.webadmin.back.dto.TourProjectGroupPurchaseApplyDto;
import com.tourism.webadmin.back.model.TourOrder;
import com.tourism.webadmin.back.model.TourProjectGroupPurchaseApply;
import com.tourism.webadmin.back.model.TourProjectGroupPurchaseBanner;
import com.tourism.webadmin.back.model.constant.Enable;
import com.tourism.webadmin.back.service.TourProjectGroupPurchaseApplyService;
import com.tourism.webadmin.back.service.TourProjectGroupPurchaseBannerService;
import com.tourism.webadmin.back.vo.TourProjectGroupPurchaseBannerVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 拼团首页banner接口。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Tag(name = "拼团首页banner接口")
@Slf4j
@RestController
@RequestMapping("/website/app/tourProjectGroupPurchaseBanner")
public class WebsiteProjectGroupPurchaseBannerController {

    @Autowired
    private TourProjectGroupPurchaseBannerService tourProjectGroupPurchaseBannerService;
    @Autowired
    private ApplicationConfig applicationConfig;

    /**
     * 获取拼团Banner列表数据。
     *
     * @return 应答结果对象，获取拼团Banner列表数据。
     */
    @SaIgnore
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/list")
    public ResponseResult<List<TourProjectGroupPurchaseBannerVo>> list() {
        TourProjectGroupPurchaseBanner tourProjectGroupPurchaseBanner = new TourProjectGroupPurchaseBanner();
        tourProjectGroupPurchaseBanner.setEnable(Enable.ENABLE_YES);
        MyOrderParam myOrderParam = new MyOrderParam();
        myOrderParam.add(new MyOrderParam.OrderInfo("showOrder", true, null));
        myOrderParam.add(new MyOrderParam.OrderInfo("createTime", false, null));
        String orderBy = MyOrderParam.buildOrderBy(myOrderParam, TourProjectGroupPurchaseBanner.class);
        List<TourProjectGroupPurchaseBanner> tourProjectGroupPurchaseBannerList =
                tourProjectGroupPurchaseBannerService.getTourProjectGroupPurchaseBannerList(tourProjectGroupPurchaseBanner, orderBy);
        List<TourProjectGroupPurchaseBannerVo> tourProjectGroupPurchaseBannerVos =
                MyModelUtil.copyCollectionTo(tourProjectGroupPurchaseBannerList, TourProjectGroupPurchaseBannerVo.class);
        for(TourProjectGroupPurchaseBannerVo i: tourProjectGroupPurchaseBannerVos){
            i.setImgUrlAfterConvert(UrlConvertUtils.urlConvertSingle(applicationConfig.getHostIpPort(), i.getImgUrl()));
        }
        return ResponseResult.success(tourProjectGroupPurchaseBannerVos);
    }
}
