|
@@ -4,6 +4,7 @@ import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.gzlh.config.ModuleEnum;
|
|
|
import com.gzlh.dto.EventDTO;
|
|
|
import com.gzlh.infrared.config.RedPropertiesConfig;
|
|
@@ -22,22 +23,12 @@ import java.util.List;
|
|
|
public class EventThread extends Thread{
|
|
|
private List<EventDTO> eventDTOList;
|
|
|
private String eventName;
|
|
|
- @Resource
|
|
|
- private LedFactory ledFactory;
|
|
|
- @Resource
|
|
|
- private RedFactory redFactory;
|
|
|
- @Resource
|
|
|
- WeighbridgeFactory weighbridgeFactory;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private WeighbridgePropertiesConfig weighbridgePropertiesConfig;
|
|
|
- @Resource
|
|
|
- private RedPropertiesConfig redPropertiesConfig;
|
|
|
- @Resource
|
|
|
- private LedPropertiesConfig ledPropertiesConfig;
|
|
|
-
|
|
|
- public EventThread() {
|
|
|
- }
|
|
|
+ private final LedFactory ledFactory=SpringUtil.getBean(LedFactory.class);
|
|
|
+ private final RedFactory redFactory=SpringUtil.getBean(RedFactory.class);
|
|
|
+ private final WeighbridgeFactory weighbridgeFactory=SpringUtil.getBean(WeighbridgeFactory.class);
|
|
|
+ private final WeighbridgePropertiesConfig weighbridgePropertiesConfig=SpringUtil.getBean(WeighbridgePropertiesConfig.class);
|
|
|
+ private final RedPropertiesConfig redPropertiesConfig=SpringUtil.getBean(RedPropertiesConfig.class);
|
|
|
+ private final LedPropertiesConfig ledPropertiesConfig=SpringUtil.getBean(LedPropertiesConfig.class);
|
|
|
|
|
|
public EventThread(String eventName) {
|
|
|
this.setName(eventName);
|
|
@@ -57,23 +48,25 @@ public class EventThread extends Thread{
|
|
|
*/
|
|
|
public void handlerEvent(String eventName) {
|
|
|
log.info("event:{}", eventName);
|
|
|
-
|
|
|
eventDTOList.stream().filter(eventDTO -> StrUtil.equals(eventName, eventDTO.getName()))
|
|
|
.findFirst().ifPresent(eventDTO -> {
|
|
|
-
|
|
|
List<String> actionList = eventDTO.getActionList().getAction();
|
|
|
//依次执行动作
|
|
|
actionList.forEach(action -> {
|
|
|
- String actionPrefix = StrUtil.subBefore(action, ".", true).toLowerCase();
|
|
|
- String actionCommand = StrUtil.subAfter(action, ".", true).toUpperCase();
|
|
|
- if (StrUtil.equals(actionPrefix, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
|
|
|
- redFactory.handler(redPropertiesConfig.getBrand()).handlerAction(actionCommand);
|
|
|
- } else if (StrUtil.equals(actionPrefix, ModuleEnum.LED_MODULE.getModuleEn())) {
|
|
|
- ledFactory.handler(ledPropertiesConfig.getBrand()).handlerAction(actionCommand);
|
|
|
- } else if (StrUtil.equals(actionPrefix, ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn())) {
|
|
|
- weighbridgeFactory.handler(weighbridgePropertiesConfig.getBrand()).handlerAction(actionCommand);
|
|
|
- } else if (StrUtil.equals(actionPrefix, ModuleEnum.CENTER_MODULE.getModuleEn())) {
|
|
|
- handlerAction(actionCommand);
|
|
|
+ String module = StrUtil.subBefore(action, ".", true);
|
|
|
+ String command = StrUtil.subAfter(action, ".", true);
|
|
|
+ if (StrUtil.equals(module, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
|
|
|
+ //动作属于红外
|
|
|
+ redFactory.handler(redPropertiesConfig.getBrand()).handlerAction(command);
|
|
|
+ } else if (StrUtil.equals(module, ModuleEnum.LED_MODULE.getModuleEn())) {
|
|
|
+ //动作属于led
|
|
|
+ ledFactory.handler(ledPropertiesConfig.getBrand()).handlerAction(command);
|
|
|
+ } else if (StrUtil.equals(module, ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn())) {
|
|
|
+ //动作属于地磅
|
|
|
+ weighbridgeFactory.handler(weighbridgePropertiesConfig.getBrand()).handlerAction(command);
|
|
|
+ } else if (StrUtil.equals(module, ModuleEnum.CENTER_MODULE.getModuleEn())) {
|
|
|
+ //动作属于中心总线
|
|
|
+ handlerAction(command);
|
|
|
}
|
|
|
ThreadUtil.sleep(250);
|
|
|
});
|
|
@@ -99,7 +92,7 @@ public class EventThread extends Thread{
|
|
|
* @param action
|
|
|
*/
|
|
|
private void handlerSleep(String action) {
|
|
|
- String time = StrUtil.subAfter(StrUtil.subAfter(action, "(", true), ")", true);
|
|
|
+ String time = StrUtil.subBefore(StrUtil.subAfter(action, "(", true), ")", true);
|
|
|
if (NumberUtil.isInteger(time)) {
|
|
|
ThreadUtil.sleep(Long.parseLong(time));
|
|
|
}
|