Przeglądaj źródła

Merge branch 'master' of http://62.234.61.92:3000/wjm/mec-cloud_IntelligentManufacturing_CRM

lph 1 rok temu
rodzic
commit
8a775fba6a

+ 42 - 56
zkqy-admin/src/main/java/com/zkqy/web/controller/system/SysUserController.java

@@ -1,5 +1,6 @@
 package com.zkqy.web.controller.system;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -32,13 +33,12 @@ import com.zkqy.system.service.ISysUserService;
 
 /**
  * 用户信息
- * 
+ *
  * @author zkqy
  */
 @RestController
 @RequestMapping("/system/user")
-public class SysUserController extends BaseController
-{
+public class SysUserController extends BaseController {
     @Autowired
     private ISysUserService userService;
 
@@ -56,8 +56,7 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:list')")
     @GetMapping("/list")
-    public TableDataInfo list(SysUser user)
-    {
+    public TableDataInfo list(SysUser user) {
         startPage();
         if (getLoginUser().isTenantAdmin()) {
             user.setTenantId(getTenantId());
@@ -66,11 +65,22 @@ public class SysUserController extends BaseController
         return getDataTable(list);
     }
 
+    @GetMapping("/userListByTenantId")
+    public TableDataInfo listByTenantId(SysUser user) {
+        //  如果当前租户Id为null则不执行,只有租户管理员才会调用此接口
+        if (user.getTenantId() == null) {
+            return getDataTable(new ArrayList<>());
+        }
+        startPage();
+        List<SysUser> list = userService.selectUserList(user);
+        return getDataTable(list);
+    }
+
+
     @Log(title = "用户管理", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('system:user:export')")
     @PostMapping("/export")
-    public void export(HttpServletResponse response, SysUser user)
-    {
+    public void export(HttpServletResponse response, SysUser user) {
         List<SysUser> list = userService.selectUserList(user);
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         util.exportExcel(response, list, "用户数据");
@@ -79,8 +89,7 @@ public class SysUserController extends BaseController
     @Log(title = "用户管理", businessType = BusinessType.IMPORT)
     @PreAuthorize("@ss.hasPermi('system:user:import')")
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
-    {
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         List<SysUser> userList = util.importExcel(file.getInputStream());
         String operName = getUsername();
@@ -89,8 +98,7 @@ public class SysUserController extends BaseController
     }
 
     @PostMapping("/importTemplate")
-    public void importTemplate(HttpServletResponse response)
-    {
+    public void importTemplate(HttpServletResponse response) {
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         util.importTemplateExcel(response, "用户数据");
     }
@@ -99,28 +107,26 @@ public class SysUserController extends BaseController
      * 根据用户编号获取详细信息
      */
     @PreAuthorize("@ss.hasPermi('system:user:query')")
-    @GetMapping(value = { "/", "/{userId}" })
-    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
-    {
+    @GetMapping(value = {"/", "/{userId}"})
+    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
         userService.checkUserDataScope(userId);
         AjaxResult ajax = AjaxResult.success();
         List<SysRole> roles = roleService.selectRoleAll();
         roles.forEach(r -> {
-            if(r.getTenantId() == null){
+            if (r.getTenantId() == null) {
                 r.setTenantId(0L);
             }
         });
         List<SysPost> sysPosts = postService.selectPostAll();
         sysPosts.forEach(s -> {
-            if (s.getTenantId() == null){
+            if (s.getTenantId() == null) {
                 s.setTenantId(0L);
             }
         });
 
         ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin() && r.getTenantId().equals(getTenantId())).collect(Collectors.toList()));
         ajax.put("posts", sysPosts.stream().filter(p -> p.getTenantId().equals(getTenantId())).collect(Collectors.toList()));
-        if (StringUtils.isNotNull(userId))
-        {
+        if (StringUtils.isNotNull(userId)) {
             SysUser sysUser = userService.selectUserById(userId);
             ajax.put(AjaxResult.DATA_TAG, sysUser);
             ajax.put("postIds", postService.selectPostListByUserId(userId));
@@ -135,18 +141,12 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:add')")
     @Log(title = "用户管理", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@Validated @RequestBody SysUser user)
-    {
-        if (!userService.checkUserNameUnique(user))
-        {
+    public AjaxResult add(@Validated @RequestBody SysUser user) {
+        if (!userService.checkUserNameUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
         }
         user.setCreateBy(getUsername());
@@ -164,20 +164,14 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@Validated @RequestBody SysUser user)
-    {
+    public AjaxResult edit(@Validated @RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
-        if (!userService.checkUserNameUnique(user))
-        {
+        if (!userService.checkUserNameUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
         }
         user.setUpdateBy(getUsername());
@@ -190,10 +184,8 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:remove')")
     @Log(title = "用户管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{userIds}")
-    public AjaxResult remove(@PathVariable Long[] userIds)
-    {
-        if (ArrayUtils.contains(userIds, getUserId()))
-        {
+    public AjaxResult remove(@PathVariable Long[] userIds) {
+        if (ArrayUtils.contains(userIds, getUserId())) {
             return error("当前用户不能删除");
         }
         return toAjax(userService.deleteUserByIds(userIds));
@@ -205,8 +197,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping("/resetPwd")
-    public AjaxResult resetPwd(@RequestBody SysUser user)
-    {
+    public AjaxResult resetPwd(@RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
@@ -220,8 +211,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
-    public AjaxResult changeStatus(@RequestBody SysUser user)
-    {
+    public AjaxResult changeStatus(@RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         user.setUpdateBy(getUsername());
@@ -233,8 +223,7 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:query')")
     @GetMapping("/authRole/{userId}")
-    public AjaxResult authRole(@PathVariable("userId") Long userId)
-    {
+    public AjaxResult authRole(@PathVariable("userId") Long userId) {
         AjaxResult ajax = AjaxResult.success();
         SysUser user = userService.selectUserById(userId);
         List<SysRole> roles = roleService.selectRolesByUserId(userId);
@@ -248,8 +237,7 @@ public class SysUserController extends BaseController
      */
     @Anonymous
     @GetMapping("/roleKeyByUserId/{userId}")
-    public AjaxResult roleKeyByUserId(@PathVariable("userId") Long userId)
-    {
+    public AjaxResult roleKeyByUserId(@PathVariable("userId") Long userId) {
         AjaxResult ajax = AjaxResult.success();
         String[] strings = roleService.selectRolesKeyByUserId(userId);
         ajax.put("rolesKey", JSON.toJSONString(strings));
@@ -262,8 +250,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.GRANT)
     @PutMapping("/authRole")
-    public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
-    {
+    public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
         userService.checkUserDataScope(userId);
         userService.insertUserAuth(userId, roleIds);
         return success();
@@ -274,8 +261,7 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:list')")
     @GetMapping("/deptTree")
-    public AjaxResult deptTree(SysDept dept)
-    {
+    public AjaxResult deptTree(SysDept dept) {
         if (getLoginUser().isTenantAdmin()) {
             dept.setTenantId(getTenantId());
         }
@@ -286,7 +272,7 @@ public class SysUserController extends BaseController
      * 查询所有用户
      */
     @GetMapping("/selectAllUser")
-    public AjaxResult selectAllUser(){
+    public AjaxResult selectAllUser() {
         return AjaxResult.success(userService.selectAllUser());
     }
 
@@ -294,7 +280,7 @@ public class SysUserController extends BaseController
      * 查询这组用户中是否存在真实用户
      */
     @GetMapping("/selectUserByUserIds/{userIds}")
-    public AjaxResult selectUserByUserIds(@PathVariable("userIds") String userIds){
+    public AjaxResult selectUserByUserIds(@PathVariable("userIds") String userIds) {
         String[] userIdsArray = userIds.split(",");
         List<Long> userIdsList = Arrays.stream(userIdsArray)
                 .map(Long::valueOf)

+ 51 - 74
zkqy-framework/src/main/java/com/zkqy/framework/aspectj/LogAspect.java

@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.lang3.ArrayUtils;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.AfterReturning;
@@ -32,27 +33,29 @@ import com.zkqy.system.domain.SysOperLog;
 
 /**
  * 操作日志记录处理
- * 
+ *
  * @author zkqy
  */
 @Aspect
 @Component
-public class LogAspect
-{
+public class LogAspect {
     private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
 
-    /** 排除敏感属性字段 */
-    public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
+    /**
+     * 排除敏感属性字段
+     */
+    public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"};
 
-    /** 计算操作消耗时间 */
+    /**
+     * 计算操作消耗时间
+     */
     private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
 
     /**
      * 处理请求前执行
      */
     @Before(value = "@annotation(controllerLog)")
-    public void boBefore(JoinPoint joinPoint, Log controllerLog)
-    {
+    public void boBefore(JoinPoint joinPoint, Log controllerLog) {
         TIME_THREADLOCAL.set(System.currentTimeMillis());
     }
 
@@ -62,44 +65,45 @@ public class LogAspect
      * @param joinPoint 切点
      */
     @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult")
-    public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult)
-    {
+    public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) {
         handleLog(joinPoint, controllerLog, null, jsonResult);
     }
 
     /**
      * 拦截异常操作
-     * 
+     *
      * @param joinPoint 切点
-     * @param e 异常
+     * @param e         异常
      */
     @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e")
-    public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e)
-    {
+    public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) {
         handleLog(joinPoint, controllerLog, e, null);
     }
 
-    protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult)
-    {
-        try
-        {
+    protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
+        try {
             // 获取当前的用户
             LoginUser loginUser = SecurityUtils.getLoginUser();
 
             // *========数据库日志=========*//
             SysOperLog operLog = new SysOperLog();
+            Long tenantId;
+            try {
+                tenantId = SecurityUtils.getTenantId();
+            } catch (Exception exception) {
+                tenantId = 0L;  // 0L 表示当前是admin(租户信息表id自增「自增id不会从0开始」)
+            }
+            operLog.setTenantId(tenantId);
             operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
             // 请求的地址
             String ip = IpUtils.getIpAddr();
             operLog.setOperIp(ip);
             operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
-            if (loginUser != null)
-            {
+            if (loginUser != null) {
                 operLog.setOperName(loginUser.getUsername());
             }
 
-            if (e != null)
-            {
+            if (e != null) {
                 operLog.setStatus(BusinessStatus.FAIL.ordinal());
                 operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
             }
@@ -115,28 +119,23 @@ public class LogAspect
             operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
             // 保存数据库
             AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
-        }
-        catch (Exception exp)
-        {
+        } catch (Exception exp) {
             // 记录本地异常日志
             log.error("异常信息:{}", exp.getMessage());
             exp.printStackTrace();
-        }
-        finally
-        {
+        } finally {
             TIME_THREADLOCAL.remove();
         }
     }
 
     /**
      * 获取注解中对方法的描述信息 用于Controller层注解
-     * 
-     * @param log 日志
+     *
+     * @param log     日志
      * @param operLog 操作日志
      * @throws Exception
      */
-    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception
-    {
+    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception {
         // 设置action动作
         operLog.setBusinessType(log.businessType().ordinal());
         // 设置标题
@@ -144,36 +143,30 @@ public class LogAspect
         // 设置操作人类别
         operLog.setOperatorType(log.operatorType().ordinal());
         // 是否需要保存request,参数和值
-        if (log.isSaveRequestData())
-        {
+        if (log.isSaveRequestData()) {
             // 获取参数的信息,传入到数据库中。
             setRequestValue(joinPoint, operLog, log.excludeParamNames());
         }
         // 是否需要保存response,参数和值
-        if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
-        {
+        if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) {
             operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
         }
     }
 
     /**
      * 获取请求的参数,放到log中
-     * 
+     *
      * @param operLog 操作日志
      * @throws Exception 异常
      */
-    private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception
-    {
+    private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception {
         Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
         String requestMethod = operLog.getRequestMethod();
         if (StringUtils.isEmpty(paramsMap)
-                && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)))
-        {
+                && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))) {
             String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
             operLog.setOperParam(StringUtils.substring(params, 0, 2000));
-        }
-        else
-        {
+        } else {
             operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
         }
     }
@@ -181,22 +174,15 @@ public class LogAspect
     /**
      * 参数拼装
      */
-    private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames)
-    {
+    private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) {
         String params = "";
-        if (paramsArray != null && paramsArray.length > 0)
-        {
-            for (Object o : paramsArray)
-            {
-                if (StringUtils.isNotNull(o) && !isFilterObject(o))
-                {
-                    try
-                    {
+        if (paramsArray != null && paramsArray.length > 0) {
+            for (Object o : paramsArray) {
+                if (StringUtils.isNotNull(o) && !isFilterObject(o)) {
+                    try {
                         String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter(excludeParamNames));
                         params += jsonObj.toString() + " ";
-                    }
-                    catch (Exception e)
-                    {
+                    } catch (Exception e) {
                     }
                 }
             }
@@ -207,38 +193,29 @@ public class LogAspect
     /**
      * 忽略敏感属性
      */
-    public PropertyPreExcludeFilter excludePropertyPreFilter(String[] excludeParamNames)
-    {
+    public PropertyPreExcludeFilter excludePropertyPreFilter(String[] excludeParamNames) {
         return new PropertyPreExcludeFilter().addExcludes(ArrayUtils.addAll(EXCLUDE_PROPERTIES, excludeParamNames));
     }
 
     /**
      * 判断是否需要过滤的对象。
-     * 
+     *
      * @param o 对象信息。
      * @return 如果是需要过滤的对象,则返回true;否则返回false。
      */
     @SuppressWarnings("rawtypes")
-    public boolean isFilterObject(final Object o)
-    {
+    public boolean isFilterObject(final Object o) {
         Class<?> clazz = o.getClass();
-        if (clazz.isArray())
-        {
+        if (clazz.isArray()) {
             return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
-        }
-        else if (Collection.class.isAssignableFrom(clazz))
-        {
+        } else if (Collection.class.isAssignableFrom(clazz)) {
             Collection collection = (Collection) o;
-            for (Object value : collection)
-            {
+            for (Object value : collection) {
                 return value instanceof MultipartFile;
             }
-        }
-        else if (Map.class.isAssignableFrom(clazz))
-        {
+        } else if (Map.class.isAssignableFrom(clazz)) {
             Map map = (Map) o;
-            for (Object value : map.entrySet())
-            {
+            for (Object value : map.entrySet()) {
                 Map.Entry entry = (Map.Entry) value;
                 return entry.getValue() instanceof MultipartFile;
             }

+ 63 - 48
zkqy-system/src/main/java/com/zkqy/system/domain/SysLogininfor.java

@@ -1,6 +1,7 @@
 package com.zkqy.system.domain;
 
 import java.util.Date;
+
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.zkqy.common.annotation.Excel;
 import com.zkqy.common.annotation.Excel.ColumnType;
@@ -8,137 +9,151 @@ import com.zkqy.common.core.domain.BaseEntity;
 
 /**
  * 系统访问记录表 sys_logininfor
- * 
+ *
  * @author zkqy
  */
-public class SysLogininfor extends BaseEntity
-{
+public class SysLogininfor extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** ID */
+    /**
+     * ID
+     */
     @Excel(name = "序号", cellType = ColumnType.NUMERIC)
     private Long infoId;
 
-    /** 用户账号 */
+    /**
+     * 用户账号
+     */
     @Excel(name = "用户账号")
     private String userName;
 
-    /** 登录状态 0成功 1失败 */
+    /**
+     * 登录状态 0成功 1失败
+     */
     @Excel(name = "登录状态", readConverterExp = "0=成功,1=失败")
     private String status;
 
-    /** 登录IP地址 */
+    /**
+     * 登录IP地址
+     */
     @Excel(name = "登录地址")
     private String ipaddr;
 
-    /** 登录地点 */
+    /**
+     * 登录地点
+     */
     @Excel(name = "登录地点")
     private String loginLocation;
 
-    /** 浏览器类型 */
+    /**
+     * 浏览器类型
+     */
     @Excel(name = "浏览器")
     private String browser;
 
-    /** 操作系统 */
+    /**
+     * 操作系统
+     */
     @Excel(name = "操作系统")
     private String os;
 
-    /** 提示消息 */
+    /**
+     * 提示消息
+     */
     @Excel(name = "提示消息")
     private String msg;
 
-    /** 访问时间 */
+    /**
+     * 访问时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date loginTime;
 
-    public Long getInfoId()
-    {
+    /**
+     * 租户ID
+     *
+     * @return
+     */
+    private Long tenantId;
+
+    public Long getInfoId() {
         return infoId;
     }
 
-    public void setInfoId(Long infoId)
-    {
+    public void setInfoId(Long infoId) {
         this.infoId = infoId;
     }
 
-    public String getUserName()
-    {
+    public String getUserName() {
         return userName;
     }
 
-    public void setUserName(String userName)
-    {
+    public void setUserName(String userName) {
         this.userName = userName;
     }
 
-    public String getStatus()
-    {
+    public String getStatus() {
         return status;
     }
 
-    public void setStatus(String status)
-    {
+    public void setStatus(String status) {
         this.status = status;
     }
 
-    public String getIpaddr()
-    {
+    public String getIpaddr() {
         return ipaddr;
     }
 
-    public void setIpaddr(String ipaddr)
-    {
+    public void setIpaddr(String ipaddr) {
         this.ipaddr = ipaddr;
     }
 
-    public String getLoginLocation()
-    {
+    public String getLoginLocation() {
         return loginLocation;
     }
 
-    public void setLoginLocation(String loginLocation)
-    {
+    public void setLoginLocation(String loginLocation) {
         this.loginLocation = loginLocation;
     }
 
-    public String getBrowser()
-    {
+    public String getBrowser() {
         return browser;
     }
 
-    public void setBrowser(String browser)
-    {
+    public void setBrowser(String browser) {
         this.browser = browser;
     }
 
-    public String getOs()
-    {
+    public String getOs() {
         return os;
     }
 
-    public void setOs(String os)
-    {
+    public void setOs(String os) {
         this.os = os;
     }
 
-    public String getMsg()
-    {
+    public String getMsg() {
         return msg;
     }
 
-    public void setMsg(String msg)
-    {
+    public void setMsg(String msg) {
         this.msg = msg;
     }
 
-    public Date getLoginTime()
-    {
+    public Date getLoginTime() {
         return loginTime;
     }
 
-    public void setLoginTime(Date loginTime)
-    {
+    public void setLoginTime(Date loginTime) {
         this.loginTime = loginTime;
     }
+
+    public Long getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Long tenantId) {
+        this.tenantId = tenantId;
+    }
 }

+ 13 - 0
zkqy-system/src/main/java/com/zkqy/system/domain/SysOperLog.java

@@ -87,6 +87,11 @@ public class SysOperLog extends BaseEntity
     @Excel(name = "消耗时间", suffix = "毫秒")
     private Long costTime;
 
+    /**
+     * 租户ID
+     */
+    private Long tenantId;
+
     public Long getOperId()
     {
         return operId;
@@ -266,4 +271,12 @@ public class SysOperLog extends BaseEntity
     {
         this.costTime = costTime;
     }
+
+    public Long getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Long tenantId) {
+        this.tenantId = tenantId;
+    }
 }

+ 18 - 14
zkqy-system/src/main/java/com/zkqy/system/service/impl/SysLogininforServiceImpl.java

@@ -1,6 +1,8 @@
 package com.zkqy.system.service.impl;
 
 import java.util.List;
+
+import com.zkqy.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.zkqy.system.domain.SysLogininfor;
@@ -9,48 +11,51 @@ import com.zkqy.system.service.ISysLogininforService;
 
 /**
  * 系统访问日志情况信息 服务层处理
- * 
+ *
  * @author zkqy
  */
 @Service
-public class SysLogininforServiceImpl implements ISysLogininforService
-{
+public class SysLogininforServiceImpl implements ISysLogininforService {
 
     @Autowired
     private SysLogininforMapper logininforMapper;
 
     /**
      * 新增系统登录日志
-     * 
+     *
      * @param logininfor 访问日志对象
      */
     @Override
-    public void insertLogininfor(SysLogininfor logininfor)
-    {
+    public void insertLogininfor(SysLogininfor logininfor) {
+        Long tenantId;
+        try {
+            tenantId = SecurityUtils.getTenantId();
+        } catch (Exception exception) {
+            tenantId = 0L;  // 0L 表示当前是admin(租户信息表id自增「自增id不会从0开始」)
+        }
+        logininfor.setTenantId(tenantId);
         logininforMapper.insertLogininfor(logininfor);
     }
 
     /**
      * 查询系统登录日志集合
-     * 
+     *
      * @param logininfor 访问日志对象
      * @return 登录记录集合
      */
     @Override
-    public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor)
-    {
+    public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor) {
         return logininforMapper.selectLogininforList(logininfor);
     }
 
     /**
      * 批量删除系统登录日志
-     * 
+     *
      * @param infoIds 需要删除的登录日志ID
      * @return 结果
      */
     @Override
-    public int deleteLogininforByIds(Long[] infoIds)
-    {
+    public int deleteLogininforByIds(Long[] infoIds) {
         return logininforMapper.deleteLogininforByIds(infoIds);
     }
 
@@ -58,8 +63,7 @@ public class SysLogininforServiceImpl implements ISysLogininforService
      * 清空系统登录日志
      */
     @Override
-    public void cleanLogininfor()
-    {
+    public void cleanLogininfor() {
         logininforMapper.cleanLogininfor();
     }
 }

+ 8 - 0
zkqy-system/src/main/java/com/zkqy/system/service/impl/SysTenantServiceImpl.java

@@ -1406,6 +1406,8 @@ public class SysTenantServiceImpl implements ISysTenantService
         String encryptHex = des.encryptHex(dataStr);
         //生成激活码操作
         activationCodeLog("生成激活码");
+        //生成了就往
+        stringRedisTemplate.opsForSet().add( "activeCode", encryptHex);
         return AjaxResult.success(encryptHex);
     }
 
@@ -1418,6 +1420,12 @@ public class SysTenantServiceImpl implements ISysTenantService
      */
     @Override
     public AjaxResult activationOperation(String tenantId, String activationCode) throws Exception {
+        //是否是一个假的
+        Boolean activeCode1 = stringRedisTemplate.opsForSet().isMember("activeCode", activationCode);
+        if(activeCode1==false){
+            return AjaxResult.error("请输入系统生成的激活码!!!");
+        }
+        //是否使用过
         String activeCode="active:code:"+activationCode;//魔法值后期抽出来
         String strCode = stringRedisTemplate.opsForValue().get(activeCode);
         if(StringUtils.isNotEmpty(strCode)){

+ 22 - 17
zkqy-system/src/main/resources/mapper/system/SysLogininforMapper.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+		PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+		"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zkqy.system.mapper.SysLogininforMapper">
 
 	<resultMap type="SysLogininfor" id="SysLogininforResult">
@@ -14,16 +14,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="os"            column="os"                />
 		<result property="msg"           column="msg"               />
 		<result property="loginTime"     column="login_time"        />
+		<result property="tenantId"     column="tenant_id"        />
 	</resultMap>
 
 	<insert id="insertLogininfor" parameterType="SysLogininfor">
-		insert into sys_logininfor (user_name, status, ipaddr, login_location, browser, os, msg, login_time)
-		values (#{userName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate())
+		insert into sys_logininfor (user_name, status, ipaddr, login_location, browser, os, msg, login_time,tenant_id)
+		values (#{userName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, sysdate(),#{tenantId})
 	</insert>
-	
+
 	<select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
-		select info_id, user_name, ipaddr, login_location, browser, os, status, msg, login_time from sys_logininfor
+		select info_id, user_name, ipaddr, login_location, browser, os, status, msg, login_time,tenant_id from
+		sys_logininfor
 		<where>
+			<if test="tenantId != null and tenantId != ''">
+				AND tenant_id = #{tenantId}
+			</if>
 			<if test="ipaddr != null and ipaddr != ''">
 				AND ipaddr like concat('%', #{ipaddr}, '%')
 			</if>
@@ -42,16 +47,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		</where>
 		order by info_id desc
 	</select>
-	
+
 	<delete id="deleteLogininforByIds" parameterType="Long">
- 		delete from sys_logininfor where info_id in
- 		<foreach collection="array" item="infoId" open="(" separator="," close=")">
- 			#{infoId}
-        </foreach> 
- 	</delete>
-    
-    <update id="cleanLogininfor">
-        truncate table sys_logininfor
-    </update>
-    
+		delete from sys_logininfor where info_id in
+		<foreach collection="array" item="infoId" open="(" separator="," close=")">
+			#{infoId}
+		</foreach>
+	</delete>
+
+	<update id="cleanLogininfor">
+		truncate table sys_logininfor
+	</update>
+
 </mapper> 

+ 28 - 24
zkqy-system/src/main/resources/mapper/system/SysOperLogMapper.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+		PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+		"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zkqy.system.mapper.SysOperLogMapper">
 
 	<resultMap type="SysOperLog" id="SysOperLogResult">
@@ -22,21 +22,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="errorMsg"       column="error_msg"      />
 		<result property="operTime"       column="oper_time"      />
 		<result property="costTime"       column="cost_time"      />
+		<result property="tenantId"       column="tenant_id"      />
 	</resultMap>
 
 	<sql id="selectOperLogVo">
-        select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time, cost_time
-        from sys_oper_log
-    </sql>
-    
+		select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time, cost_time,tenant_id
+		from sys_oper_log
+	</sql>
+
 	<insert id="insertOperlog" parameterType="SysOperLog">
-		insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, cost_time, oper_time)
-        values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate())
+		insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, cost_time, oper_time,tenant_id)
+		values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate(),#{tenantId})
 	</insert>
-	
+
 	<select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult">
 		<include refid="selectOperLogVo"/>
 		<where>
+			<if test="tenantId != null and tenantId != ''">
+				AND tenant_id = #{tenantId}
+			</if>
 			<if test="title != null and title != ''">
 				AND title like concat('%', #{title}, '%')
 			</if>
@@ -44,10 +48,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 				AND business_type = #{businessType}
 			</if>
 			<if test="businessTypes != null and businessTypes.length > 0">
-			    AND business_type in
-			    <foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
-		 			#{businessType}
-		        </foreach> 
+				AND business_type in
+				<foreach collection="businessTypes" item="businessType" open="(" separator="," close=")">
+					#{businessType}
+				</foreach>
 			</if>
 			<if test="status != null">
 				AND status = #{status}
@@ -64,21 +68,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		</where>
 		order by oper_id desc
 	</select>
-	
+
 	<delete id="deleteOperLogByIds" parameterType="Long">
- 		delete from sys_oper_log where oper_id in
- 		<foreach collection="array" item="operId" open="(" separator="," close=")">
- 			#{operId}
-        </foreach> 
- 	</delete>
- 	
- 	<select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult">
+		delete from sys_oper_log where oper_id in
+		<foreach collection="array" item="operId" open="(" separator="," close=")">
+			#{operId}
+		</foreach>
+	</delete>
+
+	<select id="selectOperLogById" parameterType="Long" resultMap="SysOperLogResult">
 		<include refid="selectOperLogVo"/>
 		where oper_id = #{operId}
 	</select>
-	
+
 	<update id="cleanOperLog">
-        truncate table sys_oper_log
-    </update>
+		truncate table sys_oper_log
+	</update>
 
 </mapper> 

+ 3 - 0
zkqy-system/src/main/resources/mapper/system/SysPostMapper.xml

@@ -38,6 +38,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="tenantId != null">
 				AND tenant_id = #{tenantId}
 			</if>
+			<if test="tenantId == null">
+				and tenant_id is null
+			</if>
 		</where>
 	</select>
 	

+ 250 - 0
zkqy-system/src/main/resources/sql/initialize_sys_tenant_menu.json

@@ -1148,5 +1148,255 @@
         "children": [],
         "tenantName": null,
         "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:28:04",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1092,
+        "menuName": "日志管理",
+        "parentName": null,
+        "parentId": 0,
+        "orderNum": 6,
+        "path": "log",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "M",
+        "visible": "0",
+        "status": "0",
+        "perms": null,
+        "icon": "log",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:29:50",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1093,
+        "menuName": "操作日志",
+        "parentName": null,
+        "parentId": 1092,
+        "orderNum": 1,
+        "path": "operlog",
+        "component": "monitor/operlog/index",
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "C",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:operlog:list",
+        "icon": "form",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:32:45",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1095,
+        "menuName": "操作查询",
+        "parentName": null,
+        "parentId": 1093,
+        "orderNum": 1,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:operlog:query",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:34:04",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1096,
+        "menuName": "操作删除",
+        "parentName": null,
+        "parentId": 1093,
+        "orderNum": 2,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:operlog:remove",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:34:27",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1097,
+        "menuName": "日志导出",
+        "parentName": null,
+        "parentId": 1093,
+        "orderNum": 3,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:operlog:export",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:31:06",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1094,
+        "menuName": "登录日志",
+        "parentName": null,
+        "parentId": 1092,
+        "orderNum": 2,
+        "path": "logininfor",
+        "component": "monitor/logininfor/index",
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "C",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:logininfor:list",
+        "icon": "logininfor",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:34:57",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1098,
+        "menuName": "登录查询",
+        "parentName": null,
+        "parentId": 1094,
+        "orderNum": 1,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:logininfor:query",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:36:58",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1099,
+        "menuName": "登录删除",
+        "parentName": null,
+        "parentId": 1094,
+        "orderNum": 2,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:logininfor:remove",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:37:21",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1100,
+        "menuName": "日志导出",
+        "parentName": null,
+        "parentId": 1094,
+        "orderNum": 3,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:logininfor:export",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
+    },
+    {
+        "createBy": null,
+        "createTime": "2023-07-06 13:37:44",
+        "updateBy": null,
+        "updateTime": null,
+        "remark": null,
+        "menuId": 1101,
+        "menuName": "账户解锁",
+        "parentName": null,
+        "parentId": 1094,
+        "orderNum": 4,
+        "path": "",
+        "component": null,
+        "query": null,
+        "isFrame": "1",
+        "isCache": "0",
+        "menuType": "F",
+        "visible": "0",
+        "status": "0",
+        "perms": "monitor:logininfor:unlock",
+        "icon": "#",
+        "children": [],
+        "tenantName": null,
+        "tenantId": null
     }
 ]