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

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

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;

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.cs.basic.item.model.BaseMtlItemMst;
import com.prolog.cs.biz.inbound.dto.PageParam;
import com.prolog.cs.biz.inbound.dto.RcvCommonLine;
import com.prolog.cs.biz.inbound.dto.rcv.RcvLinesDTO;
import com.prolog.cs.biz.inbound.remote.BaseItemRemoteCaller;
import com.prolog.cs.biz.inbound.remote.dto.OmsAsnBillDQueryVO;
import com.prolog.cs.biz.inbound.service.OmsAsnBillDService;
import com.prolog.cs.biz.inbound.service.rcv.RcvLinesService;
import com.prolog.cs.biz.inbound.vo.RcvLinesQueryVO;
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;

/**
 * @Description 收货(入库)行明细
 * @Date 2021-03-24
 */

@Api(tags = "收货(入库)行明细")
@RestController
@RequestMapping("/rcvLines/v1.0")
public class RcvLinesController {

	@Resource
	private RcvLinesService rcvLinesService;

	@Resource
	private BaseItemRemoteCaller baseItemRemoteCaller;
	
	@Resource
	private OmsAsnBillDService omsAsnBillDService;

	/**
	 * 详情(主键id)
	 */
	@ApiOperation("详情(主键id)")
	@GetMapping("/findByPkId")
	public RestMessage<RcvLinesDTO> findByPkId(String pkId) {
		return RestMessage.newInstance(true, "findByPkIdSuccess", rcvLinesService.findByPkId(pkId));
	}

	/**
	 * 获取商品详情
	 */
	@ApiOperation("获取商品集合详情列表")
	@PostMapping("/findItemsInfoList")
	public RestMessage<List<BaseMtlItemMst>> findItemsInfoList(
			@NotEmpty(message = "itemIds is empty") Set<String> itemIds) {
		return baseItemRemoteCaller.getListByIds(itemIds);
	}

	/**
	 * 条件分页
	 */
	@ApiOperation("条件分页")
	@GetMapping("/page")
	public RestMessage<Page<RcvLinesDTO>> list(RcvLinesQueryVO queryVO, PageParam pageParam) {
		return RestMessage.newInstance(true, "pageSuccess", rcvLinesService.findList(queryVO, pageParam));
	}

	/**
	 * 商品异常处理
	 */
	@ApiOperation("收货行异常处理")
	@GetMapping("/itemException")
	public RestMessage<Object> itemException(List<RcvLinesDTO> RcvLinesDTOList) {
		return RestMessage.newInstance(true, "itemException", rcvLinesService.itemException(RcvLinesDTOList));
	}

	/**
	 * 商品异常处理结果
	 */
	@ApiOperation("收货行异常处理结果返回")
	@GetMapping("/itemExceptionResult")
	public RestMessage<Object> itemExceptionResult(List<RcvLinesDTO> RcvLinesDTOList) {
		return RestMessage.newInstance(true, "itemExceptionResult",
				rcvLinesService.itemExceptionResult(RcvLinesDTOList));
	}

	/**
	 * 测试策略执行(寻库别)
	 */
	@ApiOperation("测试寻库别策略")
	@PostMapping("/testStrategy")
	public RestMessage<Object> testStrategy(@RequestBody List<RcvLinesDTO> RcvLinesDTOList) {
		return RestMessage.newInstance(true, "itemExceptionResult", rcvLinesService.testStrategy(RcvLinesDTOList));
	}

	/**
	 * 获取推荐库别/库区(逗号分隔集合)
	 */
//	@UserLog("获取推荐库别/库区(逗号分隔集合)")
	@ApiOperation("(新)获取推荐库别/库区(逗号分隔集合)")
	@PostMapping("/recommendArea")
	public RestMessage<Object> recommendArea(@RequestBody List<RcvLinesDTO> RcvLinesDTOList) {
		return RestMessage.querySuccess(rcvLinesService.recommendArea(RcvLinesDTOList));
	}
	
	@ApiOperation("(新)单个获取结论选择")
	@PostMapping("/getConclusionSingle")
	public RestMessage<List<Map<String, String>>> getConclusionSingle(@RequestBody RcvCommonLine rcvCommonLine) {
		return RestMessage.querySuccess(rcvLinesService.getConclusionSingle(rcvCommonLine));
	}
	
	@ApiOperation("(新)获取结论选择")
	@PostMapping("/getConclusion")
	public RestMessage<List<RcvCommonLine>> getConclusion(@RequestBody List<RcvCommonLine> rcvCommonLineList) {
		return RestMessage.querySuccess(rcvLinesService.getConclusion(rcvCommonLineList));
	}
	
	@ApiOperation("(新)获取库别选择")
	@PostMapping("/getAreaCategory")
	public RestMessage<List<RcvCommonLine>> getAreaCategory(@RequestBody List<RcvCommonLine> rcvCommonLineList) {
		return RestMessage.querySuccess(rcvLinesService.getAreaCategory(rcvCommonLineList));
	}
	
	
	@ApiOperation("入库库别选择策略：--依据企业+仓+货主+数据来源（0）+订单类型+收货数+收货件数+是否异型，获取库别")
	@PostMapping("/byConditionToAreaCategory")
	public RestMessage<RcvCommonLine> byConditionToAreaCategory(@RequestBody RcvCommonLine rcvCommonLineList) {
		return RestMessage.querySuccess(rcvLinesService.byConditionToAreaCategory(rcvCommonLineList));
	}
	
	/**
	 * 测试计算asn收货行数量的剩余
	 */
	@UserLog("测试计算asn收货行数量的剩余")
	@ApiOperation("测试计算asn收货行数量的剩余")
	@PostMapping("/asnd/test/remainqty")
	public RestMessage<Object> remainqty(OmsAsnBillDQueryVO vo) {
		return RestMessage.querySuccess(omsAsnBillDService.queryOmsAsnBillDRemainQty(vo));
	}
	
	/**
	 * 收货明细校验容器
	 */
	@ApiOperation("收货明细校验容器")
	@PostMapping("/vaildateContainer")
	public RestMessage<Object> vaildateContainer(@RequestBody List<RcvLinesDTO> rcvLinesDTOList) {
		return RestMessage.querySuccess(rcvLinesService.vaildateContainer(rcvLinesDTOList));
	}
}
