From f13712509eedc4f1400e9b45688c2ddf630207e7 Mon Sep 17 00:00:00 2001
From: D <3066417822@qq.com>
Date: Sat, 2 Mar 2024 00:28:24 +0800
Subject: [PATCH] update
---
.../phone/controller/DySmsController.java | 14 ++
.../phone/service/Impl/DySmsServiceImpl.java | 8 +-
.../ruoyi/oauth/phone/utils/DySmsUtil.java | 7 +-
ruoyi-online/pom.xml | 5 +
.../online/controller/OnLineController.java | 44 ++++-
.../com/ruoyi/online/domain/OnlineMb.java | 182 +++++++++---------
6 files changed, 155 insertions(+), 105 deletions(-)
diff --git a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/controller/DySmsController.java b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/controller/DySmsController.java
index 3c0c70d..fb7bb5f 100644
--- a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/controller/DySmsController.java
+++ b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/controller/DySmsController.java
@@ -1,10 +1,24 @@
package com.ruoyi.oauth.phone.controller;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.oauth.phone.service.DySmsService;
+
+
@RestController
+@Anonymous
@RequestMapping("/oauth/phone")
public class DySmsController {
+ @Autowired
+ public DySmsService dySmsService;
+ @PostMapping("/login")
+ public String postMethodName() {
+ dySmsService.doLogin("17854126030");
+ return null;
+ }
}
diff --git a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/service/Impl/DySmsServiceImpl.java b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/service/Impl/DySmsServiceImpl.java
index f9b48c5..413338e 100644
--- a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/service/Impl/DySmsServiceImpl.java
+++ b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/service/Impl/DySmsServiceImpl.java
@@ -6,12 +6,14 @@ import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
+import com.ruoyi.oauth.phone.enums.DySmsTemplate;
import com.ruoyi.oauth.phone.service.DySmsService;
import com.ruoyi.oauth.phone.utils.DySmsUtil;
import com.ruoyi.system.service.ISysUserService;
@@ -31,7 +33,7 @@ public class DySmsServiceImpl implements DySmsService {
private TokenService tokenService;
public static String generateRandomString(int n) {
- String characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ String characters = "0123456789"; //ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
StringBuilder result = new StringBuilder();
Random random = new Random();
@@ -55,7 +57,9 @@ public class DySmsServiceImpl implements DySmsService {
throw new ServiceException("该手机号未绑定用户");
}
try {
- dySmsUtil.sendSms(null, null, phone);
+ JSONObject templateParams = new JSONObject();
+ templateParams.put("code", code);
+ dySmsUtil.sendSms(DySmsTemplate.Test_TEMPLATE_CODE, templateParams, phone);
redisCache.setCacheObject("phone_codes_login" + phone, code, 1, TimeUnit.MINUTES);
} catch (Exception e) {
e.printStackTrace();
diff --git a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/utils/DySmsUtil.java b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/utils/DySmsUtil.java
index ef9f5c8..79569c2 100644
--- a/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/utils/DySmsUtil.java
+++ b/ruoyi-oauth/ruoyi-oauth-phone/src/main/java/com/ruoyi/oauth/phone/utils/DySmsUtil.java
@@ -76,8 +76,11 @@ public class DySmsUtil {
try {
// 复制代码运行请自行打印 API 的返回值
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
- logger.info("短信接口返回的数据----------------");
- logger.info(sendSmsResponse.toString());
+ if (sendSmsResponse.getBody().getCode().equals("OK")) {
+ logger.info("短信接口返回的数据---", sendSmsResponse.getBody().getMessage());
+ } else {
+ logger.error("短信接口返回的数据---", sendSmsResponse.getBody().getMessage());
+ }
} catch (TeaException error) {
// 错误 message
System.out.println(error.getMessage());
diff --git a/ruoyi-online/pom.xml b/ruoyi-online/pom.xml
index e27e330..4debdaf 100644
--- a/ruoyi-online/pom.xml
+++ b/ruoyi-online/pom.xml
@@ -23,6 +23,11 @@
ruoyi-common
+
+
+ com.ruoyi
+ ruoyi-framework
+
\ No newline at end of file
diff --git a/ruoyi-online/src/main/java/com/ruoyi/online/controller/OnLineController.java b/ruoyi-online/src/main/java/com/ruoyi/online/controller/OnLineController.java
index 88bfe60..abf33c0 100644
--- a/ruoyi-online/src/main/java/com/ruoyi/online/controller/OnLineController.java
+++ b/ruoyi-online/src/main/java/com/ruoyi/online/controller/OnLineController.java
@@ -16,10 +16,14 @@ import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.framework.web.service.PermissionService;
import com.ruoyi.online.domain.OnlineMb;
import com.ruoyi.online.service.IOnlineMbService;
import com.ruoyi.online.utils.SqlMapper;
+import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -31,9 +35,13 @@ public class OnLineController extends BaseController {
private SqlSessionFactory sqlSessionFactory;
@Autowired
private IOnlineMbService onlineMbService;
+ @Resource(name = "ss")
+ private PermissionService permissionService;
@RequestMapping("/api/**")
- public Object api(@RequestParam(required = false) HashMap params,@RequestBody(required = false) HashMap data,HttpServletRequest request,HttpServletResponse response) {
+ public Object api(@RequestParam(required = false) HashMap params,
+ @RequestBody(required = false) HashMap data, HttpServletRequest request,
+ HttpServletResponse response) {
OnlineMb selectOnlineMb = new OnlineMb();
selectOnlineMb.setPath(request.getRequestURI().replace("/online/api", ""));
selectOnlineMb.setMethod(request.getMethod());
@@ -44,28 +52,50 @@ public class OnLineController extends BaseController {
if (params != null) {
params.keySet().forEach(key -> {
Matcher matcher = pattern.matcher(key);
- if(matcher.find()){
+ if (matcher.find()) {
object_params.put(matcher.group(1), object.get(key));
- }else{
+ } else {
object.put(key, params.get(key));
}
});
}
if (data != null) {
- if(data.containsKey("params")){
+ if (data.containsKey("params")) {
object_params.putAll((HashMap) object.get("params"));
data.remove("params");
}
object.putAll(data);
}
object.put("params", object_params);
+
List selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb);
if (selectOnlineMbList.size() == 0) {
- return error("没有相关接口");
+ return AjaxResult.error("没有资源"+selectOnlineMb.getPath());
} else if (selectOnlineMbList.size() > 1) {
- return error("存在多个接口");
+ return AjaxResult.error(500,"系统错误,在线接口重复");
} else {
OnlineMb onlineMb = selectOnlineMbList.get(0);
+ boolean permissionFlag = true;
+ if (onlineMb.getPermissionType() != null) {
+ switch (onlineMb.getPermissionType()) {
+ case "hasPermi" -> permissionFlag = permissionService.hasPermi(onlineMb.getPermissionValue());
+ case "lacksPermi" -> permissionFlag = !permissionService.lacksPermi(onlineMb.getPermissionValue());
+ case "hasAnyPermi" -> permissionFlag = permissionService.hasAnyPermi(onlineMb.getPermissionValue());
+ case "hasRole" -> permissionFlag = permissionService.hasRole(onlineMb.getPermissionValue());
+ case "lacksRole" -> permissionFlag = !permissionService.lacksRole(onlineMb.getPermissionValue());
+ case "hasAnyRoles" -> permissionFlag = permissionService.hasAnyRoles(onlineMb.getPermissionValue());
+ }
+ }
+ if (!permissionFlag) {
+ return AjaxResult.error(403,"没有权限,请联系管理员授权");
+ }
+ if (onlineMb.getDeptId() != null && onlineMb.getDeptId().equals("1")) {
+ object.put("deptId", SecurityUtils.getDeptId());
+ }
+ if (onlineMb.getUserId() != null && onlineMb.getUserId().equals("1")) {
+ object.put("userId", SecurityUtils.getUserId());
+ }
+
String sql = "";
SqlSession sqlSession = sqlSessionFactory.openSession();
SqlMapper sqlMapper = new SqlMapper(sqlSession);
@@ -75,7 +105,7 @@ public class OnLineController extends BaseController {
case "selectOne" -> success(sqlMapper.selectOne(sql, object));
case "update" -> toAjax(sqlMapper.update(sql, object));
case "delete" -> toAjax(sqlMapper.delete(sql, object));
- default -> error("错误的执行器");
+ default -> AjaxResult.error(500,"系统错误,执行器错误");
};
}
}
diff --git a/ruoyi-online/src/main/java/com/ruoyi/online/domain/OnlineMb.java b/ruoyi-online/src/main/java/com/ruoyi/online/domain/OnlineMb.java
index 9bd25dc..9f2e350 100644
--- a/ruoyi-online/src/main/java/com/ruoyi/online/domain/OnlineMb.java
+++ b/ruoyi-online/src/main/java/com/ruoyi/online/domain/OnlineMb.java
@@ -15,213 +15,207 @@ import io.swagger.v3.oas.annotations.media.Schema;
* @date 2024-01-26
*/
@Schema(description = "mybatis在线接口对象")
-public class OnlineMb extends BaseEntity
-{
+public class OnlineMb extends BaseEntity {
private static final long serialVersionUID = 1L;
-
/** 主键 */
@Schema(defaultValue = "主键")
private Long mbId;
-
-
-
/** 标签名 */
@Schema(defaultValue = "标签名")
@Excel(name = "标签名")
private String tag;
-
-
-
/** 标签id */
@Schema(defaultValue = "标签id")
@Excel(name = "标签id")
private String tagId;
-
-
-
/** 参数类型 */
@Schema(defaultValue = "参数类型")
@Excel(name = "参数类型")
private String parameterType;
-
-
-
/** 结果类型 */
@Schema(defaultValue = "结果类型")
@Excel(name = "结果类型")
private String resultMap;
-
-
-
/** sql语句 */
@Schema(defaultValue = "sql语句")
@Excel(name = "sql语句")
private String sql;
-
-
-
/** 请求路径 */
@Schema(defaultValue = "请求路径")
@Excel(name = "请求路径")
private String path;
-
-
-
/** 请求方式 */
@Schema(defaultValue = "请求方式")
@Excel(name = "请求方式")
private String method;
-
-
-
/** 响应类型 */
@Schema(defaultValue = "响应类型")
@Excel(name = "响应类型")
private String resultType;
-
-
-
/** 执行器 */
@Schema(defaultValue = "执行器")
@Excel(name = "执行器")
private String actuator;
-
+ /** 是否需要userId */
+ @Schema(defaultValue = "是否需要userId")
+ @Excel(name = "是否需要userId")
+ private String userId;
- public void setMbId(Long mbId)
- {
+ /** 是否需要deptId */
+ @Schema(defaultValue = "是否需要deptId")
+ @Excel(name = "是否需要deptId")
+ private String deptId;
+
+ /** 许可类型 */
+ @Schema(defaultValue = "许可类型")
+ @Excel(name = "许可类型")
+ private String permissionType;
+
+ /** 许可值 */
+ @Schema(defaultValue = "许可值")
+ @Excel(name = "许可值")
+ private String permissionValue;
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getDeptId() {
+ return deptId;
+ }
+
+ public void setDeptId(String deptId) {
+ this.deptId = deptId;
+ }
+
+ public String getPermissionType() {
+ return permissionType;
+ }
+
+ public void setPermissionType(String permissionType) {
+ this.permissionType = permissionType;
+ }
+
+ public String getPermissionValue() {
+ return permissionValue;
+ }
+
+ public void setPermissionValue(String permissionValue) {
+ this.permissionValue = permissionValue;
+ }
+
+ public void setMbId(Long mbId) {
this.mbId = mbId;
}
- public Long getMbId()
- {
+ public Long getMbId() {
return mbId;
}
-
- public void setTag(String tag)
- {
+ public void setTag(String tag) {
this.tag = tag;
}
- public String getTag()
- {
+ public String getTag() {
return tag;
}
-
- public void setTagId(String tagId)
- {
+ public void setTagId(String tagId) {
this.tagId = tagId;
}
- public String getTagId()
- {
+ public String getTagId() {
return tagId;
}
-
- public void setParameterType(String parameterType)
- {
+ public void setParameterType(String parameterType) {
this.parameterType = parameterType;
}
- public String getParameterType()
- {
+ public String getParameterType() {
return parameterType;
}
-
- public void setResultMap(String resultMap)
- {
+ public void setResultMap(String resultMap) {
this.resultMap = resultMap;
}
- public String getResultMap()
- {
+ public String getResultMap() {
return resultMap;
}
-
- public void setSql(String sql)
- {
+ public void setSql(String sql) {
this.sql = sql;
}
- public String getSql()
- {
+ public String getSql() {
return sql;
}
-
- public void setPath(String path)
- {
+ public void setPath(String path) {
this.path = path;
}
- public String getPath()
- {
+ public String getPath() {
return path;
}
-
- public void setMethod(String method)
- {
+ public void setMethod(String method) {
this.method = method;
}
- public String getMethod()
- {
+ public String getMethod() {
return method;
}
-
- public void setResultType(String resultType)
- {
+ public void setResultType(String resultType) {
this.resultType = resultType;
}
- public String getResultType()
- {
+ public String getResultType() {
return resultType;
}
-
- public void setActuator(String actuator)
- {
+ public void setActuator(String actuator) {
this.actuator = actuator;
}
- public String getActuator()
- {
+ public String getActuator() {
return actuator;
}
-
-
@Override
public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("mbId", getMbId())
- .append("tag", getTag())
- .append("tagId", getTagId())
- .append("parameterType", getParameterType())
- .append("resultMap", getResultMap())
- .append("sql", getSql())
- .append("path", getPath())
- .append("method", getMethod())
- .append("resultType", getResultType())
- .append("actuator", getActuator())
- .toString();
+ return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+ .append("mbId", getMbId())
+ .append("tag", getTag())
+ .append("tagId", getTagId())
+ .append("parameterType", getParameterType())
+ .append("resultMap", getResultMap())
+ .append("sql", getSql())
+ .append("path", getPath())
+ .append("method", getMethod())
+ .append("resultType", getResultType())
+ .append("actuator", getActuator())
+ .append("userId",getUserId())
+ .append("deptId",getDeptId())
+ .append("permissionType",getPermissionType())
+ .append("permissionValue",getPermissionValue())
+ .toString();
}
}