Browse Source

1.商品录入添加校验 同一个url只能录入一个

2.预警结果生成添加校验
3.拉取商品最新信息后同时修改预警结果的商品信息
wq_dev
wangqiang 1 month ago
parent
commit
7a0a5740ea

+ 4
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/ZsOperationWarnresult.java View File

* 商品编号 * 商品编号
*/ */
private String goodsSkuSn; private String goodsSkuSn;
/**
* 商品url
*/
private String goodsSkuUrl;
/** /**
* 基准价格 * 基准价格
*/ */

+ 5
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/ZsOperationWarnresultBo.java View File

*/ */
private String goodsSkuSn; private String goodsSkuSn;


/**
* 商品url
*/
private String goodsSkuUrl;

/** /**
* 基准价格 * 基准价格
*/ */

+ 6
- 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/ZsOperationWarnresultVo.java View File

@ExcelProperty(value = "商品编号") @ExcelProperty(value = "商品编号")
private String goodsSkuSn; private String goodsSkuSn;


/**
* 商品url
*/
@ExcelProperty(value = "商品url")
private String goodsSkuUrl;

/** /**
* 基准价格 * 基准价格
*/ */

+ 14
- 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ZsOperationGoodsServiceImpl.java View File

package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;


import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.PageQuery;
@Override @Override
public Boolean insertByBo(ZsOperationGoodsBo bo) { public Boolean insertByBo(ZsOperationGoodsBo bo) {
ZsOperationGoods add = BeanUtil.toBean(bo, ZsOperationGoods.class); ZsOperationGoods add = BeanUtil.toBean(bo, ZsOperationGoods.class);
if (StringUtils.isBlank(add.getGoodsSkuUrl())) {
throw new RuntimeException("商品url不能为空");
}
//去空
add.setGoodsSkuUrl(add.getGoodsSkuUrl().trim());
//相同url商品只能录入一个
QueryWrapper<ZsOperationGoods> queryWrapper = new QueryWrapper();
queryWrapper.eq("goods_sku_url",add.getGoodsSkuUrl());
List<ZsOperationGoods> list = baseMapper.selectList(queryWrapper);
if (list!=null&&list.size()>0) {
throw new RuntimeException("商品url已经存在了!");
}

//获取抓取的信息 //获取抓取的信息
Map<String, Object> reMap = HttpUtil.sendGetRequest(bo.getGoodsSkuUrl(),false,bo.getPlatform()); Map<String, Object> reMap = HttpUtil.sendGetRequest(bo.getGoodsSkuUrl(),false,bo.getPlatform());
if ((boolean)reMap.get("success")) { if ((boolean)reMap.get("success")) {

+ 32
- 1
ruoyi-system/src/main/java/com/ruoyi/system/task/MonitorTaskScheduler.java View File

for (ZsOperationGoods zsOperationGoods: zsOperationGoodsList) { for (ZsOperationGoods zsOperationGoods: zsOperationGoodsList) {
String curUrl = zsOperationGoods.getGoodsSkuUrl(); String curUrl = zsOperationGoods.getGoodsSkuUrl();
//3.根据url 获取商品最新信息 //3.根据url 获取商品最新信息
log.info("调用接口开始");
Map<String, Object> reMap = HttpUtil.sendGetRequest(curUrl,true,zsOperationGoods.getPlatform()); Map<String, Object> reMap = HttpUtil.sendGetRequest(curUrl,true,zsOperationGoods.getPlatform());
log.info("调用接口结束");
if ((boolean)reMap.get("success")) { if ((boolean)reMap.get("success")) {
List dataList = (List)reMap.get("data"); List dataList = (List)reMap.get("data");
Map dataMap = (Map)dataList.get(0); Map dataMap = (Map)dataList.get(0);
zsOperationGoods.setGoodsSkuName(newName); zsOperationGoods.setGoodsSkuName(newName);
zsOperationGoods.setGoodsSkuSn(newSn); zsOperationGoods.setGoodsSkuSn(newSn);
zsOperationGoods.setRemark(newRemark); zsOperationGoods.setRemark(newRemark);
//4.更新商品信息
//4.更新商品表和预警结果表信息
zsOperationGoodsMapper.update(zsOperationGoods,new UpdateWrapper<>()); zsOperationGoodsMapper.update(zsOperationGoods,new UpdateWrapper<>());
UpdateWrapper<ZsOperationWarnresult> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("goods_sku_url",curUrl);
updateWrapper.set("goods_sku_name",newName);
updateWrapper.set("goods_sku_sn",newSn);
zsOperationWarnresultMapper.update(null,updateWrapper);




String newPriceStr = (String)dataMap.get("price"); String newPriceStr = (String)dataMap.get("price");
BigDecimal newPrice = new BigDecimal(newPriceStr); BigDecimal newPrice = new BigDecimal(newPriceStr);
//如果新价格大于0 //如果新价格大于0
if (newPrice.compareTo(BigDecimal.ZERO) > 0) { if (newPrice.compareTo(BigDecimal.ZERO) > 0) {
//判断这个商品最新的价格是否已经存在预警结果表了,如果在不发送消息和生成结果
if (checkIsExistsWarnResult(curUrl,newPrice)) {
log.info("已经存在预警结果表,并且价格没有再次变化,不记录 url=:"+curUrl);
continue;
}

//获取基准价格 //获取基准价格
BigDecimal initPrice = zsOperationGoods.getInitPrice(); BigDecimal initPrice = zsOperationGoods.getInitPrice();
//5. 获取基准价格和最新价格的差值比例 //5. 获取基准价格和最新价格的差值比例
zsOperationWarnresult.setWarnTime(new Date()); zsOperationWarnresult.setWarnTime(new Date());
zsOperationWarnresult.setGoodsSkuName(zsOperationGoods.getGoodsSkuName()); zsOperationWarnresult.setGoodsSkuName(zsOperationGoods.getGoodsSkuName());
zsOperationWarnresult.setGoodsSkuSn(zsOperationGoods.getGoodsSkuSn()); zsOperationWarnresult.setGoodsSkuSn(zsOperationGoods.getGoodsSkuSn());
zsOperationWarnresult.setGoodsSkuUrl(curUrl);
zsOperationWarnresult.setInitPrice(initPrice); zsOperationWarnresult.setInitPrice(initPrice);
zsOperationWarnresult.setCurPrice(newPrice); zsOperationWarnresult.setCurPrice(newPrice);
zsOperationWarnresult.setPriceChangeRatio(percentageChange.toString()); zsOperationWarnresult.setPriceChangeRatio(percentageChange.toString());
zsOperationWarnresult.setWarnTime(new Date()); zsOperationWarnresult.setWarnTime(new Date());
zsOperationWarnresult.setGoodsSkuName(zsOperationGoods.getGoodsSkuName()); zsOperationWarnresult.setGoodsSkuName(zsOperationGoods.getGoodsSkuName());
zsOperationWarnresult.setGoodsSkuSn(zsOperationGoods.getGoodsSkuSn()); zsOperationWarnresult.setGoodsSkuSn(zsOperationGoods.getGoodsSkuSn());
zsOperationWarnresult.setGoodsSkuUrl(curUrl);
zsOperationWarnresult.setInitPrice(zsOperationGoods.getInitPrice()); zsOperationWarnresult.setInitPrice(zsOperationGoods.getInitPrice());
zsOperationWarnresult.setCurPrice(null); zsOperationWarnresult.setCurPrice(null);
zsOperationWarnresult.setPriceChangeRatio(""); zsOperationWarnresult.setPriceChangeRatio("");
// 判断当前时间是否在 [9:00, 18:00] 区间(包含边界) // 判断当前时间是否在 [9:00, 18:00] 区间(包含边界)
return !currentTime.isBefore(startTime) && !currentTime.isAfter(endTime); return !currentTime.isBefore(startTime) && !currentTime.isAfter(endTime);
} }
public boolean checkIsExistsWarnResult(String url,BigDecimal newPrice) {
boolean isExists = false;
QueryWrapper<ZsOperationWarnresult> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("goods_sku_url",url);
queryWrapper.eq("status",0);
queryWrapper.orderByDesc("warn_time");
List<ZsOperationWarnresult> list = zsOperationWarnresultMapper.selectList(queryWrapper);
if (list!=null&&list.size()>0) {
ZsOperationWarnresult zsOperationWarnresult = list.get(0);
BigDecimal curPrice = zsOperationWarnresult.getCurPrice();
if (curPrice!=null&&newPrice.compareTo(curPrice)==0) {
isExists = true;
}
}
return isExists;
}


} }

+ 5
- 1
ruoyi-system/src/main/java/com/ruoyi/system/utils/HttpUtil.java View File

package com.ruoyi.system.utils; package com.ruoyi.system.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
//调用获取商品信息工具类 //调用获取商品信息工具类
@Component @Component
@Slf4j
public class HttpUtil { public class HttpUtil {
private static String BASE_URL; private static String BASE_URL;


* @return 响应结果 * @return 响应结果
*/ */
public static Map<String, Object> sendGetRequest(String url, boolean needScreenshot,String platform) { public static Map<String, Object> sendGetRequest(String url, boolean needScreenshot,String platform) {
Long start = System.currentTimeMillis();
try { try {
// 构建请求URL和参数 // 构建请求URL和参数
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(BASE_URL) UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(BASE_URL)
// 发送GET请求 // 发送GET请求
ResponseEntity<Map> response = restTemplate.getForEntity(builder.toUriString(), Map.class); ResponseEntity<Map> response = restTemplate.getForEntity(builder.toUriString(), Map.class);
Map body = response.getBody(); Map body = response.getBody();
Long end = System.currentTimeMillis();
log.info("调用获取商品最新信息接口耗时=:"+(end-start));
return body; return body;
} catch (Exception e) { } catch (Exception e) {
Map<String, Object> reMap = new HashMap<>(); Map<String, Object> reMap = new HashMap<>();

Loading…
Cancel
Save