This commit is contained in:
Leo
2025-11-13 23:38:30 +08:00
parent 8889791a83
commit 2cd3a0a798
9 changed files with 1343 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ import com.ruoyi.erp.request.ProductCategoryListQueryRequest;
import com.ruoyi.erp.request.ProductPropertyListQueryRequest;
import com.ruoyi.erp.request.AuthorizeListQueryRequest;
import com.ruoyi.erp.request.ProductPublishRequest;
import com.ruoyi.erp.request.ProductDownShelfRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -550,6 +551,217 @@ public class ProductController extends BaseController {
public String getAppid() { return appid; }
public void setAppid(String appid) { this.appid = appid; }
}
/**
* 下架商品(单个)
*/
@PostMapping("/downShelf")
public R<?> downShelf(@RequestBody @Validated DownShelfRequest req) {
try {
ERPAccount account = resolveAccount(req.getAppid());
ProductDownShelfRequest downShelfRequest = new ProductDownShelfRequest(account);
downShelfRequest.setProductId(req.getProductId());
String resp = downShelfRequest.getResponseBody();
JSONObject jo = JSONObject.parseObject(resp);
return R.ok(jo);
} catch (Exception e) {
log.error("下架商品失败: productId={}", req.getProductId(), e);
return R.fail("下架失败: " + e.getMessage());
}
}
/**
* 批量上架商品
*/
@PostMapping("/batchPublish")
public R<?> batchPublish(@RequestBody @Validated BatchPublishRequest req) {
try {
ERPAccount account = resolveAccount(req.getAppid());
List<Long> productIds = req.getProductIds();
if (productIds == null || productIds.isEmpty()) {
return R.fail("商品ID列表不能为空");
}
if (req.getUserName() == null || req.getUserName().isEmpty()) {
return R.fail("闲鱼会员名不能为空");
}
List<HashMap<String, Object>> results = new ArrayList<>();
int successCount = 0;
int failCount = 0;
for (Long productId : productIds) {
HashMap<String, Object> result = new HashMap<>();
result.put("productId", productId);
try {
ProductPublishRequest publishRequest = new ProductPublishRequest(account);
publishRequest.setProductId(productId);
publishRequest.setUserName(req.getUserName());
if (req.getSpecifyPublishTime() != null) {
publishRequest.setSpecifyPublishTime(req.getSpecifyPublishTime());
}
String resp = publishRequest.getResponseBody();
JSONObject jo = JSONObject.parseObject(resp);
if (jo != null && jo.getInteger("code") != null && jo.getInteger("code") == 0) {
result.put("success", true);
result.put("msg", "上架成功");
result.put("response", jo);
successCount++;
} else {
result.put("success", false);
result.put("msg", jo != null ? jo.getString("msg") : "上架失败");
result.put("response", jo);
failCount++;
}
} catch (Exception e) {
log.error("批量上架商品失败: productId={}", productId, e);
result.put("success", false);
result.put("msg", "上架异常: " + e.getMessage());
result.put("response", null);
failCount++;
}
results.add(result);
}
HashMap<String, Object> summary = new HashMap<>();
summary.put("total", productIds.size());
summary.put("success", successCount);
summary.put("fail", failCount);
summary.put("results", results);
JSONObject response = new JSONObject();
response.put("code", failCount == 0 ? 0 : 500);
response.put("msg", failCount == 0 ? "全部上架成功" : String.format("成功: %d, 失败: %d", successCount, failCount));
response.put("data", summary);
return R.ok(response);
} catch (Exception e) {
log.error("批量上架商品异常", e);
return R.fail("批量上架失败: " + e.getMessage());
}
}
/**
* 批量下架商品
*/
@PostMapping("/batchDownShelf")
public R<?> batchDownShelf(@RequestBody @Validated BatchDownShelfRequest req) {
try {
ERPAccount account = resolveAccount(req.getAppid());
List<Long> productIds = req.getProductIds();
if (productIds == null || productIds.isEmpty()) {
return R.fail("商品ID列表不能为空");
}
List<HashMap<String, Object>> results = new ArrayList<>();
int successCount = 0;
int failCount = 0;
for (Long productId : productIds) {
HashMap<String, Object> result = new HashMap<>();
result.put("productId", productId);
try {
ProductDownShelfRequest downShelfRequest = new ProductDownShelfRequest(account);
downShelfRequest.setProductId(productId);
String resp = downShelfRequest.getResponseBody();
JSONObject jo = JSONObject.parseObject(resp);
if (jo != null && jo.getInteger("code") != null && jo.getInteger("code") == 0) {
result.put("success", true);
result.put("msg", "下架成功");
result.put("response", jo);
successCount++;
} else {
result.put("success", false);
result.put("msg", jo != null ? jo.getString("msg") : "下架失败");
result.put("response", jo);
failCount++;
}
} catch (Exception e) {
log.error("批量下架商品失败: productId={}", productId, e);
result.put("success", false);
result.put("msg", "下架异常: " + e.getMessage());
result.put("response", null);
failCount++;
}
results.add(result);
}
HashMap<String, Object> summary = new HashMap<>();
summary.put("total", productIds.size());
summary.put("success", successCount);
summary.put("fail", failCount);
summary.put("results", results);
JSONObject response = new JSONObject();
response.put("code", failCount == 0 ? 0 : 500);
response.put("msg", failCount == 0 ? "全部下架成功" : String.format("成功: %d, 失败: %d", successCount, failCount));
response.put("data", summary);
return R.ok(response);
} catch (Exception e) {
log.error("批量下架商品异常", e);
return R.fail("批量下架失败: " + e.getMessage());
}
}
/**
* 下架请求体
*/
public static class DownShelfRequest {
@NotNull
private Long productId;
private String appid;
public Long getProductId() { return productId; }
public void setProductId(Long productId) { this.productId = productId; }
public String getAppid() { return appid; }
public void setAppid(String appid) { this.appid = appid; }
}
/**
* 批量上架请求体
*/
public static class BatchPublishRequest {
@NotNull
@Size(min = 1, message = "商品ID列表不能为空")
private List<Long> productIds;
@NotBlank(message = "闲鱼会员名不能为空")
private String userName;
private String specifyPublishTime;
private String appid;
public List<Long> getProductIds() { return productIds; }
public void setProductIds(List<Long> productIds) { this.productIds = productIds; }
public String getUserName() { return userName; }
public void setUserName(String userName) { this.userName = userName; }
public String getSpecifyPublishTime() { return specifyPublishTime; }
public void setSpecifyPublishTime(String specifyPublishTime) { this.specifyPublishTime = specifyPublishTime; }
public String getAppid() { return appid; }
public void setAppid(String appid) { this.appid = appid; }
}
/**
* 批量下架请求体
*/
public static class BatchDownShelfRequest {
@NotNull
@Size(min = 1, message = "商品ID列表不能为空")
private List<Long> productIds;
private String appid;
public List<Long> getProductIds() { return productIds; }
public void setProductIds(List<Long> productIds) { this.productIds = productIds; }
public String getAppid() { return appid; }
public void setAppid(String appid) { this.appid = appid; }
}
}

