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

import com.prolog.cs.biz.inbound.dto.PageParam;
import com.prolog.cs.biz.inbound.dto.rcv.RcvHDTO;
import com.prolog.cs.biz.inbound.dto.rcv.RcvInstockLinesDTO;
import com.prolog.cs.biz.inbound.dto.rqc.RqcHeadersDTO;
import com.prolog.cs.biz.inbound.dto.rqc.RqcLinesDTO;
import com.prolog.cs.biz.inbound.dto.task.TaskQcDetailDTO;
import com.prolog.cs.biz.inbound.service.rcv.RcvInstockLinesService;
import com.prolog.cs.biz.inbound.service.rqc.RqcHeadersService;
import com.prolog.cs.biz.inbound.service.task.TaskInstockDetailService;
import com.prolog.cs.biz.inbound.utils.UserUtils;
import com.prolog.cs.biz.inbound.vo.*;
import com.prolog.cs.biz.inbound.vo.task.TaskQcDetailQueryVO;
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.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * 打印控制类
 * 
 * @author Xiong
 *
 */
@Api(tags = "单据打印")
@RestController
@RequestMapping("/print/v1.0")
public class PrintController {

	@Resource
	private RqcHeadersService rqcHeadersService;

	@Resource
	private TaskInstockDetailService taskInstockDetailService;

	@Resource
	private RcvInstockLinesService rcvInstockLinesService;

	/**
	 * 入库验收通知单查询单头
	 * 
	 */
	@ApiOperation(value = "入库验收通知单查询单头(rcv头)", response = RcvHDTO.class)
	@GetMapping("/getRqcNoticeHeader")
	public RestMessage<Object> getRqcNoticeHeader(RcvQueryVO rcvQueryVO, PageParam pageParam) {
		return RestMessage.newInstance(true, "getRqcNoticeHeader",
				rqcHeadersService.getRqcNoticeHeader(rcvQueryVO, pageParam));
	}

	/**
	 * 入库验收通知单查询明细
	 * 
	 */
	@ApiOperation(value = "入库验收通知单查询明细", response = TaskQcDetailDTO.class)
	@ApiImplicitParam(value = "rcvHeaderId(收货单id必填)")
	@GetMapping("/getRqcNoticeDetails")
	public RestMessage<Object> getRqcNoticeDetails(@RequestParam String rcvHeaderId,String printStatus, PageParam pageParam) {
		if (StringUtils.isBlank(rcvHeaderId)) {
			return RestMessage.newInstance(true, "getRqcNoticeDetails", null);
		}
		return RestMessage.newInstance(true, "getRqcNoticeDetails",
				rqcHeadersService.getRqcNoticeDetails(rcvHeaderId,printStatus, pageParam));
	}

	/**
	 * 入库验收通知单打印数据获取
	 * 
	 */
	@ApiOperation("入库验收通知单打印数据获取")
	@ApiImplicitParam(value = "rcvHeaderId(收货单id必填)")
	@PostMapping("/getRqcNoticePrintData")
	public RestMessage<Object> getRqcNoticePrintData(@RequestBody TaskQcDetailQueryVO queryVo) {
		return RestMessage.doSuccess(rqcHeadersService.getRqcNoticePrintData(queryVo));
	}

	/**
	 * 验收单查询单头
	 * 
	 */
	@ApiOperation(value = "验收单打印-验收汇总查询", response = RqcHeadersDTO.class)
	@GetMapping("/getRqcHeader")
	public RestMessage<Object> getRqcHeader(RqcHQueryVO rqcHQueryVO, PageParam pageParam) {
		rqcHQueryVO.setIsDoubleHealth("1");
		return RestMessage.doSuccess(rqcHeadersService.findList(rqcHQueryVO, pageParam));
	}

	/**
	 * 验收单查询明细
	 * 
	 */
	@ApiOperation(value = "验收单打印-验收明细查询", response = RqcLinesDTO.class)
	@ApiImplicitParam(value = "getRqcDetails(质检单id必填)")
	@GetMapping("/getRqcDetails")
	public RestMessage<Object> getRqcDetails(RqcDQueryVO rqcDQueryVO) {
		String rqcHeaderId = rqcDQueryVO.getRqcHeaderId();
		if (StringUtils.isBlank(rqcHeaderId)) {
			return RestMessage.newInstance(true, "getRqcNoticeDetails", null);
		}
		rqcDQueryVO.setItemHealthIsDouble(1);
//		AssertUtils.isNotBlank(rqcDQueryVO.getRqcHeaderId(), "rqcHeaderId质检单id不可为空!");
		return RestMessage.doSuccess(rqcHeadersService.getRqcDetailsList(rqcDQueryVO));
	}

	/**
	 * 验收汇总单打印数据
	 * 
	 */
	@ApiOperation("验收汇总单打印数据获取")
	@ApiImplicitParam(value = "incloudHids(质检单id集合必填)")
	@PostMapping("/getRqcHzPrintData")
	public RestMessage<Object> getRqcHzPrintData(@RequestBody RqcHQueryVO queryVO) {
		return RestMessage.doSuccess(rqcHeadersService.getRqcGatherPrintData(queryVO));
	}

	/**
	 * 验收明细单打印
	 * 
	 */
	@ApiOperation("验收明细单打印数据获取")
	@ApiImplicitParam(value = "rqcHeaderId(质检单id选填),includeIds(质检明细id集合选填)")
	@PostMapping("/getRqcDetailsPrintData")
	public RestMessage<Object> getRqcDetailsPrintData(@RequestBody RqcDQueryVO queryVO) {
		return RestMessage.newInstance(true, "getRqcDetailsPrintDataSuccess",
				rqcHeadersService.getRqcDetailsPrintData(queryVO));
	}

