package com.miaxis.pc.controller.topic;

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 com.miaxis.topic.domain.TopicInfo;
import com.miaxis.topic.dto.TopicInfoDto;
import com.miaxis.topic.service.ITopicInfoService;
import com.miaxis.topic.vo.TopicInfoVo;
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("/topic/info")
@Api(tags={"【pc-专题管理】"})
public class TopicInfoController extends BaseController{

    private final ITopicInfoService topicInfoService;

    /**
     * 查询专题列表
     */
    @PreAuthorize("@ss.hasPermi('topic:info: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<TopicInfoVo> list(@ModelAttribute TopicInfoVo topicInfoVo){
        startPage();
        List<TopicInfoVo> list = topicInfoService.selectTopicInfoList(topicInfoVo);
        return toResponsePageInfo(list);
    }


    /**
     * 获取专题详细信息
     */
    @PreAuthorize("@ss.hasPermi('topic:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取专题详细信息")
    public Response<TopicInfoVo> getInfo(
            @ApiParam(name = "id", value = "专题参数", required = true)
            @PathVariable("id") Long id
    ){
        return topicInfoService.getTopicById(id);
    }

    /**
     * 新增专题
     */
    @PreAuthorize("@ss.hasPermi('topic:info:add')")
    @Log(title = "专题", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增专题")
    public Response<Integer> add(@RequestBody TopicInfoDto topicInfoDto){
        return topicInfoService.addTopic(topicInfoDto);
    }

    /**
     * 修改专题
     */
    @PreAuthorize("@ss.hasPermi('topic:info:edit')")
    @Log(title = "专题", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改专题")
    public Response<Integer> edit(@RequestBody TopicInfo topicInfo){
        return toResponse(topicInfoService.updateById(topicInfo) ? 1 : 0);
    }

    /**
     * 更新 0：上架 / 1：下架
     */
    @PreAuthorize("@ss.hasPermi('topic:info:updateShelfStatus')")
    @Log(title = "客户信息", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/updateShelfStatus")
    @ApiOperation("上架、下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "客户信息ids参数", dataType = "List", required = true),
            @ApiImplicitParam(name = "shelfStatus", value = "上架状态  0：上架、1：下架", dataType = "int", required = true),
    })
    public Response updateShelfStatus(Long[] ids,Integer shelfStatus) {
        return topicInfoService.updateShelfStatus(ids,shelfStatus);
    }

    /**
     * 删除专题
     */
    @PreAuthorize("@ss.hasPermi('topic:info:remove')")
    @Log(title = "专题", businessType = BusinessTypeEnum.DELETE)
	@PutMapping("/{ids}")
    @ApiOperation("删除专题")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "专题ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return topicInfoService.removeTopicByIds(ids);
    }
}
