浏览代码

:zap: 代码更新

smallchill 7 年之前
父节点
当前提交
c0dfb664d9

+ 3 - 3
pom.xml

@@ -10,16 +10,16 @@
     <version>2.0.0.RC8</version>
 
     <properties>
-        <bladex.tool.version>2.0.0.RC8</bladex.tool.version>
+        <bladex.tool.version>2.0.0.RC9</bladex.tool.version>
 
         <java.version>1.8</java.version>
         <swagger.version>2.9.2</swagger.version>
         <swagger.models.version>1.5.21</swagger.models.version>
-        <swagger.bootstrapui.version>1.9.1</swagger.bootstrapui.version>
+        <swagger.bootstrapui.version>1.9.3</swagger.bootstrapui.version>
         <mybatis.plus.version>3.1.0</mybatis.plus.version>
         <protostuff.version>1.6.0</protostuff.version>
 
-        <spring.boot.version>2.1.3.RELEASE</spring.boot.version>
+        <spring.boot.version>2.1.4.RELEASE</spring.boot.version>
         <spring.platform.version>Cairo-SR7</spring.platform.version>
 
         <!-- 推荐使用Harbor -->

+ 0 - 6
src/main/java/org/springblade/common/cache/CacheNames.java

@@ -25,10 +25,4 @@ public interface CacheNames {
 
 	String NOTICE_ONE = "blade_dict:notice:one";
 
-	String DICT_VALUE = "blade_dict:dict:value";
-	String DICT_LIST = "blade_dict:dict:list";
-
-	String AUTH_ROUTES = "blade_menu:auth_routes";
-
-
 }

+ 70 - 0
src/main/java/org/springblade/common/cache/DictCache.java

@@ -0,0 +1,70 @@
+package org.springblade.common.cache;
+
+import org.springblade.core.cache.constant.CacheConstant;
+import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.SpringUtil;
+import org.springblade.core.tool.utils.StringPool;
+import org.springblade.modules.system.entity.Dict;
+import org.springblade.modules.system.service.IDictService;
+
+import java.util.List;
+
+/**
+ * DictCache
+ *
+ * @author Chill
+ */
+public class DictCache {
+
+	private static IDictService dictService;
+
+	static {
+		dictService = SpringUtil.getBean(IDictService.class);
+	}
+
+	/**
+	 * 获取字典值
+	 *
+	 * @param code    字典编号
+	 * @param dictKey 字典键
+	 * @return
+	 */
+	public static String getValue(String code, Integer dictKey) {
+		String dictValue = CacheUtil.get(CacheConstant.DICT_VALUE, code + StringPool.UNDERSCORE + dictKey, String.class);
+		if (Func.isEmpty(dictValue)) {
+			String value = dictService.getValue(code, dictKey);
+			if (Func.isNotEmpty(value)) {
+				CacheUtil.put(CacheConstant.DICT_VALUE, code + StringPool.UNDERSCORE + dictKey, value);
+				return value;
+			} else {
+				return StringPool.EMPTY;
+			}
+		} else {
+			return dictValue;
+		}
+	}
+
+	/**
+	 * 获取字典集合
+	 *
+	 * @param code 字典编号
+	 * @return
+	 */
+	@SuppressWarnings("unchecked")
+	public static List<Dict> getList(String code) {
+		Object dictList = CacheUtil.get(CacheConstant.DICT_LIST, code);
+		if (Func.isEmpty(dictList)) {
+			List<Dict> list = dictService.getList(code);
+			if (Func.isNotEmpty(list)) {
+				CacheUtil.put(CacheConstant.DICT_LIST, code, list);
+				return list;
+			} else {
+				return null;
+			}
+		} else {
+			return (List<Dict>) dictList;
+		}
+	}
+
+}

+ 75 - 0
src/main/java/org/springblade/common/cache/UserCache.java

