|
@@ -3,16 +3,17 @@ package com.ym.mec.biz.service.impl;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.Map.Entry;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dto.CirculationUser;
|
|
|
+import com.ym.mec.biz.dal.dto.OAFinancialDto;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -31,12 +32,6 @@ import org.springframework.util.CollectionUtils;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.auth.api.enums.CertificateTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao;
|
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupStudentFeeDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
|
|
|
-import com.ym.mec.biz.dal.dao.SysUserContractsDao;
|
|
|
import com.ym.mec.biz.dal.dto.StudentInfo;
|
|
|
import com.ym.mec.biz.dal.entity.CooperationOrgan.OwnershipType;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
@@ -142,6 +137,9 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
@Autowired
|
|
|
private StudentDao studentDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EmployeeDao employeeDao;
|
|
|
+
|
|
|
@Value("${contract.baseDir:/var/pdf}")
|
|
|
private String contractBaseDir;
|
|
|
|
|
@@ -1250,4 +1248,88 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
|
|
|
FileUtils.deleteQuietly(srcFile);
|
|
|
return BaseController.succeed();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String transferOaFinancial(OAFinancialDto financialDto) {
|
|
|
+ List<Integer> circulationUserIds = financialDto.getCirculationUsers().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
|
|
|
+ List<Integer> executorIds = financialDto.getExecutors().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
|
|
|
+ circulationUserIds.addAll(executorIds);
|
|
|
+ List<SysUser> users = employeeDao.getUsers(circulationUserIds);
|
|
|
+
|
|
|
+ Integer workOrderId = null;
|
|
|
+ List<SysUserTsign> sysUserTsigns = new ArrayList<>();
|
|
|
+ for (SysUser user : users) {
|
|
|
+ SysUserTsign sysUserTsign = sysUserTsignService.get(user.getId());
|
|
|
+ if (sysUserTsign == null) {
|
|
|
+ try {
|
|
|
+ sysUserTsign = register(user.getId(), user.getRealName(), user.getIdCardNo(), user.getPhone());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("用户电子签章注册失败", e);
|
|
|
+ throw new BizException(user.getRealName() + "电子签章注册失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (CirculationUser circulationUser : financialDto.getCirculationUsers()) {
|
|
|
+ if (workOrderId == null) {
|
|
|
+ workOrderId = circulationUser.getWorkOrder();
|
|
|
+ }
|
|
|
+ if (!circulationUser.getUserId().equals(user.getId())) continue;
|
|
|
+ circulationUser.setRealName(user.getRealName());
|
|
|
+ }
|
|
|
+ for (CirculationUser executor : financialDto.getExecutors()) {
|
|
|
+ if (!executor.getUserId().equals(user.getId())) continue;
|
|
|
+ executor.setRealName(user.getRealName());
|
|
|
+ }
|
|
|
+ sysUserTsigns.add(sysUserTsign);
|
|
|
+ }
|
|
|
+ financialDto.setSysUserTsigns(sysUserTsigns);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ // 合成freemarker
|
|
|
+ String srcPdfPath = contractBaseDir + "/oa/" + dateFormat1.format(date) + "/" + workOrderId + "_" + 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>();
|
|
|
+
|
|
|
+ // 查询参数信息
|
|
|
+ params.put("organName", financialDto.getOrganName());
|
|
|
+ params.put("realName", financialDto.getRealName());
|
|
|
+ params.put("feeType", financialDto.getFeeType());
|
|
|
+ params.put("totalMoney", financialDto.getTotalMoney().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ params.put("hasLoan", financialDto.getHasLoan());
|
|
|
+ params.put("memo", financialDto.getMemo());
|
|
|
+ params.put("circulationUsers", financialDto.getCirculationUsers());
|
|
|
+ params.put("executors", financialDto.getExecutors());
|
|
|
+
|
|
|
+ templateEngine.render(params, "financial.ftl", srcFile);
|
|
|
+
|
|
|
+ // 生成借款协议PDF
|
|
|
+ try {
|
|
|
+ PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("生成签章协议失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SysUserTsign sysUserTsign : financialDto.getSysUserTsigns()) {
|
|
|
+ eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), sysUserTsign.getUserId().toString(), srcPdfPath, srcPdfPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传到oss
|
|
|
+ String dateStrOss = dateFormatOss.format(date);
|
|
|
+ dateStrOss = "oa/" + dateStrOss + "/" + DateUtil.getHour(date);
|
|
|
+ String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
|
|
|
+
|
|
|
+ FileUtils.deleteQuietly(srcFile);
|
|
|
+
|
|
|
+ return pdfFilePath;
|
|
|
+ }
|
|
|
}
|