更新逻辑修改

This commit is contained in:
liyj 2025-11-08 10:11:17 +08:00
parent c8a85d5119
commit 0152518315
5 changed files with 73 additions and 22 deletions

View File

@ -99,13 +99,22 @@ public class DynamicTaskScheduler {
if(dataBaseInfo==null||StringUtils.isEmpty(dataBaseInfo.getUserName())){ if(dataBaseInfo==null||StringUtils.isEmpty(dataBaseInfo.getUserName())){
return; return;
} }
String refreshTime="";
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); refreshTime=DateUtil.formatDateTime(dataBaseInfo.getRefreshTime());
commentModel.setSyncTime(refreshTime);
} }
sxDataService.syncStoreData(dataBaseInfo,commentModel); sxDataService.syncStoreData(dataBaseInfo,commentModel);
sxDataService.SyncBranchList(dataBaseInfo,commentModel); if(StringUtils.isNotEmpty(refreshTime)){//有刷新时间证明不是全量需要判断是否有新商品有新商品才同步品牌和分类
sxDataService.SyncCategory(dataBaseInfo,commentModel); if(sxDataService.isNewShop(dataBaseInfo,refreshTime)){
sxDataService.SyncBranchList(dataBaseInfo,commentModel);
sxDataService.SyncCategory(dataBaseInfo,commentModel);
}
}else {
log.info("首次同步,无刷新时间");
sxDataService.SyncBranchList(dataBaseInfo,commentModel);
sxDataService.SyncCategory(dataBaseInfo,commentModel);
}
sxDataService.SyncGoods(dataBaseInfo,commentModel);//todo 暂时同步全部的商品如果后期修改需要增加服务器的字段 sxDataService.SyncGoods(dataBaseInfo,commentModel);//todo 暂时同步全部的商品如果后期修改需要增加服务器的字段
try { try {
if(ObjectUtil.isNotEmpty(dataBaseInfo.getShopGapTime())){ if(ObjectUtil.isNotEmpty(dataBaseInfo.getShopGapTime())){
@ -117,9 +126,18 @@ public class DynamicTaskScheduler {
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(refreshTime);
}
sxDataService.SyncVipList(dataBaseInfo,commentModel); sxDataService.SyncVipList(dataBaseInfo,commentModel);
sxDataService.syncAtive(dataBaseInfo,commentModel); boolean isNewActives=sxDataService.syncAtive(dataBaseInfo,commentModel);
sxDataService.syncAtiveShops(dataBaseInfo,commentModel); if(isNewActives){
log.info("---有新增的活动,同步活动商品开始--");
sxDataService.syncAtiveShops(dataBaseInfo,commentModel);
}else {
log.info("---无新增的活动,无需同步活动商品--");
}
isRuning=false; isRuning=false;
} }

View File

@ -526,7 +526,7 @@ public class SxDataDao extends BaseDao{
if(stock_qty.compareTo(BigDecimal.ZERO)==0){ if(stock_qty.compareTo(BigDecimal.ZERO)==0){
continue; continue;
} }
ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(itemNo); ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(key);
if(productQuantityConsumptionDto.getSaleAmount().compareTo(BigDecimal.ZERO)==0){ if(productQuantityConsumptionDto.getSaleAmount().compareTo(BigDecimal.ZERO)==0){
continue; continue;
} }

View File

@ -42,4 +42,9 @@ public class ItemInfo {
* 进货价格 * 进货价格
*/ */
private BigDecimal price; private BigDecimal price;
/**
* 零售价
*/
private BigDecimal salePrice;
} }

View File

@ -63,7 +63,7 @@ public interface SxDataService {
* @param commentModel * @param commentModel
* @return * @return
*/ */
void syncAtive(DataBaseInfo dataBaseInfo,CommentModel commentModel); boolean syncAtive(DataBaseInfo dataBaseInfo,CommentModel commentModel);
/** /**
* 同步活动商品 * 同步活动商品
@ -73,4 +73,12 @@ public interface SxDataService {
void syncAtiveShops(DataBaseInfo dataBaseInfo,CommentModel commentModel); void syncAtiveShops(DataBaseInfo dataBaseInfo,CommentModel commentModel);
String getCategoryChildren(DataBaseInfo dataBaseInfo,String parentId); String getCategoryChildren(DataBaseInfo dataBaseInfo,String parentId);
/**
* 校验是否有新的入库
* @param dataBaseInfo
* @param refreshTime
* @return
*/
boolean isNewShop(DataBaseInfo dataBaseInfo, String refreshTime);
} }

View File

@ -134,10 +134,10 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
break; break;
case "02"://增量 todo test case "02"://增量 todo test
String sycnTime=commentModel.getSyncTime(); String sycnTime=commentModel.getSyncTime();
syncIncrementAddGoods(dataBaseInfo, commentModel); syncIncrementAddGoods(dataBaseInfo, commentModel);//同步新商品
// syncIncrementModifyGoods(dataBaseInfo, commentModel); // syncIncrementModifyGoods(dataBaseInfo, commentModel);
syncIncrementStock(dataBaseInfo, commentModel); syncIncrementStock(dataBaseInfo, commentModel);//同步库存
syncFlowPrice(dataBaseInfo, commentModel,sycnTime); syncFlowPrice(dataBaseInfo, commentModel,sycnTime);//同步调价单
break; break;
} }
@ -310,6 +310,22 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
return root; return root;
} }
/**
* 判断是否有新增商品有新增商品才同步分类
* @param dataBaseInfo
* @param refreshTime
* @return
*/
public boolean isNewShop(DataBaseInfo dataBaseInfo, String refreshTime){
String where="where b.status='1' ";
where+=" and ( b.modify_date>'"+refreshTime+"' ";
where+=" or b.build_date>'"+refreshTime+"') ";
dataBaseInfo.setWhere(where);
int total = sxDataDao.getTBditemInfoTotal(dataBaseInfo);
log.info("判断库存数量,库存数量:{}",total);
return total>0;
}
/** /**
*同步所有商品 *同步所有商品
* @param dataBaseInfo * @param dataBaseInfo
@ -340,11 +356,11 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
" shop.item_no " + " shop.item_no " +
" from " + " from " +
" t_pc_price_flow_detail tpfd " + " t_pc_price_flow_detail tpfd " +
" inner join t_pc_price_flow_master tppfm " + " left join t_pc_price_flow_master tppfm " +
" on " + " on " +
" tpfd.sheet_no = tppfm.sheet_no " + " tpfd.sheet_no = tppfm.sheet_no " +
" where " + " where " +
" tppfm.valid_flag = '2' " +//有效 " tppfm.valid_flag = '1' " +//有效
" and shop.item_no=tpfd.item_no " + " and shop.item_no=tpfd.item_no " +
" and tppfm.oper_date >'"+dataBaseInfo.getPriceOperatime()+"' " + " and tppfm.oper_date >'"+dataBaseInfo.getPriceOperatime()+"' " +
" )"; " )";
@ -622,10 +638,10 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
log.info("文件下载目录: {}", downloadDirectory); log.info("文件下载目录: {}", downloadDirectory);
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
// headers.set("User-Agent", "Apifox/1.0.0 (https://apifox.com)"); // headers.set("User-Agent", "Apifox/1.0.0 (https://apifox.com)");
headers.setAccept(Collections.singletonList(MediaType.ALL)); // 对应 */* //headers.setAccept(Collections.singletonList(MediaType.ALL)); // 对应 */*
headers.set("Accept-Encoding", "gzip, deflate, br"); // headers.set("Accept-Encoding", "gzip, deflate, br");
// 可以添加其他Apifox可能发送的头部 // 可以添加其他Apifox可能发送的头部
headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8"); // headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
headers.set("Connection", "keep-alive"); headers.set("Connection", "keep-alive");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
@ -769,10 +785,13 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
JSONObject jsonObject= restTemplate.getForObject(remoteIp+HttpUtils.URL_SYNC_GET_STOR_DATA_RELEASE JSONObject jsonObject= restTemplate.getForObject(remoteIp+HttpUtils.URL_SYNC_GET_STOR_DATA_RELEASE
+"?appKey="+commentModel.getAppKey() +"?appKey="+commentModel.getAppKey()
+"&sign="+commentModel.getAppId(),JSONObject.class); +"&sign="+commentModel.getAppId(),JSONObject.class);
// String jsonStr="[{\"consumeId\":\"1986611923814223873\",\"orderId\":\"DD_20251107_1\",\"productNumber\":\"31011\",\"unitPrice\":10.90,\"quantity\":1.500,\"saleAmount\":16.35,\"status\":0,\"storeId\":78,\"createTime\":\"2025-11-07 01:49:26\",\"updateTime\":\"2025-11-07 01:49:26\"},{\"consumeId\":\"1986611923814223872\",\"orderId\":\"DD_20251107_2\",\"productNumber\":\"6909409023853\",\"unitPrice\":1.00,\"quantity\":1.000,\"saleAmount\":1.00,\"status\":0,\"storeId\":78,\"createTime\":\"2025-11-07 01:49:26\",\"updateTime\":\"2025-11-07 01:49:26\"},{\"consumeId\":\"1986611923814223874\",\"orderId\":\"DD_20251107_1\",\"productNumber\":\"6909409023853\",\"unitPrice\":1.00,\"quantity\":2.000,\"saleAmount\":2.00,\"status\":0,\"storeId\":78,\"createTime\":\"2025-11-07 01:49:26\",\"updateTime\":\"2025-11-07 01:49:26\"}]";
if(null!=jsonObject.get("result")){ if(null!=jsonObject.get("result")){
// Map map=(Map)jsonObject.get("result"); // Map map=(Map)jsonObject.get("result");
String jsonStr= jsonObject.getStr("result");
List<ProductQuantityConsumptionDto> productQuantityConsumptionDtoList = List<ProductQuantityConsumptionDto> productQuantityConsumptionDtoList =
JSONUtil.toList(jsonObject.getStr("result"),ProductQuantityConsumptionDto.class); JSONUtil.toList(jsonStr,ProductQuantityConsumptionDto.class);
if(!productQuantityConsumptionDtoList.isEmpty()){ if(!productQuantityConsumptionDtoList.isEmpty()){
Map map = productQuantityConsumptionDtoList.stream() Map map = productQuantityConsumptionDtoList.stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
@ -786,17 +805,18 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
Map<String,ProductQuantityConsumptionDto> productQuantityConsumptionDtoMap=new HashMap<>(); Map<String,ProductQuantityConsumptionDto> productQuantityConsumptionDtoMap=new HashMap<>();
productQuantityConsumptionDtoList.forEach(productQuantityConsumptionDto -> { productQuantityConsumptionDtoList.forEach(productQuantityConsumptionDto -> {
productQuantityConsumptionDtoMap.put(productQuantityConsumptionDto.getProductNumber(),productQuantityConsumptionDto); productQuantityConsumptionDtoMap.put(productQuantityConsumptionDto.getOrderId()+"-"+productQuantityConsumptionDto.getProductNumber(),productQuantityConsumptionDto);
}); });
sxDataDao.updateStoreData(dataBaseInfo,map,productQuantityConsumptionDtoMap,productQuantityConsumptionDtoList,commentModel); sxDataDao.updateStoreData(dataBaseInfo,map,productQuantityConsumptionDtoMap,productQuantityConsumptionDtoList,commentModel);
}else {
log.info("无线上流水同步");
} }
} }
} }
@Override @Override
public void syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) { public boolean syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
String where="where 1=1"; String where="where 1=1";
Integer total =0; Integer total =0;
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
@ -807,7 +827,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
total = sxDataDao.getNewActiveCount(dataBaseInfo); total = sxDataDao.getNewActiveCount(dataBaseInfo);
if(total==0){ if(total==0){
log.info("暂无活动同步"); log.info("暂无活动同步");
return; return false;
} }
// 总页数 // 总页数
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE); int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
@ -832,7 +852,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
syncCount+=activeDtos.size(); syncCount+=activeDtos.size();
} }
log.info("成功同步活动数据:"+syncCount); log.info("成功同步活动数据:"+syncCount);
return true;
} }
@Override @Override