1
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.web.controller.jarvis;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
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.ProductJdConfig;
|
||||
import com.ruoyi.jarvis.service.IProductJdConfigService;
|
||||
|
||||
/**
|
||||
* 产品京东配置Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/jarvis/productJdConfig")
|
||||
public class ProductJdConfigController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProductJdConfigService productJdConfigService;
|
||||
|
||||
/**
|
||||
* 查询产品京东配置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:list')")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list()
|
||||
{
|
||||
List<ProductJdConfig> list = productJdConfigService.selectProductJdConfigList();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品京东配置详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:query')")
|
||||
@GetMapping(value = "/{productModel}")
|
||||
public AjaxResult getInfo(@PathVariable("productModel") String productModel)
|
||||
{
|
||||
return success(productJdConfigService.selectProductJdConfigByModel(productModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品京东配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:add')")
|
||||
@Log(title = "产品京东配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ProductJdConfig productJdConfig)
|
||||
{
|
||||
// 检查是否已存在
|
||||
ProductJdConfig existing = productJdConfigService.selectProductJdConfigByModel(productJdConfig.getProductModel());
|
||||
if (existing != null) {
|
||||
return error("产品型号已存在");
|
||||
}
|
||||
return toAjax(productJdConfigService.insertProductJdConfig(productJdConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品京东配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:edit')")
|
||||
@Log(title = "产品京东配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ProductJdConfig productJdConfig)
|
||||
{
|
||||
return toAjax(productJdConfigService.updateProductJdConfig(productJdConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品京东配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:remove')")
|
||||
@Log(title = "产品京东配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{productModels}")
|
||||
public AjaxResult remove(@PathVariable String[] productModels)
|
||||
{
|
||||
return toAjax(productJdConfigService.deleteProductJdConfigByModels(productModels));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化默认数据
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('jarvis:productJdConfig:init')")
|
||||
@Log(title = "产品京东配置", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/initData")
|
||||
public AjaxResult initData()
|
||||
{
|
||||
productJdConfigService.initDefaultData();
|
||||
return success("初始化成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.ruoyi.jarvis.domain;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 产品京东配置对象
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ProductJdConfig extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 产品型号 */
|
||||
private String productModel;
|
||||
|
||||
/** 京东链接 */
|
||||
private String jdUrl;
|
||||
|
||||
/** 佣金 */
|
||||
private BigDecimal commission;
|
||||
|
||||
public ProductJdConfig() {
|
||||
}
|
||||
|
||||
public ProductJdConfig(String productModel, String jdUrl, BigDecimal commission) {
|
||||
this.productModel = productModel;
|
||||
this.jdUrl = jdUrl;
|
||||
this.commission = commission;
|
||||
}
|
||||
|
||||
public String getProductModel() {
|
||||
return productModel;
|
||||
}
|
||||
|
||||
public void setProductModel(String productModel) {
|
||||
this.productModel = productModel;
|
||||
}
|
||||
|
||||
public String getJdUrl() {
|
||||
return jdUrl;
|
||||
}
|
||||
|
||||
public void setJdUrl(String jdUrl) {
|
||||
this.jdUrl = jdUrl;
|
||||
}
|
||||
|
||||
public BigDecimal getCommission() {
|
||||
return commission;
|
||||
}
|
||||
|
||||
public void setCommission(BigDecimal commission) {
|
||||
this.commission = commission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProductJdConfig{" +
|
||||
"productModel='" + productModel + '\'' +
|
||||
", jdUrl='" + jdUrl + '\'' +
|
||||
", commission=" + commission +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.ruoyi.jarvis.service;
|
||||
|
||||
import com.ruoyi.jarvis.domain.ProductJdConfig;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品京东配置Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IProductJdConfigService
|
||||
{
|
||||
/**
|
||||
* 查询产品京东配置列表
|
||||
*
|
||||
* @return 产品京东配置集合
|
||||
*/
|
||||
public List<ProductJdConfig> selectProductJdConfigList();
|
||||
|
||||
/**
|
||||
* 查询产品京东配置
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 产品京东配置
|
||||
*/
|
||||
public ProductJdConfig selectProductJdConfigByModel(String productModel);
|
||||
|
||||
/**
|
||||
* 新增产品京东配置
|
||||
*
|
||||
* @param productJdConfig 产品京东配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertProductJdConfig(ProductJdConfig productJdConfig);
|
||||
|
||||
/**
|
||||
* 修改产品京东配置
|
||||
*
|
||||
* @param productJdConfig 产品京东配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateProductJdConfig(ProductJdConfig productJdConfig);
|
||||
|
||||
/**
|
||||
* 批量删除产品京东配置
|
||||
*
|
||||
* @param productModels 需要删除的产品型号集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductJdConfigByModels(String[] productModels);
|
||||
|
||||
/**
|
||||
* 删除产品京东配置信息
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductJdConfigByModel(String productModel);
|
||||
|
||||
/**
|
||||
* 根据产品型号获取京东链接
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 京东链接
|
||||
*/
|
||||
public String getJdUrlByProductModel(String productModel);
|
||||
|
||||
/**
|
||||
* 初始化默认数据
|
||||
*/
|
||||
public void initDefaultData();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
private SuperAdminService superAdminService;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private IProductJdConfigService productJdConfigService;
|
||||
|
||||
// 录单模板(与 jd/JDUtil 中 WENAN_D 保持一致)
|
||||
private static final String WENAN_D = "单:\n" + "{单号} \n备注:{单的备注}\n" + "分销标记:{分销标记}\n" + "型号:\n" + "{型号}\n" + "链接:\n" + "{链接}\n" + "下单付款:\n" + "\n" + "后返金额:\n" + "\n" + "地址:\n" + "{地址}\n" + "物流链接:\n" + "\n" + "订单号:\n" + "\n" + "下单人:\n" + "\n";
|
||||
@@ -333,19 +335,7 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
}
|
||||
|
||||
// ===== TF/H/生 处理 =====
|
||||
private static final HashMap<String, String> productWithJF = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
productWithJF.put("ZQD110F-EB031", "https://u.jd.com/0gGPOZX");
|
||||
productWithJF.put("ZQD130F-EB130", "https://u.jd.com/0OGTvHh");
|
||||
productWithJF.put("ZQD130F-EB130B", "https://u.jd.com/0GGWEOR");
|
||||
productWithJF.put("ZQD150F-EB150", "https://u.jd.com/0O8BYjb");
|
||||
productWithJF.put("ZQD180F-EB200", "https://u.jd.com/0gGSoiN");
|
||||
productWithJF.put("ZQD115F-12LCS", "https://u.jd.com/0DGSFcH");
|
||||
productWithJF.put("CXW-298-IQ92DPRO", "https://u.jd.com/0OG04su");
|
||||
productWithJF.put("CXW-358-EC970", "https://u.jd.com/0g8BB3a");
|
||||
}
|
||||
// 产品京东配置已迁移到Redis,通过productJdConfigService获取
|
||||
|
||||
private static final List<String> phoneWithTF = new ArrayList<>();
|
||||
|
||||
@@ -393,7 +383,7 @@ public class InstructionServiceImpl implements IInstructionService {
|
||||
for (int i = 4; i < parts.length; i++) {
|
||||
address.append(parts[i]);
|
||||
}
|
||||
String jf = productWithJF.get(modelNumber);
|
||||
String jf = productJdConfigService.getJdUrlByProductModel(modelNumber);
|
||||
|
||||
StringBuilder order = new StringBuilder();
|
||||
order.append("生").append("\n").append("H-TF").append("\n").append(modelNumber).append("\n").append(jf).append("\n").append(quantityStr).append("\n").append(address);
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.ruoyi.jarvis.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.jarvis.domain.ProductJdConfig;
|
||||
import com.ruoyi.jarvis.service.IProductJdConfigService;
|
||||
|
||||
/**
|
||||
* 产品京东配置Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class ProductJdConfigServiceImpl implements IProductJdConfigService
|
||||
{
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* Redis key前缀
|
||||
*/
|
||||
private static final String PRODUCT_JD_CONFIG_KEY = "product:jd:config:";
|
||||
|
||||
/**
|
||||
* 初始化默认数据
|
||||
*/
|
||||
@Override
|
||||
public void initDefaultData() {
|
||||
// 检查是否已经初始化
|
||||
if (redisCache.hasKey(PRODUCT_JD_CONFIG_KEY + "ZQD110F-EB031")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化原有的数据
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD110F-EB031", "https://u.jd.com/0gGPOZX", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD130F-EB130", "https://u.jd.com/0OGTvHh", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD130F-EB130B", "https://u.jd.com/0GGWEOR", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD150F-EB150", "https://u.jd.com/0O8BYjb", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD180F-EB200", "https://u.jd.com/0gGSoiN", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("ZQD115F-12LCS", "https://u.jd.com/0DGSFcH", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("CXW-298-IQ92DPRO", "https://u.jd.com/0OG04su", BigDecimal.ZERO));
|
||||
insertProductJdConfig(new ProductJdConfig("CXW-358-EC970", "https://u.jd.com/0g8BB3a", BigDecimal.ZERO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品京东配置列表
|
||||
*
|
||||
* @return 产品京东配置
|
||||
*/
|
||||
@Override
|
||||
public List<ProductJdConfig> selectProductJdConfigList()
|
||||
{
|
||||
List<ProductJdConfig> list = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> keys = (Set<String>) redisTemplate().keys(PRODUCT_JD_CONFIG_KEY + "*");
|
||||
if (keys != null && !keys.isEmpty()) {
|
||||
for (String key : keys) {
|
||||
ProductJdConfig config = mapToConfig(key);
|
||||
if (config != null) {
|
||||
list.add(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Redis Map转换为ProductJdConfig对象
|
||||
*/
|
||||
private ProductJdConfig mapToConfig(String key) {
|
||||
Map<String, Object> map = redisCache.getCacheMap(key);
|
||||
if (map != null && !map.isEmpty()) {
|
||||
ProductJdConfig config = new ProductJdConfig();
|
||||
config.setProductModel((String) map.get("productModel"));
|
||||
config.setJdUrl((String) map.get("jdUrl"));
|
||||
Object commissionObj = map.get("commission");
|
||||
if (commissionObj != null) {
|
||||
if (commissionObj instanceof BigDecimal) {
|
||||
config.setCommission((BigDecimal) commissionObj);
|
||||
} else if (commissionObj instanceof Number) {
|
||||
config.setCommission(new BigDecimal(commissionObj.toString()));
|
||||
} else {
|
||||
config.setCommission(new BigDecimal(commissionObj.toString()));
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品京东配置
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 产品京东配置
|
||||
*/
|
||||
@Override
|
||||
public ProductJdConfig selectProductJdConfigByModel(String productModel)
|
||||
{
|
||||
return mapToConfig(PRODUCT_JD_CONFIG_KEY + productModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品京东配置
|
||||
*
|
||||
* @param productJdConfig 产品京东配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertProductJdConfig(ProductJdConfig productJdConfig)
|
||||
{
|
||||
if (StringUtils.isEmpty(productJdConfig.getProductModel())) {
|
||||
return 0;
|
||||
}
|
||||
Map<String, Object> map = new java.util.HashMap<>();
|
||||
map.put("productModel", productJdConfig.getProductModel());
|
||||
map.put("jdUrl", productJdConfig.getJdUrl());
|
||||
map.put("commission", productJdConfig.getCommission() != null ? productJdConfig.getCommission() : BigDecimal.ZERO);
|
||||
redisCache.setCacheMap(PRODUCT_JD_CONFIG_KEY + productJdConfig.getProductModel(), map);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品京东配置
|
||||
*
|
||||
* @param productJdConfig 产品京东配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateProductJdConfig(ProductJdConfig productJdConfig)
|
||||
{
|
||||
return insertProductJdConfig(productJdConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除产品京东配置
|
||||
*
|
||||
* @param productModels 需要删除的产品型号
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteProductJdConfigByModels(String[] productModels)
|
||||
{
|
||||
int count = 0;
|
||||
for (String productModel : productModels) {
|
||||
if (redisCache.deleteObject(PRODUCT_JD_CONFIG_KEY + productModel)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品京东配置信息
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteProductJdConfigByModel(String productModel)
|
||||
{
|
||||
return redisCache.deleteObject(PRODUCT_JD_CONFIG_KEY + productModel) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品型号获取京东链接
|
||||
*
|
||||
* @param productModel 产品型号
|
||||
* @return 京东链接
|
||||
*/
|
||||
@Override
|
||||
public String getJdUrlByProductModel(String productModel)
|
||||
{
|
||||
ProductJdConfig config = selectProductJdConfigByModel(productModel);
|
||||
return config != null ? config.getJdUrl() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取RedisTemplate
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private org.springframework.data.redis.core.RedisTemplate redisTemplate() {
|
||||
return redisCache.redisTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user