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.impl.GoblinFrontBannerServiceImpl;
import com.liquidnet.client.admin.zhengzai.goblin.service.impl.GoblinFrontHotWordServiceImpl;
import com.liquidnet.client.admin.zhengzai.goblin.service.impl.GoblinFrontNavigationServiceImpl;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.param.GoblinFrontBannerBuildParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
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;
    @Autowired
    GoblinFrontHotWordServiceImpl goblinFrontHotWordService;
    @Autowired
    GoblinFrontNavigationServiceImpl goblinFrontNavigationService;
    /**
     * @author zhangfuxin
     * @Description:添加banner
     * @date 2021/12/27 下午1:22
     */
    @PostMapping("create")
    @ApiOperation(value = "增加banner")
    @ResponseBody
    public AjaxResult create(@RequestBody GoblinFrontBannerBuildParam goblinFrontBannerBuildParam) {
        GoblinFrontBanner goblinFrontBanner=new GoblinFrontBanner();
        BeanUtils.copyProperties(goblinFrontBannerBuildParam,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 GoblinFrontBannerBuildParam goblinFrontBannerBuildParam) {
        GoblinFrontBanner goblinFrontBanner=new GoblinFrontBanner();
        BeanUtils.copyProperties(goblinFrontBannerBuildParam,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 GoblinFrontBannerBuildParam goblinFrontBannerBuildParam) {
        GoblinFrontBanner goblinFrontBanner=new GoblinFrontBanner();
        BeanUtils.copyProperties(goblinFrontBannerBuildParam,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 GoblinFrontBannerBuildParam goblinFrontBannerBuildParam) {
        GoblinFrontBanner goblinFrontBanner=new GoblinFrontBanner();
        BeanUtils.copyProperties(goblinFrontBannerBuildParam,goblinFrontBanner);
        logger.info("查看详情{}", 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  GoblinFrontBannerBuildParam goblinFrontBannerBuildParam) {
        GoblinFrontBanner goblinFrontBanner=new GoblinFrontBanner();
        BeanUtils.copyProperties(goblinFrontBannerBuildParam,goblinFrontBanner);
        logger.info("分页banner{}", JSON.toJSONString(goblinFrontBanner));
        return AjaxResult.success(goblinFrontBannerService.bannerPage(pageSize,pageNumber,null));
    }

    @PostMapping("online")
    @ApiOperation(value = "上线")
    @ResponseBody
    public AjaxResult online( ) {
        logger.info("上线操作");
        boolean bannerResult=goblinFrontBannerService.online();
        logger.info("bannerResult,{}",bannerResult);
        boolean hotWordResult=goblinFrontHotWordService.online();
        logger.info("hotWordResult,{}",hotWordResult);
        boolean navigationResult=goblinFrontNavigationService.online();
        logger.info("navigationResult,{}",navigationResult);
        if (bannerResult&&hotWordResult&&navigationResult ) {
            return success("操作成功");
        } else {
            return error("操作失败");
        }
    }


}
