فهرست منبع

Merge remote-tracking branch 'origin/test_saas' into test_saas

zouxuan 3 سال پیش
والد
کامیت
33f9dd5c8d
17فایلهای تغییر یافته به همراه586 افزوده شده و 95 حذف شده
  1. 20 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantContractRecordDao.java
  2. 3 2
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantInfoDao.java
  3. 2 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantProductInfoDao.java
  4. 140 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantContractRecord.java
  5. 21 0
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantContractRecordService.java
  6. 11 10
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoService.java
  7. 2 0
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantProductInfoService.java
  8. 70 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantContractRecordServiceImpl.java
  9. 140 59
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java
  10. 1 12
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java
  11. 8 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantProductInfoServiceImpl.java
  12. 12 9
      mec-biz/src/main/resources/config/contracts/lexiaoyaContract.ftl
  13. 29 0
      mec-biz/src/main/resources/config/mybatis/TenantContractRecordMapper.xml
  14. 31 2
      mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml
  15. 37 0
      mec-biz/src/main/resources/config/mybatis/TenantProductInfoMapper.xml
  16. 52 0
      mec-web/src/main/java/com/ym/mec/web/controller/TenantContractRecordController.java
  17. 7 1
      mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java

+ 20 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantContractRecordDao.java

@@ -0,0 +1,20 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ym.mec.biz.dal.entity.TenantContractRecord;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 机构协议记录表(TenantContractRecord)表数据库访问层
+ *
+ * @author hgw
+ * @since 2022-02-12 16:16:40
+ */
+public interface TenantContractRecordDao extends BaseMapper<TenantContractRecord> {
+
+    int insertBatch(@Param("entities") List<TenantContractRecord> entities);
+
+}
+

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantInfoDao.java

@@ -7,7 +7,6 @@ import com.ym.mec.biz.dal.entity.TenantInfo;
 import com.ym.mec.biz.dal.entity.TenantProductSumm;
 import org.apache.ibatis.annotations.Param;
 
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -23,7 +22,9 @@ public interface TenantInfoDao extends BaseMapper<TenantInfo> {
 
     TenantInfo queryTenantInfoByOrgan(@Param("organId") Integer organId);
 
-    void updatePhone(@Param("newPhone")String newPhone, @Param("oldPhone")String oldPhone);
+    void updatePhone(@Param("newPhone") String newPhone, @Param("oldPhone") String oldPhone);
 
     Integer queryUserByTenantId(@Param("tenantId") Integer tenantId);
+
+    int openInitNewsInformation(@Param("tenantId") Integer tenantId, @Param("orgId") String orgId);
 }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantProductInfoDao.java

@@ -4,4 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ym.mec.biz.dal.entity.TenantProductInfo;
 
 public interface TenantProductInfoDao extends BaseMapper<TenantProductInfo> {
+
+    int updateByTenantId(TenantProductInfo obj);
 }

+ 140 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantContractRecord.java

