|
@@ -18,22 +18,30 @@ import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
|
|
import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
|
|
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
|
|
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
|
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
+import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 结算表
|
|
* 结算表
|
|
@@ -41,6 +49,7 @@ import java.util.Map;
|
|
* @author Liujh
|
|
* @author Liujh
|
|
* @date 2020-12-1
|
|
* @date 2020-12-1
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@RestController
|
|
@RestController
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
@RequestMapping("/settle" )
|
|
@RequestMapping("/settle" )
|
|
@@ -49,6 +58,7 @@ public class WmPayOffController {
|
|
|
|
|
|
private final WmPayOffService wmPayOffService;
|
|
private final WmPayOffService wmPayOffService;
|
|
private final WmScorePackageService wmScorePackageService;
|
|
private final WmScorePackageService wmScorePackageService;
|
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "结算回退", notes = "提交结算")
|
|
@ApiOperation(value = "结算回退", notes = "提交结算")
|
|
@@ -61,19 +71,59 @@ public class WmPayOffController {
|
|
return wmPayOffService.settleBack(input);
|
|
return wmPayOffService.settleBack(input);
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "提交结算", notes = "提交结算")
|
|
|
|
- @SysLog("提交结算" )
|
|
|
|
- @PostMapping("/settleSubmit")
|
|
|
|
- public R settleSubmit(@RequestBody WmScorePackageSettleInput input) {
|
|
|
|
- if(CollectionUtils.isEmpty(input.getNotes())){
|
|
|
|
- return R.failed("数据异常");
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if(StringUtils.isEmpty(input.getId())){
|
|
|
|
- return R.failed("数据异常");
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取批量结算token,三分钟有效
|
|
|
|
+ * token格式:[租户i]d:order_batch:[用户id]:token:
|
|
|
|
+ *
|
|
|
|
+ * @return 结算token
|
|
|
|
+ */
|
|
|
|
+ @GetMapping(value = "/token")
|
|
|
|
+ public String getOrderBatchToken() {
|
|
|
|
+
|
|
|
|
+ String randomStr;
|
|
|
|
+
|
|
|
|
+ // 获取操作员
|
|
|
|
+ HnqzUser finaAdmin = SecurityUtils.getUser();
|
|
|
|
+ final String token = String.format("%d:order_batch:%d:token", finaAdmin.getTenantId(), finaAdmin.getId());
|
|
|
|
+
|
|
|
|
+ // 返回缓存生成好的
|
|
|
|
+ if (Boolean.TRUE.equals(redisTemplate.hasKey(token))){
|
|
|
|
+ return (String) redisTemplate.opsForValue().get(token);
|
|
}
|
|
}
|
|
- if(null == input.getInvoiceCategory()){
|
|
|
|
- return R.failed("数据异常");
|
|
|
|
|
|
+
|
|
|
|
+ // 生成缓存key,将token缓存到redis
|
|
|
|
+ do {
|
|
|
|
+ randomStr = RandomStringUtils.randomNumeric(6);
|
|
|
|
+ } while (Boolean.FALSE.equals(redisTemplate.opsForValue().setIfAbsent(token, randomStr, 3, TimeUnit.MINUTES)));
|
|
|
|
+
|
|
|
|
+ return randomStr;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 业务提交结算信息到财务
|
|
|
|
+ *
|
|
|
|
+ * @param input 输入信息
|
|
|
|
+ * @return 提交结果
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "提交结算", notes = "提交结算")
|
|
|
|
+ @SysLog("提交结算")
|
|
|
|
+ @PostMapping("/settleSubmit")
|
|
|
|
+ public R settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
|
|
|
|
+
|
|
|
|
+ //1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
|
|
|
|
+ HnqzUser finaAdmin = SecurityUtils.getUser();
|
|
|
|
+ final String REDIS_DEL_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
|
|
|
|
+ Long execute = redisTemplate.execute(new DefaultRedisScript<>(REDIS_DEL_SCRIPT, Long.class),
|
|
|
|
+ Collections.singletonList(String.format("%d:order_batch:%d:token", finaAdmin.getTenantId(), finaAdmin.getId())), input.getToken());
|
|
|
|
+ // 通过EVAL脚本原子验证令牌和删除令牌
|
|
|
|
+ boolean oops = (execute != null && execute == 0);
|
|
|
|
+
|
|
|
|
+ // 令牌验证失败
|
|
|
|
+ if (oops) {
|
|
|
|
+ log.error(String.format("提交 TOKEN 不正确:%s", input.getToken()));
|
|
|
|
+ R.failed("提交 TOKEN 不正确,请刷新页面重试");
|
|
}
|
|
}
|
|
|
|
|
|
return wmPayOffService.settleSubmit(input);
|
|
return wmPayOffService.settleSubmit(input);
|