package com.whyc.service; import com.google.gson.reflect.TypeToken; import com.whyc.dto.*; import com.whyc.pojo.db_wms.Task; import com.whyc.util.HttpUtil; import com.whyc.util.JsonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Service public class WmsService { @Autowired private TaskService taskService; public Response getMaterialList() { String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_material/get_all"; Response response = HttpUtil.doGet(httpUrl, (String) null); //对结果进行处理 if(response.getCode() == 1){ //请求成功,data有正常数据 String dataStr = (String) response.getData(); //WmsMaterialDto wmsMaterialDto = JsonUtil.getGson().fromJson(dataStr, WmsMaterialDto.class); List wmsMaterialDtoList = JsonUtil.getGson().fromJson(dataStr, new TypeToken>(){}.getType()); response.set(1,wmsMaterialDtoList); } return response; } /** * * @param palletDto * @return * 响应报文 * 实例 { * "code": 0, * "message": "string" * } * 参数说明 字段名称 参数类型 字段描述 * code Int 接口通信返回编码详细信息, 0:成功 * message String 详细信息 * 会自动根据返回编码Code在信息前增加Code详情 */ public Response sendTask(WmsPalletDto palletDto) { String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_pallet/WmsOutTask"; Response response = HttpUtil.doPost(httpUrl, JsonUtil.getGson().toJson(palletDto)); //对结果进行处理 if(response.getCode() == 1){ //请求成功,data有正常数据 String dataStr = (String) response.getData(); WmsResponse responseInside = JsonUtil.getGson().fromJson(dataStr, WmsResponse.class); response.set(1,responseInside); //对下发的任务进行数据库存储 Task task = new Task(); task.setTaskNo(responseInside.getTask_no()); task.setDes(palletDto.getDes()); //将字符串列表转为1组字符串,每个元素用逗号分割 List pallets = palletDto.getPallets(); task.setPallets(String.join(",", pallets)); List activateParameter = palletDto.getActivateParameter(); task.setActivateParameter(String.join(",",activateParameter)); Date date = new Date(); task.setCreateTime(date); taskService.add(task); } return response; } public Response getLocationList() { String httpUrl = "http://192.168.10.133:8051"+"/api/wms_location/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 wmsLocationDtoList = JsonUtil.getGson().fromJson(dataStr, new TypeToken>(){}.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 wmsPalletList = JsonUtil.getGson().fromJson(dataStr, new TypeToken>(){}.getType()); response.set(1,wmsPalletList); } return response; } }