命名重构
This commit is contained in:
parent
a58670c1bc
commit
ffb25ec8a5
@ -9,7 +9,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>xhpc-power-pole</module>
|
<module>xhpc-power-pile</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>xhpc-modules</artifactId>
|
<artifactId>xhpc-modules</artifactId>
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>xhpc-power-pole</artifactId>
|
<artifactId>xhpc-power-pile</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
充电桩服务
|
充电桩服务
|
||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
@ -21,8 +21,8 @@ public class TestController {
|
|||||||
String serverAddr = serverIp + ":" + serverPort;
|
String serverAddr = serverIp + ":" + serverPort;
|
||||||
|
|
||||||
NamingService namingService = NacosFactory.createNamingService(serverAddr);
|
NamingService namingService = NacosFactory.createNamingService(serverAddr);
|
||||||
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pole");
|
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pile");
|
||||||
// todo clean dead host pole cache
|
// todo clean dead host pile cache
|
||||||
String ipAndPort = GetIpAndPort.getIpAndPort();
|
String ipAndPort = GetIpAndPort.getIpAndPort();
|
||||||
return ipAndPort;
|
return ipAndPort;
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.xhpc.pp.domain;
|
package com.xhpc.pp.domain;
|
||||||
|
|
||||||
public class ServiceField {
|
public class ServiceField {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
@ -18,66 +19,82 @@ public class ServiceField {
|
|||||||
private String dataType;
|
private String dataType;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServiceName() {
|
public String getServiceName() {
|
||||||
|
|
||||||
return serviceName;
|
return serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServiceName(String serviceName) {
|
public void setServiceName(String serviceName) {
|
||||||
|
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setVersion(String version) {
|
||||||
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(String code) {
|
public void setCode(String code) {
|
||||||
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getLen() {
|
public Integer getLen() {
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLen(Integer len) {
|
public void setLen(Integer len) {
|
||||||
|
|
||||||
this.len = len;
|
this.len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getSeq() {
|
public Integer getSeq() {
|
||||||
|
|
||||||
return seq;
|
return seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeq(Integer seq) {
|
public void setSeq(Integer seq) {
|
||||||
|
|
||||||
this.seq = seq;
|
this.seq = seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRemark() {
|
public String getRemark() {
|
||||||
|
|
||||||
return remark;
|
return remark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRemark(String remark) {
|
public void setRemark(String remark) {
|
||||||
|
|
||||||
this.remark = remark;
|
this.remark = remark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDataType() {
|
public String getDataType() {
|
||||||
|
|
||||||
return dataType;
|
return dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataType(String dataType) {
|
public void setDataType(String dataType) {
|
||||||
|
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,4 +20,5 @@ public interface ServiceFieldMapper {
|
|||||||
int updateByPrimaryKey(ServiceField record);
|
int updateByPrimaryKey(ServiceField record);
|
||||||
|
|
||||||
List<Map<String, Object>> querySQL(Map<String, String> query);
|
List<Map<String, Object>> querySQL(Map<String, String> query);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -50,8 +50,8 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
List<byte[]> dataList = parseDataList(data);
|
List<byte[]> dataList = parseDataList(data);
|
||||||
for (byte[] d : dataList) {
|
for (byte[] d : dataList) {
|
||||||
String dataStr = HexUtils.toHex(d);
|
String dataStr = HexUtils.toHex(d);
|
||||||
String poleNo = ChargingPileServer.getPoleNo(handler);
|
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
log.info("received data <<<< {}, from pole <<<< {}", dataStr, poleNo);
|
log.info("received data <<<< {}, from pile <<<< {}", dataStr, pileNo);
|
||||||
if (d.length <= 2 || !dataStr.startsWith("68")) {
|
if (d.length <= 2 || !dataStr.startsWith("68")) {
|
||||||
log.info("received invalid data <<<< {}, len[{}]", dataStr, d.length);
|
log.info("received invalid data <<<< {}, len[{}]", dataStr, d.length);
|
||||||
continue;
|
continue;
|
||||||
@ -78,32 +78,32 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
String serviceName = HexUtils.toHex(data, 5, 6);
|
String serviceName = HexUtils.toHex(data, 5, 6);
|
||||||
String version = ChargingPileServer.getVersion(handler.getName());
|
String version = ChargingPileServer.getVersion(handler.getName());
|
||||||
Map<String, Object> req = analysis(data, serviceName, version);
|
Map<String, Object> req = analysis(data, serviceName, version);
|
||||||
String poleNo = (String) req.get("poleNo");
|
String pileNo = (String) req.get("pileNo");
|
||||||
ServiceParameter sp = new ServiceParameter(serviceName, poleNo, req);
|
ServiceParameter sp = new ServiceParameter(serviceName, pileNo, req);
|
||||||
ServiceResult result = servicemainLogic.process(sp);
|
ServiceResult result = servicemainLogic.process(sp);
|
||||||
String resultCode = result.getCode();
|
String resultCode = result.getCode();
|
||||||
if (SERVICE_REGISTER.equals(serviceName) && OK.equals(resultCode)) {
|
if (SERVICE_REGISTER.equals(serviceName) && OK.equals(resultCode)) {
|
||||||
reg(handler, poleNo, req);
|
reg(handler, pileNo, req);
|
||||||
} /*else if (SERVICE_HB.equals(serviceName)) {
|
} /*else if (SERVICE_HB.equals(serviceName)) {
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
if (result.getBinary() != null) {
|
if (result.getBinary() != null) {
|
||||||
log.info("server send msg >>>> [{}] |{}|", poleNo, HexUtils.toHex(result.getBinary()));
|
log.info("server send msg >>>> [{}] |{}|", pileNo, HexUtils.toHex(result.getBinary()));
|
||||||
handler.sendClientBinary(result.getBinary());
|
handler.sendClientBinary(result.getBinary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reg(ClientHandler handler, String poleNo, Map<String, Object> req) {
|
private void reg(ClientHandler handler, String pileNo, Map<String, Object> req) {
|
||||||
|
|
||||||
ChargingPileServer.putHandler(poleNo, handler);
|
ChargingPileServer.putHandler(pileNo, handler);
|
||||||
ChargingPileServer.putVersion(handler.getName(), (String) req.get("version"));
|
ChargingPileServer.putVersion(handler.getName(), (String) req.get("version"));
|
||||||
Map<String, Object> poleCache = REDIS.getCacheMap(poleNo);
|
Map<String, Object> pileCache = REDIS.getCacheMap(pileNo);
|
||||||
poleCache.put("Status", REGISTERED);
|
pileCache.put("Status", REGISTERED);
|
||||||
poleCache.put("Server", getLocalIPAndPort());
|
pileCache.put("Server", getLocalIPAndPort());
|
||||||
REDIS.setCacheMap(poleNo, poleCache);
|
REDIS.setCacheMap(pileNo, pileCache);
|
||||||
Set<String> polesAtHost = REDIS.getCacheSet(getLocalIP());
|
Set<String> pilesAtHost = REDIS.getCacheSet(getLocalIP());
|
||||||
polesAtHost.add(poleNo);
|
pilesAtHost.add(pileNo);
|
||||||
log.info("pole registered >>>> [{}] ", poleNo);
|
log.info("pile registered >>>> [{}] ", pileNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<byte[]> parseDataList(byte[] data) {
|
private List<byte[]> parseDataList(byte[] data) {
|
||||||
@ -15,10 +15,12 @@ public class ChargingPileCommandHandler implements ClientCommandHandler {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(ChargingPileCommandHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileCommandHandler.class);
|
||||||
|
|
||||||
public ChargingPileCommandHandler() {
|
public ChargingPileCommandHandler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ClientHandler handler, String appData) throws SocketTimeoutException, IOException {
|
public void handleCommand(ClientHandler handler, String appData) throws SocketTimeoutException, IOException {
|
||||||
|
|
||||||
log.info("handleCommand <====" + appData);
|
log.info("handleCommand <====" + appData);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -26,11 +26,11 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void lostConnection(ClientHandler handler) {
|
public void lostConnection(ClientHandler handler) {
|
||||||
|
|
||||||
String poleNo = ChargingPileServer.getPoleNo(handler);
|
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
log.info("lost connection -> [{}] {} <- {}",
|
log.info("lost connection -> [{}] {} <- {}",
|
||||||
poleNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||||
if (poleNo != null) {
|
if (pileNo != null) {
|
||||||
ChargingPileServer.removeHandler(poleNo);
|
ChargingPileServer.removeHandler(pileNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public class ChargingPileServer {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class);
|
private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class);
|
||||||
private static Map<String, ClientHandler> handlerMap = new HashMap<>();
|
private static Map<String, ClientHandler> handlerMap = new HashMap<>();
|
||||||
private static Map<String, String> versionMapper = new HashMap<>();
|
private static Map<String, String> versionMapper = new HashMap<>();
|
||||||
private static Map<String, String> poleMap = new HashMap<>();
|
private static Map<String, String> pileMap = new HashMap<>();
|
||||||
public static RedisService REDIS;
|
public static RedisService REDIS;
|
||||||
private QuickServer server;
|
private QuickServer server;
|
||||||
|
|
||||||
@ -87,38 +87,38 @@ public class ChargingPileServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void putHandler(String poleNo, ClientHandler handler) {
|
public static void putHandler(String pileNo, ClientHandler handler) {
|
||||||
|
|
||||||
handlerMap.put(poleNo, handler);
|
handlerMap.put(pileNo, handler);
|
||||||
poleMap.put(handler.getName(), poleNo);
|
pileMap.put(handler.getName(), pileNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeHandler(String poleNo) {
|
public static void removeHandler(String pileNo) {
|
||||||
|
|
||||||
ClientHandler handler = handlerMap.remove(poleNo);
|
ClientHandler handler = handlerMap.remove(pileNo);
|
||||||
Map<String, Object> cacheMap = REDIS.getCacheMap(poleNo);
|
Map<String, Object> cacheMap = REDIS.getCacheMap(pileNo);
|
||||||
cacheMap.put("Status", DISCONNECTED);
|
cacheMap.put("Status", DISCONNECTED);
|
||||||
REDIS.setCacheMap(poleNo, cacheMap);
|
REDIS.setCacheMap(pileNo, cacheMap);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
log.info("remove handler [{}] for [{}]", handler.getName(), poleNo);
|
log.info("remove handler [{}] for [{}]", handler.getName(), pileNo);
|
||||||
poleMap.remove(handler.getName());
|
pileMap.remove(handler.getName());
|
||||||
versionMapper.remove(handler.getName());
|
versionMapper.remove(handler.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendClientMsg(String poleNo, byte[] msg) {
|
public static void sendClientMsg(String pileNo, byte[] msg) {
|
||||||
|
|
||||||
if (!HexUtils.toHex(msg).startsWith("00101005")) {
|
if (!HexUtils.toHex(msg).startsWith("00101005")) {
|
||||||
log.info("server send msg >>>> [{}] |{}|", poleNo, HexUtils.toHex(msg));
|
log.info("server send msg >>>> [{}] |{}|", pileNo, HexUtils.toHex(msg));
|
||||||
}
|
}
|
||||||
if (poleNo.length() < 16) {
|
if (pileNo.length() < 16) {
|
||||||
poleNo = "0000000000000000" + poleNo;
|
pileNo = "0000000000000000" + pileNo;
|
||||||
poleNo = poleNo.substring(poleNo.length() - 16);
|
pileNo = pileNo.substring(pileNo.length() - 16);
|
||||||
}
|
}
|
||||||
ClientHandler handler = handlerMap.get(poleNo);
|
ClientHandler handler = handlerMap.get(pileNo);
|
||||||
if (handler == null || !handler.isOpen()) {
|
if (handler == null || !handler.isOpen()) {
|
||||||
log.error("send message failed. [{}] connection lost", poleNo);
|
log.error("send message failed. [{}] connection lost", pileNo);
|
||||||
removeHandler(poleNo);
|
removeHandler(pileNo);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -141,14 +141,14 @@ public class ChargingPileServer {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientHandler getHandler(String pole) {
|
public static ClientHandler getHandler(String pile) {
|
||||||
|
|
||||||
return handlerMap.get(pole);
|
return handlerMap.get(pile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPoleNo(ClientHandler handler) {
|
public static String getPileNo(ClientHandler handler) {
|
||||||
|
|
||||||
return poleMap.get(handler.getName());
|
return pileMap.get(handler.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutDown() {
|
public void shutDown() {
|
||||||
@ -24,19 +24,19 @@ public class HBLogic implements ServiceLogic {
|
|||||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||||
|
|
||||||
Map<String, Object> req = sp.getParameters();
|
Map<String, Object> req = sp.getParameters();
|
||||||
String poleNo = (String) req.get("poleNo");
|
String pileNo = (String) req.get("pileNo");
|
||||||
String gunId = (String) req.get("gunId");
|
String gunId = (String) req.get("gunId");
|
||||||
String gunStatus = (String) req.get("gunStatus");
|
String gunStatus = (String) req.get("gunStatus");
|
||||||
int gunStatusInt = 0;
|
int gunStatusInt = 0;
|
||||||
if (ServiceResult.HEX_FAIL.equals(gunStatus))
|
if (ServiceResult.HEX_FAIL.equals(gunStatus))
|
||||||
gunStatusInt = 1;
|
gunStatusInt = 1;
|
||||||
String gunKey = poleNo.concat(gunId);
|
String gunKey = pileNo.concat(gunId);
|
||||||
Map<String, Integer> cacheGun = REDIS.getCacheMap(gunKey);
|
Map<String, Integer> cacheGun = REDIS.getCacheMap(gunKey);
|
||||||
int cacheGunStatus = cacheGun.get(gunKey);
|
int cacheGunStatus = cacheGun.get(gunKey);
|
||||||
if ((1 == cacheGunStatus && 0 == gunStatusInt) || (0 == cacheGunStatus && 1 == gunStatusInt)) {
|
if ((1 == cacheGunStatus && 0 == gunStatusInt) || (0 == cacheGunStatus && 1 == gunStatusInt)) {
|
||||||
cacheGun.put(gunKey, gunStatusInt);
|
cacheGun.put(gunKey, gunStatusInt);
|
||||||
}
|
}
|
||||||
String resultStr = "680D00000004".concat(poleNo).concat(gunId).concat(ServiceResult.HEX_OK);
|
String resultStr = "680D00000004".concat(pileNo).concat(gunId).concat(ServiceResult.HEX_OK);
|
||||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||||
}
|
}
|
||||||
@ -24,17 +24,17 @@ public class RateModelValidateLogic implements ServiceLogic {
|
|||||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||||
|
|
||||||
Map<String, Object> req = sp.getParameters();
|
Map<String, Object> req = sp.getParameters();
|
||||||
String poleNo = (String) req.get("poleNo");
|
String pileNo = (String) req.get("pileNo");
|
||||||
String rateModelId = (String) req.get("rateModelId");
|
String rateModelId = (String) req.get("rateModelId");
|
||||||
Map<String, Integer> cachePole = REDIS.getCacheMap(poleNo);
|
Map<String, Integer> cachePile = REDIS.getCacheMap(pileNo);
|
||||||
String resultCode = ServiceResult.OK;
|
String resultCode = ServiceResult.OK;
|
||||||
String hexCode = ServiceResult.HEX_OK;
|
String hexCode = ServiceResult.HEX_OK;
|
||||||
Integer rateModelIdCache = cachePole.get("rateModelId");
|
Integer rateModelIdCache = cachePile.get("rateModelId");
|
||||||
if (Integer.parseInt(rateModelId) != rateModelIdCache) {
|
if (Integer.parseInt(rateModelId) != rateModelIdCache) {
|
||||||
hexCode = ServiceResult.HEX_FAIL;
|
hexCode = ServiceResult.HEX_FAIL;
|
||||||
resultCode = ServiceResult.FAIL;
|
resultCode = ServiceResult.FAIL;
|
||||||
}
|
}
|
||||||
String resultStr = "680E00000006".concat(poleNo).concat(String.format("%04d", rateModelIdCache)).concat(hexCode);
|
String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04d", rateModelIdCache)).concat(hexCode);
|
||||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||||
}
|
}
|
||||||
@ -29,15 +29,16 @@ public class RegisterLogic implements ServiceLogic {
|
|||||||
Map<String, Object> req = sp.getParameters();
|
Map<String, Object> req = sp.getParameters();
|
||||||
String resultCode = ServiceResult.OK;
|
String resultCode = ServiceResult.OK;
|
||||||
String hexCode = ServiceResult.HEX_OK;
|
String hexCode = ServiceResult.HEX_OK;
|
||||||
String poleNo = (String) req.get("poleNo");
|
String pileNo = (String) req.get("pileNo");
|
||||||
Set<String> pileSnPool = REDIS.getCacheSet("PILE_SN_POOL");
|
Set<String> pileSnPool = REDIS.getCacheSet("PILE_SN_POOL");
|
||||||
//todo set rate model to cache
|
//todo set rate model to cache
|
||||||
if (!pileSnPool.contains(poleNo)) {
|
if (!pileSnPool.contains(pileNo)) {
|
||||||
hexCode = ServiceResult.HEX_FAIL;
|
hexCode = ServiceResult.HEX_FAIL;
|
||||||
resultCode = ServiceResult.FAIL;
|
resultCode = ServiceResult.FAIL;
|
||||||
}
|
}
|
||||||
String resultStr = "680C00000002".concat(poleNo).concat(hexCode);
|
String resultStr = "680C00000002".concat(pileNo).concat(hexCode);
|
||||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -13,6 +13,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
@Component("ServiceMainLogic")
|
@Component("ServiceMainLogic")
|
||||||
public class ServiceMainLogic {
|
public class ServiceMainLogic {
|
||||||
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
// 结构:Map<serviceType,ServiceCommandLogic>
|
// 结构:Map<serviceType,ServiceCommandLogic>
|
||||||
@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
@RequestMapping
|
@RequestMapping
|
||||||
public class ServiceController {
|
public class ServiceController {
|
||||||
|
|
||||||
private static final String SESSIONID = "poleNo";
|
private static final String SESSIONID = "pileNo";
|
||||||
private static final String SERVICE_NAME = "serviceName";
|
private static final String SERVICE_NAME = "serviceName";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -25,10 +25,11 @@ public class ServiceController {
|
|||||||
@RequestMapping(value = "/api")
|
@RequestMapping(value = "/api")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String index(@RequestBody Map<String, Object> req) throws IOException {
|
public String index(@RequestBody Map<String, Object> req) throws IOException {
|
||||||
String poleNo = (String) req.get(SESSIONID);
|
|
||||||
|
String pileNo = (String) req.get(SESSIONID);
|
||||||
String serviceName = (String) req.get(SERVICE_NAME);
|
String serviceName = (String) req.get(SERVICE_NAME);
|
||||||
|
|
||||||
ServiceParameter serviceParameter = new ServiceParameter(serviceName, poleNo, req);
|
ServiceParameter serviceParameter = new ServiceParameter(serviceName, pileNo, req);
|
||||||
ServiceResult result = servicemainLogic.process(serviceParameter);
|
ServiceResult result = servicemainLogic.process(serviceParameter);
|
||||||
|
|
||||||
if (result.getJson() != null) {
|
if (result.getJson() != null) {
|
||||||
@ -9,48 +9,57 @@ public class ServiceParameter implements Serializable {
|
|||||||
|
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
|
||||||
private String poleNo;
|
private String pileNo;
|
||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
private Map<String, Object> parameters;
|
private Map<String, Object> parameters;
|
||||||
|
|
||||||
public ServiceParameter(String serviceName, String poleNo, Map<String, Object> parameters) {
|
public ServiceParameter(String serviceName, String pileNo, Map<String, Object> parameters) {
|
||||||
|
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
this.poleNo = poleNo;
|
this.pileNo = pileNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServiceName() {
|
public String getServiceName() {
|
||||||
|
|
||||||
return serviceName;
|
return serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServiceName(String serviceName) {
|
public void setServiceName(String serviceName) {
|
||||||
|
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getParameters() {
|
public Map<String, Object> getParameters() {
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameters(Map<String, Object> parameters) {
|
public void setParameters(Map<String, Object> parameters) {
|
||||||
|
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setVersion(String version) {
|
||||||
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPoleNo() {
|
public String getPileNo() {
|
||||||
return poleNo;
|
|
||||||
|
return pileNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoleNo(String poleNo) {
|
public void setPileNo(String pileNo) {
|
||||||
this.poleNo = poleNo;
|
|
||||||
|
this.pileNo = pileNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -27,10 +27,12 @@ public class ServiceResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult(Map<String, String> json) {
|
public ServiceResult(Map<String, String> json) {
|
||||||
|
|
||||||
this.json = json;
|
this.json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult(Object json) {
|
public ServiceResult(Object json) {
|
||||||
|
|
||||||
this.json = json;
|
this.json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,22 +49,28 @@ public class ServiceResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object getJson() {
|
public Object getJson() {
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJson(Map<String, Object> json) {
|
public void setJson(Map<String, Object> json) {
|
||||||
|
|
||||||
this.json = json;
|
this.json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBinary() {
|
public byte[] getBinary() {
|
||||||
|
|
||||||
return binary;
|
return binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(String code) {
|
public void setCode(String code) {
|
||||||
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.xhpc.pp.tx;
|
package com.xhpc.pp.tx;
|
||||||
|
|
||||||
public class TxException extends Exception {
|
public class TxException extends Exception {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缺少参数
|
* 缺少参数
|
||||||
*/
|
*/
|
||||||
@ -18,16 +19,19 @@ public class TxException extends Exception {
|
|||||||
private String returnCode;
|
private String returnCode;
|
||||||
|
|
||||||
public TxException(String rtnCode, Throwable reason) {
|
public TxException(String rtnCode, Throwable reason) {
|
||||||
|
|
||||||
super(rtnCode, reason);
|
super(rtnCode, reason);
|
||||||
this.returnCode = rtnCode;
|
this.returnCode = rtnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TxException(String rtnCode, String msg) {
|
public TxException(String rtnCode, String msg) {
|
||||||
|
|
||||||
super(msg);
|
super(msg);
|
||||||
this.returnCode = rtnCode;
|
this.returnCode = rtnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TxException(String rtnCode) {
|
public TxException(String rtnCode) {
|
||||||
|
|
||||||
this.returnCode = rtnCode;
|
this.returnCode = rtnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +44,7 @@ public class TxException extends Exception {
|
|||||||
* 参数错误
|
* 参数错误
|
||||||
*/
|
*/
|
||||||
public static TxException PARAMETER_INVALID(String error) {
|
public static TxException PARAMETER_INVALID(String error) {
|
||||||
|
|
||||||
return new TxException("1101", error);
|
return new TxException("1101", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +52,12 @@ public class TxException extends Exception {
|
|||||||
* 内部错误
|
* 内部错误
|
||||||
*/
|
*/
|
||||||
public static TxException INNER_ERROR(String msg) {
|
public static TxException INNER_ERROR(String msg) {
|
||||||
|
|
||||||
return new TxException("1111", msg);
|
return new TxException("1111", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReturnCode() {
|
public String getReturnCode() {
|
||||||
|
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class FileUploadUtils
|
public class FileUploadUtils {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 默认大小 50M
|
* 默认大小 50M
|
||||||
*/
|
*/
|
||||||
@ -34,18 +34,15 @@ public class FileUploadUtils
|
|||||||
* 根据文件路径上传
|
* 根据文件路径上传
|
||||||
*
|
*
|
||||||
* @param baseDir 相对应用的基目录
|
* @param baseDir 相对应用的基目录
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 文件名称
|
* @return 文件名称
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static final String upload(String baseDir, MultipartFile file) throws IOException
|
public static final String upload(String baseDir, MultipartFile file) throws IOException {
|
||||||
{
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new IOException(e.getMessage(), e);
|
throw new IOException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,22 +50,21 @@ public class FileUploadUtils
|
|||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
*
|
*
|
||||||
* @param baseDir 相对应用的基目录
|
* @param baseDir 相对应用的基目录
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @param allowedExtension 上传文件类型
|
* @param allowedExtension 上传文件类型
|
||||||
* @return 返回上传成功的文件名
|
* @return 返回上传成功的文件名
|
||||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
* @throws InvalidExtensionException 文件校验异常
|
* @throws InvalidExtensionException 文件校验异常
|
||||||
*/
|
*/
|
||||||
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
||||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||||
InvalidExtensionException
|
InvalidExtensionException {
|
||||||
{
|
|
||||||
int fileNamelength = file.getOriginalFilename().length();
|
int fileNamelength = file.getOriginalFilename().length();
|
||||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
||||||
{
|
|
||||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,30 +81,28 @@ public class FileUploadUtils
|
|||||||
/**
|
/**
|
||||||
* 编码文件名
|
* 编码文件名
|
||||||
*/
|
*/
|
||||||
public static final String extractFilename(MultipartFile file)
|
public static final String extractFilename(MultipartFile file) {
|
||||||
{
|
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String extension = getExtension(file);
|
String extension = getExtension(file);
|
||||||
fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
|
fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
|
||||||
{
|
|
||||||
File desc = new File(uploadDir + File.separator + fileName);
|
File desc = new File(uploadDir + File.separator + fileName);
|
||||||
|
|
||||||
if (!desc.exists())
|
if (!desc.exists()) {
|
||||||
{
|
if (!desc.getParentFile().exists()) {
|
||||||
if (!desc.getParentFile().exists())
|
|
||||||
{
|
|
||||||
desc.getParentFile().mkdirs();
|
desc.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
|
return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String getPathFileName(String fileName) throws IOException
|
private static final String getPathFileName(String fileName) throws IOException {
|
||||||
{
|
|
||||||
String pathFileName = "/" + fileName;
|
String pathFileName = "/" + fileName;
|
||||||
return pathFileName;
|
return pathFileName;
|
||||||
}
|
}
|
||||||
@ -118,43 +112,32 @@ public class FileUploadUtils
|
|||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||||
* @throws InvalidExtensionException 文件校验异常
|
* @throws InvalidExtensionException 文件校验异常
|
||||||
*/
|
*/
|
||||||
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
|
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
|
||||||
throws FileSizeLimitExceededException, InvalidExtensionException
|
throws FileSizeLimitExceededException, InvalidExtensionException {
|
||||||
{
|
|
||||||
long size = file.getSize();
|
long size = file.getSize();
|
||||||
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
|
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {
|
||||||
{
|
|
||||||
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
|
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String extension = getExtension(file);
|
String extension = getExtension(file);
|
||||||
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
|
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
|
||||||
{
|
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) {
|
||||||
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
|
|
||||||
{
|
|
||||||
throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
|
throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
|
||||||
fileName);
|
fileName);
|
||||||
}
|
} else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) {
|
||||||
else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
|
|
||||||
{
|
|
||||||
throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
|
throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
|
||||||
fileName);
|
fileName);
|
||||||
}
|
} else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) {
|
||||||
else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
|
|
||||||
{
|
|
||||||
throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
|
throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
|
||||||
fileName);
|
fileName);
|
||||||
}
|
} else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) {
|
||||||
else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION)
|
|
||||||
{
|
|
||||||
throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
|
throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
|
||||||
fileName);
|
fileName);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,16 +146,14 @@ public class FileUploadUtils
|
|||||||
/**
|
/**
|
||||||
* 判断MIME类型是否是允许的MIME类型
|
* 判断MIME类型是否是允许的MIME类型
|
||||||
*
|
*
|
||||||
* @param extension 上传文件类型
|
* @param extension 上传文件类型
|
||||||
* @param allowedExtension 允许上传文件类型
|
* @param allowedExtension 允许上传文件类型
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
|
public static final boolean isAllowedExtension(String extension, String[] allowedExtension) {
|
||||||
{
|
|
||||||
for (String str : allowedExtension)
|
for (String str : allowedExtension) {
|
||||||
{
|
if (str.equalsIgnoreCase(extension)) {
|
||||||
if (str.equalsIgnoreCase(extension))
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,13 +166,13 @@ public class FileUploadUtils
|
|||||||
* @param file 表单文件
|
* @param file 表单文件
|
||||||
* @return 后缀名
|
* @return 后缀名
|
||||||
*/
|
*/
|
||||||
public static final String getExtension(MultipartFile file)
|
public static final String getExtension(MultipartFile file) {
|
||||||
{
|
|
||||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
if (StringUtils.isEmpty(extension))
|
if (StringUtils.isEmpty(extension)) {
|
||||||
{
|
|
||||||
extension = MimeTypeUtils.getExtension(file.getContentType());
|
extension = MimeTypeUtils.getExtension(file.getContentType());
|
||||||
}
|
}
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -24,6 +24,7 @@ public class JSONUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T readValue(String url, Class<T> clz) {
|
public static <T> T readValue(String url, Class<T> clz) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
return mapper.readValue(u, clz);
|
return mapper.readValue(u, clz);
|
||||||
@ -39,6 +40,7 @@ public class JSONUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T readValue(String url, String params, Class<T> clz) {
|
public static <T> T readValue(String url, String params, Class<T> clz) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String param = "?params=" + params;
|
String param = "?params=" + params;
|
||||||
URL u = new URL(url + param);
|
URL u = new URL(url + param);
|
||||||
@ -55,10 +57,12 @@ public class JSONUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
|
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
|
||||||
|
|
||||||
return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
|
return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeTo(PrintWriter writer, Object value) {
|
public static void writeTo(PrintWriter writer, Object value) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapper.writeValue(writer, value);
|
mapper.writeValue(writer, value);
|
||||||
} catch (JsonGenerationException e) {
|
} catch (JsonGenerationException e) {
|
||||||
@ -72,6 +76,7 @@ public class JSONUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T readParams(String params, Class<T> clz) {
|
public static <T> T readParams(String params, Class<T> clz) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return mapper.readValue(params, clz);
|
return mapper.readValue(params, clz);
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
@ -85,6 +90,7 @@ public class JSONUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T readParams(String params, JavaType collectionType) {
|
public static <T> T readParams(String params, JavaType collectionType) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return mapper.readValue(params, collectionType);
|
return mapper.readValue(params, collectionType);
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
@ -99,10 +105,12 @@ public class JSONUtil {
|
|||||||
|
|
||||||
|
|
||||||
public static <T> T readValue(InputStream content, Class<T> type) throws Exception {
|
public static <T> T readValue(InputStream content, Class<T> type) throws Exception {
|
||||||
|
|
||||||
return mapper.readValue(content, type);
|
return mapper.readValue(content, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T readValue(String url, JavaType type) {
|
public static <T> T readValue(String url, JavaType type) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return mapper.readValue(new URL(url), type);
|
return mapper.readValue(new URL(url), type);
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
@ -125,10 +133,12 @@ public class JSONUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static <T> T copyProperties(Object src, Class<T> dest) throws Exception {
|
public static <T> T copyProperties(Object src, Class<T> dest) throws Exception {
|
||||||
|
|
||||||
return JSON.parseObject(JSON.toJSONString(src), dest);
|
return JSON.parseObject(JSON.toJSONString(src), dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T copyProperties(Object src, JavaType type) throws Exception {
|
public static <T> T copyProperties(Object src, JavaType type) throws Exception {
|
||||||
|
|
||||||
return JSON.parseObject(JSON.toJSONString(src), type);
|
return JSON.parseObject(JSON.toJSONString(src), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5,7 +5,9 @@ import com.ruoyi.common.core.utils.sign.Base64;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -38,6 +40,7 @@ public class Base64Utils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static byte[] decode(String base64) throws Exception {
|
public static byte[] decode(String base64) throws Exception {
|
||||||
|
|
||||||
return Base64.decode(base64);
|
return Base64.decode(base64);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +55,7 @@ public class Base64Utils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String encode(byte[] bytes) throws Exception {
|
public static String encode(byte[] bytes) throws Exception {
|
||||||
|
|
||||||
return new String(Base64.encode(bytes));
|
return new String(Base64.encode(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +73,7 @@ public class Base64Utils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String encodeFile(String filePath) throws Exception {
|
public static String encodeFile(String filePath) throws Exception {
|
||||||
|
|
||||||
byte[] bytes = fileToByte(filePath);
|
byte[] bytes = fileToByte(filePath);
|
||||||
return encode(bytes);
|
return encode(bytes);
|
||||||
}
|
}
|
||||||
@ -84,6 +89,7 @@ public class Base64Utils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void decodeToFile(String filePath, String base64) throws Exception {
|
public static void decodeToFile(String filePath, String base64) throws Exception {
|
||||||
|
|
||||||
byte[] bytes = decode(base64);
|
byte[] bytes = decode(base64);
|
||||||
byteArrayToFile(bytes, filePath);
|
byteArrayToFile(bytes, filePath);
|
||||||
}
|
}
|
||||||
@ -99,6 +105,7 @@ public class Base64Utils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static byte[] fileToByte(String filePath) throws Exception {
|
public static byte[] fileToByte(String filePath) throws Exception {
|
||||||
|
|
||||||
byte[] data = new byte[0];
|
byte[] data = new byte[0];
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -127,6 +134,7 @@ public class Base64Utils {
|
|||||||
* @param filePath 文件生成目录
|
* @param filePath 文件生成目录
|
||||||
*/
|
*/
|
||||||
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception {
|
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception {
|
||||||
|
|
||||||
InputStream in = new ByteArrayInputStream(bytes);
|
InputStream in = new ByteArrayInputStream(bytes);
|
||||||
File destFile = new File(filePath);
|
File destFile = new File(filePath);
|
||||||
if (!destFile.getParentFile().exists()) {
|
if (!destFile.getParentFile().exists()) {
|
||||||
@ -5,6 +5,7 @@ import java.util.Arrays;
|
|||||||
public class CRCCalculator {
|
public class CRCCalculator {
|
||||||
|
|
||||||
public static String ModbusCRC(byte[] pData) {
|
public static String ModbusCRC(byte[] pData) {
|
||||||
|
|
||||||
int crc = 0xFFFF;
|
int crc = 0xFFFF;
|
||||||
for (byte pDatum : pData) {
|
for (byte pDatum : pData) {
|
||||||
crc ^= (int) pDatum & 0xFF; // XOR byte into least sig. byte of crc
|
crc ^= (int) pDatum & 0xFF; // XOR byte into least sig. byte of crc
|
||||||
@ -22,11 +23,13 @@ public class CRCCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String calcCrc(byte[] data) {
|
public static String calcCrc(byte[] data) {
|
||||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length-2);
|
|
||||||
|
byte[] data2 = Arrays.copyOfRange(data, 2, data.length - 2);
|
||||||
return CRCCalculator.ModbusCRC(data2);
|
return CRCCalculator.ModbusCRC(data2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String calcCrc(String msg) {
|
public static String calcCrc(String msg) {
|
||||||
|
|
||||||
byte[] data = HexUtils.toBytes(msg);
|
byte[] data = HexUtils.toBytes(msg);
|
||||||
assert data != null;
|
assert data != null;
|
||||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length);
|
byte[] data2 = Arrays.copyOfRange(data, 2, data.length);
|
||||||
@ -34,6 +37,7 @@ public class CRCCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int byteArrayToInt(byte[] b) {
|
public static int byteArrayToInt(byte[] b) {
|
||||||
|
|
||||||
return b[3] & 0xFF |
|
return b[3] & 0xFF |
|
||||||
(b[2] & 0xFF) << 8 |
|
(b[2] & 0xFF) << 8 |
|
||||||
(b[1] & 0xFF) << 16 |
|
(b[1] & 0xFF) << 16 |
|
||||||
@ -41,6 +45,7 @@ public class CRCCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] intToByteArray(int a) {
|
public static byte[] intToByteArray(int a) {
|
||||||
|
|
||||||
return new byte[]{
|
return new byte[]{
|
||||||
(byte) ((a >> 24) & 0xFF),
|
(byte) ((a >> 24) & 0xFF),
|
||||||
(byte) ((a >> 16) & 0xFF),
|
(byte) ((a >> 16) & 0xFF),
|
||||||
@ -17,23 +17,26 @@ public class MD5 {
|
|||||||
* @return 签名结果
|
* @return 签名结果
|
||||||
*/
|
*/
|
||||||
public static String sign(String text, String key, String input_charset) {
|
public static String sign(String text, String key, String input_charset) {
|
||||||
|
|
||||||
text = text + key;
|
text = text + key;
|
||||||
return DigestUtils.md5Hex(getContentBytes(text, input_charset));
|
return DigestUtils.md5Hex(getContentBytes(text, input_charset));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sign(String text, String key) {
|
public static String sign(String text, String key) {
|
||||||
|
|
||||||
return sign(text, key, "utf-8").toUpperCase();
|
return sign(text, key, "utf-8").toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签名字符串
|
* 签名字符串
|
||||||
*
|
*
|
||||||
* @param text 需要签名的字符串
|
* @param text 需要签名的字符串
|
||||||
* @param sign 签名结果
|
* @param sign 签名结果
|
||||||
* @param key 密钥
|
* @param key 密钥
|
||||||
* @return 签名结果
|
* @return 签名结果
|
||||||
*/
|
*/
|
||||||
public static boolean verify(String text, String sign, String key) {
|
public static boolean verify(String text, String sign, String key) {
|
||||||
|
|
||||||
text = text + key;
|
text = text + key;
|
||||||
String mysign = DigestUtils.md5Hex(getContentBytes(text, "UTF-8"));
|
String mysign = DigestUtils.md5Hex(getContentBytes(text, "UTF-8"));
|
||||||
if (mysign.equals(sign)) {
|
if (mysign.equals(sign)) {
|
||||||
@ -51,6 +54,7 @@ public class MD5 {
|
|||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
*/
|
*/
|
||||||
private static byte[] getContentBytes(String content, String charset) {
|
private static byte[] getContentBytes(String content, String charset) {
|
||||||
|
|
||||||
if (charset == null || "".equals(charset)) {
|
if (charset == null || "".equals(charset)) {
|
||||||
return content.getBytes();
|
return content.getBytes();
|
||||||
}
|
}
|
||||||
@ -10,7 +10,7 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: xhpc-power-pole
|
name: xhpc-power-pile
|
||||||
profiles:
|
profiles:
|
||||||
# 环境配置
|
# 环境配置
|
||||||
active: dev
|
active: dev
|
||||||
74
xhpc-modules/xhpc-power-pile/src/main/resources/logback.xml
Normal file
74
xhpc-modules/xhpc-power-pile/src/main/resources/logback.xml
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/xphc-power-pile"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.xhpc" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
@ -11,5 +11,6 @@
|
|||||||
<entry key="01" value-ref="RegisterLogic"/>
|
<entry key="01" value-ref="RegisterLogic"/>
|
||||||
<entry key="03" value-ref="HBLogic"/>
|
<entry key="03" value-ref="HBLogic"/>
|
||||||
<entry key="05" value-ref="RateModelValidateLogic"/>
|
<entry key="05" value-ref="RateModelValidateLogic"/>
|
||||||
|
<entry key="09" value-ref="RateModelRequestLogic"/>
|
||||||
</util:map>
|
</util:map>
|
||||||
</beans>
|
</beans>
|
||||||
@ -1,74 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/xphc-power-pole" />
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.xhpc" level="info" />
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn" />
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console" />
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info" />
|
|
||||||
<appender-ref ref="file_error" />
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user