package com.miaxis.pc.controller.question;

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.utils.poi.ExcelUtil;
import com.miaxis.traffic.domain.TrafficSignClass;
import com.miaxis.traffic.service.ITrafficSignClassService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【标示分类】Controller
 *
 * @author miaxis
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/traffic/class")
@Api(tags={"【PC-标示分类】"})
public class PcTrafficSignClassController extends BaseController{
    @Autowired
    private ITrafficSignClassService trafficSignClassService;

    /**
     * 查询标示分类列表
     */
    @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<TrafficSignClass> list(@ModelAttribute TrafficSignClass trafficSignClass){
        startPage();
        List<TrafficSignClass> list = trafficSignClassService.selectTrafficSignClassList(trafficSignClass);
        return toResponsePageInfo(list);
    }
    
    /**
     * 导出标示分类列表
     */
    @GetMapping("/export")
    @ApiOperation("导出标示分类列表Excel")
    public Response<String> export(@ModelAttribute TrafficSignClass trafficSignClass){
        List<TrafficSignClass> list = trafficSignClassService.selectTrafficSignClassList(trafficSignClass);
        ExcelUtil<TrafficSignClass> util = new ExcelUtil<TrafficSignClass>(TrafficSignClass.class);
        return util.exportExcel(list, "class");
    }

    /**
     * 获取标示分类详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取标示分类详细信息")
    public Response<TrafficSignClass> getInfo(
            @ApiParam(name = "id", value = "标示分类参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(trafficSignClassService.getById(id));
    }

    /**
     * 新增标示分类
     */
    @PostMapping
    @ApiOperation("新增标示分类")
    public Response<Integer> add(@RequestBody TrafficSignClass trafficSignClass){
        return toResponse(trafficSignClassService.save(trafficSignClass) ? 1 : 0);
    }

    /**
     * 修改标示分类
     */
    @PutMapping
    @ApiOperation("修改标示分类")
    public Response<Integer> edit(@RequestBody TrafficSignClass trafficSignClass){
        return toResponse(trafficSignClassService.updateById(trafficSignClass) ? 1 : 0);
    }

    /**
     * 删除标示分类
     */
	@DeleteMapping("/{ids}")
    @ApiOperation("删除标示分类")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "标示分类ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(trafficSignClassService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
