|
@@ -12,6 +12,7 @@ import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
@@ -63,6 +64,9 @@ 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.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
@Service
|
|
|
public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
@@ -116,6 +120,9 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
@Autowired
|
|
|
private MusicGroupService musicGroupService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+
|
|
|
@Value("${contract.baseDir:/var/pdf}")
|
|
|
private String contractBaseDir;
|
|
|
|
|
@@ -285,6 +292,10 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public boolean transferMusicGroupCoursesContract(Integer userId, String musicGroupId) {
|
|
|
+ if(true){
|
|
|
+ return transferProduceContract(userId);
|
|
|
+ }
|
|
|
+
|
|
|
SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
|
|
|
if (sysUserTsign == null) {
|
|
@@ -474,6 +485,10 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public boolean transferVipGroupCoursesContract(Integer userId, Long vipGroupId) {
|
|
|
+ if(true){
|
|
|
+ return transferProduceContract(userId);
|
|
|
+ }
|
|
|
+
|
|
|
SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
|
|
|
if (sysUserTsign == null) {
|
|
@@ -613,6 +628,10 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public boolean transferGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
|
|
|
+ if(true){
|
|
|
+ return transferProduceContract(userId);
|
|
|
+ }
|
|
|
+
|
|
|
SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
|
|
|
if (sysUserTsign == null) {
|
|
@@ -844,6 +863,10 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
|
|
|
@Override
|
|
|
public boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
|
|
|
+ if(true){
|
|
|
+ return transferProduceContract(userId);
|
|
|
+ }
|
|
|
+
|
|
|
SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
|
|
|
if (sysUserTsign == null) {
|
|
@@ -917,4 +940,123 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public boolean transferProduceContract(Integer userId) {
|
|
|
+ SysUser user = studentDao.lockUserReturnInfo(userId);
|
|
|
+
|
|
|
+ List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT);
|
|
|
+ if(!CollectionUtils.isEmpty(userContracts)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
+ if (sysUserTsign == null) {
|
|
|
+ if (user == null) {
|
|
|
+ throw new BizException("用户信息查询失败");
|
|
|
+ }
|
|
|
+ sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ // 合成freemarker
|
|
|
+ String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + 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>();
|
|
|
+
|
|
|
+ // 查询参数信息
|
|
|
+ StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
|
|
|
+ params.put("studentInfo", studentInfo);
|
|
|
+
|
|
|
+ params.put("isShowVisualSeal", false);
|
|
|
+
|
|
|
+ params.put("ownershipType", OwnershipType.OWN);
|
|
|
+
|
|
|
+ templateEngine.render(params, "product.ftl", srcFile);
|
|
|
+
|
|
|
+ // 生成借款协议PDF
|
|
|
+ try {
|
|
|
+ PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BizException("生成产品协议失败", e);
|
|
|
+ }
|
|
|
+ String organCode = "91440300326364429H";
|
|
|
+ SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
|
|
|
+ if (organTsign == null) {
|
|
|
+ throw new BizException("甲方未创建签章");
|
|
|
+ }
|
|
|
+
|
|
|
+ eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
|
|
|
+ if (sysUserTsign != null) {
|
|
|
+ eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传到oss
|
|
|
+ String dateStrOss = dateFormatOss.format(date);
|
|
|
+ dateStrOss = "product/" + dateStrOss + "/" + DateUtil.getHour(date);
|
|
|
+ String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
|
|
|
+
|
|
|
+ SysUserContracts sysUserContracts = new SysUserContracts();
|
|
|
+ sysUserContracts.setCreateTime(date);
|
|
|
+ sysUserContracts.setType(ContractType.COURSES);
|
|
|
+ sysUserContracts.setUrl(pdfFilePath);
|
|
|
+ sysUserContracts.setUserId(userId);
|
|
|
+
|
|
|
+ sysUserContractsService.insert(sysUserContracts);
|
|
|
+
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED)
|
|
|
+ public Map<String, Object> queryProductContract(Integer userId) {
|
|
|
+ // 合成freemarker
|
|
|
+ String srcPdfPath = contractBaseDir + "/product/" + 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>();
|
|
|
+
|
|
|
+ StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
|
|
|
+ params.put("studentInfo", studentInfo);
|
|
|
+ params.put("isShowVisualSeal", true);
|
|
|
+ params.put("ownershipType", OwnershipType.OWN);
|
|
|
+ templateEngine.render(params, "product.ftl", srcFile);
|
|
|
+
|
|
|
+ String html = "";
|
|
|
+ try {
|
|
|
+ html = FileUtils.readFileToString(srcFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BizException("读取产品协议出错", e);
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysUserContracts> userContractWithType = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("exists", !CollectionUtils.isEmpty(userContractWithType));
|
|
|
+ result.put("productContract", html);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|