mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	Merge remote-tracking branch 'refs/remotes/yudao/develop' into develop
This commit is contained in:
		@@ -109,7 +109,7 @@ public class AuthController {
 | 
			
		||||
        // 1.3 获得菜单列表
 | 
			
		||||
        Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
 | 
			
		||||
        List<MenuDO> menuList = menuService.getMenuList(menuIds);
 | 
			
		||||
        menuList.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单
 | 
			
		||||
        menuList = menuService.filterDisableMenus(menuList);
 | 
			
		||||
 | 
			
		||||
        // 2. 拼接结果返回
 | 
			
		||||
        return success(AuthConvert.INSTANCE.convert(user, roles, menuList));
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ public class OAuth2OpenController {
 | 
			
		||||
                                                                     @RequestParam(value = "refresh_token", required = false) String refreshToken) { // 刷新模式
 | 
			
		||||
        List<String> scopes = OAuth2Utils.buildScopes(scope);
 | 
			
		||||
        // 1.1 校验授权类型
 | 
			
		||||
        OAuth2GrantTypeEnum grantTypeEnum = OAuth2GrantTypeEnum.getByGranType(grantType);
 | 
			
		||||
        OAuth2GrantTypeEnum grantTypeEnum = OAuth2GrantTypeEnum.getByGrantType(grantType);
 | 
			
		||||
        if (grantTypeEnum == null) {
 | 
			
		||||
            throw exception0(BAD_REQUEST.getCode(), StrUtil.format("未知授权类型({})", grantType));
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,7 @@ public class MenuController {
 | 
			
		||||
    public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() {
 | 
			
		||||
        List<MenuDO> list = menuService.getMenuListByTenant(
 | 
			
		||||
                new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
 | 
			
		||||
        list = menuService.filterDisableMenus(list);
 | 
			
		||||
        list.sort(Comparator.comparing(MenuDO::getSort));
 | 
			
		||||
        return success(BeanUtils.toBean(list, MenuSimpleRespVO.class));
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -42,4 +42,14 @@ public class SmsCallbackController {
 | 
			
		||||
        return success(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/huawei")
 | 
			
		||||
    @PermitAll
 | 
			
		||||
    @Operation(summary = "华为云短信的回调", description = "参见 https://support.huaweicloud.com/api-msgsms/sms_05_0003.html 文档")
 | 
			
		||||
    public CommonResult<Boolean> receiveHuaweiSmsStatus(HttpServletRequest request) throws Throwable {
 | 
			
		||||
        String text = ServletUtils.getBody(request);
 | 
			
		||||
        smsSendService.receiveSmsStatus(SmsChannelEnum.HUAWEI.getCode(), text);
 | 
			
		||||
        return success(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -119,6 +119,9 @@ public class UserController {
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('system:user:query')")
 | 
			
		||||
    public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
 | 
			
		||||
        AdminUserDO user = userService.getUser(id);
 | 
			
		||||
        if (user == null) {
 | 
			
		||||
            return success(null);
 | 
			
		||||
        }
 | 
			
		||||
        // 拼接数据
 | 
			
		||||
        DeptDO dept = deptService.getDept(user.getDeptId());
 | 
			
		||||
        return success(UserConvert.INSTANCE.convert(user, dept));
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.dal.dataobject.permission;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.KeySequence;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableName;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.EqualsAndHashCode;
 | 
			
		||||
 | 
			
		||||
@@ -72,7 +72,7 @@ public class RoleDO extends TenantBaseDO {
 | 
			
		||||
     *
 | 
			
		||||
     * 适用于 {@link #dataScope} 的值为 {@link DataScopeEnum#DEPT_CUSTOM} 时
 | 
			
		||||
     */
 | 
			
		||||
    @TableField(typeHandler = JsonLongSetTypeHandler.class)
 | 
			
		||||
    @TableField(typeHandler = JacksonTypeHandler.class)
 | 
			
		||||
    private Set<Long> dataScopeDeptIds;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.dal.dataobject.tenant;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
 | 
			
		||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.KeySequence;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableName;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 | 
			
		||||
import lombok.*;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
@@ -46,7 +46,7 @@ public class TenantPackageDO extends BaseDO {
 | 
			
		||||
    /**
 | 
			
		||||
     * 关联的菜单编号
 | 
			
		||||
     */
 | 
			
		||||
    @TableField(typeHandler = JsonLongSetTypeHandler.class)
 | 
			
		||||
    @TableField(typeHandler = JacksonTypeHandler.class)
 | 
			
		||||
    private Set<Long> menuIds;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.dal.dataobject.user;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler;
 | 
			
		||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.KeySequence;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableField;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableId;
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.TableName;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 | 
			
		||||
import lombok.*;
 | 
			
		||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +58,7 @@ public class AdminUserDO extends TenantBaseDO {
 | 
			
		||||
    /**
 | 
			
		||||
     * 岗位编号数组
 | 
			
		||||
     */
 | 
			
		||||
    @TableField(typeHandler = JsonLongSetTypeHandler.class)
 | 
			
		||||
    @TableField(typeHandler = JacksonTypeHandler.class)
 | 
			
		||||
    private Set<Long> postIds;
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户邮箱
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,221 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.framework.sms.core.client.impl;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.lang.Assert;
 | 
			
		||||
import cn.hutool.core.util.HexUtil;
 | 
			
		||||
import cn.hutool.core.util.StrUtil;
 | 
			
		||||
import cn.hutool.crypto.SecureUtil;
 | 
			
		||||
import cn.hutool.crypto.digest.DigestUtil;
 | 
			
		||||
import cn.hutool.json.JSONArray;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.http.HttpResponse;
 | 
			
		||||
import org.apache.http.client.methods.HttpUriRequest;
 | 
			
		||||
import org.apache.http.client.methods.RequestBuilder;
 | 
			
		||||
import org.apache.http.entity.StringEntity;
 | 
			
		||||
import org.apache.http.impl.client.CloseableHttpClient;
 | 
			
		||||
import org.apache.http.impl.client.HttpClientBuilder;
 | 
			
		||||
 | 
			
		||||
import java.net.URLEncoder;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 华为短信客户端的实现类
 | 
			
		||||
 *
 | 
			
		||||
 * @author scholar
 | 
			
		||||
 * @since 2024/6/02 11:55
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class HuaweiSmsClient extends AbstractSmsClient {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 调用成功 code
 | 
			
		||||
     */
 | 
			
		||||
    public static final String API_CODE_SUCCESS = "OK";
 | 
			
		||||
 | 
			
		||||
    public HuaweiSmsClient(SmsChannelProperties properties) {
 | 
			
		||||
        super(properties);
 | 
			
		||||
        Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空");
 | 
			
		||||
        Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void doInit() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId,
 | 
			
		||||
                                  List<KeyValue<String, Object>> templateParams) throws Throwable {
 | 
			
		||||
        // TODO @scholar:https://smsapi.cn-north-4.myhuaweicloud.com:443 是不是枚举成静态变量
 | 
			
		||||
        String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址+接口访问URI
 | 
			
		||||
        // 相比较阿里短信,华为短信发送的时候需要额外的参数“通道号”,考虑到不破坏原有的的结构
 | 
			
		||||
        // 所以将 通道号 拼接到 apiTemplateId 字段中,格式为 "apiTemplateId 通道号"。空格为分隔符。
 | 
			
		||||
        // TODO @scholar:暂时只考虑中国大陆,所以不需要 sender 哈
 | 
			
		||||
        String sender = StrUtil.subAfter(apiTemplateId, " ", true); //中国大陆短信签名通道号或全球短信通道号
 | 
			
		||||
        String templateId = StrUtil.subBefore(apiTemplateId, " ", true); //模板ID
 | 
			
		||||
 | 
			
		||||
        // 选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告
 | 
			
		||||
        String statusCallBack = properties.getCallbackUrl();
 | 
			
		||||
 | 
			
		||||
        // TODO @scholar:1)是不是用  LocalDateTimeUtil.format();这样 3 行变成一行
 | 
			
		||||
        // TODO @scholar:singerDate 叫 sdkDate 会更合适哈,这样理解起来简单。另外,singer 应该是 signed 么?
 | 
			
		||||
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
 | 
			
		||||
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
 | 
			
		||||
        String singerDate = sdf.format(new Date());
 | 
			
		||||
 | 
			
		||||
        // TODO @scholar:整个处理加密的过程,是不是应该抽成一个 private 方法哈。这样整个调用的主干更清晰。
 | 
			
		||||
        // ************* 步骤 1:拼接规范请求串 *************
 | 
			
		||||
        String httpRequestMethod = "POST";
 | 
			
		||||
        String canonicalUri = "/sms/batchSendSms/v1/";
 | 
			
		||||
        String canonicalQueryString = ""; // 查询参数为空
 | 
			
		||||
        String canonicalHeaders = "content-type:application/x-www-form-urlencoded\n"
 | 
			
		||||
                + "host:smsapi.cn-north-4.myhuaweicloud.com:443\n"
 | 
			
		||||
                + "x-sdk-date:" + singerDate + "\n";
 | 
			
		||||
        // TODO @scholar:静态枚举了
 | 
			
		||||
        String signedHeaders = "content-type;host;x-sdk-date";
 | 
			
		||||
        // TODO @scholar:下面的注释,可以考虑去掉
 | 
			
		||||
        /*
 | 
			
		||||
         * 选填,使用无变量模板时请赋空值 String templateParas = "";
 | 
			
		||||
         * 单变量模板示例:模板内容为"您的验证码是${NUM_6}"时,templateParas可填写为"[\"111111\"]"
 | 
			
		||||
         * 双变量模板示例:模板内容为"您有${NUM_2}件快递请到${TXT_20}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]"
 | 
			
		||||
         */
 | 
			
		||||
        // TODO @scholar:CollectionUtils.convertList 可以把 4 行变成 1 行。
 | 
			
		||||
        // TODO @scholar:templateParams 拼写错误哈
 | 
			
		||||
        List<String> templateParas = new ArrayList<>();
 | 
			
		||||
        for (KeyValue<String, Object> kv : templateParams) {
 | 
			
		||||
            templateParas.add(String.valueOf(kv.getValue()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 请求Body,不携带签名名称时,signature请填null
 | 
			
		||||
        String body = buildRequestBody(sender, mobile, templateId, templateParas, statusCallBack, null);
 | 
			
		||||
        // TODO @scholar:Assert 断言,抛出异常
 | 
			
		||||
        if (null == body || body.isEmpty()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        String hashedRequestBody = HexUtil.encodeHexStr(DigestUtil.sha256(body));
 | 
			
		||||
        String canonicalRequest = httpRequestMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n"
 | 
			
		||||
                + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody;
 | 
			
		||||
 | 
			
		||||
        // ************* 步骤 2:拼接待签名字符串 *************
 | 
			
		||||
        // TODO @scholar:sha256Hex 是不是更简洁哈
 | 
			
		||||
        String hashedCanonicalRequest = HexUtil.encodeHexStr(DigestUtil.sha256(canonicalRequest));
 | 
			
		||||
        String stringToSign = "SDK-HMAC-SHA256" + "\n" + singerDate + "\n" + hashedCanonicalRequest;
 | 
			
		||||
 | 
			
		||||
        // ************* 步骤 3:计算签名 *************
 | 
			
		||||
        String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign);
 | 
			
		||||
 | 
			
		||||
        // ************* 步骤 4:拼接 Authorization *************
 | 
			
		||||
        String authorization = "SDK-HMAC-SHA256" + " " + "Access=" + properties.getApiKey() + ", "
 | 
			
		||||
                + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature;
 | 
			
		||||
 | 
			
		||||
        // ************* 步骤 5:构造HttpRequest 并执行request请求,获得response *************
 | 
			
		||||
        // TODO @scholar:考虑了下,还是换 hutool 的 httpUtils。因为未来 httpclient 我们可能会移除掉
 | 
			
		||||
        HttpUriRequest postMethod = RequestBuilder.post()
 | 
			
		||||
                .setUri(url)
 | 
			
		||||
                .setEntity(new StringEntity(body, StandardCharsets.UTF_8))
 | 
			
		||||
                .setHeader("Content-Type","application/x-www-form-urlencoded")
 | 
			
		||||
                .setHeader("X-Sdk-Date", singerDate)
 | 
			
		||||
                .setHeader("Authorization", authorization)
 | 
			
		||||
                .build();
 | 
			
		||||
        // TODO @scholar:这种不太适合一直 new 的哈
 | 
			
		||||
        CloseableHttpClient client = HttpClientBuilder.create().build();
 | 
			
		||||
        HttpResponse response = client.execute(postMethod);
 | 
			
		||||
        // TODO @scholar:失败的情况下的处理
 | 
			
		||||
        // TODO @scholar:setSerialNo(Integer.toString(response.getStatusLine().getStatusCode())) 这部分,空一行。一行代码太多了,阅读性不太好哈
 | 
			
		||||
        return new SmsSendRespDTO().setSuccess(Objects.equals(response.getStatusLine().getReasonPhrase(), API_CODE_SUCCESS)).setSerialNo(Integer.toString(response.getStatusLine().getStatusCode()))
 | 
			
		||||
                .setApiRequestId(null).setApiCode(null).setApiMsg(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static String buildRequestBody(String sender, String receiver, String templateId, List<String> templateParas,
 | 
			
		||||
                                   String statusCallBack, @SuppressWarnings("SameParameterValue") String signature) {
 | 
			
		||||
        // TODO @scholar:参数不满足,是不是抛出异常更好哈;通过 hutool 的 Assert 去断言
 | 
			
		||||
        if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty()
 | 
			
		||||
                || templateId.isEmpty()) {
 | 
			
		||||
            System.out.println("buildRequestBody(): sender, receiver or templateId is null.");
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        StringBuilder body = new StringBuilder();
 | 
			
		||||
        appendToBody(body, "from=", sender);
 | 
			
		||||
        appendToBody(body, "&to=", receiver);
 | 
			
		||||
        appendToBody(body, "&templateId=", templateId);
 | 
			
		||||
        // TODO @scholar:new JSONArray(templateParas).toString(),是不是 JsonUtils.toString 呀?
 | 
			
		||||
        appendToBody(body, "&templateParas=", new JSONArray(templateParas).toString());
 | 
			
		||||
        appendToBody(body, "&statusCallback=", statusCallBack);
 | 
			
		||||
        appendToBody(body, "&signature=", signature);
 | 
			
		||||
        return body.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void appendToBody(StringBuilder body, String key, String val) {
 | 
			
		||||
        // TODO @scholar:StrUtils.isNotEmpty(val),是不是更简洁哈
 | 
			
		||||
        if (null != val && !val.isEmpty()) {
 | 
			
		||||
            body.append(key).append(URLEncoder.encode(val, StandardCharsets.UTF_8));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) {
 | 
			
		||||
        List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class);
 | 
			
		||||
        return convertList(statuses, status -> new SmsReceiveRespDTO().setSuccess(Objects.equals(status.getStatus(),"DELIVRD"))
 | 
			
		||||
                .setErrorCode(status.getStatus()).setErrorMsg(status.getStatus())
 | 
			
		||||
                .setMobile(status.getPhoneNumber()).setReceiveTime(status.getUpdateTime())
 | 
			
		||||
                .setSerialNo(status.getSmsMsgId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable {
 | 
			
		||||
        // 华为短信模板查询和发送短信,是不同的两套 key 和 secret,与阿里、腾讯的区别较大,这里模板查询校验暂不实现
 | 
			
		||||
        // 对应文档 https://support.huaweicloud.com/api-msgsms/sms_05_0040.html
 | 
			
		||||
        return new SmsTemplateRespDTO().setId(apiTemplateId).setContent(null)
 | 
			
		||||
                .setAuditStatus(SmsTemplateAuditStatusEnum.SUCCESS.getStatus()).setAuditReason(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 短信接收状态
 | 
			
		||||
     *
 | 
			
		||||
     * 参见 <a href="https://support.huaweicloud.com/api-msgsms/sms_05_0003.html">文档</a>
 | 
			
		||||
     *
 | 
			
		||||
     * @author scholar
 | 
			
		||||
     */
 | 
			
		||||
    @Data
 | 
			
		||||
    public static class SmsReceiveStatus {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 本条状态报告对应的短信的接收方号码,仅当状态报告中携带了extend参数时才会同时携带该参数
 | 
			
		||||
         */
 | 
			
		||||
        @JsonProperty("to")
 | 
			
		||||
        private String phoneNumber;
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 短信资源的更新时间,通常为短信平台接收短信状态报告的时间
 | 
			
		||||
         */
 | 
			
		||||
        @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
 | 
			
		||||
        private LocalDateTime updateTime;
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 短信状态报告枚举值
 | 
			
		||||
         */
 | 
			
		||||
        private String status;
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 发送短信成功时返回的短信唯一标识。
 | 
			
		||||
         */
 | 
			
		||||
        private String smsMsgId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -78,6 +78,7 @@ public class SmsClientFactoryImpl implements SmsClientFactory {
 | 
			
		||||
            case ALIYUN: return new AliyunSmsClient(properties);
 | 
			
		||||
            case DEBUG_DING_TALK: return new DebugDingTalkSmsClient(properties);
 | 
			
		||||
            case TENCENT: return new TencentSmsClient(properties);
 | 
			
		||||
            case HUAWEI: return  new HuaweiSmsClient(properties);
 | 
			
		||||
        }
 | 
			
		||||
        // 创建失败,错误日志 + 抛出异常
 | 
			
		||||
        log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", properties);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ public enum SmsChannelEnum {
 | 
			
		||||
    DEBUG_DING_TALK("DEBUG_DING_TALK", "调试(钉钉)"),
 | 
			
		||||
    ALIYUN("ALIYUN", "阿里云"),
 | 
			
		||||
    TENCENT("TENCENT", "腾讯云"),
 | 
			
		||||
//    HUA_WEI("HUA_WEI", "华为云"),
 | 
			
		||||
    HUAWEI("HUAWEI", "华为云"),
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,14 @@ public interface MenuService {
 | 
			
		||||
     */
 | 
			
		||||
    List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 过滤掉关闭的菜单及其子菜单
 | 
			
		||||
     *
 | 
			
		||||
     * @param list 菜单列表
 | 
			
		||||
     * @return 过滤后的菜单列表
 | 
			
		||||
     */
 | 
			
		||||
    List<MenuDO> filterDisableMenus(List<MenuDO> list);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 筛选菜单列表
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.service.permission;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
 | 
			
		||||
@@ -19,11 +21,11 @@ import org.springframework.context.annotation.Lazy;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
 | 
			
		||||
import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
 | 
			
		||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
 | 
			
		||||
 | 
			
		||||
@@ -106,12 +108,57 @@ public class MenuServiceImpl implements MenuService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<MenuDO> getMenuListByTenant(MenuListReqVO reqVO) {
 | 
			
		||||
        // 查询所有菜单,并过滤掉关闭的节点
 | 
			
		||||
        List<MenuDO> menus = getMenuList(reqVO);
 | 
			
		||||
        // 开启多租户的情况下,需要过滤掉未开通的菜单
 | 
			
		||||
        tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId())));
 | 
			
		||||
        return menus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<MenuDO> filterDisableMenus(List<MenuDO> menuList) {
 | 
			
		||||
        if (CollUtil.isEmpty(menuList)){
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
        Map<Long, MenuDO> menuMap = convertMap(menuList, MenuDO::getId);
 | 
			
		||||
 | 
			
		||||
        // 遍历 menu 菜单,查找不是禁用的菜单,添加到 enabledMenus 结果
 | 
			
		||||
        List<MenuDO> enabledMenus = new ArrayList<>();
 | 
			
		||||
        Set<Long> disabledMenuCache = new HashSet<>(); // 存下递归搜索过被禁用的菜单,防止重复的搜索
 | 
			
		||||
        for (MenuDO menu : menuList) {
 | 
			
		||||
            if (isMenuDisabled(menu, menuMap, disabledMenuCache)) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            enabledMenus.add(menu);
 | 
			
		||||
        }
 | 
			
		||||
        return enabledMenus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isMenuDisabled(MenuDO node, Map<Long, MenuDO> menuMap, Set<Long> disabledMenuCache) {
 | 
			
		||||
        // 如果已经判定是禁用的节点,直接结束
 | 
			
		||||
        if (disabledMenuCache.contains(node.getId())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 1. 遍历到 parentId 为根节点,则无需判断
 | 
			
		||||
        Long parentId = node.getParentId();
 | 
			
		||||
        if (ObjUtil.equal(parentId, ID_ROOT)) {
 | 
			
		||||
            if (CommonStatusEnum.isDisable(node.getStatus())) {
 | 
			
		||||
                disabledMenuCache.add(node.getId());
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 2. 继续遍历 parent 节点
 | 
			
		||||
        MenuDO parent = menuMap.get(parentId);
 | 
			
		||||
        if (parent == null || isMenuDisabled(parent, menuMap, disabledMenuCache)) {
 | 
			
		||||
            disabledMenuCache.add(node.getId());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<MenuDO> getMenuList(MenuListReqVO reqVO) {
 | 
			
		||||
        return menuMapper.selectList(reqVO);
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,9 @@ import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum;
 | 
			
		||||
import com.google.common.annotations.VisibleForTesting;
 | 
			
		||||
import com.mzt.logapi.context.LogRecordContext;
 | 
			
		||||
import com.mzt.logapi.service.impl.DiffParseFunction;
 | 
			
		||||
import com.mzt.logapi.starter.annotation.LogRecord;
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.cache.annotation.CacheEvict;
 | 
			
		||||
import org.springframework.cache.annotation.Cacheable;
 | 
			
		||||
@@ -26,7 +28,6 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
			
		||||
@@ -116,6 +117,7 @@ public class RoleServiceImpl implements RoleService {
 | 
			
		||||
        permissionService.processRoleDeleted(id);
 | 
			
		||||
 | 
			
		||||
        // 3. 记录操作日志上下文
 | 
			
		||||
        LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(role, RoleSaveReqVO.class));
 | 
			
		||||
        LogRecordContext.putVariable("role", role);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,8 @@ public class SmsCodeServiceImpl implements SmsCodeService {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 创建验证码记录
 | 
			
		||||
        String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1));
 | 
			
		||||
        String code = String.format("%0" + smsCodeProperties.getEndCode().toString().length() + "d",
 | 
			
		||||
                randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1));
 | 
			
		||||
        SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code).scene(scene)
 | 
			
		||||
                .todayIndex(lastSmsCode != null && isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1)
 | 
			
		||||
                .createIp(ip).used(false).build();
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.framework.sms.core.client.impl;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties;
 | 
			
		||||
import org.junit.jupiter.api.Disabled;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 各种 {@link SmsClientTests  集成测试
 | 
			
		||||
 *
 | 
			
		||||
 * @author 芋道源码
 | 
			
		||||
 */
 | 
			
		||||
public class SmsClientTests {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Disabled
 | 
			
		||||
    public void testHuaweiSmsClient() throws Throwable {
 | 
			
		||||
        SmsChannelProperties properties = new SmsChannelProperties()
 | 
			
		||||
                .setApiKey("123")
 | 
			
		||||
                .setApiSecret("456");
 | 
			
		||||
        HuaweiSmsClient client = new HuaweiSmsClient(properties);
 | 
			
		||||
        // 准备参数
 | 
			
		||||
        Long sendLogId = System.currentTimeMillis();
 | 
			
		||||
        String mobile = "15601691323";
 | 
			
		||||
        String apiTemplateId = "xx test01";
 | 
			
		||||
        List<KeyValue<String, Object>> templateParams = List.of(new KeyValue<>("code", "1024"));
 | 
			
		||||
        // 调用
 | 
			
		||||
        SmsSendRespDTO smsSendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, templateParams);
 | 
			
		||||
        // 打印结果
 | 
			
		||||
        System.out.println(smsSendRespDTO);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user