Commit d5c9239f authored by Allen Chen's avatar Allen Chen

commit

parent a23b40bd
......@@ -6,7 +6,7 @@ public class YJTConfig {
public static final String CLIENT_ID = "8f5f3f9c92e847b2894fc1c0afce3d62";
public static final String CLIENT_SECRET = "281d79ad5117d20a35efb9e7b0d5f7ee436399b0";
// 基础API地址
public static final String URL = "https://xxxx";
public static final String URL = "https://jy.ckexp.com/api/pdd_cs/order.php";
}
package org.ta.pddserver.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("package_detail")
public class PackageDetailEntity {
@TableId(value = "uid")
private String uid;
@TableField(value = "created")
private String created;
@TableField(value = "orderCode")
private String orderCode;
/**
* 运单号(必填)
*/
@TableField(value = "mailNo")
private String mailNo;
/**
* 状态 长
*/
@TableField(value = "length")
private Integer length;
/**
* 状态 宽
*/
@TableField(value = "width")
private Integer width;
/**
* 状态 高
*/
@TableField(value = "height")
private Integer height;
/**
* 状态 重
*/
@TableField(value = "weight")
private Integer weight;
@TableField(value = "packageType")
private String packageType;
@TableField(value = "inMails")
private String inMails;
@TableField(value = "orderType")
private String orderType;
}
......@@ -55,115 +55,4 @@ public class UnpackNoticeEntity {
@TableField(value = "num")
private Integer num;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getUpdated() {
return updated;
}
public void setUpdated(String updated) {
this.updated = updated;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getBuyerCode() {
return buyerCode;
}
public void setBuyerCode(String buyerCode) {
this.buyerCode = buyerCode;
}
public String getConsoType() {
return consoType;
}
public void setConsoType(String consoType) {
this.consoType = consoType;
}
public String getConsoWarehouseCode() {
return consoWarehouseCode;
}
public void setConsoWarehouseCode(String consoWarehouseCode) {
this.consoWarehouseCode = consoWarehouseCode;
}
public String getDeliveryType() {
return deliveryType;
}
public void setDeliveryType(String deliveryType) {
this.deliveryType = deliveryType;
}
public String getProviderCode() {
return providerCode;
}
public void setProviderCode(String providerCode) {
this.providerCode = providerCode;
}
public String getOrderCode() {
return orderCode;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
public String getMailDetails() {
return mailDetails;
}
public void setMailDetails(String mailDetails) {
this.mailDetails = mailDetails;
}
public String getReceiverDetail() {
return receiverDetail;
}
public void setReceiverDetail(String receiverDetail) {
this.receiverDetail = receiverDetail;
}
}
......@@ -13,13 +13,10 @@ import java.io.ByteArrayOutputStream;
public class ImagePdfCollectGenerator {
public static byte[] generatePdfWithCollectTextImage(String orderCode) {
public static byte[] generatePdfWithCollectTextImage(String orderCode, String typeText, String numText) {
try {
// 1. 将文字转为图片(示例:韩文“안녕하세요,世界!”)
byte[] imageBytes = TextToImageCollectUtils.textToImage(
orderCode
);
byte[] imageBytes = TextToImageUtils.commonBarCodeAndTextToImage(orderCode, typeText, numText);
// return imageBytes;
......@@ -39,7 +36,7 @@ public class ImagePdfCollectGenerator {
// 4. 关闭文档
document.close();
return pdfBaos.toByteArray();
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
return null;
}
......@@ -54,11 +51,11 @@ public class ImagePdfCollectGenerator {
// 2. 初始化PDF
Document document = new Document(pdfDoc, new PageSize((int) (150 * 300 / 25.4), (int) (100 * 300 / 25.4)));
for (int i = 1; i < 10; i ++) {
for (int i1 = 1; i1 < 12; i1 ++) {
for (int i2 = 1; i2 < 5; i2 ++) {
for (int i3 = 1; i3 < 3; i3 ++) {
if (i3 == 2 && (i2 == 1|| i2 == 4)) {
for (int i = 1; i < 10; i++) {
for (int i1 = 1; i1 < 12; i1++) {
for (int i2 = 1; i2 < 5; i2++) {
for (int i3 = 1; i3 < 3; i3++) {
if (i3 == 2 && (i2 == 1 || i2 == 4)) {
continue;
}
// 1. 将文字转为图片(示例:韩文“안녕하세요,世界!”)
......@@ -75,7 +72,6 @@ public class ImagePdfCollectGenerator {
}
}
......
......@@ -71,6 +71,30 @@ public class ImagePdfGenerator {
}
}
public static byte[] generateCollectCodeLabel(String code) throws Exception {
ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(pdfBaos);
PdfDocument pdfDoc = new PdfDocument(writer);
// 2. 初始化PDF
Document document = new Document(pdfDoc, new PageSize((int) (150 * 300 / 25.4), (int) (100 * 300 / 25.4)));
// 1. 将文字转为图片(示例:韩文“안녕하세요,世界!”)
byte[] imageBytes = TextToImageUtils.commonBarCodeToImage(code);
// 3. 将图片嵌入PDF
ImageData imageData = ImageDataFactory.create(imageBytes);
Image image = new Image(imageData);
// 设置图片在PDF中居中显示
image.setHorizontalAlignment(HorizontalAlignment.LEFT);
document.add(image);
// 4. 关闭文档
document.close();
return pdfBaos.toByteArray();
}
public static byte[] generateCode() throws Exception {
ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();
......
......@@ -170,6 +170,59 @@ public class TextToImageUtils {
return mailCode.substring(0, 4) + "-" + mailCode.substring(4, 8) + "-" + mailCode.substring(8, 12);
}
public static byte[] commonBarCodeAndTextToImage( String mailCode, String typeText, String numText
) throws Exception {
int width = 1770;
int height = 1180;
int startX = 0;
int startY = 0;
// 1. 创建 BufferedImage 作为画布
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
System.out.println("width = " + width + ", height = " + height);
Graphics2D g2d = image.createGraphics();
// 设置绘图属性(抗锯齿、渲染质量等)
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // 文字抗锯齿
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); // 文字平滑
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // 渲染质量
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 2. 设置背景为白色
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
g2d.setColor(Color.BLACK);
// 集运单号
Font font0 = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("./zh-gb.ttf")).deriveFont((float) 80);
g2d.setFont(font0);
FontMetrics metrics = g2d.getFontMetrics();
int x = (width - metrics.stringWidth(mailCode)) / 2; // 水平居中
// g2d.drawString(mailCode, startX + 400, 250);
g2d.drawString(mailCode, startX + 400, 1000);
byte[] code4Bytes = BarcodeUtils.generate39Barcode(mailCode, 1500, 550);
ByteArrayInputStream code4BytesIs = new ByteArrayInputStream(code4Bytes);
BufferedImage code4Img = ImageIO.read(code4BytesIs);
g2d.drawImage(code4Img, startX + 130, startY + 310, 1500, 550, null);
if (typeText != null) {
g2d.drawString(typeText, startX + 50, 100);
}
if (numText != null) {
g2d.drawString(numText, startX + 1500, 100);
}
g2d.dispose();
// 6. 将图片转为字节数组(PNG格式)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
return baos.toByteArray();
}
public static byte[] commonBarCodeToImage( String mailCode
) throws Exception {
int width = 1770;
......
package org.ta.pddserver.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.ta.pddserver.entity.PackageDetailEntity;
import java.util.List;
@Mapper
public interface PackageDetailMapper extends BaseMapper<PackageDetailEntity> {
@Delete("DELETE FROM `package_detail` WHERE `orderCode` = #{orderCode};")
int removeByOrderCode(@Param("orderCode") String orderCode);
@Select("SELECT * FROM `package_detail` WHERE `orderCode` = #{orderCode};")
List<PackageDetailEntity> findByOrderCode(@Param("orderCode") String orderCode);
}
package org.ta.pddserver.model.api.request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class PackageCompleteRequest {
@Schema(
description = "集运单号",
example = "P12345678",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private String orderCode;
@Schema(
description = "订单信息列表",
example = "",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private List<OutPackage> outPackageList;
/**
* 包裹详情
*/
@Data
public static class OutBoundList {
@Schema(
description = "运单号",
example = "P12345678",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private String mailNo;
}
@Data
public static class OutPackage {
@Schema(
description = "包裹长度,单位默认为厘米",
example = "1",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private Integer length;
@Schema(
description = "包裹宽度,单位默认为厘米",
example = "1",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private Integer width;
@Schema(
description = "包裹高度,单位默认为厘米",
example = "1",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private Integer height;
@Schema(
description = "实重重量,单位默认为克",
example = "1",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private Integer weight;
@Schema(
description = "包裹种类",
example = "1",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private String packageType;
@Schema(
description = "运单号",
example = "P1234567",
defaultValue = "",
requiredMode = Schema.RequiredMode.REQUIRED // 必填
)
private String mailNo;
@Schema(
description = "包裹关联原快递包裹单号,多拆少时必填",
example = "[\"SF000001\"]",
defaultValue = "",
requiredMode = Schema.RequiredMode.NOT_REQUIRED // 非必填
)
private List<String> outBound;
private String orderType;
}
}
package org.ta.pddserver.model.api.request;
import lombok.Data;
@Data
public class PackageLabelRequest {
private String orderCode;
private String mailNo;
}
package org.ta.pddserver.model.api.request;
import lombok.Data;
@Data
public class PackageScanOrderCodeRequest {
private String orderCode;
}
package org.ta.pddserver.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.ta.pddserver.entity.PackageDetailEntity;
public interface PackageDetailService extends IService<PackageDetailEntity> {
}
package org.ta.pddserver.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pddserver.entity.PackageDetailEntity;
import org.ta.pddserver.mapper.PackageDetailMapper;
import org.ta.pddserver.service.PackageDetailService;
import org.ta.pddserver.utils.JsonResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PackageDetailImpl extends ServiceImpl<PackageDetailMapper, PackageDetailEntity> implements PackageDetailService {
public int removeByOrderCode(String orderCode) {
return this.baseMapper.removeByOrderCode(orderCode);
}
public List<PackageDetailEntity> getByOrderCode(String orderCode) {
return this.baseMapper.findByOrderCode(orderCode);
}
}
\ No newline at end of file
......@@ -7,12 +7,12 @@ spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.2.222:3306/pdd_api?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
username: root
password: root
# url: jdbc:mysql://lyhj-mysql.mysql.rds.aliyuncs.com:3306/pdd_prod?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
# username: pdd
# password: pdd123
# url: jdbc:mysql://192.168.2.222:3306/pdd_api?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
# username: root
# password: root
url: jdbc:mysql://lyhj-mysql.mysql.rds.aliyuncs.com:3306/pdd_prod?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
username: pdd
password: pdd123
# url: jdbc:mysql://rm-j6cv8n7zx12x0sqreuo.mysql.rds.aliyuncs.com:3306/pdd_prod?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT
# username: pdd
# password: pdd123
......@@ -26,8 +26,8 @@ spring:
application:
name: PddServer
server:
port: 9000 # 正式端口号 - 向拼多多正式环境开放接口
# port: 9100 # 正式端口号 - 向海际系统正式环境开放接口
# port: 9000 # 正式端口号 - 向拼多多正式环境开放接口
port: 9100 # 正式端口号 - 向海际系统正式环境开放接口
# port: 8600 # 测试端口号
logging:
level:
......@@ -41,4 +41,4 @@ mybatis-plus:
pdd:
jyt: 0
gd: 0
lotto: 0
\ No newline at end of file
lotto: 1
\ No newline at end of file
......@@ -67,6 +67,7 @@ public class PdfTest {
byte[] strToBytes = ImagePdfGenerator.generateCode();
outputStream.write(strToBytes);
System.out.println("文件写入成功!");
} catch (IOException e) {
e.printStackTrace();
} catch (FontFormatException e) {
......
File added
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