package com.css.simulation.resource.server.adapter.controller.model_library.dynamic_configuration;

import api.common.pojo.common.ResponseBodyVO;
import api.common.pojo.param.model.VehiclePageParam;
import api.common.pojo.po.model.VehicleTempPO;
import api.common.pojo.vo.model.VehicleTempVO;
import com.css.simulation.resource.server.app.service.VehicleTempService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/vehicleTemp")
@PreAuthorize("@AuthorityCheck.admin()")
public class VehicleTemplateController {

    @Resource
    private VehicleTempService vehicleTempService;

    /**
     * 获取车辆模型下拉
     */
    @RequestMapping("/getVehicleTempTree")
    @ResponseBody
    @PreAuthorize("true")
    public ResponseBodyVO<List> getVehicleList() {
        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,vehicleTempService.getVehicleTempTree());
    }

    /**
     * 获取列表
     */
    @RequestMapping("/getVehicleTempPageList")
    @ResponseBody
    public ResponseBodyVO<PageInfo<VehicleTempVO>> getVehicleTempPageList(@RequestBody VehiclePageParam pageParam) {
        ResponseBodyVO<PageInfo<VehicleTempVO>> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(vehicleTempService.getVehicleTempPageList(pageParam));
        return response;
    }

    /**
     * 根据id获取详情
     */
    @RequestMapping("/getVehicleTempInfo")
    @ResponseBody
    public ResponseBodyVO<VehicleTempVO> getVehicleTempInfo(@RequestBody VehiclePageParam param) {
        ResponseBodyVO<VehicleTempVO> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
        response.setInfo(vehicleTempService.getVehicleTempInfo(param));
        return response;
    }

    /**
     * 新增、修改
     */
    @RequestMapping("/saveVehicleTemp")
    @ResponseBody
    public ResponseBodyVO<VehicleTempPO> saveVehicleTemp(@RequestBody VehicleTempPO po) {
        return  vehicleTempService.saveVehicleTemplate(po);
    }

    /**
     * 删除
     */
    @RequestMapping("/delVehicleTempById")
    @ResponseBody
    public ResponseBodyVO delVehicleTempById(@RequestBody VehicleTempPO po) {
        int i = vehicleTempService.delVehicleTempById(po);
        if (i > 0) {
            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
        } else {
            return new ResponseBodyVO(false, 500, "删除失败！", null);
        }
    }
}
