package com.prolog.cs.biz.outbound.controller;

import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.prolog.common.RestMsgHelper;
import com.prolog.cs.basic.common.model.print.PrintParam;
import com.prolog.cs.biz.outbound.dao.WorkStageRuntimeMapper;
import com.prolog.cs.biz.outbound.model.OmsDoBillHDO;
import com.prolog.cs.biz.outbound.model.PickOrder;
import com.prolog.cs.biz.outbound.model.PickTaskH;
import com.prolog.cs.biz.outbound.model.dto.*;
import com.prolog.cs.biz.outbound.model.dto.print.PrintAllVO;
import com.prolog.cs.biz.outbound.model.entity.BarcodeHDO;
import com.prolog.cs.biz.outbound.model.out.ContainerBindTaskDto;
import com.prolog.cs.biz.outbound.model.print.PrintDataWithMark;
import com.prolog.cs.biz.outbound.model.vo.InfTaskOutVO;
import com.prolog.cs.biz.outbound.model.vo.OuterCheckPickUpVO;
import com.prolog.cs.biz.outbound.model.vo.PickTaskConfirmVO;
import com.prolog.cs.biz.outbound.model.vo.TaskParamsVO;
import com.prolog.cs.biz.outbound.model.vo.check.OuterCheckGainVO;
import com.prolog.cs.biz.outbound.service.*;
import com.prolog.entity.vo.CompleteTaskVO;
import com.prolog.entity.vo.MarkTaskItemVO;
import com.prolog.framework.authority.util.HystrixVarUtil;
import com.prolog.framework.bz.common.print.PrintData;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.framework.core.exception.ParameterException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.lock.annotation.RepeatOperationLock;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.framework.utils.ObjectUtils;
import com.prolog.framework.utils.StringUtils;
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 org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

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

/**
 * @author zzz
 * @desc
 * @date 2021/4/27
 */
@Api(tags = "拣选任务")
@Slf4j
@RestController
@RequestMapping("/picktask")
public class PickTaskController {

    @Autowired
    private PickTaskService pickTaskService;

    @Autowired
    private BarCodeService barCodeService;

    @Autowired
    private PackService packService;

    @Autowired
    private WorkStageRuntimeMapper workStageRuntimeMapper;

    @Autowired
    private WorkStageService workStageService;

    @Autowired
    private PostBackErpService postBackErpService;

    @UserLog
    @ApiOperation(value = "强制下发(组包，生成拣选任务)")
    @PostMapping("/create-picktask")
    public RestMessage<?> addPickTask(@RequestBody List<String> waveIdList){
        packService.addPickTask(waveIdList);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "特殊出库，自动生成数据")
    @PostMapping("/create-picktask2")
    public RestMessage<?> createPickTask2(@RequestBody List<TaskParamsVO> waveList){
        packService.createPickTaskSpecial(waveList);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "特殊出库，自动生成数据")
    @PostMapping("/specialPickTaskConfirm")
    public RestMessage<?> specialPickTaskConfirm(@RequestBody List<OmsDoBillHDO> list){
        packService.specialPickTaskConfirm(list);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "打印特殊订单拣货纸单")
    @PostMapping("/print-specialData")
    public RestMessage<List<PrintData>> printSpecialPaperSlip(@RequestBody Map<String ,Object> params){
        List<String> billIds = (List<String>)params.get("billIds");
        String warehouseId = (String)params.get("warehouseId");
        String bldgId = (String)params.get("bldgId");
        String pickTaskType = (String)params.get("pickTaskType");
        List<PrintData> data = pickTaskService.printSpecialPaperSlip(billIds, warehouseId, bldgId, pickTaskType);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "索取任务(零货)")
    @ApiImplicitParam(name = "params", required = true, value = "{\"warehouseId\":\"仓库id\",\"operatorCode\":\"操作员工号\",\"containerCode\":\"容器号\",\"bldgId\":\"建筑物id\"}")
    @PostMapping("/create-pickorder")
    public RestMessage<Map<String,Object>> createPickOrder(@RequestBody Map<String,Object> params){
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        String containerCode = (String)params.get("containerCode");
        String bldgId = (String)params.get("bldgId");
        if (StringUtils.isBlank(warehouseId))
            throw new ParameterException("仓库id不能为空");
        if (StringUtils.isBlank(operatorCode) && StringUtils.isBlank(containerCode))
            throw new ParameterException("参数不能为空");
        return RestMessage.success("操作成功", pickTaskService.createPickOrder(bldgId,operatorCode,containerCode,warehouseId));
    }

    @UserLog
    @ApiOperation(value = "索取任务(整件)")
    @ApiImplicitParam(name = "params", required = true, value = "{\"warehouseId\":\"仓库id\",\"operatorCode\":\"操作员工号\",\"isPrint\":\"是否自动打印（0/1）\"}")
    @PostMapping("/create-pickorder2")
    public RestMessage<Map<String,Object>> createPickOrder2(@RequestBody Map<String,Object> params){
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        Integer isPrint = (Integer)params.get("isPrint");
        String bldgId = (String)params.get("bldgId");
        String pickTaskId = (String)params.get("pickTaskId");
        String containerNo = (String)params.get("containerNo");
        Integer type = (Integer)params.get("type");
        if (StringUtils.isBlank(warehouseId))
            throw new ParameterException("仓库id不能为空");
        if (StringUtils.isBlank(operatorCode))
            throw new ParameterException("工号不能为空");
        if (isPrint == null)
            throw new ParameterException("是否自动打印不能为空");
        if (type == null)
            throw new ParameterException("索取类型不能为空");
        return RestMessage.success("操作成功", pickTaskService.createPickOrder2(bldgId,operatorCode,warehouseId,isPrint,pickTaskId,containerNo,type));
    }

    @UserLog
    @ApiOperation(value = "索取任务(功能库房)")
    @ApiImplicitParam(name = "params", required = true, value = "{{\"warehouseId\":\"仓库id\",\"containerCode\":\"容器号\",\"operatorCode\":\"操作员工号\",\"isPrint\":\"是否自动打印（0/1）\"}")
    @PostMapping("/create-pickorder3")
    public RestMessage<Map<String,Object>> createPickOrder3(@RequestBody Map<String,Object> params){
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        String containerCode = (String)params.get("containerCode");
        Integer isPrint = (Integer)params.get("isPrint");
        String bldgId = (String)params.get("bldgId");
        return RestMessage.success("操作成功", pickTaskService.createPickOrder3(bldgId,operatorCode,containerCode,warehouseId,isPrint));
    }

    @UserLog
    @ApiOperation(value = "索取任务(整单)")
    @ApiImplicitParam(name = "params", required = true, value = "{{\"warehouseId\":\"仓库id\",\"containerCode\":\"容器号\",\"operatorCode\":\"操作员工号\",\"isPrint\":\"是否自动打印（0/1）\"}")
    @PostMapping("/create-pickorder4")
    public RestMessage<Map<String,Object>> createPickOrder4(@RequestBody Map<String,Object> params){
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        String containerCode = (String)params.get("containerCode");
        Integer isPrint = (Integer)params.get("isPrint");
        String bldgId = (String)params.get("bldgId");
        return RestMessage.success("操作成功", pickTaskService.createPickOrder4(bldgId,operatorCode,containerCode,warehouseId,isPrint));
    }

    @UserLog
    @ApiOperation(value = "索取任务(特殊任务)")
    @ApiImplicitParam(name = "params", required = true, value = "{\"warehouseId\":\"仓库id\",\"operatorCode\":\"操作员工号\",\"isPrint\":\"是否自动打印（0/1）\"}")
    @PostMapping("/create-pickorder5")
    public RestMessage<Map<String,Object>> createPickOrder5(@RequestBody Map<String,Object> params){
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        Integer isPrint = (Integer)params.get("isPrint");
        String bldgId = (String)params.get("bldgId");
        String pickTaskId = (String)params.get("pickTaskId");
        if (StringUtils.isBlank(warehouseId))
            throw new ParameterException("仓库id不能为空");
        if (StringUtils.isBlank(operatorCode))
            throw new ParameterException("工号不能为空");
        if (isPrint == null)
            throw new ParameterException("是否自动打印不能为空");
        return RestMessage.success("操作成功", pickTaskService.createPickOrder5(bldgId,operatorCode,warehouseId,isPrint,pickTaskId));
    }

