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

import com.prolog.cs.biz.inbound.dto.failure.RcvErrorDTO;
import com.prolog.cs.biz.inbound.dto.failure.RcvErrorQueryVO;
import com.prolog.cs.biz.inbound.model.failure.InReceivingAbnormalD;
import com.prolog.cs.biz.inbound.model.failure.InReceivingAbnormalH;
import com.prolog.cs.biz.inbound.service.failure.InReceivingAbnormalHService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * xiong 20220127 头表明细一起处理
 */
@Api(tags = "收货异常管理")
@RestController
@RequestMapping("/rcvError")
public class InReceivingAbnormalHController {

	@Resource
	private InReceivingAbnormalHService service;

	private final static String operateMsg = "操作成功!";

	/**
	 * 关键点: 
	 * 1. 若是收货的异常提取,是不是用查询服务关联查询会更好?(查询服务提供头表以及明细的查询) 
	 * 2. 是不是普通收货提取时需要把这一部分中的异常明细的数量排除,防止超收.(修改查询服务相关提取sql)
	 * 3. 区分billid和refbillid的含义,哪个是收货单,哪个是asn单的id,收货异常的处理是产生不了入库收货单的
	 * 4. 入库单提取的时候需要排除这部分数据,需要修改相关的查询服务
	 */

	/**
	 * 新增(关联明细数据)
	 */
	@ApiOperation("新增(级联)")
	@PostMapping("/v1/add")
	public RestMessage<Object> addWithRelated(@RequestBody RcvErrorDTO rcvErrorDTO) {
		return RestMessage.newInstance(true, operateMsg, service.addWithRelated(rcvErrorDTO));
	}

	/**
	 * 删除
	 */
	@ApiOperation("删除(级联)")
	@PostMapping("/v1/del")
	public RestMessage<Object> delWithRelated(@RequestBody RcvErrorQueryVO queryVO) {
		return RestMessage.newInstance(true, operateMsg, service.delWithRelated(queryVO));
	}

	/**
	 * 编辑(先删除明细,再保存明细)
	 */
	@ApiOperation("编辑(级联)")
	@PostMapping("/v1/edit")
	public RestMessage<Object> editWithRelated(@RequestBody RcvErrorDTO rcvErrorDTO) {
		return RestMessage.newInstance(true, operateMsg, service.editWithRelated(rcvErrorDTO));
	}

	/**
	 * 条件分页
	 */
	@ApiOperation("条件分页")
	@PostMapping("/v1/page")
	public RestMessage<Page<InReceivingAbnormalH>> page(@RequestBody RcvErrorQueryVO queryVO) {
		return RestMessage.newInstance(true, operateMsg, service.page(queryVO));
	}

	/**
	 * 条件查询全部
	 */
	@ApiOperation("条件分页")
	@PostMapping("/v1/findAll")
	public RestMessage<List<InReceivingAbnormalH>> findAll(@RequestBody RcvErrorQueryVO queryVO) {
		return RestMessage.newInstance(true, operateMsg, service.findAll(queryVO));
	}

	/**
	 * 详情
	 */
	@ApiOperation("条件分页")
	@GetMapping("/v1/findOne")
	public RestMessage<RcvErrorDTO> findOne(String id) {
		return RestMessage.newInstance(true, operateMsg, service.findOne(id));
	}

	/**
	 * 手动回传oms
	 */
	@ApiOperation("手动回传oms")
	@PostMapping("/v1/callToOms")
	public RestMessage<Object> callToOms(@RequestBody RcvErrorQueryVO queryVO) {
		return RestMessage.newInstance(true, operateMsg, service.callToOms(queryVO));
	}

	/**
	 * 查询收货异常明细
	 */
	@ApiOperation("查询收货异常明细")
	@GetMapping("/v1/getDetails")
	public RestMessage<List<InReceivingAbnormalD>> getDetails(String id) {
		return RestMessage.newInstance(true, operateMsg, service.getDetails(id));
	}
}
