package com.miaxis.pc.controller.carousel;

import com.miaxis.carousel.domain.HomePageDataInfo;
import com.miaxis.carousel.service.IHomePageDataInfoService;
import com.miaxis.carousel.vo.HomePageDataInfoVo;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【首页数据】Controller
 *
 * @author miaxis
 * @date 2021-03-11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/pc/homePage")
@Api(tags={"【pc-首页数据】"})
public class HomePageDataInfoController extends BaseController{

    private final IHomePageDataInfoService homePageDataInfoService;

    /**
     * 查询首页数据列表
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:list')")
    @GetMapping("/list")
    @ApiOperation("查询首页数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<HomePageDataInfoVo> list(@ModelAttribute HomePageDataInfo homePageDataInfo){
        startPage();
        List<HomePageDataInfoVo> list = homePageDataInfoService.selectHomePageDataInfoList(homePageDataInfo);
        return toResponsePageInfo(list);
    }


    /**
     * 新增首页数据
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:add')")
    @Log(title = "首页数据", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增首页数据")
    public Response add(@RequestBody HomePageDataInfo homePageDataInfo){

        return homePageDataInfoService.saveHomePageDataInfo(homePageDataInfo);
    }

    /**
     * 获取首页数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取首页数据详细信息")
    public Response<HomePageDataInfoVo> getHomePageDataInfo(
            @ApiParam(name = "id", value = "首页数据id", required = true)
            @PathVariable("id") Long id
    ) {
        return homePageDataInfoService.getHomePageDataById(id);
    }

    /**
     * 修改首页数据
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:edit')")
    @Log(title = "首页数据", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改首页数据")
    public Response<Integer> edit(@RequestBody HomePageDataInfo homePageDataInfo) {
        return homePageDataInfoService.updateHomePageDataInfoById(homePageDataInfo);
    }


    /**
     * 删除首页数据(伪删除)
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:remove')")
    @Log(title = "首页数据", businessType = BusinessTypeEnum.UPDATE)
	@PutMapping("/{ids}")
    @ApiOperation("删除首页数据")
    public  Response remove(
            @ApiParam(name = "ids", value = "首页数据ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return homePageDataInfoService.removeCarouselByIds(ids);
    }

    /**
     * 同步全部数据 数据库->缓存
     */
    @Log(title = "首页数据", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/synchro")
    @ApiOperation("同步数据")
    public Response synchroData(){
        return homePageDataInfoService.synchroData();
    }


}
