fix 任务指令
This commit is contained in:
@@ -51,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,7 @@ import java.util.regex.Pattern;
|
||||
@Slf4j
|
||||
public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial {
|
||||
|
||||
List<Instruction> instructions = new ArrayList();
|
||||
List<Instruction> instructions = new CopyOnWriteArrayList();
|
||||
|
||||
private final DeviceAppService deviceAppService;
|
||||
|
||||
@@ -80,7 +81,8 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
this.instructions = this.queryAll("instruction_status <2 and is_delete =0");
|
||||
List list = this.queryAll("instruction_status <2 and is_delete =0");
|
||||
this.instructions = new CopyOnWriteArrayList<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -442,14 +444,16 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
|
||||
|
||||
wo.update(json);
|
||||
removeByCodeFromCache(dto.getInstruction_code());
|
||||
|
||||
// Iterator<Instruction> iterator = instructions.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// Instruction instruction = iterator.next();
|
||||
// if (instruction.getInstruction_code().equals(dto.getInstruction_code())) {
|
||||
// iterator.remove();
|
||||
// }
|
||||
// }
|
||||
|
||||
Iterator<Instruction> iterator = instructions.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Instruction instruction = iterator.next();
|
||||
if (instruction.getInstruction_code().equals(dto.getInstruction_code())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
if (StrUtil.equals(dto.getInstruction_status(), "0") || StrUtil.equals(dto.getInstruction_status(), "1")) {
|
||||
instructions.add(dto);
|
||||
}
|
||||
@@ -1160,15 +1164,19 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
@Override
|
||||
public boolean removeByCodeFromCache(String code) {
|
||||
|
||||
Iterator<Instruction> iterator = instructions.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Instruction instruction = iterator.next();
|
||||
if (instruction.getInstruction_code().equals(code)) {
|
||||
iterator.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Iterator<Instruction> iterator = instructions.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// Instruction instruction = iterator.next();
|
||||
// if (instruction.getInstruction_code().equals(code)) {
|
||||
// iterator.remove();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
CopyOnWriteArrayList<Instruction> instructions = (CopyOnWriteArrayList<Instruction>) this.instructions;
|
||||
instructions.removeIf((inst) -> {
|
||||
return inst.getInstruction_code().equals(code);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -69,7 +70,7 @@ import java.util.regex.Pattern;
|
||||
@Slf4j
|
||||
public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
|
||||
List<TaskDto> tasks = new ArrayList();
|
||||
List<TaskDto> tasks = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final DeviceAppService deviceAppService;
|
||||
|
||||
@@ -97,7 +98,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
this.tasks = this.queryAll("task_status <2 and is_delete =0");
|
||||
List list = this.queryAll("task_status <2 and is_delete =0 order by create_time");
|
||||
tasks = new CopyOnWriteArrayList<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -455,7 +457,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
|
||||
|
||||
wo.insert(json);
|
||||
tasks.add(dto);
|
||||
synchronized(TaskServiceImpl.class){
|
||||
tasks.add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,12 +594,15 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
wo.update(json);
|
||||
|
||||
Iterator<TaskDto> iterator = tasks.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TaskDto task = iterator.next();
|
||||
if (task.getTask_code().equals(dto.getTask_code())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
// while (iterator.hasNext()) {
|
||||
// TaskDto task = iterator.next();
|
||||
// if (task.getTask_code().equals(dto.getTask_code())) {
|
||||
// iterator.remove();
|
||||
// }
|
||||
// }
|
||||
|
||||
removeByCodeFromCache(entity.getTask_code());
|
||||
|
||||
if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) {
|
||||
tasks.add(dto);
|
||||
}
|
||||
@@ -1031,15 +1038,22 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
|
||||
@Override
|
||||
public boolean removeByCodeFromCache(String code) {
|
||||
Iterator<TaskDto> iterator = tasks.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TaskDto task = iterator.next();
|
||||
if (task.getTask_code().equals(code)) {
|
||||
iterator.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// Iterator<TaskDto> iterator = tasks.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// TaskDto task = iterator.next();
|
||||
// if (task.getTask_code().equals(code)) {
|
||||
// iterator.remove();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
|
||||
CopyOnWriteArrayList<TaskDto> taskDtos = (CopyOnWriteArrayList<TaskDto>) this.tasks;
|
||||
taskDtos.removeIf((task) -> {
|
||||
return task.getTask_code().equals(code);
|
||||
});
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,22 +8,26 @@ import java.util.List;
|
||||
|
||||
public class CodeUtil {
|
||||
|
||||
public static synchronized String getNewCode(String ruleCode) {
|
||||
GenCodeService service = new GenCodeServiceImpl();
|
||||
String flag = "1";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("flag", flag);
|
||||
map.put("code", ruleCode);
|
||||
return service.codeDemo(map);
|
||||
public static String getNewCode(String ruleCode){
|
||||
synchronized (ruleCode) {
|
||||
GenCodeService service=new GenCodeServiceImpl();
|
||||
String flag = "1";
|
||||
HashMap<String,String> map = new HashMap<>();
|
||||
map.put("flag",flag);
|
||||
map.put("code",ruleCode);
|
||||
return service.codeDemo(map);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized List<String> getNewCodes(String ruleCode, Integer number) {
|
||||
GenCodeService service = new GenCodeServiceImpl();
|
||||
String flag = "1";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("flag", flag);
|
||||
map.put("code", ruleCode);
|
||||
map.put("number", number + "");
|
||||
return service.codeDemos(map);
|
||||
public static List<String> getNewCodes(String ruleCode, Integer number) {
|
||||
synchronized (ruleCode) {
|
||||
GenCodeService service = new GenCodeServiceImpl();
|
||||
String flag = "1";
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("flag", flag);
|
||||
map.put("code", ruleCode);
|
||||
map.put("number", number + "");
|
||||
return service.codeDemos(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user