This commit is contained in:
2025-08-18 01:58:23 +08:00
parent 33567109ed
commit 5e8c9614ef
71 changed files with 6864 additions and 6 deletions

View File

@@ -0,0 +1,35 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 授权列表查询请求(示例类)
*/
public class AuthorizeListQueryRequest extends ERPRequestBase {
public AuthorizeListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/user/authorize/list", erpAccount);
}
/**
* 设置分页参数
* @param pageNum 页码
* @param pageSize 每页数量
*/
public void setPagination(int pageNum, int pageSize) {
JSONObject params = new JSONObject();
params.put("page_num", pageNum);
params.put("page_size", pageSize);
this.requestBody = params;
}
/**
* 设置过滤条件
* @param status 授权状态
*/
public void setFilter(String status) {
if (requestBody == null) {
requestBody = new JSONObject();
}
requestBody.put("status", status);
}
}

View File

@@ -0,0 +1,31 @@
package com.ruoyi.erp.request;
import lombok.Getter;
/**
* @author Leo
* @version 1.0
* @create 2025/4/10 15:20
* @descriptionERP账户枚举类
*/
@Getter
public enum ERPAccount {
// 胡歌1016208368633221
ACCOUNT_HUGE("1016208368633221", "waLiRMgFcixLbcLjUSSwo370Hp1nBcBu","余生请多关照66","海尔胡歌"),
// 刘强东anotherApiKey
ACCOUNT_LQD("anotherApiKey", "anotherApiSecret","刘强东","方案小号");
private final String apiKey;
private final String apiKeySecret;
private final String xyName;
private final String remark;
ERPAccount(String apiKey, String apiKeySecret, String xyName,String remark) {
this.apiKey = apiKey;
this.apiKeySecret = apiKeySecret;
this.xyName = xyName;
this.remark = remark;
}
}

View File

@@ -0,0 +1,99 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* ERP请求基类支持开放平台签名规范
*/
public abstract class ERPRequestBase {
private static final Logger log = LoggerFactory.getLogger(ERPRequestBase.class);
protected String url;
protected String sign;
protected ERPAccount erpAccount;
@Setter
protected JSONObject requestBody;
protected long timestamp; // 统一时间戳字段
public ERPRequestBase(String url, ERPAccount erpAccount) {
this.url = url;
this.erpAccount = erpAccount;
}
/**
* 生成MD5签名兼容官方示例
* @param str 需要签名的原始字符串
* @return 十六进制小写MD5值
*/
public String genMd5(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8));
StringBuilder result = new StringBuilder();
for (byte b : digest) {
result.append(String.format("%02x", b & 0xff)); // 保证小写十六进制
}
return result.toString();
} catch (NoSuchAlgorithmException e) {
log.error("MD5算法初始化失败", e);
throw new RuntimeException("MD5算法初始化失败", e);
}
}
/**
* 生成请求签名(与官方示例保持完全一致的拼接逻辑)
*/
public void genSign(long timestamp) {
this.timestamp = timestamp;
String jsonStr = getRequestBody(); // 使用getRequestBody()方法
String data = erpAccount.getApiKey() + "," + genMd5(jsonStr) + "," + timestamp + "," + erpAccount.getApiKeySecret();
this.sign = genMd5(data);
}
/**
* 获取带签名的请求URL
* @return 包含签名参数的完整URL
*/
public String getRequestUrl() {
return url + "?appid=" + erpAccount.getApiKey() + "&timestamp=" + timestamp + "&sign=" + sign;
}
/**
* 获取请求体内容(空时返回空对象)
* @return JSON字符串格式的请求体
*/
public String getRequestBody() {
return requestBody != null ? requestBody.toJSONString() : "{}";
}
/**
* 执行HTTP请求并获取响应
* @return 接口返回的原始JSON字符串
*/
public String getResponseBody() {
try {
long timestamp = System.currentTimeMillis() / 1000;
genSign(timestamp);
String requestUrl = getRequestUrl();
String body = getRequestBody();
System.out.println("请求地址: " + requestUrl);
System.out.println("请求体: " + body);
if (requestBody == null) {
return HttpUtils.sendPost(requestUrl, body); // 保持 body 一致
}
return HttpUtils.sendJsonPost(requestUrl, body);
} catch (Exception e) {
log.error("HTTP请求失败: {}", e.getMessage(), e);
throw new RuntimeException("ERP接口调用失败: " + e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,14 @@
package com.ruoyi.erp.request;
/**
* 查询快递公司请求
*
* 对应接口POST /api/open/express/companies
*/
public class ExpressCompaniesQueryRequest extends ERPRequestBase {
public ExpressCompaniesQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/express/companies", erpAccount);
}
}

View File

@@ -0,0 +1,106 @@
package com.ruoyi.erp.request;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class HttpTest {
private static final String apiKey = "1016208368633221"; // 开放平台提供的应用KEY
private static final String apiKeySecret = "waLiRMgFcixLbcLjUSSwo370Hp1nBcBu"; // 开放平台提供的应用密钥
private static final String domain = "https://open.goofish.pro"; // 域名
public static void main(String[] args) {
// 获取当前时间戳
long timestamp = System.currentTimeMillis() / 1000L;
System.out.println("timestamp: " + timestamp);
// 请求体JSON字符串
String jsonBody = "{}";
// 生成签名
String sign = genSign(timestamp, jsonBody);
System.out.println("sign: " + sign);
// 拼接请求地址
String apiUrl = domain + "/api/open/product/list?appid=" + apiKey + "&timestamp=" + timestamp + "&sign="
+ sign;
try {
// 创建URL对象
URL url = new URL(apiUrl);
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求方法为POST
connection.setRequestMethod("POST");
// 设置请求头部
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
// 启用输出流
connection.setDoOutput(true);
// 获取输出流并写入请求体
OutputStream outputStream = connection.getOutputStream();
outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
outputStream.close();
// 获取响应状态码
int responseCode = connection.getResponseCode();
System.out.println("API Response Code: " + responseCode);
// 读取响应内容
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
response.append(line);
}
bufferedReader.close();
// 关闭连接
connection.disconnect();
System.out.println("API Response: " + response.toString());
} catch (IOException e) {
// 在此处处理异常
e.printStackTrace();
}
}
// md5加密
private static String genMd5(String str) {
StringBuilder result = new StringBuilder();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8));
for (byte b : digest) {
result.append(String.format("%02x", b & 0xff));
}
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
return result.toString();
}
// 生成签名
private static String genSign(long timestamp, String jsonStr) {
// 拼接字符串
String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + apiKeySecret;
// 商务对接模式 拼接字符串
// String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + seller_id + "," + apiKeySecret;
// 生成签名
return genMd5(data);
}
}

View File

@@ -0,0 +1,23 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 查询订单详情请求
*
* 对应接口POST /api/open/order/detail
*/
public class OrderDetailQueryRequest extends ERPRequestBase {
public OrderDetailQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/order/detail", erpAccount);
}
public void setOrderNo(String orderNo) {
ensureBody();
this.requestBody.put("order_no", orderNo);
}
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
}

View File

@@ -0,0 +1,23 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 订单卡密列表请求
*
* 对应接口POST /api/open/order/kam/list
*/
public class OrderKamListQueryRequest extends ERPRequestBase {
public OrderKamListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/order/kam/list", erpAccount);
}
public void setOrderNo(String orderNo) {
ensureBody();
this.requestBody.put("order_no", orderNo);
}
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
}

View File

@@ -0,0 +1,35 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 查询订单列表请求
*
* 对应接口POST /api/open/order/list
*/
public class OrderListQueryRequest extends ERPRequestBase {
public OrderListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/order/list", erpAccount);
}
public void setAuthorizeId(long authorizeId) { ensureBody(); this.requestBody.put("authorize_id", authorizeId); }
public void setOrderStatus(Integer orderStatus) { putIfNotNull("order_status", orderStatus); }
public void setRefundStatus(Integer refundStatus) { putIfNotNull("refund_status", refundStatus); }
public void setOrderTime(long start, long end) { setRange("order_time", start, end); }
public void setPayTime(long start, long end) { setRange("pay_time", start, end); }
public void setConsignTime(long start, long end) { setRange("consign_time", start, end); }
public void setConfirmTime(long start, long end) { setRange("confirm_time", start, end); }
public void setRefundTime(long start, long end) { setRange("refund_time", start, end); }
public void setUpdateTime(long start, long end) { setRange("update_time", start, end); }
public void setPageNo(int pageNo) { ensureBody(); this.requestBody.put("page_no", pageNo); }
public void setPageSize(int pageSize) { ensureBody(); this.requestBody.put("page_size", pageSize); }
public void setPage(int pageNo, int pageSize) { ensureBody(); this.requestBody.put("page_no", pageNo); this.requestBody.put("page_size", pageSize); }
private void setRange(String key, long start, long end) { ensureBody(); this.requestBody.put(key, new long[]{start, end}); }
private void putIfNotNull(String key, Object value) { if (value != null) { ensureBody(); this.requestBody.put(key, value); } }
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
}

View File

@@ -0,0 +1,22 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 订单修改价格请求
*
* 对应接口POST /api/open/order/modify/price
*/
public class OrderModifyPriceRequest extends ERPRequestBase {
public OrderModifyPriceRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/order/modify/price", erpAccount);
}
public void setOrderNo(String orderNo) { ensureBody(); this.requestBody.put("order_no", orderNo); }
public void setExpressFee(long expressFee) { ensureBody(); this.requestBody.put("express_fee", expressFee); }
public void setOrderPrice(long orderPrice) { ensureBody(); this.requestBody.put("order_price", orderPrice); }
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
}

View File

@@ -0,0 +1,31 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 订单物流发货请求
*
* 对应接口POST /api/open/order/ship
*/
public class OrderShipRequest extends ERPRequestBase {
public OrderShipRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/order/ship", erpAccount);
}
public void setOrderNo(String orderNo) { put("order_no", orderNo); }
public void setShipName(String shipName) { put("ship_name", shipName); }
public void setShipMobile(String shipMobile) { put("ship_mobile", shipMobile); }
public void setShipDistrictId(Integer shipDistrictId) { put("ship_district_id", shipDistrictId); }
public void setShipProvName(String shipProvName) { put("ship_prov_name", shipProvName); }
public void setShipCityName(String shipCityName) { put("ship_city_name", shipCityName); }
public void setShipAreaName(String shipAreaName) { put("ship_area_name", shipAreaName); }
public void setShipAddress(String shipAddress) { put("ship_address", shipAddress); }
public void setWaybillNo(String waybillNo) { put("waybill_no", waybillNo); }
public void setExpressCode(String expressCode) { put("express_code", expressCode); }
public void setExpressName(String expressName) { put("express_name", expressName); }
private void put(String key, Object value) { if (value != null) { ensureBody(); this.requestBody.put(key, value); } }
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
}

View File

@@ -0,0 +1,231 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import java.util.Collection;
import java.util.List;
/**
* 创建商品(批量)请求
*
* 对应接口POST /api/open/product/batchCreate
* 限制每批次最多50个商品
*/
public class ProductBatchCreateRequest extends ERPRequestBase {
public ProductBatchCreateRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/batchCreate", erpAccount);
}
/**
* 设置一批商品数据,覆盖已有的 product_data
*/
public void setProducts(Collection<ProductBuilder> products) {
ensureRequestBodyInitialized();
if (products == null || products.isEmpty()) {
throw new IllegalArgumentException("product_data不能为空");
}
if (products.size() > 50) {
throw new IllegalArgumentException("每批次最多创建50个商品");
}
JSONArray array = new JSONArray();
for (ProductBuilder builder : products) {
array.add(builder.build());
}
this.requestBody.put("product_data", array);
}
/**
* 在原有 product_data 基础上追加一个商品
*/
public void addProduct(ProductBuilder product) {
ensureRequestBodyInitialized();
JSONArray array = this.requestBody.getJSONArray("product_data");
if (array == null) {
array = new JSONArray();
this.requestBody.put("product_data", array);
}
if (array.size() >= 50) {
throw new IllegalStateException("每批次最多创建50个商品");
}
array.add(product.build());
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
/**
* 单个商品数据构建器
*/
public static class ProductBuilder {
private final JSONObject data = new JSONObject();
private final JSONArray channelPv = new JSONArray();
private final JSONArray publishShop = new JSONArray();
private final JSONArray skuItems = new JSONArray();
public ProductBuilder setItemKey(String itemKey) {
data.put("item_key", itemKey);
return this;
}
public ProductBuilder setItemBizType(int itemBizType) {
data.put("item_biz_type", itemBizType);
return this;
}
public ProductBuilder setSpBizType(int spBizType) {
data.put("sp_biz_type", spBizType);
return this;
}
public ProductBuilder setChannelCatId(String channelCatId) {
data.put("channel_cat_id", channelCatId);
return this;
}
public ProductBuilder setPrice(long price) {
data.put("price", price);
return this;
}
public ProductBuilder setOriginalPrice(Long originalPrice) {
if (originalPrice != null) {
data.put("original_price", originalPrice);
}
return this;
}
public ProductBuilder setExpressFee(Long expressFee) {
if (expressFee != null) {
data.put("express_fee", expressFee);
}
return this;
}
public ProductBuilder setStock(int stock) {
data.put("stock", stock);
return this;
}
public ProductBuilder setOuterId(String outerId) {
if (outerId != null) {
data.put("outer_id", outerId);
}
return this;
}
public ProductBuilder setStuffStatus(Integer stuffStatus) {
if (stuffStatus != null) {
data.put("stuff_status", stuffStatus);
}
return this;
}
public ProductBuilder addChannelPv(String propertyId, String propertyName, String valueId, String valueName) {
JSONObject pv = new JSONObject();
pv.put("property_id", propertyId);
pv.put("property_name", propertyName);
pv.put("value_id", valueId);
pv.put("value_name", valueName);
channelPv.add(pv);
return this;
}
public ProductBuilder addPublishShop(String userName, int province, int city, int district, String title, String content, List<String> images, String whiteImages, String serviceSupport) {
JSONObject shop = new JSONObject();
shop.put("user_name", userName);
shop.put("province", province);
shop.put("city", city);
shop.put("district", district);
shop.put("title", title);
shop.put("content", content);
if (images != null && !images.isEmpty()) {
JSONArray imgs = new JSONArray();
imgs.addAll(images);
shop.put("images", imgs);
}
if (whiteImages != null) {
shop.put("white_images", whiteImages);
}
if (serviceSupport != null) {
shop.put("service_support", serviceSupport);
}
publishShop.add(shop);
return this;
}
public ProductBuilder addSkuItem(long price, int stock, String skuText, String outerId) {
JSONObject sku = new JSONObject();
sku.put("price", price);
sku.put("stock", stock);
sku.put("sku_text", skuText);
if (outerId != null) {
sku.put("outer_id", outerId);
}
skuItems.add(sku);
return this;
}
public ProductBuilder setDetailImages(JSONArray images) {
if (images != null) {
data.put("detail_images", images);
}
return this;
}
public ProductBuilder setSkuImages(JSONArray images) {
if (images != null) {
data.put("sku_images", images);
}
return this;
}
public ProductBuilder setBookData(JSONObject bookData) { return putIfNotNull("book_data", bookData); }
public ProductBuilder setFoodData(JSONObject foodData) { return putIfNotNull("food_data", foodData); }
public ProductBuilder setReportData(JSONObject reportData) { return putIfNotNull("report_data", reportData); }
public ProductBuilder setFlashSaleType(Integer flashSaleType) { if (flashSaleType != null) data.put("flash_sale_type", flashSaleType); return this; }
public ProductBuilder setAdventData(JSONObject adventData) { return putIfNotNull("advent_data", adventData); }
public ProductBuilder setInspectData(JSONObject inspectData) { return putIfNotNull("inspect_data", inspectData); }
public ProductBuilder setBrandData(JSONObject brandData) { return putIfNotNull("brand_data", brandData); }
private ProductBuilder putIfNotNull(String key, Object value) {
if (value != null) {
data.put(key, value);
}
return this;
}
private void finalizeArrays() {
if (!channelPv.isEmpty()) {
data.put("channel_pv", channelPv);
}
if (!publishShop.isEmpty()) {
data.put("publish_shop", publishShop);
}
if (!skuItems.isEmpty()) {
data.put("sku_items", skuItems);
}
}
private void validateRequired() {
if (!data.containsKey("item_key")) throw new IllegalStateException("缺少必填字段: item_key");
if (!data.containsKey("item_biz_type")) throw new IllegalStateException("缺少必填字段: item_biz_type");
if (!data.containsKey("sp_biz_type")) throw new IllegalStateException("缺少必填字段: sp_biz_type");
if (!data.containsKey("channel_cat_id")) throw new IllegalStateException("缺少必填字段: channel_cat_id");
if (!data.containsKey("price")) throw new IllegalStateException("缺少必填字段: price");
if (!data.containsKey("stock")) throw new IllegalStateException("缺少必填字段: stock");
if (publishShop.isEmpty()) throw new IllegalStateException("缺少必填字段: publish_shop");
}
private JSONObject build() {
finalizeArrays();
validateRequired();
return data;
}
}
}

View File

@@ -0,0 +1,59 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 查询商品类目请求
*
* 对应接口POST /api/open/product/category/list
* 请求体字段:
* - item_biz_type必填商品类型
* - sp_biz_type选填行业类型
* - flash_sale_type选填闲鱼特卖类型
*/
public class ProductCategoryListQueryRequest extends ERPRequestBase {
public ProductCategoryListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/category/list", erpAccount);
}
/**
* 设置商品类型(必填)
* @param itemBizType 商品类型
*/
public void setItemBizType(int itemBizType) {
ensureRequestBodyInitialized();
this.requestBody.put("item_biz_type", itemBizType);
}
/**
* 设置行业类型(选填)
* @param spBizType 行业类型
*/
public void setSpBizType(Integer spBizType) {
if (spBizType == null) {
return;
}
ensureRequestBodyInitialized();
this.requestBody.put("sp_biz_type", spBizType);
}
/**
* 设置闲鱼特卖类型(选填)
* @param flashSaleType 闲鱼特卖类型
*/
public void setFlashSaleType(Integer flashSaleType) {
if (flashSaleType == null) {
return;
}
ensureRequestBodyInitialized();
this.requestBody.put("flash_sale_type", flashSaleType);
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,142 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import java.util.List;
/**
* 创建商品(单个)请求
*
* 对应接口POST /api/open/product/create
*/
public class ProductCreateRequest extends ERPRequestBase {
private final JSONArray channelPv = new JSONArray();
private final JSONArray publishShop = new JSONArray();
private final JSONArray skuItems = new JSONArray();
public ProductCreateRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/create", erpAccount);
}
public void setItemBizType(int itemBizType) {
ensureRequestBodyInitialized();
this.requestBody.put("item_biz_type", itemBizType);
}
public void setSpBizType(int spBizType) {
ensureRequestBodyInitialized();
this.requestBody.put("sp_biz_type", spBizType);
}
public void setChannelCatId(String channelCatId) {
ensureRequestBodyInitialized();
this.requestBody.put("channel_cat_id", channelCatId);
}
public void addChannelPv(String propertyId, String propertyName, String valueId, String valueName) {
JSONObject pv = new JSONObject();
pv.put("property_id", propertyId);
pv.put("property_name", propertyName);
pv.put("value_id", valueId);
pv.put("value_name", valueName);
channelPv.add(pv);
ensureRequestBodyInitialized();
this.requestBody.put("channel_pv", channelPv);
}
public void setPrice(long price) {
ensureRequestBodyInitialized();
this.requestBody.put("price", price);
}
public void setOriginalPrice(Long originalPrice) {
if (originalPrice == null) return;
ensureRequestBodyInitialized();
this.requestBody.put("original_price", originalPrice);
}
public void setExpressFee(long expressFee) {
ensureRequestBodyInitialized();
this.requestBody.put("express_fee", expressFee);
}
public void setStock(int stock) {
ensureRequestBodyInitialized();
this.requestBody.put("stock", stock);
}
public void setOuterId(String outerId) {
if (outerId == null) return;
ensureRequestBodyInitialized();
this.requestBody.put("outer_id", outerId);
}
public void setStuffStatus(Integer stuffStatus) {
if (stuffStatus == null) return;
ensureRequestBodyInitialized();
this.requestBody.put("stuff_status", stuffStatus);
}
public void addPublishShop(String userName, int province, int city, int district, String title, String content, List<String> images, String whiteImages, String serviceSupport) {
JSONObject shop = new JSONObject();
shop.put("user_name", userName);
shop.put("province", province);
shop.put("city", city);
shop.put("district", district);
shop.put("title", title);
shop.put("content", content);
if (images != null && !images.isEmpty()) {
JSONArray imgs = new JSONArray();
imgs.addAll(images);
shop.put("images", imgs);
}
if (whiteImages != null) {
shop.put("white_images", whiteImages);
}
if (serviceSupport != null) {
shop.put("service_support", serviceSupport);
}
publishShop.add(shop);
ensureRequestBodyInitialized();
this.requestBody.put("publish_shop", publishShop);
}
public void addSkuItem(long price, int stock, String skuText, String outerId) {
JSONObject sku = new JSONObject();
sku.put("price", price);
sku.put("stock", stock);
sku.put("sku_text", skuText);
if (outerId != null) {
sku.put("outer_id", outerId);
}
skuItems.add(sku);
ensureRequestBodyInitialized();
this.requestBody.put("sku_items", skuItems);
}
public void setBookData(JSONObject bookData) { putIfNotNull("book_data", bookData); }
public void setFoodData(JSONObject foodData) { putIfNotNull("food_data", foodData); }
public void setReportData(JSONObject reportData) { putIfNotNull("report_data", reportData); }
public void setFlashSaleType(Integer flashSaleType) { if (flashSaleType != null) { ensureRequestBodyInitialized(); this.requestBody.put("flash_sale_type", flashSaleType); } }
public void setAdventData(JSONObject adventData) { putIfNotNull("advent_data", adventData); }
public void setInspectData(JSONObject inspectData) { putIfNotNull("inspect_data", inspectData); }
public void setBrandData(JSONObject brandData) { putIfNotNull("brand_data", brandData); }
public void setDetailImages(JSONArray images) { if (images != null) { ensureRequestBodyInitialized(); this.requestBody.put("detail_images", images); } }
public void setSkuImages(JSONArray images) { if (images != null) { ensureRequestBodyInitialized(); this.requestBody.put("sku_images", images); } }
private void putIfNotNull(String key, Object value) {
if (value != null) {
ensureRequestBodyInitialized();
this.requestBody.put(key, value);
}
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,25 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 删除商品请求
*
* 对应接口POST /api/open/product/delete
*/
public class ProductDeleteRequest extends ERPRequestBase {
public ProductDeleteRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/delete", erpAccount);
}
public void setProductId(long productId) {
ensureBody();
this.requestBody.put("product_id", productId);
}
private void ensureBody() {
if (this.requestBody == null) this.requestBody = new JSONObject();
}
}

View File

@@ -0,0 +1,33 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 查询商品详情请求
*
* 对应接口POST /api/open/product/detail
* 请求体字段:
* - product_id必填管家商品ID
*/
public class ProductDetailQueryRequest extends ERPRequestBase {
public ProductDetailQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/detail", erpAccount);
}
/**
* 设置管家商品ID必填
* @param productId 管家商品ID
*/
public void setProductId(long productId) {
ensureRequestBodyInitialized();
this.requestBody.put("product_id", productId);
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,25 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 下架商品请求
*
* 对应接口POST /api/open/product/downShelf
*/
public class ProductDownShelfRequest extends ERPRequestBase {
public ProductDownShelfRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/downShelf", erpAccount);
}
public void setProductId(long productId) {
ensureBody();
this.requestBody.put("product_id", productId);
}
private void ensureBody() {
if (this.requestBody == null) this.requestBody = new JSONObject();
}
}

View File

@@ -0,0 +1,89 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import java.util.List;
/**
* 编辑商品请求(按需传入要修改的字段)
*
* 对应接口POST /api/open/product/edit
*/
public class ProductEditRequest extends ERPRequestBase {
private final JSONArray channelPv = new JSONArray();
private final JSONArray publishShop = new JSONArray();
private final JSONArray skuItems = new JSONArray();
public ProductEditRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/edit", erpAccount);
}
public void setProductId(long productId) { ensureBody(); this.requestBody.put("product_id", productId); }
public void setItemBizType(Integer itemBizType) { putIfNotNull("item_biz_type", itemBizType); }
public void setSpBizType(Integer spBizType) { putIfNotNull("sp_biz_type", spBizType); }
public void setCategoryId(Integer categoryId) { putIfNotNull("category_id", categoryId); }
public void setChannelCatId(String channelCatId) { putIfNotNull("channel_cat_id", channelCatId); }
public void addChannelPv(String propertyId, String propertyName, String valueId, String valueName) {
JSONObject pv = new JSONObject();
pv.put("property_id", propertyId);
pv.put("property_name", propertyName);
pv.put("value_id", valueId);
pv.put("value_name", valueName);
channelPv.add(pv);
ensureBody();
this.requestBody.put("channel_pv", channelPv);
}
public void setTitle(String title) { putIfNotNull("title", title); }
public void setPrice(Long price) { putIfNotNull("price", price); }
public void setOriginalPrice(Long originalPrice) { putIfNotNull("original_price", originalPrice); }
public void setExpressFee(Long expressFee) { putIfNotNull("express_fee", expressFee); }
public void setStock(Integer stock) { putIfNotNull("stock", stock); }
public void setOuterId(String outerId) { putIfNotNull("outer_id", outerId); }
public void setStuffStatus(Integer stuffStatus) { putIfNotNull("stuff_status", stuffStatus); }
public void addPublishShop(String userName, Integer province, Integer city, Integer district, String title, String content, List<String> images, String whiteImages, String serviceSupport) {
JSONObject shop = new JSONObject();
if (userName != null) shop.put("user_name", userName);
if (province != null) shop.put("province", province);
if (city != null) shop.put("city", city);
if (district != null) shop.put("district", district);
if (title != null) shop.put("title", title);
if (content != null) shop.put("content", content);
if (images != null && !images.isEmpty()) {
JSONArray imgs = new JSONArray();
imgs.addAll(images);
shop.put("images", imgs);
}
if (whiteImages != null) shop.put("white_images", whiteImages);
if (serviceSupport != null) shop.put("service_support", serviceSupport);
publishShop.add(shop);
ensureBody();
this.requestBody.put("publish_shop", publishShop);
}
public void addSkuItem(Long price, Integer stock, String skuText, String outerId) {
JSONObject sku = new JSONObject();
if (price != null) sku.put("price", price);
if (stock != null) sku.put("stock", stock);
if (skuText != null) sku.put("sku_text", skuText);
if (outerId != null) sku.put("outer_id", outerId);
skuItems.add(sku);
ensureBody();
this.requestBody.put("sku_items", skuItems);
}
public void setBookData(JSONObject bookData) { putIfNotNull("book_data", bookData); }
public void setFoodData(JSONObject foodData) { putIfNotNull("food_data", foodData); }
public void setReportData(JSONObject reportData) { putIfNotNull("report_data", reportData); }
public void setNotifyUrl(String notifyUrl) { putIfNotNull("notify_url", notifyUrl); }
public void setFlashSaleType(Integer flashSaleType) { putIfNotNull("flash_sale_type", flashSaleType); }
public void setAdventData(JSONObject adventData) { putIfNotNull("advent_data", adventData); }
public void setInspectData(JSONObject inspectData) { putIfNotNull("inspect_data", inspectData); }
public void setBrandData(JSONObject brandData) { putIfNotNull("brand_data", brandData); }
public void setDetailImages(JSONArray images) { putIfNotNull("detail_images", images); }
public void setSkuImages(JSONArray images) { putIfNotNull("sku_images", images); }
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
private void putIfNotNull(String key, Object value) { if (value != null) { ensureBody(); this.requestBody.put(key, value); } }
}

