[优化]删除不需要的功能代码

master
liuqingkun 3 years ago
parent 612a325af8
commit cfd8254673
  1. 2
      pom.xml
  2. 138
      src/main/java/org/springblade/modules/business/controller/NoticeController.java
  3. 64
      src/main/java/org/springblade/modules/business/entity/Notice.java
  4. 50
      src/main/java/org/springblade/modules/business/mapper/NoticeMapper.java
  5. 53
      src/main/java/org/springblade/modules/business/mapper/NoticeMapper.xml
  6. 4
      src/main/java/org/springblade/modules/business/service/IApmRecordService.java
  7. 39
      src/main/java/org/springblade/modules/business/service/INoticeService.java
  8. 43
      src/main/java/org/springblade/modules/business/service/impl/NoticeServiceImpl.java
  9. 23
      src/main/java/org/springblade/modules/business/vo/NoticeVO.java
  10. 64
      src/main/java/org/springblade/modules/business/wrapper/NoticeWrapper.java
  11. 50
      src/main/java/org/springblade/modules/resource/builder/sms/AliSmsBuilder.java
  12. 47
      src/main/java/org/springblade/modules/resource/builder/sms/QiniuSmsBuilder.java
  13. 157
      src/main/java/org/springblade/modules/resource/builder/sms/SmsBuilder.java
  14. 46
      src/main/java/org/springblade/modules/resource/builder/sms/TencentSmsBuilder.java
  15. 44
      src/main/java/org/springblade/modules/resource/builder/sms/YunpianSmsBuilder.java
  16. 47
      src/main/java/org/springblade/modules/resource/config/BladeSmsConfiguration.java
  17. 62
      src/main/java/org/springblade/modules/resource/enums/SmsCodeEnum.java
  18. 109
      src/main/java/org/springblade/modules/resource/utils/SmsUtil.java

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springblade</groupId>
<artifactId>BladeX-Boot</artifactId>
<artifactId>checkup-apponitment</artifactId>
<packaging>jar</packaging>
<version>3.0.1.RELEASE</version>

@ -1,138 +0,0 @@
/*
* 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.modules.business.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.TenantDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.entity.Notice;
import org.springblade.modules.business.service.INoticeService;
import org.springblade.modules.business.vo.NoticeVO;
import org.springblade.modules.business.wrapper.NoticeWrapper;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
/**
* 控制器
*
* @author Chill
*/
@TenantDS
@RestController
@RequestMapping(AppConstant.APPLICATION_DESK_NAME + "/notice")
@AllArgsConstructor
@ApiSort(2)
@Api(value = "用户博客", tags = "博客接口")
public class NoticeController extends BladeController {
private final INoticeService noticeService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入notice")
public R<NoticeVO> detail(Notice notice) {
Notice detail = noticeService.getOne(Condition.getQueryWrapper(notice));
return R.data(NoticeWrapper.build().entityVO(detail));
}
/**
* 分页
*/
@GetMapping("/list")
@ApiImplicitParams({
@ApiImplicitParam(name = "category", value = "公告类型", paramType = "query", dataType = "integer"),
@ApiImplicitParam(name = "title", value = "公告标题", paramType = "query", dataType = "string")
})
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入notice")
public R<IPage<NoticeVO>> list(@ApiIgnore @RequestParam Map<String, Object> notice, Query query) {
NoticeWrapper.build().noticeQuery(notice);
IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
return R.data(NoticeWrapper.build().pageVO(pages));
}
/**
* 多表联合查询自定义分页
*/
@GetMapping("/page")
@ApiImplicitParams({
@ApiImplicitParam(name = "category", value = "公告类型", paramType = "query", dataType = "integer"),
@ApiImplicitParam(name = "title", value = "公告标题", paramType = "query", dataType = "string")
})
@ApiOperationSupport(order = 3)
@ApiOperation(value = "分页", notes = "传入notice")
public R<IPage<NoticeVO>> page(@ApiIgnore NoticeVO notice, Query query) {
IPage<NoticeVO> pages = noticeService.selectNoticePage(Condition.getPage(query), notice);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入notice")
public R save(@RequestBody Notice notice) {
return R.status(noticeService.save(notice));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "修改", notes = "传入notice")
public R update(@RequestBody Notice notice) {
return R.status(noticeService.updateById(notice));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "新增或修改", notes = "传入notice")
public R submit(@RequestBody Notice notice) {
return R.status(noticeService.saveOrUpdate(notice));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "逻辑删除", notes = "传入notice")
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
boolean temp = noticeService.deleteLogic(Func.toLongList(ids));
return R.status(temp);
}
}

