软件适配器 数据源适配器

单号生成高并发优化
yun-zuoyi
汪云昊 6 years ago
parent 24ff03d659
commit c4011ae4df

@ -0,0 +1,23 @@
package cn.estsh.i3plus.core.api.iservice.base;
import cn.estsh.i3plus.pojo.platform.bean.SysOrderNoRule;
import io.swagger.annotations.ApiOperation;
/**
* @Description :
* @Reference :
* @Author : yunhao
* @CreateDate : 2019-09-03 13:59
* @Modify:
**/
public interface ISynchronizedService {
/**
*
* @param code
* @return
*/
@ApiOperation(value = "根据code查询最新单号规则")
SysOrderNoRule nextOrderNo(String code);
}

@ -1,5 +1,6 @@
package cn.estsh.i3plus.core.apiservice.controller.base;
import cn.estsh.i3plus.core.api.iservice.base.ISynchronizedService;
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
import cn.estsh.i3plus.core.api.iservice.busi.*;
@ -18,7 +19,6 @@ import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.fastdfs.FastDFSClient;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
@ -74,7 +74,7 @@ public class WhiteController extends CoreBaseController {
private ISysDictionaryService dictionaryService;
@Autowired
private ISysOrderNoRuleService sysOrderNoRuleService;
private ISynchronizedService synchronizedService;
@Autowired
private ISysOrganizeService sysOrganizeService;
@ -306,7 +306,7 @@ public class WhiteController extends CoreBaseController {
try {
ValidatorBean.checkNotNull(code, "code不能为空");
SysOrderNoRule sysOrderNoRule = sysOrderNoRuleService.doGetSysOrderNoRuleCode(code);
SysOrderNoRule sysOrderNoRule = synchronizedService.nextOrderNo(code);
return ResultBean.success("操作成功").setResultObject(sysOrderNoRule).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);

@ -1,5 +1,6 @@
package cn.estsh.i3plus.core.apiservice.controller.busi;
import cn.estsh.i3plus.core.api.iservice.base.ISynchronizedService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysConfigService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysMessageService;
@ -53,6 +54,9 @@ public class SysOrderNoRuleController extends CoreBaseController {
private ISysOrderNoRuleService sysOrderNoRuleService;
@Autowired
private ISynchronizedService synchronizedService;
@Autowired
private ISysConfigService sysConfigService;
@Autowired
@ -382,11 +386,11 @@ public class SysOrderNoRuleController extends CoreBaseController {
*/
@GetMapping(value = "/get-order-no/{code}")
@ApiOperation(value = "根据单号规则代码,生成单号")
public synchronized ResultBean<SysOrderNoRule> getOrderNo(@PathVariable("code") String code) {
public ResultBean<SysOrderNoRule> getOrderNo(@PathVariable("code") String code) {
try {
ValidatorBean.checkNotNull(code, "code不能为空");
SysOrderNoRule sysOrderNoRule = sysOrderNoRuleService.doGetSysOrderNoRuleCode(code);
SysOrderNoRule sysOrderNoRule = synchronizedService.nextOrderNo(code);
return ResultBean.success("操作成功").setResultObject(sysOrderNoRule).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
@ -403,14 +407,14 @@ public class SysOrderNoRuleController extends CoreBaseController {
*/
@GetMapping(value = "/get-order-no/{code}/{num}")
@ApiOperation(value = "根据单号规则代码,生成单号")
public synchronized ResultBean<String> getOrderNo(@PathVariable("code") String code,@PathVariable("num") Integer num) {
public ResultBean<String> getOrderNo(@PathVariable("code") String code,@PathVariable("num") Integer num) {
try {
ValidatorBean.checkNotNull(code, "code不能为空");
ValidatorBean.checkNotZero(num,"次数不能为零");
List<String> orderNoList = new ArrayList<>();
for (int i = 0; i < num; i++) {
orderNoList.add(sysOrderNoRuleService.doGetSysOrderNoRuleCode(code).getOrderNo());
orderNoList.add(synchronizedService.nextOrderNo(code).getOrderNo());
}
return ResultBean.success("操作成功").setResultList(orderNoList).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {

@ -0,0 +1,26 @@
package cn.estsh.i3plus.core.apiservice.serviceimpl.base;
import cn.estsh.i3plus.core.api.iservice.base.ISynchronizedService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysOrderNoRuleService;
import cn.estsh.i3plus.pojo.platform.bean.SysOrderNoRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Description :
* @Reference :
* @Author : yunhao
* @CreateDate : 2019-09-03 14:00
* @Modify:
**/
@Service
public class SynchronizedService implements ISynchronizedService {
@Autowired
private ISysOrderNoRuleService sysOrderNoRuleService;
@Override
public synchronized SysOrderNoRule nextOrderNo(String code) {
return sysOrderNoRuleService.doGetSysOrderNoRuleCode(code);
}
}
Loading…
Cancel
Save