@@ -0,0 +1,75 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.common.cache;
+
+import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.SpringUtil;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.modules.system.entity.User;
+import org.springblade.modules.system.service.IUserService;
+
+import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
+
+/**
+ * 系统缓存
+ *
+ * @author Chill
+ */
+public class UserCache {
+	private static final String USER_CACHE = "blade:user";
+	private static final String USER_CACHE_ID_ = "user:id";
+
+
+	private static IUserService userService;
+
+	static {
+		userService = SpringUtil.getBean(IUserService.class);
+	}
+
+	/**
+	 * 根据任务用户id获取用户信息
+	 *
+	 * @param taskUserId 任务用户id
+	 * @return
+	 */
+	public static User getUserByTaskUser(String taskUserId) {
+		int userId = Func.toInt(StringUtil.removePrefix(taskUserId, TASK_USR_PREFIX));
+		return getUser(userId);
+	}
+
+	/**
+	 * 获取用户名
+	 *
+	 * @param userId 用户id
+	 * @return
+	 */
+	public static User getUser(Integer userId) {
+		User user = CacheUtil.get(USER_CACHE, USER_CACHE_ID_ + userId, User.class);
+		if (Func.isEmpty(user)) {
+			User u = userService.getById(userId);
+			if (Func.isNotEmpty(u)) {
+				user = u;
+				if (Func.isNotEmpty(user)) {
+					CacheUtil.put(USER_CACHE, USER_CACHE_ID_ + userId, user);
+				}
+			}
+		}
+		return user;
+	}
+
+}

+ 23 - 0
src/main/java/org/springblade/common/constant/CommonConstant.java

@@ -40,6 +40,11 @@ public interface CommonConstant {
 	 */
 	String SENTINEL_PROD_ADDR = "10.211.55.5:8858";
 
+	/**
+	 * sentinel test 地址
+	 */
+	String SENTINEL_TEST_ADDR = "172.30.0.58:8858";
+
 	/**
 	 * sword 系统名
 	 */
@@ -65,4 +70,22 @@ public interface CommonConstant {
 	 */
 	String DEFAULT_PASSWORD = "123456";
 
+	/**
+	 * 动态获取sentinel地址
+	 *
+	 * @param profile 环境变量
+	 * @return addr
+	 */
+	static String sentinelAddr(String profile) {
+		switch (profile) {
+			case (AppConstant.PROD_CODE):
+				return SENTINEL_PROD_ADDR;
+			case (AppConstant.TEST_CODE):
+				return SENTINEL_TEST_ADDR;
+			default:
+				return SENTINEL_DEV_ADDR;
+		}
+	}
+
+
 }

+ 38 - 0
src/main/java/org/springblade/common/constant/DictConstant.java

@@ -0,0 +1,38 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.common.constant;
+
+/**
+ * 字典常量.
+ *
+ * @author zhuangqian
+ */
+public interface DictConstant {
+
+	String SEX_CODE = "sex";
+
+	String NOTICE_CODE = "notice";
+
+	String MENU_CATEGORY_CODE = "menu_category";
+
+	String BUTTON_FUNC_CODE = "button_func";
+
+	String YES_NO_CODE = "yes_no";
+
+	String FLOW_CATEGORY_CODE = "flow_category";
+
+}

+ 1 - 2
src/main/java/org/springblade/common/launch/LauncherServiceImpl.java

@@ -18,7 +18,6 @@ package org.springblade.common.launch;
 
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.core.auto.service.AutoService;
-import org.springblade.core.launch.constant.AppConstant;
 import org.springblade.core.launch.service.LauncherService;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 
@@ -35,7 +34,7 @@ public class LauncherServiceImpl implements LauncherService {
 	@Override
 	public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
 		Properties props = System.getProperties();
-		props.setProperty("spring.cloud.sentinel.transport.dashboard", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.SENTINEL_DEV_ADDR : CommonConstant.SENTINEL_PROD_ADDR);
+		props.setProperty("spring.cloud.sentinel.transport.dashboard", CommonConstant.sentinelAddr(profile));
 	}
 
 }

+ 1 - 1
src/main/java/org/springblade/common/tool/CommonUtil.java → src/main/java/org/springblade/common/utils/CommonUtil.java

@@ -14,7 +14,7 @@
  *  this software without specific prior written permission.
  *  Author: Chill 庄骞 (smallchill@163.com)
  */