@ -1,64 +0,0 @@
/*
* 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.modules.business.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.util.Date;
/**
* 实体类
*
* @author Chill
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("blade_notice")
public class Notice extends TenantEntity {
private static final long serialVersionUID = 1L;
/**
* 标题
*/
@ApiModelProperty(value = "标题")
private String title;
/**
* 通知类型
*/
@ApiModelProperty(value = "通知类型")
private Integer category;
/**
* 发布日期
*/
@ApiModelProperty(value = "发布日期")
private Date releaseTime;
/**
* 内容
*/
@ApiModelProperty(value = "内容")
private String content;
}

@ -1,50 +0,0 @@
/*
* 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.modules.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.business.entity.Notice;
import org.springblade.modules.business.vo.NoticeVO;
import java.util.List;
/**
* Mapper 接口
*
* @author Chill
*/
public interface NoticeMapper extends BaseMapper<Notice> {
/**
* 前N条数据
*
* @param number 数量
* @return List<Notice>
*/
List<Notice> topList(Integer number);
/**
* 自定义分页
*
* @param page 分页
* @param notice 实体
* @return List<NoticeVO>
*/
List<NoticeVO> selectNoticePage(IPage page, NoticeVO notice);
}

@ -1,53 +0,0 @@
<?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">
<mapper namespace="org.springblade.modules.business.mapper.NoticeMapper">
<!-- 通用查询映射结果 -->
<resultMap id="noticeResultMap" type="org.springblade.modules.business.entity.Notice">
<result column="id" property="id"/>
<result column="create_user" property="createUser"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
<result column="release_time" property="releaseTime"/>
<result column="title" property="title"/>
<result column="content" property="content"/>
</resultMap>
<!-- 通用查询映射结果 -->
<resultMap id="noticeVOResultMap" type="org.springblade.modules.business.vo.NoticeVO">
<result column="id" property="id"/>
<result column="create_user" property="createUser"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
<result column="release_time" property="releaseTime"/>
<result column="title" property="title"/>
<result column="content" property="content"/>
</resultMap>
<select id="topList" resultMap="noticeResultMap">
select * from blade_notice limit #{number}
</select>
<select id="selectNoticePage" resultMap="noticeVOResultMap">
SELECT
n.*,
d.dict_value AS categoryName
FROM
blade_notice n
LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key
WHERE
n.is_deleted = 0 and n.tenant_id = #{notice.tenantId}
<if test="notice.title!=null">
and n.title like concat(concat('%', #{notice.title}), '%')
</if>
<if test="notice.category!=null">
and n.category = #{notice.category}
</if>
</select>
</mapper>

@ -1,15 +1,11 @@
package org.springblade.modules.business.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.mp.support.Query;
import org.springblade.modules.business.dto.ApmRecordCountDTO;
import org.springblade.modules.business.entity.ApmRecord;
import org.springblade.modules.business.vo.ApmRecordListVO;
import org.springblade.modules.business.vo.ApmRecordVO;
import org.springblade.modules.business.vo.NoticeVO;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;

@ -1,39 +0,0 @@
/*
* 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.modules.business.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.business.entity.Notice;
import org.springblade.modules.business.vo.NoticeVO;
/**
* 服务类
*
* @author Chill
*/
public interface INoticeService extends BaseService<Notice> {
/**
* 自定义分页
* @param page
* @param notice
* @return
*/
IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice);
}

@ -1,43 +0,0 @@
/*
* 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.modules.business.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.business.entity.Notice;
import org.springblade.modules.business.mapper.NoticeMapper;
import org.springblade.modules.business.service.INoticeService;
import org.springblade.modules.business.vo.NoticeVO;
import org.springframework.stereotype.Service;
/**
* 服务实现类
*
* @author Chill
*/
@Service
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> implements INoticeService {
@Override
public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeVO notice) {
// 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入
notice.setTenantId(AuthUtil.getTenantId());
return page.setRecords(baseMapper.selectNoticePage(page, notice));
}
}

@ -1,23 +0,0 @@
package org.springblade.modules.business.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.business.entity.Notice;
/**
* 通知公告视图类
*
* @author Chill
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class NoticeVO extends Notice {
@ApiModelProperty(value = "通知类型名")
private String categoryName;
@ApiModelProperty(value = "租户编号")
private String tenantId;
}

@ -1,64 +0,0 @@
/*
* 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.modules.business.wrapper;
import org.springblade.common.cache.DictCache;
import org.springblade.common.enums.DictEnum;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.entity.Notice;
import org.springblade.modules.business.vo.NoticeVO;
import java.util.Map;
import java.util.Objects;
/**
* Notice包装类,返回视图层所需的字段
*
* @author Chill
*/
public class NoticeWrapper extends BaseEntityWrapper<Notice, NoticeVO> {
public static NoticeWrapper build() {
return new NoticeWrapper();
}
@Override
public NoticeVO entityVO(Notice notice) {
NoticeVO noticeVO = Objects.requireNonNull(BeanUtil.copy(notice, NoticeVO.class));
String dictValue = DictCache.getValue(DictEnum.NOTICE, noticeVO.getCategory());
noticeVO.setCategoryName(dictValue);
return noticeVO;
}
/**
* 查询条件处理
*/
public void noticeQuery(Map<String, Object> notice) {
// 此场景仅在 pg数据库 map类型传参的情况下需要处理,entity传参已经包含数据类型,则无需关心
// 针对 pg数据库 int类型字段查询需要强转的处理示例
String searchKey = "category";
if (Func.isNotEmpty(notice.get(searchKey))) {
// 数据库字段为int类型,设置"="查询,具体查询参数请见 @org.springblade.core.mp.support.SqlKeyword
notice.put(searchKey.concat("_equal"), Func.toInt(notice.get(searchKey)));
// 默认"like"查询,pg数据库 场景会报错,所以将其删除
notice.remove(searchKey);
}
}
}

@ -1,50 +0,0 @@
/*
* 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.modules.resource.builder.sms;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.SneakyThrows;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.AliSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.modules.resource.entity.Sms;
/**
* 阿里云短信构建类
*
* @author Chill
*/
public class AliSmsBuilder {
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSecretKey(sms.getSecretKey());
smsProperties.setRegionId(sms.getRegionId());
smsProperties.setSignName(sms.getSignName());
IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAccessKey(), smsProperties.getSecretKey());
IAcsClient acsClient = new DefaultAcsClient(profile);
return new AliSmsTemplate(smsProperties, acsClient, bladeRedis);
}
}

@ -1,47 +0,0 @@
/*
* 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.modules.resource.builder.sms;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import lombok.SneakyThrows;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.QiniuSmsTemplate;
import org.springblade.modules.resource.entity.Sms;
/**
* 七牛云短信构建类
*
* @author Chill
*/
public class QiniuSmsBuilder {
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSecretKey(sms.getSecretKey());
smsProperties.setSignName(sms.getSignName());
Auth auth = Auth.create(smsProperties.getAccessKey(), smsProperties.getSecretKey());
SmsManager smsManager = new SmsManager(auth);
return new QiniuSmsTemplate(smsProperties, smsManager, bladeRedis);
}
}