@@ -0,0 +1,140 @@
+package com.ym.mec.biz.dal.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 机构协议记录表(TenantContractRecord)表实体类
+ *
+ * @author hgw
+ * @since 2022-02-12 16:16:41
+ */
+@ApiModel(value = "tenant_contract_record-机构协议记录表")
+public class TenantContractRecord implements Serializable {
+
+    public enum TenantContractRecordEnum {
+        OPEN(0, "机构开通"),
+        RENEW(1, "机构续费");
+
+        private Integer type;
+
+        private String msg;
+
+        TenantContractRecordEnum(Integer type, String msg) {
+            this.type = type;
+            this.msg = msg;
+        }
+
+        public Integer getType() {
+            return type;
+        }
+
+        public void setType(Integer type) {
+            this.type = type;
+        }
+
+        public String getMsg() {
+            return msg;
+        }
+
+        public void setMsg(String msg) {
+            this.msg = msg;
+        }
+    }
+
+    @TableId(value = "id_", type = IdType.AUTO)
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+
+    @TableField("tenant_id_")
+    @ApiModelProperty(value = "机构id")
+    private Integer tenantId;
+
+    @TableField("contract_name_")
+    @ApiModelProperty(value = "协议名称")
+    private String contractName;
+
+    @TableField("url_")
+    @ApiModelProperty(value = "协议网络地址")
+    private String url;
+
+    @TableField("type_")
+    @ApiModelProperty(value = "协议类型 0机构开通 1机构续费 待补充")
+    private Integer type;
+
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @TableField("biz_date_")
+    @ApiModelProperty(value = "创建日期")
+    private Date bizDate;
+
+    @TableField("create_time_")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    private static final long serialVersionUID = 1L;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public String getContractName() {
+        return contractName;
+    }
+
+    public void setContractName(String contractName) {
+        this.contractName = contractName;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public Date getBizDate() {
+        return bizDate;
+    }
+
+    public void setBizDate(Date bizDate) {
+        this.bizDate = bizDate;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+}
+

+ 21 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantContractRecordService.java

@@ -0,0 +1,21 @@
+package com.ym.mec.biz.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.biz.dal.entity.TenantContractRecord;
+import com.ym.mec.common.page.PageInfo;
+
+import java.util.Map;
+
+/**
+ * 机构协议记录表(TenantContractRecord)表服务接口
+ *
+ * @author hgw
+ * @since 2022-02-12 16:16:41
+ */
+public interface TenantContractRecordService extends IService<TenantContractRecord> {
+
+    int insertContractRecord(Integer tenantId, String contractPath, TenantContractRecord.TenantContractRecordEnum en);
+
+    PageInfo<TenantContractRecord> queryPage(Map<String, Object> param);
+}
+

+ 11 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoService.java

@@ -1,7 +1,6 @@
 package com.ym.mec.biz.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.ym.mec.biz.dal.dao.TenantInfoDao;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
 import com.ym.mec.biz.dal.entity.TenantInfo;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
@@ -10,7 +9,6 @@ import com.ym.mec.biz.dal.entity.TenantProductSumm;
 import com.ym.mec.biz.dal.enums.TenantOrderRecordEnum;
 import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
 import com.ym.mec.common.page.PageInfo;
-import com.ym.mec.thirdparty.yqpay.Msg;
 import org.redisson.api.RBucket;
 
 import javax.servlet.http.HttpServletRequest;
@@ -19,8 +17,6 @@ import java.util.Map;
 
 public interface TenantInfoService extends IService<TenantInfo> {
 
-    TenantInfoDao baseMapper();
-
     void addTenantInfo(TenantInfoDto dto);
 
     void updateTenantInfo(TenantInfoDto dto);
@@ -29,7 +25,7 @@ public interface TenantInfoService extends IService<TenantInfo> {
 
     TenantInfoDto queryTenantInfoCheck(Integer tenantId);
 
-    Map<String,Object> opsTenantState(Integer id, Integer state);
+    Map<String, Object> opsTenantState(Integer id, Integer state);
 
     PageInfo<TenantInfoInfoPageVo> queryPage(Map<String, Object> param);
 
@@ -37,6 +33,8 @@ public interface TenantInfoService extends IService<TenantInfo> {
 
     String getContract(Integer tenantId);
 
+    String getContractAndUpLoad(Integer tenantId);
+
     Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception;
 
     Map<String, Object> tenantRenewPay(Integer tenantId, Integer val) throws Exception;
@@ -48,6 +46,8 @@ public interface TenantInfoService extends IService<TenantInfo> {
     TenantOrderRecord createOrderRecord(Integer tenantId, BigDecimal payAmount, String orderNo, TenantOrderRecordEnum
             tenantEnum, Integer orderState, String merNos);
 
+    void tenantOpenSuccess(Integer tenantId);
+
     Map<String, Object> recharge(Integer tenantId, BigDecimal amount) throws Exception;
 
     Boolean rechargeCheck(String orderNo) throws Exception;
@@ -55,16 +55,17 @@ public interface TenantInfoService extends IService<TenantInfo> {
     TenantProductSumm queryTenantInfoProductSumm(Integer id);
 
     /**
-    * @description: 保存tenantId
      * @param request
-    * @return void
-    * @author zx
-    * @date 2022/1/7 14:42
-    */
+     * @return void
+     * @description: 保存tenantId
+     * @author zx
+     * @date 2022/1/7 14:42
+     */
     void saveTenantContextHolder(HttpServletRequest request);
 
     /**
      * 按部门查询机构信息
+     *
      * @return 机构信息
      */
     TenantInfo queryTenantInfoByOrgan(Integer organId);

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantProductInfoService.java

@@ -9,4 +9,6 @@ public interface TenantProductInfoService extends IService<TenantProductInfo> {
     void addTenantProduct(TenantProductInfoDto dto);
 
     void updateTenantProduct(TenantProductInfoDto dto);
+
+    void updateByTenantId(TenantProductInfo obj);
 }

+ 70 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantContractRecordServiceImpl.java

@@ -0,0 +1,70 @@
+package com.ym.mec.biz.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.biz.dal.dao.TenantContractRecordDao;
+import com.ym.mec.biz.dal.entity.TenantContractRecord;
+import com.ym.mec.biz.service.TenantContractRecordService;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.PageUtil;
+import com.ym.mec.common.page.WrapperUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * 机构协议记录表(TenantContractRecord)表服务实现类
+ *
+ * @author hgw
+ * @since 2022-02-12 16:16:41
+ */
+@Service("tenantContractRecordService")
+public class TenantContractRecordServiceImpl extends ServiceImpl<TenantContractRecordDao, TenantContractRecord> implements TenantContractRecordService {
+
+    private final static Logger log = LoggerFactory.getLogger(TenantContractRecordServiceImpl.class);
+
+    /**
+     * 写入协议记录
+     *
+     * @param tenantId     机构id
+     * @param contractPath 文件地址
+     * @param en           文件类型
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int insertContractRecord(Integer tenantId, String contractPath, TenantContractRecord.TenantContractRecordEnum en) {
+        Date now = new Date();
+        TenantContractRecord record = new TenantContractRecord();
+        record.setContractName(en.getMsg());
+        record.setType(en.getType());
+        record.setTenantId(tenantId);
+        record.setUrl(contractPath);
+        record.setBizDate(now);
+        record.setCreateTime(now);
+        return baseMapper.insert(record);
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param param 条件
+     */
+    @Override
+    public PageInfo<TenantContractRecord> queryPage(Map<String, Object> param) {
+        Page<TenantContractRecord> pageInfo = PageUtil.getPageInfo(param);
+        //分页查询
+        IPage<TenantContractRecord> page = this.page(pageInfo,
+                new WrapperUtil<TenantContractRecord>()
+                        .hasEq("type_", param.get("type"))
+                        .hasEq("tenant_id_", param.get("tenantId"))
+                        .queryWrapper());
+        return PageUtil.pageInfo(page);
+    }
+
+}
+

+ 140 - 59
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -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);
             }
-
         });
     }
 

+ 1 - 12
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -182,18 +182,7 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
 
     //开通成功
     private void open(TenantOrderRecord record) {
-        //机构产品信息
-        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
-                .hasEq("tenant_id_", record.getTenantId()).queryWrapper().eq("using_", 0));
-        //修改机构信息
-        TenantInfo tenantInfo = new TenantInfo();
-        tenantInfo.setId(record.getTenantId());
-        tenantInfo.setPayState(1);
-        tenantInfoService.updateById(tenantInfo);
-        //修改机构产品信息
-        productInfo.setPayDate(new Date());
-        productInfo.setTenantId(record.getTenantId());
-        tenantProductInfoService.updateById(productInfo);
+        tenantInfoService.tenantOpenSuccess(record.getTenantId());
     }
 
     //续费成功

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantProductInfoServiceImpl.java

@@ -46,6 +46,14 @@ public class TenantProductInfoServiceImpl extends ServiceImpl<TenantProductInfoD
         baseMapper.updateById(info);
     }
 
