记得上下班打卡 | git大法好,push需谨慎

Commit 48db67a9 authored by jiangxiulong's avatar jiangxiulong

Merge remote-tracking branch 'origin/master' into jxl_118_reservation

parents 960fd4ec 34ea3819
......@@ -54,6 +54,10 @@ public class AdamRedisConst {
public static final String INCR_MEMBER_NO = PREFIX.concat("incr:member_no");
public static final String INCR_MEMBER_LIMITATION = PREFIX.concat("incr:member_limitation");
/**
* 用户添加/编辑入场人计数(N次/天)
*/
public static final String INCR_USER_ENTERS = PREFIX.concat("incr:limit_u_e:");
// public static final String SWITCH_BUY_MEMBER = PREFIX.concat("switch:buy:member");
......
......@@ -14,7 +14,7 @@ import java.util.List;
* @since 2021-04-28
*/
public interface IAdamEntersService {
String add(AdamEntersParam parameter);
String add(AdamEntersParam parameter, String uid, List<AdamEntersVo> vos);
void def(String uid, String entersId);
......
......@@ -2,18 +2,14 @@ package com.liquidnet.common.exception.entity;
import lombok.Data;
import java.util.List;
import java.io.Serializable;
/**
* Created by shangshengfang on 2017/2/16.
*/
@Data
public class Error {
public class Error implements Serializable, Cloneable {
String message;
String code;
Object data;
public Error() {
}
......@@ -21,4 +17,30 @@ public class Error {
this.code = code;
this.message = message;
}
public Error setMessage(String message) {
this.message = message;
return this;
}
public Error setCode(String code) {
this.code = code;
return this;
}
public Error setData(Object data) {
this.data = data;
return this;
}
private static final Error obj = new Error();
public static Error getNew() {
try {
return (Error) obj.clone();
} catch (CloneNotSupportedException e) {
return new Error();
}
}
}
......@@ -11,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
......@@ -42,10 +43,13 @@ public class RestControllerAdviceHandler {
logger.error("Ex.Handler.RestController:uri:{},param:{},ex:{},msg:{},",
req.getRequestURI(), JSON.toJSONString(req.getParameterMap()), rex.getClass().getSimpleName(), rex.getLocalizedMessage());
if (rex instanceof HttpMessageNotReadableException) {
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(ErrorCode.HTTP_PARAM_ERROR.getMessage()), HttpStatus.OK);
}
if (rex instanceof MissingServletRequestParameterException) {
MissingServletRequestParameterException ygex = (MissingServletRequestParameterException) rex;
String message = ygex.getMessage();
return new ResponseEntity<Error>(new Error(ErrorCode.HTTP_PARAM_ERROR.getCode(), message), HttpStatus.OK);
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(message), HttpStatus.OK);
}
if (rex instanceof ConstraintViolationException) {
ConstraintViolationException ygex = (ConstraintViolationException) rex;
......@@ -53,27 +57,27 @@ public class RestControllerAdviceHandler {
String violationNode = violation.getPropertyPath().toString();
// String message = violationNode.substring(violationNode.indexOf(".") + 1) + violation.getMessage();
String message = violation.getMessage();
return new ResponseEntity<Error>(new Error(ErrorCode.HTTP_PARAM_ERROR.getCode(), message), HttpStatus.OK);
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(message), HttpStatus.OK);
}
if (rex instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ygex = (MethodArgumentNotValidException) rex;
FieldError fieldError = ygex.getBindingResult().getFieldErrors().get(0);
// String message = fieldError.getField() + " " + fieldError.getDefaultMessage();
String message = fieldError.getDefaultMessage();
return new ResponseEntity<Error>(new Error(ErrorCode.HTTP_PARAM_ERROR.getCode(), message), HttpStatus.OK);
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(message), HttpStatus.OK);
}
if (rex instanceof LiquidnetFeignException) {
LiquidnetFeignException ygex = (LiquidnetFeignException) rex;
String errorCode = ygex.errorCode().getCode();
String message = ygex.getMessage();
message = message == null ? ygex.errorCode().getMessage() : message;
return new ResponseEntity<Error>(new Error(errorCode, message), HttpStatus.OK);
return new ResponseEntity<>(Error.getNew().setCode(errorCode).setMessage(message), HttpStatus.OK);
}
if (rex instanceof LiquidnetServiceException) {
LiquidnetServiceException ygex = (LiquidnetServiceException) rex;
String errorCode = ygex.getCode();
String message = ygex.getMessage();
return new ResponseEntity<Error>(new Error(errorCode, message), HttpStatus.OK);
return new ResponseEntity<>(Error.getNew().setCode(errorCode).setMessage(message), HttpStatus.OK);
} else {
logger.error("Unprocessed exception", rex);
// return new ResponseEntity<Error>(new Error(ErrorCode.HTTP_SYSTEM_ERROR.getCode(), ErrorCode.HTTP_SYSTEM_ERROR.getMessage()), HttpStatus.OK);
......
......@@ -25,6 +25,8 @@ liquidnet:
app-login:
mobile: 13724286255
user-info: false
limit:
enters: 10
enters_opr: 20
#以下为spring各环境个性配置
......@@ -25,5 +25,8 @@ liquidnet:
app-login:
mobile: 13724286255
user-info: false
limit:
enters: 10
enters_opr: 20
#以下为spring各环境个性配置
......@@ -17,6 +17,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -47,6 +48,12 @@ public class AdamEntersController {
@Autowired
IAdamEntersService adamEntersService;
@Value("${liquidnet.reviewer.limit.enters:10}")
private int reviewLimitEnters;
// @Value("${liquidnet.reviewer.limit.enters_opr:10}")
// private int reviewLimitEntersOpr;
@ApiOperationSupport(order = 1)
@ApiOperation(value = "添加入场人")
@PostMapping("add")
......@@ -84,8 +91,9 @@ public class AdamEntersController {
}
break;
}
String currentUid = CurrentUtil.getCurrentUid();
List<AdamEntersVo> vos = adamRdmService.getEntersVoByUid(CurrentUtil.getCurrentUid());
List<AdamEntersVo> vos = adamRdmService.getEntersVoByUid(currentUid);
if (!CollectionUtils.isEmpty(vos)) {
Optional<AdamEntersVo> any = vos.stream().filter(r -> (r.getIdCard().equals(parameter.getIdCard())) && r.getType().equals(parameter.getType())).findAny();
......@@ -93,12 +101,23 @@ public class AdamEntersController {
return ResponseDto.failure(ErrorMapping.get("10019"));
}
if (vos.size() >= 10) {
if (reviewLimitEnters > 0 && vos.size() >= reviewLimitEnters) {
return ResponseDto.failure(ErrorMapping.get("10025"));
}
}
String entersId = adamEntersService.add(parameter);
// int userEntersOprNo = adamRdmService.getUserEntersOprNo(currentUid);
// if (reviewLimitEntersOpr > 0 && userEntersOprNo >= reviewLimitEntersOpr) {
// return ResponseDto.failure(ErrorMapping.get("10026"));
// }
String entersId = adamEntersService.add(parameter, currentUid, vos);
// if (userEntersOprNo == -1) {
// adamRdmService.setUserEntersOprNo(currentUid);
// } else {
// adamRdmService.incrUserEntersOprNo(currentUid);
// }
return ResponseDto.success(entersId);
}
......@@ -147,12 +166,23 @@ public class AdamEntersController {
if (StringUtils.isBlank(parameter.getEntersId())) {
return ResponseDto.failure(ErrorMapping.get("10015"));
}
if (null == adamRdmService.getEntersVoByUidEntersId(CurrentUtil.getCurrentUid(), parameter.getEntersId())) {
String currentUid = CurrentUtil.getCurrentUid();
if (null == adamRdmService.getEntersVoByUidEntersId(currentUid, parameter.getEntersId())) {
return ResponseDto.failure(ErrorMapping.get("10105"));
}
adamEntersService.edit(parameter);
//// int userEntersOprNo = adamRdmService.getUserEntersOprNo(currentUid);
//// if (reviewLimitEntersOpr > 0 && userEntersOprNo >= reviewLimitEntersOpr) {
//// return ResponseDto.failure(ErrorMapping.get("10026"));
//// }
////
// adamEntersService.edit(parameter);
////
//// if (userEntersOprNo == -1) {
//// adamRdmService.setUserEntersOprNo(currentUid);
//// } else {
//// adamRdmService.incrUserEntersOprNo(currentUid);
//// }
return ResponseDto.success();
}
......
......@@ -915,6 +915,23 @@ public class AdamRdmService {
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | */
public boolean setUserEntersOprNo(String uid) {
LocalDateTime now = LocalDateTime.now();
return redisUtil.set(AdamRedisConst.INCR_USER_ENTERS.concat(uid), 1,
ChronoUnit.SECONDS.between(now, LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 23, 59, 59)));
}
public long incrUserEntersOprNo(String uid) {
return redisUtil.incr(AdamRedisConst.INCR_USER_ENTERS.concat(uid), 1);
}
public int getUserEntersOprNo(String uid) {
Object o = redisUtil.get(AdamRedisConst.INCR_USER_ENTERS.concat(uid));
return null == o ? -1 : (int) o;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | */
/* ========================================================== | Other micro-service data inquiry */
......
......@@ -43,8 +43,8 @@ public class AdamEntersServiceImpl implements IAdamEntersService {
@Override
// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public String add(AdamEntersParam parameter) {
String currentUid = CurrentUtil.getCurrentUid();
public String add(AdamEntersParam parameter, String currentUid, List<AdamEntersVo> vos) {
// String currentUid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
......@@ -58,7 +58,7 @@ public class AdamEntersServiceImpl implements IAdamEntersService {
}
List<AdamEntersVo> vos = adamRdmService.getEntersVoByUid(currentUid);
// List<AdamEntersVo> vos = adamRdmService.getEntersVoByUid(currentUid);
AdamEntersVo vo = AdamEntersVo.getNew();
BeanUtils.copyProperties(parameter, vo);
......@@ -74,15 +74,9 @@ public class AdamEntersServiceImpl implements IAdamEntersService {
log.debug("#RDS耗时:{}ms", System.currentTimeMillis() - s);
s = System.currentTimeMillis();
String msg = SqlMapping.get("adam_enters.add",
vo.getEntersId(), currentUid, vo.getType(), vo.getName(), vo.getMobile(), vo.getIdCard(), vo.getIsDefault(), vo.getState(), now
);
log.debug("#SQL.GET耗时:{}ms", System.currentTimeMillis() - s);
s = System.currentTimeMillis();
queueUtils.sendMsgByRedis(
MQConst.AdamQueue.SQL_UCENTER.getKey(),
msg
queueUtils.sendMsgByRedis(MQConst.AdamQueue.SQL_UCENTER.getKey(),
SqlMapping.get("adam_enters.add",
vo.getEntersId(), currentUid, vo.getType(), vo.getName(), vo.getMobile(), vo.getIdCard(), vo.getIsDefault(), vo.getState(), now)
);
log.debug("#MQ耗时:{}ms", System.currentTimeMillis() - s);
return vo.getEntersId();
......
......@@ -29,6 +29,7 @@
10023=背景图不合规
10024=该账号已被主动注销
10025=入场人已达上限
10026=入场人今日操作已达上限
10101=姓名或身份证件号无效
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment