Commit bc951296 LN

1.去掉不需要的菜单。工单设置页面调整。

2.ApiInteraction增加类型,HANWHA 和Panacim 都使用此功能。
3.HANWHA 和Panacim 配置页面调整,增加测试按钮。
1 个父辈 17ee4089
正在显示 25 个修改的文件 包含 478 行增加134 行删除
......@@ -150,7 +150,7 @@ public class MenuInit {
addDefaultFunctionMenu(2, poutOut,"PN出库", "tacticsOuput", "neolight/tacticsOuput/index", "tacticsOuput",DEFAULT_SHOW_MENU);
addDefaultFunctionMenu(3,poutOut,"工单出库","workOrder", "neolight/workOrder/index","orderOut",DEFAULT_SHOW_MENU);
addDefaultFunctionMenu(4,poutOut,"工单","orderkanban", "orderkanban/index","kanban");
// addDefaultFunctionMenu(4,poutOut,"工单","orderkanban", "orderkanban/index","kanban");
addDefaultFunctionMenu(5,poutOut,"库位出库", "posOutput", "system/posOutput/index", "swagger");
addDefaultFunctionMenu(6, poutOut, "物料标签", "labelOuput", "neolight/labelOuput/index", "mgroup");
addDefaultFunctionMenu(7, poutOut, "料盒操作", "materialBox", "neolight/materialBox/index", "mIbox");
......@@ -163,7 +163,7 @@ public class MenuInit {
// addDefaultFunctionMenu(12, poutOut, "单盘入库", "singleDiskWarehousing", "system/singleDiskWarehousing/index", "headIcon");
addDefaultFunctionMenu(13, poutOut, "呆滞物料", "sluggishMaterials", "system/sluggishMaterials/index", "sMaterial");
//addDefaultFunctionMenu(16, poutOut,"生成工单", "createOrder", "system/createOrder/index", "createOrder");
addDefaultFunctionMenu(91,poutOut, "共享文件夹", "orderSetting", "system/orderSetting/index", "sysSet",DEFAULT_SHOW_MENU);
// addDefaultFunctionMenu(91,poutOut, "共享文件夹", "orderSetting", "system/orderSetting/index", "sysSet",DEFAULT_SHOW_MENU);
//MSD管理:MSD库存.MSD追溯性.MSD设置
......@@ -195,7 +195,8 @@ public class MenuInit {
Menu pMenuLog = Menu.CreatePMenu("日志管理", 8, "log","log",null);
addDefaultFunctionMenu(61, pMenuLog, "物料日志", "taskLog", "neolight/taskLog/index", "education",DEFAULT_SHOW_MENU);
addDefaultFunctionMenu(62, pMenuLog, "消息查询", "message", "neolight/message/index", "messagefind",DEFAULT_SHOW_MENU);
addDefaultFunctionMenu(63, pMenuLog, "接口异常", "interfaceException", "neolight/interfaceException/index", "messagefind");
//暂未找到页面
// addDefaultFunctionMenu(63, pMenuLog, "接口异常", "interfaceException", "neolight/interfaceException/index", "messagefind");
//报表:出入库、库存
Menu pMenuReport = Menu.CreatePMenu("报表", 9, "report","inOutData",null);
......@@ -234,6 +235,7 @@ public class MenuInit {
// Menu orderSet = new Menu(, "orderSetting", "工单设置", "orderSetting", "system/orderSetting/index", "sysSet");
addDefaultFunctionMenu(106,poutSet, "料架设置", "shelfSetting", "system/shelfSetting/index", "translation",NL_SHOW_MENU);
addDefaultFunctionMenu(107,poutSet, "其他设备", "storageOther", "storage/storageOther/index", "storageOther");
addDefaultFunctionMenu(108,poutSet, "工单设置", "orderSetting", "system/orderSetting/index", "sysSet",DEFAULT_SHOW_MENU);
Menu helpAbout = Menu.CreatePMenu("帮助", 9999, "help", "help",null);
addDefaultFunctionMenu(99991, helpAbout, "说明书", "instruction", "system/instruction/index","aboutBook");
......
......@@ -148,6 +148,9 @@ public class HttpHelper {
return postJsonWithAuth(url, params, null);
}
public static String postJsonWithAuth(String url, Object params, String auth) throws ApiException {
return postJsonWithAuth(url,params,auth,CONNECTION_TIMEOUT,READ_DATA_TIMEOUT);
}
public static String postJsonWithAuth(String url, Object params, String auth,int conTimeout,int socketTimeout) throws ApiException {
String requestBody = "";
// 设置请求参数
......@@ -171,6 +174,16 @@ public class HttpHelper {
if (auth != null && !auth.isEmpty()) {
httpPost.addHeader("Authorization", auth);
}
if(conTimeout>0&&socketTimeout>0){
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(conTimeout) // 设置连接超时时间为3秒
.setSocketTimeout(socketTimeout) // 设置请求超时时间为3秒
.build();
httpPost.setConfig(requestConfig);
}
httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
httpClient = HttpClients.createDefault();
response = httpClient.execute(httpPost);
......@@ -452,6 +465,59 @@ public class HttpHelper {
}
}
public static Map<String,Object> getJsonResult(String url, Object params,int timeoutMS) throws ApiException {
// 设置请求参数
if (params != null) {
try {
ObjectMapper mapper = new ObjectMapper();
String requestBody = mapper.writeValueAsString(params);
List<NameValuePair> nameValuePairs = new LinkedList<>();
nameValuePairs.add(new BasicNameValuePair("JSON", requestBody));
String paramStr = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs));
url = appendString(url, paramStr);
// url=url+"?JSON="+requestBody;
} catch (Exception e) {
throw new ApiException("getJson append params to [" + url + "] exception:" + e.getMessage());
}
}
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeoutMS).build();
httpGet.setConfig(requestConfig);
httpGet.addHeader("Content-Type", "application/json;charset=utf-8");
httpClient = HttpClients.createDefault();
response = httpClient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
Map<String,Object> resultMap=new HashMap<>();
resultMap.put("code",code);
resultMap.put("responseContent",responseContent);
return resultMap;
//response.close();
//httpClient.close();
// return responseContent;
} catch (Exception e) {
throw new ApiException("Request to [" + url + "] failed:" + e.getMessage());
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getJson(String url, Object params) throws ApiException {
// 设置请求参数
if (params != null) {
......
package com.neotel.smfcore.core.apiInteraction.bean.query;
import com.neotel.smfcore.common.annotation.QueryCondition;
import com.neotel.smfcore.core.apiInteraction.enums.ApiInteraction_Status;
import lombok.Data;
......@@ -7,7 +8,7 @@ import java.util.Date;
@Data
public class ApiInteractionQuery {
@QueryCondition
private Date requestDate;
//private String url;
......@@ -15,7 +16,9 @@ public class ApiInteractionQuery {
//private String param;
//private String result;
private String status = ApiInteraction_Status.OK;
@QueryCondition
private String status ="";
@QueryCondition
private String type="";
}
package com.neotel.smfcore.core.apiInteraction.controller;
import com.google.common.collect.Lists;
import com.neotel.smfcore.common.base.IExcelDownLoad;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.apiInteraction.bean.query.ApiInteractionQuery;
import com.neotel.smfcore.core.apiInteraction.service.manager.IApiInteractionManager;
import com.neotel.smfcore.core.apiInteraction.service.po.ApiInteraction;
import com.neotel.smfcore.core.language.util.MessageUtils;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
......@@ -13,6 +19,13 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@Slf4j
@RequestMapping("/apiInteraction")
@RestController
......@@ -26,7 +39,45 @@ public class ApiInteractionController {
@AnonymousAccess
public PageData list(ApiInteractionQuery query, Pageable pageable){
Query q = QueryHelp.getQuery(query);
return apiInteractionManager.findByPage(q,pageable);
PageData<ApiInteraction> result= apiInteractionManager.findByPage(q,pageable);
return result;
}
@ApiOperation("接口记录导出")
@RequestMapping("/download")
@AnonymousAccess
public void download(ApiInteractionQuery query, Pageable pageable, HttpServletResponse response, HttpServletRequest request)throws IOException {
Query q = QueryHelp.getQuery(query);
FileUtil.downloadExcel(q, pageable, response, new IExcelDownLoad() {
@Override
public List<List<String>> getHeader() {
List<List<String>> header = new ArrayList<>();
Locale locale = request.getLocale();
header.add(Lists.newArrayList(MessageUtils.getText("smfcore.equipApiMsg.url", locale, "IP地址")));
header.add(Lists.newArrayList(MessageUtils.getText("smfcore.equipApiMsg.request", locale, "参数")));
header.add(Lists.newArrayList(MessageUtils.getText("smfcore.equipApiMsg.response", locale, "结果")));
header.add(Lists.newArrayList(MessageUtils.getText("smfcore.equipApiMsg.state", locale, "状态")));
header.add(Lists.newArrayList(MessageUtils.getText("smfcore.equipApiMsg.updateTime", locale, "创建时间")));
return header;
}
@Override
public List<List<Object>> getPageData(Query query, Pageable pageable) {
PageData<ApiInteraction> apiInfoList = apiInteractionManager.findByPage(q,pageable);
List<List<Object>> dataList = new ArrayList<>();
for (ApiInteraction obj : apiInfoList.getContent()) {
List<Object> data = new ArrayList<>();
data.add(obj.getUrl());
data.add(obj.getRequestDate());
data.add(obj.getResult());
data.add(obj.getStatus());
data.add(DateUtil.toDateString(obj.getCreateDate()));
dataList.add(data);
}
return dataList;
}
});
}
}
......@@ -2,6 +2,7 @@ package com.neotel.smfcore.core.apiInteraction.service.po;
import com.neotel.smfcore.common.base.BasePo;
import com.neotel.smfcore.core.apiInteraction.enums.ApiInteraction_Status;
import com.neotel.smfcore.core.equipment.enums.EquipmentType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -14,6 +15,17 @@ import java.util.Date;
@NoArgsConstructor
public class ApiInteraction extends BasePo implements Serializable {
public ApiInteraction(Date date,String url,String param,String result,String status){
this.requestDate=date;
this.url=url;
this.param=param;
this.result=result;
this.status=status;
this.type=EquipmentType.NEXIM.name();
}
private Date requestDate;
private String url;
......@@ -23,4 +35,7 @@ public class ApiInteraction extends BasePo implements Serializable {
private String result;
private String status = ApiInteraction_Status.OK;
//设备类型,nexim,hanwa,pancim
private String type="";
}
......@@ -64,6 +64,12 @@ public enum EquipmentType {
public static List<EquipmentType> availableTypeList(){
return Lists.newArrayList(AUTO,NEOSCAN,NS200,COUNTING,NEOSTATION,FUJINEOLINK,PANACIMNEOLINK,AGV,HANWHA,NEXIM);
return Lists.newArrayList(AUTO,NEOSCAN,NS200,COUNTING,PANACIMNEOLINK,AGV,HANWHA,NEXIM);
}
public static List<String> apiTypeList(){
return Lists.newArrayList(HANWHA.name(),PANACIMNEOLINK.name(),NEXIM.name());
}
}
package com.neotel.smfcore.core.equipment.rest;
import com.neotel.smfcore.common.bean.PageData;
import com.neotel.smfcore.core.equipment.util.EquipApiUtil;
import com.neotel.smfcore.core.equipment.util.bean.EquipApiInfo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/equipApiInfo")
public class EquipApiController {
@Autowired
private EquipApiUtil equipApiUtil;
@ApiOperation("获取列表")
@GetMapping("/getApiInfoList")
public PageData<EquipApiInfo> getApiInfoList() {
List<EquipApiInfo> apiInfoList = equipApiUtil.getApiInfoList();
return new PageData<EquipApiInfo>(apiInfoList, apiInfoList.size());
}
}
......@@ -2,8 +2,14 @@ package com.neotel.smfcore.core.equipment.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.core.equipment.enums.EquipmentType;
import com.neotel.smfcore.core.equipment.rest.dto.EquipConfigInfoDto;
import com.neotel.smfcore.core.equipment.rest.mapstruct.EquipConfigInfoMapper;
import com.neotel.smfcore.core.equipment.util.EquipConfigUtil;
import com.neotel.smfcore.core.equipment.util.bean.EquipConfigInfo;
import com.neotel.smfcore.custom.hanwha.handler.TMSApis;
import com.neotel.smfcore.custom.hanwha.handler.TMSCommunicator;
import com.neotel.smfcore.custom.panacim.PanaApiController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,40 +20,82 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/equipConfig")
public class EquipConfigController {
@Autowired
private EquipConfigInfoMapper equipConfigInfoMapper;
@Autowired
private EquipConfigUtil equipConfigUtil;
@Autowired
private EquipConfigUtil equipConfigUtil;
@Autowired
private PanaApiController panaApiController;
@ApiOperation("获取配置信息")
@GetMapping("/getConfig")
public ResultBean getCacheConfig(String equipType){
return ResultBean.newOkResult(equipConfigUtil.getConfigCache(equipType));
@Autowired
private TMSApis tmsApis;
@Autowired
private TMSCommunicator tmsCommunicator;
@ApiOperation("获取配置信息")
@GetMapping("/getConfig")
public ResultBean getCacheConfig(String equipType) {
EquipConfigInfo configInfo= equipConfigUtil.getConfigCache(equipType);
return ResultBean.newOkResult(equipConfigInfoMapper.toDto(configInfo));
}
@ApiOperation("更改配置信息")
@PostMapping("/updateConfig")
public ResultBean updateConfig(@RequestBody EquipConfigInfo cacheConfig) {
if (ObjectUtil.isEmpty(cacheConfig.getEquipType())) {
return ResultBean.newErrorResult(1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"equipType"});
}
equipConfigUtil.updateConfigCache(cacheConfig);
return ResultBean.newOkResult("");
}
@ApiOperation("测试接口是否连通")
@PostMapping("/apiTest")
public ResultBean apiTest(@RequestBody EquipConfigInfoDto configInfoDto) {
if (ObjectUtil.isEmpty(configInfoDto.getEquipType())) {
return ResultBean.newErrorResult(1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"equipType"});
}
//判断测试哪个接口
@ApiOperation("更改配置信息")
@PostMapping("/updateConfig")
public ResultBean updateConfig(@RequestBody EquipConfigInfo cacheConfig) {
// String host = cacheConfig.getHost();
// String apiPort = cacheConfig.getApiPort();
// String webPort = cacheConfig.getWebPort();
// log.info("收到修改ip和端口号,host为[{}],apiPort为[{}],webPort为[{}]",host,apiPort,webPort);
//
// if (StringUtils.isEmpty(host)){
// return ResultBean.newErrorResult(1,"smfcore.valueCanotNull", "{0}不能为空", new String[]{"host"});
// }
// if (StringUtils.isEmpty(webPort)){
// return ResultBean.newErrorResult(1,"smfcore.valueCanotNull", "{0}不能为空", new String[]{"webPort"});
// }
// if (StringUtils.isEmpty(apiPort)){
// return ResultBean.newErrorResult(1,"smfcore.valueCanotNull", "{0}不能为空", new String[]{"apiPort"});
// }
if(ObjectUtil.isEmpty(cacheConfig.getEquipType())){
return ResultBean.newErrorResult(1,"smfcore.valueCanotNull", "{0}不能为空", new String[]{"equipType"});
boolean result = false;
if (configInfoDto.equipType.equals(EquipmentType.HANWHA.name())) {
EquipConfigInfo config = equipConfigInfoMapper.toEntity(configInfoDto);
if (configInfoDto.apiTestKey.equals("webPort") ) {
String ip = config.GetConfigValue("host", "");
int webPort = config.GetConfigValue("webPort", 0);
String webUrl = String.format("ws://%s:%d/", ip, webPort);
if (TMSCommunicator.wsURL.equals(webUrl)) {
result = tmsCommunicator.isConnected();
} else {
result = tmsApis.TestWebSocket(ip, webPort);
}
} else {
String ip = config.GetConfigValue("host", "");
int apiPort = config.GetConfigValue("apiPort", 0);
result=tmsApis.TestApi(ip,apiPort);
}
equipConfigUtil.updateConfigCache(cacheConfig);
return ResultBean.newOkResult("");
} else if (configInfoDto.equipType.equals(EquipmentType.PANACIMNEOLINK.name())) {
result = panaApiController.TestApi();
}
if (result) {
return ResultBean.newOkResult("OK");
} else {
return ResultBean.newErrorResult(-1, "smfcore.equipconfig.connectTimeout", "连接超时");
}
}
}
......@@ -59,6 +59,13 @@ public class EquipmentController {
Query query= QueryHelp.getQuery(criteria);
PageData<Equipment> pages = equipmentManager.findByPage(query, pageable);
List<EquipmentDto> equipmentDtos =equipmentMapper.toDto(pages.getContent());
for (int i=0;i<equipmentDtos.size();i++){
if(EquipmentType.apiTypeList().contains(equipmentDtos.get(i).getType())){
equipmentDtos.get(i).setAPIEquip(true);
}
}
return new PageData(equipmentDtos,pages.getTotalElements());
}
......
package com.neotel.smfcore.core.equipment.rest.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.LinkedHashMap;
@Data
public class EquipConfigInfoDto {
@ApiModelProperty("设备类型")
public String equipType = "";
@ApiModelProperty("启用API连接 默认不启用")
public boolean enableApi;
@ApiModelProperty("配置列表")
public LinkedHashMap<String, Object> apiConfigMap;
@ApiModelProperty("测试连接的Key")
public String apiTestKey;
}
......@@ -23,5 +23,7 @@ public class EquipmentDto {
@ApiModelProperty("是否激活")
private boolean activate=true;
@ApiModelProperty("是否是第三方对接设备")
private boolean aPIEquip=false;
private String id;
}
package com.neotel.smfcore.core.equipment.rest.mapstruct;
import com.neotel.smfcore.common.base.BaseMapper;
import com.neotel.smfcore.core.equipment.rest.dto.EquipConfigInfoDto;
import com.neotel.smfcore.core.equipment.util.bean.EquipConfigInfo;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring" ,unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface EquipConfigInfoMapper extends BaseMapper<EquipConfigInfoDto, EquipConfigInfo> {
}
......@@ -42,7 +42,10 @@ public class Equipment extends BasePo implements Serializable {
* @return
*/
public boolean isAPIEquip() {
return EquipmentType.HANWHA.name().equals(type)||EquipmentType.PANACIMNEOLINK.name().equals(type)||
EquipmentType.FUJINEOLINK.name().equals(type)||EquipmentType.NEXIM.name().equals(type);
if(EquipmentType.apiTypeList().contains(type)){
return true;
}
return false;
}
}
package com.neotel.smfcore.core.equipment.util;
import com.neotel.smfcore.core.equipment.util.bean.EquipApiInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
@Slf4j
@Service
public class EquipApiUtil {
//api接口信息,默认返回10条
public static List<EquipApiInfo> apiInfoList = new CopyOnWriteArrayList<>();
public void updateApiInfoList(String url, String requestParam, String resultReturn) {
EquipApiInfo info = new EquipApiInfo();
info.setCreateDate(new Date());
info.setUrl(url);
info.setRequestParam(requestParam);
info.setResultReturn(resultReturn);
apiInfoList.add(info);
if (apiInfoList != null && apiInfoList.size() > 10) {
apiInfoList.remove(0);
}
}
public List<EquipApiInfo> getApiInfoList() {
List<EquipApiInfo> resultList = new ArrayList<>();
if (apiInfoList != null && !apiInfoList.isEmpty()) {
resultList = apiInfoList.stream().sorted(Comparator.comparing(EquipApiInfo::getCreateDate).reversed()).collect(Collectors.toList());
}
return resultList;
}
}
package com.neotel.smfcore.core.equipment.util;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.JsonUtil;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.equipment.enums.EquipmentType;
......@@ -51,6 +52,14 @@ public class EquipConfigUtil {
configInfo.setApiConfigMap(defMap);
}
}
if(equipType.equals(EquipmentType.PANACIMNEOLINK.name())) {
//增加配置
LinkedHashMap<String, Object> defMap = new LinkedHashMap<>();
defMap.put("PanaCIMIP", dataCache.getCache(Constants.Cache_PanaCIMIP));
defMap.put("PanaCIMPort", dataCache.getCache(Constants.Cache_PanaCIMPort));
configInfo.setApiConfigMap(defMap);
}
return configInfo;
}
}
package com.neotel.smfcore.core.equipment.util.bean;
import lombok.Data;
import java.util.Date;
@Data
public class EquipApiInfo {
private String url;
private String requestParam;
private String resultReturn;
private Date createDate;
}
......@@ -34,6 +34,8 @@ public class OrderSetting implements Serializable {
*/
public Map<String,String> appendData = new HashMap<>();
@ApiModelProperty("缺料不自动关闭工单")
private boolean closeWorkOrder = false;
/**
* 是否显示料架亮灯方式
*/
......
......@@ -151,6 +151,10 @@ public class SettingsController {
break;
}
}
Boolean closeWorkOrder = dataCache.getCache(Constants.CACHE_closeWorkOrder);
if(closeWorkOrder!=null){
orderSetting.setCloseWorkOrder(closeWorkOrder);
}
return orderSetting;
}
......@@ -208,6 +212,7 @@ public class SettingsController {
}
dataCache.updateCache(Constants.CACHE_OrderSetting, orderSetting);
dataCache.updateCache(Constants.CACHE_closeWorkOrder,orderSetting.isCloseWorkOrder());
log.info("更改工单设置:"+Constants.CACHE_OrderSetting+"=" + orderSetting.toString());
return ResultBean.newOkResult("保存成功");
......
......@@ -5,19 +5,31 @@ import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.JsonUtil;
import com.neotel.smfcore.core.equipment.util.EquipApiUtil;
import com.neotel.smfcore.core.apiInteraction.enums.ApiInteraction_Status;
import com.neotel.smfcore.core.apiInteraction.service.manager.IApiInteractionManager;
import com.neotel.smfcore.core.apiInteraction.service.po.ApiInteraction;
import com.neotel.smfcore.core.device.bean.StatusBean;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.equipment.enums.EquipmentType;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.custom.hanwha.client.MyWebSocketClient;
import com.neotel.smfcore.custom.hanwha.handler.bean.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URI;
import java.util.*;
@Service
@Slf4j
public class TMSApis {
@Autowired
private EquipApiUtil equipApiUtil;
private IApiInteractionManager apiInteractionManager;
@Autowired
private DataCache dataCache;
/**
* 3.16 RequestGetPartInfo
* Request part information of given ReelCode to TMS (when the Rack needs it).
......@@ -477,12 +489,112 @@ public class TMSApis {
private String PostJson(String url,Map<String,Object> sendData) throws ApiException {
String requestParam = JsonUtil.toJsonStr(sendData);
try {
String responseStr = HttpHelper.postJsonWithAuth(url, sendData, null, 3000, 10000);
log.info("PostJson, url=[" + url + "],send=[" + requestParam + "],response=[" + responseStr + "]");
apiInteractionManager.save(new ApiInteraction(new Date(), url, requestParam, responseStr, ApiInteraction_Status.OK, EquipmentType.HANWHA.name()));
return responseStr;
} catch (ApiException ex) {
log.error(ex.toString());
apiInteractionManager.save(new ApiInteraction(new Date(), url, requestParam, ex.toString(), ApiInteraction_Status.ERROE, EquipmentType.HANWHA.name()));
throw ex;
}
String responseStr = HttpHelper.postJson(url, sendData);
String requestParam=JsonUtil.toJsonStr(sendData);
log.info("PostJson, url=["+url+"],send=["+requestParam+"],response=["+responseStr+"]");
equipApiUtil.updateApiInfoList(url,requestParam,responseStr);
return responseStr;
}
public boolean TestApi(String ip,int apiPort ) {
try {
List<String> cids = new ArrayList<>(dataCache.getAllStorage().keySet());
Integer[] statusList= new Integer[0];
List<String> storageIds = new ArrayList<>();
List<String> storageTypes = new ArrayList<>();
List<Integer> isConns = new ArrayList<>();
int i = 0;
for (String cid : cids) {
Storage storage = dataCache.getStorage(cid);
if (storage == null) {
continue;
}
String type = "Storage";
if (storage.isNLShelf() || storage.isNLPShelf() || storage.isNLMShelf() || storage.isShelf()) {
type = "Rack";
}
int status = -1;
if (statusList != null && statusList.length > i) {
status = statusList[i];
} else {
StatusBean bean = DevicesStatusUtil.getStatusBean(storage.getCid());
if (bean == null || bean.timeOut()) {
status = -1;
} else {
status = bean.getStatus();
}
}
String conCode = "0";
if(status>=1){
conCode="2";
}
storageIds.add(storage.getCid());
storageTypes.add(type);
isConns.add(Integer.parseInt(conCode));
i++;
}
String RequestID="0";
String url = String.format("http://%s:%d/", ip, apiPort) + "webservice/RequestUpdateStorageConnectionInfo";
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("RequestID", RequestID);
dataMap.put("Indate", getInDataStr());
dataMap.put("StorageID", storageIds);
dataMap.put("StorageType", storageTypes);
dataMap.put("IsConn", isConns);
Map<String, Object> sendData = new HashMap<>();
sendData.put("data", dataMap);
String responseStr = PostJson(url, sendData);
return true;
} catch (Exception ex) {
return false;
}
}
public boolean TestWebSocket( String ip ,int webPort) {
try {
String webUrl = String.format("ws://%s:%d/", ip, webPort);
MyWebSocketClient websocket = new MyWebSocketClient(new URI(webUrl), null );
websocket.setConnectionLostTimeout(3000);
try {
// 设置连接超时时间为3秒
websocket.connect();
//等待3秒看是否连接
for (int i=0;i<100;i++){
Thread.sleep(30);
if(websocket.isOpen()){
log.info("TestWebSocket "+webUrl+" 已连接");
return true;
}
}
} catch (Exception e) {
return false;
} finally {
try {
websocket.close();
} catch (Exception e) {
log.info(e.toString());
}
}
} catch (Exception ex) {
log.info(ex.toString());
}
return false;
}
}
......@@ -11,6 +11,7 @@ import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.StorageConstants;
import com.neotel.smfcore.core.api.bean.CodeValidateParam;
import com.neotel.smfcore.core.api.listener.BaseSmfApiListener;
import com.neotel.smfcore.core.apiInteraction.service.manager.IApiInteractionManager;
import com.neotel.smfcore.core.barcode.bean.CodeBean;
import com.neotel.smfcore.core.barcode.enums.COMPONENT_TYPE;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
......@@ -66,6 +67,9 @@ public class PanaApiController extends BaseSmfApiListener {
protected CodeResolve codeResolve;
@Autowired
private IApiInteractionManager apiInteractionManager;
@Autowired
public void setDataCache(DataCache dataCache) {
PanaApiController.dataCache = dataCache;
String ip = dataCache.getCache(Constants.Cache_PanaCIMIP);
......@@ -134,6 +138,12 @@ public class PanaApiController extends BaseSmfApiListener {
return "";
}
private static String getkeepAliveUrl(){
if(!Strings.isNullOrEmpty(PanaCIMIP)){
return "http://"+PanaCIMIP + ":" + PanaCIMPort + "/api/Storage/keepAlive";
}
return "";
}
@RequestMapping(value = "/keepAlive")
@ResponseBody
......@@ -682,4 +692,26 @@ public class PanaApiController extends BaseSmfApiListener {
public boolean isForThisApi(String apiName) {
return apiName != null && apiName.equalsIgnoreCase("PanaCIM");
}
/**
* 测试是否可连接
* @return
*/
public boolean TestApi(){
String keepAliveUrl=getkeepAliveUrl();
try{
Map<String,Object> result = HttpHelper.getJsonResult(keepAliveUrl,new HashMap<>(),3000);
if(result!=null&&result.size()==2){
int code=(Integer)result.get("code");
if(code==200){
return true;
}
}
}catch (Exception ex){
log.error(keepAliveUrl+" error :"+ex.toString());
}
return false;
}
}
......@@ -406,4 +406,10 @@ smfcore.storageOther=\u5176\u4ED6\u8BBE\u5907
smfcore.humiture.ntemperature2=\u51B7\u85CF\u6E29\u5EA62
smfcore.humiture.ntemperature3=\u51B7\u85CF\u6E29\u5EA63
smfcore.humiture.codetemperature2=\u5236\u51B7\u6E29\u5EA62
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
\ No newline at end of file
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
smfcore.equipconfig.connectTimeout=\u8FDE\u63A5\u8D85\u65F6
smfcore.equipApiMsg.url=URL
smfcore.equipApiMsg.request=\u8BF7\u6C42\u4FE1\u606F
smfcore.equipApiMsg.response=\u7ED3\u679C\u4FE1\u606F
smfcore.equipApiMsg.updateTime=\u65F6\u95F4
smfcore.equipApiMsg.state=\u72B6\u6001
\ No newline at end of file
......@@ -397,4 +397,10 @@ smfcore.storageOther = Other Devices
smfcore.humiture.ntemperature2=Refrigeration zone temperature 2
smfcore.humiture.ntemperature3=Refrigeration zone temperature 3
smfcore.humiture.codetemperature2=Cooling Temperature 2
smfcore.humiture.wtemperature=Return temperature zone temperature
\ No newline at end of file
smfcore.humiture.wtemperature=Return temperature zone temperature
smfcore.equipconfig.connectTimeout=Connection Timeout
smfcore.equipApiMsg.url=URL
smfcore.equipApiMsg.request=Request Information
smfcore.equipApiMsg.response=Response Information
smfcore.equipApiMsg.updateTime=Time
smfcore.equipApiMsg.state=Status
\ No newline at end of file
......@@ -393,4 +393,10 @@ smfcore.storageOther = \u305D\u306E\u4ED6\u6A5F\u5668
smfcore.humiture.ntemperature2=\u51B7\u85CF\u6E29\u5EA62
smfcore.humiture.ntemperature3=\u51B7\u85CF\u6E29\u5EA63
smfcore.humiture.codetemperature2=\u5236\u51B7\u6E29\u5EA62
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
\ No newline at end of file
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
smfcore.equipconfig.connectTimeout=\u63A5\u7D9A\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8
smfcore.equipApiMsg.url=URL
smfcore.equipApiMsg.request=\u30EA\u30AF\u30A8\u30B9\u30C8\u60C5\u5831
smfcore.equipApiMsg.response=\u30EC\u30B9\u30DD\u30F3\u30B9\u60C5\u5831
smfcore.equipApiMsg.updateTime=\u6642\u9593
smfcore.equipApiMsg.state=\u30B9\u30C6\u30FC\u30BF\u30B9
......@@ -393,4 +393,10 @@ smfcore.storageOther=\u5176\u4ED6\u8BBE\u5907
smfcore.humiture.ntemperature2=\u51B7\u85CF\u6E29\u5EA62
smfcore.humiture.ntemperature3=\u51B7\u85CF\u6E29\u5EA63
smfcore.humiture.codetemperature2=\u5236\u51B7\u6E29\u5EA62
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
\ No newline at end of file
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
smfcore.equipconfig.connectTimeout=\u8FDE\u63A5\u8D85\u65F6
smfcore.equipApiMsg.url=URL
smfcore.equipApiMsg.request=\u8BF7\u6C42\u4FE1\u606F
smfcore.equipApiMsg.response=\u7ED3\u679C\u4FE1\u606F
smfcore.equipApiMsg.updateTime=\u65F6\u95F4
smfcore.equipApiMsg.state=\u72B6\u6001
\ No newline at end of file
......@@ -393,4 +393,10 @@ smfcore.storageOther=\u5176\u4ED6\u8A2D\u5099
smfcore.humiture.ntemperature2=\u51B7\u85CF\u6E29\u5EA62
smfcore.humiture.ntemperature3=\u51B7\u85CF\u6E29\u5EA63
smfcore.humiture.codetemperature2=\u5236\u51B7\u6E29\u5EA62
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
\ No newline at end of file
smfcore.humiture.wtemperature=\u56DE\u6E29\u6E29\u5EA6
smfcore.equipconfig.connectTimeout=\u8FDE\u63A5\u8D85\u65F6
smfcore.equipApiMsg.url=URL
smfcore.equipApiMsg.request=\u8BF7\u6C42\u4FE1\u606F
smfcore.equipApiMsg.response=\u7ED3\u679C\u4FE1\u606F
smfcore.equipApiMsg.updateTime=\u65F6\u95F4
smfcore.equipApiMsg.state=\u72B6\u6001
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!