package com.jeequan.jeepay.pay.ctrl.advert;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.ctrls.AbstractCtrl;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.db.entity.SysAdvertConfig;
import com.jeequan.jeepay.service.impl.SysAdvertConfigService;
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.List;

/**
 * 广告
 *
 * @author xiaoyu
 *
 * @date 2023/2/21 16:13
 */
@RestController
@RequestMapping("/api/advert")
public class AdvertController extends AbstractCtrl {

    @Autowired SysAdvertConfigService advertConfigService;

    /** 支付后广告 **/
    @GetMapping("")
    public ApiRes afterDevice() {
        Byte appPlace = getValByteDefault("appPlace", SysAdvertConfig.APP_PLACE_LITE);
        // 查询平台全局广告
        LambdaQueryWrapper<SysAdvertConfig> wrapper = SysAdvertConfig.gw();
        wrapper.eq(SysAdvertConfig::getAdvertType, SysAdvertConfig.ADVERT_TYPE_AFTER);
        wrapper.eq(SysAdvertConfig::getReleaseState, CS.YES);
        wrapper.eq(appPlace != null, SysAdvertConfig::getAppPlace, appPlace);
        wrapper.orderByDesc(SysAdvertConfig::getCreatedAt);
        List<SysAdvertConfig> list = advertConfigService.list(wrapper);
        if (list.size() > 0) {
            return ApiRes.ok(list.get(0));
        }
        return ApiRes.ok();
    }


}
