package com.shkj.wcs.controller.busin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shkj.common.annotation.Log;
import com.shkj.common.annotation.RepeatSubmit;
import com.shkj.common.enums.BusinessType;
import com.shkj.common.utils.DateUtils;
import com.shkj.wcs.service.IBusinDataTaskService;
import com.shkj.wcs.third.rcs.RCSUtil;
import com.shkj.wcs.third.rcs.dto.RcsCreateTaskDto;
import com.shkj.wcs.third.rcs.dto.RcsIdList;
import com.shkj.wcs.third.rcs.enums.RCSOperation;
import com.shkj.wcs.third.rcs.enums.RCSTaskTypeEnum;
import com.shkj.wcs.third.workbinWcs.WCSUtil;
import com.shkj.wcs.third.workbinWcs.dto.*;
import com.shkj.wcs.vo.WcsResponseVo;
import com.shkj.wcs.domain.BusinDataTask;
import com.shkj.wms.enums.TaskStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor(onConstructor_ =@Autowired)
@RestController
@RequestMapping("/api")
public class WcsTaskController {

    @Autowired
    private IBusinDataTaskService iBusinDataTaskService;

    @Autowired
    private RCSUtil rcsUtil;

    @Autowired
    private WCSUtil wcsUtil;


    /**
     * wz-wcs任务下发
     */
    @PostMapping("/toKjWcs/commonApi")
    @RepeatSubmit
    public WcsResponseVo commonApi(@Valid @RequestBody  WcsCreateTaskDto bo) {
        return iBusinDataTaskService.doTaskGeneratePickTask(bo);
    }


    @Log(title = "查询是否存在出库任务测试接口")
    @PostMapping("/toWzWcs/queryTaskStatus")
    @RepeatSubmit
    public WcsResponseVo queryTaskStatus(@RequestBody WCSQueryTaskStatusBody body) {
        WcsResponseVo vo = wcsUtil.queryTaskStatus(body);
        return vo;
    }


    @Log(title = "查询每个库区状态测试接口", businessType = BusinessType.UPDATE)
    @PostMapping("/toKjWcs/queryAreaStatus")
    @RepeatSubmit
    public WcsResponseVo queryAreaStatus(@RequestBody WCSQueryAreaStatusDto dto) {
        //测试使用
        List<WCSQueryAreaStatusBody> areaStatusBodyList = new ArrayList<>();
        String[] areaCodes = {"SC-A2", "SC-B2", "SC-C2", "SC-D2"};
        int[] statusValues = {0, 1, 1, 1};
        for (int i = 0; i < 4; i++) {
            WCSQueryAreaStatusBody queryAreaStatusBody = new WCSQueryAreaStatusBody();
            queryAreaStatusBody.setAreaInLocation(areaCodes[i]);
            queryAreaStatusBody.setStatus(statusValues[i]);
            areaStatusBodyList.add(queryAreaStatusBody);
        }
        log.info("查询结果及返回结果："+ JSONObject.toJSONString(areaStatusBodyList));
        return WcsResponseVo.success(areaStatusBodyList);
    }


    @Log(title = "任务状态上报测试接口", businessType = BusinessType.UPDATE)
    @PostMapping("/toWzWcs/uploadWCSTaskStatus")
    @RepeatSubmit
    public WcsResponseVo uploadWCSTaskStatus(@RequestBody UploadWCSTaskStatusDto dto) {
        //调用plc接口 暂时不用
        WcsResponseVo vo = wcsUtil.uploadWCSTaskStatus(dto);
        return vo;
    }


    @Log(title = "扫码处入库申请测试接口", businessType = BusinessType.UPDATE)
    @PostMapping("/toWzWcs/wcsIncomingTaskRequest")
    @RepeatSubmit
    public WcsResponseVo wcsIncomingTaskRequest(@RequestBody WcsIncomingTaskRequestBody dto) {
        //调用plc接口 暂时不用
        WcsResponseVo vo = wcsUtil.wcsIncomingTaskRequest(dto);
        return vo;
    }

    @Log(title = "生产区入库校验测试接口", businessType = BusinessType.UPDATE)
    @PostMapping("/toWzWcs/wcsIncomingTrayCheck")
    @RepeatSubmit
    public WcsResponseVo wcsIncomingTrayCheck(@RequestBody WcsIncomingTrayCheckBody dto) {

        WcsResponseVo vo = wcsUtil.wcsIncomingTrayCheck(dto);
        return vo;
    }




}


