添加h5表单信息,添加防止重复提交代码
parent
dd6df84346
commit
2cb96e3f5a
@ -0,0 +1,17 @@
|
||||
package me.zhengjie.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @功能描述 防止重复提交标记注解
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NoRepeatSubmit {
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package me.zhengjie.aspect;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.annotation.NoRepeatSubmit;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @desc aop解析注解
|
||||
* @date 2018-08-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class NoRepeatSubmitAspect {
|
||||
|
||||
private final RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
public NoRepeatSubmitAspect(RedisTemplate<Object, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@Around("@annotation(nrs)")
|
||||
public Object around(ProceedingJoinPoint pjp, NoRepeatSubmit nrs) {
|
||||
ValueOperations<Object, Object> opsForValue = redisTemplate.opsForValue();
|
||||
try {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
String sessionId = RequestContextHolder.getRequestAttributes().getSessionId();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
String key = sessionId + "-" + request.getServletPath();
|
||||
// 如果缓存中有这个url视为重复提交
|
||||
if (opsForValue.get(key) == null) {
|
||||
Object o = pjp.proceed();
|
||||
opsForValue.set(key, 0, 2, TimeUnit.SECONDS);
|
||||
return o;
|
||||
} else {
|
||||
log.error("重复提交");
|
||||
throw new BadRequestException("重复提交!");
|
||||
}
|
||||
} catch (BadRequestException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
} catch (Throwable e) {
|
||||
log.error("验证重复提交时出现未知异常!");
|
||||
throw new BadRequestException("验证重复提交时出现未知异常!");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package me.zhengjie.config;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* @功能描述 内存缓存
|
||||
* @author
|
||||
* @date 2018-08-26
|
||||
*/
|
||||
@Configuration
|
||||
public class UrlCache {
|
||||
@Bean
|
||||
public Cache<String, Integer> getCache() {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(2L, TimeUnit.SECONDS).build();
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package me.zhengjie.modules.dmp.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/1
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "数据解析与图表展示")
|
||||
@RequestMapping("/api/dmp")
|
||||
public class DMPController {
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package me.zhengjie.modules.loan.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.zhengjie.base.BaseEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_loan_user")
|
||||
public class LoanUser extends BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 631332413031546831L;
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@NotNull(groups = {BaseEntity.Update.class})
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "username")
|
||||
@ApiModelProperty(value = "用户名称")
|
||||
private String username;
|
||||
|
||||
@Column(name = "phone")
|
||||
@ApiModelProperty(value = "手机号码")
|
||||
private String phone;
|
||||
|
||||
@Column(name = "address")
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String address;
|
||||
|
||||
@Column(name = "borrowing_type")
|
||||
@ApiModelProperty(value = "借款类别 1:信用卡 2:网贷 3:信用卡+网贷")
|
||||
private Integer borrowingType;
|
||||
|
||||
@Column(name = "quota_type")
|
||||
@ApiModelProperty(value = "额度类型 1:5-10万 2:10-20万 3:20-30万 4:30-50万 5:50万以上")
|
||||
private Integer quotaType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package me.zhengjie.modules.loan.dto;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
@Data
|
||||
public class LoanUserDTO {
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "用户名称")
|
||||
private String username;
|
||||
|
||||
@NotBlank
|
||||
@ApiModelProperty(value = "手机号码")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String address;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "借款类别 1:信用卡 2:网贷 3:信用卡+网贷")
|
||||
private Integer borrowingType;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "额度类型 1:5-10万 2:10-20万 3:20-30万 4:30-50万 5:50万以上")
|
||||
private Integer quotaType;
|
||||
}
|
@ -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.loan.mapstruct;
|
||||
|
||||
import me.zhengjie.base.BaseMapper;
|
||||
import me.zhengjie.modules.loan.domain.LoanUser;
|
||||
import me.zhengjie.modules.loan.dto.LoanUserDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author x
|
||||
* @date 2021-08-05
|
||||
**/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LoanUserMapper extends BaseMapper<LoanUserDTO, LoanUser> {
|
||||
|
||||
}
|
@ -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.loan.repository;
|
||||
|
||||
import me.zhengjie.modules.loan.domain.LoanUser;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @website https://el-admin.vip
|
||||
* @author x
|
||||
* @date 2021-08-05
|
||||
**/
|
||||
public interface LoanUserRepository extends JpaRepository<LoanUser, Long>, JpaSpecificationExecutor<LoanUser> {
|
||||
|
||||
/**
|
||||
* 号码查找提交用户
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
LoanUser findByPhone(String phone);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package me.zhengjie.modules.loan.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.annotation.NoRepeatSubmit;
|
||||
import me.zhengjie.common.http.CommonResponse;
|
||||
import me.zhengjie.common.http.ResponseCode;
|
||||
import me.zhengjie.modules.loan.dto.LoanUserDTO;
|
||||
import me.zhengjie.modules.loan.service.LoanUserService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api("用户额度信息收集")
|
||||
@RequestMapping("/api/loanUser")
|
||||
@RequiredArgsConstructor
|
||||
public class LoanUserController {
|
||||
private final LoanUserService loanUserService;
|
||||
|
||||
|
||||
@NoRepeatSubmit
|
||||
@PostMapping("/submit")
|
||||
@ApiOperation("提交用户信息")
|
||||
public ResponseEntity<Object> submit(@RequestBody @Validated LoanUserDTO loanUserDTO) {
|
||||
|
||||
Boolean flag = loanUserService.userSubmit(loanUserDTO);
|
||||
return flag != null && flag ?
|
||||
new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK)
|
||||
: new ResponseEntity<>(CommonResponse.createByError(ResponseCode.ERROR), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package me.zhengjie.modules.loan.service;
|
||||
|
||||
import me.zhengjie.modules.loan.dto.LoanUserDTO;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
public interface LoanUserService {
|
||||
/**
|
||||
* 用户提交表单信息
|
||||
* @param loanUserDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean userSubmit(LoanUserDTO loanUserDTO);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package me.zhengjie.modules.loan.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.loan.domain.LoanUser;
|
||||
import me.zhengjie.modules.loan.dto.LoanUserDTO;
|
||||
import me.zhengjie.modules.loan.repository.LoanUserRepository;
|
||||
import me.zhengjie.modules.loan.service.LoanUserService;
|
||||
import me.zhengjie.utils.MobileUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/6/6
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LoanUserServiceImpl implements LoanUserService {
|
||||
|
||||
private final LoanUserRepository loanUserRepository;
|
||||
|
||||
@Override
|
||||
public Boolean userSubmit(LoanUserDTO loanUserDTO) {
|
||||
if (ObjectUtil.isNotNull(loanUserDTO)) {
|
||||
if (!MobileUtil.checkPhone(loanUserDTO.getPhone())) {
|
||||
throw new BadRequestException("号码验证失败!");
|
||||
}
|
||||
LoanUser byPhone = loanUserRepository.findByPhone(loanUserDTO.getPhone());
|
||||
if (byPhone != null) {
|
||||
throw new BadRequestException("该号码已提交信息!");
|
||||
}
|
||||
LoanUser loanUser = new LoanUser();
|
||||
BeanUtil.copyProperties(loanUserDTO, loanUser);
|
||||
LoanUser saveLoanUser = loanUserRepository.save(loanUser);
|
||||
return ObjectUtil.isNotNull(saveLoanUser.getId());
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.dto;
|
||||
package me.zhengjie.modules.system.domain.sms.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.rest;
|
||||
package me.zhengjie.modules.system.domain.sms.rest;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.util;
|
||||
package me.zhengjie.modules.system.domain.sms.util;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.vo;
|
||||
package me.zhengjie.modules.system.domain.sms.vo;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.vo;
|
||||
package me.zhengjie.modules.system.domain.sms.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.vo;
|
||||
package me.zhengjie.modules.system.domain.sms.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package me.zhengjie.modules.sms.vo;
|
||||
package me.zhengjie.modules.system.domain.sms.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
Loading…
Reference in New Issue