Browse Source

修改机构缴费、续费协议的动态参数

hgw 3 years ago
parent
commit
d7807b5c58

+ 13 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/vo/TenantInfoInfoPageVo.java → mec-biz/src/main/java/com/ym/mec/biz/dal/vo/TenantInfoPageVo.java

@@ -13,7 +13,7 @@ import java.util.Date;
  * Created by 2021-12-09
  */
 @ApiModel(value = "分页查询机构信息")
-public class TenantInfoInfoPageVo implements Serializable {
+public class TenantInfoPageVo implements Serializable {
     //机构基础信息
     @ApiModelProperty(value = "机构id")
     private Integer id;
@@ -65,9 +65,12 @@ public class TenantInfoInfoPageVo implements Serializable {
     @ApiModelProperty(value = "到期时间")
     private Date expireDate;
 
-    @ApiModelProperty(value = "合同价单价")
+    @ApiModelProperty(value = "合同价单价-续费价格")
     private BigDecimal contractPrice;
 
+    @ApiModelProperty(value = "开通价")
+    private BigDecimal openPrice;
+
     @ApiModelProperty(value = "有效期(数字-结合有效期单位)")
     private Integer expiryCount;
 
@@ -247,4 +250,12 @@ public class TenantInfoInfoPageVo implements Serializable {
     public void setServeId(Integer serveId) {
         this.serveId = serveId;
     }
+
+    public BigDecimal getOpenPrice() {
+        return openPrice;
+    }
+
+    public void setOpenPrice(BigDecimal openPrice) {
+        this.openPrice = openPrice;
+    }
 }

+ 4 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoService.java

@@ -2,12 +2,9 @@ package com.ym.mec.biz.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
-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.entity.*;
 import com.ym.mec.biz.dal.enums.TenantOrderRecordEnum;
-import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
+import com.ym.mec.biz.dal.vo.TenantInfoPageVo;
 import com.ym.mec.common.page.PageInfo;
 import org.redisson.api.RBucket;
 
@@ -27,13 +24,11 @@ public interface TenantInfoService extends IService<TenantInfo> {
 
     Map<String, Object> opsTenantState(Integer id, Integer state);
 
-    PageInfo<TenantInfoInfoPageVo> queryPage(Map<String, Object> param);
+    PageInfo<TenantInfoPageVo> queryPage(Map<String, Object> param);
 
     TenantInfo get(Integer tenantId);
 
-    String getContract(Integer tenantId);
-
-    String getContractAndUpLoad(Integer tenantId);
+    String getContract(Integer tenantId, TenantContractRecord.TenantContractRecordEnum en, Integer val);
 
     Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception;
 

+ 40 - 25
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -1,6 +1,5 @@
 package com.ym.mec.biz.service.impl;
 
-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;
@@ -20,7 +19,7 @@ import com.ym.mec.biz.dal.entity.TenantContractTemplate;
 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;
+import com.ym.mec.biz.dal.vo.TenantInfoPageVo;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -57,6 +56,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.math.RoundingMode;
 import java.nio.charset.Charset;
 import java.util.*;
@@ -514,8 +514,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * @return
      */
     @Override
-    public PageInfo<TenantInfoInfoPageVo> queryPage(Map<String, Object> param) {
-        Page<TenantInfoInfoPageVo> pageInfo = PageUtil.getPageInfo(param);
+    public PageInfo<TenantInfoPageVo> queryPage(Map<String, Object> param) {
+        Page<TenantInfoPageVo> pageInfo = PageUtil.getPageInfo(param);
         pageInfo.setAsc("a.id_");
         return PageUtil.pageInfo(baseMapper.queryPage(pageInfo, param));
     }
@@ -529,25 +529,35 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 预览协议
      *
      * @param tenantId 机构id
+     * @param en       协议类型 开通还是续费
+     * @param val      续费的时间长度
      */
     @Override
-    public String getContract(Integer tenantId) {
-        List<TenantInfoInfoPageVo> tenantInfoList = baseMapper.queryPage(new HashMap<String, Object>() {{
+    public String getContract(Integer tenantId, TenantContractRecordEnum en, Integer val) {
+        List<TenantInfoPageVo> tenantInfoList = baseMapper.queryPage(new HashMap<String, Object>() {{
             put("tenantId", tenantId);
         }});
         //查询协议中的信息
-        TenantInfoInfoPageVo tenantInfo = Optional.ofNullable(tenantInfoList)
+        TenantInfoPageVo tenantInfo = Optional.ofNullable(tenantInfoList)
                 .filter(CollectionUtils::isNotEmpty)
                 .map(a -> a.get(0))
                 .orElseThrow(() -> new BizException("未查询到机构信息"));
-        Date now = new Date();
+        //如果本次协议是开通服务则直接取开通时的价格
+        if (TenantContractRecordEnum.OPEN.equals(en)) {
+            tenantInfo.setContractPrice(tenantInfo.getOpenPrice());
+        } else {
+            //续费时 取合同价
+            BigDecimal contractAmount = tenantInfo.getContractPrice().multiply(new BigDecimal(val), new MathContext(1, RoundingMode.HALF_UP));
+            tenantInfo.setContractPrice(contractAmount);
+            tenantInfo.setExpiryCount(val);
+        }
         //获取协议变量参数
-        Map<String, Object> param = getContractParam(tenantInfo, now);
+        Map<String, Object> param = getContractParam(tenantInfo);
         //生成模版
         FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
         templateEngine.setClassForTemplateLoading(TenantInfoServiceImpl.class, "/config/contracts/");
         //文件地址验证
-        String srcPath = contractBaseDir + "/" + lexiaoyaContract + "/" + tenantId + "-" + tenantInfo.getServeName() + DateUtils.formatDate(now, "yyyyMMddHHmmss") + ".html";
+        String srcPath = contractBaseDir + "/" + lexiaoyaContract + "/" + tenantId + "-" + tenantInfo.getServeName() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmss") + ".html";
         File srcFile = new File(srcPath);
         if (!srcFile.getParentFile().exists()) {
             srcFile.getParentFile().mkdirs();
@@ -561,14 +571,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             throw new BizException("读取产品协议出错");
         } finally {
             //删除文件
-//            FileUtils.deleteQuietly(srcFile);
+            FileUtils.deleteQuietly(srcFile);
         }
     }
 
     /**
      * 获取协议变量参数
      */
-    private Map<String, Object> getContractParam(TenantInfoInfoPageVo tenantInfo, Date now) {
+    private Map<String, Object> getContractParam(TenantInfoPageVo tenantInfo) {
+        Date now = new Date();
         //将数据转换为Map
         Map<String, Object> param = WrapperUtil.toMap(tenantInfo);
         //当前时间
@@ -576,7 +587,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         //服务过期时间
         param.put("expireDate", DateUtils.formatDate(getExpiryDate(tenantInfo.getExpiryCount(), tenantInfo.getExpiryUnit(), now), "yyyy年MM月dd日"));
         //购买服务的时长单位
-        param.put("expiryUnit", TenantProductInfo.MONTH.equals(tenantInfo.getExpiryUnit()) ? "月" : "年");
+        param.put("expiryUnit", TenantProductInfo.MONTH.equals(tenantInfo.getExpiryUnit()) ? "月" : "年");
         //乙方公章
         param.put("officialSealB", "https://daya.ks3-cn-beijing.ksyun.com/202202/Sx6rzWm.png");
         //获取产品名称
@@ -641,9 +652,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 生成PDF协议上传到服务器并返回协议地址
      *
      * @param tenantId 机构id
+     * @param en       协议类型 开通还是续费
+     * @param val      续费的时间长度-续费才有值
      * @return 协议地址
      */
-    public String getContractAndUpLoad(Integer tenantId) {
+    private String getContractAndUpLoad(Integer tenantId, TenantContractRecordEnum en, Integer val) {
         Date now = new Date();
         //创建PDF本次缓存地址
         String srcPdfPath = contractBaseDir + lexiaoyaContract + DateUtils.formatDate(now, "yyyyMMddHHmmss") + "/" + tenantId + "_" + java.time.LocalDateTime.now().getSecond() + ".pdf";
@@ -653,7 +666,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             srcFile.getParentFile().mkdirs();
         }
         //获取协议内容
-        String contractHtml = getContract(tenantId);
+        String contractHtml = getContract(tenantId, en, val);
         // 生成PDF格式协议
         try {
             PDFUtil.renderToPDFByData(TenantInfoServiceImpl.class.getResource("/").getFile(), contractHtml, srcPdfPath, "simsun.ttc");
@@ -726,7 +739,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Map<String, Object> result = new HashMap<>();
         TenantProductInfo productInfo = getProductInfo(tenantId);
         //续费时 取合同价
-        BigDecimal amount = productInfo.getContractPrice().multiply(new BigDecimal(val));
+        BigDecimal amount = productInfo.getContractPrice().multiply(new BigDecimal(val), new MathContext(1, RoundingMode.HALF_UP));
         //生成订单编号
         String orderNo = idGenerator.generatorId("payment") + "";
         int orderState = 0;
@@ -791,16 +804,17 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         tenantProductInfoService.updateById(productInfo);
 
         //生成协议并上传得到地址
-        String contractPath = getContractAndUpLoad(tenantId);
+        TenantContractRecordEnum renew = TenantContractRecordEnum.RENEW;
+        String contractPath = getContractAndUpLoad(tenantId, renew, val);
         //写入协议记录
-        tenantContractRecordService.insertContractRecord(tenantId, contractPath, TenantContractRecordEnum.RENEW);
+        tenantContractRecordService.insertContractRecord(tenantId, contractPath, renew);
 
         //发送邮件短信
         Map<String, Object> par = new HashMap<>();
         par.put("tenantId", tenantId);
-        List<TenantInfoInfoPageVo> tenantInfos = baseMapper.queryPage(par);
+        List<TenantInfoPageVo> tenantInfos = baseMapper.queryPage(par);
         if (CollectionUtils.isNotEmpty(tenantInfos)) {
-            TenantInfoInfoPageVo tenantInfo = tenantInfos.get(0);
+            TenantInfoPageVo tenantInfo = tenantInfos.get(0);
             //邮件
             if (StringUtils.isNotBlank(tenantInfo.getEmail())) {
                 //机构名称 服务名称 学员上限 有效期
@@ -967,9 +981,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         productInfo.setTenantId(tenantId);
         tenantProductInfoService.updateByTenantId(productInfo);
         //生成协议并上传得到地址
-        String contractPath = getContractAndUpLoad(tenantId);
+        TenantContractRecordEnum open = TenantContractRecordEnum.OPEN;
+        String contractPath = getContractAndUpLoad(tenantId, open, null);
         //写入协议记录
-        tenantContractRecordService.insertContractRecord(tenantId, contractPath, TenantContractRecordEnum.OPEN);
+        tenantContractRecordService.insertContractRecord(tenantId, contractPath, open);
     }
 
     @Override
@@ -1098,7 +1113,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Map<String, Object> par = new HashMap<>();
         par.put("expiryDate", maturity);
         par.put("state", 1);
-        List<TenantInfoInfoPageVo> maturityTenant = baseMapper.queryPage(par);
+        List<TenantInfoPageVo> maturityTenant = baseMapper.queryPage(par);
         maturityTenant.forEach(t -> {
             TenantInfo tenantInfo = baseMapper.selectById(t.getId());
             tenantInfo.setState(2);
@@ -1115,12 +1130,12 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Map<String, Object> par = new HashMap<>();
         par.put("state", 1);
         par.put("expiryDate", expiryDate);
-        List<TenantInfoInfoPageVo> tenantList = baseMapper.queryPage(par);
+        List<TenantInfoPageVo> tenantList = baseMapper.queryPage(par);
         expiringSend(tenantList, DateUtils.formatDate(expiryDate, "yyyy年MM月dd日"), i);
     }
 
     //向即将到期的机构发送信息
-    private void expiringSend(List<TenantInfoInfoPageVo> infoList, String dateStr, int i) {
+    private void expiringSend(List<TenantInfoPageVo> infoList, String dateStr, int i) {
         infoList.forEach(t -> {
             //邮件
             if (StringUtils.isNotBlank(t.getEmail())) {

+ 3 - 1
mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -36,7 +36,7 @@
         update tenant_info set phone_ = #{newPhone} where phone_ = #{oldPhone}
     </update>
 
-    <resultMap id="TenantInfoInfoResult" type="com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo">
+    <resultMap id="TenantInfoInfoResult" type="com.ym.mec.biz.dal.vo.TenantInfoPageVo">
         <!--  机构基础信息-->
         <id column="id_" jdbcType="INTEGER" property="id"/>
         <result column="name_" jdbcType="VARCHAR" property="name"/>
@@ -58,6 +58,7 @@
         <result column="student_up_limit_" jdbcType="INTEGER" property="studentUpLimit"/>
         <result column="expiry_date_" jdbcType="TIMESTAMP" property="expireDate"/>
         <result column="contract_price_" jdbcType="VARCHAR" property="contractPrice"/>
+        <result column="pay_amount_" jdbcType="VARCHAR" property="openPrice"/>
         <result column="expiry_count_" jdbcType="INTEGER" property="expiryCount"/>
         <result column="expiry_unit_" jdbcType="VARCHAR" property="expiryUnit"/>
     </resultMap>
@@ -86,6 +87,7 @@
         ifnull(st.studentCount, 0) as studentCount,
         a.user_id_ as userId,
         b.contract_price_,
+        b.pay_amount_,
         b.expiry_unit_,
         b.expiry_count_,
         d.student_up_limit_

+ 13 - 11
mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java

@@ -3,6 +3,7 @@ package com.ym.mec.web.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
+import com.ym.mec.biz.dal.entity.TenantContractRecord;
 import com.ym.mec.biz.dal.entity.TenantInfo;
 import com.ym.mec.biz.dal.entity.TenantProductSumm;
 import com.ym.mec.biz.service.TenantInfoSendMsgService;
@@ -24,6 +25,7 @@ import javax.validation.Valid;
 import java.math.BigDecimal;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 
 import static com.ym.mec.biz.service.impl.TenantInfoSendMsgServiceImpl.OPEN;
 
@@ -123,19 +125,19 @@ public class TenantInfoController extends BaseController {
         return succeed(tenantInfoService.queryPage(param));
     }
 
-    /**
-     * 获取机构付款及续费时需要预览的协议
-     */
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", dataType = "Integer", value = "机构id"),
+            @ApiImplicitParam(name = "type", dataType = "Integer", value = "0开通 1续费"),
+            @ApiImplicitParam(name = "renewCount", dataType = "Integer", value = "若是续费,则需要传入续费时长"),
+    })
     @ApiOperation("获取机构付款及续费时需要预览的协议")
     @GetMapping(value = "/getContract/{id}")
-    public Object getContract(@PathVariable("id") Integer id) {
-        return succeed(tenantInfoService.getContract(id));
-    }
-
-    @ApiOperation("机构付款及续费时生成协议并上传")
-    @GetMapping(value = "/getContractPath/{id}")
-    public Object generateContractAndUpLoad(@PathVariable("id") Integer id) {
-        return succeed(tenantInfoService.getContractAndUpLoad(id));
+    public Object getContract(@PathVariable("id") Integer id, Integer type, Integer renewCount) {
+        TenantContractRecord.TenantContractRecordEnum en = Optional.ofNullable(type)
+                .filter(t -> TenantContractRecord.TenantContractRecordEnum.RENEW.getType().equals(t))
+                .map(t -> TenantContractRecord.TenantContractRecordEnum.RENEW)
+                .orElse(TenantContractRecord.TenantContractRecordEnum.OPEN);
+        return succeed(tenantInfoService.getContract(id, en, renewCount));
     }
 
     @ApiOperation("机构支付")