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.UserDTO;
import org.springblade.modules.app.common.dto.WaybillDTO;
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.WaybillManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.app.vo.CarPush;
import org.springblade.modules.app.vo.CarPushVo;
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
 */
@Slf4j
@RestController
@RequestMapping("app/waybill")
@Api(value = "调运单管理", tags = "调运单管理")
public class WaybillController extends BaseController {

    @Autowired
    private WaybillManager waybillManager;

    //@ApiOperation(value = "创建调运单")
    @PostMapping
    public ResponseEntity<ResultDTO<String>> createOrder(@RequestBody WaybillDTO waybillDTO) {
        log.error("data is {}",waybillDTO);
        return success(waybillManager.createWaybill(waybillDTO));
    }

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

    //@ApiOperation(value = "查询调运单详情")
    @GetMapping("/{token}/{id}")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<WaybillDTO>> getWaybillDetail(@PathVariable Long id,@PathVariable String token) {
        return success(waybillManager.getWaybillDetail(id,token));
    }

    //@ApiOperation(value = "养殖场上传附件信息")
    @GetMapping("/submit/picture")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> submitPicture(WaybillDTO waybillDTO) {
        return success(waybillManager.submitPicture(waybillDTO));
    }


    //@ApiOperation(value = "屠宰场确认调运单")
    @PutMapping("approval/slaughter")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> approvalOrderBySlaughter(@RequestBody ApprovalVO approvalVO) {
        return success(waybillManager.approvalOrderBySlaughter(approvalVO));
    }

    //@ApiOperation(value = "审批调运单")
    @PutMapping("approval")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> approvalOrder(@RequestBody ApprovalVO approvalVO) {
        return success(waybillManager.approvalWaybill(approvalVO));
    }

    @PutMapping("top")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> topOrder(@RequestBody ApprovalVO approvalVO) {
        return success(waybillManager.topWaybill(approvalVO));
    }

    @PutMapping("carPush")
    public ResponseEntity<ResultDTO<Boolean>> checkCarPush(@RequestBody CarPushVo carPush) {
        return success(waybillManager.carNoPush(carPush));
    }



    //@ApiOperation(value = "重新提交调运单")
    @PutMapping("/resubmit")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<String>> resubmit(@RequestBody WaybillDTO waybillDTO) {
        return success(waybillManager.resubmit(waybillDTO));
    }

    //@ApiOperation(value = "撤销备案单")
    @PostMapping("/cancel/{id}")
    @ApiImplicitParam(name = "id", value = "备案单id", required = true)
    @DisableLoginVerify
    @ClientLogin
    public ResponseEntity<ResultDTO<Boolean>> cancel(@PathVariable Long id) {
        return success(waybillManager.cancel(id));
    }

    //@ApiOperation(value = "删除备案单")
    @DeleteMapping("/delete/{token}/{id}")
    @ApiImplicitParam(name = "id", value = "备案单id", required = true)
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<Boolean>> delete(@PathVariable String token,@PathVariable Long id) {
        return success(waybillManager.delete(id));
    }
}

