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
* @param sysDepartment
*
* @return
*/
@ApiOperation(value = "根据sysDepartment查询所有符合条件的部门信息")
List<SysDepartment> findAllByBaseBean(SysDepartment sysDepartment);
@ApiOperation(value = "查询默认条件的部门信息")
List<SysDepartment> findAllByBaseBean();
}

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

@ -31,6 +31,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -48,6 +49,7 @@ import java.io.*;
import java.net.URLEncoder;
import java.nio.file.attribute.PosixFileAttributes;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -486,9 +488,9 @@ public class SysUserInfoController extends CoreBaseController {
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
try {
String filename = "userImportTemplate.xls";
SysPosition positionBean = new SysPosition();
positionBean.setOrganizeCode(AuthUtil.getOrganizeCode());
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
// SysPosition positionBean = new SysPosition();
// positionBean.setOrganizeCode(AuthUtil.getOrganizeCode());
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, Map<String, String>> relatefildMap = new HashMap<>();
@ -520,9 +522,11 @@ public class SysUserInfoController extends CoreBaseController {
@PostMapping("/import")
@ApiOperation(value = "导用入户信息", notes = "导入用户信息")
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 {
if (rLock.tryLock(0, TimeUnit.MINUTES)) {
ExcelTool excelTool = new ExcelTool(entityManager, redisRes);
//1.读取数据
List<UserInfoImportModel> importModelList = excelTool.importDataAndConver(file.getOriginalFilename(), file.getInputStream(), UserInfoImportModel.class, UserInfoImportModel.class.getSimpleName());
List<ResultBean> faildList = new ArrayList<>();
@ -534,16 +538,17 @@ public class SysUserInfoController extends CoreBaseController {
List<UserInfoImportModel> userInfoList = validateAndDistinc(importModelList, faildList);
//3.某些数据字段转换
SysPosition positionBean = new SysPosition();
String organizationCode = AuthUtil.getOrganizeCode();
positionBean.setOrganizeCode(organizationCode);
List<SysPosition> positionList = positionService.findAllByBaseBean(positionBean);
// SysPosition positionBean = new SysPosition();
// String organizationCode = AuthUtil.getOrganizeCode();
// positionBean.setOrganizeCode(organizationCode);
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));
SysDepartment departmentBean = new SysDepartment();
departmentBean.setOrganizeCode(organizationCode);
List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
// SysDepartment departmentBean = new SysDepartment();
// departmentBean.setOrganizeCode(organizationCode);
// List<SysDepartment> departmentList = departmentService.findAllByBaseBean(departmentBean);
List<SysDepartment> departmentList = departmentService.findAllByBaseBean();
//部门树
List<SysDepartment> departmentTree = new ArrayList<>();
//部门id的映射
@ -592,11 +597,100 @@ public class SysUserInfoController extends CoreBaseController {
// resultMap.put("successList", successList);
resultMap.put("failList", faildList);
return new ResultBean().setSuccess(true).setResultMap(resultMap).build();
}
return ResultBean.fail("当前账号有正在上传的任务进行,请等待上传完毕");
} catch (InterruptedException e) {
LOGGER.error("导入人员数据出错", e);
return ResultBean.fail(e);
} catch (ImppBusiException busExcep) {
LOGGER.error("导入人员数据出错", busExcep);
return ResultBean.fail(busExcep);
} catch (Exception e) {
LOGGER.error("导入人员数据出错", 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")
@ -773,6 +867,7 @@ public class SysUserInfoController extends CoreBaseController {
return ResultBean.success().setResultObject(userDetailModel).build();
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("导入人员数据转换出错", 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 org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -67,6 +68,10 @@ public class SynchronizedService implements ISynchronizedService {
@Override
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);
if (codeRole == null) {
throw ImppExceptionBuilder.newInstance()
@ -114,6 +119,13 @@ public class SynchronizedService implements ISynchronizedService {
// 生成单号更缓存
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
public List<SysDepartment> findAllByBaseBean(SysDepartment sysDepartment) {
Example example = Example.of(sysDepartment);
return this.departmentRDao.findAll(example);
public List<SysDepartment> findAllByBaseBean() {
// Example example = Example.of(sysDepartment);
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
return this.departmentRDao.findByHqlWhere(ddlPackBean);
}

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

@ -12,6 +12,7 @@ import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import com.sun.mail.smtp.SMTPAddressFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.activation.DataHandler;
@ -38,6 +39,12 @@ import java.util.Properties;
public class MailUtil {
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[] cc = new Address[]{};
@ -206,6 +213,7 @@ public class MailUtil {
/**
*
*
* @param fileName
* @param attachmentByte
* @throws MessagingException
@ -217,6 +225,7 @@ public class MailUtil {
/**
*
*
* @param fileName
* @param attachmentByte
* @param contentType
@ -232,6 +241,7 @@ public class MailUtil {
/**
*
*
* @param attachment
* @throws MessagingException
*/
@ -267,6 +277,9 @@ public class MailUtil {
if (this.isAuthenticationSMTP) {
server.put("mail.smtp.auth", "true");
}
if (smtpStarttlsEnabled) {
server.put("mail.smtp.starttls.enable", "true");
}
Session conn = Session.getInstance(server, null);

@ -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