commit 87e0e7693f95a34cddfa44225d512f2439a2ce72 Author: 雷欧(林平凡) Date: Wed Nov 6 17:55:07 2024 +0800 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ApifoxUploaderProjectSetting.xml b/.idea/ApifoxUploaderProjectSetting.xml new file mode 100644 index 0000000..22a0c1e --- /dev/null +++ b/.idea/ApifoxUploaderProjectSetting.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..74dd33a --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,19 @@ + + + + + mysql.8 + true + true + $PROJECT_DIR$/src/main/resources/application.yml + com.mysql.cj.jdbc.Driver + jdbc:mysql://134.175.126.60:33306/jd?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..bdfedf0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,39 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0e5a600 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..79f7680 --- /dev/null +++ b/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + + com.example + springboot-hql-web + 1.0-SNAPSHOT + SpringBootHQLWeb + Spring Boot with HQL and Web support + + + + 1.8 + 2.6.13 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + mysql + mysql-connector-java + runtime + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.2 + + + + + org.codehaus.jackson + jackson-core-asl + 1.9.2 + + + + + com.alibaba.fastjson2 + fastjson2 + 2.0.21 + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/src/main/java/cn/van/Application.java b/src/main/java/cn/van/Application.java new file mode 100644 index 0000000..45d54b3 --- /dev/null +++ b/src/main/java/cn/van/Application.java @@ -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); + } +} diff --git a/src/main/java/cn/van/business/model/OrderRow.java b/src/main/java/cn/van/business/model/OrderRow.java new file mode 100644 index 0000000..1a8e94f --- /dev/null +++ b/src/main/java/cn/van/business/model/OrderRow.java @@ -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; + } +} diff --git a/src/main/java/cn/van/business/repository/OrderRowRepository.java b/src/main/java/cn/van/business/repository/OrderRowRepository.java new file mode 100644 index 0000000..c15b3e2 --- /dev/null +++ b/src/main/java/cn/van/business/repository/OrderRowRepository.java @@ -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 { + // 这里可以根据需要添加自定义的查询方法,例如: + + // 根据订单号查询订单行 + List findByOrderId(long orderId); + + // 根据SKU ID 和订单号查询订单行 + List findBySkuIdAndOrderId(long skuId, long orderId); + + // 根据有效码查询订单行 + List findByValidCode(int validCode); +} diff --git a/src/main/java/cn/van/business/util/JDUtils.java b/src/main/java/cn/van/business/util/JDUtils.java new file mode 100644 index 0000000..29a6ade --- /dev/null +++ b/src/main/java/cn/van/business/util/JDUtils.java @@ -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); + } + +} diff --git a/src/main/libs/open-api-sdk-2.0-2024-10-21.jar b/src/main/libs/open-api-sdk-2.0-2024-10-21.jar new file mode 100644 index 0000000..58745e4 Binary files /dev/null and b/src/main/libs/open-api-sdk-2.0-2024-10-21.jar differ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..0fcf3c6 --- /dev/null +++ b/src/main/resources/application.yml @@ -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