张江玮
2 years ago
19 changed files with 19 additions and 855 deletions
@ -1,105 +0,0 @@ |
|||||
package org.nl.acs.auto.run; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
|
|
||||
import java.util.Date; |
|
||||
|
|
||||
@Slf4j |
|
||||
public abstract class AbstractAutoRunnable implements Runnable { |
|
||||
private ThreadStatusEnum status; |
|
||||
private Date startTime; |
|
||||
private Date stopTime; |
|
||||
private String stopMessage; |
|
||||
private ThreadUsedStatusEnum usedStatus; |
|
||||
@Override |
|
||||
public void run() { |
|
||||
this.setStatus(ThreadStatusEnum.run); |
|
||||
this.setStartTime(new Date()); |
|
||||
this.setStopMessage(""); |
|
||||
String true_clear = "执行完毕"; |
|
||||
|
|
||||
try { |
|
||||
this.before(); |
|
||||
//子类该方法是个死循环
|
|
||||
this.autoRun(); |
|
||||
this.setStopMessage(true_clear); |
|
||||
} catch (Throwable arg5) { |
|
||||
log.warn("", arg5); |
|
||||
System.out.println(arg5.getMessage()); |
|
||||
// this.setStopMessage(ExceptionUtlEx.getSimpleTrace(arg5));
|
|
||||
} finally { |
|
||||
this.setStopTime(new Date()); |
|
||||
this.setStatus(ThreadStatusEnum.stop); |
|
||||
this.after(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public void before() throws Exception { |
|
||||
} |
|
||||
|
|
||||
public void after() { |
|
||||
} |
|
||||
|
|
||||
public void stop() { |
|
||||
this.after(); |
|
||||
} |
|
||||
|
|
||||
public Boolean getForbidStop() { |
|
||||
return Boolean.valueOf(false); |
|
||||
} |
|
||||
|
|
||||
public Boolean getForbidDisable() { |
|
||||
return Boolean.valueOf(false); |
|
||||
} |
|
||||
|
|
||||
public abstract String getCode(); |
|
||||
|
|
||||
public abstract String getName(); |
|
||||
|
|
||||
public String getDescription() { |
|
||||
return this.getName(); |
|
||||
} |
|
||||
|
|
||||
public abstract void autoRun() throws Exception; |
|
||||
|
|
||||
public ThreadStatusEnum getStatus() { |
|
||||
return this.status; |
|
||||
} |
|
||||
|
|
||||
public void setStatus(ThreadStatusEnum status) { |
|
||||
this.status = status; |
|
||||
} |
|
||||
|
|
||||
public Date getStartTime() { |
|
||||
return this.startTime; |
|
||||
} |
|
||||
|
|
||||
public void setStartTime(Date startTime) { |
|
||||
this.startTime = startTime; |
|
||||
} |
|
||||
|
|
||||
public Date getStopTime() { |
|
||||
return this.stopTime; |
|
||||
} |
|
||||
|
|
||||
public void setStopTime(Date stopTime) { |
|
||||
this.stopTime = stopTime; |
|
||||
} |
|
||||
|
|
||||
public String getStopMessage() { |
|
||||
return this.stopMessage; |
|
||||
} |
|
||||
|
|
||||
public void setStopMessage(String stopMessage) { |
|
||||
this.stopMessage = stopMessage; |
|
||||
} |
|
||||
|
|
||||
public ThreadUsedStatusEnum getUsedStatus() { |
|
||||
return this.usedStatus; |
|
||||
} |
|
||||
|
|
||||
public void setUsedStatus(ThreadUsedStatusEnum usedStatus) { |
|
||||
this.usedStatus = usedStatus; |
|
||||
} |
|
||||
} |
|
@ -1,22 +0,0 @@ |
|||||
package org.nl.acs.auto.run; |
|
||||
|
|
||||
public enum ThreadStatusEnum { |
|
||||
create("创建", 1), run("运行", 2), stop("停止", 3); |
|
||||
|
|
||||
private String description; |
|
||||
private int order; |
|
||||
|
|
||||
private ThreadStatusEnum(String name, int order) { |
|
||||
this.description = name; |
|
||||
this.order = order; |
|
||||
} |
|
||||
|
|
||||
public String description() { |
|
||||
return this.description; |
|
||||
} |
|
||||
|
|
||||
public int getOrder() { |
|
||||
return this.order; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,23 +0,0 @@ |
|||||
package org.nl.acs.auto.run; |
|
||||
|
|
||||
public enum ThreadUsedStatusEnum { |
|
||||
|
|
||||
used("使用", 1), unUsed("未使用", 2); |
|
||||
|
|
||||
private String description; |
|
||||
private int order; |
|
||||
|
|
||||
private ThreadUsedStatusEnum(String name, int order) { |
|
||||
this.description = name; |
|
||||
this.order = order; |
|
||||
} |
|
||||
|
|
||||
public String description() { |
|
||||
return this.description; |
|
||||
} |
|
||||
|
|
||||
public int getOrder() { |
|
||||
return this.order; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,10 +0,0 @@ |
|||||
package org.nl.acs.udw; |
|
||||
|
|
||||
public class UdwConfig { |
|
||||
|
|
||||
//历史记录最大数量
|
|
||||
public static int max_history_length = 10; |
|
||||
|
|
||||
public UdwConfig() { |
|
||||
} |
|
||||
} |
|
@ -1,25 +0,0 @@ |
|||||
package org.nl.acs.udw; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import java.util.Date; |
|
||||
|
|
||||
@Data |
|
||||
public class UnifiedData { |
|
||||
private Object value; |
|
||||
private Date last_modify_date; |
|
||||
|
|
||||
public UnifiedData() { |
|
||||
this.last_modify_date = new Date(); |
|
||||
} |
|
||||
|
|
||||
public UnifiedData(Object value) { |
|
||||
this.value = value; |
|
||||
this.last_modify_date = new Date(); |
|
||||
} |
|
||||
|
|
||||
public void changeValue(Object value) { |
|
||||
this.value = value; |
|
||||
this.last_modify_date = new Date(); |
|
||||
} |
|
||||
} |
|
@ -1,17 +0,0 @@ |
|||||
package org.nl.acs.udw; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
public interface UnifiedDataAccessor { |
|
||||
List<String> getAllKey(); |
|
||||
|
|
||||
Object getValue(String key); |
|
||||
|
|
||||
void setValue(String key, Object value); |
|
||||
|
|
||||
UnifiedData getUnifiedData(String key); |
|
||||
|
|
||||
List<UnifiedData> getHistoryUnifiedData(String key); |
|
||||
|
|
||||
void setValueWithPersistence(String key, Object value); |
|
||||
} |
|
@ -1,20 +0,0 @@ |
|||||
package org.nl.acs.udw; |
|
||||
|
|
||||
import org.nl.acs.udw.service.impl.UnifiedDataAccessorImpl; |
|
||||
import org.nl.acs.udw.service.impl.UnifiedDataAppServiceImpl; |
|
||||
|
|
||||
public class UnifiedDataAccessorFactory { |
|
||||
public UnifiedDataAccessorFactory() { |
|
||||
} |
|
||||
|
|
||||
public static UnifiedDataAppService getUnifiedDataAppService() { |
|
||||
return UnifiedDataAppServiceImpl.getInstance(); |
|
||||
} |
|
||||
|
|
||||
public static UnifiedDataAccessor getAccessor(String unified_key) { |
|
||||
UnifiedDataAccessorImpl accessor = new UnifiedDataAccessorImpl(); |
|
||||
accessor.setUnifiedKey(unified_key); |
|
||||
accessor.setUnifiedDataService(getUnifiedDataAppService()); |
|
||||
return accessor; |
|
||||
} |
|
||||
} |
|
@ -1,47 +0,0 @@ |
|||||
package org.nl.acs.udw; |
|
||||
|
|
||||
import cn.hutool.core.util.ObjectUtil; |
|
||||
import org.nl.acs.udw.service.impl.UnifiedDataUnit; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
public interface UnifiedDataAppService { |
|
||||
/** |
|
||||
* 获取所有的key |
|
||||
* |
|
||||
* @return |
|
||||
*/ |
|
||||
List<String> getAllUnifiedKey(); |
|
||||
|
|
||||
/** |
|
||||
* 根据key获取数据单元 |
|
||||
* |
|
||||
* @param key |
|
||||
* @return |
|
||||
*/ |
|
||||
UnifiedDataUnit getUnifiedDataUnit(String key); |
|
||||
|
|
||||
UnifiedData getUnifiedData(String var1, String var2); |
|
||||
|
|
||||
Object getValue(String var1, String var2); |
|
||||
|
|
||||
void setValue(String var1, String var2, Object var3); |
|
||||
|
|
||||
void setValueNoLog(String var1, String var2, Object var3); |
|
||||
|
|
||||
List<UnifiedData> getHistoryUnifiedData(String var1, String var2); |
|
||||
|
|
||||
List<String> getAllDataKey(String var1); |
|
||||
|
|
||||
void removeValue(String var1, String var2); |
|
||||
|
|
||||
void setValueWithPersistenceNoLog(String var1, String var2, Object var3); |
|
||||
|
|
||||
void setValueWithPersistence(String var1, String var2, Object var3); |
|
||||
|
|
||||
void removeValueWithPersistence(String var1, String var2); |
|
||||
|
|
||||
static boolean isEquals(Object a, Object b) { |
|
||||
return ObjectUtil.equal(a, b); |
|
||||
} |
|
||||
} |
|
@ -1,16 +0,0 @@ |
|||||
package org.nl.acs.udw.dto; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import java.util.Date; |
|
||||
|
|
||||
/** |
|
||||
* 统一数据源管理 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class UdwDto { |
|
||||
private String unified_key; |
|
||||
private String key; |
|
||||
private Object value; |
|
||||
private Date last_modify_date; |
|
||||
} |
|
@ -1,37 +0,0 @@ |
|||||
|
|
||||
package org.nl.acs.udw.rest; |
|
||||
|
|
||||
|
|
||||
import io.swagger.annotations.Api; |
|
||||
import lombok.RequiredArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.nl.acs.udw.service.UdwManageService; |
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||
import org.springframework.web.bind.annotation.RestController; |
|
||||
|
|
||||
@RestController |
|
||||
@RequiredArgsConstructor |
|
||||
@Api(tags = "内存点位管理") |
|
||||
@RequestMapping("/api/udw") |
|
||||
@Slf4j |
|
||||
public class UdwManagerController { |
|
||||
|
|
||||
private final UdwManageService udwManageService; |
|
||||
|
|
||||
// @GetMapping
|
|
||||
// @Log("查询内存点位")
|
|
||||
// @ApiOperation("查询内存点位")
|
|
||||
// @SaIgnore
|
|
||||
// public ResponseEntity<Object> query(@RequestParam JSONObject whereJson) {
|
|
||||
// return new ResponseEntity<>(udwManageService.queryByConditions(whereJson), HttpStatus.OK);
|
|
||||
// }
|
|
||||
|
|
||||
// @GetMapping
|
|
||||
// @Log("查询内存点位")
|
|
||||
// @ApiOperation("查询内存点位")
|
|
||||
// @SaIgnore
|
|
||||
// //@PreAuthorize("@el.check('device:list')")
|
|
||||
// public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
|
|
||||
// return new ResponseEntity<>(udwManageService.queryAll(whereJson, page), HttpStatus.OK);
|
|
||||
// }
|
|
||||
} |
|
@ -1,28 +0,0 @@ |
|||||
package org.nl.acs.udw.service; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import org.nl.acs.udw.dto.UdwDto; |
|
||||
import org.springframework.data.domain.Pageable; |
|
||||
|
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
public interface UdwManageService { |
|
||||
/** |
|
||||
* 根据条件查询 |
|
||||
* |
|
||||
* @param where |
|
||||
* @return |
|
||||
*/ |
|
||||
List<UdwDto> queryByConditions(JSONObject where); |
|
||||
|
|
||||
/** |
|
||||
* 查询数据分页 |
|
||||
* |
|
||||
* @param whereJson 条件 |
|
||||
* @param page 分页参数 |
|
||||
* @return Map<String, Object> |
|
||||
*/ |
|
||||
Map<String, Object> queryAll(Map whereJson, Pageable page); |
|
||||
|
|
||||
} |
|
@ -1,156 +0,0 @@ |
|||||
package org.nl.acs.udw.service.impl; |
|
||||
|
|
||||
import cn.hutool.core.util.StrUtil; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import org.nl.acs.udw.UnifiedData; |
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory; |
|
||||
import org.nl.acs.udw.dto.UdwDto; |
|
||||
import org.nl.acs.udw.service.UdwManageService; |
|
||||
import org.springframework.data.domain.Pageable; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.Iterator; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
@Service |
|
||||
public class UdwManagerServiceImpl implements UdwManageService { |
|
||||
|
|
||||
public UdwManagerServiceImpl() { |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public List<UdwDto> queryByConditions(JSONObject where) { |
|
||||
String unified_key = null; |
|
||||
String keys = null; |
|
||||
|
|
||||
UnifiedDataUnit unifiedDataUnit = UnifiedDataAccessorFactory.getUnifiedDataAppService().getUnifiedDataUnit(unified_key); |
|
||||
if (unifiedDataUnit == null) { |
|
||||
return null; |
|
||||
} else { |
|
||||
String key; |
|
||||
UdwDto udwDto; |
|
||||
Map storage; |
|
||||
ArrayList udwDtos; |
|
||||
Iterator var14; |
|
||||
if (keys != null) { |
|
||||
storage = unifiedDataUnit.getStorage(); |
|
||||
udwDtos = new ArrayList(); |
|
||||
var14 = storage.keySet().iterator(); |
|
||||
|
|
||||
while(var14.hasNext()) { |
|
||||
key = (String)var14.next(); |
|
||||
if (key.indexOf(keys) != -1) { |
|
||||
udwDto = new UdwDto(); |
|
||||
udwDto.setUnified_key(unified_key); |
|
||||
udwDto.setKey(key); |
|
||||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|
||||
udwDtos.add(udwDto); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return udwDtos; |
|
||||
} else { |
|
||||
storage = unifiedDataUnit.getStorage(); |
|
||||
udwDtos = new ArrayList(); |
|
||||
var14 = storage.keySet().iterator(); |
|
||||
|
|
||||
while(var14.hasNext()) { |
|
||||
key = (String)var14.next(); |
|
||||
udwDto = new UdwDto(); |
|
||||
udwDto.setUnified_key(unified_key); |
|
||||
udwDto.setKey(key); |
|
||||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|
||||
udwDtos.add(udwDto); |
|
||||
} |
|
||||
|
|
||||
return udwDtos; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public Map<String, Object> queryAll(Map whereJson, Pageable page) { |
|
||||
|
|
||||
String unified_key = (String) whereJson.get("unified_key"); |
|
||||
String keys = (String) whereJson.get("code"); |
|
||||
if(StrUtil.isEmpty(unified_key)) |
|
||||
{ |
|
||||
unified_key = "opc_value"; |
|
||||
} |
|
||||
// String unified_key = (String) whereJson.get("unified_key");
|
|
||||
// String code = (String) whereJson.get("code");
|
|
||||
|
|
||||
// unified_key = whereJson.get("key").toString();
|
|
||||
// keys = whereJson.get("value").toString();
|
|
||||
|
|
||||
|
|
||||
//[[{"column":"unified_key","value":"cached","compareType":"equals","columnType":"object"}]]
|
|
||||
UnifiedDataUnit unifiedDataUnit = UnifiedDataAccessorFactory.getUnifiedDataAppService().getUnifiedDataUnit(unified_key); |
|
||||
if (unifiedDataUnit == null) { |
|
||||
return null; |
|
||||
} else { |
|
||||
String key; |
|
||||
UdwDto udwDto; |
|
||||
Map storage; |
|
||||
ArrayList udwDtos; |
|
||||
Iterator var14; |
|
||||
if (keys != null) { |
|
||||
storage = unifiedDataUnit.getStorage(); |
|
||||
udwDtos = new ArrayList(); |
|
||||
var14 = storage.keySet().iterator(); |
|
||||
|
|
||||
while(var14.hasNext()) { |
|
||||
key = (String)var14.next(); |
|
||||
if (key.indexOf(keys) != -1) { |
|
||||
udwDto = new UdwDto(); |
|
||||
udwDto.setUnified_key(unified_key); |
|
||||
udwDto.setKey(key); |
|
||||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|
||||
udwDtos.add(udwDto); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Integer currentPageNumber = page.getPageNumber() + 1; |
|
||||
Integer pageMaxSize = page.getPageSize(); |
|
||||
|
|
||||
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize) |
|
||||
.limit(pageMaxSize) |
|
||||
.collect(Collectors.toList()); |
|
||||
|
|
||||
JSONObject jo = new JSONObject(); |
|
||||
jo.put("content", orderbyDtoList); |
|
||||
jo.put("totalElements", udwDtos.size()); |
|
||||
|
|
||||
return jo; |
|
||||
} else { |
|
||||
storage = unifiedDataUnit.getStorage(); |
|
||||
udwDtos = new ArrayList(); |
|
||||
var14 = storage.keySet().iterator(); |
|
||||
|
|
||||
while(var14.hasNext()) { |
|
||||
key = (String)var14.next(); |
|
||||
udwDto = new UdwDto(); |
|
||||
udwDto.setUnified_key(unified_key); |
|
||||
udwDto.setKey(key); |
|
||||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|
||||
udwDtos.add(udwDto); |
|
||||
} |
|
||||
Integer currentPageNumber = page.getPageNumber() + 1; |
|
||||
Integer pageMaxSize = page.getPageSize(); |
|
||||
|
|
||||
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize) |
|
||||
.limit(pageMaxSize) |
|
||||
.collect(Collectors.toList()); |
|
||||
|
|
||||
JSONObject jo = new JSONObject(); |
|
||||
jo.put("content", orderbyDtoList); |
|
||||
jo.put("totalElements", udwDtos.size()); |
|
||||
|
|
||||
return jo; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,47 +0,0 @@ |
|||||
package org.nl.acs.udw.service.impl; |
|
||||
|
|
||||
import org.nl.acs.udw.UnifiedData; |
|
||||
import org.nl.acs.udw.UnifiedDataAccessor; |
|
||||
import org.nl.acs.udw.UnifiedDataAppService; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
public class UnifiedDataAccessorImpl implements UnifiedDataAccessor { |
|
||||
private String unified_key; |
|
||||
private UnifiedDataAppService unifiedDataAppService; |
|
||||
|
|
||||
public UnifiedDataAccessorImpl() { |
|
||||
} |
|
||||
|
|
||||
public void setUnifiedKey(String unified_key) { |
|
||||
this.unified_key = unified_key; |
|
||||
} |
|
||||
|
|
||||
public void setUnifiedDataService(UnifiedDataAppService unifiedDataService) { |
|
||||
this.unifiedDataAppService = unifiedDataService; |
|
||||
} |
|
||||
|
|
||||
public List<String> getAllKey() { |
|
||||
return this.unifiedDataAppService.getAllDataKey(this.unified_key); |
|
||||
} |
|
||||
|
|
||||
public Object getValue(String key) { |
|
||||
return this.unifiedDataAppService.getValue(this.unified_key, key); |
|
||||
} |
|
||||
|
|
||||
public void setValue(String key, Object value) { |
|
||||
this.unifiedDataAppService.setValue(this.unified_key, key, value); |
|
||||
} |
|
||||
|
|
||||
public void setValueWithPersistence(String key, Object value) { |
|
||||
this.unifiedDataAppService.setValueWithPersistence(this.unified_key, key, value); |
|
||||
} |
|
||||
|
|
||||
public UnifiedData getUnifiedData(String key) { |
|
||||
return this.unifiedDataAppService.getUnifiedData(this.unified_key, key); |
|
||||
} |
|
||||
|
|
||||
public List<UnifiedData> getHistoryUnifiedData(String key) { |
|
||||
return this.unifiedDataAppService.getHistoryUnifiedData(this.unified_key, key); |
|
||||
} |
|
||||
} |
|
@ -1,185 +0,0 @@ |
|||||
package org.nl.acs.udw.service.impl; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.nl.acs.udw.UdwConfig; |
|
||||
import org.nl.acs.udw.UnifiedData; |
|
||||
import org.nl.acs.udw.UnifiedDataAppService; |
|
||||
import org.nl.modules.common.exception.BadRequestException; |
|
||||
|
|
||||
import java.util.*; |
|
||||
|
|
||||
@Slf4j |
|
||||
public class UnifiedDataAppServiceImpl implements UnifiedDataAppService { |
|
||||
public static UnifiedDataAppService unifiedDataAppService; |
|
||||
private Map<String, UnifiedDataUnit> factory = Collections.synchronizedMap(new HashMap()); |
|
||||
|
|
||||
private UnifiedDataAppServiceImpl() { |
|
||||
} |
|
||||
|
|
||||
public static UnifiedDataAppService getInstance() { |
|
||||
if (unifiedDataAppService == null) { |
|
||||
Class var0 = UnifiedDataAppServiceImpl.class; |
|
||||
synchronized (UnifiedDataAppServiceImpl.class) { |
|
||||
if (unifiedDataAppService == null) { |
|
||||
unifiedDataAppService = new UnifiedDataAppServiceImpl(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return unifiedDataAppService; |
|
||||
} |
|
||||
|
|
||||
public List<String> getAllUnifiedKey() { |
|
||||
return new ArrayList(this.factory.keySet()); |
|
||||
} |
|
||||
|
|
||||
public UnifiedDataUnit getUnifiedDataUnit(String unified_key) { |
|
||||
UnifiedDataUnit dataUnit = (UnifiedDataUnit) this.factory.get(unified_key); |
|
||||
return dataUnit == null ? null : dataUnit; |
|
||||
} |
|
||||
|
|
||||
public List<String> getAllDataKey(String unified_key) { |
|
||||
UnifiedDataUnit dataUnit = (UnifiedDataUnit) this.factory.get(unified_key); |
|
||||
if (dataUnit == null) { |
|
||||
return new ArrayList(); |
|
||||
} else { |
|
||||
Map<String, UnifiedData> storage = dataUnit.getStorage(); |
|
||||
return new ArrayList(storage.keySet()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public UnifiedData getUnifiedData(String unified_key, String key) { |
|
||||
UnifiedDataUnit dataUnit = this.getUnifiedDataUnit(unified_key); |
|
||||
if (dataUnit == null) { |
|
||||
return null; |
|
||||
} else { |
|
||||
Map<String, UnifiedData> storage = dataUnit.getStorage(); |
|
||||
return (UnifiedData) storage.get(key); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public Object getValue(String unified_key, String key) { |
|
||||
UnifiedData unifiedData = this.getUnifiedData(unified_key, key); |
|
||||
return unifiedData == null ? null : unifiedData.getValue(); |
|
||||
} |
|
||||
|
|
||||
public void removeValueWithPersistence(String unified_key, String key) { |
|
||||
UnifiedDataUnit dataUnit = this.getUnifiedDataUnit(unified_key); |
|
||||
if (dataUnit != null) { |
|
||||
Map<String, UnifiedData> storage = dataUnit.getStorage(); |
|
||||
if (storage.containsKey(key)) { |
|
||||
storage.remove(key); |
|
||||
} |
|
||||
|
|
||||
Map<String, List<UnifiedData>> history = dataUnit.getHistory(); |
|
||||
if (history.containsKey(key)) { |
|
||||
history.remove(key); |
|
||||
} |
|
||||
|
|
||||
/*PersistenceService persistenceService = PersistenceServiceFactory.getPersistenceService(); |
|
||||
persistenceService.deleteData(unified_key, key);*/ |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public void removeValue(String unified_key, String key) { |
|
||||
UnifiedDataUnit dataUnit = this.getUnifiedDataUnit(unified_key); |
|
||||
if (dataUnit != null) { |
|
||||
Map<String, UnifiedData> storage = dataUnit.getStorage(); |
|
||||
if (storage.containsKey(key)) { |
|
||||
storage.remove(key); |
|
||||
} |
|
||||
|
|
||||
Map<String, List<UnifiedData>> history = dataUnit.getHistory(); |
|
||||
if (history.containsKey(key)) { |
|
||||
history.remove(key); |
|
||||
} |
|
||||
|
|
||||
if (history.size() == 0) { |
|
||||
this.factory.remove(unified_key); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public void setValueNoLog(String unified_key, String key, Object value) { |
|
||||
this.setValue(unified_key, key, value, false, false); |
|
||||
} |
|
||||
|
|
||||
public void setValue(String unified_key, String key, Object value) { |
|
||||
this.setValue(unified_key, key, value, false, true); |
|
||||
} |
|
||||
|
|
||||
public void setValueWithPersistenceNoLog(String unified_key, String key, Object value) { |
|
||||
this.setValue(unified_key, key, value, true, false); |
|
||||
} |
|
||||
|
|
||||
public void setValueWithPersistence(String unified_key, String key, Object value) { |
|
||||
this.setValue(unified_key, key, value, true, true); |
|
||||
} |
|
||||
|
|
||||
public synchronized void setValue(String unified_key, String key, Object value, boolean save, boolean is_log) { |
|
||||
if (unified_key == null) { |
|
||||
throw new BadRequestException(""); |
|
||||
//throw new BusinessException(SystemMessage.cant_be_empty, new Object[]{"unified_key"});
|
|
||||
} else if (key == null) { |
|
||||
throw new BadRequestException(""); |
|
||||
//throw new BusinessException(SystemMessage.cant_be_empty, new Object[]{"key"});
|
|
||||
} else { |
|
||||
if (!this.factory.containsKey(unified_key)) { |
|
||||
this.factory.put(unified_key, new UnifiedDataUnit(unified_key)); |
|
||||
} |
|
||||
|
|
||||
UnifiedDataUnit dataUnit = (UnifiedDataUnit) this.factory.get(unified_key); |
|
||||
Map<String, UnifiedData> storage = dataUnit.getStorage(); |
|
||||
if (!storage.containsKey(key)) { |
|
||||
storage.put(key, new UnifiedData()); |
|
||||
} |
|
||||
|
|
||||
UnifiedData unifiedData = (UnifiedData) storage.get(key); |
|
||||
if (!UnifiedDataAppService.isEquals(unifiedData.getValue(), value)) { |
|
||||
Map<String, List<UnifiedData>> history = dataUnit.getHistory(); |
|
||||
List<UnifiedData> historyunifiedData = (List) history.get(key); |
|
||||
if (historyunifiedData == null) { |
|
||||
history.put(key, new ArrayList()); |
|
||||
} |
|
||||
|
|
||||
UnifiedData historydata = new UnifiedData(); |
|
||||
historydata.setLast_modify_date(unifiedData.getLast_modify_date()); |
|
||||
historydata.setValue(unifiedData.getValue()); |
|
||||
|
|
||||
while (((List) history.get(key)).size() > UdwConfig.max_history_length) { |
|
||||
((List) history.get(key)).remove(UdwConfig.max_history_length); |
|
||||
} |
|
||||
|
|
||||
((List) history.get(key)).add(0, historydata); |
|
||||
Object oldvalue = unifiedData.getValue(); |
|
||||
unifiedData.changeValue(value); |
|
||||
if (save) { |
|
||||
/*PersistenceService persistenceService = PersistenceServiceFactory.getPersistenceService(); |
|
||||
persistenceService.saveData(unified_key, key, StringUtl.getString(value)); |
|
||||
if (is_log) { |
|
||||
this.businessLogger.setResource(unified_key, unified_key); |
|
||||
this.businessLogger.setMaterial(key, key); |
|
||||
this.businessLogger.setContainer(StringUtl.getString(value)); |
|
||||
this.businessLogger.log("统一数据源中: unit: {}, key: {}, 值: {} 更改为 {}。", new Object[]{unified_key, key, oldvalue, value}); |
|
||||
}*/ |
|
||||
} |
|
||||
|
|
||||
if (is_log && key != null && !key.endsWith("heartbeat") && !key.endsWith("distancex") && !key.endsWith("distancey") && !key.endsWith("Xwz") && !key.endsWith("Ywz") && !key.endsWith("Zwz")) { |
|
||||
log.trace("统一数据源中: unit: {}, key: {}, 值: {} 更改为 {}。", new Object[]{unified_key, key, oldvalue, value}); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public List<UnifiedData> getHistoryUnifiedData(String unified_key, String key) { |
|
||||
UnifiedDataUnit dataUnit = this.getUnifiedDataUnit(unified_key); |
|
||||
if (dataUnit == null) { |
|
||||
return new ArrayList(); |
|
||||
} else { |
|
||||
Map<String, List<UnifiedData>> history = dataUnit.getHistory(); |
|
||||
List<UnifiedData> result = (List) history.get(key); |
|
||||
return (List) (result == null ? new ArrayList() : result); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,21 +0,0 @@ |
|||||
package org.nl.acs.udw.service.impl; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
import org.nl.acs.udw.UnifiedData; |
|
||||
|
|
||||
import java.util.Collections; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
|
|
||||
@Data |
|
||||
public class UnifiedDataUnit { |
|
||||
private String unifiedKey; |
|
||||
private Map<String, UnifiedData> storage = Collections.synchronizedMap(new HashMap()); |
|
||||
private Map<String, List<UnifiedData>> history = Collections.synchronizedMap(new HashMap()); |
|
||||
|
|
||||
public UnifiedDataUnit(String unifiedKey) { |
|
||||
this.unifiedKey = unifiedKey; |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,41 +0,0 @@ |
|||||
/* |
|
||||
* Copyright 2019-2020 Zheng Jie |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.nl.modules.common.exception; |
|
||||
|
|
||||
import lombok.Getter; |
|
||||
import org.springframework.http.HttpStatus; |
|
||||
|
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST; |
|
||||
|
|
||||
/** |
|
||||
* @author Zheng Jie |
|
||||
* @date 2018-11-23 |
|
||||
* 统一异常处理 |
|
||||
*/ |
|
||||
@Getter |
|
||||
public class BadRequestException extends RuntimeException{ |
|
||||
|
|
||||
private Integer status = BAD_REQUEST.value(); |
|
||||
|
|
||||
public BadRequestException(String msg){ |
|
||||
super(msg); |
|
||||
} |
|
||||
|
|
||||
public BadRequestException(HttpStatus status, String msg){ |
|
||||
super(msg); |
|
||||
this.status = status.value(); |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue