错误码分组
This commit is contained in:
@@ -7,7 +7,7 @@ import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
*
|
||||
* system 系统,使用 1-002-000-000 段
|
||||
*/
|
||||
public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
|
||||
public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<SystemErrorCodeEnum> {
|
||||
|
||||
// ========== OAUTH2 模块 ==========
|
||||
OAUTH2_UNKNOWN(1001001000, "未知错误"), // 预留
|
||||
@@ -113,8 +113,16 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
// TODO: 2020-05-22 封装成start的时候,直接在start中定义一个统一的枚举,从中取值;
|
||||
@Override
|
||||
public int getGroup() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -85,6 +85,22 @@
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.experimental.Accessors;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
/** // TODO FROM 芋艿 to 2447007062:最好加下字段的注释哈;
|
||||
* @author:mac
|
||||
* @descriptio
|
||||
* @create: 2020-5-12 20:43:00
|
||||
|
||||
@@ -20,11 +20,12 @@ public class ServiceExceptionConfiguration {
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html
|
||||
public void initMessages() {
|
||||
List<ErrorCodeBO> list = errorCodeService.getErrorCodeList();
|
||||
errorCodeService.deleteSyStemErrorCode(SystemErrorCodeEnum.ADMIN_NOT_FOUND.getGroup());
|
||||
errorCodeService.addSystemErrorCodeList(SystemErrorCodeEnum.values());
|
||||
for (SystemErrorCodeEnum item : SystemErrorCodeEnum.values()) {
|
||||
ServiceExceptionUtil.put(item.getCode(), item.getMessage());
|
||||
}
|
||||
for (ErrorCodeBO bo : list) {
|
||||
for (ErrorCodeBO bo : errorCodeService.getErrorCodeByGroup(SystemErrorCodeEnum.ADMIN_NOT_FOUND.getGroup())) {
|
||||
ServiceExceptionUtil.put(bo.getCode(),bo.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package cn.iocoder.mall.system.biz.dao.errorcode;
|
||||
|
||||
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleResourceDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO;
|
||||
import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO;
|
||||
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
|
||||
import cn.iocoder.mall.system.biz.enums.errorcode.ErrorCodeTypeEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -42,4 +44,9 @@ public interface ErrorCodeMapper extends BaseMapper<ErrorCodeDO> {
|
||||
default List<ErrorCodeDO> selectByGroup(Integer group) {
|
||||
return selectList(new QueryWrapperX<ErrorCodeDO>().eqIfPresent("group", group));
|
||||
}
|
||||
|
||||
|
||||
default int deleteSyStemErrorCode(int group){
|
||||
return delete(new QueryWrapper<ErrorCodeDO>().eq("group", group));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.system.biz.dao.user;
|
||||
|
||||
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -25,12 +27,11 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
||||
* @return
|
||||
*/
|
||||
default IPage<UserDO> selectUserPage(UserPageDTO userPageDTO) {
|
||||
// TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦
|
||||
// TODO FROM 伟帆 to 芋艿: 这里是使用MP原生的判空,支持lambda好,还是使用QueryWrapperX,使用字段名字符串的好呢
|
||||
// TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦 [DONE]
|
||||
return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()),
|
||||
Wrappers.<UserDO>query().lambda()
|
||||
.eq(StringUtils.isNotBlank(userPageDTO.getNickname()), UserDO::getNickname, userPageDTO.getNickname())
|
||||
.eq(null != userPageDTO.getStatus(), UserDO::getStatus, userPageDTO.getStatus())
|
||||
new QueryWrapperX<UserDO>()
|
||||
.eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname())
|
||||
.eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,13 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 访问日志添加 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class AccessLogPageDTO {
|
||||
public class AccessLogPageDTO { // TODO FROM 芋艿 to 2447007062:有个 PageParams 类哈,可以继承
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/15 18:09
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface OperationLogging {
|
||||
|
||||
/**
|
||||
* 日志信息
|
||||
* @return
|
||||
*/
|
||||
String value();
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.aspect;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.iocoder.common.framework.util.HttpUtil;
|
||||
import cn.iocoder.common.framework.util.MallUtil;
|
||||
import cn.iocoder.mall.system.biz.log.operation.annotation.OperationLogging;
|
||||
import cn.iocoder.mall.system.biz.log.operation.enums.LogStatus;
|
||||
import cn.iocoder.mall.system.biz.log.operation.event.OperationLogEvent;
|
||||
import cn.iocoder.mall.system.biz.log.operation.model.dto.OperationLogDTO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/15 18:16
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Order(0)
|
||||
@RequiredArgsConstructor
|
||||
public class OperationLogAspect {
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
@Around("@annotation(operationLogging)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, OperationLogging operationLogging) throws Throwable {
|
||||
Signature signature = joinPoint.getSignature();
|
||||
String strClassName = joinPoint.getTarget().getClass().getName();
|
||||
String strMethodName = signature.getName();
|
||||
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
|
||||
|
||||
// 获取日志
|
||||
OperationLogDTO operationLogDTO = prodOperationLog();
|
||||
operationLogDTO.setMsg(operationLogging.value());
|
||||
// 记录参数
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
operationLogDTO.setParams(getParams(joinPoint, methodSignature));
|
||||
// 开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object result;
|
||||
try {
|
||||
result = joinPoint.proceed();
|
||||
} catch (Throwable throwable) {
|
||||
operationLogDTO.setStatus(LogStatus.FAIL.getValue());
|
||||
throw throwable;
|
||||
}
|
||||
// 结束时间
|
||||
operationLogDTO.setResponseTime((int) (System.currentTimeMillis() - startTime));
|
||||
// 发布事件
|
||||
publisher.publishEvent(new OperationLogEvent(operationLogDTO));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取方法参数
|
||||
* @param joinPoint joinPoint
|
||||
* @param methodSignature 方法签名
|
||||
* @return 方法参数的Json字符串形式
|
||||
*/
|
||||
private String getParams(ProceedingJoinPoint joinPoint, MethodSignature methodSignature) {
|
||||
String[] parameterNames = methodSignature.getParameterNames();
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if(ArrayUtil.isEmpty(parameterNames)){
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> paramsMap = new HashMap<>();
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
paramsMap.put(parameterNames[i], args[i]);
|
||||
}
|
||||
return JSONUtil.toJsonStr(paramsMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据请求生成操作日志
|
||||
* @return 操作日志DTO
|
||||
*/
|
||||
private OperationLogDTO prodOperationLog() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects
|
||||
.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
|
||||
return new OperationLogDTO()
|
||||
.setTraceId(MallUtil.getTraceId())
|
||||
.setUri(URLUtil.getPath(request.getRequestURI()))
|
||||
.setUserAgent(HttpUtil.getUserAgent(request))
|
||||
.setIp(HttpUtil.getIp(request))
|
||||
.setMethod(request.getMethod())
|
||||
// TODO 获取管理员用户名 或者 用户ID
|
||||
// .setOperator(Objects.requireNonNull(LogUtils.getUsername()))
|
||||
.setStatus(LogStatus.SUCCESS.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.enums;
|
||||
|
||||
/**
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2020/5/15 14:47
|
||||
*/
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 操作状态
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum LogStatus {
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
SUCCESS(1),
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
FAIL(0);
|
||||
|
||||
private final int value;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.event;
|
||||
|
||||
import cn.iocoder.mall.system.biz.log.operation.model.dto.OperationLogDTO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* 系统日志事件
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class OperationLogEvent {
|
||||
private final OperationLogDTO operationLogDTO;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.event;
|
||||
|
||||
import cn.iocoder.mall.system.biz.log.operation.service.OperationLogSaveService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* 异步监听日志事件
|
||||
*/
|
||||
@Slf4j
|
||||
public class OperationLogListener {
|
||||
|
||||
@Autowired
|
||||
private OperationLogSaveService operationLogSaveService;
|
||||
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(OperationLogEvent.class)
|
||||
public void saveSysLog(OperationLogEvent event) {
|
||||
operationLogSaveService.saveLog(event.getOperationLogDTO());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.model.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 操作日志
|
||||
*
|
||||
* @author hccake
|
||||
* @date 2020-05-15 15:12:53
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "操作日志")
|
||||
public class OperationLogDTO{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*/
|
||||
@ApiModelProperty(value = "链路追踪编号")
|
||||
private String traceId;
|
||||
/**
|
||||
* 账号编号
|
||||
*/
|
||||
@ApiModelProperty(value = "账号编号")
|
||||
private Integer accountId;
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
@ApiModelProperty(value = "应用名")
|
||||
private String applicationName;
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
@ApiModelProperty(value = "访问地址")
|
||||
private String uri;
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
@ApiModelProperty(value = "参数")
|
||||
private String params;
|
||||
/**
|
||||
* http 方法
|
||||
*/
|
||||
@ApiModelProperty(value = "http 方法")
|
||||
private String method;
|
||||
/**
|
||||
* userAgent
|
||||
*/
|
||||
@ApiModelProperty(value = "userAgent")
|
||||
private String userAgent;
|
||||
/**
|
||||
* ip
|
||||
*/
|
||||
@ApiModelProperty(value = "ip")
|
||||
private String ip;
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
@ApiModelProperty(value = "请求时间")
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 响应时长 -- 毫秒级
|
||||
*/
|
||||
@ApiModelProperty(value = "响应时长 -- 毫秒级")
|
||||
private Integer responseTime;
|
||||
/**
|
||||
* 日志消息
|
||||
*/
|
||||
@ApiModelProperty(value = "日志消息")
|
||||
private String msg;
|
||||
/**
|
||||
* 操作状态
|
||||
*/
|
||||
@ApiModelProperty(value = "操作状态")
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@ApiModelProperty(value = "创建者")
|
||||
private String operator;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 操作日志
|
||||
*
|
||||
* @author hccake
|
||||
* @date 2020-05-15 15:12:53
|
||||
*/
|
||||
@Data
|
||||
@TableName("operation_log")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "操作日志")
|
||||
public class OperationLogPO extends Model<OperationLogPO> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*/
|
||||
private String traceId;
|
||||
/**
|
||||
* 账号编号
|
||||
*/
|
||||
private Integer accountId;
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
private String applicationName;
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
private String uri;
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private String params;
|
||||
/**
|
||||
* http 方法
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* userAgent
|
||||
*/
|
||||
private String userAgent;
|
||||
/**
|
||||
* ip
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 请求时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 响应时长 -- 毫秒级
|
||||
*/
|
||||
private Integer responseTime;
|
||||
/**
|
||||
* 日志消息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 操作状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String operator;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.system.biz.log.operation.service;
|
||||
|
||||
|
||||
import cn.iocoder.mall.system.biz.log.operation.model.dto.OperationLogDTO;
|
||||
|
||||
/**
|
||||
* 操作日志业务类
|
||||
* @author Hccake
|
||||
* @version 1.0
|
||||
* @date 2019/10/15 19:57
|
||||
*/
|
||||
public interface OperationLogSaveService {
|
||||
|
||||
/**
|
||||
* 保存操作日志
|
||||
* @param operationLogDTO
|
||||
* @return true/false
|
||||
*/
|
||||
boolean saveLog(OperationLogDTO operationLogDTO);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.mall.system.biz.service.errorcode;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.errorcode.ErrorCodeDO;
|
||||
@@ -53,6 +54,13 @@ public interface ErrorCodeService extends IService<ErrorCodeDO>{
|
||||
*/
|
||||
Boolean addErrorCodeList(List<ErrorCodeAddDTO> list);
|
||||
|
||||
/**
|
||||
* 批量添加错误码信息,项目启动时初始化错误码信息。
|
||||
* @param enumerable 错误码枚举类
|
||||
* @return 是否成功
|
||||
*/
|
||||
Boolean addSystemErrorCodeList(ServiceExceptionUtil.Enumerable[] enumerable);
|
||||
|
||||
/**
|
||||
* 更新错误码,系统内置错误码是不允许更新
|
||||
* @param errorCodeUpdateDTO 错误码信息
|
||||
@@ -64,4 +72,10 @@ public interface ErrorCodeService extends IService<ErrorCodeDO>{
|
||||
* @param errorCodeDeleteDTO 只允许删除自定义错误码
|
||||
*/
|
||||
void deleteErrorCode(ErrorCodeDeleteDTO errorCodeDeleteDTO);
|
||||
|
||||
/**
|
||||
* 删除分组下的错误码,只提供给服务初始化时候
|
||||
* @param group 分组
|
||||
*/
|
||||
void deleteSyStemErrorCode(int group);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,21 @@ public class ErrorCodeServiceImpl extends ServiceImpl<ErrorCodeMapper, ErrorCode
|
||||
return this.saveBatch(doList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addSystemErrorCodeList(ServiceExceptionUtil.Enumerable[] enumerable) {
|
||||
List<ErrorCodeDO> doList = new ArrayList<>();
|
||||
for (ServiceExceptionUtil.Enumerable errorCodeEnum : enumerable){
|
||||
ErrorCodeDO errorCode = new ErrorCodeDO().setCode(errorCodeEnum.getCode()).
|
||||
setMessage(errorCodeEnum.getMessage()).setType(ErrorCodeTypeEnum.SYSTEM.getType())
|
||||
.setGroup(errorCodeEnum.getGroup());
|
||||
errorCode.setCreateTime(new Date());
|
||||
errorCode.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
doList.add(errorCode);
|
||||
}
|
||||
// TODO 插入操作日志
|
||||
return this.saveBatch(doList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateErrorCode(ErrorCodeUpdateDTO errorCodeUpdateDTO) {
|
||||
// 校验错误码是否存在
|
||||
@@ -118,8 +133,12 @@ public class ErrorCodeServiceImpl extends ServiceImpl<ErrorCodeMapper, ErrorCode
|
||||
// TODO FROM 芋艿 to 鱿鱼丝:不能删除内置错误码
|
||||
// 更新到数据库,标记删除
|
||||
errorCodeMapper.deleteById(errorCodeDO.getId());
|
||||
// TODO: 2020-05-10 刷新对外提供的错误码列表
|
||||
// TODO: 2020-05-10 ServiceExceptionUtil中未提供去除错误码操作,后续新增此接口是否影响?
|
||||
ServiceExceptionUtil.delete(errorCodeDO.getCode(),errorCodeDO.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSyStemErrorCode(int group) {
|
||||
errorCodeMapper.deleteSyStemErrorCode(group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,7 +80,6 @@ public class AliYunSmsClient implements SmsClient {
|
||||
request.putQueryParameter("SignName", sign);
|
||||
request.putQueryParameter("TemplateCode", templateCode);
|
||||
request.putQueryParameter("TemplateParam", JSON.toJSONString(templateParams));
|
||||
|
||||
// 发送请求
|
||||
return doSend(request);
|
||||
}
|
||||
@@ -88,19 +87,17 @@ public class AliYunSmsClient implements SmsClient {
|
||||
@Override
|
||||
public SendResult batchSend(List<String> mobileList, String sign, String templateCode,
|
||||
String template, Map<String, String> templateParams) {
|
||||
|
||||
// 最大发送数为 1000,我们设置为 500 个, 分段发送
|
||||
int maxSendSize = MAX_BATCH_SIZE;
|
||||
int maxSendSizeCount = mobileList.size() % maxSendSize == 0
|
||||
? mobileList.size() / maxSendSize
|
||||
: mobileList.size() / maxSendSize + 1;
|
||||
|
||||
// 处理批量
|
||||
SendResult sendResult = null;
|
||||
for (int i = 0; i < maxSendSizeCount; i++) {
|
||||
// 分批发送
|
||||
List<String> batchSendMobile = mobileList
|
||||
.subList(i * maxSendSize, (i + 1) * maxSendSize);
|
||||
|
||||
// params
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.setMethod(MethodType.POST);
|
||||
@@ -111,7 +108,6 @@ public class AliYunSmsClient implements SmsClient {
|
||||
request.putQueryParameter("SignNameJson", JSON.toJSONString(Collections.singletonList(sign)));
|
||||
request.putQueryParameter("TemplateCode", templateCode);
|
||||
request.putQueryParameter("TemplateParamJson", JSON.toJSONString(Collections.singletonList(templateParams)));
|
||||
|
||||
// 发送请求
|
||||
sendResult = doSend(request);
|
||||
}
|
||||
@@ -125,9 +121,7 @@ public class AliYunSmsClient implements SmsClient {
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
Result result = JSON.parseObject(response.getData(), Result.class);
|
||||
if (!SUCCESS_CODE.equals(result.getCode())) {
|
||||
|
||||
LOGGER.info("发送验证码失败 params {} res {}", JSON.toJSON(request), JSON.toJSON(result));
|
||||
|
||||
// 错误发送失败
|
||||
return new SendResult()
|
||||
.setIsSuccess(false)
|
||||
@@ -135,7 +129,6 @@ public class AliYunSmsClient implements SmsClient {
|
||||
.setMessage(result.getMessage());
|
||||
} else {
|
||||
LOGGER.info("发送验证码失败 params {} res", JSON.toJSON(request), JSON.toJSON(result));
|
||||
|
||||
// 发送成功
|
||||
return new SendResult()
|
||||
.setIsSuccess(true)
|
||||
|
||||
@@ -23,6 +23,7 @@ import cn.iocoder.mall.system.biz.dto.smsTemplate.ListSmsTemplateDTO;
|
||||
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
|
||||
import cn.iocoder.mall.system.biz.enums.sms.SmsApplyStatusEnum;
|
||||
import cn.iocoder.mall.system.biz.enums.sms.SmsPlatformEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -70,16 +71,14 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public PageResult<ListSmsTemplateBO> listSmsTemplate(ListSmsTemplateDTO listSmsTemplateDTO) {
|
||||
// 获取 template
|
||||
IPage<SmsTemplateDO> signPage = smsTemplateMapper.listSmsTemplate(listSmsTemplateDTO);
|
||||
|
||||
List<ListSmsTemplateBO> templateList
|
||||
= SmsTemplateConvert.INSTANCE.convert(signPage.getRecords());
|
||||
|
||||
if (CollectionUtils.isEmpty(templateList)) {
|
||||
if (CollectionUtils.isEmpty(signPage.getRecords())) {
|
||||
// TODO DOME FROM 芋艿 to 小范,Collections.EMPTY_LIST =》Collections.emptyList();另外,可以考虑直接 Convert 哈
|
||||
return new PageResult<ListSmsTemplateBO>().setList(Collections.emptyList()).setTotal(signPage.getTotal());
|
||||
}
|
||||
|
||||
// 转换bo
|
||||
List<ListSmsTemplateBO> templateList = SmsTemplateConvert.INSTANCE.convert(signPage.getRecords());
|
||||
// 获取 sign
|
||||
Set<Integer> smsSignIds = templateList.stream().map(
|
||||
ListSmsTemplateBO::getSmsSignId).collect(Collectors.toSet());
|
||||
@@ -88,37 +87,32 @@ public class SmsServiceImpl implements SmsService {
|
||||
new QueryWrapper<SmsSignDO>().in("id", smsSignIds));
|
||||
|
||||
List<ListSmsTemplateBO.Sign> signList = SmsTemplateConvert.INSTANCE.convertTemplateSign(smsSignDOList);
|
||||
|
||||
// sign 转换为 map
|
||||
Map<Integer, ListSmsTemplateBO.Sign> smsSignDOMap = signList
|
||||
.stream().collect(Collectors.toMap(ListSmsTemplateBO.Sign::getId, o -> o));
|
||||
|
||||
// 设置 sign
|
||||
|
||||
templateList.forEach(template -> {
|
||||
if (smsSignDOMap.containsKey(template.getSmsSignId())) {
|
||||
template.setSign(smsSignDOMap.get(template.getSmsSignId()));
|
||||
}
|
||||
});
|
||||
|
||||
return new PageResult<ListSmsTemplateBO>().setList(templateList).setTotal(signPage.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addSign(AddSignDTO addSignDTO) {
|
||||
|
||||
// 避免重复
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>()
|
||||
.eq("platform", addSignDTO.getPlatform())
|
||||
.eq("sign", addSignDTO.getSign())
|
||||
);
|
||||
|
||||
// 处理 null 情况
|
||||
if (smsSignDO != null) {
|
||||
// TODO DOME FROM 芋艿 to 小范:可以使用 ServiceExceptionUtil.exception(SystemErrorCodeEnum.SMS_SIGN_IS_EXISTENT);
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.SMS_SIGN_IS_EXISTENT);
|
||||
}
|
||||
|
||||
// 保存数据库
|
||||
smsSignMapper.insert(
|
||||
(SmsSignDO) new SmsSignDO()
|
||||
@@ -133,16 +127,17 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public SmsSignBO getSign(Integer signId) {
|
||||
// 查询数据库
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>()
|
||||
.eq("id", signId)
|
||||
.eq("deleted", DeletedStatusEnum.DELETED_NO.getValue()));
|
||||
|
||||
// 处理 null
|
||||
if (smsSignDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 转换vo返回
|
||||
return SmsSignConvert.INSTANCE.convert(smsSignDO);
|
||||
}
|
||||
|
||||
@@ -154,12 +149,11 @@ public class SmsServiceImpl implements SmsService {
|
||||
new QueryWrapper<SmsSignDO>()
|
||||
.eq("sign", updateSignDTO.getSign())
|
||||
.eq("platform", updateSignDTO.getPlatform()));
|
||||
|
||||
// 处理 null
|
||||
if (smsSignDO != null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_IS_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 更新
|
||||
smsSignMapper.update(
|
||||
(SmsSignDO) new SmsSignDO()
|
||||
@@ -172,15 +166,13 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public void deleteSign(Integer id) {
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>()
|
||||
.eq("id", id));
|
||||
|
||||
// 根据id查询
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectById(id);
|
||||
// 处理 null
|
||||
if (smsSignDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 更新 deleted 为 YES
|
||||
smsSignMapper.delete(new UpdateWrapper<SmsSignDO>()
|
||||
.set("deleted", DeletedStatusEnum.DELETED_YES.getName())
|
||||
@@ -192,15 +184,13 @@ public class SmsServiceImpl implements SmsService {
|
||||
@Transactional
|
||||
public void addTemplate(Integer smsSignId, String templateCode,
|
||||
String template, Integer platform, Integer smsType) {
|
||||
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>().eq("id", smsSignId));
|
||||
|
||||
// 根据id查询
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectById(smsSignId);
|
||||
// 处理 null
|
||||
if (smsSignDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 保存数据库
|
||||
smsTemplateMapper.insert(
|
||||
(SmsTemplateDO) new SmsTemplateDO()
|
||||
@@ -219,16 +209,17 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public SmsTemplateBO getTemplate(Integer id, Integer platform) {
|
||||
// 获取数据
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne(
|
||||
new QueryWrapper<SmsTemplateDO>()
|
||||
.eq("platform", platform)
|
||||
.eq("id", id));
|
||||
|
||||
// 处理 null
|
||||
if (smsTemplateDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 转换bo返回
|
||||
return SmsTemplateConvert.INSTANCE.convert(smsTemplateDO);
|
||||
}
|
||||
|
||||
@@ -236,22 +227,20 @@ public class SmsServiceImpl implements SmsService {
|
||||
@Transactional
|
||||
public void updateTemplate(Integer id, Integer smsSignId, String templateCode,
|
||||
String template, Integer platform, Integer smsType) {
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne(
|
||||
new QueryWrapper<SmsTemplateDO>().eq("id", id));
|
||||
|
||||
// 获取 template
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectById(id);
|
||||
if (smsTemplateDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 获取 sign
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>().eq("id", smsTemplateDO.getSmsSignId()));
|
||||
|
||||
if (smsSignDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
smsTemplateMapper.update(
|
||||
(SmsTemplateDO) new SmsTemplateDO()
|
||||
.setSmsSignId(smsSignId)
|
||||
@@ -269,13 +258,12 @@ public class SmsServiceImpl implements SmsService {
|
||||
public void deleteTemplate(Integer id) {
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne(
|
||||
new QueryWrapper<SmsTemplateDO>().eq("id", id));
|
||||
|
||||
// 处理不存在情况
|
||||
if (smsTemplateDO == null
|
||||
|| smsTemplateDO.getDeleted().equals(DeletedStatusEnum.DELETED_YES.getValue())) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 删除 数据库模板
|
||||
SmsTemplateDO updateTemplate =new SmsTemplateDO();
|
||||
updateTemplate.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
||||
@@ -287,29 +275,24 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public void singleSend(String mobile, Integer smsTemplateId, Map<String, String> params) {
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne(
|
||||
new QueryWrapper<SmsTemplateDO>().eq("id", smsTemplateId));
|
||||
|
||||
// 获取 template
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectById(smsTemplateId);
|
||||
if (smsTemplateDO == null
|
||||
|| smsTemplateDO.getDeleted().equals(DeletedStatusEnum.DELETED_YES.getValue())) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>().eq("id", smsTemplateDO.getSmsSignId()));
|
||||
|
||||
// 获取 sign
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectById(smsTemplateDO.getSmsSignId());
|
||||
if (smsSignDO == null) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 获取 client
|
||||
SmsClient smsClient = getSmsClient(smsTemplateDO.getPlatform());
|
||||
// 发送短信
|
||||
SmsClient.SendResult sendResult = smsClient.singleSend(mobile, smsSignDO.getSign(),
|
||||
smsTemplateDO.getTemplateCode(), smsTemplateDO.getTemplate(), params);
|
||||
|
||||
// 添加日志
|
||||
smsSendMapper.insert(
|
||||
(SmsSendLogDO) new SmsSendLogDO()
|
||||
@@ -322,18 +305,15 @@ public class SmsServiceImpl implements SmsService {
|
||||
|
||||
@Override
|
||||
public void batchSend(List<String> mobileList, Integer smsTemplateId, Map<String, String> params) {
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectOne(
|
||||
new QueryWrapper<SmsTemplateDO>().eq("id", smsTemplateId));
|
||||
|
||||
// 获取 template
|
||||
SmsTemplateDO smsTemplateDO = smsTemplateMapper.selectById(smsTemplateId);
|
||||
if (smsTemplateDO == null
|
||||
|| smsTemplateDO.getDeleted().equals(DeletedStatusEnum.DELETED_YES.getValue())) {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_TEMPLATE_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectOne(
|
||||
new QueryWrapper<SmsSignDO>().eq("id", smsTemplateDO.getSmsSignId()));
|
||||
|
||||
// 获取 sign
|
||||
SmsSignDO smsSignDO = smsSignMapper.selectById(smsTemplateDO.getSmsSignId());
|
||||
if (smsSignDO == null) {
|
||||
// 添加日志
|
||||
smsSendMapper.insert(
|
||||
@@ -347,14 +327,11 @@ public class SmsServiceImpl implements SmsService {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_SIGN_NOT_EXISTENT.getMessage());
|
||||
}
|
||||
|
||||
// 获取 client
|
||||
SmsClient smsClient = getSmsClient(smsTemplateDO.getPlatform());
|
||||
|
||||
// 发送短信
|
||||
SmsClient.SendResult sendResult = smsClient.batchSend(mobileList, smsSignDO.getSign(),
|
||||
smsTemplateDO.getTemplateCode(), smsTemplateDO.getTemplate(), params);
|
||||
|
||||
// 添加日志
|
||||
smsSendMapper.insert(
|
||||
(SmsSendLogDO) new SmsSendLogDO()
|
||||
@@ -373,18 +350,18 @@ public class SmsServiceImpl implements SmsService {
|
||||
*/
|
||||
private SmsClient getSmsClient(Integer platform) {
|
||||
SmsClient smsClient = null;
|
||||
// 阿里云和云片
|
||||
if (SmsPlatformEnum.YunPian.getValue().equals(platform)) {
|
||||
smsClient = smsYunPianClient;
|
||||
} else if (SmsPlatformEnum.AliYun.getValue().equals(platform)) {
|
||||
smsClient = smsAliYunClient;
|
||||
}
|
||||
|
||||
// 没有支持的平台
|
||||
if (smsClient == null) {
|
||||
throw new ServiceException(
|
||||
SystemErrorCodeEnum.SMS_NOT_SEND_CLIENT.getCode(),
|
||||
SystemErrorCodeEnum.SMS_NOT_SEND_CLIENT.getMessage());
|
||||
}
|
||||
|
||||
return smsClient;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ public class YunPianSmsClient implements SmsClient {
|
||||
*/
|
||||
private static final String URL_SEND_BATCH = "https://sms.yunpian.com/v2/sms/batch_send.json";
|
||||
|
||||
|
||||
//编码格式。发送编码格式统一用UTF-8
|
||||
private static String ENCODING = "UTF-8";
|
||||
|
||||
@@ -99,7 +98,6 @@ public class YunPianSmsClient implements SmsClient {
|
||||
public SendResult singleSend(String mobile, String sign, String templateCode, String template, Map<String, String> templateParams) {
|
||||
// build 模板
|
||||
template = buildTemplate(sign, template, templateParams);
|
||||
|
||||
// 请求参数
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("apikey", apiKey);
|
||||
@@ -114,7 +112,7 @@ public class YunPianSmsClient implements SmsClient {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_PLATFORM_FAIL.getCode(),
|
||||
jsonObject.getString("detail"));
|
||||
}
|
||||
|
||||
// 转换 result
|
||||
return new SendResult()
|
||||
.setIsSuccess(SUCCESS_CODE == jsonObject.getInteger("code"))
|
||||
.setCode(jsonObject.getInteger("code"))
|
||||
@@ -127,7 +125,6 @@ public class YunPianSmsClient implements SmsClient {
|
||||
Map<String, String> templateParams) {
|
||||
// build 模板
|
||||
template = buildTemplate(sign, template, templateParams);
|
||||
|
||||
// 最大发送数为 1000,我们设置为 500 个, 分段发送
|
||||
int maxSendSize = MAX_BATCH_SIZE;
|
||||
int maxSendSizeCount = mobileList.size() % maxSendSize == 0
|
||||
@@ -142,9 +139,7 @@ public class YunPianSmsClient implements SmsClient {
|
||||
sendMobileStr.append(",");
|
||||
sendMobileStr.append(mobileList.get(k));
|
||||
}
|
||||
|
||||
String dividedMobile = sendMobileStr.toString().substring(1);
|
||||
|
||||
// 发送手机号
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("apikey", apiKey);
|
||||
@@ -159,12 +154,10 @@ public class YunPianSmsClient implements SmsClient {
|
||||
throw new ServiceException(SystemErrorCodeEnum.SMS_PLATFORM_FAIL.getCode(),
|
||||
jsonObject.getString("detail"));
|
||||
}
|
||||
|
||||
// 用于递增 maxSendSize
|
||||
j = j2;
|
||||
j2 = j + maxSendSize;
|
||||
}
|
||||
|
||||
return new SendResult()
|
||||
.setIsSuccess(true)
|
||||
.setCode(SUCCESS_CODE)
|
||||
@@ -181,18 +174,17 @@ public class YunPianSmsClient implements SmsClient {
|
||||
*/
|
||||
private static String buildTemplate(String sign, String template,
|
||||
Map<String, String> templateParams) {
|
||||
|
||||
// 不处理 empty 数据
|
||||
if (CollectionUtils.isEmpty(templateParams)) {
|
||||
return template;
|
||||
}
|
||||
|
||||
// 处理template参数
|
||||
for (Map.Entry<String, String> entry : templateParams.entrySet()) {
|
||||
String paramsKey = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
String paramPlace = String.format(PARAM_TEMPLATE, paramsKey);
|
||||
template = template.replaceAll(paramPlace, value);
|
||||
}
|
||||
|
||||
template = String.format(SIGN_TEMPLATE, sign, template);
|
||||
return template;
|
||||
}
|
||||
@@ -234,7 +226,6 @@ public class YunPianSmsClient implements SmsClient {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.debug("云片短信平台 res: {}", responseText);
|
||||
return responseText;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SystemLogServiceImpl implements SystemLogService {
|
||||
@SuppressWarnings("Duplicates")
|
||||
public PageResult<AccessLogBO> getAccessLogPage(AccessLogPageDTO accessLogPageDTO) {
|
||||
PageResult<AccessLogBO> accessLogPageBOPageResult = SystemLogConvert.INSTANCE.convertPage(
|
||||
accessLogMapper.selectPage(accessLogPageDTO));
|
||||
accessLogMapper.selectPage(accessLogPageDTO)); // TODO FROM 芋艿 to 2447007062:可以考虑直接 return,简洁 + IDEA 不告警;
|
||||
return accessLogPageBOPageResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ public class SystemLogController {
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
|
||||
|
||||
// TODO FROM 芋艿 to 2447007062:不要留这么大的空行;
|
||||
// TODO FROM 芋艿 to 2447007062:使用 Request 接收参数噢;
|
||||
AccessLogPageDTO accessLogPageDTO = new AccessLogPageDTO().setAccountId(accountId)
|
||||
.setPageNo(pageNo).setPageSize(pageSize);
|
||||
// 查询分页
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface AccessLogConvert {
|
||||
AccessLogConvert INSTANCE = Mappers.getMapper(AccessLogConvert.class);
|
||||
|
||||
|
||||
@Mappings({})
|
||||
@Mappings({}) // TODO FROM 芋艿 to 2447007062:注意空行哟;另外,如果不需要专门 mapping,可以不添加该注解,嘿嘿。
|
||||
PageResult<AccessLogPageResponse> convert(PageResult<AccessLogBO> result);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user