命名重构
This commit is contained in:
parent
a58670c1bc
commit
ffb25ec8a5
@ -9,7 +9,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<modules>
|
||||
<module>xhpc-power-pole</module>
|
||||
<module>xhpc-power-pile</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>xhpc-modules</artifactId>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>xhpc-power-pole</artifactId>
|
||||
<artifactId>xhpc-power-pile</artifactId>
|
||||
|
||||
<description>
|
||||
充电桩服务
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
@ -21,8 +21,8 @@ public class TestController {
|
||||
String serverAddr = serverIp + ":" + serverPort;
|
||||
|
||||
NamingService namingService = NacosFactory.createNamingService(serverAddr);
|
||||
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pole");
|
||||
// todo clean dead host pole cache
|
||||
List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pile");
|
||||
// todo clean dead host pile cache
|
||||
String ipAndPort = GetIpAndPort.getIpAndPort();
|
||||
return ipAndPort;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.xhpc.pp.domain;
|
||||
|
||||
public class ServiceField {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String serviceName;
|
||||
@ -18,66 +19,82 @@ public class ServiceField {
|
||||
private String dataType;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getLen() {
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
public void setLen(Integer len) {
|
||||
|
||||
this.len = len;
|
||||
}
|
||||
|
||||
public Integer getSeq() {
|
||||
|
||||
return seq;
|
||||
}
|
||||
|
||||
public void setSeq(Integer seq) {
|
||||
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
@ -20,4 +20,5 @@ public interface ServiceFieldMapper {
|
||||
int updateByPrimaryKey(ServiceField record);
|
||||
|
||||
List<Map<String, Object>> querySQL(Map<String, String> query);
|
||||
|
||||
}
|
||||
@ -50,8 +50,8 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
||||
List<byte[]> dataList = parseDataList(data);
|
||||
for (byte[] d : dataList) {
|
||||
String dataStr = HexUtils.toHex(d);
|
||||
String poleNo = ChargingPileServer.getPoleNo(handler);
|
||||
log.info("received data <<<< {}, from pole <<<< {}", dataStr, poleNo);
|
||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||
log.info("received data <<<< {}, from pile <<<< {}", dataStr, pileNo);
|
||||
if (d.length <= 2 || !dataStr.startsWith("68")) {
|
||||
log.info("received invalid data <<<< {}, len[{}]", dataStr, d.length);
|
||||
continue;
|
||||
@ -78,32 +78,32 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
||||
String serviceName = HexUtils.toHex(data, 5, 6);
|
||||
String version = ChargingPileServer.getVersion(handler.getName());
|
||||
Map<String, Object> req = analysis(data, serviceName, version);
|
||||
String poleNo = (String) req.get("poleNo");
|
||||
ServiceParameter sp = new ServiceParameter(serviceName, poleNo, req);
|
||||
String pileNo = (String) req.get("pileNo");
|
||||
ServiceParameter sp = new ServiceParameter(serviceName, pileNo, req);
|
||||
ServiceResult result = servicemainLogic.process(sp);
|
||||
String resultCode = result.getCode();
|
||||
if (SERVICE_REGISTER.equals(serviceName) && OK.equals(resultCode)) {
|
||||
reg(handler, poleNo, req);
|
||||
reg(handler, pileNo, req);
|
||||
} /*else if (SERVICE_HB.equals(serviceName)) {
|
||||
|
||||
}*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
Map<String, Object> poleCache = REDIS.getCacheMap(poleNo);
|
||||
poleCache.put("Status", REGISTERED);
|
||||
poleCache.put("Server", getLocalIPAndPort());
|
||||
REDIS.setCacheMap(poleNo, poleCache);
|
||||
Set<String> polesAtHost = REDIS.getCacheSet(getLocalIP());
|
||||
polesAtHost.add(poleNo);
|
||||
log.info("pole registered >>>> [{}] ", poleNo);
|
||||
Map<String, Object> pileCache = REDIS.getCacheMap(pileNo);
|
||||
pileCache.put("Status", REGISTERED);
|
||||
pileCache.put("Server", getLocalIPAndPort());
|
||||
REDIS.setCacheMap(pileNo, pileCache);
|
||||
Set<String> pilesAtHost = REDIS.getCacheSet(getLocalIP());
|
||||
pilesAtHost.add(pileNo);
|
||||
log.info("pile registered >>>> [{}] ", pileNo);
|
||||
}
|
||||
|
||||
private List<byte[]> parseDataList(byte[] data) {
|
||||
@ -15,10 +15,12 @@ public class ChargingPileCommandHandler implements ClientCommandHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(ChargingPileCommandHandler.class);
|
||||
|
||||
public ChargingPileCommandHandler() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(ClientHandler handler, String appData) throws SocketTimeoutException, IOException {
|
||||
|
||||
log.info("handleCommand <====" + appData);
|
||||
|
||||
}
|
||||
@ -26,11 +26,11 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
||||
@Override
|
||||
public void lostConnection(ClientHandler handler) {
|
||||
|
||||
String poleNo = ChargingPileServer.getPoleNo(handler);
|
||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||
log.info("lost connection -> [{}] {} <- {}",
|
||||
poleNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
if (poleNo != null) {
|
||||
ChargingPileServer.removeHandler(poleNo);
|
||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
if (pileNo != null) {
|
||||
ChargingPileServer.removeHandler(pileNo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class ChargingPileServer {
|
||||
private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class);
|
||||
private static Map<String, ClientHandler> handlerMap = 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;
|
||||
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);
|
||||
poleMap.put(handler.getName(), poleNo);
|
||||
handlerMap.put(pileNo, handler);
|
||||
pileMap.put(handler.getName(), pileNo);
|
||||
}
|
||||
|
||||
public static void removeHandler(String poleNo) {
|
||||
public static void removeHandler(String pileNo) {
|
||||
|
||||
ClientHandler handler = handlerMap.remove(poleNo);
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap(poleNo);
|
||||
ClientHandler handler = handlerMap.remove(pileNo);
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap(pileNo);
|
||||
cacheMap.put("Status", DISCONNECTED);
|
||||
REDIS.setCacheMap(poleNo, cacheMap);
|
||||
REDIS.setCacheMap(pileNo, cacheMap);
|
||||
if (handler != null) {
|
||||
log.info("remove handler [{}] for [{}]", handler.getName(), poleNo);
|
||||
poleMap.remove(handler.getName());
|
||||
log.info("remove handler [{}] for [{}]", handler.getName(), pileNo);
|
||||
pileMap.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")) {
|
||||
log.info("server send msg >>>> [{}] |{}|", poleNo, HexUtils.toHex(msg));
|
||||
log.info("server send msg >>>> [{}] |{}|", pileNo, HexUtils.toHex(msg));
|
||||
}
|
||||
if (poleNo.length() < 16) {
|
||||
poleNo = "0000000000000000" + poleNo;
|
||||
poleNo = poleNo.substring(poleNo.length() - 16);
|
||||
if (pileNo.length() < 16) {
|
||||
pileNo = "0000000000000000" + pileNo;
|
||||
pileNo = pileNo.substring(pileNo.length() - 16);
|
||||
}
|
||||
ClientHandler handler = handlerMap.get(poleNo);
|
||||
ClientHandler handler = handlerMap.get(pileNo);
|
||||
if (handler == null || !handler.isOpen()) {
|
||||
log.error("send message failed. [{}] connection lost", poleNo);
|
||||
removeHandler(poleNo);
|
||||
log.error("send message failed. [{}] connection lost", pileNo);
|
||||
removeHandler(pileNo);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@ -141,14 +141,14 @@ public class ChargingPileServer {
|
||||
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() {
|
||||
@ -24,19 +24,19 @@ public class HBLogic implements ServiceLogic {
|
||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||
|
||||
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 gunStatus = (String) req.get("gunStatus");
|
||||
int gunStatusInt = 0;
|
||||
if (ServiceResult.HEX_FAIL.equals(gunStatus))
|
||||
gunStatusInt = 1;
|
||||
String gunKey = poleNo.concat(gunId);
|
||||
String gunKey = pileNo.concat(gunId);
|
||||
Map<String, Integer> cacheGun = REDIS.getCacheMap(gunKey);
|
||||
int cacheGunStatus = cacheGun.get(gunKey);
|
||||
if ((1 == cacheGunStatus && 0 == gunStatusInt) || (0 == cacheGunStatus && 1 == 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));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
@ -24,17 +24,17 @@ public class RateModelValidateLogic implements ServiceLogic {
|
||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||
|
||||
Map<String, Object> req = sp.getParameters();
|
||||
String poleNo = (String) req.get("poleNo");
|
||||
String pileNo = (String) req.get("pileNo");
|
||||
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 hexCode = ServiceResult.HEX_OK;
|
||||
Integer rateModelIdCache = cachePole.get("rateModelId");
|
||||
Integer rateModelIdCache = cachePile.get("rateModelId");
|
||||
if (Integer.parseInt(rateModelId) != rateModelIdCache) {
|
||||
hexCode = ServiceResult.HEX_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));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||
}
|
||||
@ -29,15 +29,16 @@ public class RegisterLogic implements ServiceLogic {
|
||||
Map<String, Object> req = sp.getParameters();
|
||||
String resultCode = ServiceResult.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");
|
||||
//todo set rate model to cache
|
||||
if (!pileSnPool.contains(poleNo)) {
|
||||
if (!pileSnPool.contains(pileNo)) {
|
||||
hexCode = ServiceResult.HEX_FAIL;
|
||||
resultCode = ServiceResult.FAIL;
|
||||
}
|
||||
String resultStr = "680C00000002".concat(poleNo).concat(hexCode);
|
||||
String resultStr = "680C00000002".concat(pileNo).concat(hexCode);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||
}
|
||||
|
||||
}
|
||||
@ -13,6 +13,7 @@ import java.util.Map;
|
||||
|
||||
@Component("ServiceMainLogic")
|
||||
public class ServiceMainLogic {
|
||||
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
// 结构:Map<serviceType,ServiceCommandLogic>
|
||||
@ -16,7 +16,7 @@ import java.util.Map;
|
||||
@RequestMapping
|
||||
public class ServiceController {
|
||||
|
||||
private static final String SESSIONID = "poleNo";
|
||||
private static final String SESSIONID = "pileNo";
|
||||
private static final String SERVICE_NAME = "serviceName";
|
||||
|
||||
@Autowired
|
||||
@ -25,10 +25,11 @@ public class ServiceController {
|
||||
@RequestMapping(value = "/api")
|
||||
@ResponseBody
|
||||
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);
|
||||
|
||||
ServiceParameter serviceParameter = new ServiceParameter(serviceName, poleNo, req);
|
||||
ServiceParameter serviceParameter = new ServiceParameter(serviceName, pileNo, req);
|
||||
ServiceResult result = servicemainLogic.process(serviceParameter);
|
||||
|
||||
if (result.getJson() != null) {
|
||||
@ -9,48 +9,57 @@ public class ServiceParameter implements Serializable {
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private String poleNo;
|
||||
private String pileNo;
|
||||
|
||||
private String version;
|
||||
|
||||
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.parameters = parameters;
|
||||
this.poleNo = poleNo;
|
||||
this.pileNo = pileNo;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParameters() {
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map<String, Object> parameters) {
|
||||
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getPoleNo() {
|
||||
return poleNo;
|
||||
public String getPileNo() {
|
||||
|
||||
return pileNo;
|
||||
}
|
||||
|
||||
public void setPoleNo(String poleNo) {
|
||||
this.poleNo = poleNo;
|
||||
public void setPileNo(String pileNo) {
|
||||
|
||||
this.pileNo = pileNo;
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,10 +27,12 @@ public class ServiceResult {
|
||||
}
|
||||
|
||||
public ServiceResult(Map<String, String> json) {
|
||||
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public ServiceResult(Object json) {
|
||||
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@ -47,22 +49,28 @@ public class ServiceResult {
|
||||
}
|
||||
|
||||
public Object getJson() {
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public void setJson(Map<String, Object> json) {
|
||||
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public byte[] getBinary() {
|
||||
|
||||
return binary;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.xhpc.pp.tx;
|
||||
|
||||
public class TxException extends Exception {
|
||||
|
||||
/**
|
||||
* 缺少参数
|
||||
*/
|
||||
@ -18,16 +19,19 @@ public class TxException extends Exception {
|
||||
private String returnCode;
|
||||
|
||||
public TxException(String rtnCode, Throwable reason) {
|
||||
|
||||
super(rtnCode, reason);
|
||||
this.returnCode = rtnCode;
|
||||
}
|
||||
|
||||
public TxException(String rtnCode, String msg) {
|
||||
|
||||
super(msg);
|
||||
this.returnCode = rtnCode;
|
||||
}
|
||||
|
||||
public TxException(String rtnCode) {
|
||||
|
||||
this.returnCode = rtnCode;
|
||||
}
|
||||
|
||||
@ -40,6 +44,7 @@ public class TxException extends Exception {
|
||||
* 参数错误
|
||||
*/
|
||||
public static TxException PARAMETER_INVALID(String error) {
|
||||
|
||||
return new TxException("1101", error);
|
||||
}
|
||||
|
||||
@ -47,10 +52,12 @@ public class TxException extends Exception {
|
||||
* 内部错误
|
||||
*/
|
||||
public static TxException INNER_ERROR(String msg) {
|
||||
|
||||
return new TxException("1111", msg);
|
||||
}
|
||||
|
||||
public String getReturnCode() {
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@ import java.io.IOException;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileUploadUtils
|
||||
{
|
||||
public class FileUploadUtils {
|
||||
|
||||
/**
|
||||
* 默认大小 50M
|
||||
*/
|
||||
@ -34,18 +34,15 @@ public class FileUploadUtils
|
||||
* 根据文件路径上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param file 上传的文件
|
||||
* @return 文件名称
|
||||
* @throws IOException
|
||||
*/
|
||||
public static final String upload(String baseDir, MultipartFile file) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
public static final String upload(String baseDir, MultipartFile file) throws IOException {
|
||||
|
||||
try {
|
||||
return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
@ -53,22 +50,21 @@ public class FileUploadUtils
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param baseDir 相对应用的基目录
|
||||
* @param file 上传的文件
|
||||
* @param allowedExtension 上传文件类型
|
||||
* @return 返回上传成功的文件名
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||
* @throws IOException 比如读写文件出错时
|
||||
* @throws InvalidExtensionException 文件校验异常
|
||||
* @throws IOException 比如读写文件出错时
|
||||
* @throws InvalidExtensionException 文件校验异常
|
||||
*/
|
||||
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
|
||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||
InvalidExtensionException
|
||||
{
|
||||
InvalidExtensionException {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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 extension = getExtension(file);
|
||||
fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
|
||||
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);
|
||||
|
||||
if (!desc.exists())
|
||||
{
|
||||
if (!desc.getParentFile().exists())
|
||||
{
|
||||
if (!desc.exists()) {
|
||||
if (!desc.getParentFile().exists()) {
|
||||
desc.getParentFile().mkdirs();
|
||||
}
|
||||
}
|
||||
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;
|
||||
return pathFileName;
|
||||
}
|
||||
@ -118,43 +112,32 @@ public class FileUploadUtils
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||
* @throws InvalidExtensionException 文件校验异常
|
||||
* @throws InvalidExtensionException 文件校验异常
|
||||
*/
|
||||
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
|
||||
throws FileSizeLimitExceededException, InvalidExtensionException
|
||||
{
|
||||
throws FileSizeLimitExceededException, InvalidExtensionException {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
String extension = getExtension(file);
|
||||
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
|
||||
{
|
||||
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
|
||||
{
|
||||
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
|
||||
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) {
|
||||
throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
|
||||
fileName);
|
||||
}
|
||||
else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
|
||||
{
|
||||
} else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION) {
|
||||
throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
|
||||
fileName);
|
||||
}
|
||||
else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
|
||||
{
|
||||
} else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION) {
|
||||
throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
|
||||
fileName);
|
||||
}
|
||||
else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION)
|
||||
{
|
||||
} else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION) {
|
||||
throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
|
||||
fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
||||
}
|
||||
}
|
||||
@ -163,16 +146,14 @@ public class FileUploadUtils
|
||||
/**
|
||||
* 判断MIME类型是否是允许的MIME类型
|
||||
*
|
||||
* @param extension 上传文件类型
|
||||
* @param extension 上传文件类型
|
||||
* @param allowedExtension 允许上传文件类型
|
||||
* @return true/false
|
||||
*/
|
||||
public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
|
||||
{
|
||||
for (String str : allowedExtension)
|
||||
{
|
||||
if (str.equalsIgnoreCase(extension))
|
||||
{
|
||||
public static final boolean isAllowedExtension(String extension, String[] allowedExtension) {
|
||||
|
||||
for (String str : allowedExtension) {
|
||||
if (str.equalsIgnoreCase(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -185,13 +166,13 @@ public class FileUploadUtils
|
||||
* @param file 表单文件
|
||||
* @return 后缀名
|
||||
*/
|
||||
public static final String getExtension(MultipartFile file)
|
||||
{
|
||||
public static final String getExtension(MultipartFile file) {
|
||||
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
if (StringUtils.isEmpty(extension))
|
||||
{
|
||||
if (StringUtils.isEmpty(extension)) {
|
||||
extension = MimeTypeUtils.getExtension(file.getContentType());
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,6 +24,7 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
public static <T> T readValue(String url, Class<T> clz) {
|
||||
|
||||
try {
|
||||
URL u = new URL(url);
|
||||
return mapper.readValue(u, clz);
|
||||
@ -39,6 +40,7 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
public static <T> T readValue(String url, String params, Class<T> clz) {
|
||||
|
||||
try {
|
||||
String param = "?params=" + params;
|
||||
URL u = new URL(url + param);
|
||||
@ -55,10 +57,12 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
|
||||
|
||||
return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
|
||||
}
|
||||
|
||||
public static void writeTo(PrintWriter writer, Object value) {
|
||||
|
||||
try {
|
||||
mapper.writeValue(writer, value);
|
||||
} catch (JsonGenerationException e) {
|
||||
@ -72,6 +76,7 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
public static <T> T readParams(String params, Class<T> clz) {
|
||||
|
||||
try {
|
||||
return mapper.readValue(params, clz);
|
||||
} catch (JsonParseException e) {
|
||||
@ -85,6 +90,7 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
public static <T> T readParams(String params, JavaType collectionType) {
|
||||
|
||||
try {
|
||||
return mapper.readValue(params, collectionType);
|
||||
} catch (JsonParseException e) {
|
||||
@ -99,10 +105,12 @@ public class JSONUtil {
|
||||
|
||||
|
||||
public static <T> T readValue(InputStream content, Class<T> type) throws Exception {
|
||||
|
||||
return mapper.readValue(content, type);
|
||||
}
|
||||
|
||||
public static <T> T readValue(String url, JavaType type) {
|
||||
|
||||
try {
|
||||
return mapper.readValue(new URL(url), type);
|
||||
} catch (JsonParseException e) {
|
||||
@ -125,10 +133,12 @@ public class JSONUtil {
|
||||
* @return
|
||||
*/
|
||||
public static <T> T copyProperties(Object src, Class<T> dest) throws Exception {
|
||||
|
||||
return JSON.parseObject(JSON.toJSONString(src), dest);
|
||||
}
|
||||
|
||||
public static <T> T copyProperties(Object src, JavaType type) throws Exception {
|
||||
|
||||
return JSON.parseObject(JSON.toJSONString(src), type);
|
||||
}
|
||||
|
||||
@ -5,7 +5,9 @@ import com.ruoyi.common.core.utils.sign.Base64;
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/** */
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -38,6 +40,7 @@ public class Base64Utils {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decode(String base64) throws Exception {
|
||||
|
||||
return Base64.decode(base64);
|
||||
}
|
||||
|
||||
@ -52,6 +55,7 @@ public class Base64Utils {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encode(byte[] bytes) throws Exception {
|
||||
|
||||
return new String(Base64.encode(bytes));
|
||||
}
|
||||
|
||||
@ -69,6 +73,7 @@ public class Base64Utils {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encodeFile(String filePath) throws Exception {
|
||||
|
||||
byte[] bytes = fileToByte(filePath);
|
||||
return encode(bytes);
|
||||
}
|
||||
@ -84,6 +89,7 @@ public class Base64Utils {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void decodeToFile(String filePath, String base64) throws Exception {
|
||||
|
||||
byte[] bytes = decode(base64);
|
||||
byteArrayToFile(bytes, filePath);
|
||||
}
|
||||
@ -99,6 +105,7 @@ public class Base64Utils {
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] fileToByte(String filePath) throws Exception {
|
||||
|
||||
byte[] data = new byte[0];
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
@ -127,6 +134,7 @@ public class Base64Utils {
|
||||
* @param filePath 文件生成目录
|
||||
*/
|
||||
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception {
|
||||
|
||||
InputStream in = new ByteArrayInputStream(bytes);
|
||||
File destFile = new File(filePath);
|
||||
if (!destFile.getParentFile().exists()) {
|
||||
@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
public class CRCCalculator {
|
||||
|
||||
public static String ModbusCRC(byte[] pData) {
|
||||
|
||||
int crc = 0xFFFF;
|
||||
for (byte pDatum : pData) {
|
||||
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) {
|
||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length-2);
|
||||
|
||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length - 2);
|
||||
return CRCCalculator.ModbusCRC(data2);
|
||||
}
|
||||
|
||||
public static String calcCrc(String msg) {
|
||||
|
||||
byte[] data = HexUtils.toBytes(msg);
|
||||
assert data != null;
|
||||
byte[] data2 = Arrays.copyOfRange(data, 2, data.length);
|
||||
@ -34,6 +37,7 @@ public class CRCCalculator {
|
||||
}
|
||||
|
||||
public static int byteArrayToInt(byte[] b) {
|
||||
|
||||
return b[3] & 0xFF |
|
||||
(b[2] & 0xFF) << 8 |
|
||||
(b[1] & 0xFF) << 16 |
|
||||
@ -41,6 +45,7 @@ public class CRCCalculator {
|
||||
}
|
||||
|
||||
public static byte[] intToByteArray(int a) {
|
||||
|
||||
return new byte[]{
|
||||
(byte) ((a >> 24) & 0xFF),
|
||||
(byte) ((a >> 16) & 0xFF),
|
||||
@ -17,23 +17,26 @@ public class MD5 {
|
||||
* @return 签名结果
|
||||
*/
|
||||
public static String sign(String text, String key, String input_charset) {
|
||||
|
||||
text = text + key;
|
||||
return DigestUtils.md5Hex(getContentBytes(text, input_charset));
|
||||
}
|
||||
|
||||
public static String sign(String text, String key) {
|
||||
|
||||
return sign(text, key, "utf-8").toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名字符串
|
||||
*
|
||||
* @param text 需要签名的字符串
|
||||
* @param sign 签名结果
|
||||
* @param key 密钥
|
||||
* @param text 需要签名的字符串
|
||||
* @param sign 签名结果
|
||||
* @param key 密钥
|
||||
* @return 签名结果
|
||||
*/
|
||||
public static boolean verify(String text, String sign, String key) {
|
||||
|
||||
text = text + key;
|
||||
String mysign = DigestUtils.md5Hex(getContentBytes(text, "UTF-8"));
|
||||
if (mysign.equals(sign)) {
|
||||
@ -51,6 +54,7 @@ public class MD5 {
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private static byte[] getContentBytes(String content, String charset) {
|
||||
|
||||
if (charset == null || "".equals(charset)) {
|
||||
return content.getBytes();
|
||||
}
|
||||
@ -10,7 +10,7 @@ server:
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: xhpc-power-pole
|
||||
name: xhpc-power-pile
|
||||
profiles:
|
||||
# 环境配置
|
||||
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="03" value-ref="HBLogic"/>
|
||||
<entry key="05" value-ref="RateModelValidateLogic"/>
|
||||
<entry key="09" value-ref="RateModelRequestLogic"/>
|
||||
</util:map>
|
||||
</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