ソースを参照

电签大小调整,日志删除异常

DengLinLang 8 ヶ月 前
コミット
b3f19e7693

+ 11 - 4
blade-service/blade-business/src/main/java/org/springblade/business/controller/ContractLogController.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springblade.business.entity.*;
 import org.springblade.business.feign.MessageWarningClient;
@@ -42,6 +43,7 @@ import org.springblade.system.cache.ParamCache;
 import org.springframework.beans.BeanUtils;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
@@ -54,6 +56,7 @@ import java.util.stream.Collectors;
  * @author BladeX
  * @since 2022-06-15
  */
+@Slf4j
 @RestController
 @AllArgsConstructor
 @RequestMapping("/contractLog")
@@ -113,12 +116,13 @@ public class ContractLogController extends BladeController {
     }
 
     /**
-     * 删除日志
+     *
      */
     @PostMapping("/removeByIds")
     @ApiOperationSupport(order = 12)
     @ApiOperation(value = "删除日志")
     @ApiImplicitParam(name = "ids", value = "删除的数据ID", required = true)
+    @Transactional
     public R<Boolean> removeByIds(@RequestBody JSONObject json) {
         if (json.containsKey("ids")) {
             Object ids = json.get("ids");
@@ -150,13 +154,16 @@ public class ContractLogController extends BladeController {
 
                 for (ContractLog log : contractLogList) {
                     //删除施工日志记录信息
-                    jdbcTemplate.execute("delete from u_contract_log where data_id = " + log.getDataId());
+                    jdbcTemplate.execute("delete from u_contract_log where data_id = '" + log.getDataId()+"'");
                     //删除关联的工序wbs信息
-                    jdbcTemplate.execute("delete from u_contract_log_wbs where business_id = " + log.getDataId() + " and contract_log_id = " + log.getId());
+                    jdbcTemplate.execute("delete from u_contract_log_wbs where contract_log_id = " + log.getId());
 
                     if (tableTemp != null && StringUtils.isNotEmpty(tableTemp.getInitTableName())) {
                         //删除实体表对应的数据信息
-                        jdbcTemplate.execute("delete from " + tableTemp.getInitTableName() + " where id = " + log.getDataId());
+                        String[] split = log.getDataId().split(",");
+                        for (String dataId : split) {
+                            jdbcTemplate.execute("delete from " + tableTemp.getInitTableName() + " where id = " + dataId);
+                        }
                     }
                 }
             }

+ 16 - 4
blade-service/blade-business/src/main/java/org/springblade/business/controller/UserViewProjectContractController.java

@@ -72,6 +72,7 @@ public class UserViewProjectContractController {
     private final ISysClient sysClient;
 
     private final SignPfxClient signPfxClient;
+    private static final double INCH_TO_CM = 2.54;
 
     /**
      * 获取用户信息
@@ -100,13 +101,15 @@ public class UserViewProjectContractController {
                 Double wide = signPfxFile.getWide();
                 Double high = signPfxFile.getHigh();
                 if(ObjectUtil.isNotEmpty(wide) && ObjectUtil.isNotEmpty(high)){
-                    BigDecimal wideBigDecimal = new BigDecimal(wide);
+                    int w = cmToPx(wide);
+                    int h = cmToPx(high);
+                    /*BigDecimal wideBigDecimal = new BigDecimal(wide);
                     BigDecimal highBigDecimal = new BigDecimal(high);
                     //分别乘以1.29 保留两位小数
                     BigDecimal wideDecima = wideBigDecimal.multiply(new BigDecimal(1.29)).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    BigDecimal highDecima = highBigDecimal.multiply(new BigDecimal(1.29)).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    wide = wideDecima.doubleValue();
-                    high = highDecima.doubleValue();
+                    BigDecimal highDecima = highBigDecimal.multiply(new BigDecimal(1.29)).setScale(2, BigDecimal.ROUND_HALF_UP);*/
+                    wide = Integer.valueOf(w).doubleValue();
+                    high = Integer.valueOf(h).doubleValue();
                 }else {
                     //获取图片本身大小 设置默认值
                     URL url = new URL(signatureFileUrl);
@@ -284,5 +287,14 @@ public class UserViewProjectContractController {
         }
         return R.data(-1, null, "数据查询失败");
     }
+    public static int cmToPx(double cm) {
+        double pixelsPerCm = 90 / INCH_TO_CM;
+        return (int) Math.round(cm * pixelsPerCm);
+    }
+    public static double pxToCm(int px) {
+        double cmPerPixel = INCH_TO_CM / 90;
+        //保留两位小数
+        return Math.round(px * cmPerPixel * 100) / 100.0;
+    }
 
 }

+ 9 - 11
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/SignPfxFileController.java

@@ -25,6 +25,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import okhttp3.OkHttpClient;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
@@ -467,12 +468,13 @@ public class SignPfxFileController extends BladeController {
     }*/
 
     /**
-     * 根据用户设定尺寸压缩图片后上传至oss
+     * 单纯的 上传文件到oss
      */
     @PostMapping("/compressAndUpload")
     public R<BladeFile> compressAndUpload(@RequestParam MultipartFile file, @RequestParam double wide,@RequestParam double high) throws Exception {
+        Long id = SnowFlakeUtil.getId();
         String file_path = FileUtils.getSysLocalFileUrl();
-        String localImgPath = file_path + "print//" + SnowFlakeUtil.getId() + ".png";
+        String localImgPath = file_path + "print//" +id + ".png";
         // 检查文件是否存在
         File newFile = new File(localImgPath);
         if (!newFile.exists()) {
@@ -484,11 +486,8 @@ public class SignPfxFileController extends BladeController {
         }
         // 保存文件
         file.transferTo(newFile);
-        //图片压缩后的地址
-        Long id = SnowFlakeUtil.getId();
-        String compressImgPath = file_path + "/print//" + id + ".png";
-        FileUtils.compressImage(localImgPath, compressImgPath, wide, high);
-        return R.data(newIOSSClient.uploadFile(id+".png", compressImgPath));
+        //FileUtils.compressImage(localImgPath, compressImgPath, wide, high);
+        return R.data(newIOSSClient.uploadFile(id+".png", localImgPath));
     }
 
     @PostMapping ("/prePicture")
@@ -527,7 +526,7 @@ public class SignPfxFileController extends BladeController {
             }
 
         }
-        vo.setSignatureFileUrl(compressionAndUpload(vo.getSignatureFileUrl(), vo.getWide(), vo.getHigh()));
+        //vo.setSignatureFileUrl(compressionAndUpload(vo.getSignatureFileUrl(), vo.getWide(), vo.getHigh()));
         return R.status(this.signPfxFileService.updateById(vo));
     }
 
