package com.pj.tb_banner;

import cn.hutool.extra.cglib.CglibUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pj.enummj.DeleteStatus;
import com.pj.tb_banner.vo.TbBannerVo;
import com.pj.utils.sg.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
*APP取轮播图
*
* @author loovi
* @date
*/
@RestController
@RequestMapping("/app/TbBanner/")
public class TbBannerAppController {

    @Autowired
    TbBannerService tbBannerService;

    /**
    *APP端获取轮播图
    *
    * @author loovi
    * @date
    */
    @RequestMapping("getList")
    public AjaxJson getList() {
        // 构造获取可用的轮播图条件
        QueryWrapper<TbBanner> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", DeleteStatus.DELETE_STATUS_ON.getCode());
        // 获取轮播图列表
        List<TbBanner> list = tbBannerService.list(queryWrapper);
        // 将结果列表拷贝到轮播图vo列表中
        List<TbBannerVo> resList = CglibUtil.copyList(list, TbBannerVo::new);
        //返回列表
        return AjaxJson.getSuccess("轮播图列表", resList);
    }
}
