提交修改

This commit is contained in:
quyixiao 2025-03-13 13:31:23 +08:00
parent 3dccd71916
commit b6f4973617
9 changed files with 673 additions and 77 deletions

View File

@ -5,7 +5,7 @@ package com.heyu.api.data.dao.api;
* </p>
*
* @author quyixiao
* @since 2025-03-11
* @since 2025-03-12
*/
import com.heyu.api.data.entity.api.ApiPostCodeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

View File

@ -10,7 +10,7 @@ import java.util.Date;import java.util.Date;
/**
*结果表
* @author quyixiao
* @since 2025-03-11
* @since 2025-03-12
*/
@Data
@ -37,6 +37,7 @@ private static final long serialVersionUID = 1L;
public final static String param10_ = CLASS_NAME + "param10"; //
public final static String param11_ = CLASS_NAME + "param11"; //
public final static String param12_ = CLASS_NAME + "param12"; //
public final static String md5_unique = CLASS_NAME + "md5_unique"; //
//
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ -70,6 +71,8 @@ private static final long serialVersionUID = 1L;
private String param11;
//
private String param12;
//
private String md5Unique;
/**
*
* @return
@ -310,6 +313,21 @@ private static final long serialVersionUID = 1L;
this.param12 = param12;
}
/**
*
* @return
*/
public String getMd5Unique() {
return md5Unique;
}
/**
*
* @param md5Unique
*/
public void setMd5Unique(String md5Unique) {
this.md5Unique = md5Unique;
}
@Override
public String toString() {
return "ApiPostCodeEntity{" +
@ -329,6 +347,7 @@ private static final long serialVersionUID = 1L;
",param10=" + param10 +
",param11=" + param11 +
",param12=" + param12 +
",md5Unique=" + md5Unique +
"}";
}
}

View File

@ -5,7 +5,7 @@ package com.heyu.api.data.service.api;
* </p>
*
* @author quyixiao
* @since 2025-03-11
* @since 2025-03-12
*/
import com.baomidou.mybatisplus.extension.service.IService;
import com.heyu.api.data.entity.api.ApiPostCodeEntity;

View File

@ -5,7 +5,7 @@ package com.heyu.api.data.service.impl.api;
* </p>
*
* @author quyixiao
* @since 2025-03-11
* @since 2025-03-12
*/
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

View File