View File

@@ -0,0 +1,37 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
/**
* 编辑库存请求
*
* 对应接口POST /api/open/product/edit/stock
*/
public class ProductEditStockRequest extends ERPRequestBase {
public ProductEditStockRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/edit/stock", erpAccount);
}
public void setProductId(long productId) { ensureBody(); this.requestBody.put("product_id", productId); }
public void setPrice(Long price) { putIfNotNull("price", price); }
public void setOriginalPrice(Long originalPrice) { putIfNotNull("original_price", originalPrice); }
public void setStock(Integer stock) { putIfNotNull("stock", stock); }
public void addSkuItem(long skuId, Integer stock, Long price, String outerId) {
ensureBody();
JSONArray arr = this.requestBody.getJSONArray("sku_items");
if (arr == null) { arr = new JSONArray(); this.requestBody.put("sku_items", arr); }
JSONObject sku = new JSONObject();
sku.put("sku_id", skuId);
if (stock != null) sku.put("stock", stock);
if (price != null) sku.put("price", price);
if (outerId != null) sku.put("outer_id", outerId);
arr.add(sku);
}
private void ensureBody() { if (this.requestBody == null) this.requestBody = new JSONObject(); }
private void putIfNotNull(String key, Object value) { if (value != null) { ensureBody(); this.requestBody.put(key, value); } }
}

