|
@@ -24,7 +24,6 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -78,7 +77,7 @@ public class ContractServiceImpl implements ContractService {
|
|
|
@Override
|
|
|
@Async
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
|
|
|
- public HttpResponseResult<String> transferProduceContract(Long userId, SysUserType userType, ContractTemplateTypeEnum contractType, Boolean isShowVisualSeal) {
|
|
|
+ public HttpResponseResult<String> transferProduceContract(Long userId, SysUserType userType, ContractTemplateTypeEnum contractType) {
|
|
|
SysUser user = sysUserService.findUserById(userId);
|
|
|
if (user == null) {
|
|
|
logger.error("用户不存在({})", userId);
|
|
@@ -114,14 +113,14 @@ public class ContractServiceImpl implements ContractService {
|
|
|
FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
|
|
|
templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
|
|
|
|
|
|
- Boolean signflag = contractRecordService.checkContractSign(userId,userType, contractType);
|
|
|
+ Boolean signflag = contractRecordService.checkContractSign(userId, userType, contractType);
|
|
|
if (signflag) {
|
|
|
return HttpResponseResult.failed("用户已经签署协议");
|
|
|
}
|
|
|
|
|
|
// 查询最新协议模板
|
|
|
ContractTemplate tenantContractTemplate = contractTemplateService.queryLatestContractTemplate(contractType);
|
|
|
- if(tenantContractTemplate == null){
|
|
|
+ if (tenantContractTemplate == null) {
|
|
|
logger.error("最新协议模板查询失败");
|
|
|
return HttpResponseResult.failed("最新协议模板查询失败");
|
|
|
}
|
|
@@ -129,23 +128,23 @@ public class ContractServiceImpl implements ContractService {
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
String companyName = sysConfigService.findConfigValue(SysConfigConstant.COMPANY_NAME);
|
|
|
- params.put("companyName",companyName);
|
|
|
- params.put("companySealPicture",sysConfigService.findConfigValue(SysConfigConstant.COMPANY_SEAL_PICTURE));
|
|
|
- params.put("contractMainContent",mainContent);
|
|
|
- params.put("isShowVisualSeal", isShowVisualSeal);
|
|
|
+ params.put("companyName", companyName);
|
|
|
+ params.put("companySealPicture", sysConfigService.findConfigValue(SysConfigConstant.COMPANY_SEAL_PICTURE));
|
|
|
+ params.put("contractMainContent", mainContent);
|
|
|
+ params.put("isShowVisualSeal", false);
|
|
|
|
|
|
|
|
|
- Map<String,Object> userInfo = new HashMap<>();
|
|
|
- userInfo.put("realName",user.getRealName());
|
|
|
- userInfo.put("phone",user.getPhone());
|
|
|
- userInfo.put("idCardNo",user.getIdCardNo());
|
|
|
+ Map<String, Object> userInfo = new HashMap<>();
|
|
|
+ userInfo.put("realName", user.getRealName());
|
|
|
+ userInfo.put("phone", user.getPhone());
|
|
|
+ userInfo.put("idCardNo", user.getIdCardNo());
|
|
|
|
|
|
- if(SysUserType.STUDENT.equals(userType)){
|
|
|
+ if (SysUserType.STUDENT.equals(userType)) {
|
|
|
StudentVo detail = studentService.detail(userId);
|
|
|
- userInfo.put("subjectName",detail.getSubjectName());
|
|
|
- }else if(SysUserType.TEACHER.equals(userType)){
|
|
|
+ userInfo.put("subjectName", detail.getSubjectName());
|
|
|
+ } else if (SysUserType.TEACHER.equals(userType)) {
|
|
|
TeacherVo detail = teacherService.detail(userId);
|
|
|
- userInfo.put("subjectName",detail.getSubjectName());
|
|
|
+ userInfo.put("subjectName", detail.getSubjectName());
|
|
|
}
|
|
|
params.put("userInfo", userInfo);
|
|
|
|
|
@@ -163,7 +162,7 @@ public class ContractServiceImpl implements ContractService {
|
|
|
SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
|
|
|
if (organTsign == null) {
|
|
|
//创建企业签章
|
|
|
- addTsign(0L, organCode, companyName);
|
|
|
+ organTsign = addTsign(0L, organCode, companyName);
|
|
|
}
|
|
|
|
|
|
eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
|
|
@@ -179,10 +178,79 @@ public class ContractServiceImpl implements ContractService {
|
|
|
return HttpResponseResult.succeed(pdfFilePath);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED)
|
|
|
+ public HttpResponseResult<String> queryProductContract(Long userId, SysUserType userType, ContractTemplateTypeEnum contractType) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("code", "false");
|
|
|
+
|
|
|
+ SysUser user = sysUserService.findUserById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return HttpResponseResult.failed("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCardNo())) {
|
|
|
+ return HttpResponseResult.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/");
|
|
|
+
|
|
|
+ // 查询最新协议模板
|
|
|
+ ContractTemplate tenantContractTemplate = contractTemplateService.queryLatestContractTemplate(contractType);
|
|
|
+ if (tenantContractTemplate == null) {
|
|
|
+ return HttpResponseResult.failed("最新协议模板查询失败");
|
|
|
+ }
|
|
|
+ String mainContent = tenantContractTemplate.getContractTemplateContent();
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ String companyName = sysConfigService.findConfigValue(SysConfigConstant.COMPANY_NAME);
|
|
|
+ params.put("companyName", companyName);
|
|
|
+ params.put("companySealPicture", sysConfigService.findConfigValue(SysConfigConstant.COMPANY_SEAL_PICTURE));
|
|
|
+ params.put("contractMainContent", mainContent);
|
|
|
+ params.put("isShowVisualSeal", true);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> userInfo = new HashMap<>();
|
|
|
+ userInfo.put("realName", user.getRealName());
|
|
|
+ userInfo.put("phone", user.getPhone());
|
|
|
+ userInfo.put("idCardNo", user.getIdCardNo());
|
|
|
|
|
|
+ if (SysUserType.STUDENT.equals(userType)) {
|
|
|
+ StudentVo detail = studentService.detail(userId);
|
|
|
+ userInfo.put("subjectName", detail.getSubjectName());
|
|
|
+ } else if (SysUserType.TEACHER.equals(userType)) {
|
|
|
+ TeacherVo detail = teacherService.detail(userId);
|
|
|
+ userInfo.put("subjectName", detail.getSubjectName());
|
|
|
+ }
|
|
|
+ params.put("userInfo", userInfo);
|
|
|
+ templateEngine.render(params, "latest_contract_template.ftl", srcFile);
|
|
|
+
|
|
|
+ String html = "";
|
|
|
+ try {
|
|
|
+ html = FileUtils.readFileToString(srcFile);
|
|
|
+ } catch (IOException e) {
|
|
|
+ return HttpResponseResult.failed("读取产品协议出错");
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+ }
|
|
|
+ return HttpResponseResult.succeed(html);
|
|
|
+ }
|
|
|
|
|
|
- public SysUserTsign register(Long userId, String realName, String idCardNo, String mobileNo) {
|
|
|
|
|
|
+ private SysUserTsign register(Long userId, String realName, String idCardNo, String mobileNo) {
|
|
|
if (StringUtils.isBlank(realName) || StringUtils.isBlank(idCardNo) || StringUtils.isBlank(mobileNo)) {
|
|
|
return null;
|
|
|
}
|
|
@@ -223,12 +291,10 @@ public class ContractServiceImpl implements ContractService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public void addTsign(Long userId, String organCode, String orgName) {
|
|
|
+ private SysUserTsign addTsign(Long userId, String organCode, String orgName) {
|
|
|
Optional.ofNullable(organCode).orElseThrow(() -> new BizException("营业执照编号不能为空!"));
|
|
|
Optional.ofNullable(orgName).orElseThrow(() -> new BizException("营业名称不能为空"));
|
|
|
|
|
|
- SysUserTsign sysUserTsign = null;
|
|
|
-
|
|
|
SysUserTsign orignSysUserTsign = sysUserTsignService.queryByCardNo(organCode);
|
|
|
|
|
|
if (orignSysUserTsign == null) {
|
|
@@ -243,8 +309,8 @@ public class ContractServiceImpl implements ContractService {
|
|
|
throw new BizException("创建电子存证印章失败");
|
|
|
}
|
|
|
|
|
|
- sysUserTsign = new SysUserTsign(-userId, accountId, sealData, orgName, organCode);
|
|
|
- sysUserTsignService.insert(sysUserTsign);
|
|
|
+ orignSysUserTsign = new SysUserTsign(-userId, accountId, sealData, orgName, organCode);
|
|
|
+ sysUserTsignService.insert(orignSysUserTsign);
|
|
|
|
|
|
} else if (!StringUtils.equals(orignSysUserTsign.getName(), orgName)) {
|
|
|
if (eSealPlugin.updateOrganAccount(orignSysUserTsign.getAccountId(), orgName, organCode)) {
|
|
@@ -252,6 +318,7 @@ public class ContractServiceImpl implements ContractService {
|
|
|
sysUserTsignService.update(orignSysUserTsign);
|
|
|
}
|
|
|
}
|
|
|
+ return orignSysUserTsign;
|
|
|
|
|
|
}
|
|
|
|