package com.zd.airbottle.controller;

import com.zd.airbottle.domain.QpTransportCar;
import com.zd.airbottle.domain.dto.QpTransportCarDto;
import com.zd.airbottle.domain.vo.QpTransportCarVo;
import com.zd.airbottle.service.IQpTransportCarService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 运输车辆Controller
 */
@RestController
@Api(tags = "【运输车辆】")
@RequestMapping("/car")
public class QpTransportCarController extends BaseController<QpTransportCar> {
    @Autowired
    private IQpTransportCarService qpTransportCarService;

    /**
     * 查询运输车辆列表
     */
    @GetMapping("/list")
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @ApiOperation(value = "查询运输车辆列表")
    public ResultData<List<QpTransportCarVo>> list(QpTransportCar qpTransportCar) {
        return ResultData.success(qpTransportCarService.getCarList(qpTransportCar));
    }

    /**
     * 供应商端运输车辆列表
     */
    @GetMapping("/supplier/list")
    @ApiOperation(value = "供应商端运输车辆列表")
    public ResultData<List<QpTransportCarVo>> supplierList(QpTransportCar qpTransportCar) {
        return ResultData.success(qpTransportCarService.getSupplierCarList(qpTransportCar));
    }

    /**
     * 待审核运输车辆列表
     */
    @GetMapping("/checkList")
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @ApiOperation(value = "待审核运输车辆列表")
    public TableDataInfo<QpTransportCarVo> checkList(QpTransportCar transportCar) {
        startPage("create_time", null);
        List<QpTransportCar> list = qpTransportCarService.checkList(transportCar);
        TableDataInfo<QpTransportCar> dataTable = getDataTable(list);
        TableDataInfo<QpTransportCarVo> dataInfo = new TableDataInfo<>();
        BeanUtils.copyProperties(dataTable, dataInfo);
        if (!list.isEmpty()) {
            List<QpTransportCarVo> carVos = qpTransportCarService.getListVo(list);
            dataInfo.setRows(carVos);
        }
        return dataInfo;
    }

    /**
     * 获取运输车辆详细信息
     */
    @ApiOperation(value = "获取运输车辆详细信息")
    @GetMapping(value = "/{id}")
    public ResultData<QpTransportCarVo> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(qpTransportCarService.selectQpTransportCarById(id));
    }

    /**
     * 新增运输车辆
     */
    @ApiOperation(value = "新增运输车辆")
    @Log(title = "运输车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData<Boolean> add(@RequestBody QpTransportCarDto transportCarDto) {
        return ResultData.result(qpTransportCarService.insertQpTransportCar(transportCarDto));
    }

    /**
     * 修改运输车辆
     */
    @ApiOperation(value = "修改运输车辆")
    @Log(title = "运输车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData<Boolean> edit(@RequestBody QpTransportCarDto transportCarDto) {
        return ResultData.result(qpTransportCarService.editQpTransportCar(transportCarDto));
    }

    /**
     * 删除运输车辆
     */
    @ApiOperation(value = "删除运输车辆")
    @PreAuthorize(hasPermi = "airbottle:supplier:remove")
    @Log(title = "运输车辆", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData<Boolean> remove(@PathVariable Long[] ids) {
        return ResultData.result(qpTransportCarService.deleteQpTransportCarByIds(ids));
    }
}
