feat(商城): 添加阿里巴巴代码规范检测

master
wayn 2 years ago
parent b3ab408b6a
commit 24d4c82955

@ -1,9 +1,9 @@
# waynboot-mall
| 分支名称 | Spring Boot 版本 |
|--------------------------------------------------------------------|---------------------|
| [master](https://github.com/wayn111/waynboot-mall) | 3.0.5 |
| [springboot-2.7](https://github.com/wayn111/waynboot-mall/tree/springboot-2.7) | 2.7
|--------------------------------------------------------------------|----------------|
| [master](https://github.com/wayn111/waynboot-mall) | 3.0.6 |
| [springboot-2.7](https://github.com/wayn111/waynboot-mall/tree/springboot-2.7) | 2.7
---
@ -23,7 +23,6 @@ waynboot-mall是一套全部开源的微商城项目包含一个运营后台
关注公众号waynblog每周更新最新技术文章。回复关键字
- **学习**:加群交流,群内问题都会一一解答。
- **演示账号**:获得线上项目管理后台演示账号。
- **chatgpt**获取博主自建chatgpt网站访问地址和访问密码。
- **开源项目**获取博主自己写的三个开源项目包含PC、H5商城、后台权限管理系统等。
<img src="images/wx-mp-code.png" width = "100" />

@ -25,7 +25,7 @@
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<spring-boot.version>3.0.5</spring-boot.version>
<spring-boot.version>3.0.6</spring-boot.version>
<mysql.connector.java.version>8.0.30</mysql.connector.java.version>
<lettuce.version>6.2.3.RELEASE</lettuce.version>
<elasticsearch.version>7.14.0</elasticsearch.version>

@ -2,10 +2,12 @@ package com.wayn.common.task;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.stereotype.Component;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@Slf4j
@Component
@ -14,8 +16,9 @@ public class TaskService {
@PostConstruct
private void init() {
Executors.newSingleThreadExecutor().execute(() -> {
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1,
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build());
executorService.execute(() -> {
while (true) {
try {
Task task = delayQueue.take();
@ -27,15 +30,15 @@ public class TaskService {
});
}
public void addTask(Task task) {
public boolean addTask(Task task) {
if (delayQueue.contains(task)) {
return;
return false;
}
delayQueue.add(task);
return delayQueue.add(task);
}
public void removeTask(Task task) {
delayQueue.remove(task);
public boolean removeTask(Task task) {
return delayQueue.remove(task);
}
}

@ -81,8 +81,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
File file = new File(filePath);
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
flag = true;
flag = file.delete();
}
return flag;
}
@ -149,7 +148,9 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
String temp = null;
while (true) {
try {
if ((temp = br.readLine()) == null) break;
if ((temp = br.readLine()) == null) {
break;
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}

@ -90,8 +90,9 @@ public class IpUtils {
switch (elements.length) {
case 1 -> {
l = Long.parseLong(elements[0]);
if ((l < 0L) || (l > 4294967295L))
if ((l < 0L) || (l > 4294967295L)) {
return null;
}
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
bytes[1] = (byte) (int) ((l & 0xFFFFFF) >> 16 & 0xFF);
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
@ -99,12 +100,14 @@ public class IpUtils {
}
case 2 -> {
l = Integer.parseInt(elements[0]);
if ((l < 0L) || (l > 255L))
if ((l < 0L) || (l > 255L)) {
return null;
}
bytes[0] = (byte) (int) (l & 0xFF);
l = Integer.parseInt(elements[1]);
if ((l < 0L) || (l > 16777215L))
if ((l < 0L) || (l > 16777215L)) {
return null;
}
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
@ -112,21 +115,24 @@ public class IpUtils {
case 3 -> {
for (i = 0; i < 2; ++i) {
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L))
if ((l < 0L) || (l > 255L)) {
return null;
}
bytes[i] = (byte) (int) (l & 0xFF);
}
l = Integer.parseInt(elements[2]);
if ((l < 0L) || (l > 65535L))
if ((l < 0L) || (l > 65535L)) {
return null;
}
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
bytes[3] = (byte) (int) (l & 0xFF);
}
case 4 -> {
for (i = 0; i < 4; ++i) {
l = Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L))
if ((l < 0L) || (l > 255L)) {
return null;
}
bytes[i] = (byte) (int) (l & 0xFF);
}
}

@ -1,10 +1,13 @@
package com.test;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.stream.Collectors;
@Slf4j
public class BufferedInputFile {
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new FileReader("E:/data.txt"))) {

@ -8,7 +8,7 @@ public class CompletableFutureTest {
.supplyAsync(() -> 1)
.thenApplyAsync(integer -> integer + 1)
.thenApplyAsync(integer -> integer * integer)
.thenCombineAsync(CompletableFuture.completedFuture(11), (integer, integer2) -> integer + integer2)
.thenAcceptAsync(integer -> System.out.println(integer));
.thenCombineAsync(CompletableFuture.completedFuture(11), Integer::sum)
.thenAcceptAsync(System.out::println);
}
}

@ -1,20 +1,20 @@
package com.test;
import java.io.FileNotFoundException;
import lombok.extern.slf4j.Slf4j;
import java.io.FileReader;
import java.io.IOException;
@Slf4j
public class FileRead {
public static void main(String[] args) {
try (FileReader fileReader = new FileReader("E:/data.txt")) {
char arr[] = new char[1024];
char[] arr = new char[1024];
int len;
while ((len = fileReader.read(arr)) != -1) {
System.out.println(new String(arr,0 ,len));
}
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);;
} catch (IOException e) {
log.error(e.getMessage(), e);;
}

@ -1,75 +0,0 @@
package com.test;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class FileRead1 {
public static void main(String[] args) {
File file1 = new File("E:\\扫黑办聚合码\\打印一张");
File file2 = new File("E:\\扫黑办聚合码\\打印两张");
File file3 = new File("E:\\扫黑办聚合码\\打印三张");
File file4 = new File("E:\\扫黑办聚合码\\打印一张\\1组");
File file5 = new File("E:\\扫黑办聚合码\\打印一张\\3组");
File file6 = new File("E:\\扫黑办聚合码\\打印一张\\4组");
File file7 = new File("E:\\扫黑办聚合码\\打印一张\\5组");
List<String> all = new ArrayList<>();
List<String> list1 = Arrays.asList(file1.list());
List<String> list2 = Arrays.asList(file2.list());
List<String> list3 = Arrays.asList(file3.list());
List<String> list4 = Arrays.asList(file4.list());
List<String> list5 = Arrays.asList(file5.list());
List<String> list6 = Arrays.asList(file6.list());
List<String> list7 = Arrays.asList(file7.list());
all.addAll(list1);
all.addAll(list2);
all.addAll(list3);
all.addAll(list4);
all.addAll(list5);
all.addAll(list6);
all.addAll(list7);
System.out.println(all.size());
List<Integer> names = new ArrayList<>();
for (String s : all) {
if (s.contains("下载")) {
continue;
}
System.out.println(s);
String[] split = s.split("-", -1);
if (split.length == 1) {
String s1 = split[0].trim().split(".png", -1)[0];
if (s1.contains(" (") || s1.contains("组")) {
continue;
}
names.add(Integer.parseInt(s1));
}
if (split.length == 2) {
if (Integer.parseInt(split[0].trim()) < 16) {
// if (split[1].trim().contains("-")) {
// names.add(Integer.parseInt(split[1].trim().split("-.png", -1)[0]));
// } else {
// }
names.add(Integer.parseInt(split[1].trim().split(".png", -1)[0]));
// names.add(Integer.parseInt(split[1].trim()));
} else {
names.add(Integer.parseInt(split[0].trim()));
}
}
if (split.length >= 3) {
names.add(Integer.parseInt(split[1].trim()));
}
}
names = names.stream().distinct().collect(Collectors.toList());
names.sort(Comparator.comparingInt(o -> o));
System.out.println(StringUtils.join(names, ","));
System.out.println(names.size());
}
}

@ -1,40 +0,0 @@
package com.test;
public class FoodTest {
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Origin extends Fruit {
}
class Plate <T>{
private T item;
public Plate(T t) {
item = t;
}
public void set(T t) {
item = t;
}
public T get() {
return item;
}
}
public static void main(String[] args) {
new FoodTest().test();
}
public void test() {
Plate<? extends Fruit> p = new Plate<>(new Apple());
}
}

@ -1,33 +0,0 @@
package com.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class NIOTest {
private static String name = "E:/data.txt";
private static final int BSIZE = 1024;
public static void main(String[] args) throws IOException {
// 写入一个文件:
FileChannel fc = new FileOutputStream(name)
.getChannel();
fc.write(ByteBuffer
.wrap("Some text ".getBytes()));
// 读取文件e:
FileChannel fc2 = new FileInputStream(name)
.getChannel();
ByteBuffer buff = ByteBuffer.allocate(BSIZE);
fc2.read(buff);
buff.flip();
while (buff.hasRemaining())
System.out.write(buff.get());
System.out.println();
System.out.flush();
}
}

@ -1,38 +0,0 @@
package com.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class OSExecute {
public static void command(String command) throws Exception {
boolean err = false;
try {
Process process = new ProcessBuilder(
command.split(" ")).start();
try (
BufferedReader results = new BufferedReader(
new InputStreamReader(
process.getInputStream(), "gbK"));
BufferedReader errors = new BufferedReader(
new InputStreamReader(
process.getErrorStream()))
) {
results.lines()
.forEach(System.out::println);
err = errors.lines()
.peek(System.err::println)
.count() > 0;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (err)
throw new Exception(
"Errors executing " + command);
}
public static void main(String[] args) throws Exception {
command("java -version");
}
}

@ -1,25 +0,0 @@
package com.test;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class TestEOF {
public static void main(String[] args) {
try (DataInputStream in = new DataInputStream(new FileInputStream("E:/data.txt"))) {
while (in.available() != 0) {
System.out.write(in.readByte());
}
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);;
} catch (IOException e) {
log.error(e.getMessage(), e);;
}
System.out.println(1000== 1000);
Integer i1 = 1000;
Integer i2 = 1000;
System.out.println(i1== i2);
}
}

@ -73,7 +73,8 @@ public class LoginController {
// 删除验证码
redisCache.deleteObject(registryObj.getEmailKey());
Member member = new Member();
member.setNickname("昵称" + new Date().getTime() / 1000);
long time = System.currentTimeMillis();
member.setNickname("昵称" + time / 1000);
String avatar = SysConstants.DEFAULT_AVATAR;
member.setAvatar(avatar);
member.setMobile(registryObj.getMobile());

@ -49,9 +49,10 @@ public class IHomeServiceImpl implements IHomeService {
R success = R.success();
Map<String, Object> shopHomeIndexHash = redisCache.getCacheMap(SHOP_HOME_INDEX_HASH);
// 当缓存中存在数据,并且过期时间不为空而且小于等于过期时间则直接从缓存中取出数据
long nowTime = System.currentTimeMillis();;
if (MapUtils.isNotEmpty(shopHomeIndexHash) && shopHomeIndexHash.containsKey(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD)) {
long time = (long) shopHomeIndexHash.get(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD);
if ((new Date().getTime() - time) <= Constants.ONE_DAY) {
if ((nowTime - time) <= Constants.ONE_DAY) {
shopHomeIndexHash.forEach(success::add);
log.info("getHomeIndexDataCompletableFuture:{}", success);
return success;
@ -96,7 +97,7 @@ public class IHomeServiceImpl implements IHomeService {
list.add(f4);
CompletableFuture.allOf(list.toArray(new CompletableFuture[0])).join();
// 通过hash的field设置过期时间防止过期时间设置失败导致缓存无法删除
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD, new Date().getTime());
redisCache.setCacheMapValue(SHOP_HOME_INDEX_HASH, SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD, nowTime);
return success;
}

Loading…
Cancel
Save