|
|
@@ -1,22 +1,23 @@
|
|
|
package org.dromara.server.consume.controller.v1;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.constant.CacheNames;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.domain.model.ErrorInfo;
|
|
|
import org.dromara.common.core.domain.model.ErrorResult;
|
|
|
import org.dromara.common.core.enums.CreditTypeEnum;
|
|
|
import org.dromara.common.core.enums.SystemUseTypeEnum;
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
|
import org.dromara.server.consume.business.ConsumeBusiness;
|
|
|
import org.dromara.server.consume.convert.strategy.RecordConvertStrategyContent;
|
|
|
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;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -39,27 +40,87 @@ public class ConsumeController {
|
|
|
private final RecordConvertStrategyContent recordConvertStrategy;
|
|
|
private final ConsumeBusiness consumeBusiness;
|
|
|
|
|
|
+ /**
|
|
|
+ * 请求消费(校园码)
|
|
|
+ * @param record 消费信息
|
|
|
+ * @param mac 校验码
|
|
|
+ * @param qrcode 校园码
|
|
|
+ * @param xfPwd 消费密码
|
|
|
+ * @return 请求消费结果
|
|
|
+ */
|
|
|
+ @PostMapping("/ConsumeOriginal/virtualCard")
|
|
|
+ public Object consumeOriginalVirtualCard(@RequestBody Object record, @RequestParam(name = "mac", required = false) String mac,
|
|
|
+ @RequestParam(name = "qrcode") String qrcode,
|
|
|
+ @RequestParam(name = "xfPwd", required = false) String xfPwd) {
|
|
|
+ JSONObject yc = JSONUtil.parseObj(record);
|
|
|
+ long userNo = ObjectUtil.isEmpty(yc.get("employeeID")) ? 0L : Long.parseLong(yc.get("employeeID").toString());
|
|
|
+ Object redisQrCode = RedisUtils.getCacheMapValue(CacheNames.SCHOOL_CODE,Long.toString(userNo));
|
|
|
+ if(ObjectUtil.equals(qrcode,redisQrCode)){
|
|
|
+ ErrorResult result = ErrorResult.instance(HttpStatus.FORBIDDEN, "处理失败", 1, "PARAM_ERROR", "二维码失效",
|
|
|
+ "请勿重复使用相同的二维码消费。");
|
|
|
+ return new ResponseEntity<Object>(result, null, HttpStatus.FORBIDDEN);
|
|
|
+ }
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.SCHOOL_CODE, Long.toString(userNo), qrcode);
|
|
|
+
|
|
|
+ return doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求消费(实体卡)
|
|
|
+ * @param record 消费信息
|
|
|
+ * @param mac 校验码
|
|
|
+ * @param xfPwd 消费密码
|
|
|
+ * @return 请求消费结果
|
|
|
+ */
|
|
|
@PostMapping("/ConsumeOriginal")
|
|
|
- public Object consumeOriginal(@RequestBody Object record) {
|
|
|
- return doRecordData(record, "requestConsume");
|
|
|
+ public Object consumeOriginal(@RequestBody Object record, @RequestParam(name = "mac", required = false) String mac,
|
|
|
+ @RequestParam(name = "xfPwd", required = false) String xfPwd) {
|
|
|
+ return doRecordData(record, "requestConsume", mac, xfPwd);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 上传消费记录
|
|
|
+ * @param record 消费信息
|
|
|
+ * @param mac 校验码
|
|
|
+ * @return 上传消费记录结果
|
|
|
+ */
|
|
|
@PostMapping("/Consume")
|
|
|
- public Object uploadRecord(@RequestBody Object record) {
|
|
|
- return doRecordData(record, "uploadRecord");
|
|
|
+ public Object uploadRecord(@RequestBody Object record, @RequestParam(name = "mac", required = false) String mac) {
|
|
|
+ return doRecordData(record, "uploadRecord", mac, "");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 请求消费 + 消费记录上传
|
|
|
+ * @param record 消费信息
|
|
|
+ * @param mac 校验码
|
|
|
+ * @param xfPwd 消费密码
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
@PostMapping("/Consume/all")
|
|
|
- public Object consumeAll(@RequestBody Object record) {
|
|
|
- return doRecordData(record, "fullRecord");
|
|
|
+ public Object consumeAll(@RequestBody Object record, @RequestParam(name = "mac", required = false) String mac,
|
|
|
+ @RequestParam(name = "xfPwd", required = false) String xfPwd) {
|
|
|
+ return doRecordData(record, "fullRecord", "", "");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * kafka 推送消费信息处理
|
|
|
+ * @param bo 消费业务对象
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
@PostMapping("/Consume/kafka")
|
|
|
public R<ErrorInfo> consumeKafka(@RequestBody ConsumptionBo bo) {
|
|
|
return consumeBusiness.fullOrder(bo);
|
|
|
}
|
|
|
|
|
|
- private Object doRecordData(Object record, String type) {
|
|
|
+ /**
|
|
|
+ * 消费业务初步处理
|
|
|
+ * @param record 消费信息
|
|
|
+ * @param type 接口类型
|
|
|
+ * @param mac 校验码
|
|
|
+ * @param xfPwd 消费密码
|
|
|
+ * @return 处理结果
|
|
|
+ */
|
|
|
+ private Object doRecordData(Object record, String type, String mac, String xfPwd) {
|
|
|
if (ObjectUtil.length(record) == 0) {
|
|
|
ErrorResult result = ErrorResult.instance(HttpStatus.FORBIDDEN, "处理失败", 1, "PARAM_ERROR", "参数错误",
|
|
|
"json字符串无法还原为对象,可能原因是格式不正确。");
|
|
|
@@ -78,7 +139,7 @@ public class ConsumeController {
|
|
|
} else {
|
|
|
errorInfo = consumeBusiness.fullOrder(bo);
|
|
|
}
|
|
|
- if (!R.isSuccess(errorInfo)) {
|
|
|
+ if (R.isError(errorInfo)) {
|
|
|
ErrorResult result = new ErrorResult();
|
|
|
result.setStatusCode(HttpStatus.NOT_FOUND.value());
|
|
|
result.setMessage(errorInfo.getMsg());
|