package com.prolog.cs.base.gsp.controller;


import com.prolog.cs.base.gsp.QueryDTO;
import com.prolog.cs.base.gsp.model.DxiGspQualityReviewD;
import com.prolog.cs.base.gsp.model.DxiGspQualityReviewH;
import com.prolog.cs.base.gsp.service.GspQualityReviewService;
import com.prolog.cs.base.gsp.vo.GspQualityCheckMoveItemVo;
import com.prolog.cs.base.gsp.vo.GspQualityCheckMoveVo;
import com.prolog.cs.base.gsp.vo.GspUpkeepCheckVO;
import com.prolog.cs.data.exchange.client.ExchangeSender;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @Description 质量复查管理
 * @Date 2022-05-27
 */

@Slf4j
@Api(tags = "质量复查管理")
@RestController
@RequestMapping("/gspQualityReview")
public class GspQualityReviewController {

	@Autowired
	private GspQualityReviewService gspQualityReviewService;

	/**
	 * 分页查询质量复查列表
	 */
	@ApiOperation("分页查询质量复查单列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "branchcode", required = true, dataType = "String"),
			@ApiImplicitParam(name = "consignorcode", required = true, dataType = "String"),
			@ApiImplicitParam(name = "requestBilltype", required = false, dataType = "String"),
			@ApiImplicitParam(name = "billno", required = false, dataType = "String"),
			@ApiImplicitParam(name = "status", required = true, dataType = "String",defaultValue = "10初始单 40 复查单"),
			@ApiImplicitParam(name = "pageSize",required = true, dataType = "Integer", defaultValue = "0"),
			@ApiImplicitParam(name = "pageNum",required = true, dataType = "Integer", defaultValue = "10")
	})
	@GetMapping("/listPage")
	public RestMessage<Page<DxiGspQualityReviewH>> listPage(@RequestParam("branchcode") String branchcode,
															@RequestParam("consignorcode") String consignorcode,
															 String requestBilltype,
															 String billno,
															@RequestParam("status") String status,
															@RequestParam("pageSize") Integer pageSize,
															@RequestParam("pageNum") Integer pageNum) throws Exception {
		return RestMessage.newInstance(true, "success", gspQualityReviewService.listPage(branchcode,consignorcode,requestBilltype,billno,status,pageSize,pageNum));
	}


	/**
	 * 主表单据id查询复查列表
	 */
	@GetMapping("/findDetailByBillId")
	@ApiOperation("主表单据id查询复查列表")
	public RestMessage<List<DxiGspQualityReviewD>> findDetailByBillId(@RequestParam String billId) throws Exception {
		return RestMessage.newInstance(true, "success", gspQualityReviewService.findDetailByBillId(billId));
	}


	/**
	 * 质量主管审核
	 */
	@ApiOperation("质量审核")
	@PostMapping("/directorAudit")
	public RestMessage<Object> directorAudit(@NotEmpty(message = "collection is empty")@RequestBody List<DxiGspQualityReviewD> list) throws Exception {
		gspQualityReviewService.batchAudit(list);
		return RestMessage.newInstance(true, "success", "");
	}


	/**
	 * 质量主管审核
	 */
	/*@ApiOperation("质量经理审核")
	@PostMapping("/managerAudit")
	public RestMessage<Object> directorAudit(@NotEmpty(message = "collection is empty")@RequestBody List<DxiGspQualityReviewD> list) throws Exception {
		gspQualityReviewService.batchAudit(list);
		return RestMessage.newInstance(true, "success", "");
	}*/



	/**
	 * 质量复检移库不合格品主表提取
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "warehouseId", required = true, dataType = "String"),
			@ApiImplicitParam(name = "cargoOwnerId", required = true, dataType = "String"),
			@ApiImplicitParam(name = "requestBilltype", required = false, dataType = "String"),
			@ApiImplicitParam(name = "billno", required = false, dataType = "String")
	})
	@ApiOperation("质量复检移库不合格品主表提取")
	@GetMapping("/findQualityReview4MovePick")
	public RestMessage<List<GspQualityCheckMoveVo>> findQualityReview4MovePick(@RequestParam("warehouseId") String warehouseId,
																			   @RequestParam("cargoOwnerId") String cargoOwnerId,
																			   String requestBilltype,
																			   String billno){
		List<GspQualityCheckMoveVo> qualityCheck4MovePick = gspQualityReviewService.findQualityReview4MovePick(warehouseId,cargoOwnerId,requestBilltype,billno);
		return RestMessage.newInstance(true, "success", qualityCheck4MovePick);
	}


	/**
	 * 质量复检移库不合格明细提取
	 */
	@ApiOperation("质量复检移库不合格明细提取")
	@GetMapping("/findQualityReview4MoveItemPick")
	public RestMessage<List<GspQualityCheckMoveItemVo>> findQualityReview4MoveItemPick(String billId){
		return RestMessage.newInstance(true, "success", gspQualityReviewService.findQualityReview4MoveItemPick(billId));
	}


	@PostMapping("/confirmQualityReviewMove")
	@ApiOperation(value = "质量复核移库确认")
	public RestMessage confirmQualityReviewMove(@RequestBody String[] arrList){
		gspQualityReviewService.confirmQualityReviewMove(arrList);
		return RestMessage.newInstance(true, "success", null);
	}

}
