package com.prolog.upcloud.base.wh.operate.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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.log.aop.annotation.UserLog;
import com.prolog.upcloud.base.wh.operate.service.AdjustService;
import com.prolog.upcloud.base.wh.operate.vo.ErpAdjustAddVO;
import com.prolog.upcloud.base.wh.operate.vo.WmsAdjustAddVO;
import com.prolog.upcloud.base.wh.operate.vo.WmsAdjustUpdateVO;

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

/**
 * @author zzz
 * @desc
 * @date 2021/4/9
 */
@Api(tags = "损溢管理")
@RestController
@RequestMapping("adjust")
public class AdjustController {

	@Autowired
	private AdjustService service;

	/**
	 * 无计划损溢
	 * 
	 * @param wmsAdjustAddVO
	 * @return
	 */
	@UserLog
	@ApiOperation(value = "新增无计划损溢")
	@PostMapping("add")
	public RestMessage<?> saveAdjust(@RequestBody WmsAdjustAddVO wmsAdjustAddVO) {
		service.saveAdjust(wmsAdjustAddVO);
		return RestMessage.success("操作成功", null);
	}

	@UserLog
	@ApiOperation(value = "损溢审核(包含有/无计划,仓储审->质管审->回传erp)")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "map", value = "{\"adjustStatus\":\"损溢状态（0：仓储一审 5：质管二审）\",\"adjustType\":\"损溢来源（0：计划盘点 1：无计划盘点 2：WMS调整 3: erp发起）\",\"status\":\"审核类型（0：通过 1：驳回）\",\"adjustLineIds\":\"多id逗号分隔\"}") })
	@PostMapping("/examine")
	public RestMessage<?> examineAdjust(@RequestBody Map<String, Object> map) {
		service.examineAdjust(map);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * erp驳回数据的处理
	 */
	@UserLog
	@ApiOperation(value = "wms发起erp损溢驳回处理(清除预占)")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "map", value = "{\"status\":\"审核类型（0：通过）\",\"adjustLineIds\":\"多id逗号分隔\"}") })
	@PostMapping("reject")
	public RestMessage<?> rejectAdjust(@RequestBody Map<String, Object> map) {
		service.rejectAdjust(map);
		return RestMessage.success("操作成功", null);
	}

	@Deprecated
	@UserLog
	@ApiOperation(value = "修改无计划损溢(作废)")
	@PostMapping("update")
	public RestMessage<?> updateAdjust(@RequestBody WmsAdjustUpdateVO wmsAdjustUpdateVO) {
		service.updateAdjust(wmsAdjustUpdateVO);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * 主动调用erp审核过的数据生成结果
	 */
	@UserLog
	@ApiOperation(value = "erp审核数据生成结果回传erp")
	@GetMapping("doAdjustCallBack2erp")
	public RestMessage<?> doAdjustCallBack2erp(String billids) {
		service.procesAdjustAudit(billids);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * 直接生成result回传
	 */
	@UserLog
	@ApiOperation(value = "erp审核数据生成结果回传erp")
	@GetMapping("doCallBack2erp")
	public RestMessage<?> doCallBack2erp(String billids) {
		service.doCallBack2erp(billids);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * 直接生成result回传
	 */
	@UserLog
	@ApiOperation(value = "结果回传erp")
	@GetMapping("doCallBackResult2erp")
	public RestMessage<?> doCallBackResult2erp(String billids) {
		service.doCallBackResult2erp(billids);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * erp发起损溢提取(OMS_INVENTORY_ORDER)走查询服务是最好的
	 */

	/**
	 * erp发起损溢审核(生成损益单)
	 */
	@UserLog
	@ApiOperation(value = "erp发起损溢审核(生成损益单)")
	@PostMapping("genAdjust")
	public RestMessage<Object> genAdjust(@RequestBody List<ErpAdjustAddVO> ErpAdjustAddVOList) {
		service.genAdjust(ErpAdjustAddVOList);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * 转损溢报损时货位数量不够
	 */
	@UserLog
	@ApiOperation(value = "erp发起转损溢时驳回处理")
	@PostMapping("rejectErpForGen")
	public RestMessage<Object> rejectErpAdjust(@RequestBody List<ErpAdjustAddVO> ErpAdjustAddVOList) {
		service.rejectErpForGen(ErpAdjustAddVOList);
		return RestMessage.success("操作成功", null);
	}

	/**
	 * 新增新的批次信息(无法做到又生成新批次又生成损溢数据)
	 */
	@ApiOperation(value = "代管损溢中新增批次信息")
	@PostMapping("genBatchInfo")
	public RestMessage<Object> genBatchInfo(@RequestBody WmsAdjustAddVO addVO) {
		return RestMessage.success("操作成功", service.genBatchInfo(addVO));
	}

	/**
	 * 代管库存新增损溢(无需审核,直接增减库存,以及回传结果oms)
	 */
	@ApiOperation(value = "代管库存新增损溢")
	@PostMapping("hostAdd")
	public RestMessage<Object> hostAdd(@RequestBody WmsAdjustAddVO addVO) {
		return RestMessage.success("操作成功", service.hostAdd(addVO));
	}

	/**
	 * 损溢不回传erp扣减库存(wms审核),在二审时候,先扣减库存,不写order表数据,更新损溢状态
	 */

	/**
	 * 损溢回传erp不扣减库存(wms审核),在二审时候,先取消预占,直接写result表数据回传oms->erp,更新损溢状态
	 */

	/**
	 * 损溢预占清理
	 */

	/**
	 * 库存批次打印(查询服务已经实现)
	 */
}
