This commit is contained in:
雷欧(林平凡)
2024-11-06 17:55:07 +08:00
commit 87e0e7693f
15 changed files with 1072 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package cn.van;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author Leo
* @version 1.0
* @create 2024/11/6 10:17
* @description
*/
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,608 @@
package cn.van.business.model;
/**
* @author Leo
* @version 1.0
* @create 2024/11/6 10:52
* @description
*/
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.GoodsInfo;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "order_rows")
public class OrderRowVO {
@Id
@Column(name = "id")
private String id;
@Column(name = "order_id")
private Long orderId;
@Column(name = "parent_id")
private Long parentId;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "order_time")
private Date orderTime;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "finish_time")
private Date finishTime;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "modify_time")
private Date modifyTime;
@Column(name = "order_emt")
private Integer orderEmt;
@Column(name = "plus")
private Integer plus;
@Column(name = "union_id")
private Long unionId;
@Column(name = "sku_id")
private Long skuId;
@Column(name = "sku_name")
private String skuName;
@Column(name = "sku_num")
private Integer skuNum;
@Column(name = "sku_return_num")
private Integer skuReturnNum;
@Column(name = "sku_frozen_num")
private Integer skuFrozenNum;
@Column(name = "price")
private Double price;
@Column(name = "commission_rate")
private Double commissionRate;
@Column(name = "sub_side_rate")
private Double subSideRate;
@Column(name = "subsidy_rate")
private Double subsidyRate;
@Column(name = "final_rate")
private Double finalRate;
@Column(name = "estimate_cos_price")
private Double estimateCosPrice;
@Column(name = "estimate_fee")
private Double estimateFee;
@Column(name = "actual_cos_price")
private Double actualCosPrice;
@Column(name = "actual_fee")
private Double actualFee;
@Column(name = "valid_code")
private Integer validCode;
@Column(name = "trace_type")
private Integer traceType;
@Column(name = "position_id")
private Long positionId;
@Column(name = "site_id")
private Long siteId;
@Column(name = "union_alias")
private String unionAlias;
@Column(name = "pid")
private String pid;
@Column(name = "cid1")
private Long cid1;
@Column(name = "cid2")
private Long cid2;
@Column(name = "cid3")
private Long cid3;
@Column(name = "sub_union_id")
private String subUnionId;
@Column(name = "union_tag")
private String unionTag;
@Column(name = "pop_id")
private Long popId;
@Column(name = "ext1")
private String ext1;
@Column(name = "pay_month")
private String payMonth;
@Column(name = "cp_act_id")
private Long cpActId;
@Column(name = "union_role")
private Integer unionRole;
@Column(name = "gift_coupon_ocs_amount")
private Double giftCouponOcsAmount;
@Column(name = "gift_coupon_key")
private String giftCouponKey;
@Column(name = "balance_ext")
private String balanceExt;
@Column(name = "sign")
private String sign;
@Column(name = "pro_price_amount")
private Double proPriceAmount;
@Column(name = "rid")
private Long rid;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "goods_info_id", referencedColumnName = "id")
private GoodsInfo goodsInfo;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "category_info_id", referencedColumnName = "id")
private CategoryInfoVO categoryInfoVO;
@Column(name = "express_status")
private Integer expressStatus;
@Column(name = "channel_id")
private Long channelId;
@Column(name = "sku_tag")
private String skuTag;
@Column(name = "item_id")
private String itemId;
@Column(name = "caller_item_id")
private String callerItemId;
@Column(name = "order_tag")
private String orderTag;
public OrderRowVO() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public Date getOrderTime() {
return orderTime;
}
public void setOrderTime(Date orderTime) {
this.orderTime = orderTime;
}
public Date getFinishTime() {
return finishTime;
}
public void setFinishTime(Date finishTime) {
this.finishTime = finishTime;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public Integer getOrderEmt() {
return orderEmt;
}
public void setOrderEmt(Integer orderEmt) {
this.orderEmt = orderEmt;
}
public Integer getPlus() {
return plus;
}
public void setPlus(Integer plus) {
this.plus = plus;
}
public Long getUnionId() {
return unionId;
}
public void setUnionId(Long unionId) {
this.unionId = unionId;
}
public Long getSkuId() {
return skuId;
}
public void setSkuId(Long skuId) {
this.skuId = skuId;
}
public String getSkuName() {
return skuName;
}
public void setSkuName(String skuName) {
this.skuName = skuName;
}
public Integer getSkuNum() {
return skuNum;
}
public void setSkuNum(Integer skuNum) {
this.skuNum = skuNum;
}
public Integer getSkuReturnNum() {
return skuReturnNum;
}
public void setSkuReturnNum(Integer skuReturnNum) {
this.skuReturnNum = skuReturnNum;
}
public Integer getSkuFrozenNum() {
return skuFrozenNum;
}
public void setSkuFrozenNum(Integer skuFrozenNum) {
this.skuFrozenNum = skuFrozenNum;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Double getCommissionRate() {
return commissionRate;
}
public void setCommissionRate(Double commissionRate) {
this.commissionRate = commissionRate;
}
public Double getSubSideRate() {
return subSideRate;
}
public void setSubSideRate(Double subSideRate) {
this.subSideRate = subSideRate;
}
public Double getSubsidyRate() {
return subsidyRate;
}
public void setSubsidyRate(Double subsidyRate) {
this.subsidyRate = subsidyRate;
}
public Double getFinalRate() {
return finalRate;
}
public void setFinalRate(Double finalRate) {
this.finalRate = finalRate;
}
public Double getEstimateCosPrice() {
return estimateCosPrice;
}
public void setEstimateCosPrice(Double estimateCosPrice) {
this.estimateCosPrice = estimateCosPrice;
}
public Double getEstimateFee() {
return estimateFee;
}
public void setEstimateFee(Double estimateFee) {
this.estimateFee = estimateFee;
}
public Double getActualCosPrice() {
return actualCosPrice;
}
public void setActualCosPrice(Double actualCosPrice) {
this.actualCosPrice = actualCosPrice;
}
public Double getActualFee() {
return actualFee;
}
public void setActualFee(Double actualFee) {
this.actualFee = actualFee;
}
public Integer getValidCode() {
return validCode;
}
public void setValidCode(Integer validCode) {
this.validCode = validCode;
}
public Integer getTraceType() {
return traceType;
}
public void setTraceType(Integer traceType) {
this.traceType = traceType;
}
public Long getPositionId() {
return positionId;
}
public void setPositionId(Long positionId) {
this.positionId = positionId;
}
public Long getSiteId() {
return siteId;
}
public void setSiteId(Long siteId) {
this.siteId = siteId;
}
public String getUnionAlias() {
return unionAlias;
}
public void setUnionAlias(String unionAlias) {
this.unionAlias = unionAlias;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public Long getCid1() {
return cid1;
}
public void setCid1(Long cid1) {
this.cid1 = cid1;
}
public Long getCid2() {
return cid2;
}
public void setCid2(Long cid2) {
this.cid2 = cid2;
}
public Long getCid3() {
return cid3;
}
public void setCid3(Long cid3) {
this.cid3 = cid3;
}
public String getSubUnionId() {
return subUnionId;
}
public void setSubUnionId(String subUnionId) {
this.subUnionId = subUnionId;
}
public String getUnionTag() {
return unionTag;
}
public void setUnionTag(String unionTag) {
this.unionTag = unionTag;
}
public Long getPopId() {
return popId;
}
public void setPopId(Long popId) {
this.popId = popId;
}
public String getExt1() {
return ext1;
}
public void setExt1(String ext1) {
this.ext1 = ext1;
}
public String getPayMonth() {
return payMonth;
}
public void setPayMonth(String payMonth) {
this.payMonth = payMonth;
}
public Long getCpActId() {
return cpActId;
}
public void setCpActId(Long cpActId) {
this.cpActId = cpActId;
}
public Integer getUnionRole() {
return unionRole;
}
public void setUnionRole(Integer unionRole) {
this.unionRole = unionRole;
}
public Double getGiftCouponOcsAmount() {
return giftCouponOcsAmount;
}
public void setGiftCouponOcsAmount(Double giftCouponOcsAmount) {
this.giftCouponOcsAmount = giftCouponOcsAmount;
}
public String getGiftCouponKey() {
return giftCouponKey;
}
public void setGiftCouponKey(String giftCouponKey) {
this.giftCouponKey = giftCouponKey;
}
public String getBalanceExt() {
return balanceExt;
}
public void setBalanceExt(String balanceExt) {
this.balanceExt = balanceExt;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public Double getProPriceAmount() {
return proPriceAmount;
}
public void setProPriceAmount(Double proPriceAmount) {
this.proPriceAmount = proPriceAmount;
}
public Long getRid() {
return rid;
}
public void setRid(Long rid) {
this.rid = rid;
}
public GoodsInfo getGoodsInfo() {
return goodsInfo;
}
public void setGoodsInfo(GoodsInfo goodsInfo) {
this.goodsInfo = goodsInfo;
}
public CategoryInfo getCategoryInfo() {
return categoryInfo;
}
public void setCategoryInfo(CategoryInfo categoryInfo) {
this.categoryInfo = categoryInfo;
}
public Integer getExpressStatus() {
return expressStatus;
}
public void setExpressStatus(Integer expressStatus) {
this.expressStatus = expressStatus;
}
public Long getChannelId() {
return channelId;
}
public void setChannelId(Long channelId) {
this.channelId = channelId;
}
public String getSkuTag() {
return skuTag;
}
public void setSkuTag(String skuTag) {
this.skuTag = skuTag;
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getCallerItemId() {
return callerItemId;
}
public void setCallerItemId(String callerItemId) {
this.callerItemId = callerItemId;
}
public String getOrderTag() {
return orderTag;
}
public void setOrderTag(String orderTag) {
this.orderTag = orderTag;
}
}

View File

@@ -0,0 +1,28 @@
package cn.van.business.repository;
/**
* @author Leo
* @version 1.0
* @create 2024/11/6 14:44
* @description
*/
import cn.van.business.model.OrderRow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface OrderRowRepository extends JpaRepository<OrderRow, String> {
// 这里可以根据需要添加自定义的查询方法,例如:
// 根据订单号查询订单行
List<OrderRow> findByOrderId(long orderId);
// 根据SKU ID 和订单号查询订单行
List<OrderRow> findBySkuIdAndOrderId(long skuId, long orderId);
// 根据有效码查询订单行
List<OrderRow> findByValidCode(int validCode);
}

View File

@@ -0,0 +1,114 @@
package cn.van.business.util;
import cn.van.business.model.OrderRow;
import cn.van.business.repository.OrderRowRepository;
import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.domain.kplunion.OrderService.request.query.OrderRowReq;
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Leo
* @version 1.0
* @create 2024/11/5 17:40
* @description
*/
@Component
public class JDUtils {
private static final String SERVER_URL =
"https://api.jd.com/routerjson";
private static final String APP_KEY =
"98e21c89ae5610240ec3f5f575f86a59";
private static final String SECRET_KEY =
"3dcb6b23a1104639ac433fd07adb6dfb";
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private OrderRowRepository orderRowRepository;
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 写两个方法,一个拉最新的订单。一个拉历史订单
*/
@Scheduled(cron = "0 0 * * * ?")
public void getHistoryOrder() {
// 因为只能一小时一小时的拉取订单,所以要循环的倒推去拉取历史订单,存到数据库
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 当前是2024-10-10 11:46:00 , 则生成一个 2024-10-10 11:00:00
}
@Scheduled(cron = "0 * * * * ?")
public void getNewOrder() throws Exception {
//一分钟一分钟拉取 2020-01-02 21:23:00
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startTime = sdf.format(new Date(System.currentTimeMillis() - 1000 * 60));
String endTime = sdf.format(new Date());
UnionOpenOrderRowQueryResponse response = getUnionOpenOrderRowQueryResponse(startTime, endTime);
int code = response.getQueryResult().getCode();
System.out.println("响应码:" + code);
if (code == 200) {
if (response.getQueryResult().getCode() == 200) {
OrderRowResp[] orderRowResps = response.getQueryResult().getData();
if (orderRowResps == null) {
return;
}
for (OrderRowResp orderRowResp : orderRowResps) {
// 固化到数据库
OrderRow orderRow = new OrderRow();
orderRow.setOrderId(orderRowResp.getOrderId());
orderRow.setSkuId(orderRowResp.getSkuId());
orderRow.setSkuName(orderRowResp.getSkuName());
orderRowRepository.save(orderRowResp);
}
}
}
}
/**
* 获取订单列表
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
* @throws Exception
*/
public UnionOpenOrderRowQueryResponse getUnionOpenOrderRowQueryResponse(String startTime, String endTime) throws Exception {
String accessToken = "";
JdClient client = new DefaultJdClient(SERVER_URL, accessToken, APP_KEY, SECRET_KEY);
UnionOpenOrderRowQueryRequest request = new UnionOpenOrderRowQueryRequest();
OrderRowReq orderReq = new OrderRowReq();
orderReq.setPageIndex(1);
orderReq.setPageSize(200);
orderReq.setStartTime(startTime);
orderReq.setEndTime(endTime);
orderReq.setType(1);
request.setOrderReq(orderReq);
request.setVersion("1.0");
request.setSignmethod("md5");
// 时间戳格式为yyyy-MM-dd HH:mm:ss时区为GMT+8。API服务端允许客户端请求最大时间误差为10分钟
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
request.setTimestamp(simpleDateFormat.format(date));
return client.execute(request);
}
}

Binary file not shown.

View File

@@ -0,0 +1,67 @@
server:
port: 36888
spring:
application:
name: wxSend
profiles:
active: dev
#数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://134.175.126.60:33306/jd?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: mysql_7sjTXH
#redis配置
redis:
host: 134.175.126.60
port: 36379
database: 7
timeout: 1800000
lettuce:
pool:
max-active: 20
#最大阻塞等待时间(负数表示没限制)
max-wait: -1
max-idle: 5
min-idle: 0
password: redis_6PZ52S # 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 20MB
# 设置总上传的文件大小
max-request-size: 20MB
#MyWebMvcConfig中开启@EnableWebMvc则失效
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
# # 对象字段为null不显示
# default-property-inclusion: non_null
# 资源信息
messages:
# 国际化资源文件路径
basename: i18n/messages
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌密钥
secret: 5c6649a39f184678af3580795a7307d9
# 令牌有效期(单位分钟)
expireTime: 1440
# 用户配置
user:
password:
# 密码最大错误次数
maxRetryCount: 5
# 密码锁定时间默认10分钟
lockTime: 10
# 日志配置
logging:
level:
cn.van333: debug
org.springframework: warn