    @UserLog
    @ApiOperation(value = "拣选任务-绑定容器(零货)")
    @ApiImplicitParam(name = "params", required = true, value = "{\"pickOrderId\":\"拣选单id\",\"containerCode\":\"容器号\"}")
    @PostMapping("/bind-container")
    public RestMessage<?> bindContainer(@RequestBody Map<String,String> params){
        String pickOrderId = params.get("pickOrderId");
        String containerCode = params.get("containerCode");
        pickTaskService.bindContainer(pickOrderId,containerCode);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "绑定容器-功能库房/整单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"pickOrderId\":\"拣选单id\",\"containerCode\":\"容器号\"\"warehouseId\":\"仓id\",\"bldgId\":\"建筑物id\",\"pickTaskType\":\"2-功能库房 3-整单\"}")
    @PostMapping("/bind-container-mix")
    public RestMessage<?> bindContainerMix(@RequestBody Map<String,String> params){
        String pickOrderId = params.get("pickOrderId");
        String containerCode = params.get("containerCode");
        String bldgId = params.get("bldgId");
        String warehouseId = params.get("warehouseId");
        String pickTaskType = params.get("pickTaskType");
        pickTaskService.bindContainerMix(pickOrderId,pickTaskType,containerCode,bldgId,warehouseId);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "取消拣选单")
    @ApiImplicitParam(name = "pickOrderId", value = "拣选单id", required = true, dataType = "String")
    @GetMapping("/cancel-pickorder")
    public RestMessage<?> cancelPickOrder(String pickOrderId){
        pickTaskService.cancelPickOrder(pickOrderId);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "取消拣货任务")
    @ApiImplicitParam(name = "pickTaskId", value = "拣选任务id", required = true, dataType = "String")
    @GetMapping("/cancel-picktask")
    public RestMessage<?> cancelPickTask(String pickTaskId){
        pickTaskService.cancelPickTask(pickTaskId);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "取消拣货任务")
    @ApiImplicitParam(name = "pickTaskId", value = "拣选任务id", required = true, dataType = "String")
    @GetMapping("/cancelPickTask")
    public RestMessage<?> cancelPickTask(List<String> idList){
        pickTaskService.cancelPickTask(idList);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "取消订单")
    @ApiImplicitParam(name = "billGroupId", value = "订单编号", required = true, dataType = "String")
    @GetMapping("/cancel-bill")
    public RestMessage<?> cancelBill(String billGroupId,String warehouseId){
        pickTaskService.cancelBill(billGroupId,warehouseId);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "拣货确认")
    @PostMapping("/picktask-confirm")
    public RestMessage<?> pickTaskConfirm(@RequestBody List<PickTaskConfirmVO> list){
        pickTaskService.pickTaskConfirm(list,0);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "冲红确认")
    @PostMapping("/picktask-confirm-red")
    public RestMessage<?> pickTaskRedConfirm(@RequestBody List<PickTaskConfirmVO> list){
        pickTaskService.pickTaskConfirm(list,1);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "拣选单分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pickTaskType", value = "任务类型（0-整件/1-散件/2-整散合一）", required = false, dataType = "int"),
            @ApiImplicitParam(name = "parames", value = "拣选单号/工号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = false, dataType = "String"),
            @ApiImplicitParam(name = "bldgId", value = "仓库id", required = false, dataType = "String"),
            @ApiImplicitParam(name = "operatorCode", value = "工号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态 0：任务索取 1：任务确认", required = false, dataType = "String")
    })
    @GetMapping("/page-pickorder")
    public RestMessage<Page<PickOrder>> getPickOrderPage(String operatorCode,String bldgId,Integer pickTaskType,String parames,String warehouseId,String status,Integer pageNum,Integer pageSize){
        return RestMessage.success("操作成功", pickTaskService.getPickOrderPage(operatorCode,bldgId,pickTaskType,parames,warehouseId, status, pageNum, pageSize));
    }

    @UserLog
    @ApiOperation(value = "(零货)拣选任务主表查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pickOrderId", value = "拣选单id", required = false, dataType = "String")
    })
    @GetMapping("/list-picktaskh")
    public RestMessage<List<PickTaskH>> getPickTaskHList(String pickOrderId){
        List<PickTaskH> list = pickTaskService.getPickTaskHList(pickOrderId);
        return RestMessage.success("操作成功", list);
    }

    @UserLog
    @ApiOperation(value = "(零货)拣选任务明细查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pickTaskId", value = "拣选任务主表id", required = true, dataType = "String")
    })
    @GetMapping("/list-picktaskd")
    public RestMessage<List<PickTaskDDTO>> getPickTaskDList(String pickTaskId){
        List<PickTaskDDTO> list = pickTaskService.getPickTaskDList(pickTaskId);
        return RestMessage.success("操作成功", list);
    }

    @UserLog
    @ApiOperation(value = "(零货)拣选确认 分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pickOrderId", value = "拣选单id", required = true, dataType = "String")
    })
    @GetMapping("/page-picktask")
    public RestMessage<Page<PickTaskDDTO>> getPickTaskPage(String pickOrderId, String itemCode, String containerCode, Integer pageNum, Integer pageSize){
        Page<PickTaskDDTO> page = pickTaskService.getPickTaskPage(pickOrderId,itemCode,containerCode,pageNum,pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "待索取任务分页查询(整件/功能库房/整单)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pickTaskType", value = "任务类型（0-整件/2-功能库房/3-整单 4-特殊任务拣货）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "warehouseAreaCode", value = "库区编码", required = false, dataType = "String"),
            @ApiImplicitParam(name = "itemCode", value = "商品编码", required = false, dataType = "String"),
            @ApiImplicitParam(name = "srcCode", value = "订单编号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "tab", value = "1：待索取页面，2：任务索取页面，default：任务索取页面", required = false, dataType = "String")
    })
    @GetMapping("/page-waitpicktask")
    public RestMessage<Page<PickTaskDDTO>> getWaitPickTaskPage(
            String bldgId,
            String pickTaskType,
            String warehouseAreaCode,
            String itemCode,
            String srcCode,
            String warehouseId,
            Integer pageNum,
            Integer pageSize,
            String tab,
            String containerCode
    ){
        Page<PickTaskDDTO> page = pickTaskService.getWaitPickTaskPage(
                bldgId,
                pickTaskType,
                warehouseAreaCode,
                itemCode,
                srcCode,
                warehouseId,
                pageNum,
                pageSize,
                tab,
                containerCode
        );
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "(整件)拣选任务分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "0：任务索取  1：任务确认 2:已确认(补打标签)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pickOrderId", value = "拣选单id", required = false, dataType = "String"),
            @ApiImplicitParam(name = "operatorCode", value = "索取人工号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "barcode", value = "条码", required = false, dataType = "String"),
            @ApiImplicitParam(name = "srcCode", value = "订单编号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "itemCode", value = "商品编号", required = false, dataType = "String")
    })
    @GetMapping("/page-picktaskall")
    public RestMessage<Page<PickTaskDDTO>> getPickTaskAllPage(
            String bldgId,
            String type,
            String pickOrderId,
            String itemCode,
            String operatorCode,
            String barcode,
            String srcCode,
            String warehouseId,
            String billType,
            String containerNo,
            Integer pageNum,
            Integer pageSize
    ){
        Page<PickTaskDDTO> page = pickTaskService.getPickTaskAllPage(
                bldgId,
                type,
                pickOrderId,
                itemCode,
                operatorCode,
                barcode,
                srcCode,
                warehouseId,
                billType,
                containerNo,
                pageNum,
                pageSize
        );
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "(功能/整单)任务确认 分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pickTaskType", value = "任务类型（2-功能库房/3-整单）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pickOrderId", value = "拣选单id", required = false, dataType = "String"),
            @ApiImplicitParam(name = "operatorCode", value = "索取人工号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "srcCode", value = "订单编号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "itemCode", value = "商品编号", required = false, dataType = "String")
    })
    @GetMapping("/page-mixpicktaskall")
    public RestMessage<Page<PickTaskDDTO>> getMixPickTaskAllList(
            String bldgId,
            String pickTaskType,
            String pickOrderId,
            String itemCode,
            String operatorCode,
            String srcCode,
            String warehouseId,
            Integer pageNum,
            Integer pageSize
    ){
        Page<PickTaskDDTO> page = pickTaskService.getMixPickTaskAllList(bldgId,pickTaskType,pickOrderId, itemCode, operatorCode, srcCode,warehouseId, pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-索取任务")
    @PostMapping("/outercheck-gain")
    public RestMessage<Integer> outerCheckGain(@RequestBody List<OuterCheckGainVO> vos){
        return RestMessage.success("操作成功", barCodeService.outerCheckGain(vos));
    }

    @UserLog
    @ApiOperation(value = "外复核-查询已索取任务主表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "operatorCode", value = "索取人工号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int")
    })
    @GetMapping("/page-outercheckh")
    public RestMessage<Page<WaveBillDODTO>> getOuterCheckH(String bldgId,String warehouseId, String operatorCode,String srcBillCode,String barcode, Integer pageNum, Integer pageSize){
        Page<WaveBillDODTO> page = barCodeService.getOuterCheckH(bldgId,warehouseId,operatorCode,srcBillCode,barcode,pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-查询待索取订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true, dataType = "String")
    })
    @GetMapping("/page-unoutercheckh")
    public RestMessage<Page<WaveBillDODTO>> getUnOuterCheckH(String barcode,String srcBillCode,String bldgId,String warehouseId,@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(name = "pageSize",defaultValue = "15")  Integer pageSize){
        Page<WaveBillDODTO> page = barCodeService.getUnOuterCheckH(barcode,srcBillCode,null,bldgId,warehouseId,pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-查询待索取订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true, dataType = "String")
    })
    @GetMapping("/page-unoutercheckh2")
    public RestMessage<Page<WaveBillDODTO>> getUnOuterCheckH2(String barcode,String srcBillCode,String bldgId,String warehouseId,String partlyRed,String billtypeGroup ,@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(name = "pageSize",defaultValue = "15")  Integer pageSize){
        Page<WaveBillDODTO> page = barCodeService.getUnOuterCheckH2(barcode,srcBillCode,null,bldgId,warehouseId,partlyRed,billtypeGroup,pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-查询草单主表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true, dataType = "String")
    })
    @GetMapping("/page-outercheck-order")
    public RestMessage<Page<WaveBillDODTO>> getOuterCheckHOrder(String srcBillCode,String bldgId,String warehouseId, Integer pageNum, Integer pageSize){
        Page<WaveBillDODTO> page = barCodeService.getOuterCheckHOrder(srcBillCode,bldgId,warehouseId,pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-根据订单号查询条码明细")
    @ApiImplicitParam(name = "srcCode", value = "订单编号", required = true, dataType = "String")
    @GetMapping("/list-barcodeh")
    public RestMessage<List<BarcodeHDO>> getBarcodeHList(String srcCode, String warehouseId, String bldgId){
        List<BarcodeHDO> list = barCodeService.getBarcodeHList(srcCode,warehouseId,bldgId);
        return RestMessage.success("操作成功", list);
    }

    @UserLog
    @ApiOperation(value = "外复核-查询商品明细")
    @ApiImplicitParam(name = "srcCode", value = "订单编号", required = true, dataType = "String")
    @GetMapping("/list-outercheckd")
    public RestMessage<List<OuterCheckDDTO>> getOuterCheckD(String srcCode,String warehouseId,String bldgId){
        List<OuterCheckDDTO> list = barCodeService.getOuterCheckD(srcCode,warehouseId,bldgId);
        return RestMessage.success("操作成功", list);
    }

    @UserLog
    @ApiOperation(value = "自提外复核-查询待索取订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", required = true, dataType = "String")
    })
    @GetMapping("/page-unoutercheckh-self")
    public RestMessage<Page<WaveBillDODTO>> getUnOuterCheckHSelf(String barcode,String srcCode,String bldgId,String warehouseId,@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(name = "pageSize",defaultValue = "15")  Integer pageSize){
        Page<WaveBillDODTO> page = barCodeService.getUnOuterCheckH(barcode,srcCode,1,bldgId,warehouseId,pageNum, pageSize);
        return RestMessage.success("操作成功", page);
    }

    @UserLog
    @ApiOperation(value = "外复核-复核确认")
    @ApiImplicitParam(name = "params", required = true, value = "{\"operatorCode\":\"工号\",\"srcCodes\":\"srcCode 列表\",\"warehouseId\":\"仓id\",\"bldgId\":\"建筑物id\"}")
    @PostMapping("/outercheck-confirm")
    public RestMessage<?> outerCheckConfirm(@RequestBody Map<String ,Object> params){
        List<String> srcCodes = (List<String>)params.get("srcCodes");
        String operatorCode = (String)params.get("operatorCode");
        String warehouseId = (String)params.get("warehouseId");
        String bldgId = (String)params.get("bldgId");
        //部分冲红标识
        String partlyRed = "";
//        if(params.get("partlyRed")!=null){
//            partlyRed = params.get("partlyRed").toString();
//        }
//        //查询集货区
//        Map<String,String> codeMap = new HashMap<>();
//        for(String srcCode:srcCodes){
//            //查询集货区
//            Map<String, Object> map = MapUtils.put("billGroupId", srcCode).put("buildingCode", bldgId).getMap();
//            List<WorkStageRuntimeDO> stages = workStageRuntimeMapper.findByMap(map, WorkStageRuntimeDO.class);
//            List<String> stageCodes = stages.stream().map(x -> x.getStageCode()).collect(toList());
//            String codes = String.join(",", stageCodes);
//            codeMap.put(srcCode,codes);
//        }
        barCodeService.outerCheckConfirm(srcCodes,operatorCode,warehouseId,bldgId);
        //部分冲红，未冲红部分移入盘点库，并生成移库单
//        if(!StringUtils.isEmpty(partlyRed)&&partlyRed.equals("1")){
//            List<ReportData> reportData = barCodeService.outerCheckConfirmMove(srcCodes, operatorCode, warehouseId, bldgId,codeMap);
//            return RestMessage.success("操作成功", reportData);
//        }
//        if(!StringUtils.isEmpty(partlyRed)&&partlyRed.equals("1")){
//            List<ReportData> reportData = barCodeService.outerCheckConfirmMove(srcCodes, operatorCode, warehouseId, bldgId,codeMap);
//            return RestMessage.success("操作成功", reportData);
//        }
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "外复核-冲红")
    @ApiImplicitParam(name = "params", required = true, value = "{\"operatorCode\":\"工号\",\"srcCodes\":\"srcCode 列表\",\"warehouseId\":\"仓id\",\"bldgId\":\"建筑物id\"}")
    @PostMapping("/outercheck-red")
    public RestMessage<?> outerCheckRed(@RequestBody Map<String ,Object> params){
        barCodeService.outerCheckRed(params);
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "自提出库外复核-复核确认")
    @ApiImplicitParam(name = "params", required = true, value = "{\"operatorCode\":\"工号\",\"srcCodes\":\"srcCode 列表\",\"warehouseId\":\"仓id\",\"bldgId\":\"建筑物id\"}")
    @PostMapping("/outercheck-self-confirm")
    public RestMessage<?> outerCheckConfirmSelf(@RequestBody OuterCheckPickUpVO vo){
        barCodeService.outerCheckConfirmSelf(vo);
        return RestMessage.success("操作成功", null);
    }


    @UserLog
    @ApiOperation(value = "查询拣货工作量")
    @ApiImplicitParam(name = "params", required = true, value = "{\"type\":\"0-整件 1-零货 2-功能库房\",\"warehouseId\":\"仓id\"}")
    @PostMapping("/picktask-count")
    public RestMessage<PickTaskCountDTO> getPickTaskCount(@RequestBody Map<String ,Object> params){
//        List<Map<String, String>> list = (List<Map<String, String>>)params.get("list");
        String warehouseId = (String)params.get("warehouseId");
        Integer type = (Integer)params.get("type");
        return RestMessage.success("操作成功", pickTaskService.getPickTaskCount(type,warehouseId));
    }


    @UserLog
    @ApiOperation(value = "打印拣货纸单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"pickOrderIds\":\"拣货单id数组\",\"warehouseId\":\"仓id\",\"bldgId\":\"建筑物id\",\"pickTaskType\":\"0-整件 1-零货 2-功能库房 3-整单\"}")
    @PostMapping("/print-paperslip")
    public RestMessage<List<PrintData>> printPaperSlip(@RequestBody Map<String ,Object> params){
        List<String> pickOrderIds = (List<String>)params.get("pickOrderIds");
        String warehouseId = (String)params.get("warehouseId");
        String bldgId = (String)params.get("bldgId");
        String pickTaskType = (String)params.get("pickTaskType");
        List<PrintData> data = pickTaskService.printPaperSlip(pickOrderIds, warehouseId, bldgId, pickTaskType);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "打印外复核草单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"srcCodes\":\"合单单号数组\",\"warehouseId\":\"仓id\"}")
    @PostMapping("/print-paperslip-outer")
    public RestMessage<List<PrintData>> printOuterPaperSlip(@RequestBody Map<String ,Object> params){
        List<String> srcCodes = (List<String>)params.get("srcCodes");
        String warehouseId = (String)params.get("warehouseId");
        String warehouseName = (String)params.get("warehouseName");
        List<PrintData> data = barCodeService.printOuterPaperSlip(srcCodes,warehouseId,warehouseName);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "打印外复核报告单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"srcCodes\":\"合单单号数组\",\"warehouseId\":\"仓id\"}")
    @PostMapping("/print-paperReport-outer")
    public RestMessage<List<PrintData>> printOuterPaperReport(@RequestBody Map<String ,Object> params){
        List<String> srcCodes = (List<String>)params.get("srcCodes");
        String warehouseId = (String)params.get("warehouseId");
        String warehouseName = (String)params.get("warehouseName");
        List<String> itemLots = new ArrayList<>();
        if(ObjectUtils.isNotNull(params.get("itemLots"))){
            itemLots = (List<String>)params.get("itemLots");
        }
        List<PrintData> data = barCodeService.printReportPaperSlip(srcCodes,warehouseId,warehouseName,itemLots);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "打印出库清单、特殊订单、自提单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"srcCodes\":\"合单单号数组\",\"warehouseId\":\"仓id\"}")
    @PostMapping("/print-delivery-outer")
    public RestMessage<List<PrintData>> printDeliveryOuter(@RequestBody Map<String ,Object> params){
        List<String> srcCodes = (List<String>)params.get("srcCodes");
        String warehouseId = (String)params.get("warehouseId");
        String warehouseName = (String)params.get("warehouseName");
        List<PrintData> data = barCodeService.printDeliveryOuter(srcCodes,warehouseId,warehouseName);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "打印外复核单")
    @ApiImplicitParam(name = "params", required = true, value = "{\"srcCodes\":\"合单单号数组\",\"warehouseId\":\"仓id\"}")
    @PostMapping("/print-paperslip-outerh")
    public RestMessage<List<PrintData>> printOuterPaperSlipH(@RequestBody Map<String ,Object> params){
        List<String> srcCodes = (List<String>)params.get("srcCodes");
        String warehouseId = (String)params.get("warehouseId");
        String warehouseName = (String)params.get("warehouseName");
        List<PrintData> data = barCodeService.printOuterPaperSlipH(srcCodes,warehouseId,warehouseName);
        return RestMessage.success("操作成功", data);
    }

    @UserLog
    @ApiOperation(value = "打印整件拣货标签(PDA)")
    @GetMapping("/print-whole-label")
    public RestMessage<List<PrintData>> printWholeLabel(String pickTaskDId){
        return RestMessage.success("操作成功", pickTaskService.printWholeLabel(pickTaskDId));
    }

    @UserLog
    @ApiOperation(value = "打印整件拣货/补货标签")
    @RepeatOperationLock(timeOut = 1000)
    @ApiImplicitParam(name = "params", required = true, value = "{\"pickTaskDIds\":\"id数组\",\"warehouseId\":\"仓id\",\"type\":\"类型：0-拣货 1-补货\"}")
    @PostMapping("/print-whole-labels")
    public RestMessage<List<PrintDataWithMark>> printWholeLabels(@RequestBody Map<String ,Object> params){
        List<String> pickTaskDIds = (List<String>)params.get("pickTaskDIds");
        List<String> barcodeIds = (List<String>)params.get("barcodeIds");
        String warehouseId = (String)params.get("warehouseId");
        Integer type = (Integer)params.get("type");
        return RestMessage.success("操作成功", pickTaskService.printWholeLabels(pickTaskDIds,barcodeIds,warehouseId,type,null));
    }

    @UserLog
    @ApiOperation(value = "查询AGV拣货明细,生成新的拣货数据")
    @PostMapping("/picktask-confrim")
    public RestMessage<?> pickTaskConfrim(){
        pickTaskService.pickTaskConfrim();
        return RestMessage.success("操作成功", "");
    }
    
    @ApiOperation(value = "保存设备拣货数据")
    @PostMapping("/pickTaskConfirm")
    public RestMessage<?> confirmDevicePickTask(@RequestBody List<ContainerBindTaskDto> containerBindTaskDtoList){
        pickTaskService.confirmDevicePickTask(containerBindTaskDtoList);
        return RestMessage.success("操作成功", "");
    }

    @ApiOperation(value = "手动下发agv拣货数据")
    @PostMapping("/manualSendAgv")
    public RestMessage<?> manualSendAgv(@RequestBody List<String> billGroupIds){
        pickTaskService.manualSendAgv(billGroupIds);
        return RestMessage.success("操作成功", "");
    }

    @ApiOperation(value = "AGV任务推送")
    @PostMapping("/v1/sendDeviceTaskList")
    public RestMessage<?> sendDeviceTaskList(@RequestBody List<InfTaskOutVO> infTaskOutVOList) {
        return RestMessage.success("操作成功", pickTaskService.sendDeviceTaskList(infTaskOutVOList));
    }

    @ApiOperation(value = "重新推送失败的AGV任务-定时任务")
    @PostMapping("/v1/reSendDeviceTaskList")
    public RestMessage<?> reSendDeviceTaskList() {
        return RestMessage.success("操作成功", pickTaskService.reSendDeviceTaskList());
    }

    @ApiOperation(value = "AGV托盘,四向库回告")
    @PostMapping("/v1/infTaskOutBack/pallet")
    @RepeatOperationLock(timeOut = 500)
    public RestMessage<List<InfTaskOutBackDTO>> infTaskOutBackPallet(@RequestBody List<InfTaskOutBackDTO> infTaskOutBackDTOList) {
        return pickTaskService.infTaskOutBack(infTaskOutBackDTOList);
    }

    @ApiOperation(value = "AGV货架回告")
    @PostMapping("/v1/infTaskOutBack/agvLBack")
    @RepeatOperationLock(timeOut = 500)
    public RestMessage<List<InfTaskOutBackDTO>> agvlBack(@RequestBody List<InfTaskOutBackDTO> infTaskOutBackDTOList) {
        return pickTaskService.infTaskOutBackAgvL(infTaskOutBackDTOList);
    }

    @ApiOperation(value = "播种容器绑定校验,批量校验")
    @PostMapping("/v1/validateContainerNoList")
    @RepeatOperationLock(timeOut = 500)
    public RestMessage<List<ValidateContainerNoDTO>> validateContainerNoList(@RequestBody List<ValidateContainerNoDTO> containerNoList) {
        return pickTaskService.validateContainerNoList(containerNoList);
    }

    @ApiOperation(value = "出库回传接口数据查询")
    @PostMapping("/v1/queryOutboundDataToOms")
    public RestMessage<?> queryOutboundDataToOms() {
        List<String> omsBillIds = new ArrayList<>();
        return RestMessage.success("操作成功", pickTaskService.queryOutboundDataToOms(omsBillIds));
    }

    @UserLog
    @ApiOperation(value = "单据补打-按任务查询补打列表")
    @PostMapping("/v1/print/again/task-list")
    public RestMessage<Page<RePrintWholeDto>> taskListForPrintAgain(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.taskListForPrintAgain(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-按订单补打")
    @PostMapping("/v1/print/again/bill")
    public RestMessage<List<PrintDataWithMark>> billPrintAgain(@RequestBody TaskPrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.billPrintAgain(printAgainVo));
    }

    @ApiOperation(value = "定时回传托盘拣货完成至EIS")
    @PostMapping("/v1/eis/containerConfirm")
    public RestMessage<String> sendPickEndToEis() {
        pickTaskService.sendPickEndToEis();
        return RestMessage.newInstance(true, "查询成功", "");
    }

    @ApiOperation(value = "TMS启运回传释放集货区")
    @PostMapping("/v1/tms/releaseWorkStageByTms")
    public RestMessage<String> releaseWorkStageByTms(@RequestBody Map<String,Object> map) {
        if(ObjectUtils.isNull(map.get("billId"))){
            throw new BizException("订单号不能为空");
        }
        String billGroupId = map.get("billId").toString();
        workStageService.releaseWorkStage(billGroupId);
        return RestMessage.newInstance(true, "查询成功", "");
    }
	
	@UserLog
    @ApiOperation(value = "单据补打-整件汇总列表")
    @PostMapping("/v1/print/again/task-list/whole")
    public RestMessage<Page<RePrintWholeDto>> listWholeLabelRepair(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.listWholeLabelRepair(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-打印整件标签")
    @PostMapping("/v1/print/again/wholeLabels")
    public RestMessage<List<PrintDataWithMark>> wholeLabelRepairPrint(@RequestBody PrintAgainVo printAgainVo){
        return RestMessage.success("操作成功", pickTaskService.wholeLabelRepairPrint(printAgainVo));
    }

/*    @UserLog
    @ApiOperation(value = "单据补打-面单整件")
    @PostMapping("/v1/print/again/all")
    public RestMessage<String> printAll(@RequestBody List<PrintAllVO> VOList){
        pickTaskService.printAll(VOList);
        return RestMessage.success("操作成功", null);
    }*/

    @UserLog
    @ApiOperation(value = "单据补打-面单整件")
    @PostMapping("/v1/print/again/all")
    public RestMessage<Object> printAll(@RequestBody List<PrintAllVO> VOList){
        return RestMessage.newInstance(true, "printAgainAllSuccess", pickTaskService.printAll(VOList));
    }


    @UserLog
    @ApiOperation(value = "单据补打-拼箱汇总列表")
    @PostMapping("/v1/print/again/task-list/spell")
    public RestMessage<Page<RePrintBulkDto>> listSpellLabelRepair(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.listSpellLabelRepair(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-整散合一明细")
    @PostMapping("/v1/print/again/task-list/wholeBulk/detail")
    public RestMessage<List<RePrintWholeBulkDetailDto>> listWholeBulkDetailRepair(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.listWholeBulkDetailRepair(printAgainVo.getIds()));
    }

    @UserLog
    @ApiOperation(value = "单据补打-拼箱明细")
    @PostMapping("/v1/print/again/task-list/bulk/detail")
    public RestMessage<List<RePrintBulkDetailDto>> listSpellLabelDetailRepair(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.listSpellLabelDetailRepair(printAgainVo.getIds()));
    }

    @UserLog
    @ApiOperation(value = "单据补打-打印拼箱数据")
    @PostMapping("/v1/print/again/lcl/print")
    public RestMessage<List<PrintDataWithMark>> printLcl(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.doSuccess(pickTaskService.printLcl(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-打印整散合一纸单")
    @PostMapping("/v1/print/again/print-paperslip")
    public RestMessage<List<PrintDataWithMark>> printAgainPaperSlip(@RequestBody PrintAgainVo printAgainVo){
        return RestMessage.doSuccess(pickTaskService.printAgainPaperSlip(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-整散合一汇总列表")
    @PostMapping("/v1/print/again/task-list/wholeBulk")
    public RestMessage<Page<RePrintWholeBulkDto>> listWholeBulkRepair(@RequestBody PrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.listWholeBulkRepair(printAgainVo));
    }

    @UserLog
    @ApiOperation(value = "单据补打-按任务补打")
    @PostMapping("/v1/print/again/task")
    public RestMessage<List<PrintDataWithMark>> taskPrintAgain(@RequestBody TaskPrintAgainVo printAgainVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.taskPrintAgain(printAgainVo));
    }

    /*@ApiOperation(value = "EIS获取打印数据")
    @PostMapping("/v1/eis/print/data")
    public RestMessage<List<EisPrintDataOutDto>> eisPrintData(@RequestBody List<InfTaskOutBackDTO> eisPrintDataVo) {
        return RestMessage.newInstance(true, "查询成功", pickTaskService.eisPrintData(eisPrintDataVo));
    }*/

    @UserLog
    @ApiOperation(value = "通过标签进行-拣货确认")
    @PostMapping("/confirm/byLabel")
    public RestMessage<?> pickTaskConfirmByLabel(@RequestBody Map<String, String> param){
        pickTaskService.confirmPickTaskByBarcode(param.get("barcode"));
        return RestMessage.success("操作成功", null);
    }

    @UserLog
    @ApiOperation(value = "定时任务回传OMS装箱信息")
    @PostMapping("/autoPostBackOmsPackingData")
    public RestMessage<?> autoPostBackOmsPackingData(){
        postBackErpService.autoPostBackOmsPackingData();
        return RestMessage.success("操作成功",null);
    }

    @UserLog
    @ApiOperation(value = "EIS作业完成回告")
    @PostMapping("/completeTask")
    public RestMessage<Map<String, Object>> completeTask(@RequestBody List<CompleteTaskVO> list) {
        Map<String, Object> map = pickTaskService.completeTask(list);
        String taskHIds =  map.get("taskHIds") == null ? null : (String) map.get("taskHIds");
        ServletRequestAttributes reqa = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        new Thread(()-> {
            RequestContextHolder.setRequestAttributes(reqa, false);
            ServletRequestAttributes servletRequestAttributes =
                    (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
            String userkey = servletRequestAttributes.getRequest().getHeader("UserKey");

            if (!HystrixRequestContext.isCurrentThreadInitialized()) {
                HystrixRequestContext.initializeContext();
            }
            HystrixVarUtil.setUserKey(userkey);
            try {
                pickTaskService.printDetailAndFp(taskHIds);
            }catch (Exception e) {
                log.error("作业完成回告打印失败：{}", e.getMessage());
            }finally {
                RequestContextHolder.resetRequestAttributes();
            }
        }).start();
        return RestMsgHelper.runAndGet(() -> map);
    }

    @UserLog
    @ApiOperation(value = "EIS超补更新补货明细对应出库任务明细数量")
    @PostMapping("/changeTaskQty")
    public RestMessage changeTaskQty(@RequestBody List<MarkTaskItemVO> list) {
        pickTaskService.changeTaskQty(list);
        return RestMessage.success("操作成功",null);
    }
}