@ -0,0 +1,472 @@
package com.heyu.api.data.utils;
import lombok.extern.slf4j.Slf4j;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/************************************************
* MD5 算法的Java Bean
*************************************************/
@Slf4j
public class MD5Utils {
/*
* 下面这些S11-S44实际上是一个4*4的矩阵在原始的C实现中是用#define 实现的 这里把它们实现成为static final是表示了只读切能在同一个进程空间内的多个 Instance间共享
*/
static final int S11 = 7;
static final int S12 = 12;
static final int S13 = 17;
static final int S14 = 22;
static final int S21 = 5;
static final int S22 = 9;
static final int S23 = 14;
static final int S24 = 20;
static final int S31 = 4;
static final int S32 = 11;
static final int S33 = 16;
static final int S34 = 23;
static final int S41 = 6;
static final int S42 = 10;
static final int S43 = 15;
static final int S44 = 21;
static final byte[] PADDING = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0};
/*
* 下面的三个成员是MD5计算过程中用到的3个核心数据在原始的C实现中 被定义到MD5_CTX结构中
*/
private static long[] state = new long[4]; // state (ABCD)
private static long[] count = new long[2]; // number of bits, modulo 2^64
// (lsb
// first)
private static byte[] buffer = new byte[64]; // input buffer
/*
* digestHexStr是MD5的唯一一个公共成员是最新一次计算结果的   16进制ASCII表示.
*/
public static String digestHexStr;
/*
* digest,是最新一次计算结果的2进制内部表示表示128bit的MD5值.
*/
private static byte[] digest = new byte[16];
public MD5Utils() {
md5Init();
return;
}
/* md5Init是一个初始化函数初始化核心变量装入标准的幻数 */
private static void md5Init() {
count[0] = 0L;
count[1] = 0L;
// /* Load magic initialization constants.
state[0] = 0x67452301L;
state[1] = 0xefcdab89L;
state[2] = 0x98badcfeL;
state[3] = 0x10325476L;
return;
}
/*
* F, G, H ,I 是4个基本的MD5函数在原始的MD5的C实现中由于它们是 简单的位运算可能出于效率的考虑把它们实现成了宏在java中我们把它们   实现成了private方法名字保持了原来C中的
*/
private static long F(long x, long y, long z) {
return (x & y) | ((~x) & z);
}
private static long G(long x, long y, long z) {
return (x & z) | (y & (~z));
}
private static long H(long x, long y, long z) {
return x ^ y ^ z;
}
private static long I(long x, long y, long z) {
return y ^ (x | (~z));
}
/*
* FF,GG,HH和II将调用F,G,H,I进行近一步变换 FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is separate
* from addition to prevent recomputation.
*/
private static long FF(long a, long b, long c, long d, long x, long s, long ac) {
a += F(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
private static long GG(long a, long b, long c, long d, long x, long s, long ac) {
a += G(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
private static long HH(long a, long b, long c, long d, long x, long s, long ac) {
a += H(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
private static long II(long a, long b, long c, long d, long x, long s, long ac) {
a += I(b, c, d) + x + ac;
a = ((int) a << s) | ((int) a >>> (32 - s));
a += b;
return a;
}
/*
* md5Update是MD5的主计算过程inbuf是要变换的字节串inputlen是长度这个 函数由getMD5ofStr调用调用之前需要调用md5init因此把它设计成private的
*/
private static void md5Update(byte[] inbuf, int inputLen) {
int i, index, partLen;
byte[] block = new byte[64];
index = (int) (count[0] >>> 3) & 0x3F;
// /* Update number of bits */
if ((count[0] += (inputLen << 3)) < (inputLen << 3)) {
count[1]++;
}
count[1] += (inputLen >>> 29);
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen >= partLen) {
md5Memcpy(buffer, inbuf, index, 0, partLen);
md5Transform(buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
md5Memcpy(block, inbuf, 0, i, 64);
md5Transform(block);
}
index = 0;
} else {
i = 0;
}
// /* Buffer remaining input */
md5Memcpy(buffer, inbuf, index, i, inputLen - i);
}
/*
* md5Final整理和填写输出结果
*/
private static void md5Final() {
byte[] bits = new byte[8];
int index, padLen;
// /* Save number of bits */
Encode(bits, count, 8);
// /* Pad out to 56 mod 64.
index = (int) (count[0] >>> 3) & 0x3f;
padLen = (index < 56) ? (56 - index) : (120 - index);
md5Update(PADDING, padLen);
// /* Append length (before padding) */
md5Update(bits, 8);
// /* Store state in digest */
Encode(digest, state, 16);
}
/*
* md5Memcpy是一个内部使用的byte数组的块拷贝函数从input的inpos开始把len长度的       字节拷贝到output的outpos位置开始
*/
private static void md5Memcpy(byte[] output, byte[] input, int outpos, int inpos, int len) {
int i;
for (i = 0; i < len; i++) {
output[outpos + i] = input[inpos + i];
}
}
/*
* md5Transform是MD5核心变换程序有md5Update调用block是分块的原始字节
*/
private static void md5Transform(byte[] block) {
long a = state[0], b = state[1], c = state[2], d = state[3];
long[] x = new long[16];
Decode(x, block, 64);
/* Round 1 */
a = FF(a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
d = FF(d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
c = FF(c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
b = FF(b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
a = FF(a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
d = FF(d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
c = FF(c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
b = FF(b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
a = FF(a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
d = FF(d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
c = FF(c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
b = FF(b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
a = FF(a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
d = FF(d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
c = FF(c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
b = FF(b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
/* Round 2 */
a = GG(a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
d = GG(d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
c = GG(c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
a = GG(a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
d = GG(d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
c = GG(c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
a = GG(a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
d = GG(d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
c = GG(c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
b = GG(b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
a = GG(a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
c = GG(c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
/* Round 3 */
a = HH(a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
d = HH(d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
c = HH(c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
b = HH(b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
a = HH(a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
b = HH(b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
a = HH(a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
d = HH(d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
c = HH(c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
b = HH(b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
a = HH(a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
d = HH(d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
b = HH(b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
/* Round 4 */
a = II(a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
d = II(d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
c = II(c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
b = II(b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
a = II(a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
d = II(d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
c = II(c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
b = II(b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
a = II(a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
c = II(c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
b = II(b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
a = II(a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
d = II(d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
c = II(c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
b = II(b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
/*
* Encode把long数组按顺序拆成byte数组因为java的long类型是64bit的 只拆低32bit以适应原始C实现的用途
*/
private static void Encode(byte[] output, long[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (byte) (input[i] & 0xffL);
output[j + 1] = (byte) ((input[i] >>> 8) & 0xffL);
output[j + 2] = (byte) ((input[i] >>> 16) & 0xffL);
output[j + 3] = (byte) ((input[i] >>> 24) & 0xffL);
}
}
/*
* Decode把byte数组按顺序合成成long数组因为java的long类型是64bit的 只合成低32bit高32bit清零以适应原始C实现的用途
*/
private static void Decode(long[] output, byte[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[i] = b2iu(input[j]) | (b2iu(input[j + 1]) << 8) | (b2iu(input[j + 2]) << 16)
| (b2iu(input[j + 3]) << 24);
}
return;
}
/*
* b2iu是我写的一个把byte按照不考虑正负号的原则的升位程序因为java没有unsigned运算
*/
public static long b2iu(byte b) {
return b < 0 ? b & 0x7F + 128 : b;
}
/*
* byteHEX()用来把一个byte类型的数转换成十六进制的ASCII表示  因为java中的byte的toString无法实现这一点我们又没有C语言中的 sprintf(outbuf,"%02X",ib)
*/
public static String byteHEX(byte ib) {
char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char[] ob = new char[2];
ob[0] = Digit[(ib >>> 4) & 0X0F];
ob[1] = Digit[ib & 0X0F];
String s = new String(ob);
return s;
}
public static String encode(String inbuf) {
md5Init();
md5Update(inbuf.getBytes(), inbuf.length());
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
}
public static String encodeLowerCase(String inbuf) {
md5Init();
md5Update(inbuf.getBytes(), inbuf.length());
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr.toLowerCase();
}
/*
* getMD5ofStr是类MD5最主要的公共方法入口参数是你想要进行MD5变换的字符串 返回的是变换完的结果这个结果是从公共成员digestHexStr取得的
*/
public static String getMD5ofStr(String inbuf) {
md5Init();
md5Update(inbuf.getBytes(), inbuf.length());
md5Final();
digestHexStr = "";
for (int i = 0; i < 16; i++) {
digestHexStr += byteHEX(digest[i]);
}
return digestHexStr;
}
/**
* App MD5
*
* @param plainText
* @return
*/
public static String encryption(String plainText) {
String re_md5 = new String();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte[] b = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
re_md5 = buf.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return re_md5;
}
public final static String getMD5(String pwd) {
// 用于加密的字符
char md5String[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
try {
// 使用平台的默认字符集将此 String 编码为 byte序列并将结果存储到一个新的 byte数组中
byte[] btInput = pwd.getBytes();
// 获得指定摘要算法的 MessageDigest对象此处为MD5
// MessageDigest类为应用程序提供信息摘要算法的功能 MD5 SHA 算法
// 信息摘要是安全的单向哈希函数它接收任意大小的数据并输出固定长度的哈希值
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// System.out.println(mdInst);
// MD5 Message Digest from SUN,
// MessageDigest对象通过使用 update方法处理数据 使用指定的byte数组更新摘要
mdInst.update(btInput);
// System.out.println(mdInst);
// MD5 Message Digest from SUN,
// 摘要更新之后通过调用digest()执行哈希计算获得密文
byte[] md = mdInst.digest();
// System.out.println(md);
// 把密文转换成十六进制的字符串形式
int j = md.length;
// System.out.println(j);
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) { // i = 0
byte byte0 = md[i]; // 95
str[k++] = md5String[byte0 >>> 4 & 0xf]; // 5
str[k++] = md5String[byte0 & 0xf]; // F
}
// 返回经过加密后的字符串
String x = new String(str);
if(StringUtils.isNotBlank(x)){
return x.toLowerCase();
}
} catch (Exception e) {
log.error("md5 加密出错",e);
}
return null;
}
}

View File

@ -14,4 +14,27 @@
<dependencies>
</dependencies>
<build>
<finalName>api-interface</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.heyu.api.ApiUserApiApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -8,6 +8,7 @@ import com.heyu.api.data.dao.api.ApiPostCodeDao;
import com.heyu.api.data.dao.calca.CalcaAccountDao;
import com.heyu.api.data.entity.api.ApiPostCodeEntity;
import com.heyu.api.data.entity.calca.CalcaAccountEntity;
import com.heyu.api.data.utils.MD5Utils;
import com.heyu.api.data.utils.R;
import com.heyu.api.data.utils.RedisUtils;
import com.heyu.api.data.utils.StringUtils;
@ -18,18 +19,23 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;
@Slf4j
@RestController
@RequestMapping("/app/test")
@NotIntercept
public class TestController{
public class TestController {
@Autowired
private CalcaAccountDao calcaAccountDao;
@ -42,12 +48,13 @@ public class TestController{
private ApiPostCodeDao apiPostCodeDao;
@Autowired
private RabbitTemplate rabbitTemplate;
public static ExecutorService cachedThreadPool = Executors.newFixedThreadPool(4);
@Value("${eb.config.rabbitQueue.postCodeData}")
private String accountLogNameQueue;
@ -72,13 +79,11 @@ public class TestController{
// http://localhost:8888/app/test/email?key=AX
@RequestMapping("/email")
public R email(String key ) throws Exception {
String fileName = "/Users/quyixiao/Desktop/"+key+"/"+key+".txt";
public R email(String key) throws Exception {
String fileName = "/Users/quyixiao/Desktop/" + key + "/" + key + ".txt";
// 读取文件内容到Stream流中按行读取
Stream<String> lines = Files.lines(Paths.get(fileName));
StringBuffer sb = new StringBuffer();
// 随机行顺序进行数据处理
lines.forEach(ele -> {
int max_length = 32;
@ -86,87 +91,87 @@ public class TestController{
int index = -1;
String a[] = ele.split("\t");
String b[] = new String[12];
if (a != null && a.length == 11){
if (a != null && a.length == 11) {
for (int i = 0; i < a.length; i++) {
b[i] = a[i];
}
b[11] = "";
a = b ;
a = b;
}
if (a != null && a.length == 12) {
try {
sb.append("INSERT INTO api_post_code ( is_delete, create_time, modify_time, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12) VALUES\n" +
" ( 0, '2025-03-11 00:36:20', '2025-03-11 00:36:20'" +
", '"+a[0] +"'" +
", '"+a[1]+"'" +
", '"+a[2]+"'" +
", '"+a[3]+"'" +
", '"+a[4]+"'" +
", '"+a[5]+"'" +
", '"+a[6]+"'" +
", '"+a[7]+"'" +
", '"+a[8]+"'" +
", '"+a[9]+"'" +
", '"+a[10]+"'" +
", '"+a[11]+"');");
", '" + a[0] + "'" +
", '" + a[1] + "'" +
", '" + a[2] + "'" +
", '" + a[3] + "'" +
", '" + a[4] + "'" +
", '" + a[5] + "'" +
", '" + a[6] + "'" +
", '" + a[7] + "'" +
", '" + a[8] + "'" +
", '" + a[9] + "'" +
", '" + a[10] + "'" +
", '" + a[11] + "');");
sb.append("\n");
if(a[0].length()>32){
if (a[0].length() > 32) {
max_length = a[0].length();
value = a[0];
index = 0 ;
index = 0;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[1].length()>64){
if (a[1].length() > 64) {
max_length = a[1].length();
value = a[1];
index = 1 ;
index = 1;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[2].length()>255){
if (a[2].length() > 255) {
max_length = a[2].length();
value = a[2];
index = 2 ;
index = 2;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[3].length()>64){
if (a[3].length() > 64) {
max_length = a[3].length();
value = a[3];
index = 3 ;
index = 3;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[4].length()>64){
if (a[4].length() > 64) {
max_length = a[4].length();
value = a[4];
index = 4;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[5].length()>64){
if (a[5].length() > 64) {
max_length = a[5].length();
value = a[5];
index = 5 ;
index = 5;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[6].length()>64){
if (a[6].length() > 64) {
max_length = a[6].length();
value = a[6];
index = 6 ;
index = 6;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[7].length()>64){
if (a[7].length() > 64) {
max_length = a[7].length();
value = a[7];
index = 7 ;
index = 7;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if(a[8].length()>64){
if (a[8].length() > 64) {
max_length = a[8].length();
value = a[8];
index = 8 ;
index = 8;
System.out.println(" max_length:" + max_length + ",value:" + value + ",index:" + index);
}
if (a[9].length() > 32) {
@ -189,14 +194,11 @@ public class TestController{
}
} catch (Exception e) {
log.error(e.getMessage());
}
} else {
log.info("数据格式不正确 " + ele + ",length" + a.length );
log.info("数据格式不正确 " + ele + ",length" + a.length);
}
});
String newFile = "/Users/quyixiao/Desktop/post_code.sql";
@ -206,20 +208,76 @@ public class TestController{
out.write(sb.toString());
out.close();
fos.close();
return R.ok();
}
public static int count_flag = 0;
// http://localhost:8888/app/test/email2?key=AD
@RequestMapping("/email2")
public R email2(String key ) throws Exception {
String fileName = "/Users/quyixiao/Desktop/"+key+"/"+key+".txt";
public R email2(String key) throws Exception {
File file = new File("/Users/quyixiao/Desktop/test");
List<String> list = new ArrayList<String>();
showList(list, file);
System.out.println("----------------x---------");
for(String a: list){
System.out.println("===============>" + a );
doSend(a);
}
return R.ok();
}
public String getValue(String value) {
if (StringUtils.isBlank(value)) {
return "";
}
return value;
}
private static void showList(List<String> list, File file) {
if (file.isDirectory()) {//如果是目录
File[] listFiles = file.listFiles();//获取当前路径下的所有文件和目录,返回File对象数组
for (File f : listFiles) {//将目录内的内容对象化并遍历
String fName = f.getPath();
System.out.println("文件:" + fName);
if (fName.endsWith(".txt") & !fName.contains("readme.txt")) {
list.add(fName);
}
if (f.isDirectory()) {
showList(list, new File(fName));
}
}
} else if (file.isFile()) {//如果是文件
String fileName = file.getPath();
System.out.println("文件:" + fileName);
if (fileName.endsWith(".txt") & !fileName.contains("readme.txt")) {
list.add(fileName);
}
}
}
public static void main(String[] args) {
File file = new File("/Users/quyixiao/Desktop/test");
List<String> list = new ArrayList<String>();
showList(list, file);
System.out.println("----------------x---------");
for(String a: list){
System.out.println("===============>" + a );
}
}
public void doSend(String fileName) throws Exception{
count_flag = 0;
// 读取文件内容到Stream流中按行读取
Stream<String> lines = Files.lines(Paths.get(fileName));
StringBuffer sb = new StringBuffer();
@ -230,45 +288,60 @@ public class TestController{
String a[] = ele.split("\t");
String b[] = new String[12];
if (a != null && a.length == 11){
if (a != null && a.length == 11) {
for (int i = 0; i < a.length; i++) {
b[i] = a[i];
}
b[11] = "";
a = b ;
a = b;
}
if (a != null && a.length == 12) {
ApiPostCodeEntity apiPostCodeEntity = new ApiPostCodeEntity();
apiPostCodeEntity.setParam1(getValue(a[0]));
apiPostCodeEntity.setParam2(getValue(a[1]));
apiPostCodeEntity.setParam3(getValue(a[2]));
apiPostCodeEntity.setParam4(getValue(a[3]));
apiPostCodeEntity.setParam5(getValue(a[4]));
apiPostCodeEntity.setParam6(getValue(a[5]));
apiPostCodeEntity.setParam7(getValue(a[6]));
apiPostCodeEntity.setParam8(getValue(a[7]));
apiPostCodeEntity.setParam9(getValue(a[8]));
apiPostCodeEntity.setParam10(getValue(a[9]));
apiPostCodeEntity.setParam11(getValue(a[10]));
apiPostCodeEntity.setParam12(getValue(a[11]));
String param1 = getValue(a[0]);
String param2 = getValue(a[1]);
String param3 = getValue(a[2]);
String param4 = getValue(a[3]);
String param5 = getValue(a[4]);
String param6 = getValue(a[5]);
String param7 = getValue(a[6]);
String param8 = getValue(a[7]);
String param9 = getValue(a[8]);
String param10 = getValue(a[9]);
String param11 = getValue(a[10]);
String param12 = getValue(a[11]);
apiPostCodeEntity.setParam1(param1);
apiPostCodeEntity.setParam2(param2);
apiPostCodeEntity.setParam3(param3);
apiPostCodeEntity.setParam4(param4);
apiPostCodeEntity.setParam5(param5);
apiPostCodeEntity.setParam6(param6);
apiPostCodeEntity.setParam7(param7);
apiPostCodeEntity.setParam8(param8);
apiPostCodeEntity.setParam9(param9);
apiPostCodeEntity.setParam10(param10);
apiPostCodeEntity.setParam11(param11);
apiPostCodeEntity.setParam12(param12);
String param = param1
+ param2
+ param3
+ param4
+ param5
+ param6
+ param7
+ param8
+ param9
+ param10
+ param11
+ param12;
String md5 = MD5Utils.encode(param);
apiPostCodeEntity.setMd5Unique(md5);
System.out.println("=-------------------->"+ count_flag);
rabbitTemplate.convertAndSend(accountLogNameQueue, JSON.toJSONString(apiPostCodeEntity));
}
});
return R.ok();
}
public String getValue(String value ) {
if(StringUtils.isBlank(value)){
return "null";
}
return value;
}
}

View File

@ -11,10 +11,11 @@ import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
//@Component
@Slf4j
public class PostCodeQueueSimpleRabbitListener {
@ -30,6 +31,12 @@ public class PostCodeQueueSimpleRabbitListener {
apiPostCodeDao.insertApiPostCode(apiPostCodeEntity);
} catch (Exception e) {
log.error("exception e " + message, e);
}finally {
try {
channel.basicAck(delivertTag, true);
} catch (IOException e) {
log.error("消息确认异常", e);
}
}
}

View File

@ -44,6 +44,8 @@
<logback.version>1.2.3</logback.version>
<slf4j.version>1.7.25</slf4j.version>
<mybatis-plus.version>3.4.3</mybatis-plus.version>
<spring.boot.maven.plugin.version>2.0.4.RELEASE</spring.boot.maven.plugin.version>
</properties>