	/**
	 * 上架标签打印
	 */
	@ApiOperation("验收上架标签打印获取")
	@ApiImplicitParam(value = "rqcHeaderId(质检单id必填)")
	@PostMapping("/getRqcInstockLabelPrintData")
	public RestMessage<Object> getRqcInstockLabelPrintData(@RequestBody RqcDQueryVO queryVO) {
		return RestMessage.newInstance(true, "getRqcInstockLabelPrintDataSuccess",
				rqcHeadersService.getRqcInstockLabelPrintData(queryVO));
	}

	/**
	 * 代管等未验收直接上架的标签补打
	 */
	@ApiOperation("代管等未验收直接上架的标签补打")
	@PostMapping("/getRcvInstockLabelPrintData")
	public RestMessage<Object> getRcvInstockLabelPrintData(@RequestBody TaskQueryVO queryVO) {
		return RestMessage.newInstance(true, "getRcvInstockLabelPrintDataSuccess",
				taskInstockDetailService.excuteAssembleInstockPrintData(queryVO.getIncloudIds(),userUtils.getUserDTO(),true));
	}

	@Resource
	private UserUtils userUtils;


	@ApiOperation(value = "收货单打印-收货单头列表查询", response = RcvHDTO.class)
	@GetMapping("/getRqcNoticeHeaderNew")
	public RestMessage<Object> getRqcNoticeHeaderNew(RcvQueryVO rcvQueryVO, PageParam pageParam) {
		return RestMessage.newInstance(true, "getRqcNoticeHeader",
				rqcHeadersService.getRqcNoticeHeaderNew(rcvQueryVO, pageParam));
	}

	/**
	 * 收货单明细列表查询
	 *
	 */
	@ApiOperation(value = "收货单打印-收货单明细列表查询", response = TaskQcDetailDTO.class)
	@ApiImplicitParam(value = "rcvHeaderId(收货单id必填)")
	@GetMapping("/getRqcNoticeDetailsNew")
	public RestMessage<Object> getRqcNoticeDetailsNew(@RequestParam String rcvHeaderId, PageParam pageParam) {
		if (StringUtils.isBlank(rcvHeaderId)) {
			return RestMessage.newInstance(true, "getRqcNoticeDetails", null);
		}
		return RestMessage.newInstance(true, "getRqcNoticeDetails",
				rqcHeadersService.getRqcNoticeDetailsNew(rcvHeaderId, pageParam));
	}

	/**
	 * 收货单打印查询
	 *
	 */
	@ApiOperation("收货单打印-收货单打印数据")
	@ApiImplicitParam(value = "rcvHeaderId(收货单id必填)")
	@GetMapping("/getRqcNoticePrintDataNew")
	public RestMessage<Object> getRqcNoticePrintDataNew(RcvLinesQueryVO queryVo) {
		return RestMessage.doSuccess(rqcHeadersService.getRqcNoticePrintDataNew(queryVo));
	}


	@ApiOperation("验收单打印-验收单打印数据")
	@ApiImplicitParam(value = "rqcHeaderId(质检单id选填),includeIds(质检明细id集合选填)")
	@PostMapping("/getRqcDetailsPrintDataNew")
	public RestMessage<Object> getRqcDetailsPrintDataNew(@RequestBody RqcDQueryVO queryVO) {
		queryVO.setItemHealthIsDouble(1);
		return RestMessage.newInstance(true, "getRqcDetailsPrintDataSuccess",
				rqcHeadersService.getRqcDetailsPrintDataNew(queryVO));
	}

	@ApiOperation("上架单打印-上架单查询")
	@GetMapping("/instockLinesList")
	public RestMessage<Page<RcvInstockLinesDTO>> InstockLinesList(RcvInstockLinesQueryVO rcvInstockLinesQueryVO, PageParam pageParam) throws Exception {
		return RestMessage.newInstance(true, "pageSuccess",
				rcvInstockLinesService.findListNew(rcvInstockLinesQueryVO, pageParam));
	}

	@ApiOperation("上架单打印-打印数据")
	@GetMapping("/getInstockLabelPrintDataNew")
	public RestMessage<Object> getInstockLabelPrintDataNew(RqcDQueryVO queryVO) {
		return RestMessage.newInstance(true, "getInstockLabelPrintDataNew",
				rqcHeadersService.getRqcInstockLabelPrintDataNew(queryVO));
	}

    @ApiOperation("上架单打印-库别查询")
    @GetMapping("/queryRoomInfo")
    public RestMessage<List<Map<String, String>>> queryRoomInfo(String warehouseId) throws Exception {
        return RestMessage.newInstance(true, "pageSuccess",
                rcvInstockLinesService.queryRoomInfo(warehouseId));
    }

    @ApiOperation("上架单打印-库区查询")
    @GetMapping("/queryAreaInfo")
    public RestMessage<List<Map<String, String>>> queryAreaInfo(String warehouseId) throws Exception {
        return RestMessage.newInstance(true, "pageSuccess",
                rcvInstockLinesService.queryAreaInfo(warehouseId));
    }

	@ApiOperation("验收单打印-上传监管码")
	@ApiImplicitParam(value = "rcvHeaderId，rcvLineId必传")
	@PostMapping("/uploadCircubillRcvDetails")
	public RestMessage<Object> uploadCircubillRcvDetails(@RequestBody RqcLinesDTO rqcLinesDTO) {
		return RestMessage.newInstance(true, "上传成功",
				rqcHeadersService.uploadCircubillRcvDetails(rqcLinesDTO));
	}
}
