package com.liquidnet.client.admin.web.controller.zhengzai.goblin;


import com.alibaba.fastjson.JSON;
import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.zhengzai.goblin.service.imp.GoblinFrontBannerServiceImpl;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author liquidnet
 * @since 2021-12-27
 */

@Api(tags = "banner管理")
@RestController
@RequestMapping("/frontBanner")
public class GoblinFrontBannerController extends BaseController {
    @Autowired
    GoblinFrontBannerServiceImpl goblinFrontBannerService;
    /**
     * @author zhangfuxin
     * @Description:添加banner
     * @date 2021/12/27 下午1:22
     */
    @PostMapping("create")
    @ApiOperation(value = "增加banner")
    @ResponseBody
    public AjaxResult create( @RequestBody GoblinFrontBanner goblinFrontBanner) {
        logger.info("增加banner{}", JSON.toJSONString(goblinFrontBanner));
        boolean result=goblinFrontBannerService.create(goblinFrontBanner);
        if (result ) {
            return success("操作成功");
        } else {
            return error("操作失败");
        }
    }

    @PostMapping("update")
    @ApiOperation(value = "修改banner")
    @ResponseBody
    public AjaxResult update( @RequestBody GoblinFrontBanner goblinFrontBanner) {
        logger.info("修改banner{}", JSON.toJSONString(goblinFrontBanner));
        boolean result=goblinFrontBannerService.update(goblinFrontBanner);
        if (result ) {
            return success("操作成功");
        } else {
            return error("操作失败");
        }
    }
    @PostMapping("delete")
    @ApiOperation(value = "删除banner")
    @ResponseBody
    public AjaxResult delete( @RequestBody GoblinFrontBanner goblinFrontBanner) {
        logger.info("删除banner{}", JSON.toJSONString(goblinFrontBanner));
        boolean result=goblinFrontBannerService.delte(goblinFrontBanner.getMid());
        if (result ) {
            return success("操作成功");
        } else {
            return error("操作失败");
        }
    }
    @PostMapping("getOne")
    @ApiOperation(value = "查看详情")
    @ResponseBody
    public AjaxResult getOne( @RequestBody GoblinFrontBanner goblinFrontBanner) {
        logger.info("修改banner{}", JSON.toJSONString(goblinFrontBanner));
        GoblinFrontBanner goblinFrontBanner1=goblinFrontBannerService.getOne(goblinFrontBanner.getMid());
        return AjaxResult.success(goblinFrontBanner1);
    }
    @PostMapping("page")
    @ApiOperation(value = "分页")
    @ResponseBody
    public AjaxResult page( @RequestParam(name = "pageSize", required = true) int pageSize,@RequestParam(name = "pageNumber", required = true)int pageNumber,@RequestBody GoblinFrontBanner goblinFrontBanner) {
        logger.info("分页banner{}", JSON.toJSONString(goblinFrontBanner));
        return AjaxResult.success(goblinFrontBannerService.bannerPage(pageSize,pageNumber,null));
    }


}
