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.traffic.domain.TrafficSign;
import com.miaxis.traffic.service.ITrafficSignService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 【标示】Controller
 *
 * @author miaxis
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/traffic/sign")
@Api(tags={"【PC-标示】"})
public class PcTrafficSignController extends BaseController{
    @Autowired
    private ITrafficSignService trafficSignService;

    /**
     * 查询标示列表
     */
    @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<TrafficSign> list(@ModelAttribute TrafficSign trafficSign){
        startPage();
        List<TrafficSign> list = trafficSignService.selectTrafficSignList(trafficSign);
        return toResponsePageInfo(list);
    }
    

    /**
     * 获取标示详细信息
     */
    @PreAuthorize("@ss.hasPermi('traffic:sign:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取标示详细信息")
    public Response<TrafficSign> getInfo(
            @ApiParam(name = "id", value = "标示参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(trafficSignService.getById(id));
    }

    /**
     * 新增标示
     */
    @PostMapping
    @ApiOperation("新增标示")
    public Response<Integer> add(@RequestBody TrafficSign trafficSign){
        return toResponse(trafficSignService.save(trafficSign) ? 1 : 0);
    }

    /**
     * 修改标示
     */
    @PutMapping
    @ApiOperation("修改标示")
    public Response<Integer> edit(@RequestBody TrafficSign trafficSign){
        return toResponse(trafficSignService.updateById(trafficSign) ? 1 : 0);
    }

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