Commit 95612579 authored by ZWT's avatar ZWT

feat(能源管理系统): 修改架构

1.修改架构添加cse;
2.修改各微服务服务名,启动验证,完成cse注册;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent f58bfbf8
package pps.core.common.pdf; package pps.core.common.pdf;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Map;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.BaseFont;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.xhtmlrenderer.pdf.ITextFontResolver; import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer; import org.xhtmlrenderer.pdf.ITextRenderer;
import sun.misc.BASE64Decoder; import sun.misc.BASE64Decoder;
import java.io.*;
import java.util.Map;
public class Html2Pdf { public class Html2Pdf {
public static String htmlTopdf(String htmlContent ,String fontPath) throws Exception { public static String htmlTopdf(String htmlContent, String fontPath) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = null; ByteArrayOutputStream byteArrayOutputStream = null;
InputStream sbs = null; InputStream sbs = null;
try{ try {
byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer(); ITextRenderer renderer = new ITextRenderer();
ITextFontResolver font = renderer.getFontResolver(); ITextFontResolver font = renderer.getFontResolver();
...@@ -28,12 +22,12 @@ public class Html2Pdf { ...@@ -28,12 +22,12 @@ public class Html2Pdf {
renderer.layout(); renderer.layout();
renderer.createPDF(byteArrayOutputStream); renderer.createPDF(byteArrayOutputStream);
renderer.finishPDF(); renderer.finishPDF();
byte[] buffer =byteArrayOutputStream.toByteArray(); byte[] buffer = byteArrayOutputStream.toByteArray();
sbs = new ByteArrayInputStream(buffer); sbs = new ByteArrayInputStream(buffer);
return getBase64FromInputStream(sbs); return getBase64FromInputStream(sbs);
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
if (byteArrayOutputStream != null) { if (byteArrayOutputStream != null) {
try { try {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
...@@ -49,7 +43,8 @@ public class Html2Pdf { ...@@ -49,7 +43,8 @@ public class Html2Pdf {
} }
return null; return null;
} }
public static byte[] htmlToPdfByte(String htmlContent ,String fontPath){
public static byte[] htmlToPdfByte(String htmlContent, String fontPath) {
ByteArrayOutputStream byteArrayOutputStream = null; ByteArrayOutputStream byteArrayOutputStream = null;
try { try {
byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream = new ByteArrayOutputStream();
...@@ -60,9 +55,9 @@ public class Html2Pdf { ...@@ -60,9 +55,9 @@ public class Html2Pdf {
renderer.layout(); renderer.layout();
renderer.createPDF(byteArrayOutputStream); renderer.createPDF(byteArrayOutputStream);
renderer.finishPDF(); renderer.finishPDF();
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
if (byteArrayOutputStream != null) { if (byteArrayOutputStream != null) {
try { try {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
...@@ -72,6 +67,7 @@ public class Html2Pdf { ...@@ -72,6 +67,7 @@ public class Html2Pdf {
} }
return byteArrayOutputStream.toByteArray(); return byteArrayOutputStream.toByteArray();
} }
public static String getBase64FromInputStream(InputStream in) { public static String getBase64FromInputStream(InputStream in) {
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 // 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
byte[] data = null; byte[] data = null;
...@@ -99,37 +95,35 @@ public class Html2Pdf { ...@@ -99,37 +95,35 @@ public class Html2Pdf {
} }
public static void saveBase64strToFile(String base64str , String outPath){ public static void saveBase64strToFile(String base64str, String outPath) {
createFile(new File(outPath)); createFile(new File(outPath));
if (base64str == null){ if (base64str == null) {
return ; return;
} }
BASE64Decoder decoder = new BASE64Decoder(); BASE64Decoder decoder = new BASE64Decoder();
try try {
{
byte[] b = decoder.decodeBuffer(base64str); byte[] b = decoder.decodeBuffer(base64str);
for(int i=0;i<b.length;++i) for (int i = 0; i < b.length; ++i) {
{ if (b[i] < 0) {
if(b[i]<0){ b[i] += 256;
b[i]+=256;
} }
} }
OutputStream out = new FileOutputStream(outPath); OutputStream out = new FileOutputStream(outPath);
out.write(b); out.write(b);
out.flush(); out.flush();
out.close(); out.close();
} } catch (Exception e) {
catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
} }
public static String replaceContent(String htmlContent , Map<String,String> map){ public static String replaceContent(String htmlContent, Map<String, String> map) {
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
htmlContent = htmlContent.replaceAll(entry.getKey() , entry.getValue()); htmlContent = htmlContent.replaceAll(entry.getKey(), entry.getValue());
} }
return htmlContent; return htmlContent;
} }
public static void createFile(File file) { public static void createFile(File file) {
if (file.exists()) { if (file.exists()) {
System.out.println("File exists"); System.out.println("File exists");
...@@ -150,21 +144,21 @@ public class Html2Pdf { ...@@ -150,21 +144,21 @@ public class Html2Pdf {
} }
} }
public static void outFile(InputStream input , String outPath){ public static void outFile(InputStream input, String outPath) {
createFile(new File(outPath)); createFile(new File(outPath));
BufferedInputStream in=null; BufferedInputStream in = null;
BufferedOutputStream out=null; BufferedOutputStream out = null;
try { try {
in=new BufferedInputStream(input); in = new BufferedInputStream(input);
out=new BufferedOutputStream(new FileOutputStream(outPath)); out = new BufferedOutputStream(new FileOutputStream(outPath));
int len=-1; int len = -1;
byte[] b=new byte[1024]; byte[] b = new byte[1024];
while((len=in.read(b))!=-1){ while ((len = in.read(b)) != -1) {
out.write(b,0,len); out.write(b, 0, len);
} }
in.close(); in.close();
out.close(); out.close();
}catch (Exception e){ } catch (Exception e) {
} }
} }
......
...@@ -54,15 +54,15 @@ ...@@ -54,15 +54,15 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.70</version> <version>2.0.32</version>
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>gf</groupId>--> <!-- <groupId>gf</groupId>-->
<!-- <artifactId>fiybook-cloud</artifactId>--> <!-- <artifactId>fiybook-cloud</artifactId>-->
<!-- <version>1.0.0-pps</version>--> <!-- <version>1.0.0-pps</version>-->
<!-- <scope>compile</scope>--> <!-- <scope>compile</scope>-->
<!-- </dependency>--> <!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
...@@ -112,5 +112,10 @@ ...@@ -112,5 +112,10 @@
<enabled>true</enabled> <enabled>true</enabled>
</releases> </releases>
</repository> </repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories> </repositories>
</project> </project>
...@@ -33,8 +33,8 @@ public class DeployPpsPredictionApplication { ...@@ -33,8 +33,8 @@ public class DeployPpsPredictionApplication {
startup.enable(XRpcFeature.class); startup.enable(XRpcFeature.class);
startup.enable(XCloudHuaweiCseFeature.class) startup.enable(XCloudHuaweiCseFeature.class)
.config(XCloudBundlesConf.with( .config(XCloudBundlesConf.with(
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "system"), XCloudBundle.naming("pps-system").addModule("pps", "cloud", "system"),
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "base"), XCloudBundle.naming("pps-base").addModule("pps", "cloud", "base"),
XCloudBundle.naming("pps-space").addModule("pps", "cloud", "space") XCloudBundle.naming("pps-space").addModule("pps", "cloud", "space")
)); ));
startup.run(args); startup.run(args);
......
...@@ -33,8 +33,8 @@ public class DeployPpsSpaceApplication { ...@@ -33,8 +33,8 @@ public class DeployPpsSpaceApplication {
startup.enable(XRpcFeature.class); startup.enable(XRpcFeature.class);
startup.enable(XCloudHuaweiCseFeature.class) startup.enable(XCloudHuaweiCseFeature.class)
.config(XCloudBundlesConf.with( .config(XCloudBundlesConf.with(
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "base"), XCloudBundle.naming("pps-base").addModule("pps", "cloud", "base"),
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "system"), XCloudBundle.naming("pps-system").addModule("pps", "cloud", "system"),
XCloudBundle.naming("pps-prediction").addModule("pps", "cloud", "prediction") XCloudBundle.naming("pps-prediction").addModule("pps", "cloud", "prediction")
) )
); );
......
...@@ -24,7 +24,7 @@ public class DeployPpsSystemApplication { ...@@ -24,7 +24,7 @@ public class DeployPpsSystemApplication {
public static void main(String... args) { public static void main(String... args) {
CounterBuilder.globalCounterBuilder.setFieldValue(CounterBuilder.DEPLOY_KEY, DeployPpsSystemApplication.class.getSimpleName()); CounterBuilder.globalCounterBuilder.setFieldValue(CounterBuilder.DEPLOY_KEY, DeployPpsSystemApplication.class.getSimpleName());
XStartup startup = new XStartupApplication("pps"); XStartup startup = new XStartupApplication("pps");
startup.config(new XServerConf(22061).naming("pps-base-info")) startup.config(new XServerConf(22061).naming("pps-system"))
.config(new XServiceConf("pps")); .config(new XServiceConf("pps"));
startup.enable(XApiFeature.class) startup.enable(XApiFeature.class)
.config(new XApiCookieConf("%4bH8s9&", 43200)); .config(new XApiCookieConf("%4bH8s9&", 43200));
......
...@@ -43,8 +43,8 @@ public class DeployPpsTaskApplication { ...@@ -43,8 +43,8 @@ public class DeployPpsTaskApplication {
startup.enable(XRpcFeature.class); startup.enable(XRpcFeature.class);
startup.enable(XCloudHuaweiCseFeature.class) startup.enable(XCloudHuaweiCseFeature.class)
.config(XCloudBundlesConf.with( .config(XCloudBundlesConf.with(
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "system"), XCloudBundle.naming("pps-system").addModule("pps", "cloud", "system"),
XCloudBundle.naming("pps-base-info").addModule("pps", "cloud", "base"), XCloudBundle.naming("pps-base").addModule("pps", "cloud", "base"),
XCloudBundle.naming("pps-prediction").addModule("pps", "cloud", "prediction"), XCloudBundle.naming("pps-prediction").addModule("pps", "cloud", "prediction"),
XCloudBundle.naming("pps-space").addModule("pps", "cloud", "space") XCloudBundle.naming("pps-space").addModule("pps", "cloud", "space")
)); ));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment