package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.common.exception.BusinessException;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.domain.entity.main.YcqRollPic;
import com.crunii.micro.service.sysmgr.api.domain.dto.YcqPageRollPicDTO;
import com.crunii.micro.service.sysmgr.api.domain.dto.YcqRollPicDTO;
import com.crunii.micro.service.sysmgr.api.domain.vo.YcqRollPicVO;
import com.crunii.micro.service.sysmgr.dto.sysmgr.AccessPageVo;
import com.crunii.micro.service.sysmgr.service.YcqRollPicService;
import com.crunii.micro.web.mvc.CurrWorker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * 轮播图
 * @author : http://www.chiner.pro
 * @date : 2023-9-27
 */
@Api(tags = "轮播图对象功能接口")
@RestController
@RequestMapping("/auth/ycqRollPic")
public class YcqRollPicController{
    @Autowired
    private YcqRollPicService ycqRollPicService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/queryById/{id}")
    public Result<YcqRollPicVO> queryById(@PathVariable("id") Long id){
        if (null == id){
            throw new BusinessException("invalid param");
        }
        return Result.ofSuccess(ycqRollPicService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param ycqRollPic 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @PostMapping("/pageByCondition")
    public Result<PageRsp<YcqRollPicVO>> pageByCondition(@RequestBody PageReq<YcqPageRollPicDTO> pageRequest){
        return Result.ofSuccess(ycqRollPicService.pageQuery(pageRequest));
    }

    /**
     * 新增数据
     *
     * @param ycqRollPic 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/insert")
    public Result<Boolean> insert(@RequestBody YcqRollPicDTO ycqRollPic,@CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(ycqRollPicService.insert(ycqRollPic, worker.getLoginId()));
    }

    /**
     * 更新数据
     *
     * @param ycqRollPic 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PostMapping("/update")
    public Result<Boolean> update(@Valid @RequestBody YcqRollPicDTO ycqRollPic,@CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(ycqRollPicService.update(ycqRollPic, worker.getLoginId()));
    }

    @ApiOperation("一级类型列表")
    @PostMapping("/getTypeList")
    public Result<List<AccessPageVo>> getTypeList(){
        return Result.ofSuccess(ycqRollPicService.getTypeList());
    }
    @ApiOperation("二级位置列表")
    @PostMapping("/getYcqRollPicByType")
    public Result<YcqRollPic> getYcqRollPicByType(@RequestBody YcqRollPicDTO ycqRollPic){
        return Result.ofSuccess(ycqRollPicService.getYcqRollPicByType(ycqRollPic));
    }
}