新增发送短信逻辑 获取资讯类
parent
053dec8c3e
commit
9a9f4158fe
@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
package me.zhengjie.annotation.rest;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* 使用redis进行分布式锁
|
||||
*/
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface RedisLock {
|
||||
|
||||
/**
|
||||
* redis锁 名字
|
||||
*/
|
||||
String lockName() default "";
|
||||
|
||||
/**
|
||||
* redis锁 key 支持spel表达式
|
||||
*/
|
||||
String key() default "";
|
||||
|
||||
/**
|
||||
* 过期秒数,默认为5毫秒
|
||||
*
|
||||
* @return 轮询锁的时间
|
||||
*/
|
||||
int expire() default 5000;
|
||||
|
||||
/**
|
||||
* 超时时间单位
|
||||
*
|
||||
* @return 秒
|
||||
*/
|
||||
TimeUnit timeUnit() default TimeUnit.MILLISECONDS;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
|
||||
|
||||
package me.zhengjie.aspect;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.annotation.rest.RedisLock;
|
||||
import me.zhengjie.utils.SpelUtil;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author lgh
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RedisLockAspect {
|
||||
|
||||
private final RedissonClient redissonClient;
|
||||
|
||||
private static final String REDISSON_LOCK_PREFIX = "redisson_lock:";
|
||||
|
||||
@Around("@annotation(redisLock)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, RedisLock redisLock) throws Throwable {
|
||||
String key = redisLock.key();
|
||||
String lockName = redisLock.lockName();
|
||||
RLock rLock = redissonClient.getLock(getRedisKey(joinPoint, lockName, key));
|
||||
rLock.lock(redisLock.expire(), redisLock.timeUnit());
|
||||
Object result;
|
||||
try {
|
||||
//执行方法
|
||||
result = joinPoint.proceed();
|
||||
} finally {
|
||||
rLock.unlock();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将spel表达式转换为字符串
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
* @return redisKey
|
||||
*/
|
||||
private String getRedisKey(ProceedingJoinPoint joinPoint, String lockName, String spel) {
|
||||
Signature signature = joinPoint.getSignature();
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
Method targetMethod = methodSignature.getMethod();
|
||||
Object target = joinPoint.getTarget();
|
||||
Object[] arguments = joinPoint.getArgs();
|
||||
return REDISSON_LOCK_PREFIX + lockName + StrUtil.COLON + SpelUtil.parse(target, spel, targetMethod, arguments);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package me.zhengjie.config;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/9/7
|
||||
*/
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.config.Config;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.SentinelServersConfig;
|
||||
import org.redisson.config.SingleServerConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnClass(Config.class)
|
||||
@EnableConfigurationProperties(RedissonProperties.class)
|
||||
public class RedissonAutoConfiguration {
|
||||
|
||||
private final RedissonProperties redissonProperties;
|
||||
|
||||
/**
|
||||
* 哨兵模式自动装配
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(name="redisson.master-name")
|
||||
RedissonClient redissonSentinel() {
|
||||
Config config = new Config();
|
||||
SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redissonProperties.getSentinelAddresses())
|
||||
.setMasterName(redissonProperties.getMasterName())
|
||||
.setTimeout(redissonProperties.getTimeout())
|
||||
.setMasterConnectionPoolSize(redissonProperties.getMasterConnectionPoolSize())
|
||||
.setSlaveConnectionPoolSize(redissonProperties.getSlaveConnectionPoolSize());
|
||||
if(StringUtils.isNotBlank(redissonProperties.getPassword())) {
|
||||
serverConfig.setPassword(redissonProperties.getPassword());
|
||||
}
|
||||
return Redisson.create(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单机模式自动装配
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(name="redisson.address")
|
||||
RedissonClient redissonSingle() {
|
||||
Config config = new Config();
|
||||
SingleServerConfig serverConfig = config.useSingleServer()
|
||||
.setAddress(redissonProperties.getAddress())
|
||||
.setTimeout(redissonProperties.getTimeout())
|
||||
.setConnectionPoolSize(redissonProperties.getConnectionPoolSize())
|
||||
.setConnectionMinimumIdleSize(redissonProperties.getConnectionMinimumIdleSize());
|
||||
|
||||
if(StringUtils.isNotBlank(redissonProperties.getPassword())) {
|
||||
serverConfig.setPassword(redissonProperties.getPassword());
|
||||
}
|
||||
return Redisson.create(config);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package me.zhengjie.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/9/7
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "redisson")
|
||||
@ConditionalOnProperty("redisson.password")
|
||||
public class RedissonProperties {
|
||||
|
||||
private int timeout = 3000;
|
||||
|
||||
private String address;
|
||||
|
||||
private String masterName;
|
||||
|
||||
private String password;
|
||||
|
||||
private int database = 0;
|
||||
|
||||
private String[] sentinelAddresses;
|
||||
|
||||
private int connectionPoolSize = 64;
|
||||
|
||||
private int connectionMinimumIdleSize = 10;
|
||||
|
||||
private int slaveConnectionPoolSize = 250;
|
||||
|
||||
private int masterConnectionPoolSize = 250;
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package me.zhengjie.config.thread;
|
||||
|
||||
import me.zhengjie.modules.constant.DefaultConstant;
|
||||
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* 线程池配置总类,用于配置线程池
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class ThreadPoolSendMessage {
|
||||
|
||||
|
||||
/**
|
||||
* produce
|
||||
*/
|
||||
@Value(value = "${save.task.sendMessage.corePoolSize}")
|
||||
private int saveCorePoolSize = 2;
|
||||
@Value(value = "${save.task.sendMessage.maxPoolSize}")
|
||||
private int saveMaxPoolSize = 16;
|
||||
@Value(value = "${save.task.sendMessage.queueCapacity}")
|
||||
private int saveQueueCapacity = 3;
|
||||
|
||||
|
||||
@Bean(value = "sendMessageTaskExecutor")
|
||||
public Executor SendBigDataTaskExecutor(){
|
||||
return new ThreadPoolExecutor(saveCorePoolSize,
|
||||
saveMaxPoolSize,
|
||||
DefaultConstant.THREE_NUMBER,
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingDeque<>(saveQueueCapacity),
|
||||
Executors.defaultThreadFactory(),
|
||||
new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description /
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="tb_sms_configuration")
|
||||
public class SmsConfiguration implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@ApiModelProperty(value = "配置id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id")
|
||||
@ApiModelProperty(value = "角色ID")
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "message_content")
|
||||
@ApiModelProperty(value = "短信内容")
|
||||
private String messageContent;
|
||||
|
||||
@Column(name = "picture_path")
|
||||
@ApiModelProperty(value = "图片路径")
|
||||
private String picturePath;
|
||||
|
||||
@Column(name = "image_url")
|
||||
@ApiModelProperty(value = "图片路径")
|
||||
private String imageUrl;
|
||||
|
||||
@Column(name = "link_address")
|
||||
@ApiModelProperty(value = "跳转链接")
|
||||
private String linkAddress;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "create_time")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private Timestamp createTime;
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "update_time")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Timestamp updateTime;
|
||||
|
||||
public void copy(SmsConfiguration source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.repository;
|
||||
|
||||
import me.zhengjie.modules.sms.domain.SmsConfiguration;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
public interface SmsConfigurationRepository extends JpaRepository<SmsConfiguration, Long>, JpaSpecificationExecutor<SmsConfiguration> {
|
||||
/**
|
||||
* 用户id查找
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
SmsConfiguration findByUserId(Long userId);
|
||||
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.annotation.Log;
|
||||
import me.zhengjie.common.http.CommonResponse;
|
||||
import me.zhengjie.common.http.ResponseCode;
|
||||
import me.zhengjie.modules.sms.domain.SmsConfiguration;
|
||||
import me.zhengjie.modules.sms.service.SmsConfigurationService;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationDto;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationQueryCriteria;
|
||||
import me.zhengjie.modules.sms.vo.UploadAndSendMessageVo;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @website https://el-admin.vip
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "短信配置管理")
|
||||
@RequestMapping("/api/smsConfiguration")
|
||||
public class SmsConfigurationController {
|
||||
|
||||
private final SmsConfigurationService smsConfigurationService;
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('SmsConfiguration:list')")
|
||||
public void download(HttpServletResponse response, SmsConfigurationQueryCriteria criteria) throws IOException {
|
||||
smsConfigurationService.download(smsConfigurationService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询短信配置参数")
|
||||
@ApiOperation("查询短信配置参数")
|
||||
@PreAuthorize("@el.check('SmsConfiguration:list')")
|
||||
public ResponseEntity<Object> query(SmsConfigurationQueryCriteria criteria, Pageable pageable) {
|
||||
return new ResponseEntity<>(smsConfigurationService.queryAll(criteria, pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增短信配置参数")
|
||||
@ApiOperation("新增新增短信配置参数")
|
||||
@PreAuthorize("@el.check('SmsConfiguration:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SmsConfiguration resources) {
|
||||
return new ResponseEntity<>(smsConfigurationService.create(resources, SecurityUtils.getCurrentUserId()), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@Log("获取短信配置详情")
|
||||
@ApiOperation("获取短信配置详情")
|
||||
public ResponseEntity<SmsConfigurationDto> detail(Long id) {
|
||||
return new ResponseEntity<>(smsConfigurationService.
|
||||
getSmsConfiguration(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改短信配置参数")
|
||||
@ApiOperation("修改修改短信配置参数")
|
||||
@PreAuthorize("@el.check('SmsConfiguration:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody SmsConfiguration resources) {
|
||||
smsConfigurationService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除短信配置")
|
||||
@ApiOperation("删除短信配置")
|
||||
@PreAuthorize("@el.check('SmsConfiguration:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||
smsConfigurationService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@Log("上传并发送短信")
|
||||
@ApiOperation("上传发送短信")
|
||||
@PostMapping("/fileSendMessage")
|
||||
public ResponseEntity<Object> fileSendMessage(@RequestParam("file") MultipartFile file,
|
||||
UploadAndSendMessageVo messageVo) {
|
||||
// 校验上传是否有文件
|
||||
if (file == null) {
|
||||
return new ResponseEntity<>(CommonResponse.createByError(ResponseCode.NO_FILE_INPUT), HttpStatus.OK);
|
||||
}
|
||||
Boolean result = smsConfigurationService.
|
||||
uploadAndSendMessage(file, messageVo, SecurityUtils.getCurrentUserId());
|
||||
return result != null && result ?
|
||||
new ResponseEntity<>(CommonResponse.createBySuccess
|
||||
(ResponseCode.SUCCESS), HttpStatus.OK)
|
||||
: new ResponseEntity<>(CommonResponse.createByError
|
||||
(ResponseCode.ERROR), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.service;
|
||||
|
||||
import me.zhengjie.modules.sms.domain.SmsConfiguration;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationDto;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationQueryCriteria;
|
||||
import me.zhengjie.modules.sms.vo.UploadAndSendMessageVo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description 服务接口
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
public interface SmsConfigurationService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(SmsConfigurationQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<SmsConfigurationDto>
|
||||
*/
|
||||
List<SmsConfigurationDto> queryAll(SmsConfigurationQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param userId ID
|
||||
* @return SmsConfigurationDto
|
||||
*/
|
||||
SmsConfigurationDto findById(Long userId);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources /
|
||||
* @param currentUserId 用户id
|
||||
* @return SmsConfigurationDto
|
||||
*/
|
||||
SmsConfigurationDto create(SmsConfiguration resources, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(SmsConfiguration resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
*/
|
||||
void deleteAll(Long[] ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<SmsConfigurationDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param id id
|
||||
* @return SmsConfigurationDto
|
||||
*/
|
||||
SmsConfigurationDto getSmsConfiguration(Long id);
|
||||
|
||||
/**
|
||||
* 上传并发送消息
|
||||
*
|
||||
* @param files
|
||||
* @param messageVo
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
Boolean uploadAndSendMessage(MultipartFile files, UploadAndSendMessageVo messageVo, Long currentUserId);
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @description /
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@Data
|
||||
public class SmsConfigurationDto implements Serializable {
|
||||
|
||||
/** 配置id */
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/** 角色ID */
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/** 短信内容 */
|
||||
private String messageContent;
|
||||
|
||||
/** 图片路径 */
|
||||
private String picturePath;
|
||||
|
||||
/** 跳转链接 */
|
||||
private String linkAddress;
|
||||
|
||||
/** 背景图片 */
|
||||
private String imageUrl;
|
||||
|
||||
/** 创建日期 */
|
||||
private Timestamp createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
private Timestamp updateTime;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@Data
|
||||
public class SmsConfigurationQueryCriteria{
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.annotation.rest.RedisLock;
|
||||
import me.zhengjie.common.http.ResponseCode;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.constant.DefaultConstant;
|
||||
import me.zhengjie.modules.sms.domain.SmsConfiguration;
|
||||
import me.zhengjie.modules.sms.repository.SmsConfigurationRepository;
|
||||
import me.zhengjie.modules.sms.service.SmsConfigurationService;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationDto;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationQueryCriteria;
|
||||
import me.zhengjie.modules.sms.service.mapstruct.SmsConfigurationMapper;
|
||||
import me.zhengjie.modules.sms.vo.UploadAndSendMessageVo;
|
||||
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
|
||||
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
|
||||
import me.zhengjie.modules.uploadnew.task.SendMessageTask;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static me.zhengjie.modules.upload.consts.UploadFileConst.FILE_PATH_SPLIT;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @website https://el-admin.vip
|
||||
* @description 服务实现
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsConfigurationServiceImpl implements SmsConfigurationService {
|
||||
|
||||
|
||||
private final SendMessageTask sendMessageTask;
|
||||
|
||||
private final TbUploadFileNewService tbUploadFileNewService;
|
||||
|
||||
private final SmsConfigurationMapper smsConfigurationMapper;
|
||||
|
||||
private final SmsConfigurationRepository smsConfigurationRepository;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(SmsConfigurationQueryCriteria criteria, Pageable pageable) {
|
||||
Page<SmsConfiguration> page = smsConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
return PageUtil.toPage(page.map(smsConfigurationMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmsConfigurationDto> queryAll(SmsConfigurationQueryCriteria criteria) {
|
||||
return smsConfigurationMapper.toDto(smsConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SmsConfigurationDto findById(Long userId) {
|
||||
SmsConfiguration smsConfiguration = smsConfigurationRepository.findById(userId).orElseGet(SmsConfiguration::new);
|
||||
ValidationUtil.isNull(smsConfiguration.getUserId(), "SmsConfiguration", "userId", userId);
|
||||
return smsConfigurationMapper.toDto(smsConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SmsConfigurationDto create(SmsConfiguration resources, Long currentUserId) {
|
||||
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||
resources.setUserId(currentUserId);
|
||||
resources.setId(snowflake.nextId());
|
||||
return smsConfigurationMapper.toDto(smsConfigurationRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SmsConfiguration resources) {
|
||||
SmsConfiguration smsConfiguration = smsConfigurationRepository.findById(resources.getUserId()).orElseGet(SmsConfiguration::new);
|
||||
ValidationUtil.isNull(smsConfiguration.getUserId(), "SmsConfiguration", "id", resources.getUserId());
|
||||
smsConfiguration.copy(resources);
|
||||
smsConfigurationRepository.save(smsConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Long[] ids) {
|
||||
for (Long userId : ids) {
|
||||
smsConfigurationRepository.deleteById(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<SmsConfigurationDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SmsConfigurationDto smsConfigurationDto : all) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("短信内容", smsConfigurationDto.getMessageContent());
|
||||
map.put("图片路径", smsConfigurationDto.getPicturePath());
|
||||
map.put("跳转链接", smsConfigurationDto.getLinkAddress());
|
||||
map.put("创建日期", smsConfigurationDto.getCreateTime());
|
||||
map.put("更新时间", smsConfigurationDto.getUpdateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmsConfigurationDto getSmsConfiguration(Long id) {
|
||||
SmsConfiguration smsConfiguration = smsConfigurationRepository.findById(id).orElseGet(SmsConfiguration::new);
|
||||
ValidationUtil.isNull(smsConfiguration, "SmsConfiguration", "id", smsConfiguration.getId());
|
||||
return smsConfigurationMapper.toDto(smsConfiguration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RedisLock(lockName = "uploadSendMessage", key = "#currentUserId")
|
||||
public Boolean uploadAndSendMessage(MultipartFile file, UploadAndSendMessageVo messageVo, Long currentUserId) {
|
||||
String name = file.getOriginalFilename();
|
||||
String taskName = messageVo.getTaskName();
|
||||
if (name != null) {
|
||||
int lastIndexOf = name.lastIndexOf(StrUtil.DOT);
|
||||
// 校验文件格式
|
||||
String nameStr = name.substring(lastIndexOf);
|
||||
if (!((".xlsx".equals(nameStr)
|
||||
|| ".xls".equals(nameStr))
|
||||
|| ".txt".equals(nameStr)
|
||||
|| ".csv".equals(nameStr))) {
|
||||
throw new BadRequestException(ResponseCode.NO_FILE_FORMAT.getDesc());
|
||||
}
|
||||
// 任务名称检验,为必填参数,且不能重复
|
||||
if (StringUtils.isNotBlank(taskName)) {
|
||||
if (StringUtils.contains(taskName, FILE_PATH_SPLIT)) {
|
||||
taskName = taskName.substring(0, taskName.length() - 1);
|
||||
}
|
||||
TbUploadFileNewDto tbUploadFileNewDto = tbUploadFileNewService.findByTaskName(taskName);
|
||||
if (tbUploadFileNewDto != null) {
|
||||
throw new BadRequestException(ResponseCode.TASK_NAME_IS_EXIST.getDesc());
|
||||
}
|
||||
}
|
||||
// 生成本地文件
|
||||
TbUploadFileNewDto tbUploadFileNewDto = tbUploadFileNewService.
|
||||
encryptDataAndSaveToFileNew(file, messageVo.getUploadType(), taskName, DefaultConstant.ZERO_NUMBER);
|
||||
// 如果临时生成失败就修改状态为失败
|
||||
if (Objects.isNull(tbUploadFileNewDto)) {
|
||||
log.error("TbUploadFileNewController:fileUpload | Operation Fail.tbUploadFileNewDto is Null");
|
||||
throw new BadRequestException(ResponseCode.TASK_FILE_SAVE_FAIL.getDesc());
|
||||
}
|
||||
SmsConfigurationDto configurationDto = createSmsConfiguration(messageVo, currentUserId);
|
||||
// 调用异步任务
|
||||
sendMessageTask.doRunTask(tbUploadFileNewDto, configurationDto);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private SmsConfigurationDto createSmsConfiguration(UploadAndSendMessageVo messageVo, Long currentUserId) {
|
||||
SmsConfiguration smsConfiguration = new SmsConfiguration();
|
||||
BeanUtil.copyProperties(messageVo, smsConfiguration);
|
||||
smsConfiguration.setUserId(currentUserId);
|
||||
return smsConfigurationMapper.toDto(smsConfigurationRepository.save(smsConfiguration));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.sms.service.mapstruct;
|
||||
|
||||
import me.zhengjie.base.BaseMapper;
|
||||
import me.zhengjie.modules.sms.domain.SmsConfiguration;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author Enzo
|
||||
* @date 2021-09-07
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface SmsConfigurationMapper extends BaseMapper<SmsConfigurationDto, SmsConfiguration> {
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package me.zhengjie.modules.sms.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2021-9-7
|
||||
*/
|
||||
@Data
|
||||
public class UploadAndSendMessageVo {
|
||||
|
||||
|
||||
|
||||
@ApiModelProperty("上传类型")
|
||||
private Integer uploadType;
|
||||
|
||||
@ApiModelProperty("任务名称")
|
||||
private String taskName;
|
||||
|
||||
@ApiModelProperty("背景图片")
|
||||
private String imageUrl;
|
||||
|
||||
@ApiModelProperty(value = "短信内容")
|
||||
private String messageContent;
|
||||
|
||||
@ApiModelProperty(value = "图片路径")
|
||||
private String picturePath;
|
||||
|
||||
|
||||
|
||||
@ApiModelProperty(value = "跳转链接")
|
||||
private String linkAddress;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
# please make the rsa key first
|
||||
|
||||
read line <
|
||||
|
||||
scp -i ~/.ssh/id_rsa devops@myserver.org:/path/to/bin/*.derp .
|
||||
|
||||
|
@ -0,0 +1,161 @@
|
||||
package me.zhengjie.modules.uploadnew.task;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.constant.SmsConstant;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.constant.DefaultConstant;
|
||||
import me.zhengjie.modules.sms.domain.TbSendSms;
|
||||
import me.zhengjie.modules.sms.dto.ShortLinkUrlDto;
|
||||
import me.zhengjie.modules.sms.service.TbSendSmsService;
|
||||
import me.zhengjie.modules.sms.service.dto.SmsConfigurationDto;
|
||||
import me.zhengjie.modules.sms.util.SmsUtil;
|
||||
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
|
||||
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService;
|
||||
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
|
||||
import me.zhengjie.modules.uploadnew.util.ExcelUtils;
|
||||
import me.zhengjie.modules.uploadnew.util.TxtUtils;
|
||||
import me.zhengjie.utils.ConvertUtil;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.enums.StatusEnum;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.zhengjie.modules.upload.consts.UploadFileConst.FAIL_TAG;
|
||||
import static me.zhengjie.modules.upload.consts.UploadFileConst.SUCCESS_TAG;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2021-9-7
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SendMessageTask {
|
||||
|
||||
private final TbSendSmsService tbSendSmsService;
|
||||
|
||||
private final TbUploadFileNewService tbUploadFileNewService;
|
||||
|
||||
@Async(value = "sendMessageTaskExecutor")
|
||||
public void doRunTask(TbUploadFileNewDto tbUploadFileNewDto, SmsConfigurationDto smsConfigurationDto) {
|
||||
Long startMilliSecond = Instant.now().toEpochMilli();
|
||||
log.info("====== [ task start running, task name is {} ] ======", "sendMessageTask");
|
||||
runTask(tbUploadFileNewDto, smsConfigurationDto);
|
||||
Long endMilliSecond = Instant.now().toEpochMilli();
|
||||
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "sendMessageTask", ConvertUtil.secondToTime(endMilliSecond - startMilliSecond));
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行异步任务
|
||||
*
|
||||
* @param tbUploadFileNewDto 需要传输用到的Bean
|
||||
* @param smsConfigurationDto
|
||||
*/
|
||||
private void runTask(TbUploadFileNewDto tbUploadFileNewDto, SmsConfigurationDto smsConfigurationDto) {
|
||||
// 获取需求的地址
|
||||
String tempFilesPath = tbUploadFileNewDto.getLocalSavePath();
|
||||
// 单文件处理
|
||||
boolean finalTag = handleEachFileContent(tempFilesPath, tbUploadFileNewDto.getFileFormat(), smsConfigurationDto);
|
||||
// 更新状态为成功,更新解析成功的条数
|
||||
TbUploadFileNew tbUploadFileNew = new TbUploadFileNew();
|
||||
BeanUtils.copyProperties(tbUploadFileNewDto, tbUploadFileNew);
|
||||
tbUploadFileNew.setFileTransSuccessCount(tbUploadFileNewDto.getFileCount());
|
||||
tbUploadFileNew.setUploadTag(finalTag ? SUCCESS_TAG : FAIL_TAG);
|
||||
tbUploadFileNewService.update(tbUploadFileNew);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对每一个文件的处理操作
|
||||
*
|
||||
* @param filePath 进行操作的每一个文件的路径
|
||||
* @param smsConfigurationDto
|
||||
*/
|
||||
private boolean handleEachFileContent(String filePath, String fileFormat, SmsConfigurationDto smsConfigurationDto) {
|
||||
//根据文件类型进行解析
|
||||
List<String> list = null;
|
||||
try {
|
||||
if ("excel文件".equals(fileFormat)) {
|
||||
ExcelUtils excelUtils = new ExcelUtils();
|
||||
list = excelUtils.excelParseListByUrl(filePath);
|
||||
} else if ("txt文件".equals(fileFormat)) {
|
||||
list = TxtUtils.txtParseListVyUrl(filePath);
|
||||
} else if ("csv文件".equals(fileFormat)) {
|
||||
list = TxtUtils.csvParseListByUrl(filePath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("SaveToFileTaskNew|batchSendToEncrypt ready send json is : {}", "");
|
||||
throw new BadRequestException("解析文件异常");
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
List<String> stringList = list.stream().filter
|
||||
(phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER).
|
||||
collect((Collectors.toList()));
|
||||
Map<String, Object> map = new HashMap<>(DefaultConstant.TWO_NUMBER);
|
||||
if (!CollectionUtils.isEmpty(stringList)) {
|
||||
map.put("baseUrlAddr", SmsConstant.LINK_ADDRESS.concat
|
||||
(smsConfigurationDto.getId().toString()));
|
||||
map.put("variableList", stringList);
|
||||
// 接收生成短链参数
|
||||
ShortLinkUrlDto urlDto =
|
||||
JSONUtil.toBean(HttpUtil.post
|
||||
(SmsConstant.SHORT_GENERATION_LINK,
|
||||
JSON.toJSONString(map)),
|
||||
ShortLinkUrlDto.class);
|
||||
String phone;
|
||||
String linkUrl;
|
||||
TbSendSms sendSms;
|
||||
if (!CollectionUtils.isEmpty(urlDto.getData().getShortChainResult())) {
|
||||
for (String resultUrl : urlDto.getData().getShortChainResult()) {
|
||||
sendSms = new TbSendSms();
|
||||
// StrUtil 工具类
|
||||
String[] split = StringUtils.split(resultUrl, SmsConstant.VERTICAL_LINE);
|
||||
phone = split[1];
|
||||
linkUrl = split[0];
|
||||
String sendMessage = smsConfigurationDto.getMessageContent().replace
|
||||
("${url}",
|
||||
StrUtil.SPACE +
|
||||
SmsConstant.SHORT_CHAIN_PREFIX + linkUrl + StrUtil.SPACE);
|
||||
sendSms.setPhone(phone);
|
||||
sendSms.setLinkUrl(linkUrl);
|
||||
sendSms.setSendMessage(sendMessage);
|
||||
sendSms.setIsLinkCallback(DefaultConstant.ZERO_NUMBER);
|
||||
sendSms.setSendTime(new Timestamp(System.currentTimeMillis()));
|
||||
boolean sendResult = SmsUtil.sendSms(phone, sendMessage, smsConfigurationDto.getId());
|
||||
sendSms.setSendStatus(sendResult ? StatusEnum.SUCCESS.getValue() : StatusEnum.UNSUCCESSFUL.getValue());
|
||||
tbSendSmsService.save(sendSms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 把临时存储的文件进行删除
|
||||
return delTempSaveFile(filePath);
|
||||
}
|
||||
|
||||
private boolean delTempSaveFile(String tempFilesPath) {
|
||||
boolean del = FileUtil.del(tempFilesPath);
|
||||
if (del) {
|
||||
log.info("======== [success del file, file path is {} ] ========", tempFilesPath);
|
||||
return Boolean.TRUE;
|
||||
} else {
|
||||
log.error("======== [fail del file, file path is {} ] ========", tempFilesPath);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package me.zhengjie.domain.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/9/8
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConsultVo {
|
||||
|
||||
private String picUrl;
|
||||
|
||||
private String title;
|
||||
|
||||
private String linkUrl;
|
||||
|
||||
}
|
Loading…
Reference in New Issue