View File

@@ -0,0 +1,179 @@
package com.ruoyi.web.controller.jarvis;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jarvis.domain.ErpProduct;
import com.ruoyi.jarvis.service.IErpProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 闲鱼商品Controller
*
* @author ruoyi
* @date 2024-01-01
*/
@RestController
@RequestMapping("/jarvis/erpProduct")
public class ErpProductController extends BaseController
{
@Autowired
private IErpProductService erpProductService;
/**
* 查询闲鱼商品列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:list')")
@GetMapping("/list")
public TableDataInfo list(ErpProduct erpProduct)
{
startPage();
List<ErpProduct> list = erpProductService.selectErpProductList(erpProduct);
return getDataTable(list);
}
/**
* 导出闲鱼商品列表
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:export')")
@Log(title = "闲鱼商品", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(ErpProduct erpProduct)
{
List<ErpProduct> list = erpProductService.selectErpProductList(erpProduct);
ExcelUtil<ErpProduct> util = new ExcelUtil<ErpProduct>(ErpProduct.class);
return util.exportExcel(list, "闲鱼商品数据");
}
/**
* 获取闲鱼商品详细信息
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(erpProductService.selectErpProductById(id));
}
/**
* 新增闲鱼商品
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:add')")
@Log(title = "闲鱼商品", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ErpProduct erpProduct)
{
return toAjax(erpProductService.insertErpProduct(erpProduct));
}
/**
* 修改闲鱼商品
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:edit')")
@Log(title = "闲鱼商品", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ErpProduct erpProduct)
{
return toAjax(erpProductService.updateErpProduct(erpProduct));
}
/**
* 删除闲鱼商品
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:remove')")
@Log(title = "闲鱼商品", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(erpProductService.deleteErpProductByIds(ids));
}
/**
* 从闲鱼ERP拉取商品列表并保存
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:pull')")
@Log(title = "拉取闲鱼商品", businessType = BusinessType.INSERT)
@PostMapping("/pull")
public AjaxResult pullProductList(
@RequestParam(required = false) String appid,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "50") Integer pageSize,
@RequestParam(required = false) Integer productStatus)
{
try {
int count = erpProductService.pullAndSaveProductList(appid, pageNo, pageSize, productStatus);
return success("成功拉取并保存 " + count + " 个商品");
} catch (Exception e) {
return error("拉取商品列表失败: " + e.getMessage());
}
}
/**
* 批量上架商品
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:publish')")
@Log(title = "批量上架商品", businessType = BusinessType.UPDATE)
@PostMapping("/batchPublish")
public AjaxResult batchPublish(@RequestBody BatchOperationRequest request)
{
try {
return success("批量上架功能请调用 /erp/product/batchPublish 接口");
} catch (Exception e) {
return error("批量上架失败: " + e.getMessage());
}
}
/**
* 批量下架商品
*/
@PreAuthorize("@ss.hasPermi('jarvis:erpProduct:downShelf')")
@Log(title = "批量下架商品", businessType = BusinessType.UPDATE)
@PostMapping("/batchDownShelf")
public AjaxResult batchDownShelf(@RequestBody BatchOperationRequest request)
{
try {
return success("批量下架功能请调用 /erp/product/batchDownShelf 接口");
} catch (Exception e) {
return error("批量下架失败: " + e.getMessage());
}
}
/**
* 批量操作请求体
*/
public static class BatchOperationRequest {
private java.util.List<Long> productIds;
private String appid;
public java.util.List<Long> getProductIds() {
return productIds;
}
public void setProductIds(java.util.List<Long> productIds) {
this.productIds = productIds;
}
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
}
}