Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java =================================================================== diff -u -r40905 -r40906 --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java (.../VerificationCodeManagerImpl.java) (revision 40905) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/verification/VerificationCodeManagerImpl.java (.../VerificationCodeManagerImpl.java) (revision 40906) @@ -239,15 +239,22 @@ } //限制每天每个用户最多发送的短信数量 String dateAreaSql = dateQueryAdapter.dateAreaSql("createDateTime", DateTools.getFormatDateStr(DateTools.startOfDate(nowDateTime), DateTools.COMMON_DATE_HMS), DateTools.getFormatDateStr(nowDateTime, DateTools.COMMON_DATE_HMS)); - String countSql = String.format("select count(1) from %s where userName = '%s' and %s", SmsVerificationCode.class.getSimpleName(), loginName, dateAreaSql); - if(objectDao.countBySql(countSql) >= SmsVerificationCode.MAX_SMS_AMOUNT_PER_DAY){ + String userSmsCountSql = String.format("select count(1) from %s where userName = '%s' and %s", SmsVerificationCode.class.getSimpleName(), loginName, dateAreaSql); + if(objectDao.countBySql(userSmsCountSql) >= SmsVerificationCode.MAX_SMS_AMOUNT_USER_DAY){ + logger.info(String.format("用户【%s】%s发送短信达到上限%s条!", loginName, DateTools.getCurrentDayByFormat(DateTools.COMMON_DATE_ONLY), SmsVerificationCode.MAX_SMS_AMOUNT_USER_DAY)); throw new SystemException("验证码获取达到上限,请联系管理员处理。"); } - //生成随机验证码 - Integer num = (int)((Math.random()*9+1)*1000); + //限制系统每天发送的短信数量 + String totalSmsCountSql = String.format("select count(1) from %s where %s", SmsVerificationCode.class.getSimpleName(), dateAreaSql); + if(objectDao.countBySql(totalSmsCountSql) >= SmsVerificationCode.MAX_SMS_AMOUNT_PER_DAY){ + logger.info(String.format("系统%s发送短信达到上限%s条!", loginName, DateTools.getCurrentDayByFormat(DateTools.COMMON_DATE_ONLY), SmsVerificationCode.MAX_SMS_AMOUNT_PER_DAY)); + throw new SystemException("验证码获取达到上限,请联系管理员处理。"); + } + //生成随机验证码6位 + Integer num = (int)((Math.random()*9+1)*100000); String verificationCode = num.toString(); //verificationCode="0000"; - String messageContent = generateMessageContent(verificationCode); + String messageContent = "【丁香软件】验证码:" + verificationCode + ",用于安全验证。验证码请勿泄露给他人,谨防账号被盗。"; //调用第三方接口,发送验证码短信 verificationCodeDao.sendVerificationCodeSms(smsMumber, messageContent); //保存短信验证码 Index: forgon-core/src/main/java/com/forgon/security/model/SmsVerificationCode.java =================================================================== diff -u -r40894 -r40906 --- forgon-core/src/main/java/com/forgon/security/model/SmsVerificationCode.java (.../SmsVerificationCode.java) (revision 40894) +++ forgon-core/src/main/java/com/forgon/security/model/SmsVerificationCode.java (.../SmsVerificationCode.java) (revision 40906) @@ -7,6 +7,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.Table; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; @@ -20,6 +22,9 @@ @Entity @DynamicInsert(false) @DynamicUpdate(true) +@Table(indexes={@Index(columnList="userName",name="sms_username_index"), + @Index(columnList="createDateTime",name="sms_createtime_index"), + @Index(columnList="smsNumber",name="sms_smsnumber_index")}) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class SmsVerificationCode { @@ -71,9 +76,13 @@ */ public static final Integer MAX_VERIFY_FAIL_TIMES = 5; /** - * 每天最多发送的短信数量 + * 系统每天发送的短信数量上限2000 */ - public static final Integer MAX_SMS_AMOUNT_PER_DAY = 20; + public static final Integer MAX_SMS_AMOUNT_PER_DAY = 2000; + /** + * 每人每天发送的短信数量上限20 + */ + public static final Integer MAX_SMS_AMOUNT_USER_DAY = 20; @Id @GeneratedValue(strategy = GenerationType.AUTO)