whycxzp
2025-03-21 7a5fb2587abdfdcc6ecf8ed283f0b10e4aa5b10b
src/main/java/com/whyc/service/WmsService.java
@@ -1,10 +1,7 @@
package com.whyc.service;
import com.google.gson.reflect.TypeToken;
import com.whyc.dto.Response;
import com.whyc.dto.WmsLocationDto;
import com.whyc.dto.WmsMaterialDto;
import com.whyc.dto.WmsPalletDto;
import com.whyc.dto.*;
import com.whyc.util.HttpUtil;
import com.whyc.util.JsonUtil;
import org.springframework.stereotype.Service;
@@ -14,10 +11,6 @@
@Service
public class WmsService {
    /**
     * TODO ip和端口待确定调整
     * @return
     */
    public Response getMaterialList() {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_material/get_all";
        Response response = HttpUtil.doGet(httpUrl, (String) null);
@@ -52,7 +45,7 @@
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            Response responseInside = JsonUtil.getGson().fromJson(dataStr, Response.class);
            WmsResponse responseInside = JsonUtil.getGson().fromJson(dataStr, WmsResponse.class);
            response.set(1,responseInside);
        }
        return response;
@@ -64,10 +57,29 @@
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            //截取dataStr中"data:"后的字符串
            int index = dataStr.indexOf("data");
            dataStr = dataStr.substring(index+6, dataStr.length()-3);
            //WmsLocationDto wmsLocationDto = JsonUtil.getGson().fromJson(dataStr, WmsLocationDto.class);
            List<WmsLocationDto> wmsLocationDtoList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsLocationDto>>(){}.getType());
            response.set(1,wmsLocationDtoList);
        }
        return response;
    }
    public Response getPalletList() {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_pallet/get_all";
        Response response = HttpUtil.doGet(httpUrl, (String) null);
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            //截取dataStr中"data:"后的字符串
            int index = dataStr.indexOf("data");
            dataStr = dataStr.substring(index+6, dataStr.length()-3);
            //WmsLocationDto wmsLocationDto = JsonUtil.getGson().fromJson(dataStr, WmsLocationDto.class);
            List<WmsPallet> wmsPalletList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsPallet>>(){}.getType());
            response.set(1,wmsPalletList);
        }
        return response;
    }
}