代码说明
This commit is contained in:
15
pom.xml
15
pom.xml
@ -65,6 +65,21 @@
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.55</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itext7-core</artifactId>
|
||||
<version>7.2.5</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
<!-- 亚洲字体包(必需!) -->
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>font-asian</artifactId>
|
||||
<version>7.2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -30,7 +30,7 @@ public class Reward {
|
||||
lock.lock();
|
||||
try {
|
||||
JSONObject dataa = rewards.getJSONObject("data");
|
||||
log.info("奖励数据 "+ rewards.toJSONString());
|
||||
log.info(dataa.toJSONString());
|
||||
String id = dataa.getString("id");
|
||||
String timeConversionS = dataa.getString("shangcheheyanriqi");
|
||||
String timeConversion = TimeUtil.timeConversions(timeConversionS);
|
||||
@ -105,9 +105,7 @@ public class Reward {
|
||||
|
||||
JSONObject widget1708503246372 = test.getJSONObject("_widget_1708503246372");
|
||||
if (widget1708503246372 != null) {
|
||||
|
||||
fs_p1 = widget1708503246372.getString("name");
|
||||
log.info("有问题的数据==============" + fs_p1 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,15 +120,10 @@ public class Reward {
|
||||
real_name = test1.getString("real_name");
|
||||
id_card3331 = test1.getString("id_card");
|
||||
}
|
||||
log.info("f_user_id++++++ " + f_user_id);
|
||||
|
||||
|
||||
String flag = "";
|
||||
|
||||
|
||||
// 奖励1
|
||||
if (!f_user_id.equals("0") && !f_user_id.isEmpty() && f_user_id != null) {
|
||||
flag = "A";
|
||||
JSONObject jiangli = new JSONObject();
|
||||
jiangli.put("app_id", "65815f117de49256b1e67e75");
|
||||
jiangli.put("entry_id", "658fce1d771e971c5816e475");
|
||||
@ -468,11 +461,12 @@ public class Reward {
|
||||
}
|
||||
|
||||
|
||||
flag = "完成";
|
||||
|
||||
|
||||
}
|
||||
// 奖励2
|
||||
if (f_user_idS != null && !f_user_idS.isEmpty() && !f_user_idS.equals("0") && flag.equals("A")) {
|
||||
if (!f_user_idS.equals("0") && !f_user_idS.isEmpty() && f_user_idS != null && flag.equals("完成")) {
|
||||
|
||||
JSONObject jsonObject22 = new JSONObject();
|
||||
jsonObject22.put("app_id", "65815f117de49256b1e67e75");
|
||||
|
||||
@ -4,59 +4,154 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.example.sso.dao.QianDuan;
|
||||
import com.example.sso.util.TimeUtil;
|
||||
import com.itextpdf.io.image.ImageData;
|
||||
import com.itextpdf.io.image.ImageDataFactory;
|
||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.element.Image;
|
||||
import com.itextpdf.layout.element.Paragraph;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@Slf4j
|
||||
public class C {
|
||||
public static void main(String[] args) {{
|
||||
JSONObject jsonObject = QianDuan.i();
|
||||
Integer i = jsonObject.getInteger("integer");
|
||||
String id = jsonObject.getString("id");
|
||||
i += 1;
|
||||
Integer max = QianDuan.max();
|
||||
JSONArray fou = QianDuan.fou();
|
||||
log.info("c俄式" + i + id +max );
|
||||
for (Object o : fou) {
|
||||
JSONObject test = (JSONObject) o;
|
||||
Integer xuhao = test.getInteger("xuhao");
|
||||
if (i == xuhao) {
|
||||
i += 1;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
C.createPdfWithTextAndImage("D:\\下载模板\\a.pdf","a","D:\\下载模板\\OIP-C.jpg");
|
||||
}
|
||||
|
||||
|
||||
public static void createPdfWithTextAndImage(String pdfPath, String text, String imagePath) {
|
||||
try {
|
||||
// 1. 创建PdfWriter和PdfDocument
|
||||
PdfWriter writer = new PdfWriter(pdfPath);
|
||||
PdfDocument pdfDoc = new PdfDocument(writer);
|
||||
Document document = new Document(pdfDoc);
|
||||
|
||||
// 2. 添加文字内容
|
||||
document.add(new Paragraph("文档标题")
|
||||
.setFontSize(20)
|
||||
.setBold());
|
||||
|
||||
// 添加多段落文字
|
||||
String[] paragraphs = text.split("\n");
|
||||
for (String para : paragraphs) {
|
||||
document.add(new Paragraph(para)
|
||||
.setFontSize(12)
|
||||
.setMarginBottom(10));
|
||||
}
|
||||
|
||||
// 3. 添加图片
|
||||
if (imagePath != null && new File(imagePath).exists()) {
|
||||
// 加载图片
|
||||
ImageData imageData = ImageDataFactory.create(imagePath);
|
||||
Image image = new Image(imageData);
|
||||
|
||||
// 设置图片属性
|
||||
image.setAutoScale(true); // 自动缩放
|
||||
image.setHorizontalAlignment(com.itextpdf.layout.properties.HorizontalAlignment.CENTER);
|
||||
image.setMarginTop(20);
|
||||
image.setMarginBottom(20);
|
||||
|
||||
document.add(image);
|
||||
document.add(new Paragraph("图片说明")
|
||||
.setFontSize(10)
|
||||
.setItalic()
|
||||
.setTextAlignment(com.itextpdf.layout.properties.TextAlignment.CENTER));
|
||||
}
|
||||
|
||||
// 4. 关闭文档
|
||||
document.close();
|
||||
|
||||
System.out.println("PDF创建成功: " + pdfPath);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPdfWithTextAndImagea(String pdfPath, String imagePath) {
|
||||
try {
|
||||
// 1. 创建PdfWriter和PdfDocument
|
||||
PdfWriter writer = new PdfWriter(pdfPath);
|
||||
PdfDocument pdfDoc = new PdfDocument(writer);
|
||||
Document document = new Document(pdfDoc);
|
||||
|
||||
// 2. 添加文字内容
|
||||
document.add(new Paragraph("文档标题")
|
||||
.setFontSize(20)
|
||||
.setBold());
|
||||
|
||||
|
||||
|
||||
// 3. 添加图片
|
||||
if (imagePath != null && new File(imagePath).exists()) {
|
||||
// 加载图片
|
||||
ImageData imageData = ImageDataFactory.create(imagePath);
|
||||
Image image = new Image(imageData);
|
||||
|
||||
// 设置图片属性
|
||||
image.setAutoScale(true); // 自动缩放
|
||||
image.setHorizontalAlignment(com.itextpdf.layout.properties.HorizontalAlignment.CENTER);
|
||||
image.setMarginTop(20);
|
||||
image.setMarginBottom(20);
|
||||
|
||||
document.add(image);
|
||||
document.add(new Paragraph("图片说明")
|
||||
.setFontSize(10)
|
||||
.setItalic()
|
||||
.setTextAlignment(com.itextpdf.layout.properties.TextAlignment.CENTER));
|
||||
}
|
||||
|
||||
// 4. 关闭文档
|
||||
document.close();
|
||||
|
||||
System.out.println("PDF创建成功: " + pdfPath);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createPdfWithTextAndImageb(String pdfPath, String text) {
|
||||
try {
|
||||
// 1. 创建PdfWriter和PdfDocument
|
||||
PdfWriter writer = new PdfWriter(pdfPath);
|
||||
PdfDocument pdfDoc = new PdfDocument(writer);
|
||||
Document document = new Document(pdfDoc);
|
||||
|
||||
// 2. 添加文字内容
|
||||
document.add(new Paragraph("文档标题")
|
||||
.setFontSize(20)
|
||||
.setBold());
|
||||
|
||||
// 添加多段落文字
|
||||
String[] paragraphs = text.split("\n");
|
||||
for (String para : paragraphs) {
|
||||
document.add(new Paragraph(para)
|
||||
.setFontSize(12)
|
||||
.setMarginBottom(10));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 4. 关闭文档
|
||||
document.close();
|
||||
|
||||
System.out.println("PDF创建成功: " + pdfPath);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (i <= max) {
|
||||
JSONArray select = QianDuan.select(i);
|
||||
for (Object o : select ){
|
||||
JSONObject test = (JSONObject) o;
|
||||
String fsName = test.getString("fs_name");
|
||||
Integer integer = test.getJSONObject("fs_user").getInteger("dept_no");
|
||||
QianDuan.insert(id,i,fsName,integer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
JSONArray select = QianDuan.select(1);
|
||||
for (Object o : select ){
|
||||
JSONObject test = (JSONObject) o;
|
||||
String fsName = test.getString("fs_name");
|
||||
Integer integer = test.getJSONObject("fs_user").getInteger("dept_no");
|
||||
QianDuan.insert(id,1,fsName,integer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +1,33 @@
|
||||
package com.example.sso.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class D {
|
||||
public static void main(String[] args) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
String utcTimeString = "2025-07-14T07:56:50.000Z";
|
||||
|
||||
// 获取当前月份
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1; // 月份从 0 开始,所以要加 1
|
||||
// 1. 直接解析为OffsetDateTime
|
||||
OffsetDateTime utcTime = OffsetDateTime.parse(utcTimeString);
|
||||
|
||||
// 格式化为 "YYYY-MM"
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
||||
String formattedMonth = dateFormat.format(calendar.getTime());
|
||||
// 2. 转换为北京时间(UTC+8)
|
||||
ZonedDateTime beijingTime = utcTime.atZoneSameInstant(ZoneId.of("Asia/Shanghai"));
|
||||
|
||||
System.out.println("Current Month: " + formattedMonth);
|
||||
// 3. 格式化输出
|
||||
String formattedTime = beijingTime.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
System.out.println("UTC时间: " + utcTimeString);
|
||||
System.out.println("格式化输出: " + formattedTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
package com.example.sso.test;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.example.sso.dao.Photo;
|
||||
import com.example.sso.dao.ThreeOne;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Q {
|
||||
public static void main(String[] args) {
|
||||
JSONArray array = ThreeOne.array("8613");
|
||||
System.out.println(array);
|
||||
public static void main(String[] args) throws IOException {
|
||||
Photo.startPDF("D:\\下载模板\\a.pdf");
|
||||
Photo.appendTextSection("犯得上反对");
|
||||
Photo.appendImageSection("D:\\下载模板\\OIP-C.jpg");
|
||||
Photo.closePDF();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
package com.example.sso.test;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.example.sso.dao.*;
|
||||
import com.example.sso.util.APIUtils;
|
||||
import com.example.sso.util.TimeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.ParseException;
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class R {
|
||||
// @PostMapping("/reward")
|
||||
|
||||
public String reward(@RequestBody JSONObject rewards) throws ParseException {
|
||||
|
||||
|
||||
|
||||
log.info("奖励数据 "+ rewards.toJSONString());
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -31,9 +31,15 @@ import org.apache.http.util.EntityUtils;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.*;
|
||||
@ -869,6 +875,61 @@ public class APIUtils {
|
||||
}
|
||||
|
||||
|
||||
public static String hkfile(String fileUrl) {
|
||||
String path = "";
|
||||
// String fileUrl = "https://www.jiyuankeshang.com/_/file/get_file?bucket=jdy-file&key=518b56ae-3c68-4c61-bd68-b5eb18427d08&filename=%E6%BC%94%E7%A4%BA%E6%95%B0%E6%8D%AE.xlsx&expires=1742968799&token=Ko7O1AqDnF3mL1LE:r6gj1iTAgv2FTQSUALYf4_-uqSY="; // 替换为你要下载的文件URL
|
||||
String desktopPath = "/home/java/dpapp8090/pdf/";
|
||||
String folderName = "hkfile";
|
||||
// String substringAfterThirdDot = V5utils.getSubstringAfterThirdDot(fileUrl, 3);
|
||||
String substringAfterThirdDot = "";
|
||||
if (fileUrl.contains(".png")) {
|
||||
substringAfterThirdDot = ".png";
|
||||
} else if (fileUrl.contains(".pdf")) {
|
||||
substringAfterThirdDot = ".pdf";
|
||||
} else if (fileUrl.contains(".xlsx")) {
|
||||
substringAfterThirdDot = ".xlsx";
|
||||
}else if (fileUrl.contains(".docx")){
|
||||
substringAfterThirdDot = ".docx";
|
||||
}else if (fileUrl.contains(".jpg")){
|
||||
substringAfterThirdDot = ".jpg";
|
||||
}
|
||||
String uuid = String.valueOf(UUID.randomUUID());
|
||||
String fileName = uuid + substringAfterThirdDot; // 你可以根据URL动态生成文件名
|
||||
|
||||
try {
|
||||
// 创建文件夹路径
|
||||
Path folderPath = Paths.get(desktopPath, folderName);
|
||||
if (!Files.exists(folderPath)) {
|
||||
Files.createDirectories(folderPath);
|
||||
}
|
||||
|
||||
// 创建文件路径
|
||||
Path filePath = folderPath.resolve(fileName);
|
||||
|
||||
|
||||
// 下载文件
|
||||
URL url = new URL(fileUrl);
|
||||
try (BufferedInputStream in = new BufferedInputStream(url.openStream());
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(filePath.toFile())) {
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
||||
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("文件已下载到: " + filePath);
|
||||
path = String.valueOf(filePath);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -4,6 +4,10 @@ import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
@ -131,6 +135,26 @@ public class TimeUtil {
|
||||
}
|
||||
|
||||
|
||||
public static String timss(String utcTimeString) {
|
||||
//String utcTimeString = "2025-07-14T07:56:50.000Z";
|
||||
|
||||
// 1. 直接解析为OffsetDateTime
|
||||
OffsetDateTime utcTime = OffsetDateTime.parse(utcTimeString);
|
||||
|
||||
// 2. 转换为北京时间(UTC+8)
|
||||
ZonedDateTime beijingTime = utcTime.atZoneSameInstant(ZoneId.of("Asia/Shanghai"));
|
||||
|
||||
// 3. 格式化输出
|
||||
String formattedTime = beijingTime.format(
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
);
|
||||
|
||||
System.out.println("UTC时间: " + utcTimeString);
|
||||
System.out.println("格式化输出: " + formattedTime);
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user