|  | @@ -16,6 +16,7 @@ import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.tenant.TenantContextHolder;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.eseal.ESealPlugin;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.storage.StoragePluginContext;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
 | 
	
	
		
			
				|  | @@ -25,6 +26,7 @@ import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.freemarker.FreemarkerTemplateEngine;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.money.MoneyUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.pdf.PDFUtil;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import org.apache.commons.io.FileUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
	
		
			
				|  | @@ -116,6 +118,9 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private TenantConfigService tenantConfigService;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private TenantContractTemplateService tenantContractTemplateService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Value("${contract.baseDir:/var/pdf}")
 | 
	
		
			
				|  |  |      private String contractBaseDir;
 | 
	
	
		
			
				|  | @@ -908,8 +913,18 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 | 
	
		
			
				|  |  |          if (Objects.nonNull(courseViewType)) {
 | 
	
		
			
				|  |  |              ownershipType = courseViewType;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +        // 查询最新协议模板
 | 
	
		
			
				|  |  | +		TenantContractTemplate tenantContractTemplate = tenantContractTemplateService.queryLatestContractTemplate(TenantContextHolder.getTenantId(), null, null);
 | 
	
		
			
				|  |  | +		if(tenantContractTemplate == null){
 | 
	
		
			
				|  |  | +			logger.error("最新协议模板查询失败");
 | 
	
		
			
				|  |  | +			return;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		String mainContent = tenantContractTemplate.getContractTemplateContent();
 | 
	
		
			
				|  |  | +		params.put("contractMainContent", mainContent);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, ownershipType.getContractVersion());
 | 
	
		
			
				|  |  | +        // 查询是否已生成协议
 | 
	
		
			
				|  |  | +        List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, tenantContractTemplate.getVersion());
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(userContracts)) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -937,7 +952,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        templateEngine.render(params, "product" + ownershipType.getContractVersion() + ".ftl", srcFile);
 | 
	
		
			
				|  |  | +        templateEngine.render(params, "latest_contract_template.ftl", srcFile);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 生成借款协议PDF
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -980,7 +995,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 | 
	
		
			
				|  |  |          sysUserContracts.setType(ContractType.PRODUCT);
 | 
	
		
			
				|  |  |          sysUserContracts.setUrl(pdfFilePath);
 | 
	
		
			
				|  |  |          sysUserContracts.setUserId(userId);
 | 
	
		
			
				|  |  | -        sysUserContracts.setVersion(ownershipType.getContractVersion());
 | 
	
		
			
				|  |  | +        sysUserContracts.setVersion(tenantContractTemplate.getVersion());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          sysUserContractsService.insert(sysUserContracts);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1062,8 +1077,15 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 | 
	
		
			
				|  |  |  				params.put("sealPicture", "https://daya-online.oss-cn-beijing.aliyuncs.com/website/clcf.png");
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +		TenantContractTemplate tenantContractTemplate = tenantContractTemplateService.queryLatestContractTemplate(TenantContextHolder.getTenantId(), null, null);
 | 
	
		
			
				|  |  | +		if(tenantContractTemplate == null){
 | 
	
		
			
				|  |  | +			throw new BizException("最新协议模板查询失败");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		String mainContent = tenantContractTemplate.getContractTemplateContent();
 | 
	
		
			
				|  |  | +		params.put("contractMainContent", mainContent);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        templateEngine.render(params, "product" + ownershipType.getContractVersion() + ".ftl", srcFile);
 | 
	
		
			
				|  |  | +        templateEngine.render(params, "latest_contract_template.ftl", srcFile);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          String html = "";
 | 
	
		
			
				|  |  |          try {
 |