Commit 60798c9e authored by 李德才's avatar 李德才

去除SN码存入redis中的操作,由各子系统校验成功后存入

parent 573f90f3
...@@ -21,11 +21,7 @@ public class SnController extends Controller { ...@@ -21,11 +21,7 @@ public class SnController extends Controller {
public void getPropertiesValue() { public void getPropertiesValue() {
String cupCode = getPara("cupCode"); String cupCode = getPara("cupCode");
try { try {
String snCode = snService.getPropertiesValue(cupCode); renderJson(Ret.ok("snCode", snService.getPropertiesValue(cupCode)));
if (StrKit.isBlank(snCode)) {
snService.setProperty(cupCode, "");
}
renderJson(Ret.ok("snCode", snCode));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
renderJson(Ret.fail()); renderJson(Ret.fail());
......
...@@ -25,19 +25,15 @@ public class SnService { ...@@ -25,19 +25,15 @@ public class SnService {
/** /**
* 从 Properties 文件中获取指定对应的值 * 从 Properties 文件中获取指定对应的值
* *
* @param cupCode * @param cpuCode
* @return * @return
*/ */
public String getPropertiesValue(String cupCode) { public String getPropertiesValue(String cpuCode) {
Object redisSnCode = Redis.use().get(PREFIX + cupCode); Object redisSnCode = Redis.use().get(PREFIX + cpuCode);
if (redisSnCode != null) { if (redisSnCode != null) {
return redisSnCode.toString(); return redisSnCode.toString();
} }
String fileSnCode = PropertyUtil.getProperty(cupCode, FILE_PATH); return PropKit.use(new File(FILE_PATH)).get(cpuCode);
if (StrKit.notBlank(fileSnCode)) {
saveSnToRedis(PREFIX + cupCode, fileSnCode);
}
return fileSnCode;
} }
......
package com.archser.aserver.util; package com.archser.aserver.util;
import java.io.BufferedReader;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
...@@ -17,6 +21,30 @@ import java.util.Properties; ...@@ -17,6 +21,30 @@ import java.util.Properties;
public class PropertyUtil { public class PropertyUtil {
public static Properties loadResource(String propFile) throws IOException {
Properties properties = new Properties();
InputStreamReader reader = new InputStreamReader(
PropertyUtil.class.getResourceAsStream(propFile));
properties.load(reader);
return properties;
}
public static String get(String filePath, String key) {
Properties prop = null;
try {
prop = loadResource(filePath);
} catch (IOException e) {
e.printStackTrace();
}
String title = null;
try {
assert prop != null;
title = new String(prop.getOrDefault(key, null).toString().getBytes(), "UTF-8");
} catch (UnsupportedEncodingException ignored) {
}
return title;
}
/** /**
* 读取配置文件中的值 * 读取配置文件中的值
* *
...@@ -29,8 +57,9 @@ public class PropertyUtil { ...@@ -29,8 +57,9 @@ public class PropertyUtil {
InputStream input = null; InputStream input = null;
try { try {
input = new FileInputStream(filePath); input = new FileInputStream(filePath);
props.load(input); BufferedReader bf = new BufferedReader(new InputStreamReader(input));
value = props.getProperty(key); props.load(bf);
value = new String(props.getProperty(key).getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -46,6 +75,7 @@ public class PropertyUtil { ...@@ -46,6 +75,7 @@ public class PropertyUtil {
/** /**
* 向配置文件中写值 * 向配置文件中写值
*
* @param key * @param key
* @param value * @param value
* @param filePath * @param filePath
......
#Tue Dec 01 16:30:09 CST 2020 cfc84f0ff5395302517acc5ded7e7101f415cb953d535833296b292fa0f9c5ae=huayiwendang,04c5c8a0db17ff09e046e64099dbe532fc2c79e0f8898a4351234d96049055964448a10b4d1459e598532c33069a1b1293d2d6aeb66ca28448a622a364fdeec28e781180b7cbf8738b654860ac18dd2592d055ee3d1a1104b747c7f43070ae0e1102287bd0a6f84113a629e4eb9a4f5f7c4628c691416ab536201bccfd8f5d3fe44e7bb737760dd21edff98347200a0d258b5097fc252b3c41401f2bb26683f2aa56e220c85fb83ae653e1a26a11adf14564383578e7d202d9c83f7130b4c912e8295f8c9fa93deb20dbbe18e1fcc2cbd7e281d5acfe5b01ad61477542c335012b8753a27a52f164990743194b1314885a
AAAAAAAAAAAAAAA=cdcdscdscsdcdc \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment