This commit is contained in:
Leo
2025-03-02 16:25:53 +08:00
parent d8e97e7e2b
commit 31a5178d9c
13 changed files with 158 additions and 125 deletions

View File

@@ -1,9 +1,13 @@
package cn.van;
import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.Arrays;
/**
* @author Leo
* @version 1.0
@@ -14,7 +18,22 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
public class Application {
private final Environment env;
public Application(Environment env) {
this.env = env;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@PostConstruct
public void init() {
String[] activeProfiles = env.getActiveProfiles();
if (activeProfiles.length == 0) {
activeProfiles = env.getDefaultProfiles();
}
System.out.println("Active profiles: " + Arrays.toString(activeProfiles));
}
}

View File

@@ -0,0 +1,15 @@
package cn.van.business.config;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RocketMQConfig {
@Bean
public RocketMQTemplate rocketMQTemplate() {
System.out.println("RocketMQTemplate init");
return new RocketMQTemplate();
}
}

View File

@@ -1,49 +1,49 @@
package cn.van.business.controller.jd;
import cn.van.business.mq.MessageProducerService;
import cn.van.business.util.JDUtil;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Leo
* @version 1.0
* @create 2024/11/7 13:39
* @description
*/
@RestController
@RequestMapping("/order")
public class OrderController {
public static String TOKEN = "cc0313";
@Autowired
private JDUtil jdUtils;
@Autowired
private MessageProducerService messageProducerService;
public boolean checkToken(String token) {
return TOKEN.equals(token);
}
@RequestMapping("/refreshHistory")
@ResponseBody
public String refreshHistory(String token) throws Exception {
if (checkToken(token)) {
jdUtils.fetchHistoricalOrders3090();
}
return "OK";
}
@RequestMapping("/mq")
@ResponseBody
public String mq() {
JSONObject jsonObject = new JSONObject();
messageProducerService.sendMessage(jsonObject);
return "OK";
}
}
//package cn.van.business.controller.jd;
//
//import cn.van.business.mq.MessageProducerService;
//import cn.van.business.util.JDUtil;
//import com.alibaba.fastjson2.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestController;
//
//
///**
// * @author Leo
// * @version 1.0
// * @create 2024/11/7 13:39
// * @description
// */
//@RestController
//@RequestMapping("/order")
//public class OrderController {
//
// public static String TOKEN = "cc0313";
// @Autowired
// private JDUtil jdUtils;
// @Autowired
// private MessageProducerService messageProducerService;
//
// public boolean checkToken(String token) {
// return TOKEN.equals(token);
// }
//
// @RequestMapping("/refreshHistory")
// @ResponseBody
// public String refreshHistory(String token) throws Exception {
// if (checkToken(token)) {
// jdUtils.fetchHistoricalOrders3090();
// }
// return "OK";
// }
//
// @RequestMapping("/mq")
// @ResponseBody
// public String mq() {
// JSONObject jsonObject = new JSONObject();
// messageProducerService.sendMessage(jsonObject);
// return "OK";
// }
//
//}

View File

@@ -22,11 +22,11 @@ public class SkuInfo {
/**
* 商品类型名称。
*/
@Column(name = "type_name", unique = true, nullable = false)
private String typeName;
@Column(name = "sku_name")
private String skuName;
@Column(name = "sku", unique = true, nullable = false)
private String sku;
@Column(name = "sku_id")
private String skuId;
}

View File

@@ -1,6 +1,8 @@
package cn.van.business.model.jd;
import jakarta.persistence.*;
import java.util.List;
import java.util.Set;
/**
@@ -27,8 +29,30 @@ public class SkuType {
/**
* 与该商品类型关联的商品ID集合。
*/
@OneToMany(mappedBy = "sku_id", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ProductOrder> productOrders;
@Column(name = "sku_id")
private String skuId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public String getSkuId() {
return skuId;
}
public void setSkuId(String skuId) {
this.skuId = skuId;
}
}

View File

@@ -6,6 +6,7 @@ import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@@ -23,6 +24,7 @@ public class MessageProducerService {
private final RocketMQTemplate rocketMQTemplate;
@Autowired
public MessageProducerService(RocketMQTemplate rocketMQTemplate) {
this.rocketMQTemplate = rocketMQTemplate;
}
@@ -31,7 +33,6 @@ public class MessageProducerService {
public void sendMessage(JSONObject jsonObject) {
Message message = new Message(topic, jsonObject.toJSONString().getBytes());
message.setTags("wx");
this.rocketMQTemplate.convertAndSend(topic, message);
rocketMQTemplate.convertAndSend(topic, message);
}
}

View File

@@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -100,7 +101,7 @@ public class WXUtil {
@Autowired
public WXUtil(Environment env, WxtsUtil wxTsUtil, MessageProducerService messageProducerService) {
public WXUtil(Environment env, WxtsUtil wxTsUtil, @Lazy MessageProducerService messageProducerService) {
this.messageProducerService = messageProducerService;
this.wxTsUtil = wxTsUtil;
this.env = env;