-package org.springblade.common.tool;
+package org.springblade.common.utils;
 
 /**
  * 通用工具类

+ 2 - 5
src/main/java/org/springblade/modules/system/controller/DictController.java

@@ -20,9 +20,7 @@ import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
-import org.springblade.core.secure.annotation.PreAuth;
 import org.springblade.core.tool.api.R;
-import org.springblade.core.tool.constant.RoleConstant;
 import org.springblade.core.tool.node.INode;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.system.entity.Dict;
@@ -37,8 +35,8 @@ import javax.validation.Valid;
 import java.util.List;
 import java.util.Map;
 
-import static org.springblade.common.cache.CacheNames.DICT_LIST;
-import static org.springblade.common.cache.CacheNames.DICT_VALUE;
+import static org.springblade.core.cache.constant.CacheConstant.DICT_LIST;
+import static org.springblade.core.cache.constant.CacheConstant.DICT_VALUE;
 
 /**
  * 控制器
@@ -50,7 +48,6 @@ import static org.springblade.common.cache.CacheNames.DICT_VALUE;
 @RequestMapping("/blade-system/dict")
 @ApiIgnore
 @Api(value = "字典", tags = "字典")
-@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 public class DictController extends BladeController {
 
 	private IDictService dictService;

+ 1 - 1
src/main/java/org/springblade/modules/system/controller/MenuController.java

@@ -39,7 +39,7 @@ import javax.validation.Valid;
 import java.util.List;
 import java.util.Map;
 
-import static org.springblade.common.cache.CacheNames.AUTH_ROUTES;
+import static org.springblade.core.cache.constant.CacheConstant.AUTH_ROUTES;
 
 /**
  * 控制器

+ 32 - 5
src/main/java/org/springblade/modules/system/controller/UserController.java

@@ -41,6 +41,7 @@ import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
 import javax.validation.Valid;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -52,7 +53,6 @@ import java.util.Map;
 @RestController
 @RequestMapping("blade-user")
 @AllArgsConstructor
-@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 public class UserController {
 
 	private IUserService userService;
@@ -64,6 +64,7 @@ public class UserController {
 	 */
 	@ApiOperation(value = "查看详情", notes = "传入id", position = 1)
 	@GetMapping("/detail")
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R<UserVO> detail(User user) {
 		User detail = userService.getOne(Condition.getQueryWrapper(user));
 		UserWrapper userWrapper = new UserWrapper(userService, dictService);
@@ -79,6 +80,7 @@ public class UserController {
 		@ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
 	})
 	@ApiOperation(value = "列表", notes = "传入account和realName", position = 2)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R<IPage<UserVO>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query, BladeUser bladeUser) {
 		QueryWrapper<User> queryWrapper = Condition.getQueryWrapper(user, User.class);
 		IPage<User> pages = userService.page(Condition.getPage(query), (!bladeUser.getTenantCode().equals(BladeConstant.ADMIN_TENANT_CODE)) ? queryWrapper.lambda().eq(User::getTenantCode, bladeUser.getTenantCode()) : queryWrapper);
@@ -91,6 +93,7 @@ public class UserController {
 	 */
 	@PostMapping("/submit")
 	@ApiOperation(value = "新增或修改", notes = "传入User", position = 3)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R submit(@Valid @RequestBody User user) {
 		return R.status(userService.submit(user));
 	}
@@ -99,7 +102,8 @@ public class UserController {
 	 * 修改
 	 */
 	@PostMapping("/update")
-	@ApiOperation(value = "修改", notes = "传入User", position = 3)
+	@ApiOperation(value = "修改", notes = "传入User", position = 4)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R update(@Valid @RequestBody User user) {
 		return R.status(userService.updateById(user));
 	}
@@ -108,7 +112,8 @@ public class UserController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "删除", notes = "传入地基和", position = 4)
+	@ApiOperation(value = "删除", notes = "传入地基和", position = 5)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R remove(@RequestParam String ids) {
 		return R.status(userService.deleteLogic(Func.toIntList(ids)));
 	}
@@ -121,18 +126,40 @@ public class UserController {
 	 * @return
 	 */
 	@PostMapping("/grant")
-	@ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合", position = 5)
+	@ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合", position = 6)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R grant(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds,
 				   @ApiParam(value = "roleId集合", required = true) @RequestParam String roleIds) {
 		boolean temp = userService.grant(userIds, roleIds);
 		return R.status(temp);
 	}
 
+	/**
+	 * 重置密码
+	 *
+	 * @param userIds
+	 * @return
+	 */
 	@PostMapping("/reset-password")
-	@ApiOperation(value = "初始化密码", notes = "传入userId集合", position = 5)
+	@ApiOperation(value = "初始化密码", notes = "传入userId集合", position = 7)
+	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
 	public R resetPassword(@ApiParam(value = "userId集合", required = true) @RequestParam String userIds) {
 		boolean temp = userService.resetPassword(userIds);
 		return R.status(temp);
 	}
 
+	/**
+	 * 用户列表
+	 *
+	 * @param user
+	 * @return
+	 */
+	@GetMapping("/user-list")
+	@ApiOperation(value = "用户列表", notes = "传入user", position = 8)
+	public R<List<User>> userList(User user) {
+		List<User> list = userService.list(Condition.getQueryWrapper(user));
+		return R.data(list);
+	}
+
+
 }

+ 2 - 1
src/main/java/org/springblade/modules/system/mapper/MenuMapper.xml

@@ -109,7 +109,7 @@
     </select>
 
     <select id="grantTree" resultMap="treeNodeResultMap">
-        select id, parent_id, name as title, id as 'value', id as 'key' from blade_menu where is_deleted = 0
+        select id, parent_id, name as title, id as 'value', id as 'key' from blade_menu where is_deleted = 0 order by sort
     </select>
 
     <select id="grantTreeByRole" resultMap="treeNodeResultMap">
@@ -125,6 +125,7 @@
                 #{item}
             </foreach> )
           )