+    /**
+     * 根据机构id修改正在使用的机构产品信息
+     */
+    @Override
+    public void updateByTenantId(TenantProductInfo obj) {
+        baseMapper.updateByTenantId(obj);
+    }
+
     private void checkServe(Integer id, Integer detailId) {
         Optional.ofNullable(id)
                 .map(platformServeService::getById)

+ 12 - 9
mec-biz/src/main/resources/config/contracts/lexiaoyaContract.ftl

@@ -65,7 +65,7 @@
             left: 50%;
             width: 140px;
             height: 140px;
-            margin-left: -70px;
+            margin-left: -90px;
         }
 
         .iInfo {
@@ -85,7 +85,7 @@
         }
     </style>
 </head>
-<body>
+<body style="font-family:'SimSun'">
 <div class="container">
     <h1>管乐迷产品服务协议</h1>
     <table border="1" style="width: 100%; border-collapse: collapse;">
@@ -137,7 +137,6 @@
             <td style="text-align: center;">13296657052</td>
         </tr>
 
-        <br/>
     </table>
     武汉乐小雅网络科技有限公司(以下称为“乙方”)系专业的乐团运营管理综合服务提供方。甲、乙双方本着互惠互利、共同发展的原则,在平等、公平、自愿、诚信的基础上,经友好协商,就甲方向已方提供乐团运营管理综合服务相关事宜达成一致,同意按照下述协议条款及相关附件执行:
 