@@ -575,7 +574,8 @@ public class SignPfxFileController extends BladeController {
     }
     public String compressionAndUpload(String fileStr, double wide, double high) throws Exception {
         String file_path = FileUtils.getSysLocalFileUrl();
-        InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(fileStr);
+        InputStream inputStreamByUrl = CommonUtil.getOSSInputStream(fileStr);
+        //InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(fileStr);
         //图片压缩后的地址
         Long id = SnowFlakeUtil.getId();
         String compressImgPath = file_path + "/print//" + id + ".png";
@@ -583,6 +583,4 @@ public class SignPfxFileController extends BladeController {
         BladeFile bladeFile = newIOSSClient.uploadFile(id + ".png", compressImgPath);
         return bladeFile.getLink();
     }
-
-
 }

+ 14 - 8
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/SignPfxFilePreServiceImpl.java

@@ -86,11 +86,11 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
                 Map imageSize = FileUtils.getImageSize(inputStreamByUrl1);
                 Integer width = (Integer) imageSize.get("width");
                 Integer height = (Integer) imageSize.get("height");
-                wide = width.doubleValue();
-                high = height.doubleValue();
+                wide = PdfAddimgUtil.pxToCm(width);
+                high = PdfAddimgUtil.pxToCm(height);
             }else {
-                wide = FileUtils.getImageWidth(file1).doubleValue();
-                high = FileUtils.getImageHeight(file1).doubleValue();
+                wide = PdfAddimgUtil.pxToCm(FileUtils.getImageWidth(file1));
+                high =PdfAddimgUtil.pxToCm(FileUtils.getImageHeight(file1));
             }
         }
         //图片地址
@@ -172,13 +172,19 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
         FileOutputStream outputStream = new FileOutputStream(excelPath);
         workbook.write(outputStream);
         FileUtils.excelToPdf(excelPath, pdfPath);
