yonge 5 роки тому
батько
коміт
21ff0274c5

+ 25 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ContractService.java

@@ -1,5 +1,8 @@
 package com.ym.mec.biz.service;
 
+import java.math.BigDecimal;
+import java.util.Date;
+
 import com.ym.mec.biz.dal.entity.SysUserTsign;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
 
@@ -80,4 +83,26 @@ public interface ContractService {
 	 * @return
 	 */
 	String queryGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum);
+
+	/**
+	 * 查询陪练课购买协议
+	 * @param userId
+	 * @param courseSectionNum 课程数
+	 * @param startDate 开始日期
+	 * @param endDate 结束日期
+	 * @param fee 费用
+	 * @return
+	 */
+	String queryPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee);
+
+	/**
+	 * 生成陪练课购买协议
+	 * @param userId
+	 * @param courseSectionNum
+	 * @param startDate
+	 * @param endDate
+	 * @param fee
+	 * @return
+	 */
+	boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee);
 }

+ 120 - 20
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service.impl;
 
 import java.io.File;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -81,7 +82,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 	@Autowired
 	private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
-	
+
 	@Autowired
 	private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
 
@@ -116,7 +117,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 	private String contractBaseDir;
 
 	private DateFormat dateFormatOss = new SimpleDateFormat("yyyy/MM/dd");
-	
+
 	private DateFormat dateFormat1 = new SimpleDateFormat("yyMMddHHmmSS");
 
 	@Override
@@ -215,8 +216,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 生成借款协议PDF
 		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"simsun.ttc");
+			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
@@ -348,22 +348,21 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 生成借款协议PDF
 		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"simsun.ttc");
+			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
 		String organCode = "";
-		if(musicGroup.getOwnershipType() == OwnershipType.OWN){
+		if (musicGroup.getOwnershipType() == OwnershipType.OWN) {
 			organCode = "91440300326364429H";
-		}else{
+		} else {
 			organCode = "91420106333619290A";
 		}
 		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if(organTsign == null){
+		if (organTsign == null) {
 			throw new BizException("甲方未创建签章");
 		}
-		
+
 		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
 		eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
 
@@ -513,17 +512,16 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 生成借款协议PDF
 		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"simsun.ttc");
+			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
 		String organCode = "91440300326364429H";
 		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if(organTsign == null){
+		if (organTsign == null) {
 			throw new BizException("甲方未创建签章");
 		}
-		
+
 		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
 
 		eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
@@ -673,22 +671,21 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 生成借款协议PDF
 		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"simsun.ttc");
+			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
 		String organCode = "";
-		if(musicGroup.getOwnershipType() == OwnershipType.OWN){
+		if (musicGroup.getOwnershipType() == OwnershipType.OWN) {
 			organCode = "91440300326364429H";
-		}else{
+		} else {
 			organCode = "91420106333619290A";
 		}
 		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if(organTsign == null){
+		if (organTsign == null) {
 			throw new BizException("甲方未创建签章");
 		}
-		
+
 		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
 
 		eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
@@ -787,4 +784,107 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		return result;
 	}
 
+	@Override
+	public String queryPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
+		// 合成freemarker
+		String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
+
+		File srcFile = new File(srcPdfPath);
+
+		File debtFile = new File(srcFile.getParent());
+		if (!debtFile.exists()) {
+			debtFile.mkdirs();
+		}
+
+		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("courseSectionNum", courseSectionNum);
+		params.put("startDate", startDate);
+		params.put("endDate", endDate);
+		params.put("fee", fee);
+
+		templateEngine.render(params, "practice.ftl", srcFile);
+
+		String result = "";
+		try {
+			result = FileUtils.readFileToString(srcFile);
+		} catch (IOException e) {
+			throw new BizException("读取陪练课购买协议出错", e);
+		}
+		FileUtils.deleteQuietly(srcFile);
+
+		return result;
+	}
+
+	@Override
+	public boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
+		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+
+		if (sysUserTsign == null) {
+			SysUser user = sysUserFeignService.queryUserById(userId);
+			if (user == null) {
+				throw new BizException("用户信息查询失败");
+			}
+			sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+		}
+
+		Date date = new Date();
+
+		// 合成freemarker
+		String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
+
+		File srcFile = new File(srcPdfPath);
+
+		File debtFile = new File(srcFile.getParent());
+		if (!debtFile.exists()) {
+			debtFile.mkdirs();
+		}
+
+		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+		Map<String, Object> params = new HashMap<String, Object>();
+		params.put("courseSectionNum", courseSectionNum);
+		params.put("startDate", startDate);
+		params.put("endDate", endDate);
+		params.put("fee", fee);
+
+		templateEngine.render(params, "practice.ftl", srcFile);
+
+		// 生成借款协议PDF
+		try {
+			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+		} catch (IOException e) {
+			throw new BizException("生成pdf协议失败", e);
+		}
+		String organCode = "91440300326364429H";
+		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+		if (organTsign == null) {
+			throw new BizException("甲方未创建签章");
+		}
+
+		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+
+		eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+
+		// 上传到oss
+		String dateStrOss = dateFormatOss.format(date);
+		dateStrOss = "practice/" + dateStrOss + "/" + DateUtil.getHour(date);
+		String pdfFilePath = storagePlugin.uploadFile(dateStrOss, srcFile);
+
+		SysUserContracts sysUserContracts = new SysUserContracts();
+		sysUserContracts.setCreateTime(date);
+		sysUserContracts.setType(ContractType.REGISTER);
+		sysUserContracts.setUrl(pdfFilePath);
+		sysUserContracts.setUserId(userId);
+
+		sysUserContractsService.insert(sysUserContracts);
+
+		FileUtils.deleteQuietly(srcFile);
+
+		return true;
+	}
+
 }

+ 13 - 0
mec-student/src/main/java/com/ym/mec/student/controller/ContractsController.java

@@ -1,5 +1,8 @@
 package com.ym.mec.student.controller;
 
+import java.math.BigDecimal;
+import java.util.Date;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
@@ -65,4 +68,14 @@ public class ContractsController extends BaseController {
 		return succeed(contractService.queryVipGroupCoursesContract(sysUser.getId(), vipGroupId));
 	}
 
+	@ApiOperation("查询陪练课课程协议")
+	@GetMapping(value = "queryPracticeCoursesContract")
+	public Object queryPracticeCoursesContract(int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
+		SysUser sysUser = sysUserFeignService.queryUserInfo();
+		if (sysUser == null) {
+			return failed("获取用户信息失败");
+		}
+		return succeed(contractService.queryPracticeCoursesContract(sysUser.getId(), courseSectionNum, startDate, endDate, fee));
+	}
+
 }