1、防止前端重复提交:
@ApiOperation(value = "会员开卡", httpMethod = "POST", notes = "会员开卡") @PostMapping(value = "/createCard") public ResultBean createCard(@RequestBody MemberVo vo){ ResultBean resultBean = new ResultBean(); //防止重复提交 String key = "miniprogram_create_card_"+vo.getPhone(); if (redisService.exists(key)) { resultBean.setMsg("5秒内请勿重复提交"); resultBean.setCode(ResultBean.FAIL); return resultBean; } redisService.set(key,"",6); return iMemberCenterService.createCardEnter(vo); }
2、注册时生成id:
//会员开卡获取会员卡号 public String getCardId(String dpId) { String parentId = BusinessUtil.getParentId(dpId); if (!redisService.exists(parentId + "_cardId")) { String sql = "select max(card_id) as card_id from " + parentId + "_account limit 1 "; Record record = Db.findFirst(sql); if (record != null && record.get("card_id") != null) { String newStr = record.getStr("card_id").replaceAll("^(0+)", ""); redisService.set(dpId + "_cardId", newStr, 0); } } String cardId = redisService.incr(dpId + "_cardId").toString(); int length = cardId.length(); for (int i = 0; i < 11 - length; i++) { cardId = "0" + cardId; } return cardId; }