Browse Source

修改bug

DengLinLang 5 months ago
parent
commit
284c27fc6d

+ 1 - 1
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/OssBuilder.java

@@ -85,7 +85,7 @@ public class OssBuilder {
         String tenantId = AuthUtil.getTenantId();
         Oss oss = getOss(tenantId, code);
         //oss.setEndpoint("http://183.247.216.148:9000/");
-       oss.setEndpoint("https://oss-cn-shenzhen.aliyuncs.com/");
+       //oss.setEndpoint("https://oss-cn-shenzhen.aliyuncs.com/");
         Oss ossCached = ossPool.get(tenantId);
         OssTemplateRe template = templatePool.get(tenantId);
         // 若为空或者不一致,则重新加载

+ 4 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/SignPfxFilePreVo.java

@@ -6,5 +6,9 @@ import org.springframework.web.multipart.MultipartFile;
 
 @Data
 public class SignPfxFilePreVo extends SignPfxFilePre {
+    //接收的图片文件
     private MultipartFile file;
+    private  String preUrl;
+    //接收的图片地址
+    private String fileStr;
 }

+ 26 - 13
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/SignPfxFileController.java

@@ -19,9 +19,9 @@ package org.springblade.manager.controller;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
-import com.mixsmart.utils.StringUtils;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import okhttp3.OkHttpClient;
@@ -34,7 +34,10 @@ import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
-import org.springblade.manager.entity.*;
+import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.ProjectInfo;
+import org.springblade.manager.entity.SignPfxDeputy;
+import org.springblade.manager.entity.SignPfxFile;
 import org.springblade.manager.feign.ProjectAssignmentUserClient;
 import org.springblade.manager.service.*;
 import org.springblade.manager.utils.FileUtils;
@@ -53,7 +56,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.io.File;
-import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -469,7 +471,7 @@ public class SignPfxFileController extends BladeController {
     @PostMapping("/compressAndUpload")
     public R<BladeFile> compressAndUpload(@RequestParam MultipartFile file, @RequestParam double wide,@RequestParam double high) throws Exception {
         String file_path = FileUtils.getSysLocalFileUrl();
-        String localImgPath = file_path + "print//" + UUID.randomUUID() + ".png";
+        String localImgPath = file_path + "print//" + SnowFlakeUtil.getId() + ".png";
         // 检查文件是否存在
         File newFile = new File(localImgPath);
         if (!newFile.exists()) {
@@ -482,12 +484,13 @@ public class SignPfxFileController extends BladeController {
         // 保存文件
         file.transferTo(newFile);
         //图片压缩后的地址
-        UUID uuid = UUID.randomUUID();
-        String compressImgPath = file_path + "/print//" + uuid + ".png";
+        Long id = SnowFlakeUtil.getId();
+        String compressImgPath = file_path + "/print//" + id + ".png";
         FileUtils.compressImage(localImgPath, compressImgPath, wide, high);
-        return R.data(newIOSSClient.uploadFile(uuid+".png", compressImgPath));
+        return R.data(newIOSSClient.uploadFile(id+".png", compressImgPath));
     }
-    @PostMapping("/picPresave")
+    /*弃用   预览电签图片之前的一个新增
+ @PostMapping("/picPresave")
     @ApiOperationSupport(order = 3)
     @ApiOperation(value = "预览图片新增准备", notes = "传入signPfxFile")
     public R picPresave( @RequestParam MultipartFile file, @RequestParam double wide,@RequestParam double high) throws IOException {
@@ -496,15 +499,25 @@ public class SignPfxFileController extends BladeController {
         signPfxFilePreVo.setWide(wide);
         signPfxFilePreVo.setHigh(high);
         return pfxFilePreService.picPresave(signPfxFilePreVo);
-    }
+    }*/
     @PostMapping ("/prePicture")
     @ApiOperationSupport(order = 4)
     @ApiOperation(value = "预览电签后的图片", notes = "传入signPfxFile")
-    public R prePicture( @RequestBody SignPfxFilePre signPfxFilePre) throws Exception {
-        return pfxFilePreService.prePicture(signPfxFilePre);
+    public R prePicture(@RequestParam Optional<MultipartFile> file, @RequestParam Optional<String> fileStr, @RequestParam Optional<String> wide,@RequestParam Optional<String> high) throws Exception {
+        SignPfxFilePreVo signPfxFilePreVo = new SignPfxFilePreVo();
+        signPfxFilePreVo.setFile(file.orElse(null));
+        if(Func.isNotEmpty(wide.orElse(null)) && Func.isNotEmpty(high.orElse(null)) && !"null".equals(wide.get()) && !"null".equals(high.get())){
+            double wideDouble = Double.parseDouble(wide.get());
+            double highDouble = Double.parseDouble(high.get());
+            signPfxFilePreVo.setWide(wideDouble);
+            signPfxFilePreVo.setHigh(highDouble);
+        }else {
+            signPfxFilePreVo.setWide(null);
+            signPfxFilePreVo.setHigh(null);
+        }
+        signPfxFilePreVo.setFileStr(fileStr.orElse(null));
+        return pfxFilePreService.prePicture(signPfxFilePreVo);
     }
-
-
     /**
      * 修改 个人/企业证书信息表
      */

+ 1 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/ISignPfxFilePreService.java

@@ -1,7 +1,6 @@
 package org.springblade.manager.service;
 
 import org.springblade.core.tool.api.R;
-import org.springblade.manager.entity.SignPfxFilePre;
 import org.springblade.manager.vo.SignPfxFilePreVo;
 
 import java.io.IOException;
@@ -9,5 +8,5 @@ import java.io.IOException;
 public interface ISignPfxFilePreService {
     R picPresave(SignPfxFilePreVo signPfxFilePreVo) throws IOException;
 
-    R prePicture(SignPfxFilePre signPfxFilePre) throws Exception;
+    R prePicture(SignPfxFilePreVo signPfxFilePreVo) throws Exception;
 }

+ 40 - 15
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/SignPfxFilePreServiceImpl.java

@@ -9,10 +9,12 @@ import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
 import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.ribbon.utils.BeanUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.core.tool.utils.ResourceUtil;
 import org.springblade.manager.entity.SignPfxFilePre;
 import org.springblade.manager.entity.TextdictInfo;
@@ -29,7 +31,10 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @Service
 public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
@@ -47,7 +52,7 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
         MultipartFile file1 = vo.getFile();
         //图片保存到本地
         String file_path = FileUtils.getSysLocalFileUrl();
-        String localImgPath = file_path + "print//" + UUID.randomUUID() + ".png";
+        String localImgPath = file_path + "print//" + SnowFlakeUtil.getId() + ".png";
             // 检查文件是否存在
             File file = new File(localImgPath);
             if (!file.exists()) {
@@ -68,22 +73,33 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
     }
 
     @Override
-    public R prePicture(SignPfxFilePre signPfxFilePre) throws Exception {
-        SignPfxFilePre spr = signPfxFilePreMapper.selectByPrimaryKey(signPfxFilePre.getId());
+    public R prePicture(SignPfxFilePreVo vo) throws Exception {
+//        SignPfxFilePre spr = signPfxFilePreMapper.selectByPrimaryKey(vo.getId());
+        InputStream inputStreamByUrl1 = FileUtils.getInputStreamByUrl(vo.getFileStr());
+        MultipartFile file1 = vo.getFile();
         //宽度
-        Double wide = spr.getWide();
+        Double wide = vo.getWide();
         //高度
-        Double hight = spr.getHigh();
+        Double high = vo.getHigh();
+        if(ObjectUtil.isEmpty(wide) && ObjectUtil.isEmpty(high)){
+            if(ObjectUtil.isEmpty(file1)){
+                Map imageSize = FileUtils.getImageSize(inputStreamByUrl1);
+                Integer width = (Integer) imageSize.get("width");
+                Integer height = (Integer) imageSize.get("height");
+                wide = width.doubleValue();
+                high = height.doubleValue();
+            }else {
+                wide = FileUtils.getImageWidth(file1).doubleValue();
+                high = FileUtils.getImageHeight(file1).doubleValue();
+            }
+        }
         //图片地址
-        String localImgPath = spr.getSignaturePngUrl();
         String file_path = FileUtils.getSysLocalFileUrl();
+        Long id = SnowFlakeUtil.getId();
+        String compressImgPath = file_path + "/pdf//" + id  + ".png";
 
-        //图片压缩后的地址
-        UUID uuid = UUID.randomUUID();
-        String compressImgPath = file_path + "/print//" + uuid + ".png";
-
-        String pdfPath = file_path + "/pdf//" + "1751795857679712265" + ".pdf";
-        String excelPath = file_path + "/pdf//" + uuid + ".xlsx";
+        String pdfPath = file_path + "/print//" + "1751795857679712265" + ".pdf";
+        String excelPath = file_path + "/pdf//" + id + ".xlsx";
 
         File tabPdf = ResourceUtil.getFile(pdfPath);
         if (tabPdf.exists()) {
@@ -155,9 +171,18 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
         FileOutputStream outputStream = new FileOutputStream(excelPath);
         workbook.write(outputStream);
         FileUtils.excelToPdf(excelPath, pdfPath);
-        FileUtils.compressImage(localImgPath,compressImgPath, spr.getWide(),spr.getHigh());
+        if(ObjectUtil.isEmpty(file1)){
+            InputStream inputStreamByUrl2 = FileUtils.getInputStreamByUrl(vo.getFileStr());
+            FileUtils.compressImage(inputStreamByUrl2,compressImgPath, wide,high);
+        }else {
+            FileUtils.compressImage(file1.getInputStream(),compressImgPath, wide,high);
+        }
         PdfAddimgUtil.pdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath);
         //压缩后的图片上传oss
-        return R.data(FileUtils.getNetUrl(pdfPath));
+        SignPfxFilePreVo signPfxFilePreVo = new SignPfxFilePreVo();
+        signPfxFilePreVo.setWide(wide);
+        signPfxFilePreVo.setHigh(high);
+        signPfxFilePreVo.setPreUrl(FileUtils.getNetUrl(pdfPath));
+        return R.data(signPfxFilePreVo);
     }
 }

+ 6 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

@@ -31,8 +31,6 @@ import org.springblade.manager.mapper.WbsTreePrivateMapper;
 import org.springblade.manager.service.ITextdictInfoService;
 import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.vo.TextdictInfoVO;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -69,8 +67,12 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                     for(Element ek:table){
                         dqid.addAll(Func.toStrList("\\|\\|",ek.attr("dqid")));
                     }
-                    if(textdictInfo.getShowType() == 1){
-                        textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
+                    if(Func.isNotEmpty(textdictInfo.getShowType()) && textdictInfo.getShowType() == 1){
+                        if(Func.isNotEmpty(dqid) && dqid.size() > 0){
+                            textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
+                        }else {
+                            textdict = new ArrayList<>();
+                        }
                     }else{
                         textdict = baseMapper.selectTextdictInfoByExcelId(page, textdictInfo);
                     }

+ 10 - 8
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -31,7 +31,6 @@ import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.node.ForestNodeMerger;
-import org.springblade.core.tool.support.Try;
 import org.springblade.core.tool.utils.*;
 import org.springblade.manager.bean.NodeVO;
 import org.springblade.manager.dto.*;
@@ -57,11 +56,14 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.*;
-import java.util.concurrent.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -973,7 +975,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
     @Override
     public boolean syncContractTabSort(String projectId) {
         if (ObjectUtil.isNotEmpty(projectId)) {
-            List<WbsTreePrivate> tabs = jdbcTemplate.query("select id,sort from m_wbs_tree_private where is_deleted = 0 and sort is not null and wbs_type = 1 and project_id = " + projectId, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+            List<WbsTreePrivate> tabs = jdbcTemplate.query("select id,p_key_id,sort from m_wbs_tree_private where is_deleted = 0 and sort is not null and wbs_type = 1 and project_id = " + projectId, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
             List<ContractInfo> contractInfos = jdbcTemplate.query("select id from m_contract_info where is_deleted = 0 and contract_type = 1 and p_id = " + projectId, new BeanPropertyRowMapper<>(ContractInfo.class));
             for (ContractInfo contractInfo : contractInfos) {
                 for (List<WbsTreePrivate> wbsTreePrivates : Lists.partition(tabs, 1000)) {
@@ -1149,13 +1151,13 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
      * @param contractId      合同段id
      */
     private void batchUpdateData(List<WbsTreePrivate> wbsTreePrivates, Long contractId) {
-        StringBuilder updateSqlBuilder = new StringBuilder("UPDATE m_wbs_tree_contract SET sort = CASE id ");
+        StringBuilder updateSqlBuilder = new StringBuilder("UPDATE m_wbs_tree_contract SET sort = CASE is_type_private_pid ");
         for (WbsTreePrivate wbsTreePrivate : wbsTreePrivates) {
-            updateSqlBuilder.append("WHEN ").append(wbsTreePrivate.getId()).append(" THEN ").append(wbsTreePrivate.getSort()).append(" ");
+            updateSqlBuilder.append("WHEN ").append(wbsTreePrivate.getPKeyId()).append(" THEN ").append(wbsTreePrivate.getSort()).append(" ");
         }
-        updateSqlBuilder.append("END WHERE id IN (");
+        updateSqlBuilder.append("END WHERE is_type_private_pid IN (");
         for (WbsTreePrivate wbsTreePrivate : wbsTreePrivates) {
-            updateSqlBuilder.append(wbsTreePrivate.getId()).append(",");
+            updateSqlBuilder.append(wbsTreePrivate.getPKeyId()).append(",");
         }
         updateSqlBuilder.deleteCharAt(updateSqlBuilder.length() - 1); //删除最后一个逗号
         updateSqlBuilder.append(") AND contract_id = ").append(contractId);

+ 75 - 10
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/FileUtils.java

@@ -36,6 +36,7 @@ import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.IoUtil;
 import org.springblade.core.tool.utils.ResourceUtil;
 import org.springblade.system.cache.ParamCache;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
@@ -328,6 +329,65 @@ public class FileUtils {
         // 保存缩放后的图片
         ImageIO.write(resizedImage, getFormat(sourceImagePath), new File(targetImagePath));
     }
+    public static void compressImage(InputStream inputStream, String targetImagePath, double maxWidth, double maxHeight) throws Exception {
+        // 读取源图片
+        BufferedImage originalImage = ImageIO.read(inputStream);
+        // 给定的目标宽度和高度
+        int targetWidth = (int)Math.round(maxWidth); // 目标宽度
+        int targetHeight = (int)Math.round(maxHeight); // 目标高度
+        // 创建新的图片对象
+        BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, originalImage.getType());
+        // 使用 Graphics2D 进行绘制
+        Graphics2D g2d = resizedImage.createGraphics();
+        g2d.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
+        g2d.dispose();
+        // 保存缩放后的图片
+        ImageIO.write(resizedImage, "png", new File(targetImagePath));
+    }
+
+    /**
+     * 获取图片的宽度
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    public static Integer getImageWidth(MultipartFile file) throws IOException {
+        try (InputStream is = file.getInputStream()) {
+            BufferedImage image = ImageIO.read(is);
+            return image.getWidth();
+        }
+    }
+
+    /**
+     * 传入流获取图片的高度和宽度
+     * @param is
+     * @return
+     * @throws IOException
+     */
+    public static Map getImageSize(InputStream is) throws IOException {
+            BufferedImage image = ImageIO.read(is);
+        int width = image.getWidth();
+        int height = image.getHeight();
+        HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
+        stringIntegerHashMap.put("width", width);
+        stringIntegerHashMap.put("height", height);
+        return stringIntegerHashMap;
+
+    }
+
+    /**
+     * 获取图片的高度
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    public static Integer getImageHeight(MultipartFile file) throws IOException {
+        try (InputStream is = file.getInputStream()) {
+            BufferedImage image = ImageIO.read(is);
+            return image.getHeight();
+        }
+    }
+
 
     /**
      * 获取图片格式
@@ -446,15 +506,14 @@ public class FileUtils {
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         String file_path2 = getSysLocalFileUrl();
         String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
-        if(fileUrl.indexOf("/www/wwwroot")>=0){
+        String sys_isonline = ParamCache.getValue(CommonConstant.SYS_ISONLINE);
+
+        if (fileUrl.indexOf("aliyuncs.com") >= 0) {
+            return fileUrl;
+        }else {
             file_path2 = file_path;
         }
-//        File file = new File(fileUrl);
-//
-//        if(file.exists()){
-//            //存在
-//            return fileUrl;
-//        }
+
        String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path2, "");
         return path;
     }
@@ -463,15 +522,21 @@ public class FileUtils {
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         String sys_isonline = ParamCache.getValue(CommonConstant.SYS_ISONLINE);
 
-        if(sys_isonline.equals("3")){ //正式环境
+        if(sys_isonline.equals("1")){ //正式环境
             if (SystemUtils.isMacOs()) {
-                file_path = "/Users/hongchuangyanfa/Desktop/";
+                file_path = "/www/wwwroot/Users/hongchuangyanfa/Desktop";
             } else if (SystemUtils.isWindows()) {
                 file_path = "C://upload//";
             }
         }else if(sys_isonline.equals("2")){ //109测试环境
             if (SystemUtils.isMacOs()) {
-                file_path = "/Users/hongchuangyanfa/Desktop/";
+                file_path = "/www/wwwroot/Users/hongchuangyanfa/Desktop/";
+            } else if (SystemUtils.isWindows()) {
+                file_path = "C://upload//";
+            }
+        }else if(sys_isonline.equals("20")){ //109测试环境
+            if (SystemUtils.isMacOs()) {
+                file_path = "/home/www/wwwroot/Users/hongchuangyanfa/Desktop/";
             } else if (SystemUtils.isWindows()) {
                 file_path = "C://upload//";
             }