|
@@ -12,6 +12,8 @@ import java.util.Map.Entry;
|
|
|
import com.ym.mec.auth.api.enums.CertificateTypeEnum;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -20,6 +22,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -1143,4 +1146,97 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResponseResult transferProduceContractOnlyWithCourseList(Integer userId) {
|
|
|
+ SysUser user = studentDao.lockUserReturnInfo(userId);
|
|
|
+ if (user == null) {
|
|
|
+ logger.error("用户不存在({})", userId);
|
|
|
+ return BaseController.failed("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isBlank(user.getRealName())||StringUtils.isBlank(user.getIdCardNo())){
|
|
|
+ return BaseController.failed(HttpStatus.PARTIAL_CONTENT, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
|
|
|
+ if (sysUserTsign == null && CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
|
|
|
+ try {
|
|
|
+ sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("用户电子签章注册失败", e);
|
|
|
+ return BaseController.failed("用户电子签章注册失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ // 合成freemarker
|
|
|
+ String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + userId + "_" + LocalDateTime.now().getSecond() + ".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);
|
|
|
+
|
|
|
+ CourseViewTypeEnum courseViewType = CourseViewTypeEnum.COURSE_lIST;
|
|
|
+ params.put("ownershipType", "OWN");
|
|
|
+
|
|
|
+ List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, 2);
|
|
|
+ if(!CollectionUtils.isEmpty(userContracts)){
|
|
|
+ return BaseController.succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ templateEngine.render(params, "product2.ftl", srcFile);
|
|
|
+
|
|
|
+ // 生成借款协议PDF
|
|
|
+ try {
|
|
|
+ PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("生成产品协议失败", e);
|
|
|
+ return BaseController.failed("生成产品协议失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String organCode = "91440300326364429H";
|
|
|
+
|
|
|
+ SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
|
|
|
+ if (organTsign == null) {
|
|
|
+ logger.error("甲方未创建签章");
|
|
|
+ return BaseController.failed("甲方未创建签章");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.PRODUCT);
|
|
|
+ sysUserContracts.setUrl(pdfFilePath);
|
|
|
+ sysUserContracts.setUserId(userId);
|
|
|
+ sysUserContracts.setVersion(2);
|
|
|
+
|
|
|
+ sysUserContractsService.insert(sysUserContracts);
|
|
|
+
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ return BaseController.succeed();
|
|
|
+ }
|
|
|
}
|