package com.sckw.truck.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.sckw.truck.entity.req.BusinessTruckPageListParam;
import com.sckw.truck.entity.req.BusinessTruckReq;
import com.sckw.truck.service.BusinessTruckService;
import com.sckw.core.web.response.HttpResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 车辆管理
 * @author: lt
 * @date: 2024/4/5 15:24
 */
@Validated
@RestController
@RequestMapping("/truck")
public class TruckController {

    @Autowired
    BusinessTruckService businessTruckService;

    /**
     * @desc: 车辆新增
     * @author: lt
     * @date: 2024/4/5 16:50
     */
    @PostMapping(value = "/truckInsert")
    public HttpResult truckInsert(@RequestBody @Valid BusinessTruckReq businessTruckReq)
    {
        return businessTruckService.truckInsert(businessTruckReq);
    }

    /**
     * @desc: 车辆更新
     * @author: lt
     * @date: 2024/4/5  15:48
     */
    @PostMapping(value = "/truckUpdate")
    public  HttpResult truckUpdate(@RequestBody BusinessTruckReq businessTruckReq)
    {
        if (ObjectUtils.isNull(businessTruckReq.getId())){
            return HttpResult.error("缺少参数id");
        }
        return businessTruckService.truckUpdate(businessTruckReq);
    }

    /**
     * 删除
     */
    @PostMapping(value = "/truckDelete")
    public HttpResult delete(@RequestParam("id") String id){
        return businessTruckService.truckDelete(id);
    }

    /**
     * @desc: 分页列表
     * @author: lt
     * @date: 2024/4/5 17:05
     */
    @PostMapping(value = "/truckPageList")
    public HttpResult truckPageList(@RequestBody BusinessTruckPageListParam businessTruckPageListParam)
    {
        return businessTruckService.truckPageList(businessTruckPageListParam);
    }

    /**
     * @desc: 根据ID获取 车辆详情
     * @author: lt
     * @date: 2024/4/7 14:13
     */
    @GetMapping(value = "/getTruckDetailById")
    public HttpResult truckDetailById(@RequestParam("id") String id)
    {
        return HttpResult.ok( businessTruckService.truckDetailById(id));
    }

    /**
     * @desc: 获取车辆类型
     * @author: lt
     * @date: 2024/4/7 14:41
     */
    @GetMapping(value = "/getTruckTypeList")
    public HttpResult truckTypeList()
    {
        return HttpResult.ok( businessTruckService.truckTypeList());
    }

    /**
     * @desc: 获取车辆能源类型
     * @author: lt
     * @date: 2024/4/7 14:41
     */
    @GetMapping(value = "/getTruckEnergyList")
    public HttpResult truckEnergyList()
    {
        return HttpResult.ok( businessTruckService.truckEnergyList());
    }


}
