|
@@ -15,6 +15,7 @@ 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.*;
|
|
|
+import com.ym.mec.biz.dal.entity.TenantContractRecord.TenantContractRecordEnum;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.dal.vo.PlatformServePageVo;
|
|
|
import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
|
|
@@ -26,9 +27,12 @@ import com.ym.mec.common.page.WrapperUtil;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
+import com.ym.mec.thirdparty.storage.StoragePluginContext;
|
|
|
+import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
|
|
|
import com.ym.mec.thirdparty.yqpay.DateUtils;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.freemarker.FreemarkerTemplateEngine;
|
|
|
+import com.ym.mec.util.pdf.PDFUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -67,10 +71,6 @@ import static com.ym.mec.biz.dal.enums.MessageTypeEnum.*;
|
|
|
public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(TenantInfoServiceImpl.class);
|
|
|
|
|
|
- public TenantInfoDao baseMapper() {
|
|
|
- return baseMapper;
|
|
|
- }
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
@Autowired
|
|
@@ -108,6 +108,27 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private ContractService contractService;
|
|
|
+ @Autowired
|
|
|
+ private SysAreaService sysAreaService;
|
|
|
+ @Autowired
|
|
|
+ private StoragePluginContext storagePluginContext;
|
|
|
+ @Autowired
|
|
|
+ private TenantPreJoinService tenantPreJoinService;
|
|
|
+ @Autowired
|
|
|
+ private TenantContractRecordService tenantContractRecordService;
|
|
|
+
|
|
|
+ @Value("${contract.baseDir:/var/pdf}")
|
|
|
+ private String contractBaseDir;
|
|
|
+ //乐小雅协议名称
|
|
|
+ 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>";
|
|
|
|
|
|
/**
|
|
|
* 新增机构
|
|
@@ -150,6 +171,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
// }
|
|
|
//添加机构配置
|
|
|
setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
|
|
|
+ //查询机构入驻表如果公司全称和联系电话相同则把入驻表修改为已入驻
|
|
|
+ TenantPreJoin preJoin = tenantPreJoinService.getOne(new QueryWrapper<TenantPreJoin>()
|
|
|
+ .eq("phone_", dto.getPhone())
|
|
|
+ .eq("state_", 0));
|
|
|
+ if (Objects.nonNull(preJoin)) {
|
|
|
+ preJoin.setState(1);
|
|
|
+ tenantPreJoinService.updateById(preJoin);
|
|
|
+ }
|
|
|
//释放
|
|
|
bucket.delete();
|
|
|
}
|
|
@@ -373,6 +402,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now);
|
|
|
productInfo.setExpiryDate(expiryDate);
|
|
|
tenantProductInfoService.updateById(productInfo);
|
|
|
+ //关联精彩活动等数据
|
|
|
+ baseMapper.openInitNewsInformation(tenantId, orgId.toString());
|
|
|
//释放锁
|
|
|
bucket.delete();
|
|
|
|
|
@@ -468,26 +499,12 @@ 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
|
|
|
*/
|
|
|
+ @Override
|
|
|
public String getContract(Integer tenantId) {
|
|
|
List<TenantInfoInfoPageVo> tenantInfoList = baseMapper.queryPage(new HashMap<String, Object>() {{
|
|
|
put("tenantId", tenantId);
|
|
@@ -498,35 +515,69 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
.map(a -> a.get(0))
|
|
|
.orElseThrow(() -> new BizException("未查询到机构信息"));
|
|
|
Date now = new Date();
|
|
|
+ //获取协议变量参数
|
|
|
+ Map<String, Object> param = getContractParam(tenantInfo, now);
|
|
|
+ //生成模版
|
|
|
+ FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
|
|
|
+ templateEngine.setClassForTemplateLoading(TenantInfoServiceImpl.class, "/config/contracts/");
|
|
|
+ //文件地址验证
|
|
|
+ String srcPath = contractBaseDir + "/" + lexiaoyaContract + "/" + 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);
|
|
|
+ try {
|
|
|
+ return FileUtils.readFileToString(srcFile, Charset.defaultCharset());
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取产品协议出错", e.getCause());
|
|
|
+ throw new BizException("读取产品协议出错");
|
|
|
+ } finally {
|
|
|
+ //删除文件
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取协议变量参数
|
|
|
+ */
|
|
|
+ private Map<String, Object> getContractParam(TenantInfoInfoPageVo tenantInfo, Date now) {
|
|
|
//将数据转换为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,
|
|
|
+ //获取产品名称
|
|
|
+ opsContractData(tenantInfo.getServeId(), platformServeService::queryProductNameById,
|
|
|
"未查询到产品信息!",
|
|
|
param::put, "productName", PlatformServePageVo::getProductName);
|
|
|
//获取城市
|
|
|
- SysArea city = opsContactData(tenantInfo.getAreaId(), sysAreaService::get,
|
|
|
+ SysArea city = opsContractData(tenantInfo.getAreaId(), sysAreaService::get,
|
|
|
"未查询到城市信息!",
|
|
|
param::put, "city", SysArea::getName);
|
|
|
//获取省份
|
|
|
- opsContactData(city.getId(), sysAreaService::getParentArea,
|
|
|
+ opsContractData(city.getId(), sysAreaService::getParentArea,
|
|
|
"未查询到省份信息!",
|
|
|
param::put, "province", SysArea::getName);
|
|
|
//查询机构配置信息
|
|
|
- TenantConfig tenantConfig = opsContactData(tenantId, tenantConfigService::queryByTenantId,
|
|
|
+ TenantConfig tenantConfig = opsContractData(tenantInfo.getId(), tenantConfigService::queryByTenantId,
|
|
|
"未查询到机构配置信息!",
|
|
|
param::put, "chargeRate", TenantConfig::getChargeRate);
|
|
|
+ //甲方企业公章
|
|
|
+ param.put("officialSealA", tenantConfig.getCorporateChops());
|
|
|
//获取云教室规则 String人数 BigDecimal每分钟扣费标准
|
|
|
- Map<String, BigDecimal> rule = opsContactData(tenantConfig.getConfig(), tenantConfigService::getCloudRoomRule,
|
|
|
+ Map<String, BigDecimal> rule = opsContractData(tenantConfig.getConfig(), tenantConfigService::getCloudRoomRule,
|
|
|
"未查询到云教室的价格配置!",
|
|
|
param::put, "rowspan", Map::size);
|
|
|
|
|
|
AtomicReference<String> rowspanData = new AtomicReference<>("");
|
|
|
- //生成默认云教室数据
|
|
|
+ //生成云教室扣费的样式
|
|
|
rule.forEach((k, v) -> {
|
|
|
//人数
|
|
|
int count = Integer.parseInt(k) - 1;
|
|
@@ -537,31 +588,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
}
|
|
|
});
|
|
|
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;
|
|
|
+ return param;
|
|
|
}
|
|
|
|
|
|
private Map toMap(TenantInfoInfoPageVo tenantInfo) {
|
|
@@ -571,8 +598,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
.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) {
|
|
|
+ private static <O, T, S> T opsContractData(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 -> {
|
|
@@ -592,6 +619,39 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 生成PDF协议上传到服务器并返回协议地址
|
|
|
+ *
|
|
|
+ * @param tenantId 机构id
|
|
|
+ * @return 协议地址
|
|
|
+ */
|
|
|
+ public String getContractAndUpLoad(Integer tenantId) {
|
|
|
+ Date now = new Date();
|
|
|
+ //创建PDF本次缓存地址
|
|
|
+ String srcPdfPath = contractBaseDir + lexiaoyaContract + DateUtils.formatDate(now, "yyyyMMddHHmmss") + "/" + tenantId + "_" + java.time.LocalDateTime.now().getSecond() + ".pdf";
|
|
|
+ //生成文件
|
|
|
+ File srcFile = new File(srcPdfPath);
|
|
|
+ if (!srcFile.getParentFile().exists()) {
|
|
|
+ srcFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ //获取协议内容
|
|
|
+ String contractHtml = getContract(tenantId);
|
|
|
+ // 生成PDF格式协议
|
|
|
+ try {
|
|
|
+ PDFUtil.renderToPDFByData(TenantInfoServiceImpl.class.getResource("/").getFile(), contractHtml, srcPdfPath, "simsun.ttc");
|
|
|
+ } catch (IOException e) {
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ throw new BizException("生成产品协议失败");
|
|
|
+ }
|
|
|
+ //上传到云服务器后获取上传地址
|
|
|
+ String dateStrOss = DateUtils.formatDate(now, "yyyy/MM/dd");
|
|
|
+ dateStrOss = "oa/" + dateStrOss + "/" + DateUtil.getHour(now);
|
|
|
+ String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
|
|
|
+ //删除本次PDF生成的文件缓存
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ return pdfFilePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 机构开通缴费
|
|
|
*/
|
|
|
public Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception {
|
|
@@ -621,7 +681,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
} else {
|
|
|
//已支付
|
|
|
orderState = 1;
|
|
|
- tenantOpen(tenantId);
|
|
|
+ tenantOpenSuccess(tenantId);
|
|
|
Map<String, Object> payMap = new HashMap<>();
|
|
|
payMap.put("orderNo", orderNo);
|
|
|
result.put("payMap", payMap);
|
|
@@ -639,6 +699,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
* @param tenantId 机构id
|
|
|
* @param val 购买周期
|
|
|
*/
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> tenantRenewPay(Integer tenantId, Integer val) throws Exception {
|
|
|
|
|
|
TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_RENEW;
|
|
@@ -709,6 +771,12 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
productInfo.setExpiryCount(productInfo.getExpiryCount() + val);
|
|
|
tenantProductInfoService.updateById(productInfo);
|
|
|
|
|
|
+ //生成协议并上传得到地址
|
|
|
+ String contractPath = getContractAndUpLoad(tenantId);
|
|
|
+ //写入协议记录
|
|
|
+ tenantContractRecordService.insertContractRecord(tenantId, contractPath, TenantContractRecordEnum.RENEW);
|
|
|
+
|
|
|
+ //发送邮件短信
|
|
|
Map<String, Object> par = new HashMap<>();
|
|
|
par.put("tenantId", tenantId);
|
|
|
List<TenantInfoInfoPageVo> tenantInfos = baseMapper.queryPage(par);
|
|
@@ -858,17 +926,31 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //修机构相关的改付款时间
|
|
|
- private void tenantOpen(Integer tenantId) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构开通需修机构相关的改付款时间和状态
|
|
|
+ *
|
|
|
+ * @param tenantId 机构id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void tenantOpenSuccess(Integer tenantId) {
|
|
|
+ //修改机构状态
|
|
|
TenantInfo tenantInfo = new TenantInfo();
|
|
|
tenantInfo.setId(tenantId);
|
|
|
tenantInfo.setPayState(1);
|
|
|
baseMapper.updateById(tenantInfo);
|
|
|
|
|
|
+ Date now = new Date();
|
|
|
+ //修改机构正在使用的产品的付款时间
|
|
|
TenantProductInfo productInfo = new TenantProductInfo();
|
|
|
- productInfo.setPayDate(new Date());
|
|
|
+ productInfo.setPayDate(now);
|
|
|
productInfo.setTenantId(tenantId);
|
|
|
- tenantProductInfoService.updateById(productInfo);
|
|
|
+ tenantProductInfoService.updateByTenantId(productInfo);
|
|
|
+ //生成协议并上传得到地址
|
|
|
+ String contractPath = getContractAndUpLoad(tenantId);
|
|
|
+ //写入协议记录
|
|
|
+ tenantContractRecordService.insertContractRecord(tenantId, contractPath, TenantContractRecordEnum.OPEN);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1045,7 +1127,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
|
|
|
sendPar2, null, 0, null,
|
|
|
"SYSTEM", phoneMsg);
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
|