@ -1,157 +0,0 @@
/*
* 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.modules.resource.builder.sms;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.enums.SmsEnum;
import org.springblade.core.sms.enums.SmsStatusEnum;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.modules.resource.entity.Sms;
import org.springblade.modules.resource.service.ISmsService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
/**
* Sms短信服务统一构建类
*
* @author Chill
*/
public class SmsBuilder {
public static final String SMS_CODE = "sms:code:";
public static final String SMS_PARAM_KEY = "code";
private final SmsProperties smsProperties;
private final ISmsService smsService;
private final BladeRedis bladeRedis;
public SmsBuilder(SmsProperties smsProperties, ISmsService smsService, BladeRedis bladeRedis) {
this.smsProperties = smsProperties;
this.smsService = smsService;
this.bladeRedis = bladeRedis;
}
/**
* SmsTemplate配置缓存池
*/
private final Map<String, SmsTemplate> templatePool = new ConcurrentHashMap<>();
/**
* Sms配置缓存池
*/
private final Map<String, Sms> smsPool = new ConcurrentHashMap<>();
/**
* 获取template
*
* @return SmsTemplate
*/
public SmsTemplate template() {
return template(StringPool.EMPTY);
}
/**
* 获取template
*
* @param code 资源编号
* @return SmsTemplate
*/
public SmsTemplate template(String code) {
String tenantId = AuthUtil.getTenantId();
Sms sms = getSms(tenantId, code);
Sms smsCached = smsPool.get(tenantId);
SmsTemplate template = templatePool.get(tenantId);
// 若为空或者不一致,则重新加载
if (Func.hasEmpty(template, smsCached) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
synchronized (SmsBuilder.class) {
template = templatePool.get(tenantId);
if (Func.hasEmpty(template, smsCached) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
if (sms.getCategory() == SmsEnum.YUNPIAN.getCategory()) {
template = YunpianSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.QINIU.getCategory()) {
template = QiniuSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.ALI.getCategory()) {
template = AliSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.TENCENT.getCategory()) {
template = TencentSmsBuilder.template(sms, bladeRedis);
}
templatePool.put(tenantId, template);
smsPool.put(tenantId, sms);
}
}
}
return template;
}
/**
* 获取短信实体
*
* @param tenantId 租户ID
* @return Sms
*/
public Sms getSms(String tenantId, String code) {
String key = tenantId;
LambdaQueryWrapper<Sms> lqw = Wrappers.<Sms>query().lambda().eq(Sms::getTenantId, tenantId);
// 获取传参的资源编号并查询,若有则返回,若没有则调启用的配置
String smsCode = StringUtil.isBlank(code) ? WebUtil.getParameter(SMS_PARAM_KEY) : code;
if (StringUtil.isNotBlank(smsCode)) {
key = key.concat(StringPool.DASH).concat(smsCode);
lqw.eq(Sms::getSmsCode, smsCode);
} else {
lqw.eq(Sms::getStatus, SmsStatusEnum.ENABLE.getNum());
}
Sms sms = CacheUtil.get(RESOURCE_CACHE, SMS_CODE, key, () -> {
Sms s = smsService.getOne(lqw);
// 若为空则调用默认配置
if ((Func.isEmpty(s))) {
Sms defaultSms = new Sms();
defaultSms.setId(0L);
defaultSms.setTemplateId(smsProperties.getTemplateId());
defaultSms.setRegionId(smsProperties.getRegionId());
defaultSms.setCategory(SmsEnum.of(smsProperties.getName()).getCategory());
defaultSms.setAccessKey(smsProperties.getAccessKey());
defaultSms.setSecretKey(smsProperties.getSecretKey());
defaultSms.setSignName(smsProperties.getSignName());
return defaultSms;
} else {
return s;
}
});
if (sms == null || sms.getId() == null) {
throw new ServiceException("未获取到对应的短信配置");
} else {
return sms;
}
}
}

@ -1,46 +0,0 @@
/*
* 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.modules.resource.builder.sms;
import com.github.qcloudsms.SmsMultiSender;
import lombok.SneakyThrows;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.TencentSmsTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.resource.entity.Sms;
/**
* 腾讯云短信构建类
*
* @author Chill
*/
public class TencentSmsBuilder {
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSecretKey(sms.getSecretKey());
smsProperties.setSignName(sms.getSignName());
SmsMultiSender smsSender = new SmsMultiSender(Func.toInt(smsProperties.getAccessKey()), sms.getSecretKey());
return new TencentSmsTemplate(smsProperties, smsSender, bladeRedis);
}
}