View File

@@ -0,0 +1,69 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
public class ProductListQueryRequest extends ERPRequestBase {
public ProductListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/list", erpAccount);
}
public void setOnlineTime(long start, long end) {
ensureRequestBodyInitialized();
this.requestBody.put("online_time", new long[]{start, end});
}
public void setOfflineTime(long start, long end) {
ensureRequestBodyInitialized();
this.requestBody.put("offline_time", new long[]{start, end});
}
public void setSoldTime(long start, long end) {
ensureRequestBodyInitialized();
this.requestBody.put("sold_time", new long[]{start, end});
}
public void setUpdateTime(long start, long end) {
ensureRequestBodyInitialized();
this.requestBody.put("update_time", new long[]{start, end});
}
public void setCreateTime(long start, long end) {
ensureRequestBodyInitialized();
this.requestBody.put("create_time", new long[]{start, end});
}
public void setProductStatus(int productStatus) {
ensureRequestBodyInitialized();
this.requestBody.put("product_status", productStatus);
}
public void setSaleStatus(Integer saleStatus) {
if (saleStatus == null) {
return;
}
ensureRequestBodyInitialized();
this.requestBody.put("sale_status", saleStatus);
}
public void setPageNo(int pageNo) {
ensureRequestBodyInitialized();
this.requestBody.put("page_no", pageNo);
}
public void setPageSize(int pageSize) {
ensureRequestBodyInitialized();
this.requestBody.put("page_size", pageSize);
}
public void setPage(int pageNo, int pageSize) {
ensureRequestBodyInitialized();
this.requestBody.put("page_no", pageNo);
this.requestBody.put("page_size", pageSize);
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,66 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
/**
* 查询商品属性请求
*
* 对应接口POST /api/open/product/pv/list
* 请求体字段:
* - item_biz_type必填商品类型
* - sp_biz_type必填行业类型
* - channel_cat_id必填渠道类目ID
* - sub_property_id选填属性值ID用于二级属性查询
*/
public class ProductPropertyListQueryRequest extends ERPRequestBase {
public ProductPropertyListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/pv/list", erpAccount);
}
/**
* 设置商品类型(必填)
* @param itemBizType 商品类型
*/
public void setItemBizType(int itemBizType) {
ensureRequestBodyInitialized();
this.requestBody.put("item_biz_type", itemBizType);
}
/**
* 设置行业类型(必填)
* @param spBizType 行业类型
*/
public void setSpBizType(int spBizType) {
ensureRequestBodyInitialized();
this.requestBody.put("sp_biz_type", spBizType);
}
/**
* 设置渠道类目ID必填
* @param channelCatId 渠道类目ID
*/
public void setChannelCatId(String channelCatId) {
ensureRequestBodyInitialized();
this.requestBody.put("channel_cat_id", channelCatId);
}
/**
* 设置下级属性ID选填
* @param subPropertyId 下级属性ID
*/
public void setSubPropertyId(String subPropertyId) {
if (subPropertyId == null || subPropertyId.isEmpty()) {
return;
}
ensureRequestBodyInitialized();
this.requestBody.put("sub_property_id", subPropertyId);
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,45 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
/**
* 上架商品请求
*
* 对应接口POST /api/open/product/publish
*/
public class ProductPublishRequest extends ERPRequestBase {
public ProductPublishRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/publish", erpAccount);
}
public void setProductId(long productId) {
ensureBody();
this.requestBody.put("product_id", productId);
}
public void setUserName(String userName) {
ensureBody();
JSONArray arr = new JSONArray();
arr.add(userName);
this.requestBody.put("user_name", arr);
}
public void setSpecifyPublishTime(String time) {
if (time == null) return;
ensureBody();
this.requestBody.put("specify_publish_time", time);
}
public void setNotifyUrl(String notifyUrl) {
if (notifyUrl == null) return;
ensureBody();
this.requestBody.put("notify_url", notifyUrl);
}
private void ensureBody() {
if (this.requestBody == null) this.requestBody = new JSONObject();
}
}

View File

@@ -0,0 +1,58 @@
package com.ruoyi.erp.request;
import com.alibaba.fastjson2.JSONObject;
import java.util.Collection;
/**
* 查询商品规格请求(仅多规格商品)
*
* 对应接口POST /api/open/product/sku/list
* 请求体字段:
* - product_id必填管家商品ID数组最多100个
*/
public class ProductSkuListQueryRequest extends ERPRequestBase {
public ProductSkuListQueryRequest(ERPAccount erpAccount) {
super("https://open.goofish.pro/api/open/product/sku/list", erpAccount);
}
/**
* 设置商品ID数组必填最多100个
*/
public void setProductIds(long... productIds) {
if (productIds == null || productIds.length == 0) {
throw new IllegalArgumentException("productIds不能为空");
}
if (productIds.length > 100) {
throw new IllegalArgumentException("productIds数量不能超过100");
}
ensureRequestBodyInitialized();
this.requestBody.put("product_id", productIds);
}
/**
* 设置商品ID集合必填最多100个
*/
public void setProductIds(Collection<Long> productIds) {
if (productIds == null || productIds.isEmpty()) {
throw new IllegalArgumentException("productIds不能为空");
}
if (productIds.size() > 100) {
throw new IllegalArgumentException("productIds数量不能超过100");
}
long[] ids = new long[productIds.size()];
int i = 0;
for (Long id : productIds) {
ids[i++] = id == null ? 0L : id;
}
setProductIds(ids);
}
private void ensureRequestBodyInitialized() {
if (this.requestBody == null) {
this.requestBody = new JSONObject();
}
}
}

View File

@@ -0,0 +1,17 @@
package com.ruoyi.erp.request;
/**
* @author Leo
* @version 1.0
* @create 2025/8/16 19:02
* @description
*/
public class RequestDemo {
public static void main(String[] args) {
ERPAccount erpAccount = ERPAccount.ACCOUNT_HUGE;
ProductListQueryRequest request = new ProductListQueryRequest(erpAccount);
String responseBody = request.getResponseBody();
System.out.println("响应结果: " + responseBody);
}
}