package com.prolog.rdc.tms.app.controller.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.business.PendingSubmitQueryDTO;
import com.prolog.rdc.tms.app.model.vo.business.PendingSubmitQueryVO;
import com.prolog.rdc.tms.app.service.business.PendingSubmitService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 待提交控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/7/20 15:45
 */
@RestController
@Api(tags = "业务APP-待提交控制层")
@RequestMapping("/pendingSubmit")
public class PendingSubmitController {

    @Autowired
    private PendingSubmitService pendingSubmitService;

    @UserLog("查询运单")
    @ApiOperation(value = "查询运单", notes = "查询运单")
    @PostMapping("/query_shipbill")
    public RestMessage<Page<PendingSubmitQueryDTO>> queryShipbillExecute(@RequestBody PendingSubmitQueryVO pendingSubmitQueryVO) {
        Page<PendingSubmitQueryDTO> list = pendingSubmitService.queryShipbillData(pendingSubmitQueryVO);
        return RestMessage.newInstance(true, "查询成功！", list);
    }

    @UserLog("运单接单")
    @ApiOperation(value = "运单接单", notes = "运单接单")
    @PostMapping("/receive")
    public RestMessage<String> receiveShipbillDataExecute(@RequestBody List<String> ids) {
        try {
            pendingSubmitService.receiveShipbillData(ids);
            return RestMessage.newInstance(true, "操作成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("运单拒绝")
    @ApiOperation(value = "运单拒绝", notes = "运单拒绝")
    @PostMapping("/reject")
    public RestMessage<String> rejectShipbillDataExecute(@RequestBody List<String> ids) {
        try {
            pendingSubmitService.rejectShipbillData(ids);
            return RestMessage.newInstance(true, "操作成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("运单提交")
    @ApiOperation(value = "运单提交", notes = "运单提交")
    @PostMapping("/submit")
    public RestMessage<Object> submitShipbillExecute(@RequestBody List<String> ids) {
        try {
            pendingSubmitService.submitShipbillData(ids);
            return RestMessage.newInstance(true, "操作成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }
}
