From 23bd719cebe5feeff4e48fde925b0b39755eea93 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 15 十一月 2022 10:59:50 +0800
Subject: [PATCH] 2022.11.15

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/CommitmentServiceImpl.kt |   83 ++++++++++++++++++++++++++---------------
 1 files changed, 52 insertions(+), 31 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/CommitmentServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/CommitmentServiceImpl.kt
index d854dbc..693e017 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/CommitmentServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/Impl/CommitmentServiceImpl.kt
@@ -2,10 +2,8 @@
 
 import cn.flightfeather.supervision.common.pdf.DynamicParam
 import cn.flightfeather.supervision.common.pdf.GeneratePdfUtil
-import cn.flightfeather.supervision.common.pdf.PdfUtil
 import cn.flightfeather.supervision.domain.entity.Commitment
 import cn.flightfeather.supervision.domain.enumeration.SceneType
-import cn.flightfeather.supervision.domain.enumeration.UserType
 import cn.flightfeather.supervision.domain.mapper.CommitmentMapper
 import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
 import cn.flightfeather.supervision.infrastructure.utils.DateUtil
@@ -17,16 +15,14 @@
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.kotlin.readValue
 import com.github.pagehelper.PageHelper
-import net.coobird.thumbnailator.tasks.io.InputStreamImageSource
+import com.google.gson.Gson
 import org.springframework.beans.factory.annotation.Value
 import org.springframework.stereotype.Service
 import org.springframework.web.multipart.MultipartFile
 import tk.mybatis.mapper.entity.Example
-import java.awt.Image
-import java.io.File
+import java.time.LocalDate
+import java.time.format.DateTimeFormatter
 import java.util.*
-import javax.imageio.ImageReader
-import javax.imageio.stream.ImageInputStream
 import javax.servlet.http.HttpServletResponse
 
 /**
@@ -60,7 +56,7 @@
         var success = 0
         commitmentVos.forEach {
             var picPath = ""
-            val time = DateUtil().DateToString(Date(), DateUtil.DateStyle.YYYY_MM)
+            val time = DateUtil.DateToString(Date(), DateUtil.DateStyle.YYYY_MM)
             files.forEach { file ->
                 val fileName = file.originalFilename
                 //TODO 姝ゅ鐨勬枃浠惰矾寰勯渶瑕佷慨鏀逛负鍔ㄦ�侀厤缃�
@@ -94,13 +90,15 @@
         return commitmentVos.size == success
     }
 
-    override fun createLetterOfCommitment(userId: String, info: CommitmentVo, sign: MultipartFile, seal: MultipartFile?): BaseResponse<String> {
-        val signUrl = FileUtil.compressImage2(sign.bytes, 400)
+    override fun createLetterOfCommitment(userId: String, info: String, sign: MultipartFile?, seal: MultipartFile?): BaseResponse<List<String>> {
+        sign ?: return BaseResponse(false, "绛惧悕鍥剧墖鏈笂浼犳垚鍔�")
+        val infoVo = Gson().fromJson(info, CommitmentVo::class.java)
+
+        val signUrl = infoVo.sign.ifBlank { FileUtil.compressImage2(sign.bytes, 400) }
         val sealUrl = if (seal != null) FileUtil.compressImage2(seal.bytes, 400) else ""
 
-        val templatePath = (Thread.currentThread().contextClassLoader?.getResource("/")?.path ?: "src/main") + "/resources/templates/"
-
-        val time = DateUtil().DateToString(Date(), DateUtil.DateStyle.YYYY_MM)
+        val templatePath = (Thread.currentThread().contextClassLoader?.getResource("/")?.path ?: "src/main/resources") + "/templates/"
+        val time = DateUtil.DateToString(Date(), DateUtil.DateStyle.YYYY_MM)
         val path = "commitments/$time/$userId/"
         val contractPath = imgPath + path
 
@@ -128,35 +126,58 @@
                 contractName = "commitment-vehicle-${now.time}.pdf"
             }
         }
+//        val picName = contractName.replace("pdf", "jpg")
+
+        //琛ュ叏淇℃伅
+        infoVo.apply {
+            if (city.isBlank()) city = "涓婃捣甯�"
+            if (district.isBlank()) district = userInfo.extension1 ?: ""
+            if (year.isBlank()) {
+                val t = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")).split("-")
+                year = t[0]
+                month = t[1]
+                day = t[2]
+            }
+        }
         params.apply {
-            put("City", info.city)
-            put("District", info.district)
-            put("Department", info.department)
-            put("SocialCode", info.socialCode)
-            put("Number", info.number)
-            put("JuridicalPerson", info.juridicalPerson)
-            put("IdNo", info.idNo)
-            put("Type1", if (info.type1) "鉁�" else "鈻�")
-            put("Type2", if (info.type2) "鉁�" else "鈻�")
-            put("Type3", if (info.type3) "鉁�" else "鈻�")
-            put("Type4", if (info.type4) "鉁�" else "鈻�")
+            put("City", infoVo.city)
+            put("District", infoVo.district)
+            put("Department", infoVo.department)
+            put("SocialCode", infoVo.socialCode)
+            put("Number", infoVo.number)
+            put("JuridicalPerson", infoVo.juridicalPerson)
+            put("IdNo", infoVo.idNo)
+            put("Type1", if (infoVo.type1) "鈭�" else "鈻�")
+            put("Type2", if (infoVo.type2) "鈭�" else "鈻�")
+            put("Type3", if (infoVo.type3) "鈭�" else "鈻�")
+            put("Type4", if (infoVo.type4) "鈭�" else "鈻�")
             put("Sign", signUrl)
             put("Seal", sealUrl)
-            put("Year", info.year)
-            put("Month", info.month)
-            put("Day", info.day)
+            put("Year", infoVo.year)
+            put("Month", infoVo.month)
+            put("Day", infoVo.day)
         }
         val param = DynamicParam(templatePath, templateName, contractPath, contractName, params)
-        GeneratePdfUtil.generateContract(param)
-        //灏嗙敓浜х殑鎵胯涔﹁褰曟彃鍏ユ暟鎹簱
+        val picPaths = GeneratePdfUtil.generateContract(param)
+        var picPath = ""
+        for (i in picPaths.indices) {
+            val picName = contractName.replace(".pdf", "(${i}).jpg");
+            if (picPath.isNotBlank()) {
+                picPath += ";"
+            }
+            picPath += (path + picName)
+        }
+
+        //灏嗙敓鎴愮殑鎵胯涔﹁褰曟彃鍏ユ暟鎹簱
         val commitment = Commitment().apply {
             cmGuid = UUIDGenerator.generate16ShortUUID()
             uiGuid = userId
-            cmUrl = path + contractName
+            cmUrl = picPath
+            cmPdfUrl = path + contractName
             cmCreateTime = Date()
         }
         val r = commitmentMapper.insert(commitment)
 
-        return BaseResponse(r == 1, data = path)
+        return BaseResponse(r == 1, data = listOf(commitment.cmUrl, commitment.cmPdfUrl))
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3