| | |
| | | @Autowired |
| | | private UserLoginService userLoginService; |
| | | |
| | | protected Long getUserId(){ |
| | | if(Cools.isEmpty(request.getAttribute("userId"))){ |
| | | protected Long getUserId() { |
| | | if (Cools.isEmpty(request.getAttribute("userId"))) { |
| | | return 000L; |
| | | } |
| | | return Long.parseLong(String.valueOf(request.getAttribute("userId"))); |
| | | } |
| | | |
| | | protected User getUser(){ |
| | | protected User getUser() { |
| | | User user = userService.selectById(getUserId()); |
| | | if (null == user) { |
| | | throw new CoolException(BaseRes.DENIED); |
| | |
| | | return user; |
| | | } |
| | | |
| | | protected String getComment(Class<?> cls, String fieldName){ |
| | | protected String getComment(Class<?> cls, String fieldName) { |
| | | Field[] fields = Cools.getAllFields(cls); |
| | | for (Field field : fields){ |
| | | if (fieldName.equals(field.getName())){ |
| | | for (Field field : fields) { |
| | | if (fieldName.equals(field.getName())) { |
| | | return field.getAnnotation(ApiModelProperty.class).value(); |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | protected Tag getOriginTag(){ |
| | | protected Tag getOriginTag() { |
| | | return tagService.getTop(); |
| | | } |
| | | |
| | | protected Node getOriginNode(){ |
| | | protected Node getOriginNode() { |
| | | Node node = nodeService.getTop(); |
| | | if (node == null) { |
| | | throw new CoolException("库区数据错误"); |
| | |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | protected <T> Page<T> toPage(Integer pageNumber, Integer pageSize, Map<String, Object> map, Class<T> cls){ |
| | | protected <T> Page<T> toPage(Integer pageNumber, Integer pageSize, Map<String, Object> map, Class<T> cls) { |
| | | // 分页索引和单页数量组装 |
| | | pageNumber = Optional.ofNullable(pageNumber).orElse(1); |
| | | pageSize = Optional.ofNullable(pageSize).orElse(10); |
| | |
| | | // 全字段模糊搜索 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())){ |
| | | || Modifier.isTransient(field.getModifiers())) { |
| | | continue; |
| | | } |
| | | String column = null; |
| | |
| | | columns.add(column); |
| | | } |
| | | } |
| | | columns.forEach(col->map.put(col, map.get("condition"))); |
| | | columns.forEach(col -> map.put(col, map.get("condition"))); |
| | | } |
| | | page.setCondition(map); |
| | | return page; |
| | |
| | | * @param set 排除字段集合 |
| | | * @param condition 搜索内容 |
| | | */ |
| | | protected <T> void allLike(Class<T> cls, Set<String> set, EntityWrapper<T> wrapper, String condition){ |
| | | protected <T> void allLike(Class<T> cls, Set<String> set, EntityWrapper<T> wrapper, String condition) { |
| | | if (Cools.isEmpty(condition)) { |
| | | return; |
| | | } |
| | | List<String> columns = new ArrayList<>(); |
| | | 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())){ |
| | | || Modifier.isTransient(field.getModifiers())) { |
| | | continue; |
| | | } |
| | | String column = null; |
| | | if (field.isAnnotationPresent(TableField.class)) { |
| | | if (field.isAnnotationPresent(TableField.class) && field.getAnnotation(TableField.class).exist()) { |
| | | column = field.getAnnotation(TableField.class).value(); |
| | | } |
| | | if (Cools.isEmpty(column)) { |
| | |
| | | if (columns.isEmpty()) { |
| | | return; |
| | | } |
| | | for (int i=0;i<columns.size();i++){ |
| | | if (i==0){ |
| | | for (int i = 0; i < columns.size(); i++) { |
| | | if (i == 0) { |
| | | wrapper.andNew(); |
| | | } else { |
| | | wrapper.or(); |
| | |
| | | } |
| | | } |
| | | |
| | | protected <T> void hostEq(EntityWrapper<T> wrapper){ |
| | | protected <T> void hostEq(EntityWrapper<T> wrapper) { |
| | | Long hostId = getHostId(); |
| | | if (hostId != null) { |
| | | wrapper.eq("host_id", hostId); |
| | | } |
| | | } |
| | | |
| | | protected Long getHostId(){ |
| | | protected Long getHostId() { |
| | | if (getUserId() == 9527) { |
| | | return null; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public static boolean isNumber(String str){ |
| | | for (int i = str.length();--i>=0;){ |
| | | if (!Character.isDigit(str.charAt(i))){ |
| | | public static boolean isNumber(String str) { |
| | | for (int i = str.length(); --i >= 0; ) { |
| | | if (!Character.isDigit(str.charAt(i))) { |
| | | return false; |
| | | } |
| | | } |