|
@@ -194,7 +194,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
BeanUtils.copyProperties(tenantInfo, tenantInfoDto);
|
|
|
//机构产品信息
|
|
|
TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
|
|
|
- .eq("tenant_id_", tenantId));
|
|
|
+ .eq("tenant_id_", tenantId).eq("using_", 0));
|
|
|
setTenantInfo(productInfo, new TenantProductInfoDto(), tenantInfoDto::setProductInfo);
|
|
|
//机构配置信息
|
|
|
TenantConfig tenantConfig = tenantConfigService.getOne(new QueryWrapper<TenantConfig>()
|
|
@@ -227,16 +227,17 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
if (Objects.isNull(tenantId)) {
|
|
|
throw new BizException("请传入机构id");
|
|
|
}
|
|
|
- //查询最后一条该机构开通记录
|
|
|
- TenantOrderRecord oneRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>().queryWrapper()
|
|
|
+ //查询开通 续费 正在支付的记录
|
|
|
+ List<TenantOrderRecord> record = tenantOrderRecordService.list(new WrapperUtil<TenantOrderRecord>().queryWrapper()
|
|
|
.eq("tenant_id_", tenantId)
|
|
|
.isNotNull("trans_no_")
|
|
|
- .eq("order_type_", "TENANT_OPEN")
|
|
|
+ .and(wrapper -> wrapper.eq("order_type_", "TENANT_OPEN")
|
|
|
+ .or().eq("order_type_", "TENANT_RENEW"))
|
|
|
.eq("payment_channel_", "ADAPAY")
|
|
|
- .orderByDesc("created_time_"));
|
|
|
+ .eq("order_state_", 0));
|
|
|
//存在,就去第三方再次校验
|
|
|
- if (Objects.nonNull(oneRecord)) {
|
|
|
- tenantOrderRecordService.checkTenantOrder(oneRecord);
|
|
|
+ if (CollectionUtils.isNotEmpty(record)) {
|
|
|
+ record.forEach(r -> tenantOrderRecordService.checkTenantOrder(r));
|
|
|
}
|
|
|
return queryTenantInfo(tenantId);
|
|
|
}
|
|
@@ -300,7 +301,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
}
|
|
|
//获取产品信息得到服务id
|
|
|
TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
|
|
|
- .hasEq("tenant_id_", tenantId).queryWrapper());
|
|
|
+ .hasEq("tenant_id_", tenantId).queryWrapper().eq("using_", 0));
|
|
|
if (Objects.isNull(productInfo)) {
|
|
|
throw new BizException("开通账号信息异常!未查询到购买的产品信息!");
|
|
|
}
|
|
@@ -320,22 +321,18 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
//建立角色和菜单关系数据
|
|
|
Lists.partition(collectMenuId, 50)
|
|
|
.forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId));
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
//创建资产信息
|
|
|
TenantAssetsInfo assetsInfo = new TenantAssetsInfo();
|
|
|
assetsInfo.setTenantId(tenantId);
|
|
|
assetsInfo.setBalance(BigDecimal.ZERO);
|
|
|
assetsInfo.setFrozenAmount(BigDecimal.ZERO);
|
|
|
- assetsInfo.setCreatedTime(new Date());
|
|
|
+ assetsInfo.setCreatedTime(now);
|
|
|
assetsInfoService.save(assetsInfo);
|
|
|
//修改有效期
|
|
|
- Date expiryDate;
|
|
|
- if (TenantProductInfo.MONTH.equals(productInfo.getExpiryUnit())) {
|
|
|
- expiryDate = DateUtils.addMonths(new Date(), productInfo.getExpiryCount());
|
|
|
- } else if (TenantProductInfo.YEAR.equals(productInfo.getExpiryUnit())) {
|
|
|
- expiryDate = DateUtils.addYears(new Date(), productInfo.getExpiryCount());
|
|
|
- } else {
|
|
|
- throw new BizException("产品信息异常!开通失败!");
|
|
|
- }
|
|
|
+ Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now);
|
|
|
productInfo.setExpiryDate(expiryDate);
|
|
|
tenantProductInfoService.updateById(productInfo);
|
|
|
//发送邮件提醒
|
|
@@ -348,6 +345,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
bucket.delete();
|
|
|
}
|
|
|
|
|
|
+ //计算过期时间
|
|
|
+ private Date getExpiryDate(Integer expiryCount, String expiryUnit, Date date) {
|
|
|
+ Date expiryDate;
|
|
|
+ if (TenantProductInfo.MONTH.equals(expiryUnit)) {
|
|
|
+ expiryDate = DateUtils.addMonths(date, expiryCount);
|
|
|
+ } else if (TenantProductInfo.YEAR.equals(expiryUnit)) {
|
|
|
+ expiryDate = DateUtils.addYears(date, expiryCount);
|
|
|
+ } else {
|
|
|
+ throw new BizException("产品信息异常!开通失败!");
|
|
|
+ }
|
|
|
+ return expiryDate;
|
|
|
+ }
|
|
|
+
|
|
|
//拆分菜单获取菜单ID
|
|
|
private List<Integer> getMenuId(List<String> menuIdList) {
|
|
|
return menuIdList.stream()
|
|
@@ -427,21 +437,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
* 机构开通缴费
|
|
|
*/
|
|
|
public Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception {
|
|
|
- TenantInfo tenantInfo = Optional.ofNullable(tenantId)
|
|
|
- .map(baseMapper::selectById)
|
|
|
- .orElseThrow(() -> new BizException("未查询到机构信息!"));
|
|
|
- String key = "Tenant_Pay:" + tenantId;
|
|
|
- RBucket<Object> bucket = redissonClient.getBucket(key);
|
|
|
- //原子操作 抢锁成功为true
|
|
|
- if (!bucket.trySet(tenantId, 10, TimeUnit.SECONDS)) {
|
|
|
- if (tenantInfo.getPayState() == 1) {
|
|
|
- throw new BizException("已缴费请勿重复缴费!");
|
|
|
- }
|
|
|
- throw new BizException("正在缴费中请稍后!");
|
|
|
- }
|
|
|
- //机构产品信息
|
|
|
- TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
|
|
|
- .eq("tenant_id_", tenantId));
|
|
|
+ TenantProductInfo productInfo = getProductInfo(tenantId);
|
|
|
//生成订单编号
|
|
|
String orderNo = idGenerator.generatorId("payment") + "";
|
|
|
String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
@@ -474,6 +470,94 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 机构续费
|
|
|
+ *
|
|
|
+ * @param tenantId 机构id
|
|
|
+ * @param val 购买周期
|
|
|
+ */
|
|
|
+ public Map<String, Object> tenantRenewPay(Integer tenantId, Integer val) throws Exception {
|
|
|
+ TenantProductInfo productInfo = getProductInfo(tenantId);
|
|
|
+ //续费时 取合同价
|
|
|
+ BigDecimal amount = productInfo.getContractPrice().multiply(new BigDecimal(val));
|
|
|
+
|
|
|
+ //生成订单编号
|
|
|
+ String orderNo = idGenerator.generatorId("payment") + "";
|
|
|
+ TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_RENEW;
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ int orderState = 0;
|
|
|
+ //消费大于0元则拉起支付
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ result = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ BigDecimal.ZERO,
|
|
|
+ orderNo,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ tenantEnum.getMsg(),
|
|
|
+ tenantEnum.getMsg(),
|
|
|
+ 1,//临时写死
|
|
|
+ tenantEnum.getCode()
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ //续费成功
|
|
|
+ renewSuccess(val, productInfo, amount);
|
|
|
+ orderState = 1;
|
|
|
+ }
|
|
|
+ createOrderRecord(tenantId, amount, orderNo, tenantEnum, orderState);
|
|
|
+ //写入续费信息
|
|
|
+ opsRenewInfo(tenantId).set(val, 1, TimeUnit.HOURS);
|
|
|
+ log.info("tenant pay >>>>> {} ", result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //操作续费信息
|
|
|
+ public RBucket<Object> opsRenewInfo(Integer tenantId) {
|
|
|
+ String key = TenantOrderRecordEnum.TENANT_RENEW.getCode() + ":" + tenantId;
|
|
|
+ return redissonClient.getBucket(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 续费成功
|
|
|
+ *
|
|
|
+ * @param val 续费周期
|
|
|
+ * @param productInfo 原产品信息
|
|
|
+ * @param amount 续费总金额
|
|
|
+ */
|
|
|
+ public void renewSuccess(Integer val, TenantProductInfo productInfo, BigDecimal amount) {
|
|
|
+ Date expiryDate;
|
|
|
+ Date now = new Date();
|
|
|
+ if (productInfo.getExpiryDate().compareTo(now) > 0) {
|
|
|
+ //在上一个时间节点上做增加操作
|
|
|
+ expiryDate = getExpiryDate(val, productInfo.getExpiryUnit(), productInfo.getExpiryDate());
|
|
|
+ } else {
|
|
|
+ //如果上一个时间已经到期则 取现在时间
|
|
|
+ expiryDate = getExpiryDate(val, productInfo.getExpiryUnit(), now);
|
|
|
+ }
|
|
|
+ productInfo.setExpiryDate(expiryDate);
|
|
|
+ productInfo.setPayAmount(productInfo.getPayAmount().add(amount));
|
|
|
+ productInfo.setExpiryCount(productInfo.getExpiryCount() + val);
|
|
|
+ tenantProductInfoService.updateById(productInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private TenantProductInfo getProductInfo(Integer tenantId) {
|
|
|
+ TenantInfo tenantInfo = Optional.ofNullable(tenantId)
|
|
|
+ .map(baseMapper::selectById)
|
|
|
+ .orElseThrow(() -> new BizException("未查询到机构信息!"));
|
|
|
+ String key = "Tenant_Pay:" + tenantId;
|
|
|
+ RBucket<Object> bucket = redissonClient.getBucket(key);
|
|
|
+ //原子操作 抢锁成功为true
|
|
|
+ if (!bucket.trySet(tenantId, 10, TimeUnit.SECONDS)) {
|
|
|
+ if (tenantInfo.getPayState() == 1) {
|
|
|
+ throw new BizException("已缴费请勿重复缴费!");
|
|
|
+ }
|
|
|
+ throw new BizException("正在缴费中请稍后!");
|
|
|
+ }
|
|
|
+ //机构产品信息
|
|
|
+ return tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
|
|
|
+ .eq("tenant_id_", tenantId).eq("using_", 0));
|
|
|
+ }
|
|
|
+
|
|
|
//生成订单
|
|
|
private void createOrderRecord(Integer tenantId, BigDecimal payAmount, String orderNo, TenantOrderRecordEnum
|
|
|
tenantEnum, Integer orderState) {
|
|
@@ -614,7 +698,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
@Override
|
|
|
public Map<String, Object> recharge(Integer tenantId, BigDecimal amount) throws Exception {
|
|
|
log.error("机构 " + tenantId.toString() + "充值");
|
|
|
- TenantInfo tenantInfo = Optional.ofNullable(tenantId)
|
|
|
+ Optional.of(tenantId)
|
|
|
.map(baseMapper::selectById)
|
|
|
.orElseThrow(() -> new BizException("充值时,未查询到机构信息!"));
|
|
|
String key = "Tenant_Pay:" + tenantId;
|
|
@@ -679,19 +763,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
@Override
|
|
|
public void saveTenantContextHolder(HttpServletRequest request) {
|
|
|
String tenantId = request.getHeader("tenantId");
|
|
|
- if(StringUtils.isEmpty(tenantId)){
|
|
|
+ if (StringUtils.isEmpty(tenantId)) {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- if(sysUser != null && sysUser.getTenantId() != null){
|
|
|
+ if (sysUser != null && sysUser.getTenantId() != null) {
|
|
|
tenantId = sysUser.getTenantId().toString();
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtils.isNotEmpty(tenantId)){
|
|
|
+ if (StringUtils.isNotEmpty(tenantId)) {
|
|
|
TenantContextHolder.setTenantId(Integer.parseInt(tenantId));
|
|
|
- if(Integer.parseInt(tenantId) != -1){
|
|
|
+ if (Integer.parseInt(tenantId) != -1) {
|
|
|
TenantInfo tenantInfo = this.baseMapper.getOpenTenant(Integer.parseInt(tenantId));
|
|
|
- if(tenantInfo != null){
|
|
|
+ if (tenantInfo != null) {
|
|
|
request.setAttribute("datasourceId", tenantInfo.getDataSource());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new BizException("机构信息异常,请联系管理员");
|
|
|
}
|
|
|
}
|
|
@@ -703,7 +787,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
return baseMapper.queryTenantInfoByOrgan(organId);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public Boolean testEmail() {
|
|
|
SysUser user = sysUserFeignService.queryUserInfo();
|
|
@@ -711,7 +794,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
receivers.put(user.getId(), "yanite1234@sina.com");
|
|
|
receivers.put(2, "yanite2016@sina.com");
|
|
|
receivers.put(3, "yanite@qq.com");
|
|
|
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", null);
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", "小风乐团", "xiaofeng", "this is password");
|
|
|
|
|
|
return false;
|
|
|
}
|