Merge remote-tracking branch 'upstream/test' into test

yun-zuoyi
castle.zang 4 years ago
commit b85a9fd55a

@ -110,11 +110,10 @@ public interface ISysDepartmentService extends ICrudService<SysDepartment> {
SysDepartment findSysDepartmentByDepartCodeAndOrganizedId(String departmentCode,Long organizeId); SysDepartment findSysDepartmentByDepartCodeAndOrganizedId(String departmentCode,Long organizeId);
/** /**
* sysDepartment *
* @param sysDepartment
* @return * @return
*/ */
@ApiOperation(value = "根据sysDepartment查询所有符合条件的部门信息") @ApiOperation(value = "查询默认条件的部门信息")
List<SysDepartment> findAllByBaseBean(SysDepartment sysDepartment); List<SysDepartment> findAllByBaseBean();
} }

@ -105,12 +105,11 @@ public interface ISysPositionService extends ICrudService<SysPosition> {
SysPosition findPositionByPositionCodeAndOrganizeId(String positionCode,String organizeCode); SysPosition findPositionByPositionCodeAndOrganizeId(String positionCode,String organizeCode);
/** /**
* *
* @param sysPosition bean
* @return * @return
*/ */
@ApiOperation(value = "查询符合条件的岗位信息", notes = "根据SysPosition查询所有符合条件的岗位") @ApiOperation(value = "查询默认条件条件的岗位信息", notes = "查询默认条件条件的岗位信息")
List<SysPosition> findAllByBaseBean(SysPosition sysPosition); List<SysPosition> findAllByBaseBean();
/** /**
* *

@ -31,6 +31,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.redisson.api.RLock;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -48,6 +49,7 @@ import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFileAttributes;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -486,9 +488,9 @@ public class SysUserInfoController extends CoreBaseController {
ExcelTool excelTool = new ExcelTool(entityManager, redisRes); ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
try { try {
String filename = "userImportTemplate.xls"; String filename = "userImportTemplate.xls";
SysPosition positionBean = new SysPosition(); // SysPosition positionBean = new SysPosition();
positionBean.setOrganizeCode(AuthUtil.getOrganizeCode()); // positionBean.setOrganizeCode(AuthUtil.getOrganizeCode());
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean); List<SysPosition> positionList = positionService.findAllByBaseBean();
Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> position.getName(), (oldKey, newkey) -> oldKey)); Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> position.getName(), (oldKey, newkey) -> oldKey));
Map<String, Map<String, String>> relatefildMap = new HashMap<>(); Map<String, Map<String, String>> relatefildMap = new HashMap<>();
@ -520,9 +522,11 @@ public class SysUserInfoController extends CoreBaseController {
@PostMapping("/import") @PostMapping("/import")
@ApiOperation(value = "导用入户信息", notes = "导入用户信息") @ApiOperation(value = "导用入户信息", notes = "导入用户信息")
public ResultBean importUserInfo(@RequestParam MultipartFile file) { public ResultBean importUserInfo(@RequestParam MultipartFile file) {
ExcelTool excelTool = new ExcelTool(entityManager, redisRes); String lockKey = "REDISLOCK:IMPP:IMPORT_USER:" + AuthUtil.getSessionUser().getUserId();
RLock rLock = (RLock) redisRes.getLock(lockKey);
try { try {
if (rLock.tryLock(0, TimeUnit.MINUTES)) {
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
//1.读取数据 //1.读取数据
List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName()); List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
List<ResultBean> faildList = new ArrayList<>(); List<ResultBean> faildList = new ArrayList<>();
@ -534,16 +538,17 @@ public class SysUserInfoController extends CoreBaseController {
List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList); List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
//3.某些数据字段转换 //3.某些数据字段转换
SysPosition positionBean = new SysPosition(); // SysPosition positionBean = new SysPosition();
String organizationCode = AuthUtil.getOrganizeCode(); // String organizationCode = AuthUtil.getOrganizeCode();
positionBean.setOrganizeCode(organizationCode); // positionBean.setOrganizeCode(organizationCode);
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean); List<SysPosition> positionList = positionService.findAllByBaseBean();
Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey)); Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey));
SysDepartment departmentBean = new SysDepartment(); // SysDepartment departmentBean = new SysDepartment();
departmentBean.setOrganizeCode(organizationCode); // departmentBean.setOrganizeCode(organizationCode);
List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean); // List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
List<SysDepartment> departmentList = departmentService.findAllByBaseBean();
//部门树 //部门树
List<SysDepartment> departmentTree = new ArrayList<>(); List<SysDepartment> departmentTree = new ArrayList<>();
//部门id的映射 //部门id的映射
@ -592,11 +597,100 @@ public class SysUserInfoController extends CoreBaseController {
// resultMap.put("successList", successList); // resultMap.put("successList", successList);
resultMap.put("failList", faildList); resultMap.put("failList", faildList);
return new ResultBean().setSuccess(true).setResultMap(resultMap).build(); return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
}
return ResultBean.fail("当前账号有正在上传的任务进行,请等待上传完毕");
} catch (InterruptedException e) {
LOGGER.error("导入人员数据出错", e);
return ResultBean.fail(e);
} catch (ImppBusiException busExcep) { } catch (ImppBusiException busExcep) {
LOGGER.error("导入人员数据出错", busExcep);
return ResultBean.fail(busExcep); return ResultBean.fail(busExcep);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("导入人员数据出错", e);
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} finally {
if (rLock.isHeldByCurrentThread()) {
rLock.unlock();
}
} }
// try {
// //1.读取数据
// List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
// List<ResultBean> faildList = new ArrayList<>();
// LOGGER.debug("导入用户信息: 共读取数据{}条", importModelList.size());
// if (ObjectUtils.isEmpty(importModelList)) {
// return ResultBean.success();
// }
// //2.数据格式校验并去重
// List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
//
// //3.某些数据字段转换
// SysPosition positionBean = new SysPosition();
// String organizationCode = AuthUtil.getOrganizeCode();
// positionBean.setOrganizeCode(organizationCode);
// List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
//
// Map<String, String> positionMap = positionList.stream().collect(Collectors.toMap(position -> position.getPositionCode(), position -> String.valueOf(position.getId()), (oldKey, newkey) -> oldKey));
//
// SysDepartment departmentBean = new SysDepartment();
// departmentBean.setOrganizeCode(organizationCode);
// List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
// //部门树
// List<SysDepartment> departmentTree = new ArrayList<>();
// //部门id的映射
// Map<Long, SysDepartment> parentMap = departmentList.stream().collect(Collectors.toMap(el -> el.getId(), Function.identity()));
// //构造全部部门的部门树
// departmentList.forEach(el -> {
// if (!ObjectUtils.isEmpty(el.getParentId())) {
// if (CommonEnumUtil.PARENT.DEFAULT.getValue().longValue() == el.getParentId().longValue()) {
// departmentTree.add(el);
// } else {
// SysDepartment parentSys = parentMap.get(el.getParentId());
// if (!ObjectUtils.isEmpty(parentSys)) {
// if (null == parentSys.getChildList()) {
// parentSys.setChildList(new ArrayList<>());
// }
// parentSys.getChildList().add(el);
// }
// }
// }
// });
//// SysRole roleBean = new SysRole();
//// roleBean.setOrganizeCode(organizationCode);
// List<SysRole> roleList = sysRoleService.findAll();
// Map<String, String> roleMap = roleList.stream().collect(Collectors.toMap(sysRole -> sysRole.getName(), sysRole -> String.valueOf(sysRole.getId()), (oldKey, newkey) -> oldKey));
//
// List<ResultBean> successList = new ArrayList<>();
// //4.插入数据
// for (int i = 0; i < userInfoList.size(); i++) {
// UserInfoImportModel el = userInfoList.get(i);
// ResultBean<UserDetailModel> resultBean = converImportData(el, departmentTree, positionMap, roleMap);
// if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
// faildList.add(resultBean);
// continue;
// }
// resultBean = personnelController.insertUserDetailModel(resultBean.getResultObject());
// if (ObjectUtils.isEmpty(resultBean) || !resultBean.success) {
// faildList.add(resultBean);
// continue;
// }
// successList.add(resultBean);
// }
// Map<String, Object> resultMap = new HashMap<>();
// resultMap.put("total", importModelList.size());
// resultMap.put("success", successList.size());
// resultMap.put("fail", faildList.size());
//// resultMap.put("successList", successList);
// resultMap.put("failList", faildList);
// return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
// } catch (ImppBusiException busExcep) {
// return ResultBean.fail(busExcep);
// } catch (Exception e) {
// return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
// }
} }
@GetMapping("/find-position-ref-user") @GetMapping("/find-position-ref-user")
@ -773,6 +867,7 @@ public class SysUserInfoController extends CoreBaseController {
return ResultBean.success().setResultObject(userDetailModel).build(); return ResultBean.success().setResultObject(userDetailModel).build();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
LOGGER.error("导入人员数据转换出错", e); LOGGER.error("导入人员数据转换出错", e);
return ResultBean.fail(e); return ResultBean.fail(e);
} }

@ -12,6 +12,7 @@ import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.redisson.api.RLock;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -67,6 +68,10 @@ public class SynchronizedService implements ISynchronizedService {
@Override @Override
public synchronized List<SysOrderNoRule> nextOrderNo(String code, int num) { public synchronized List<SysOrderNoRule> nextOrderNo(String code, int num) {
//先拿规则 //先拿规则
String lockKey = CommonConstWords.REDIS_PREFIX_LOCK_GET_ORDER_NO + ":" + "LOCK" + ":" + code;
RLock rLock = (RLock) redisRes.getLock(lockKey);
rLock.lock();
try {
SysOrderNoRule codeRole = sysOrderNoRuleService.getSysOrderNoRuleByCode(code); SysOrderNoRule codeRole = sysOrderNoRuleService.getSysOrderNoRuleByCode(code);
if (codeRole == null) { if (codeRole == null) {
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
@ -114,6 +119,13 @@ public class SynchronizedService implements ISynchronizedService {
// 生成单号更缓存 // 生成单号更缓存
return orderNoRuleList; return orderNoRuleList;
} catch (Exception e) {
LOGGER.error("生成单号失败,单号代码:{},num:{}", code, num, e);
} finally {
if (rLock.isHeldByCurrentThread()) {
rLock.unlock();
}
}
return null;
} }
} }

@ -328,9 +328,10 @@ public class SysDepartmentService extends CrudService<SysDepartment> implements
} }
@Override @Override
public List<SysDepartment> findAllByBaseBean(SysDepartment sysDepartment) { public List<SysDepartment> findAllByBaseBean() {
Example example = Example.of(sysDepartment); // Example example = Example.of(sysDepartment);
return this.departmentRDao.findAll(example); DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
return this.departmentRDao.findByHqlWhere(ddlPackBean);
} }

@ -127,9 +127,10 @@ public class SysPositionService extends CrudService<SysPosition> implements ISys
} }
@Override @Override
public List<SysPosition> findAllByBaseBean(SysPosition sysPosition) { public List<SysPosition> findAllByBaseBean() {
Example example = Example.of(sysPosition); // Example example = Example.of(sysPosition);
return this.positionRDao.findAll(example); DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
return this.positionRDao.findByHqlWhere(ddlPackBean);
} }
@Override @Override

@ -12,6 +12,7 @@ import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import com.sun.mail.smtp.SMTPAddressFailedException; import com.sun.mail.smtp.SMTPAddressFailedException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.activation.DataHandler; import javax.activation.DataHandler;
@ -38,6 +39,12 @@ import java.util.Properties;
public class MailUtil { public class MailUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class); public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class);
/**
* starttls , outlook
*/
@Value("${mail.smtp.starttls.enable:false}")
private boolean smtpStarttlsEnabled;
// 收件人 // 收件人
private Address[] to = new Address[]{}; private Address[] to = new Address[]{};
private Address[] cc = new Address[]{}; private Address[] cc = new Address[]{};
@ -55,9 +62,9 @@ public class MailUtil {
private boolean isAuthenticationSMTP = false; private boolean isAuthenticationSMTP = false;
private final List<BodyPart> attachmentList = new ArrayList<>(); private final List<BodyPart> attachmentList = new ArrayList<>();
private static final int MAIL_SMTP_TIMEOUT =10000; private static final int MAIL_SMTP_TIMEOUT = 10000;
private static final int MAIL_SMTP_CONNECTIONTIMEOUT =10000; private static final int MAIL_SMTP_CONNECTIONTIMEOUT = 10000;
private static final int MAIL_SMTP_WRITETIMEOUT =10000; private static final int MAIL_SMTP_WRITETIMEOUT = 10000;
/** /**
* *
@ -206,6 +213,7 @@ public class MailUtil {
/** /**
* *
*
* @param fileName * @param fileName
* @param attachmentByte * @param attachmentByte
* @throws MessagingException * @throws MessagingException
@ -217,12 +225,13 @@ public class MailUtil {
/** /**
* *
*
* @param fileName * @param fileName
* @param attachmentByte * @param attachmentByte
* @param contentType * @param contentType
* @throws MessagingException * @throws MessagingException
*/ */
public void addAttachment(String fileName, byte[] attachmentByte,String contentType) throws MessagingException { public void addAttachment(String fileName, byte[] attachmentByte, String contentType) throws MessagingException {
BodyPart attachmentBodyPart = new MimeBodyPart(); BodyPart attachmentBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(attachmentByte, contentType); DataSource source = new ByteArrayDataSource(attachmentByte, contentType);
attachmentBodyPart.setDataHandler(new DataHandler(source)); attachmentBodyPart.setDataHandler(new DataHandler(source));
@ -232,6 +241,7 @@ public class MailUtil {
/** /**
* *
*
* @param attachment * @param attachment
* @throws MessagingException * @throws MessagingException
*/ */
@ -243,7 +253,7 @@ public class MailUtil {
attachmentList.add(attachmentBodyPart); attachmentList.add(attachmentBodyPart);
} }
public void cleanAttachmentList(){ public void cleanAttachmentList() {
attachmentList.clear(); attachmentList.clear();
} }
@ -267,6 +277,9 @@ public class MailUtil {
if (this.isAuthenticationSMTP) { if (this.isAuthenticationSMTP) {
server.put("mail.smtp.auth", "true"); server.put("mail.smtp.auth", "true");
} }
if (smtpStarttlsEnabled) {
server.put("mail.smtp.starttls.enable", "true");
}
Session conn = Session.getInstance(server, null); Session conn = Session.getInstance(server, null);
@ -323,7 +336,7 @@ public class MailUtil {
LOGGER.info("邮件发送成功"); LOGGER.info("邮件发送成功");
} catch (SMTPAddressFailedException e) { } catch (SMTPAddressFailedException e) {
LOGGER.error("邮件发送异常",e); LOGGER.error("邮件发送异常", e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getCode())
@ -331,7 +344,7 @@ public class MailUtil {
.setErrorSolution("请重新设置收件人") .setErrorSolution("请重新设置收件人")
.build(); .build();
} catch (AuthenticationFailedException e) { } catch (AuthenticationFailedException e) {
LOGGER.error("邮件发送异常",e); LOGGER.error("邮件发送异常", e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getCode())
@ -339,7 +352,7 @@ public class MailUtil {
.setErrorSolution("请重新设置账号或密码") .setErrorSolution("请重新设置账号或密码")
.build(); .build();
} catch (MessagingException e) { } catch (MessagingException e) {
LOGGER.error("邮件发送异常",e); LOGGER.error("邮件发送异常", e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
@ -347,7 +360,7 @@ public class MailUtil {
.setErrorSolution("请重新设置邮件服务器地址或端口") .setErrorSolution("请重新设置邮件服务器地址或端口")
.build(); .build();
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
LOGGER.error("邮件发送异常",e); LOGGER.error("邮件发送异常", e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
@ -355,7 +368,7 @@ public class MailUtil {
.setErrorSolution("请重新设置邮件服务器地址或端口") .setErrorSolution("请重新设置邮件服务器地址或端口")
.build(); .build();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("邮件发送异常",e); LOGGER.error("邮件发送异常", e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())

@ -0,0 +1,67 @@
package test.cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
import cn.estsh.i3plus.core.api.iservice.base.ISynchronizedService;
import cn.estsh.i3plus.core.apiservice.serviceimpl.base.SynchronizedService;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.platform.bean.SysOrderNoRule;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.run.ImppGo;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.util.ObjectUtils;
import org.testng.TestRunner;
import org.testng.annotations.Test;
import javax.annotation.Resource;
import java.util.Random;
/**
* @author ns
* orderNo
* @create 2021/9/15 0015 13:46
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ImppGo.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestSynchronizedService extends AbstractTestNGSpringContextTests {
@Autowired
private ISynchronizedService synchronizedService;
@Resource(name = CommonConstWords.IMPP_REDIS_RES)
private ImppRedis resRedis;
public static String orderNoKey = CommonConstWords.REDIS_PREFIX_LOCK_GET_ORDER_NO + ":" + "LOCK" + ":" + "PO_ORDER_NO" + ":" + "ORDERNO";
public static String serialNoKey = CommonConstWords.REDIS_PREFIX_LOCK_GET_ORDER_NO + ":" + "LOCK" + ":" + "PO_ORDER_NO" + ":" + "SERIALNO";
@Test(threadPoolSize = 5)
public void getOrderNo() {
while (true) {
try {
SysOrderNoRule sysOrderNoRule = synchronizedService.nextOrderNo("PO_ORDER_NO");
System.out.println(sysOrderNoRule);
System.out.println(sysOrderNoRule.getOrderNo());
System.out.println(sysOrderNoRule.getSerialNo());
if (!ObjectUtils.isEmpty(resRedis.getHash(orderNoKey + ":ORDERNO" ,sysOrderNoRule.getOrderNo()))){
throw new Exception("订单号重复");
}else{
resRedis.putHash(orderNoKey + ":ORDERNO",sysOrderNoRule.getOrderNo(), System.currentTimeMillis());
}
if (!ObjectUtils.isEmpty(resRedis.getHash(orderNoKey + ":SERIALNO", String.valueOf(sysOrderNoRule.getSerialNo())))){
throw new Exception("订单号重复");
}else {
resRedis.putHash(orderNoKey + ":SERIALNO", String.valueOf(sysOrderNoRule.getSerialNo()), System.currentTimeMillis());
}
Thread.sleep(new Random().nextInt(20));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Loading…
Cancel
Save