|
@@ -1,20 +1,114 @@
|
|
|
package com.nokia;
|
|
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
+import com.nokia.dao.RoleDao;
|
|
|
+import com.nokia.vo.TokenFlagVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.csv.CSVFormat;
|
|
|
+import org.apache.commons.csv.CSVParser;
|
|
|
+import org.apache.commons.csv.CSVPrinter;
|
|
|
+import org.apache.commons.csv.CSVRecord;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.test.context.ActiveProfiles;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@ActiveProfiles("test")
|
|
|
@SpringBootTest
|
|
|
-public class OtherTest {
|
|
|
+class OtherTest {
|
|
|
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+ @Autowired
|
|
|
+ private RoleDao roleDao;
|
|
|
|
|
|
@Test
|
|
|
- void test() {
|
|
|
+ void testSplitAddress() {
|
|
|
+ String inputPath = "test/org1.csv";
|
|
|
+ String outputFilePath = "test/org2.csv";
|
|
|
+ try (CSVParser parser = CSVFormat.DEFAULT.builder().build()
|
|
|
+ .parse(new InputStreamReader(Files.newInputStream(Paths.get(inputPath)), StandardCharsets.UTF_8));
|
|
|
+ OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(Paths.get(outputFilePath)),
|
|
|
+ StandardCharsets.UTF_8);
|
|
|
+ CSVPrinter printer = new CSVPrinter(osw, CSVFormat.DEFAULT)) {
|
|
|
+ printer.printRecord("org_id", "org_name", "province", "city", "district");
|
|
|
+ for (CSVRecord t : parser) {
|
|
|
+ String orgId = t.get(0);
|
|
|
+ String address = t.get(1);
|
|
|
+ log.info("{}: {}", t.getRecordNumber(), address);
|
|
|
+ Map<String, String> map = splitAddress(address);
|
|
|
+ printer.printRecord(orgId, address, "河北省", map.get("city"), map.get("county"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> splitAddress(String s) {
|
|
|
+ Pattern pattern = Pattern.compile("(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县|.*?新区)(?<county>[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?<town>[^区]+区|.+镇)?(?<village>.*)");
|
|
|
+
|
|
|
+ Matcher m = pattern.matcher(s);
|
|
|
+ Map<String, String> map = new LinkedHashMap<>();
|
|
|
+ while (m.find()) {
|
|
|
+
|
|
|
+
|
|
|
+ String city = m.group("city");
|
|
|
+ map.put("city", city == null ? "" : city.trim());
|
|
|
+ String county = m.group("county");
|
|
|
+ map.put("county", county == null ? "" : county.trim());
|
|
|
+ String town = m.group("town");
|
|
|
+ map.put("town", town == null ? "" : town.trim());
|
|
|
+ String village = m.group("village");
|
|
|
+ map.put("village", village == null ? "" : village.trim());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testRedis() {
|
|
|
Object object = redisTemplate.opsForValue().get("abc");
|
|
|
System.out.println(object);
|
|
|
System.out.println("done!");
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testWoyunwei() {
|
|
|
+ String token = "a";
|
|
|
+
|
|
|
+ String woyunweiUrl = "http://192.168.70.130:13000/PAOOS/aaaa/userservice/getUserInfo.do?method=findUserBySessionID&sessionID=";
|
|
|
+ String url = woyunweiUrl + token;
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ String r = restTemplate.postForObject(url, new HashMap<>(), String.class);
|
|
|
+ log.info("沃运维获取用户信息响应: {}", r);
|
|
|
+ if (!StringUtils.hasText(r)) {
|
|
|
+ TokenFlagVo vo = new TokenFlagVo();
|
|
|
+ vo.setIsValid(1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JsonObject jsonObject = JsonParser.parseString(r).getAsJsonObject();
|
|
|
+ String userName = jsonObject.get("userName").getAsString();
|
|
|
+ TokenFlagVo vo = new TokenFlagVo();
|
|
|
+ vo.setIsValid(StringUtils.hasText(userName) ? 0 : 1);
|
|
|
+ vo.setLoginName(userName);
|
|
|
+ log.info("vo: {}", vo);
|
|
|
+ }
|
|
|
}
|