@@ -272,9 +271,11 @@
 
     <table border="1" style="width: 100%; border-collapse: collapse;">
         <tr>
-            <td style="text-align: center;">甲方盖章:</td>
-            <td style="text-align: center;" class="sign">
-                乙方盖章 <img class="cachet" src="${officialSealB}" alt="">
+            <td style="text-align: center;">
+                甲方盖章:<div class="sign"><img class="cachet" src="${officialSealA}" alt="" /></div>
+            </td>
+            <td style="text-align: center;">
+                乙方盖章:<div class="sign"><img class="cachet" src="${officialSealB}" alt="" /></div>
             </td>
         </tr>
         <tr>
@@ -401,9 +402,11 @@
             <td style="text-align: center;">乙方:武汉乐小雅网络科技有限公司</td>
         </tr>
         <tr>
-            <td style="text-align: center;">甲方盖章:</td>
-            <td style="text-align: center;" class="sign">
-                乙方盖章 <img class="cachet" src="${officialSealB}" alt="">
+            <td style="text-align: center;">
+                甲方盖章:<div class="sign"><img class="cachet" src="${officialSealA}" alt="" /></div>
+            </td>
+            <td style="text-align: center;">
+                乙方盖章:<div class="sign"><img class="cachet" src="${officialSealB}" alt="" /></div>
             </td>
         </tr>
         <tr>

+ 29 - 0
mec-biz/src/main/resources/config/mybatis/TenantContractRecordMapper.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ym.mec.biz.dal.dao.TenantContractRecordDao">
+    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantContractRecord">
+        <id column="id_" jdbcType="INTEGER" property="id"/>
+        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
+        <result column="contract_name_" jdbcType="VARCHAR" property="contractName"/>
+        <result column="url_" jdbcType="VARCHAR" property="url"/>
+        <result column="type_" jdbcType="INTEGER" property="type"/>
+        <result column="biz_date_" jdbcType="TIMESTAMP" property="bizDate"/>
+        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id_
+        , tenant_id_, contract_name_, url_, type_, biz_date_, create_time_
+    </sql>
+
+    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
+            parameterType="com.ym.mec.biz.dal.entity.TenantContractRecord">
+        insert into tenant_contract_record(tenant_id_, contract_name_, url_, type_, biz_date_, create_time_)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.tenantId}, #{entity.contractName}, #{entity.url}, #{entity.type}, #{entity.bizDate},
+            #{entity.createTime})
+        </foreach>
+    </insert>
+
+</mapper>

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 31 - 2
mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml


+ 37 - 0
mec-biz/src/main/resources/config/mybatis/TenantProductInfoMapper.xml

@@ -22,4 +22,41 @@
         , tenant_id_, serve_id_, serve_detail_id_, original_price_, contract_price_, pay_amount_, pay_date_, expiry_count_, expiry_unit_, expiry_date_, using_
     </sql>
 
+    <update id="updateByTenantId" parameterType="com.ym.mec.biz.dal.entity.TenantProductInfo">
+        update tenant_product_info
+        <set>
+            <if test="serveId != null">
+                serve_id_ = #{serveId,jdbcType=INTEGER},
+            </if>
+            <if test="serveDetailId != null">
+                serve_detail_id_ = #{serveDetailId,jdbcType=INTEGER},
+            </if>
+            <if test="originalPrice != null">
+                original_price_ = #{originalPrice,jdbcType=VARCHAR},
+            </if>
+            <if test="contractPrice != null">
+                contract_price_ = #{contractPrice,jdbcType=VARCHAR},
+            </if>
+            <if test="payAmount != null">
+                pay_amount_ = #{payAmount,jdbcType=VARCHAR},
+            </if>
+            <if test="payDate != null">
+                pay_date_ = #{payDate,jdbcType=TIMESTAMP},
+            </if>
+            <if test="expiryCount != null">
+                expiry_count_ = #{expiryCount,jdbcType=INTEGER},
+            </if>
+            <if test="expiryUnit != null">
+                expiry_unit_ = #{expiryUnit,jdbcType=VARCHAR},
+            </if>
+            <if test="expiryDate != null">
+                expiry_date_ = #{expiryDate,jdbcType=TIMESTAMP},
+            </if>
+            <if test="using != null">
+                using_ = #{using,jdbcType=INTEGER},
+            </if>
+        </set>
+        where tenant_id_ = #{tenantId,jdbcType=INTEGER} and using_ = 0
+    </update>
+
 </mapper>

+ 52 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantContractRecordController.java

@@ -0,0 +1,52 @@
+package com.ym.mec.web.controller;
+
+
+import com.ym.mec.biz.dal.entity.TenantContractRecord;
+import com.ym.mec.biz.service.TenantContractRecordService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.page.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.Map;
+
+/**
+ * 机构协议记录表(TenantContractRecord)表控制层
+ *
+ * @author hgw
+ * @since 2022-02-12 16:16:40
+ */
+@Api(tags = "机构协议记录表")
+@RestController
+@RequestMapping("/tenantContractRecord")
+public class TenantContractRecordController extends BaseController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private TenantContractRecordService tenantContractRecordService;
+
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tenantId", dataType = "Integer", value = "机构Id"),
+            @ApiImplicitParam(name = "type", dataType = "Integer", value = "协议类型 0机构开通 1机构续费 待补充"),
+            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
+            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
+    })
+    @ApiOperation("分页查询")
+    @PostMapping("/queryPage")
+    @PreAuthorize("@pcs.hasPermissions('tenantContractRecord/queryPage')")
+    public HttpResponseResult<PageInfo<TenantContractRecord>> queryPage(@RequestBody Map<String, Object> param) {
+        return succeed(tenantContractRecordService.queryPage(param));
+    }
+
+}
+

+ 7 - 1
mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java

@@ -69,7 +69,7 @@ public class TenantInfoController extends BaseController {
         Map<String, Object> openPar = tenantInfoService.opsTenantState(id, state);
         //有返回密码(第一次开通机构会生成登录密码并返回)就发送邮件及短信提醒
         String pw = WrapperUtil.toStr(openPar, "pw");
-        TenantInfo tenantInfo =(TenantInfo) openPar.get("tenantInfo");
+        TenantInfo tenantInfo = (TenantInfo) openPar.get("tenantInfo");
         if (StringUtils.isNotBlank(pw) && Objects.nonNull(tenantInfo)) {
             Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), pw, "https://online.dayaedu.com"};
             tenantInfoSendMsgService.platformSendToAll(OPEN, tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
@@ -132,6 +132,12 @@ public class TenantInfoController extends BaseController {
         return succeed(tenantInfoService.getContract(id));
     }
 
+    @ApiOperation("机构付款及续费时生成协议并上传")
+    @GetMapping(value = "/getContractPath/{id}")
+    public Object generateContractAndUpLoad(@PathVariable("id") Integer id) {
+        return succeed(tenantInfoService.getContractAndUpLoad(id));
+    }
+
     @ApiOperation("机构支付")
     @GetMapping(value = "/pay/{id}")
     public Object pay(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) throws Exception {

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است