package com.wms_main.controller.wms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.wms_main.model.dto.request.ewm.SendEwmGetStockInformationRequest;
import com.wms_main.model.dto.request.ewm.SendWarehouseInCompletedRequest;
import com.wms_main.model.dto.request.ewm.SendWarehouseOutCompletedRequest;
import com.wms_main.model.dto.request.wcs.WcsVehicleInRequest;
import com.wms_main.model.dto.response.ewm.EwmApiBackResponse;
import com.wms_main.model.dto.response.ewm.EwmApiStockResponse;
import com.wms_main.model.po.TAppEquipment;
import com.wms_main.model.po.TAppLocation;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.repository.utils.UUIDUtils;
import com.wms_main.service.api.IEwmApiService;
import com.wms_main.service.business.IStackerTaskService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

/**
 * 测试专用
 */
@RestController
@ResponseBody
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/test")
public class TestController {
    private static final Logger log = LoggerFactory.getLogger(TestController.class);
    private final IEwmApiService ewmApiService;
    private final IStackerTaskService stackerTaskService;// 堆垛机任务服务
    @GetMapping(value = "/test")
    public String testApi() {
        return UUIDUtils.getNewUUID();
    }

    /**
     * test
     */
//    @PostMapping("/status")
//    public EwmApiBackResponse test(@RequestBody WcsVehicleInRequest wcsVehicleInRequest) {
//        // 回告EWm系统出库完成
//        SendWarehouseOutCompletedRequest request = new SendWarehouseOutCompletedRequest();
//        List<SendWarehouseOutCompletedRequest.PickingDetail> pickingDetails = new ArrayList<>();
//        SendWarehouseOutCompletedRequest.PickingDetail pickingDetail = new SendWarehouseOutCompletedRequest.PickingDetail();
//        pickingDetail.setTaskNo("confirmTaskRequest.getTaskConfirm().getTaskId()");
//        pickingDetail.setMatNo("confirmTaskRequest.getTaskConfirm().getGoodsId()");
//        pickingDetail.setPickingQty(1.0);
//        pickingDetail.setActQty(2.0);
//        pickingDetail.setUnit("件");
//        pickingDetail.setContainerNo("1");
//        pickingDetails.add(pickingDetail);
//        request.setPickingDetailParams(pickingDetails);
//        EwmApiBackResponse ewmApiBackResponse = ewmApiService.sendWarehouseOutCompleted(request);
////        if (!ewmApiBackResponse.getSuccessful()) {
////            log.error("调用EWM系统接口异常，请求参数: {}", request);
////        }else {
////            log.info("调用EWM系统接口成功，请求参数: {}", request);
////        }
//        return ewmApiBackResponse;
//    }

    @PostMapping("/status2")
    public EwmApiStockResponse test2(@RequestBody SendEwmGetStockInformationRequest  request) {
        //List<EwmApiStockResponse.BinStock> binStocks = ewmApiService.getEwmStock(request).getContent();
        return ewmApiService.getEwmStock(request);
    }

    @PostMapping("/status3")
    public String test3() {
        //List<Integer> equipmentIds = stackerTaskService.test();
        TAppLocation targetLocation = stackerTaskService.requestOneLocation(null, "5555");
        return targetLocation.getLocationId();
    }
}
