Browse Source

诊断程序:一个品牌只能有一个发布版;
维修手册:利用pdf.js适配平板端的查看

bmmx 1 year ago
parent
commit
1c09361721

+ 18 - 7
src/main/java/com/om/service/impl/DiagnosisVersionInfoServiceImpl.java

@@ -303,11 +303,23 @@ public class DiagnosisVersionInfoServiceImpl extends ServiceImpl<DiagnosisVersio
     @Override
     @Override
     public Result release(Integer id) {
     public Result release(Integer id) {
         DiagnosisVersionInfo info = this.getById(id);
         DiagnosisVersionInfo info = this.getById(id);
-        info.setStatus(1);
-        LambdaQueryWrapper<DiagnosisVersionInfo> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(DiagnosisVersionInfo::getId, id);
-        this.update(info, queryWrapper);
-        return Result.ok();
+        String brandCode = info.getBrandCode();
+        DiagnosisVersionInfo diagnosisVersionInfo = this.lambdaQuery()
+                .eq(DiagnosisVersionInfo::getBrandCode, brandCode)
+                .eq(DiagnosisVersionInfo::getStatus, 1)
+                .one();
+
+        if (BeanUtil.isEmpty(diagnosisVersionInfo)){
+            info.setStatus(1);
+            LambdaQueryWrapper<DiagnosisVersionInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(DiagnosisVersionInfo::getId, id);
+            this.update(info, queryWrapper);
+            return Result.ok();
+        }else {
+            throw new BadReqException("一个品牌只能有一个发布版!!");
+        }
+
+
     }
     }
 
 
     @Override
     @Override
@@ -362,14 +374,13 @@ public class DiagnosisVersionInfoServiceImpl extends ServiceImpl<DiagnosisVersio
             List<DiagnosisVersionInfo> diagnosisVersionInfos = this.lambdaQuery()
             List<DiagnosisVersionInfo> diagnosisVersionInfos = this.lambdaQuery()
                     .eq(DiagnosisVersionInfo::getBrandCode, vehicleDates.getBrandCode())
                     .eq(DiagnosisVersionInfo::getBrandCode, vehicleDates.getBrandCode())
                     .eq(user.getUserType() == 0,DiagnosisVersionInfo::getStatus,1)
                     .eq(user.getUserType() == 0,DiagnosisVersionInfo::getStatus,1)
-
                     .eq(user.getUserType() == 1,DiagnosisVersionInfo::getStatus,0)
                     .eq(user.getUserType() == 1,DiagnosisVersionInfo::getStatus,0)
                     .apply("CONCAT(',', client_number, ',') LIKE {0}", "%,"+clientNum+",%")
                     .apply("CONCAT(',', client_number, ',') LIKE {0}", "%,"+clientNum+",%")
                     .gt(StringUtils.isNotBlank(version),DiagnosisVersionInfo::getVersion, version)
                     .gt(StringUtils.isNotBlank(version),DiagnosisVersionInfo::getVersion, version)
                     .orderByDesc(DiagnosisVersionInfo::getVersion)
                     .orderByDesc(DiagnosisVersionInfo::getVersion)
                     .list();
                     .list();
             if(CollectionUtil.isEmpty(diagnosisVersionInfos)){
             if(CollectionUtil.isEmpty(diagnosisVersionInfos)){
-                return Result.fail("没有可用的诊断程序更新");
+               continue;
             }
             }
             DiagnosisVersionInfo diagnosisVersionInfo = diagnosisVersionInfos.get(0);
             DiagnosisVersionInfo diagnosisVersionInfo = diagnosisVersionInfos.get(0);
             //根据品牌id查询品牌
             //根据品牌id查询品牌

+ 13 - 0
src/main/java/com/om/service/impl/WxscServiceImpl.java

@@ -27,6 +27,8 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
 import java.time.ZoneOffset;
 import java.time.ZoneOffset;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
@@ -44,6 +46,10 @@ public class WxscServiceImpl extends ServiceImpl<WxscMapper, Wxsc> implements IW
   private final WxscMapper wxscMapper;
   private final WxscMapper wxscMapper;
     @Autowired
     @Autowired
     private BrandMapper brandMapper;
     private BrandMapper brandMapper;
+    @Autowired
+    private HtmlGenerator htmlGenerator;
+    @Autowired
+    private HuaweiObsUtil huaweiObsUtil;
 
 
     public WxscServiceImpl(WxscMapper wxscMapper) {
     public WxscServiceImpl(WxscMapper wxscMapper) {
     this.wxscMapper = wxscMapper;
     this.wxscMapper = wxscMapper;
@@ -140,6 +146,13 @@ public class WxscServiceImpl extends ServiceImpl<WxscMapper, Wxsc> implements IW
         if (BeanUtil.isEmpty(wxsc)){
         if (BeanUtil.isEmpty(wxsc)){
             throw new BadReqException("该维修资料不存在!");
             throw new BadReqException("该维修资料不存在!");
         }
         }
+        File file = htmlGenerator.ziliaoHtml(wxsc.getTitle(), wxsc.getFileUrl(), wxsc.getId());
+        try {
+            String ziliao = huaweiObsUtil.upload(file, "ziliao");
+            wxsc.setFileUrl(ziliao);
+        } catch (IOException e) {
+            throw new BizException("上传失败");
+        }
         return Result.ok(wxsc);
         return Result.ok(wxsc);
     }
     }
 
 

