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

import com.prolog.cs.biz.inbound.constant.OperationConstant;
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.task.TaskInstockDetailDTO;
import com.prolog.cs.biz.inbound.model.task.TaskInstockDetail;
import com.prolog.cs.biz.inbound.service.rcv.RcvInstockLinesService;
import com.prolog.cs.biz.inbound.vo.InsockTaskRcvQueryVO;
import com.prolog.cs.biz.inbound.vo.RcvInstockLinesQueryVO;
import com.prolog.cs.biz.inbound.vo.task.InstockTaskQueryVO;
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.AssertUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Description // TODO
 * @Date 2021-03-24
 */

@Api(tags = "上架收货行")
@RestController
@RequestMapping("/rcvInstockLines")
public class RcvInstockLinesController {

    @Resource
    private RcvInstockLinesService rcvInstockLinesService;

    /**
     * 条件分页
     */
    @ApiOperation("条件分页")
    @GetMapping("/page")
    public RestMessage<Page<RcvInstockLinesDTO>> list(RcvInstockLinesQueryVO rcvInstockLinesQueryVO, PageParam pageParam) throws Exception {
        return RestMessage.newInstance(true, "pageSuccess", rcvInstockLinesService.findList(rcvInstockLinesQueryVO, pageParam));
    }

    /**
     * 批量添加
     */
    @ApiOperation("批量添加")
    @PostMapping("/batchAdd")
    public RestMessage<Object> batchAdd(@RequestBody List<RcvInstockLinesDTO> rcvInstockLinesDTOList) {
        AssertUtils.isNotEmpty(rcvInstockLinesDTOList, OperationConstant.BATCH_ADD_ERROR_MSG);
        return RestMessage.newInstance(true, "batchAddSuccess", rcvInstockLinesService.batchAdd(rcvInstockLinesDTOList));
    }

    /**
     * 批量编辑
     */
    @ApiOperation("批量编辑")
    @PostMapping("/batchEdit")
    public RestMessage<Object> batchEdit(@RequestBody List<RcvInstockLinesDTO> rcvInstockLinesDTOList) {
        AssertUtils.isNotEmpty(rcvInstockLinesDTOList, OperationConstant.BATCH_EDIT_ERROR_MSG);
        return RestMessage.newInstance(true, "batchEditSuccess", rcvInstockLinesService.batchEdit(rcvInstockLinesDTOList));
    }

    /**
     * 详情
     */
    @ApiOperation("详情(主键id)")
    @GetMapping("/findByPkId")
    public RestMessage<RcvInstockLinesDTO> findByPkId(String pkId) {
        AssertUtils.isNotBlank(pkId, "主键id不可为空");
        return RestMessage.newInstance(true, "findByPkIdSuccess", rcvInstockLinesService.findByPkId(pkId));
    }

    /**
     * 拆分保存
     */

    /**
     * 找寻待上架的rcv头表
     */
    @ApiOperation("提取上架的rcv头表")
    @GetMapping("/extractRcvH")
    public RestMessage<Page<RcvHDTO>> extractRcvH(InsockTaskRcvQueryVO rcvQueryVO, PageParam pageParam) {
        return RestMessage.newInstance(true, "extractRcvH", rcvInstockLinesService.extractRcvHAndPro(rcvQueryVO, pageParam));
    }
    //	/**
    //	 * 找寻待上架的rcv头表
    //	 */
    //	@ApiOperation("提取上架的rcv头表")
    //	@GetMapping("/extractRcvH")
    //	public RestMessage<Page<RcvHDTO>> extractRcvH(RcvQueryVO rcvQueryVO, PageParam pageParam) {
    //		return RestMessage.newInstance(true, "extractRcvH",
    //				rcvInstockLinesService.extractRcvHAndPro(rcvQueryVO, pageParam));
    //	}

    /**
     * 提取待上架的任务
     */
    @ApiOperation("提取上架池中的任务(条件分页)")
    @GetMapping("/extractTask")
    public RestMessage<Page<TaskInstockDetailDTO>> extractTask(TaskQueryVO queryVO, PageParam pageParam) {
        return RestMessage.newInstance(true, "extractTask", rcvInstockLinesService.extractTask(queryVO, pageParam));
    }

    /**
     * 已索取我的任务
     */
    @ApiOperation("已索取我的任务")
    @GetMapping("/getMyTask")
    public RestMessage<Page<TaskInstockDetailDTO>> getMyTask(TaskQueryVO queryVO, PageParam pageParam) {
        return RestMessage.newInstance(true, "getMyTask", rcvInstockLinesService.getMyTask(queryVO, pageParam));
    }

    /**
     * 索取任务
     */
    @PostMapping("/claimPutawayTask")
    public RestMessage<List<TaskInstockDetailDTO>> claimPutawayTask(@RequestBody InstockTaskQueryVO vo) {
        return RestMessage.newInstance(true, "claimPutawayTask", rcvInstockLinesService.claimPutawayTask(vo));
    }

    /**
     * pad保存上架
     */
    @ApiOperation("pad保存上架")
    @PostMapping("/add-pad")
    public RestMessage<Object> addByPad(@RequestBody RcvInstockLinesDTO rcvInstockLinesDTO) {
        AssertUtils.notNull(rcvInstockLinesDTO, OperationConstant.OBJ_NULL_MSG);
        return RestMessage.newInstance(true, "addByPad", rcvInstockLinesService.addByPad(rcvInstockLinesDTO));
    }

    /**
     * pad保存上架
     */
    @ApiOperation("pad保存上架")
    @PostMapping("/v2/add-pad")
    public RestMessage<Object> addByPadV2(@RequestBody RcvInstockLinesDTO rcvInstockLinesDTO) {
        AssertUtils.notNull(rcvInstockLinesDTO, OperationConstant.OBJ_NULL_MSG);
        return RestMessage.newInstance(true, "addByPad", rcvInstockLinesService.addByPadV2(rcvInstockLinesDTO));
    }


    /**
     * 上架任务拆分
     */
    @ApiOperation("上架任务拆分")
    @PostMapping("/taskSplit")
    public RestMessage<Object> splitTask(@RequestBody List<TaskInstockDetailDTO> taskInstockDetailDTOList) {
        AssertUtils.isNotEmpty(taskInstockDetailDTOList, "数据集合为空!");
        return RestMessage.newInstance(true, "splitTask", rcvInstockLinesService.splitTask(taskInstockDetailDTOList));
    }

    @ApiOperation("上架任务拆分---确认拆分")
    @PostMapping("/confirmSplitTask")
    public RestMessage<Object> confirmSplitTask(@RequestBody TaskInstockDetailDTO taskInstockDetailDTO) {
        return RestMessage.newInstance(true, "splitTask", rcvInstockLinesService.confirmSplitTask(taskInstockDetailDTO));
    }

    /**
     * 上架任务合并(同品同批) TODO
     */
    @ApiOperation("上架任务合并(同品同批)")
    @PostMapping("/taskMerge")
    public RestMessage<Object> taskMerge(@RequestBody List<TaskInstockDetailDTO> taskInstockDetailDTOList) {
        AssertUtils.isNotEmpty(taskInstockDetailDTOList, "数据集合为空!");
        return RestMessage.newInstance(true, "splitTask", rcvInstockLinesService.taskMerge(taskInstockDetailDTOList));
    }

    /**
     * 异常任务处理
     */
    @ApiOperation("异常任务处理")
    @PostMapping("/doException")
    public RestMessage<Object> doException(@RequestBody List<RcvInstockLinesDTO> rcvInstockLinesDTOList) {
        AssertUtils.isNotEmpty(rcvInstockLinesDTOList, "数据集合为空!");
        return RestMessage.newInstance(true, "doException", rcvInstockLinesService.doException(rcvInstockLinesDTOList));
    }

    /**
     * PAD提取上架任务
     */
    @ApiOperation("条件提取上架任务(Pad)")
    @PostMapping("/conditionExtractTask")
    public RestMessage<Object> conditionExtractTask(InstockTaskQueryVO queryVO, PageParam pageParam) {
        AssertUtils.notNull(queryVO, "查询条件为空!");
        return RestMessage.newInstance(true, "conditionExtractTask", rcvInstockLinesService.conditionExtractTask(queryVO, pageParam));
    }

    @ApiOperation("上架任务拆分---查询上架任务明细")
    @PostMapping("/queryUpTaskDetail")
    public RestMessage<Object> queryUpTaskDetail(@RequestBody InstockTaskQueryVO queryVO) {
        AssertUtils.notNull(queryVO, "查询条件为空!");
        return RestMessage.newInstance(true, "queryUpTaskDetail", rcvInstockLinesService.queryUpTaskDetail(queryVO));
    }

