package com.zd.airbottle.controller;

import com.zd.airbottle.domain.QpTransportUser;
import com.zd.airbottle.domain.dto.QpTransportUserDto;
import com.zd.airbottle.domain.vo.QpTransportUserVo;
import com.zd.airbottle.service.IQpTransportUserService;
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("/user")
public class QpTransportUserController extends BaseController<QpTransportUser> {
    @Autowired
    private IQpTransportUserService qpTransportUserService;

    /**
     * 查询运输人员列表
     */
    @GetMapping("/list")
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @ApiOperation(value = "查询运输人员列表")
    public ResultData<List<QpTransportUserVo>> list(QpTransportUser qpTransportUser) {
        return ResultData.success(qpTransportUserService.getTransportUserList(qpTransportUser));
    }

    /**
     * 供应商端查询运输人员列表
     */
    @GetMapping("/supplier/list")
    @ApiOperation(value = "供应商端查询运输人员列表")
    public ResultData<List<QpTransportUserVo>> supplierList(QpTransportUser qpTransportUser) {
        return ResultData.success(qpTransportUserService.getSupplierUserList(qpTransportUser));
    }

    /**
     * 审核运输人员列表
     */
    @GetMapping("/checkList")
    @PreAuthorize(hasPermi = "airbottle:supplier:list")
    @ApiOperation(value = "审核运输人员列表")
    public TableDataInfo<QpTransportUserVo> checkList(QpTransportUser transportUser) {
        startPage("create_time", null);
        List<QpTransportUser> list = qpTransportUserService.checkList(transportUser);
        TableDataInfo<QpTransportUser> dataTable = getDataTable(list);
        TableDataInfo<QpTransportUserVo> dataInfo = new TableDataInfo<>();
        BeanUtils.copyProperties(dataTable, dataInfo);
        if (!list.isEmpty()) {
            List<QpTransportUserVo> userVos = qpTransportUserService.getListVo(list);
            dataInfo.setRows(userVos);
        }

        return dataInfo;
    }

    /**
     * 获取运输人员详细信息
     */
    @ApiOperation(value = "获取运输人员详细信息")
    @GetMapping(value = "/{id}")
    public ResultData<QpTransportUserVo> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(qpTransportUserService.selectQpTransportUserById(id));
    }

    /**
     * 新增运输人员
     */
    @ApiOperation(value = "新增运输人员")
    @Log(title = "运输人员", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData<Boolean> add(@RequestBody QpTransportUserDto transportUserDto) {
        return ResultData.result(qpTransportUserService.insertQpTransportUser(transportUserDto));
    }

    /**
     * 修改运输人员
     */
    @ApiOperation(value = "修改运输人员")
    @Log(title = "运输人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData<Boolean> edit(@RequestBody QpTransportUserDto transportUserDto) {
        return ResultData.result(qpTransportUserService.edit(transportUserDto));
    }

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