+ 18 - 30
src/main/java/com/om/utils/HtmlGenerator.java

@@ -60,47 +60,35 @@ public class HtmlGenerator {
     }
     }
 
 
 
 
+    public  File ziliaoHtml(String title,String pdfUrl,Integer id){
 
 
-
-    public static void main(String[] args) {
-        // 初始化Velocity引擎
-        Properties properties = new Properties();
-        properties.setProperty("resource.loader", "class");
-        properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
-        VelocityEngine velocityEngine = new VelocityEngine(properties);
-
-        // 创建Velocity上下文,并设置变量
-        VelocityContext context = new VelocityContext();
-        context.put("title", "PDFzzzz");
-        context.put("pdfUrl", "https://wl-resource.obs.cn-south-1.myhuaweicloud.com:443/ziliao/%E8%AF%8A%E6%96%AD%E4%BB%AA%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E4%B9%A6%20-%20%E6%97%A5%E6%96%87.pdf?AccessKeyId=FL8POSPAPQDTW42RL8SN&Expires=2094028867&Signature=HmE4BxnLD849gQKWqRBE7I8Nx%2Fg%3D");
-
-        // 加载Velocity模板
-        StringWriter writer = new StringWriter();
-        velocityEngine.mergeTemplate("template/static/ziliao.html", "UTF-8", context, writer);
-
-        // 输出渲染后的HTML到控制台
-        String htmlContent = writer.toString();
-        System.out.println(htmlContent);
-
-        // 生成HTML文件
         try {
         try {
-            // 获取当前日期以创建文件夹
-            String yyyyMMdd = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
-            String baseStatic = "path/to/output/directory/"; // 更新为实际的输出目录
-            String outputPath = baseStatic + yyyyMMdd + "outputH5.html";
+            Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
+            cfg.setClassForTemplateLoading(OperationApplication.class, "../../template/static/");
 
 
-            // 创建文件并写入内容
-            File file = new File(outputPath);
-            FileWriter fileWriter = new FileWriter(file);
+            Template template = cfg.getTemplate("ziliao.html");
+            StringWriter out = new StringWriter();
+            Map<String, Object> data = new HashMap<>();
+            data.put("title",title);
+            data.put("pdfUrl", pdfUrl);
+            template.process(data, out);
+
+            // 将HTML内容写入文件
+            String htmlContent = out.toString();
+            String outputPath = baseStatic+"ziliao"+id+".html";
+            FileWriter fileWriter = new FileWriter(outputPath);
             fileWriter.write(htmlContent);
             fileWriter.write(htmlContent);
+            File file = new File(baseStatic+"ziliao"+id+".html");
             fileWriter.close();
             fileWriter.close();
-
             System.out.println("HTML文件已生成:" + outputPath);
             System.out.println("HTML文件已生成:" + outputPath);
+            return file;
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
+        return null;
     }
     }
 
 
 
 
 
 
+
 }
 }

+ 1 - 1
src/main/resources/template/static/report.html

@@ -432,7 +432,7 @@
         var input = document.getElementById(field);
         var input = document.getElementById(field);
         var id = ${id};
         var id = ${id};
 
 
-        axios.post('http://47.113.197.148:8888/app/diagnosis/report/updateCompany', {
+        axios.post('http://116.205.227.91:8888/app/diagnosis/report/updateCompany', {
             id: id,
             id: id,
             type: field,
             type: field,
             value: value,
             value: value,

+ 2 - 2
src/main/resources/template/static/ziliao.html

@@ -3,7 +3,7 @@
 <head>
 <head>
     <meta charset="UTF-8">
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>$title</title>
+    <title>${title}</title>
     <style>
     <style>
         #pdf-container {
         #pdf-container {
             width: 100%;
             width: 100%;
@@ -29,7 +29,7 @@
     pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.worker.min.js';
     pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.worker.min.js';
 
 
     // PDF文件URL
     // PDF文件URL
-    const url = '$pdfUrl';
+    const url = `${pdfUrl}`;
 
 
     pdfjsLib.getDocument(url).promise.then(function(pdfDoc) {
     pdfjsLib.getDocument(url).promise.then(function(pdfDoc) {
         const pdfContainer = document.getElementById('pdf-container');
         const pdfContainer = document.getElementById('pdf-container');