    /**
     * 上架标签补打 TODO 单据不确定,待确认
     */
    @ApiOperation("上架标签补打数据(单据不确定,待确认)")
    @PostMapping("/getInstockPrintData")
    public RestMessage<Object> getInstockPrintData(@RequestBody RcvInstockLinesQueryVO queryVO) {
        AssertUtils.notNull(queryVO, OperationConstant.OBJ_NULL_MSG);
        return RestMessage.newInstance(true, "getInstockPrintDataSuccess", rcvInstockLinesService.getInstockPrintData(queryVO));
    }

    /**
     * 按区域上架头
     */
    @ApiOperation("按区域上架头")
    @GetMapping("/getInstockTaskArea")
    public RestMessage<Object> getInstockTaskArea(TaskQueryVO queryVO) {
        return RestMessage.newInstance(true, "getInstockTaskAreaSuccess", rcvInstockLinesService.getInstockTaskArea(queryVO));
    }

    /**
     * 按区域上架明细
     */
    @ApiOperation("按区域上架明细查询")
    @GetMapping("/getInstockTaskDetailsByArea")
    public RestMessage<Object> getInstockTaskDetailsByArea(TaskQueryVO queryVO, PageParam pageParam) {
        return RestMessage.newInstance(true, "getInstockTaskDetailsByAreaSuccess", rcvInstockLinesService.getInstockTaskDetailsByArea(queryVO, pageParam));
    }

    /**
     * 获取待上架任务容器编号集合
     */
    @ApiOperation("获取待上架任务容器编号集合")
    @GetMapping("/getInstockTaskContainer")
    public RestMessage<Object> getInstockTaskContainer(String warehouseId, String mtlOwnerId, String enterpriseId, Integer pageNum, Integer pageSize) {
        return RestMessage.newInstance(true, "getInstockTaskContainer", rcvInstockLinesService.getInstockTaskContainer(warehouseId, mtlOwnerId, enterpriseId, pageNum, pageSize));
    }

    /**
     * 模拟调用库存缺不回调erp方法
     */
    @ApiOperation("模拟调用库存缺不回调erp方法")
    @GetMapping("/getInstockInstockIn")
    public RestMessage<Object> getInstockInstockIn(String ids) {
        return RestMessage.newInstance(true, "getInstockInstockIn", rcvInstockLinesService.getInstockInstockIn(ids));
    }

    /**
     * 模拟直接上架不回传erp
     */
    @ApiOperation("模拟直接上架不回传erp")
    @PostMapping("/batchAddNoCall2Erp")
    public RestMessage<Object> batchAddNoCall2Erp(@RequestBody List<RcvInstockLinesDTO> rcvInstockLinesDTOList) {
        AssertUtils.isNotEmpty(rcvInstockLinesDTOList, OperationConstant.BATCH_ADD_ERROR_MSG);
        return RestMessage.newInstance(true, "batchAddNoCall2Erp", rcvInstockLinesService.batchAddNoCall2Erp(rcvInstockLinesDTOList));
    }

    /**
     * 上架明细回传erp
     */
    @ApiOperation("上架明细回传erp")
    @GetMapping("/instockCall2Erp")
    public RestMessage<Object> instockCall2Erp(String hids) {
        return RestMessage.newInstance(true, "instockCall2Erp", rcvInstockLinesService.instockCall2Erp(hids));
    }

    /**
     * 出库补货上架
     */
    @ApiOperation("补货上架")
    @PostMapping("/replenis-instock")
    public RestMessage<Object> replenisInstock(@RequestBody List<RcvInstockLinesDTO> rcvInstockLinesDTOList) {
        return RestMessage.newInstance(true, "replenisInstock", rcvInstockLinesService.replenisInstock(rcvInstockLinesDTOList));
    }

    @PostMapping("/getSyncErpDataInfo")
    public RestMessage<Object> getSyncErpDataInfo(String rcvHeaderId) {
        return RestMessage.newInstance(true, "getSyncErpDataInfo", rcvInstockLinesService.getSyncErpDataInfo(rcvHeaderId));
    }

    /**
     * 绑定支架号（鹰江）
     */
    @ApiOperation("绑定支架号")
    @PostMapping("/bindPalletNo")
    public RestMessage<Object> bindPalletNo(@RequestBody TaskInstockDetailDTO taskInstockDetailDTO) {
        //绑定支架
        rcvInstockLinesService.bindPalletNo(taskInstockDetailDTO);
        //推送EIS上架任务
        //rcvInstockLinesService.receiveInStockWms(taskInstockDetailDTO.getContainerCode());
        return RestMessage.newInstance(true, "bindPalletNo",null);
    }

}
