|
@@ -1,40 +1,6 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import static com.ym.mec.biz.dal.enums.MessageTypeEnum.EMAIL_TENANT_EXPIRATION_REMINDERS;
|
|
|
-import static com.ym.mec.biz.dal.enums.MessageTypeEnum.EMAIL_TENANT_RENEWAL_SUCCESSFUL;
|
|
|
-import static com.ym.mec.biz.dal.enums.MessageTypeEnum.SMS_TENANT_EXPIRATION_REMINDERS;
|
|
|
-import static com.ym.mec.biz.dal.enums.MessageTypeEnum.SMS_TENANT_RENEWAL_SUCCESSFUL;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.joda.time.LocalDate;
|
|
|
-import org.joda.time.LocalDateTime;
|
|
|
-import org.redisson.api.RBucket;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.dao.DuplicateKeyException;
|
|
|
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -48,39 +14,11 @@ import com.ym.mec.biz.dal.dao.TenantInfoDao;
|
|
|
import com.ym.mec.biz.dal.dto.TenantConfigDto;
|
|
|
import com.ym.mec.biz.dal.dto.TenantInfoDto;
|
|
|
import com.ym.mec.biz.dal.dto.TenantProductInfoDto;
|
|
|
-import com.ym.mec.biz.dal.entity.Employee;
|
|
|
-import com.ym.mec.biz.dal.entity.Organization;
|
|
|
-import com.ym.mec.biz.dal.entity.PlatformServe;
|
|
|
-import com.ym.mec.biz.dal.entity.PlatformServeDetail;
|
|
|
-import com.ym.mec.biz.dal.entity.SysConfig;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserTsign;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantConfig;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantInfo;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantOrderRecord;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantProductInfo;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantProductSumm;
|
|
|
-import com.ym.mec.biz.dal.enums.GradeTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.JobNatureEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.TenantOrderRecordEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.dal.vo.PlatformServePageVo;
|
|
|
import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
|
|
|
-import com.ym.mec.biz.service.ContractService;
|
|
|
-import com.ym.mec.biz.service.EmployeeService;
|
|
|
-import com.ym.mec.biz.service.PayService;
|
|
|
-import com.ym.mec.biz.service.PlatformProductService;
|
|
|
-import com.ym.mec.biz.service.PlatformServeDetailService;
|
|
|
-import com.ym.mec.biz.service.PlatformServeService;
|
|
|
-import com.ym.mec.biz.service.StudentService;
|
|
|
-import com.ym.mec.biz.service.SysConfigService;
|
|
|
-import com.ym.mec.biz.service.SysMessageService;
|
|
|
-import com.ym.mec.biz.service.SysUserTsignService;
|
|
|
-import com.ym.mec.biz.service.TenantAssetsInfoService;
|
|
|
-import com.ym.mec.biz.service.TenantConfigService;
|
|
|
-import com.ym.mec.biz.service.TenantInfoService;
|
|
|
-import com.ym.mec.biz.service.TenantOrderRecordService;
|
|
|
-import com.ym.mec.biz.service.TenantProductInfoService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.page.PageUtil;
|
|
@@ -90,6 +28,40 @@ import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.thirdparty.yqpay.DateUtils;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
+import com.ym.mec.util.freemarker.FreemarkerTemplateEngine;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.joda.time.LocalDate;
|
|
|
+import org.joda.time.LocalDateTime;
|
|
|
+import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.ym.mec.biz.dal.enums.MessageTypeEnum.*;
|
|
|
|
|
|
@Service
|
|
|
public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService {
|
|
@@ -168,13 +140,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
setIdByApply(tenantId, dto.getProductInfo(), dto.getProductInfo()::setTenantId,
|
|
|
tenantProductInfoService::addTenantProduct);
|
|
|
//新建机构是0元时,直接默认支付成功
|
|
|
- if (dto.getProductInfo().getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- //修机构相关的改付款时间
|
|
|
- tenantOpen(tenantId);
|
|
|
- String orderNo = idGenerator.generatorId("payment") + "";
|
|
|
- //写入付款记录
|
|
|
- createOrderRecord(tenantId, BigDecimal.ZERO, orderNo, TenantOrderRecordEnum.TENANT_OPEN, 1, null);
|
|
|
- }
|
|
|
+ //2022年2月10日 根据需求进行变更,0元要走缴费流程,因为缴费之前要弹协议给客户看
|
|
|
+// if (dto.getProductInfo().getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// //修机构相关的改付款时间
|
|
|
+// tenantOpen(tenantId);
|
|
|
+// String orderNo = idGenerator.generatorId("payment") + "";
|
|
|
+// //写入付款记录
|
|
|
+// createOrderRecord(tenantId, BigDecimal.ZERO, orderNo, TenantOrderRecordEnum.TENANT_OPEN, 1, null);
|
|
|
+// }
|
|
|
//添加机构配置
|
|
|
setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
|
|
|
//释放
|
|
@@ -495,6 +468,129 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
return baseMapper.selectById(tenantId);
|
|
|
}
|
|
|
|
|
|
+ @Value("${contract.baseDir:/var/pdf}")
|
|
|
+ private String contractBaseDir;
|
|
|
+ @Autowired
|
|
|
+ private SysAreaService sysAreaService;
|
|
|
+ //乐小雅协议名称
|
|
|
+ public static final String lexiaoyaContract = "lexiaoyaContract";
|
|
|
+ //云教室每分钟价格
|
|
|
+ public static final String cloudAmount = "${cloudAmount}";
|
|
|
+ //云教室人数
|
|
|
+ public static final String cloudCount = "${cloudCount}";
|
|
|
+ //协议中云教室价格动态的样式 默认一个人的价格
|
|
|
+ public static final String defSpan = "<td style='text-align: center;'>" + cloudAmount + "/分钟/1V" + cloudCount + "</td>";
|
|
|
+ //超过1人的则需要这样的样式
|
|
|
+ public static final String rowspan = "<tr>" + defSpan + "</tr>";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预览协议
|
|
|
+ *
|
|
|
+ * @param tenantId 机构id
|
|
|
+ */
|
|
|
+ public String getContract(Integer tenantId) {
|
|
|
+ List<TenantInfoInfoPageVo> tenantInfoList = baseMapper.queryPage(new HashMap<String, Object>() {{
|
|
|
+ put("tenantId", tenantId);
|
|
|
+ }});
|
|
|
+ //查询协议中的信息
|
|
|
+ TenantInfoInfoPageVo tenantInfo = Optional.ofNullable(tenantInfoList)
|
|
|
+ .filter(CollectionUtils::isNotEmpty)
|
|
|
+ .map(a -> a.get(0))
|
|
|
+ .orElseThrow(() -> new BizException("未查询到机构信息"));
|
|
|
+ Date now = new Date();
|
|
|
+ //将数据转换为Map
|
|
|
+ Map<String, Object> param = toMap(tenantInfo);
|
|
|
+ param.put("nowDate", DateUtils.formatDate(now, "yyyy年MM月dd日"));
|
|
|
+ param.put("expireDate", DateUtils.formatDate(getExpiryDate(tenantInfo.getExpiryCount(), tenantInfo.getExpiryUnit(), now), "yyyy年MM月dd日"));
|
|
|
+ param.put("expiryUnit", TenantProductInfo.MONTH.equals(tenantInfo.getExpiryUnit()) ? "月" : "年");
|
|
|
+ param.put("officialSealB", "https://daya.ks3-cn-beijing.ksyun.com/202202/Sx6rzWm.png");
|
|
|
+ //写入产品名称
|
|
|
+ opsContactData(tenantInfo.getServeId(), platformServeService::queryProductNameById,
|
|
|
+ "未查询到产品信息!",
|
|
|
+ param::put, "productName", PlatformServePageVo::getProductName);
|
|
|
+ //获取城市
|
|
|
+ SysArea city = opsContactData(tenantInfo.getAreaId(), sysAreaService::get,
|
|
|
+ "未查询到城市信息!",
|
|
|
+ param::put, "city", SysArea::getName);
|
|
|
+ //获取省份
|
|
|
+ opsContactData(city.getId(), sysAreaService::getParentArea,
|
|
|
+ "未查询到省份信息!",
|
|
|
+ param::put, "province", SysArea::getName);
|
|
|
+ //查询机构配置信息
|
|
|
+ TenantConfig tenantConfig = opsContactData(tenantId, tenantConfigService::queryByTenantId,
|
|
|
+ "未查询到机构配置信息!",
|
|
|
+ param::put, "chargeRate", TenantConfig::getChargeRate);
|
|
|
+ //获取云教室规则 String人数 BigDecimal每分钟扣费标准
|
|
|
+ Map<String, BigDecimal> rule = opsContactData(tenantConfig.getConfig(), tenantConfigService::getCloudRoomRule,
|
|
|
+ "未查询到云教室的价格配置!",
|
|
|
+ param::put, "rowspan", Map::size);
|
|
|
+
|
|
|
+ AtomicReference<String> rowspanData = new AtomicReference<>("");
|
|
|
+ //生成默认云教室数据
|
|
|
+ rule.forEach((k, v) -> {
|
|
|
+ //人数
|
|
|
+ int count = Integer.parseInt(k) - 1;
|
|
|
+ if (count == 1) {
|
|
|
+ param.put("defRowspanData", replaceTemplate(defSpan, count, v));
|
|
|
+ } else {
|
|
|
+ rowspanData.set(rowspanData.get() + replaceTemplate(rowspan, count, v));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ param.put("rowspanData", rowspanData.get());
|
|
|
+
|
|
|
+ //生成模版
|
|
|
+ FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
|
|
|
+ templateEngine.setClassForTemplateLoading(TenantInfoServiceImpl.class, "/config/contracts/");
|
|
|
+ //文件地址验证
|
|
|
+ String srcPath = contractBaseDir + "/" + lexiaoyaContract + "/" + tenantId + "-" + tenantInfo.getServeName() + DateUtils.formatDate(now, "yyyyMMddHHmmss") + ".html";
|
|
|
+// String srcPath = "C:\\Users\\hgw\\Desktop\\" + tenantId +"-"+tenantInfo.getServeName()+DateUtils.formatDate(now, "yyyyMMddHHmmss")+ ".html";
|
|
|
+ File srcFile = new File(srcPath);
|
|
|
+ if (!srcFile.getParentFile().exists()) {
|
|
|
+ srcFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ //读取模版并替换模版内容
|
|
|
+ templateEngine.render(param, lexiaoyaContract + ".ftl", srcPath);
|
|
|
+ String html;
|
|
|
+ try {
|
|
|
+ html = FileUtils.readFileToString(srcFile, Charset.defaultCharset());
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取产品协议出错", e.getCause());
|
|
|
+ throw new BizException("读取产品协议出错");
|
|
|
+ } finally {
|
|
|
+ //删除文件
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ return html;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map toMap(TenantInfoInfoPageVo tenantInfo) {
|
|
|
+ return Optional.ofNullable(tenantInfo)
|
|
|
+ .map(JSONObject::toJSON)
|
|
|
+ .map(o -> JSONObject.toJavaObject((JSONObject) o, Map.class))
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static <O, T, S> T opsContactData(O param, Function<O, T> fun, String msg,
|
|
|
+ BiConsumer<String, Object> putC, String key, Function<T, S> val) {
|
|
|
+ Optional<T> optional = Optional.ofNullable(fun.apply(param));
|
|
|
+ optional.orElseThrow(() -> new BizException(msg));
|
|
|
+ optional.ifPresent(a -> {
|
|
|
+ S apply = val.apply(a);
|
|
|
+ if (apply instanceof BigDecimal) {
|
|
|
+ putC.accept(key, ((BigDecimal) apply).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ } else {
|
|
|
+ putC.accept(key, apply);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return optional.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String replaceTemplate(String tem, Integer count, BigDecimal v) {
|
|
|
+ return tem.replace(cloudCount, count + "")
|
|
|
+ .replace(cloudAmount, v.toString());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 机构开通缴费
|
|
|
*/
|
|
@@ -918,11 +1014,12 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
Map<String, Object> par = new HashMap<>();
|
|
|
par.put("state", 1);
|
|
|
par.put("expiryDate", expiryDate);
|
|
|
- List<TenantInfoInfoPageVo> oneTenant = baseMapper.queryPage(par);
|
|
|
- send(oneTenant, DateUtils.formatDate(expiryDate, "yyyy年MM月dd日"), i);
|
|
|
+ List<TenantInfoInfoPageVo> tenantList = baseMapper.queryPage(par);
|
|
|
+ expiringSend(tenantList, DateUtils.formatDate(expiryDate, "yyyy年MM月dd日"), i);
|
|
|
}
|
|
|
|
|
|
- private void send(List<TenantInfoInfoPageVo> infoList, String dateStr, int i) {
|
|
|
+ //向即将到期的机构发送信息
|
|
|
+ private void expiringSend(List<TenantInfoInfoPageVo> infoList, String dateStr, int i) {
|
|
|
infoList.forEach(t -> {
|
|
|
//邮件
|
|
|
if (StringUtils.isNotBlank(t.getEmail())) {
|