package org.springblade.modules.app.web;


import org.springblade.common.auth.permission.DisableLoginVerify;
import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import org.springblade.modules.app.aspect.ClientLogin;
import org.springblade.modules.app.common.dto.TransportDTO;
import org.springblade.modules.app.common.dto.UserDTO;
import org.springblade.modules.app.common.query.WaybillClientQuery;
import org.springblade.modules.app.common.vo.ApprovalVO;
import org.springblade.modules.app.common.vo.WaybillListVO;
import org.springblade.modules.app.manager.TransportManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 运输单信息 前端控制器
 * </p>
 *
 * @author fuxinsheng
 * @since 2021-11-05
 */
@RestController
@RequestMapping("app/transport")
@Api(value = "运输单管理", tags = "运输单管理")
public class AppTransportController extends BaseController {

    @Autowired
    private TransportManager transportManager;

    //@ApiOperation(value = "创建运输单")
    @PostMapping
    public ResponseEntity<ResultDTO<String>> transport(@RequestBody TransportDTO transportDTO) {
        return success(transportManager.creatTransport(transportDTO));
    }

    //@ApiOperation(value = "查询运输单详情")
    @GetMapping("/{token}/{transportId}")
    public ResponseEntity<ResultDTO<TransportDTO>> getTransportDetail(@PathVariable Long transportId,@PathVariable String token) {
        return success(transportManager.getTransportDetail(transportId,token));
    }

    //@ApiOperation(value = "初始化运输单信息")
    @GetMapping("/init/{token}/{waybillId}")
    public ResponseEntity<ResultDTO<TransportDTO>> initTransport(@PathVariable Long waybillId,@PathVariable String token) {
        return success(transportManager.initTransport(waybillId,token));
    }

    //@ApiOperation(value = "查询运输单列表")
    @GetMapping("/list")
    public ResponseEntity<ResultDTO<List<WaybillListVO>>> getTransportList(WaybillClientQuery waybillClientQuery) {
        return success(transportManager.getTransportList(waybillClientQuery));
    }

    //@ApiOperation(value = "审批运输单")
    @PutMapping("/approval")
    public ResponseEntity<ResultDTO<Boolean>> approvalTransport(@RequestBody ApprovalVO approvalVO) {
        return success(transportManager.approvalTransport(approvalVO));
    }

    //@ApiOperation(value = "重新提交运输单")
    @PutMapping("/resubmit")
    public ResponseEntity<ResultDTO<Boolean>> resubmitTransport(@RequestBody TransportDTO transportDTO) {
        return success(transportManager.resubmitTransport(transportDTO));
    }

    //@ApiOperation(value = "查看调运单码")
    @GetMapping("/out/code/{token}/{transportId}")
    public ResponseEntity<ResultDTO<String>> getOutcode(@PathVariable Long transportId,@PathVariable String token) {
        return success(transportManager.getOutcode(transportId,token));
    }

    //@ApiOperation(value = "撤销运输单")
    @PostMapping("/cancel/{token}/{id}")
    @ApiImplicitParam(name = "id", value = "运输单id", required = true)
    @DisableLoginVerify
    @ClientLogin
    public ResponseEntity<ResultDTO<Boolean>> cancel(@PathVariable Long id,@ApiIgnore UserDTO userDTO) {
        return success(transportManager.cancel(id, userDTO));
    }

    //@ApiOperation(value = "查看检疫码")
    @GetMapping("/verify/code/{transportId}")
    @DisableLoginVerify
    @ClientLogin
    public ResponseEntity<ResultDTO<String>> getVerifycode(@PathVariable Long transportId, @ApiIgnore UserDTO userDTO) {
        return success(transportManager.getVerifycode(transportId, userDTO));
    }
}