+        order by sort
     </select>
 
     <select id="authRoutes" resultType="org.springblade.modules.system.dto.MenuDTO">

+ 3 - 3
src/main/java/org/springblade/modules/system/service/impl/DictServiceImpl.java

@@ -34,8 +34,8 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 
-import static org.springblade.common.cache.CacheNames.DICT_LIST;
-import static org.springblade.common.cache.CacheNames.DICT_VALUE;
+import static org.springblade.core.cache.constant.CacheConstant.DICT_LIST;
+import static org.springblade.core.cache.constant.CacheConstant.DICT_VALUE;
 
 /**
  * 服务实现类
@@ -68,7 +68,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
 	}
 
 	@Override
-	@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE})
+	@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE}, allEntries = true)
 	public boolean submit(Dict dict) {
 		LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
 		Integer cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));

+ 1 - 1
src/main/java/org/springblade/modules/system/service/impl/MenuServiceImpl.java

@@ -39,7 +39,7 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.stream.Collectors;
 
-import static org.springblade.common.cache.CacheNames.AUTH_ROUTES;
+import static org.springblade.core.cache.constant.CacheConstant.AUTH_ROUTES;
 
 /**
  * 服务实现类

+ 30 - 11
src/main/resources/ehcache.xml

@@ -13,45 +13,64 @@
 
     <!-- =================业务缓存================= -->
     <!-- 缓存半小时 -->
-    <cache name="blade_notice:one"
+    <cache name="blade:notice:one"
            maxElementsInMemory="10000"
            maxElementsOnDisk="100000"
            eternal="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!-- 缓存半小时 -->
-    <cache name="blade_dict:value"
+    <cache name="blade:dict:value"
            maxElementsInMemory="10000"
            maxElementsOnDisk="100000"
            eternal="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!-- 缓存半小时 -->
-    <cache name="blade_dict:list"
+    <cache name="blade:dict:list"
            maxElementsInMemory="10000"
            maxElementsOnDisk="100000"
            eternal="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!-- 缓存半小时 -->
-    <cache name="blade_menu:auth_routes"
+    <cache name="blade:menu:auth:routes"
            maxElementsInMemory="10000"
            maxElementsOnDisk="100000"
            eternal="false"
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
+    <!-- 缓存半小时 -->
+    <cache name="blade:user"
+           maxElementsInMemory="10000"
+           maxElementsOnDisk="100000"
+           eternal="false"
+           timeToIdleSeconds="1800"
+           timeToLiveSeconds="1800"
+           overflowToDisk="false"
+           diskPersistent="false"/>
+
+    <!-- 缓存半小时 -->
+    <cache name="flow:process"
+           maxElementsInMemory="10000"
+           maxElementsOnDisk="100000"
+           eternal="false"
+           timeToIdleSeconds="1800"
+           timeToLiveSeconds="1800"
+           overflowToDisk="false"
+           diskPersistent="false"/>
 
     <!-- =================系统缓存================= -->
     <!-- 缓存半小时 -->
@@ -62,7 +81,7 @@
            timeToIdleSeconds="1800"
            timeToLiveSeconds="1800"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!-- 缓存一小时 -->
     <cache name="hour"
@@ -72,7 +91,7 @@
            timeToIdleSeconds="3600"
            timeToLiveSeconds="3600"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!-- 缓存一天 -->
     <cache name="one:day"
@@ -82,7 +101,7 @@
            timeToIdleSeconds="86400"
            timeToLiveSeconds="86400"
            overflowToDisk="false"
-           diskPersistent="false" />
+           diskPersistent="false"/>
 
     <!--
         name:缓存名称。