AdMgrController.java 2.36 KB
package com.glsx.controller;

import cn.com.glsx.openplatform.model.PlatformAd;
import cn.com.glsx.openplatform.service.AdMgrService;
import cn.com.glsx.openplatform.vo.R;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.oreframework.web.ui.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@Api
@RestController
@RequestMapping(value = "/admgr")
public class AdMgrController {
    /**
     * 日志
     */
    private final static Logger LOGGER = LoggerFactory.getLogger(AdMgrController.class);

    @Autowired
    private AdMgrService adMgrService;

    @RequestMapping(value = "/getAdMgrList", method = RequestMethod.GET)
    @ResponseBody
    public R getAdMgrList(Pagination pagination) {
        //PageHelper注入分页和要分页的查询之前不能有其它查询,不然分页到第一个查询上面
        Page<PlatformAd> page = PageHelper.startPage(pagination.getCurrentPage(), pagination.getPageSize(), true);

        List<PlatformAd> adMgrList = adMgrService.getAdMgrList();

        return R.ok().putPageData(page, adMgrList);
    }

    @RequestMapping(value = "/insertAd", method = RequestMethod.POST)
    @ResponseBody
    public R insertAd(PlatformAd ad) {
        int num = adMgrService.insertAd(ad);
        if (num == 0) {
            return R.error("新增广告失败");
        }
        return R.ok("新增广告成功");
    }

    @RequestMapping(value = "/updateAd", method = RequestMethod.POST)
    @ResponseBody
    public R updateAd(PlatformAd ad) {
        int num = adMgrService.updateAd(ad);
        if (num == 0) {
            return R.error("编辑广告失败");
        }
        return R.ok("编辑广告成功");
    }


    @RequestMapping(value = "/startandstop", method = RequestMethod.GET)
    @ResponseBody
    public R startandstop(int id, int status) {
        int num = adMgrService.startandstop(id, status);
        if (num == 0) {
            return R.error("修改广告投放状态失败");
        }
        return R.ok("修改广告投放状态成功");
    }
}