Commit d6f0806e hjh

富士接口代码提交

1 个父辈 aa41a5d9
package com.neotel.smfcore.custom.fushi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.core.api.listener.DefaultSmfApiListener;
import com.neotel.smfcore.custom.fushi.bean.FushiApiToken;
import com.neotel.smfcore.custom.fushi.bean.InventoryDid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class FuShiApi extends DefaultSmfApiListener {
@Value("${smd.userName}")
private String userName;
@Value("${smd.password}")
private String password;
@Value("${smd.url}")
private String fuShiUrl;
public static final String tokenUrl = "auth/login";
public static final String inventoryUrl = "inventory/dids";
private String accessToken;
public String getAccessToken() {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("userName", userName);
paramMap.put("password", password);
log.info("getAccessToken调用参数为:" + JSON.toJSONString(paramMap));
String result = "";
try {
String url = fuShiUrl + tokenUrl;
result = HttpHelper.postJson(url, paramMap);
// result = "{\n" +
// " \"accessToken\": \"accessToken1234\",\n" +
// " \"refreshToken\": \"refreshToken12345\"\n" +
// "}";
log.info("getAccessToken接口返回为:" + result);
FushiApiToken fushiApiToken = JSONObject.parseObject(result, FushiApiToken.class);
result = fushiApiToken.getAccess_token();
accessToken = fushiApiToken.getAccess_token();
} catch (Exception e) {
e.printStackTrace();
log.info("getAccessToken接口错误信息为:" + e.getMessage());
}
return result;
}
public List<String> getInventoryList(int pageSize, int pageToken) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("pageSize", pageSize);
paramMap.put("pageToken", pageToken);
log.info("getInventoryList调用参数为:" + JSON.toJSONString(paramMap));
List<String> inventoryDids = new ArrayList<>();
String result = "";
try {
String url = fuShiUrl + inventoryUrl;
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("fujiAccessToken", accessToken);
result = HttpHelper.getJson(url,headerMap, paramMap);
// result = "{\n" +
// " \"datas\": [\n" +
// " {\n" +
// " \"did\": \"121\",\n" +
// " \"partNumber\": \"M21000012\",\n" +
// " \"quantity\": 21234\n" +
// " },\n" +
// " {\n" +
// " \"did\": \"12345\",\n" +
// " \"partNumber\": \"M21230012\",\n" +
// " \"quantity\": 16394\n" +
// " },\n" +
// " {\n" +
// " \"did\": \"1223\",\n" +
// " \"partNumber\": \"M21000232\",\n" +
// " \"quantity\": 16734\n" +
// " }\n" +
// " ],\n" +
// " \"metadata\": {\n" +
// " \"totalCount\": 14,\n" +
// " \"pageSize\": 0\n" +
// " }\n" +
// "}";
log.info("getInventoryList接口返回为:" + result);
InventoryDid inventory = JSONObject.parseObject(result, InventoryDid.class);
if (inventory != null) {
if (inventory.getDatas() != null && !inventory.getDatas().isEmpty()) {
for (int i = 0; i < inventory.getDatas().size(); i++) {
String did = inventory.getDatas().get(i).getDid();
inventoryDids.add(did);
}
}
}
} catch (Exception e) {
e.printStackTrace();
log.info("getInventoryList接口错误信息为:" + e.getMessage());
}
return inventoryDids;
}
public String getInventoryAdd(String partBarcode, Integer quantity, String partNumber) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("partBarcode", partBarcode);
paramMap.put("quantity", quantity);
paramMap.put("partNumber", partNumber);
log.info("getInventoryAdd调用参数为:" + JSON.toJSONString(paramMap));
String result = "";
try {
String url = fuShiUrl + inventoryUrl;
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("fujiAccessToken", accessToken);
result = HttpHelper.postJson(url, paramMap, headerMap);
// result = "{\n" +
// " \"addedCount\": 100\n" +
// "}";
log.info("getInventoryAdd接口返回为:" + result);
InventoryDid ResultData = JSONObject.parseObject(result, InventoryDid.class);
Integer addedCount = ResultData.getAddedCount();
result = addedCount + "";
} catch (Exception e) {
e.printStackTrace();
log.info("getInventoryAdd接口错误信息为:" + e.getMessage());
}
return result;
}
}
package com.neotel.smfcore.custom.fushi.bean;
import lombok.Data;
@Data
public class FushiApiToken {
private String access_token;
private String refresh_token;
}
package com.neotel.smfcore.custom.fushi.bean.Inventory;
import lombok.Data;
@Data
public class Datas {
private String did;
private String partNumber;
private String partBarcode;
private String originalPartBarcode;
private Integer quantity;
private String packageType;
private Integer partsoutWarning;
private Integer splicingWarning;
private String vendorName;
private String lotName;
private String dateCode;
private String area;
private String location;
private String machine;
private Integer module;
private Integer stageNo;
private Integer slotNo;
private String createdUser;
private String createDate;
private String updatedUser;
private String updatedDate;
private String dryStatus;
private String boxLife;
private String floorLife;
private String memo;
private String lightingClass;
private Integer lightingLimit;
private String note1;
private String note2;
private String note3;
private String note4;
private boolean useSplicing;
private boolean useTrayPackage;
private Integer trayStackCount;
private Integer trayPickupPositionX;
private Integer trayPickupPositionY;
private Integer traySizeX;
private Integer traySizeY;
}
package com.neotel.smfcore.custom.fushi.bean.Inventory;
import lombok.Data;
@Data
public class MetaData {
private Integer totalCount;
private Integer pageSize;
private Integer pageToken;
private String nextPageToken;
}
package com.neotel.smfcore.custom.fushi.bean;
import com.neotel.smfcore.custom.fushi.bean.Inventory.Datas;
import com.neotel.smfcore.custom.fushi.bean.Inventory.MetaData;
import lombok.Data;
import java.util.List;
@Data
public class InventoryDid {
private List<Datas> datas;
private MetaData metadata;
private Integer addedCount;
}
package com.neotel.smfcore.custom.fushi.controller;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.custom.fushi.FuShiApi;
import com.neotel.smfcore.custom.fushi.bean.InventoryDid;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Api(tags = "fuShi接口")
@Slf4j
@RestController
@RequestMapping("/manuallyPutStorage")
public class ManuallyPutStorageController {
@Autowired
private FuShiApi fuShiApi;
/***
*
* @param barcode
* @param did
*/
@RequestMapping("/PutInStorage")
public ResultBean PutInStorage(@RequestBody Barcode barcode, @RequestParam String did) {
log.info("调用接口PutInStorage用到的参数:" + barcode + " DiD为" + did);
String accessToken = fuShiApi.getAccessToken();
if (accessToken.isEmpty()) {
log.error("调用接口getAccessToken异常");
return ResultBean.newErrorResult(-1, "", "调用接口getAccessToken信息错误,数据为空");
}
Integer pageSize = 12;
Integer pageToken = 0;
List<String> inventoryList = fuShiApi.getInventoryList(pageSize, pageToken);
if (inventoryList == null || inventoryList.size() == 0) {
log.error("调用接口getInventoryList异常");
return ResultBean.newErrorResult(-1, "", "调用接口getInventoryList信息错误,数据为空");
}
boolean inFlag = true;
for (int i = 0; i < inventoryList.size(); i++) {
String inDid = inventoryList.get(i);
if (did.equals(inDid)) {
inFlag = false;
break;
}
}
if (inFlag) {
String partBarcode = barcode.getBarcode();
Integer quantity = barcode.getAmount();
String partNumber = barcode.getPartNumber();
String inventoryAdd = fuShiApi.getInventoryAdd(partBarcode, quantity, partNumber);
if ("".equals(inventoryAdd)) {
log.error("调用接口getInventoryAdd异常");
return ResultBean.newErrorResult(-1, "", "调用getInventoryAdd接口信息错误,数据为空");
}
}
return ResultBean.newOkResult("OK");
}
}
...@@ -12,18 +12,18 @@ spring: ...@@ -12,18 +12,18 @@ spring:
host: localhost # 主机地址 host: localhost # 主机地址
port: 27017 # 端口 port: 27017 # 端口
database: smf # 数据库 database: smf # 数据库
username: username: Siemens
password: password: Siemens
#备份数据库,如果有,则开启,注意:如果主数据库设置了用户名和密码,备份服务器必须设置用户名和密码!! #备份数据库,如果有,则开启,注意:如果主数据库设置了用户名和密码,备份服务器必须设置用户名和密码!!
#西门子的正式和备份数据库,用户名和密码都是Siemens #西门子的正式和备份数据库,用户名和密码都是Siemens
#backup-mongodb: backup-mongodb:
# auto-index-creation: true # 默认为false,即不会自动创建索引 auto-index-creation: true # 默认为false,即不会自动创建索引
# host: localhost # 主机地址 host: localhost # 主机地址
# port: 27017 # 端口 port: 27017 # 端口
# database: backup_smf # 数据库 database: backup_smf # 数据库
# username: username: Siemens
# password: password: Siemens
servlet: servlet:
multipart: multipart:
......
...@@ -7,6 +7,8 @@ api: ...@@ -7,6 +7,8 @@ api:
outNotifyUrl: outNotifyUrl:
inNotifyUrl: inNotifyUrl:
hella: hella:
#host: 127.0.0.1 #host: 127.0.0.1
#port: 3333 #port: 3333
...@@ -50,5 +52,6 @@ menu: ...@@ -50,5 +52,6 @@ menu:
smd: smd:
filePath: filePath:
userName:
password:
\ No newline at end of file \ No newline at end of file
userName : Administrator
password : FjAdmin
url: http://175.41.238.212:80/
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!