@ -1,44 +0,0 @@
/*
* 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.modules.resource.builder.sms;
import com.yunpian.sdk.YunpianClient;
import lombok.SneakyThrows;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.YunpianSmsTemplate;
import org.springblade.modules.resource.entity.Sms;
/**
* 云片短信构建类
*
* @author Chill
*/
public class YunpianSmsBuilder {
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSignName(sms.getSignName());
YunpianClient client = new YunpianClient(smsProperties.getAccessKey()).init();
return new YunpianSmsTemplate(smsProperties, client, bladeRedis);
}
}

@ -1,47 +0,0 @@
/*
* 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.modules.resource.config;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.modules.resource.builder.sms.SmsBuilder;
import org.springblade.modules.resource.service.ISmsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Sms配置类
*
* @author Chill
*/
@Configuration(proxyBeanMethods = false)
@AllArgsConstructor
public class BladeSmsConfiguration {
private final SmsProperties smsProperties;
private final ISmsService smsService;
private final BladeRedis bladeRedis;
@Bean
public SmsBuilder smsBuilder() {
return new SmsBuilder(smsProperties, smsService, bladeRedis);
}
}

@ -1,62 +0,0 @@
/*
* 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.modules.resource.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.core.tool.utils.StringPool;
/**
* Sms资源编码枚举类
*
* @author Chill
* @apiNote 该枚举类对应短信配置模块的资源编码可根据业务需求自行拓展
*/
@Getter
@AllArgsConstructor
public enum SmsCodeEnum {
/**
* 默认编号
*/
DEFAULT(StringPool.EMPTY, 1),
/**
* 验证码编号
*/
VALIDATE("qiniu-validate", 2),
/**
* 通知公告编号
*/
NOTICE("notice", 3),
/**
* 下单通知编号
*/
ORDER("order", 4),
/**
* 会议通知编号
*/
MEETING("meeting", 5),
;
final String name;
final int category;
}

@ -1,109 +0,0 @@
/*
* 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.modules.resource.utils;
import org.springblade.core.sms.model.SmsCode;
import org.springblade.core.sms.model.SmsData;
import org.springblade.core.sms.model.SmsResponse;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.RandomType;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.resource.builder.sms.SmsBuilder;
import java.util.HashMap;
import java.util.Map;
/**
* 短信服务工具类
*
* @author Chill
*/
public class SmsUtil {
public static final String PARAM_KEY = "code";
public static final String SEND_SUCCESS = "短信发送成功";
public static final String SEND_FAIL = "短信发送失败";
public static final String VALIDATE_SUCCESS = "短信校验成功";
public static final String VALIDATE_FAIL = "短信校验失败";
private static SmsBuilder smsBuilder;
/**
* 获取短信服务构建类
*
* @return SmsBuilder
*/
public static SmsBuilder getBuilder() {
if (smsBuilder == null) {
smsBuilder = SpringUtil.getBean(SmsBuilder.class);
}
return smsBuilder;
}
/**
* 获取短信验证码参数
*
* @return 验证码参数
*/
public static Map<String, String> getValidateParams() {
Map<String, String> params = new HashMap<>(1);
params.put(PARAM_KEY, StringUtil.random(6, RandomType.INT));
return params;
}
/**
* 发送短信
*
* @param code 资源编号
* @param params 模板参数
* @param phones 手机号集合
* @return 发送结果
*/
public static SmsResponse sendMessage(String code, Map<String, String> params, String phones) {
SmsData smsData = new SmsData(params);
return getBuilder().template(code).sendMessage(smsData, Func.toStrList(phones));
}
/**
* 发送验证码
*
* @param code 资源编号
* @param phone 手机号
* @return 发送结果
*/
public static SmsCode sendValidate(String code, String phone) {
Map<String, String> params = SmsUtil.getValidateParams();
return getBuilder().template(code).sendValidate(new SmsData(params).setKey(PARAM_KEY), phone);
}
/**
* 校验短信
*
* @param code 资源编号
* @param id 校验id
* @param value 校验值
* @param phone 手机号
* @return 发送结果
*/
public static boolean validateMessage(String code, String id, String value, String phone) {
SmsCode smsCode = new SmsCode().setId(id).setValue(value).setPhone(phone);
return getBuilder().template(code).validateMessage(smsCode);
}
}
Loading…
Cancel
Save