+        //把图片存储到本地
+
         if(ObjectUtil.isEmpty(file1)){
-            InputStream inputStreamByUrl2 = FileUtils.getInputStreamByUrl(vo.getFileStr());
-            FileUtils.compressImage(inputStreamByUrl2,compressImgPath, wide,high);
+            InputStream inputStreamByUrl2 = CommonUtil.getOSSInputStream(vo.getFileStr());
+            FileUtils.saveFile(inputStreamByUrl2,compressImgPath);
+            PdfAddimgUtil.PrepdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath,wide, high);
+           // FileUtils.compressImage(inputStreamByUrl2,compressImgPath, wide,high);
         }else {
-            FileUtils.compressImage(file1.getInputStream(),compressImgPath, wide,high);
+            FileUtils.saveFile(file1.getInputStream(),compressImgPath);
+            PdfAddimgUtil.PrepdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath,wide, high);
+            //FileUtils.compressImage(file1.getInputStream(),compressImgPath, wide,high);
         }
-        PdfAddimgUtil.PrepdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath);
+        //PdfAddimgUtil.PrepdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath,wide.intValue(), high.intValue());
         //压缩后的图片上传oss
         SignPfxFilePreVo signPfxFilePreVo = new SignPfxFilePreVo();
         signPfxFilePreVo.setWide(wide);

+ 17 - 9
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/PdfAddimgUtil.java

@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 
 public class PdfAddimgUtil {
+    private static final double INCH_TO_CM = 2.54;
 
     public static void pdfAddImgInfo(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap) throws Exception {
         String file_path = FileUtils.getSysLocalFileUrl();
@@ -143,7 +144,7 @@ public class PdfAddimgUtil {
         reader.close();
     }
     //后管新增电签预览添加图片信息方法
-    public static void PrepdfAddImgInfoNew(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap ,String signImg) throws Exception {
+    public static void PrepdfAddImgInfoNew(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap ,String signImg,double wide , double hign) throws Exception {
         File pdfFile = new File(pdfUrl);
         byte[] pdfData = new byte[(int) pdfFile.length()];
         FileInputStream inputStream = null;
@@ -181,14 +182,14 @@ public class PdfAddimgUtil {
                     pyzby = Func.toFloat(textdictInfo.getPyzby());
                     type = textdictInfo.getType()+"";
                 }
-                PreGaizhang(pdfFile, new File(pdfUrl), (int) position[0], position[1], position[2], signImg,pyzbx,pyzby,type);
+                PreGaizhang(pdfFile, new File(pdfUrl), (int) position[0], position[1], position[2], signImg,pyzbx,pyzby,type,wide,hign);
             }
         }
     }
 
 
     //后管新增电签预览盖章方法
-    public static void PreGaizhang(File src, File dest, int page, float x, float y, String imagePath,float pyzbx,float pyzby,String type) throws Exception {
+    public static void PreGaizhang(File src, File dest, int page, float x, float y, String imagePath,float pyzbx,float pyzby,String type,double wide, double hign) throws Exception {
         // 读取模板文件
         InputStream input = new FileInputStream(src);
         PdfReader reader = new PdfReader(input);
@@ -207,15 +208,14 @@ public class PdfAddimgUtil {
 
         // 读图片
         Image image = Image.getInstance(imagePath);
-
         // 获取操作的页面
         PdfContentByte under = stamper.getOverContent(page);
         // 添加图片
 
-        /*// 设置图片的新宽度和高度
-        float newWidth = 75f; // 新的宽度
-        float newHeight = image.getScaledHeight() * (newWidth / image.getScaledWidth()); // 根据宽度计算高度
-        image.scaleAbsolute(newWidth, newHeight); // 设置图片的新尺寸*/
+        // 设置图片的新宽度和高度
+        int newWidth = cmToPx(wide);
+        int newHeight = cmToPx(hign);
+        image.scaleAbsolute(newWidth, newHeight); // 设置图片的新尺寸
         //调整图片尺寸
         image.setAbsolutePosition(x, y);
         under.addImage(image);
@@ -223,7 +223,15 @@ public class PdfAddimgUtil {
         stamper.close();
         reader.close();
     }
-
+    public static int cmToPx(double cm) {
+        double pixelsPerCm = 90 / INCH_TO_CM;
+        return (int) Math.round(cm * pixelsPerCm);
+    }
+    public static double pxToCm(int px) {
+        double cmPerPixel = INCH_TO_CM / 90;
+        //保留两位小数
+        return Math.round(px * cmPerPixel * 100) / 100.0;
+    }
     /**
      * 【功能描述:添加图片和文字水印】 【功能详细描述:功能详细描述】
      *