package com.prolog.cs.biz.inbound.controller.failure;

import com.prolog.cs.biz.inbound.dto.PageParam;
import com.prolog.cs.biz.inbound.dto.failure.ExceptionCascadeDTO;
import com.prolog.cs.biz.inbound.dto.failure.ExceptionHQueryDTO;
import com.prolog.cs.biz.inbound.dto.failure.ExceptionHQueryVO;
import com.prolog.cs.biz.inbound.dto.failure.ExceptionLinesDTO;
import com.prolog.cs.biz.inbound.dto.rcv.RcvHDTO;
import com.prolog.cs.biz.inbound.dto.task.TaskExceptionDetailDTO;
import com.prolog.cs.biz.inbound.service.failure.ExceptionHeadersService;
import com.prolog.cs.biz.inbound.vo.RcvQueryVO;
import com.prolog.cs.biz.inbound.vo.task.TaskQueryVO;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 错误收货单头控制类
 * @Date 2021-03-24
 */

@Api(tags = "异常单")
@RestController
@RequestMapping("/exceptionHeaders")
public class ExceptionHeadersController {

	@Resource
	private ExceptionHeadersService exceptionHeadersService;

	/**
	 * 保存收货处理错误单头
	 */
	@ApiOperation("保存异常处理单(级联保存)")
	@PostMapping("/v1/add")
	@UserLog("保存异常处理单(级联保存)")
	public RestMessage<Object> addWithRelated(@RequestBody ExceptionCascadeDTO cascadeDTO) {
		return RestMessage.newInstance(true, "addWithRelated", exceptionHeadersService.addWithRelated(cascadeDTO));
	}

	/**
	 * 详情异常头表(主键id)
	 */
	@ApiOperation("详情异常头表(主键id)")
	@UserLog("详情异常头表(主键id)")
	@GetMapping("/v1/findByPkId")
	public RestMessage<ExceptionHQueryDTO> findByPkId(String pkId) {
		return RestMessage.newInstance(true, "findByPkIdSuccess", exceptionHeadersService.findByPkId(pkId));
	}

	/**
	 * 条件分页查
	 */
	@UserLog("异常头表条件分页查")
	@ApiOperation("条件分页查")
	@GetMapping("/v1/page")
	public RestMessage<Page<ExceptionHQueryDTO>> list(ExceptionHQueryVO queryVO) throws Exception {
		return RestMessage.newInstance(true, "pageSuccess", exceptionHeadersService.findPage(queryVO));
	}

	/**
	 * 提取池中的任务
	 */
	@UserLog("异常头表异常池任务提取")
	@ApiOperation("提取异常池中的任务(条件分页)")
	@GetMapping("/v1/extractTask")
	public RestMessage<Page<TaskExceptionDetailDTO>> extractTask(TaskQueryVO taskQueryVO, PageParam pageParam) {
		return RestMessage.newInstance(true, "extractTask",
				exceptionHeadersService.extractTask(taskQueryVO, pageParam));
	}

	/**
	 * 找寻任务的rcv头表
	 */
	@UserLog("异常头表提取待异常处理的rcv头表")
	@ApiOperation("提取待异常处理的rcv头表")
	@GetMapping("/v1/extractRcvH")
	public RestMessage<Page<RcvHDTO>> extractRcvH(RcvQueryVO rcvQueryVO, PageParam pageParam) {
		return RestMessage.newInstance(true, "extractRcvH",
				exceptionHeadersService.extractRcvHAndPro(rcvQueryVO, pageParam));
	}

	/**
	 * 批号错误驳回
	 */
	@ApiOperation("批号错误驳回")
	@PostMapping("/v1/rejectLotNo")
	@UserLog("批号错误驳回")
	public RestMessage<Object> rejectLotNo(@RequestBody List<ExceptionLinesDTO> ExceptionLineList) {
		return RestMessage.newInstance(true, "rejectLotNo", exceptionHeadersService.rejectLotNo(ExceptionLineList));
	}
	/**
	 * 
	 * 异常取消
	 */
	@ApiOperation("异常取消")
	@PostMapping("/v1/cancel")
	@UserLog("异常取消")
	public RestMessage<Object> cancel(@RequestBody List<ExceptionLinesDTO> ExceptionLineList) {
		return RestMessage.newInstance(true, "cancel", exceptionHeadersService.cancel(ExceptionLineList));
	}

	/**
	 * 判断批次是否有库存记录
	 */
	@ApiOperation("判断批次是否有库存记录")
	@GetMapping("/v1/hasInstock")
	@UserLog("判断批次是否有库存记录")
	public RestMessage<Object> hasInstock(String batchIdOld,String warehouseId) {
		return RestMessage.newInstance(true, "hasInstock", exceptionHeadersService.hasInstock(batchIdOld,warehouseId));
	}
}
