Commit a3425e6f LN

Merge remote-tracking branch 'origin/master'

2 个父辈 a6ea5055 0951b9ed
......@@ -52,6 +52,8 @@ public enum EquipmentType {
*/
HANWHA(),
/**
* NEXIM
*/
NEXIM()
}
package com.neotel.smfcore.custom.hanwha.controller;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.custom.hanwha.util.HanwhaApiInfoUtil;
import com.neotel.smfcore.custom.hanwha.util.bean.HanwhaApiInfo;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/hanwhaApiInfo")
public class HanwhaApiInfoController {
@Autowired
private HanwhaApiInfoUtil hanwhaApiInfoUtil;
@ApiOperation("获取列表")
@RequestMapping("/getApiInfoList")
public ResultBean getApiInfoList(){
List<HanwhaApiInfo> apiInfoList = hanwhaApiInfoUtil.getApiInfoList();
return ResultBean.newOkResult(apiInfoList);
}
}
package com.neotel.smfcore.custom.hanwha.controller;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.custom.hanwha.util.HanwhaCacheUtil;
import com.neotel.smfcore.custom.hanwha.util.bean.HanwhaCacheConfig;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/hanwhaConfig")
public class HanwhaConfigController {
@Autowired
private HanwhaCacheUtil hanwhaCacheUtil;
@ApiOperation("获取ip和端口号")
@RequestMapping("/getCacheConfig")
public ResultBean getCacheConfig(){
return ResultBean.newOkResult(hanwhaCacheUtil.getHostAndPortCache());
}
@ApiOperation("修改ip和端口号")
@RequestMapping("/updateCacheConfig")
public ResultBean updateCacheConfig(@RequestBody HanwhaCacheConfig 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"});
}
hanwhaCacheUtil.updateHostAndPort(cacheConfig);
return ResultBean.newOkResult("");
}
}
package com.neotel.smfcore.custom.hanwha.util;
import com.google.common.collect.Maps;
import com.neotel.smfcore.custom.hanwha.util.bean.HanwhaApiInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
@Slf4j
@Service
public class HanwhaApiInfoUtil {
//api接口信息,默认返回10条
public static List<HanwhaApiInfo> apiInfoList = new CopyOnWriteArrayList<>();
public void updateApiInfoList(String url, String requestParam, String resultReturn) {
HanwhaApiInfo info = new HanwhaApiInfo();
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<HanwhaApiInfo> getApiInfoList(){
List<HanwhaApiInfo> resultList = new ArrayList<>();
if (apiInfoList != null && !apiInfoList.isEmpty()){
resultList = apiInfoList.stream().sorted(Comparator.comparing(HanwhaApiInfo::getCreateDate).reversed()).collect(Collectors.toList());
}
return resultList;
}
}
package com.neotel.smfcore.custom.hanwha.util;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.custom.hanwha.util.bean.HanwhaCacheConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class HanwhaCacheUtil {
@Autowired
private DataCache dataCache;
public static final String Cache_Hanwha_HostAndPost = "Cache_Hanwha_HostAndPost";
public void updateHostAndPort(HanwhaCacheConfig cacheConfig) {
HanwhaCacheConfig hanwhaCacheConfig = dataCache.getCache(Cache_Hanwha_HostAndPost);
if (hanwhaCacheConfig == null) {
hanwhaCacheConfig = new HanwhaCacheConfig();
}
hanwhaCacheConfig.setHost(cacheConfig.getHost());
hanwhaCacheConfig.setWebPort(cacheConfig.getWebPort());
hanwhaCacheConfig.setApiPort(cacheConfig.getApiPort());
hanwhaCacheConfig.setSingleOrder(cacheConfig.isSingleOrder());
dataCache.updateCache(Cache_Hanwha_HostAndPost, hanwhaCacheConfig);
}
public HanwhaCacheConfig getHostAndPortCache(){
HanwhaCacheConfig hostAndPortCache = dataCache.getCache(Cache_Hanwha_HostAndPost);
if (hostAndPortCache == null) {
hostAndPortCache = new HanwhaCacheConfig();
}
return hostAndPortCache;
}
}
package com.neotel.smfcore.custom.hanwha.util.bean;
import lombok.Data;
import java.util.Date;
@Data
public class HanwhaApiInfo {
private String url;
private String requestParam;
private String resultReturn;
private Date createDate;
}
package com.neotel.smfcore.custom.hanwha.util.bean;
import lombok.Data;
@Data
public class HanwhaCacheConfig {
private String host;
private String webPort;
private String apiPort;
private boolean singleOrder = false;
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!