Commit eab52fd3 LN

20057:hotayi接口修改。增加登录验证接口

1 个父辈 bcf60dc8
......@@ -341,6 +341,8 @@ public class HttpHelper {
}
try {
HttpGet httpGet = new HttpGet(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT).build();
httpGet.setConfig(requestConfig);
httpGet.addHeader("Content-Type", "application/json;charset=utf-8");
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);
......
package com.neotel.smfcore.core.api;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.init.MenuInit;
......@@ -63,6 +64,9 @@ public class SmfApi {
@Value("${api.fetchInListUrl:}")
protected String fetchInListUrl = "";
@Value("${api.loginCheckUrl:}")
protected String loginCheckUrl = "";
/**
* API名称
*/
......@@ -84,7 +88,7 @@ public class SmfApi {
orderNotifyUrl = dataCache.getConfigCache("api.orderNotifyUrl",orderNotifyUrl);
fetchInListUrl = dataCache.getConfigCache("api.fetchInListUrl",fetchInListUrl);
fetchOrderUrl = dataCache.getConfigCache("api.fetchOrderUrl",fetchOrderUrl);
loginCheckUrl=dataCache.getConfigCache("api.loginCheckUrl",loginCheckUrl);
}
/**
......@@ -220,7 +224,20 @@ public class SmfApi {
return null;
}
public boolean canLogin(String username, String pwd)throws ValidateException {
if (ObjectUtil.isNotEmpty(username) && ObjectUtil.isNotEmpty(pwd)) {
if (isUrlExist(loginCheckUrl)) {
for (ISmfApiListener apiListener : apiListenerList) {
if (apiListener.isForThisApi(apiName)) {
boolean result = apiListener.canLogin(loginCheckUrl, username, pwd);
return result;
}
}
}
}
return true;
}
/**
* 判断URL是否存在,如果不存在不需要进行发送
* @param url
......
......@@ -106,6 +106,10 @@ public abstract class BaseSmfApiListener implements ISmfApiListener {
return null;
}
@Override
public boolean canLogin(String loginCheckUrl, String userName, String pwd) throws ValidateException {
return true;
}
protected String getData(Map<String, Object> dataMap, String dataKey) {
Object data = dataMap.get(dataKey);
if (data == null) {
......
......@@ -55,4 +55,10 @@ public interface ISmfApiListener {
* @return
*/
LiteOrder fetchOrder(String url, String orderNumber, String username);
/**
* 是否可以登陆
*/
boolean canLogin(String loginCheckUrl, String userName,String pwd) throws ValidateException;
}
......@@ -114,7 +114,12 @@ public class HotayiApi extends BaseSmfApiListener {
log.info(reelId + "入库验证M6,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.getJson(codeResolveUrl, paramMap);
// "{ \"Info\": {\"MachineID\": \"00001\",\"IPAddress\": \"192.168.0.1\",\"MessageNo\": \"M5\"},\"Data\": {\"PartNo\": \"A005\",\"ExpireDate\": \"2022-01-01\",\"SerialNo\": \"A005$$A\"}}";
log.info(reelId + "入库验证返回" + result);
result=result.replace("\\\"","\"");
result=result.replace("\"{","{");
result=result.replace("}\"","}");
log.info(reelId + "入库验证返回 处理后" + result);
HotayiBean hotayiBean = JsonUtil.toObj(result, HotayiBean.class);
String resultMsgNo = hotayiBean.getInfoItem("MessageNo");
if (resultMsgNo.equals("M90")) {
......@@ -146,7 +151,12 @@ public class HotayiApi extends BaseSmfApiListener {
Date expireDate = DateUtil.toDate(expireDateStr, "yyyy-MM-dd");
barcode.setExpireDate(expireDate);
}
//默认设置重量=0
if(codeBean.getBarcode()!=null) {
barcode.setAmount(codeBean.getBarcode().getAmount());
}if(barcode.getAmount()<=0){
barcode.setAmount(1);
}
resolveComponent(barcode);
barcode = barcodeManager.saveBarcode(barcode);
return barcode;
......@@ -157,6 +167,7 @@ public class HotayiApi extends BaseSmfApiListener {
}
}
@Override
public void inTaskStatusChange(String inNotifyUrl, DataLog task) {
String requestParams = "";
......@@ -247,6 +258,56 @@ public class HotayiApi extends BaseSmfApiListener {
bean.addData("Mode", Mode);
return bean;
}
private HotayiBean getM22Bean(String UserName,String pwd,String MachineType ) {
HotayiBean bean = new HotayiBean();
bean.addInfo("MachineID", machineID);
bean.addInfo("IPAddress", iPAddress);
bean.addInfo("MessageNo", "M22");
bean.addData("UserName", UserName+pwd);
bean.addData("MachineType", MachineType);
return bean;
}
@Override
public boolean canLogin(String loginCheckUrl, String userName, String pwd) throws ValidateException {
try {
HotayiBean m22Bean = getM22Bean(userName, pwd, "SMT Machine");
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("Info", m22Bean.getInfo());
paramMap.put("Date", m22Bean.getData());
String requestParams = JsonUtil.toJsonStr(paramMap);
log.info(userName + "登陆验证M22,参数" + requestParams);
String result = HttpHelper.getJson(loginCheckUrl, paramMap);
log.info(userName + "登陆验证M22 返回" + result);
// ApiResult apiResult = JsonUtil.toObj(responseInfo, ApiResult.class);
result = result.replace("\\\"", "\"");
result = result.replace("\"{", "{");
result = result.replace("}\"", "}");
log.info(userName + "登陆验证M22 处理后" + result);
HotayiBean hotayiBean = JsonUtil.toObj(result, HotayiBean.class);
String resultMsgNo = hotayiBean.getInfoItem("MessageNo");
if (resultMsgNo.equals("M90")) {
String errorCode = hotayiBean.getDataItem("ErrorCode");
String errorMessage = hotayiBean.getDataItem("ErrorMessage");
throw new ValidateException("smfcore.mesApi.loginCheck.ng","NG: ["+errorCode+"]"+errorMessage);
}else {
String UserLevel = hotayiBean.getInfoItem("UserLevel");
if (ObjectUtil.isNotEmpty(UserLevel)) {
log.info(userName + "登陆验证M22 返回 UserLevel=" + UserLevel);
return true;
} else {
log.info(userName + "登陆验证M22 返回 UserLevel=" + UserLevel);
throw new ValidateException("smfcore.mesApi.loginCheck.fail", "MES Login fail ");
}
}
} catch (Exception e) {
log.error("登陆验证接口出错:" + e.getMessage());
throw new ValidateException("smfcore.mesApi.loginCheck.error", "MES Login Error:" + e.getMessage());
}
}
}
......@@ -18,6 +18,7 @@ package com.neotel.smfcore.security.service;
import com.neotel.smfcore.common.exception.EntityNotFoundException;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.api.SmfApi;
import com.neotel.smfcore.security.rest.bean.dto.JwtUserDto;
import com.neotel.smfcore.security.service.manager.IMenuManager;
import com.neotel.smfcore.security.service.manager.IUserManager;
......@@ -40,9 +41,11 @@ import java.util.stream.Collectors;
public class UserDetailsServiceImpl implements UserDetailsService {
private final IUserManager userManager;
private final IMenuManager menuManager;
private final SmfApi smfApi;
@Override
public JwtUserDto loadUserByUsername(String username) {
smfApi.canLogin(username,"");
boolean searchDb = true;
JwtUserDto jwtUserDto = null;
if (searchDb) {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!