From c587ad55323c00ebedb797cb8f9031b3fef4ad1d Mon Sep 17 00:00:00 2001 From: liyj <1617420630@qq.com> Date: Sat, 2 Aug 2025 17:21:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/controller/WebController.java | 32 +++- .../java/com/small/client/dao/SxDataDao.java | 151 ++++++++++++++++++ .../small/client/service/SxDataService.java | 10 +- .../client/service/imp/SxDataServiceImp.java | 36 ++++- 4 files changed, 207 insertions(+), 22 deletions(-) diff --git a/client/src/main/java/com/small/client/controller/WebController.java b/client/src/main/java/com/small/client/controller/WebController.java index 9f8a53cc..21d45b73 100644 --- a/client/src/main/java/com/small/client/controller/WebController.java +++ b/client/src/main/java/com/small/client/controller/WebController.java @@ -21,9 +21,19 @@ public class WebController { @Autowired private SxDataService sxDataService; - @RequestMapping("/upload") + @RequestMapping("/test") public void upload(){ - System.out.println("upload"); + CommentModel commentModel= sxDataService.getCommentModel(); + DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel); + if(dataBaseInfo==null){ + log.error("syncGoods dataBaseInfo is null"); + return; + } + if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ + commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); + } + // sxDataService.getCategoryChildren(new DataBaseInfo(),"0101"); + System.out.println(sxDataService.getCategoryChildren(dataBaseInfo,"01")); //webClientService.uploudSxData(); } @@ -120,7 +130,19 @@ public class WebController { @RequestMapping("/syncStoreData") public void syncStoreData(){ - sxDataService.syncStoreData(new DataBaseInfo(),sxDataService.getCommentModel()); + CommentModel commentModel= sxDataService.getCommentModel(); + DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel); + if(dataBaseInfo==null){ + log.error("syncGoods dataBaseInfo is null"); + return; + } + if(StringUtils.isEmpty(commentModel.getSyncTime())){ + commentModel =sxDataService.getCommentModel(); + } + if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ + commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); + } + sxDataService.syncStoreData(dataBaseInfo,commentModel); } @@ -136,7 +158,7 @@ public class WebController { commentModel =sxDataService.getCommentModel(); } if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ - commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); + commentModel.setSyncTime(DateUtil.formatDate(dataBaseInfo.getRefreshTime())); } sxDataService.syncAtive(new DataBaseInfo(),commentModel); // sxDataService.syncAtive(new DataBaseInfo(),new CommentModel()); @@ -154,7 +176,7 @@ public class WebController { commentModel =sxDataService.getCommentModel(); } if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){ - commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime())); + commentModel.setSyncTime(DateUtil.formatDate(dataBaseInfo.getRefreshTime())); } sxDataService.syncAtiveShops(new DataBaseInfo(),commentModel); //sxDataService.syncAtiveShops(new DataBaseInfo(),new CommentModel()); 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 65ab27b4..ab583823 100644 --- a/client/src/main/java/com/small/client/dao/SxDataDao.java +++ b/client/src/main/java/com/small/client/dao/SxDataDao.java @@ -55,6 +55,9 @@ public class SxDataDao extends BaseDao{ public final static String DEFAULT_IMG="https://digitalassets.tesla.com/tesla-contents/image/upload/f_auto,q_auto/Homepage-Model-Y-2-Promo-Hero-Tablet-CN.png"; + private final static String T_PUB_PLAN_MASTER="t_pub_plan_master";//活动方案表 + private final static String T_PUB_PLAN_DETAIL_B="t_pub_plan_detail_b";//活动商品表 + private final static String PLAN_NO="plan_no";//活动方案表排序字段 /** * 查找商品分类数据 * @param dataBaseInfo @@ -601,6 +604,17 @@ public class SxDataDao extends BaseDao{ where); } + /** + * + * @param dataBaseInfo + * @return + */ + public Integer getNewActiveCount(DataBaseInfo dataBaseInfo){ + String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'"; + return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(), + T_PUB_PLAN_MASTER,where); + } + /** * * @param dataBaseInfo @@ -712,4 +726,141 @@ public class SxDataDao extends BaseDao{ return clsBrandDtos; } + + /** + *获取促销活动价格 时段特价单 + * @param dataBaseInfo + * DD-直接折扣 t_pub_plan_sendext t_pub_plan_detail_b + * PS-直接特价 t_pub_plan_detail_b + * PM-im促销 t_pub_plan_detail_b + * range_flag='I' 代表按商品维度促销 + * @return + */ + public List getNewActiveList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){ + String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'"; + ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp() + ,dataBaseInfo.getUserName() + ,dataBaseInfo.getPassword() + ,dataBaseInfo.getDbPort() + ,dataBaseInfo.getDataBaseName() + ,T_PUB_PLAN_MASTER + ,PLAN_NO + ,pageNo + ,pageSize + ,where); + ResultSet rs= resultDto.getResultSet(); + List activeDtos=new ArrayList<>(); + try { + while (rs.next()) { + ActiveDto activeDto=new ActiveDto(); + String specialType=rs.getString("rule_no").trim(); + String activityName=rs.getString("plan_name").trim(); + if(specialType.equals("DD")){//折扣 + activeDto.setActivityTypeId(2); + } + if(specialType.equals("PS")||specialType.equals("PM")){//特价(秒杀) + activeDto.setActivityTypeId(1); + } + if(specialType.equals("E")){//满减 todo + + } + activeDto.setActivityName(activityName); + activeDto.setActivity_remark(rs.getString("plan_memo").trim()); + activeDto.setFlowNo(rs.getString("plan_no")); + activeDto.setActivityReleasetime(rs.getDate("oper_date")); + activeDto.setActivityStarttime(rs.getDate("begin_date")); + activeDto.setActivityEndtime(rs.getDate("end_date")); + if(DateUtil.compare(activeDto.getActivityEndtime(),DateUtil.date())>0){ + activeDto.setActivityState(1);//正常进行中 + }else { + activeDto.setActivityState(2);//结束 + } + activeDtos.add(activeDto); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + resultDto.getConnection().close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + return activeDtos; + } + + + /** + * 获取折扣商品 + * @param dataBaseInfo + * @return + */ + public List getSpecShops(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){ + String where=dataBaseInfo.getWhere()+" and b.range_flag='I' and rule_no in('DD','PS','PM')"; + ResultDto resultDto=baseFindListJoinPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(), + T_PUB_PLAN_DETAIL_B,T_PUB_PLAN_MASTER,"plan_no","plan_no","flow_id","t.rule_no,t.plan_name,t.begin_date,t.end_date",pageNo,pageSize,where); + ResultSet rs= resultDto.getResultSet(); + List activeShopInfos=new ArrayList<>(); + try { + while (rs.next()) { + ActiveShopInfo activeShopInfo=new ActiveShopInfo(); + activeShopInfo.setItemNo(rs.getString("item_no").trim()); + String specialType=rs.getString("rule_no").trim(); + String activityName=rs.getString("plan_name").trim(); + if(specialType.equals("DD")){//折扣 折扣和满减分类比较多,目前只同步商品级别的 + BigDecimal discount=rs.getBigDecimal("value"); + //String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10))); + // activeShopInfo.setActivityName(activityName); + activeShopInfo.setDiscount(discount); + activeShopInfo.setActivityTypeId(2); + } + if(specialType.equals("PS")||specialType.equals("PM")){//特价(秒杀) + //activeShopInfo.setActivityName(activityName); + activeShopInfo.setOldPrice(rs.getBigDecimal("num2")); + activeShopInfo.setSpecPrice(rs.getBigDecimal("value")); + activeShopInfo.setActivityTypeId(1); + } +// if(specialType.equals("FR")){//满减 todo 没有同步 +// String total1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price")); +// String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price")); +// String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1"))); +// String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1"))); +// activeShopInfo.setActivityName("满"+total1+"减"+max1+",满"+total2+"减"+max2); +// activeShopInfo.setActivityTypeId(3); +// } + activeShopInfo.setActivityName(activityName); + activeShopInfo.setActivityItemMinQuantity(rs.getBigDecimal("limit_qty")); + activeShopInfo.setActivityStarttime(rs.getDate("begin_date")); + activeShopInfo.setActivityEndtime(rs.getDate("end_date")); + activeShopInfo.setFlowNo(rs.getString("plan_no")); + activeShopInfo.setItemNo(rs.getString("item_no").trim()); + if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){ + activeShopInfo.setActivityState(1);//正常进行中 + }else { + activeShopInfo.setActivityState(2);//结束 + } + activeShopInfos.add(activeShopInfo); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + resultDto.getConnection().close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + return activeShopInfos; + } + + /** + * + * @param dataBaseInfo + * @return + */ + public Integer getTotalSpecShop(DataBaseInfo dataBaseInfo){ + String where=dataBaseInfo.getWhere()+" and d.range_flag='I' and rule_no in('DD','PS','PM')"; + return getTotalSpecShop(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(), + dataBaseInfo.getDataBaseName(),where); + } } 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 adc2ee3d..39b2e623 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 */ - boolean syncAtive(DataBaseInfo dataBaseInfo,CommentModel commentModel); + void syncAtive(DataBaseInfo dataBaseInfo,CommentModel commentModel); /** * 同步活动商品 @@ -73,12 +73,4 @@ 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 656f7f5c..be756656 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 @@ -238,6 +238,26 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService return parentId; } + /** + * 获取父节点下的子节点 + * @param dataBaseInfo + * @param parentId + * @return + */ + @Override + public String getCategoryChildren(DataBaseInfo dataBaseInfo,String parentId){ + List sxSyncCategories=new SxDataDao().findTBdItemClsList(dataBaseInfo); + String childrens=commonCache.get(CommonCache.CACHE_CATEGROY+parentId); + if(StringUtils.isEmpty(childrens)){ + log.info(JSONUtil.toJsonStr(buildTree(sxSyncCategories,parentId))); + childrens=commonCache.get(CommonCache.CACHE_CATEGROY+parentId); + if(StringUtils.isEmpty(childrens)){ + return parentId; + } + } + return childrens; + } + /** * 构建树节点 * @param sxSyncCategories @@ -261,7 +281,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService public List getRootNode(List sxSyncCategories){ List rootNodeList=new ArrayList<>(); for (SxSyncCategory node : sxSyncCategories) { - if (null==node.getCls_parent()) { + if (StringUtils.isEmpty(node.getCls_parent())) { rootNodeList.add(node); } } @@ -709,10 +729,10 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService Integer total =0; if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ where+=" and b.start_date>'"+commentModel.getSyncTime()+"' "; - where+=" or b.oper_date>'"+commentModel.getSyncTime()+"' "; + // where+=" or b.oper_date>'"+commentModel.getSyncTime()+"') "; } dataBaseInfo.setWhere(where); - total = sxDataDao.getActiveCount(dataBaseInfo); + total = sxDataDao.getNewActiveCount(dataBaseInfo); if(total==0){ log.info("暂无活动同步"); return; @@ -724,7 +744,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService Date tenMinutesAgo = Date.from(Instant.now());//刷新时间 Date refreshDate= DateUtil.date(tenMinutesAgo); for (int i = 1; i <=pages; i++) { - List activeDtos= sxDataDao.getActiveList(dataBaseInfo,i,SxDataDao.PAGESIZE); + List activeDtos= sxDataDao.getNewActiveList(dataBaseInfo,i,SxDataDao.PAGESIZE); Gson gson=new GsonBuilder() .setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式 .create(); @@ -748,12 +768,12 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService String where="where 1=1"; Integer total =0; if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ - where+=" and start_date>'"+commentModel.getSyncTime()+"' "; - where+=" or oper_date>'"+commentModel.getSyncTime()+"' "; + where+=" and m.oper_date>'"+commentModel.getSyncTime()+"' "; + // where+=" or m.oper_date>'"+commentModel.getSyncTime()+"') "; } dataBaseInfo.setWhere(where); - total = sxDataDao.getAllSpecCount(dataBaseInfo); + total = sxDataDao.getTotalSpecShop(dataBaseInfo); if(total==0){ log.info("暂无活动商品同步"); return; @@ -765,7 +785,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService Date tenMinutesAgo = Date.from(Instant.now());//刷新时间 Date refreshDate= DateUtil.date(tenMinutesAgo);//todo 要记录刷新时间 for (int i = 1; i <=pages; i++) { - List activeDtos= sxDataDao.getAllSpecPriceList(dataBaseInfo,i,SxDataDao.PAGESIZE); + List activeDtos= sxDataDao.getSpecShops(dataBaseInfo,i,SxDataDao.PAGESIZE); Gson gson=new GsonBuilder() .setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式 .registerTypeAdapter(BigDecimal.class,new BigDecimalTypeAdapter())