From f4be36f30a802e70038bde438d1689eb749032fd Mon Sep 17 00:00:00 2001 From: zhangchao <zc857179121@qq.com> Date: 星期五, 22 十一月 2024 08:49:19 +0800 Subject: [PATCH] 采用定长的线程池,防止定时任务的异常导致大量线程被占用 --- src/main/java/com/zy/common/web/BaseController.java | 83 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/zy/common/web/BaseController.java b/src/main/java/com/zy/common/web/BaseController.java index 8c880d1..0309a4a 100644 --- a/src/main/java/com/zy/common/web/BaseController.java +++ b/src/main/java/com/zy/common/web/BaseController.java @@ -7,7 +7,13 @@ import com.core.common.Cools; import com.core.controller.AbstractBaseController; import com.core.exception.CoolException; +import com.zy.asrs.entity.Node; +import com.zy.asrs.entity.Tag; +import com.zy.asrs.service.NodeService; +import com.zy.asrs.service.TagService; import com.zy.system.entity.User; +import com.zy.system.entity.UserLogin; +import com.zy.system.service.UserLoginService; import com.zy.system.service.UserService; import io.swagger.annotations.ApiModelProperty; import org.springframework.beans.factory.annotation.Autowired; @@ -22,12 +28,24 @@ */ public class BaseController extends AbstractBaseController { + protected static final String RANGE_TIME_LINK = " - "; + @Autowired protected HttpServletRequest request; @Autowired private UserService userService; + @Autowired + private TagService tagService; + @Autowired + private NodeService nodeService; + + @Autowired + private UserLoginService userLoginService; protected Long getUserId(){ + if(Cools.isEmpty(request.getAttribute("userId"))){ + return 000L; + } return Long.parseLong(String.valueOf(request.getAttribute("userId"))); } @@ -47,6 +65,18 @@ } } return ""; + } + + protected Tag getOriginTag(){ + return tagService.getTop(); + } + + protected Node getOriginNode(){ + Node node = nodeService.getTop(); + if (node == null) { + throw new CoolException("搴撳尯鏁版嵁閿欒"); + } + return node; } /** @@ -69,7 +99,7 @@ // 鍏ㄥ瓧娈垫ā绯婃悳绱� todo if (!Cools.isEmpty(map.get("condition"))) { Set<String> columns = new HashSet<>(); - for (Field field :Cools.getAllFields(cls)){ + for (Field field : Cools.getAllFields(cls)){ if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())){ @@ -132,4 +162,55 @@ wrapper.like(columns.get(i), condition); } } + + public static boolean isJSON(String str) { + if (Cools.isEmpty(str)) { + return false; + } else { + str = str.trim(); + if (str.startsWith("{") && str.endsWith("}")) { + return true; + } else if (str.startsWith("[") && str.endsWith("]")) { + return true; + } else { + return false; + } + } + } + + protected <T> void hostEq(EntityWrapper<T> wrapper){ + Long hostId = getHostId(); + if (hostId != null) { + wrapper.eq("host_id", hostId); + } + } + + protected Long getHostId(){ + if (getUserId() == 9527) { + return null; + } + User user = getUser(); + if (user.getRoleId() == 1) { + String hostId = String.valueOf(request.getAttribute("hostId")); + if (Cools.isEmpty(hostId)) { + UserLogin userLogin = userLoginService.selectOne(new EntityWrapper<UserLogin>().eq("user_id", user.getId())); + if (userLogin != null) { + //return userLogin.getHostId(); + return 1L; + } + } + return Long.parseLong(hostId); + } else { + return user.getHostId(); + } + } + + public static boolean isNumber(String str){ + for (int i = str.length();--i>=0;){ + if (!Character.isDigit(str.charAt(i))){ + return false; + } + } + return true; + } } -- Gitblit v1.9.1