package com.sw.mes.wms.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSONObject;
import com.sw.mes.core.annotation.Jinko;
import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.utils.StringUtils;
import com.sw.mes.wms.dao.LogWmsMesInteractiveDao;
import com.sw.mes.wms.entity.LogWmsMesInteractive;
import com.sw.mes.wms.service.LogWmsMesInteractiveService;

import lombok.extern.slf4j.Slf4j;

/**
 * 晶科WMS下发数据通信记录Service业务层处理
 *
 * @author liru
 * @date 2024-01-08
 */
@Slf4j
@Service
@Transactional
@Jinko(value = "晶科WMS下发数据通信记录Service业务层处理", author = "liru")
public class LogWmsMesInteractiveServiceImpl extends BaseServiceImpl<LogWmsMesInteractive> implements LogWmsMesInteractiveService {
    private LogWmsMesInteractiveDao dao;

    @Autowired
    public void setDao(LogWmsMesInteractiveDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    @Override
    public List<LogWmsMesInteractive> filterWMSToWarehouse(int page, int pageSize) {
        List<Map<String, Object>> list = dao.filterWMSToWarehouse(page, pageSize);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }

        for (Map<String, Object> map : list) {
            String returnContext = map.get("rtn").toString();
            JSONObject ES_BC_INFO = JSONObject.parseObject(returnContext).getJSONObject("ES_BC_INFO");
            String resultState = ES_BC_INFO.getString("TYPE");
            if (StringUtils.isBlank(resultState) || resultState.equals("E")) {//返回的error
                continue;
            }

        }

        return null;
    }

	@Override
	public List<LogWmsMesInteractive> findByControllerNameAndTimeRange(String controllerName, String createTimeStart, String createTimeEnd) {
		return dao.findByControllerNameAndTimeRange(controllerName,createTimeStart,createTimeEnd);
	}
}
