From 015251831597e24c6d503ff73323eb8b94b52d34 Mon Sep 17 00:00:00 2001 From: liyj <1617420630@qq.com> Date: Sat, 8 Nov 2025 10:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/Schedule/DynamicTaskScheduler.java | 30 +++++++++--- .../java/com/small/client/dao/SxDataDao.java | 2 +- .../java/com/small/client/dto/ItemInfo.java | 5 ++ .../small/client/service/SxDataService.java | 10 +++- .../client/service/imp/SxDataServiceImp.java | 48 +++++++++++++------ 5 files changed, 73 insertions(+), 22 deletions(-) diff --git a/client/src/main/java/com/small/client/Schedule/DynamicTaskScheduler.java b/client/src/main/java/com/small/client/Schedule/DynamicTaskScheduler.java index 23b9bf55..40ef8277 100644 --- a/client/src/main/java/com/small/client/Schedule/DynamicTaskScheduler.java +++ b/client/src/main/java/com/small/client/Schedule/DynamicTaskScheduler.java @@ -99,13 +99,22 @@ public class DynamicTaskScheduler { if(dataBaseInfo==null||StringUtils.isEmpty(dataBaseInfo.getUserName())){ return; } + String refreshTime=""; if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ - commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); + refreshTime=DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()); + commentModel.setSyncTime(refreshTime); } - sxDataService.syncStoreData(dataBaseInfo,commentModel); - sxDataService.SyncBranchList(dataBaseInfo,commentModel); - sxDataService.SyncCategory(dataBaseInfo,commentModel); + if(StringUtils.isNotEmpty(refreshTime)){//有刷新时间,证明不是全量,需要判断是否有新商品,有新商品才同步品牌和分类 + 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 暂时同步全部的商品如果后期修改,需要增加服务器的字段 try { if(ObjectUtil.isNotEmpty(dataBaseInfo.getShopGapTime())){ @@ -117,9 +126,18 @@ public class DynamicTaskScheduler { } catch (InterruptedException e) { throw new RuntimeException(e); } + if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ + commentModel.setSyncTime(refreshTime); + } sxDataService.SyncVipList(dataBaseInfo,commentModel); - sxDataService.syncAtive(dataBaseInfo,commentModel); - sxDataService.syncAtiveShops(dataBaseInfo,commentModel); + boolean isNewActives=sxDataService.syncAtive(dataBaseInfo,commentModel); + if(isNewActives){ + log.info("---有新增的活动,同步活动商品开始--"); + sxDataService.syncAtiveShops(dataBaseInfo,commentModel); + }else { + log.info("---无新增的活动,无需同步活动商品--"); + } + isRuning=false; } diff --git a/client/src/main/java/com/small/client/dao/SxDataDao.java b/client/src/main/java/com/small/client/dao/SxDataDao.java index d9de60c4..6d004280 100644 --- a/client/src/main/java/com/small/client/dao/SxDataDao.java +++ b/client/src/main/java/com/small/client/dao/SxDataDao.java @@ -526,7 +526,7 @@ public class SxDataDao extends BaseDao{ if(stock_qty.compareTo(BigDecimal.ZERO)==0){ continue; } - ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(itemNo); + ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(key); if(productQuantityConsumptionDto.getSaleAmount().compareTo(BigDecimal.ZERO)==0){ continue; } diff --git a/client/src/main/java/com/small/client/dto/ItemInfo.java b/client/src/main/java/com/small/client/dto/ItemInfo.java index c422e7ec..22c10a59 100644 --- a/client/src/main/java/com/small/client/dto/ItemInfo.java +++ b/client/src/main/java/com/small/client/dto/ItemInfo.java @@ -42,4 +42,9 @@ public class ItemInfo { * 进货价格 */ private BigDecimal price; + + /** + * 零售价 + */ + private BigDecimal salePrice; } diff --git a/client/src/main/java/com/small/client/service/SxDataService.java b/client/src/main/java/com/small/client/service/SxDataService.java index 39b2e623..adc2ee3d 100644 --- a/client/src/main/java/com/small/client/service/SxDataService.java +++ b/client/src/main/java/com/small/client/service/SxDataService.java @@ -63,7 +63,7 @@ public interface SxDataService { * @param commentModel * @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); String getCategoryChildren(DataBaseInfo dataBaseInfo,String parentId); + + /** + * 校验是否有新的入库 + * @param dataBaseInfo + * @param refreshTime + * @return + */ + boolean isNewShop(DataBaseInfo dataBaseInfo, String refreshTime); } diff --git a/client/src/main/java/com/small/client/service/imp/SxDataServiceImp.java b/client/src/main/java/com/small/client/service/imp/SxDataServiceImp.java index 6aae15ee..93842264 100644 --- a/client/src/main/java/com/small/client/service/imp/SxDataServiceImp.java +++ b/client/src/main/java/com/small/client/service/imp/SxDataServiceImp.java @@ -134,10 +134,10 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService break; case "02"://增量 todo test String sycnTime=commentModel.getSyncTime(); - syncIncrementAddGoods(dataBaseInfo, commentModel); + syncIncrementAddGoods(dataBaseInfo, commentModel);//同步新商品 // syncIncrementModifyGoods(dataBaseInfo, commentModel); - syncIncrementStock(dataBaseInfo, commentModel); - syncFlowPrice(dataBaseInfo, commentModel,sycnTime); + syncIncrementStock(dataBaseInfo, commentModel);//同步库存 + syncFlowPrice(dataBaseInfo, commentModel,sycnTime);//同步调价单 break; } @@ -310,6 +310,22 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService 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 @@ -340,11 +356,11 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService " shop.item_no " + " from " + " t_pc_price_flow_detail tpfd " + - " inner join t_pc_price_flow_master tppfm " + + " left join t_pc_price_flow_master tppfm " + " on " + " tpfd.sheet_no = tppfm.sheet_no " + " where " + - " tppfm.valid_flag = '2' " +//有效 + " tppfm.valid_flag = '1' " +//有效 " and shop.item_no=tpfd.item_no " + " and tppfm.oper_date >'"+dataBaseInfo.getPriceOperatime()+"' " + " )"; @@ -622,10 +638,10 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService log.info("文件下载目录: {}", downloadDirectory); HttpHeaders headers = new HttpHeaders(); // headers.set("User-Agent", "Apifox/1.0.0 (https://apifox.com)"); - headers.setAccept(Collections.singletonList(MediaType.ALL)); // 对应 */* - headers.set("Accept-Encoding", "gzip, deflate, br"); + //headers.setAccept(Collections.singletonList(MediaType.ALL)); // 对应 */* + // headers.set("Accept-Encoding", "gzip, deflate, br"); // 可以添加其他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"); HttpEntity> 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 +"?appKey="+commentModel.getAppKey() +"&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")){ // Map map=(Map)jsonObject.get("result"); + String jsonStr= jsonObject.getStr("result"); List productQuantityConsumptionDtoList = - JSONUtil.toList(jsonObject.getStr("result"),ProductQuantityConsumptionDto.class); + JSONUtil.toList(jsonStr,ProductQuantityConsumptionDto.class); if(!productQuantityConsumptionDtoList.isEmpty()){ Map map = productQuantityConsumptionDtoList.stream() .collect(Collectors.groupingBy( @@ -786,17 +805,18 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService Map productQuantityConsumptionDtoMap=new HashMap<>(); productQuantityConsumptionDtoList.forEach(productQuantityConsumptionDto -> { - productQuantityConsumptionDtoMap.put(productQuantityConsumptionDto.getProductNumber(),productQuantityConsumptionDto); + productQuantityConsumptionDtoMap.put(productQuantityConsumptionDto.getOrderId()+"-"+productQuantityConsumptionDto.getProductNumber(),productQuantityConsumptionDto); }); sxDataDao.updateStoreData(dataBaseInfo,map,productQuantityConsumptionDtoMap,productQuantityConsumptionDtoList,commentModel); + }else { + log.info("无线上流水同步"); } - } } @Override - public void syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) { + public boolean syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) { String where="where 1=1"; Integer total =0; if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ @@ -807,7 +827,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService total = sxDataDao.getNewActiveCount(dataBaseInfo); if(total==0){ log.info("暂无活动同步"); - return; + return false; } // 总页数 int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE); @@ -832,7 +852,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService syncCount+=activeDtos.size(); } log.info("成功同步活动数据:"+syncCount); - + return true; } @Override