diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/page/service/impl/ShopPageBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/page/service/impl/ShopPageBaseServiceImpl.java index be965da8..253b6ea7 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/page/service/impl/ShopPageBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/page/service/impl/ShopPageBaseServiceImpl.java @@ -645,9 +645,13 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl items = (List) data.get("items"); @@ -1433,12 +1437,16 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); Integer category_parent_id = getParameter("category_parent_id", Integer.class); if (category_parent_id != null) { queryWrapper.eq("category_parent_id", category_parent_id); } + if (storeId != null) { + queryWrapper.eq("store_id", storeId); + } String category_name = ObjectUtil.defaultIfNull(categoryName, getParameter("category_name", getParameter("search_key"))); if (StrUtil.isNotBlank(category_name)) { diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sync/controller/SyncThirdDataController.java b/mall-shop/src/main/java/com/suisung/mall/shop/sync/controller/SyncThirdDataController.java index 8a24a639..fa6d8bf3 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sync/controller/SyncThirdDataController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sync/controller/SyncThirdDataController.java @@ -146,4 +146,14 @@ public class SyncThirdDataController { } + @ApiOperation(value = "通知上传商品文件到cos", notes = "通知上传商品文件到cos") + @RequestMapping(value = "/uploudToCos", method = RequestMethod.POST) + public ThirdApiRes uploudToCos(@RequestBody List folders, + @RequestParam String appKey, + @RequestParam String sign, + @RequestParam String syncType) { + return syncThirdDataService.fileUploadToOss(appKey,sign,syncType,folders); + } + + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/SyncThirdDataService.java b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/SyncThirdDataService.java index 43ffdea1..a8b9baf7 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/SyncThirdDataService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/SyncThirdDataService.java @@ -110,4 +110,13 @@ public interface SyncThirdDataService { */ void saveStoreRealeas(Map storeData); + + /** + * + * @param appKey + * @param sign + * @param folders + * @return + */ + ThirdApiRes fileUploadToOss(String appKey, String sign,String syncType, List folders); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncThirdDataServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncThirdDataServiceImpl.java index 9efc2319..628be020 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncThirdDataServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncThirdDataServiceImpl.java @@ -11,10 +11,11 @@ package com.suisung.mall.shop.sync.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpException; +import cn.hutool.core.util.ZipUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONUtil; @@ -25,7 +26,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.qcloud.cos.model.COSObjectSummary; import com.suisung.mall.common.api.CommonResult; -import com.suisung.mall.common.domain.UserDto; import com.suisung.mall.common.enums.DicEnum; import com.suisung.mall.common.modules.base.ShopBaseProductBrand; import com.suisung.mall.common.modules.base.ShopBaseProductCategory; @@ -57,7 +57,6 @@ import com.suisung.mall.shop.sixun.service.SxSyncGoodsService; import com.suisung.mall.shop.sixun.service.SxSyncVipService; import com.suisung.mall.shop.sixun.utils.CommonUtil; import com.suisung.mall.shop.sixun.utils.FileUtils; -import com.suisung.mall.shop.sync.Utils.CryptoUtils; import com.suisung.mall.shop.sync.Utils.ThreadFileUtils; import com.suisung.mall.shop.sync.keymanage.RedisKey; import com.suisung.mall.shop.sync.service.*; @@ -83,6 +82,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.Duration; +import java.time.Instant; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; @@ -123,12 +124,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements @Autowired private StoreDbConfigService storeDbConfigService; - private final static String CLIENTFILEPATH="sxclient/"; - @Autowired private ShopBaseProductCategoryService shopBaseProductCategoryService; - @Autowired - private FileUtils fileUtils; @Autowired private ShopProductSpecItemService shopProductSpecItemService; @@ -136,6 +133,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements @Autowired private ShopBaseProductSpecService baseProductSpecService; + @Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}") + private String TENGXUN_DEFA; /** * 批量保存商品的分类 * @@ -435,6 +434,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements if (syncAppO == null) { return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!")); } + String storeId = syncAppO.getStore_id(); try { if (multipartFile.isEmpty()) { @@ -446,6 +446,14 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements String filePath= FileUtils.createFolderAndFileUsingFile(folder,filName); Path path = Paths.get(filePath); Files.write(path, bytes); + logger.info("path-{},parent-{},filename-{},root-{}",path.toString(),path.getParent(),path.getFileName().toString(),path.getRoot()); + // String filaPath=path.toString(); +// if(filePath.contains(":")){ +// filePath=filePath.substring(filePath.indexOf(":")+1); +// } +// filePath=filePath.replaceAll("\\\\","/"); +// String cosFileName =TENGXUN_DEFA.concat("/").concat("sync/").concat(filePath); +// ossService.uploadObject4OSS(new File(filePath),cosFileName); // String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath() // .path("/download/") // .path(Objects.requireNonNull(multipartFile.getOriginalFilename())) @@ -471,6 +479,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements .eq(SyncApp::getApp_key, appKey) .eq(SyncApp::getApp_secret,sign)); String storeId = syncApp.getStore_id(); + Date tenMinutesAgo = Date.from(Instant.now().minus(Duration.ofMinutes(5)));//校准误差 + Date date= DateUtil.date(tenMinutesAgo); if(null==syncApp.getStore_id()|| syncApp.getStore_id().isEmpty()){ logger.info("商品id为空"); return; @@ -479,11 +489,16 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements logger.info("没有商品数据"); return; } + List newFolders=new ArrayList<>(); folders.forEach(page->{ String newfolder=new FileUtils().getSyncTypeFlag(syncType,clientPath)+storeId+FileUtils.pathSeparator+page+FileUtils.pathSeparator; newFolders.add(newfolder); }); + + //upLoadZipToOss(newFolders.get(0));//上传文件到cos + dowloadAndUnZip(newFolders.get(0));//读取cos文件回本地 + syncPrimaryKey(); shopNumberSeqService.clearKey(); shopBaseProductCategoryService.clearCategoryCache(storeId); @@ -560,6 +575,19 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements //todo 定时清理文件,建议用服务器脚本 logger.info("执行成功{}个文件,失败{}个文件",success,fails); logger.info("同步商品数据执行结束"); + //更新当前的获取时间,用户客户端获取 + try { + QueryWrapper storeDbConfigQueryWrapper = new QueryWrapper<>(); + storeDbConfigQueryWrapper.eq("store_id", storeId); + StoreDbConfig storeDbConfig=storeDbConfigService.getOne(storeDbConfigQueryWrapper); + if(ObjectUtil.isNotEmpty(storeDbConfig)){ + storeDbConfig.setRefreshTime(date); + storeDbConfigService.saveOrUpdate(storeDbConfig); + } + }catch (RuntimeException e){ + logger.error("同步时间失败"+e.getMessage()); + } + } @Override @@ -685,4 +713,86 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements } + /** + * 压缩商家数据,并上传cos + * 保存商店数据 如 + * "E:\\data\\uploaded\\goods\\2025\\6\\6\\1\\2" + * @param path + */ + public void upLoadZipToOss(String path){ + File file=new File(path); + File parentFile=null; + if(!file.exists()){//存在则取本地,不存在下载cos的数据 + logger.info("没有同步数据上传"); + return; + } + parentFile=file.getParentFile(); + String filePath=parentFile.getPath(); + filePath=filePath.replaceAll("\\\\","/"); + String folderName=parentFile.getName(); + String parentFolderName=parentFile.getParentFile().getPath().replaceAll("\\\\","/"); + String localPath=parentFolderName+"/"+folderName+".zip"; + ZipUtil.zip(filePath,localPath,true); + if(parentFolderName.contains(":")){ + parentFolderName=parentFolderName.substring(filePath.indexOf(":")+1); + } + String cosFileName =TENGXUN_DEFA.concat("/").concat("sync").concat(parentFolderName).concat("/").concat(folderName+".zip"); + ossService.uploadObject4OSS(new File(localPath),cosFileName); + } + + /** + * 压缩商家数据,并上传cos + * 保存商店数据 如 + * "E:\\data\\uploaded\\goods\\2025\\6\\6\\1\\2" + * @param path + */ + public void dowloadAndUnZip(String path){ + File file=new File(path); + File parentFile=null; + if(file.exists()){//存在则取本地,不存在下载cos的数据 + logger.info("没有同步数据下载"); + }else { + parentFile=file.getParentFile(); + String ossFilePath=parentFile.getParentFile().getPath(); + + String fileName=parentFile.getName()+".zip"; + + String parentFolderName=parentFile.getParent().replaceAll("\\\\","/"); + String localPath=parentFolderName+"/"+fileName; + ossFilePath=ossFilePath.replaceAll("\\\\","/")+"/"+fileName; + + if(ossFilePath.contains(":")){ + ossFilePath=ossFilePath.substring(ossFilePath.indexOf(":")+1); + } + ossFilePath=TENGXUN_DEFA.concat("/").concat("sync").concat(ossFilePath); + String dowlowFilePath=ossService.download(ossFilePath,localPath); + File localFile=new File(dowlowFilePath); + ZipUtil.unzip(dowlowFilePath,localFile.getParent(), CharsetUtil.CHARSET_GBK); + } + } + + @Override + public ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType, List folders) { + SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper() + .select(SyncApp::getApp_key, SyncApp::getApp_secret,SyncApp::getStore_id) + .eq(SyncApp::getApp_key, appKey) + .eq(SyncApp::getApp_secret,sign)); + String storeId = syncApp.getStore_id(); + Date tenMinutesAgo = Date.from(Instant.now().minus(Duration.ofMinutes(5)));//校准误差 + Date date= DateUtil.date(tenMinutesAgo); + if(null==syncApp.getStore_id()|| syncApp.getStore_id().isEmpty()){ + logger.info("商品id为空"); + return new ThirdApiRes().fail(250,"商品id为空"); + } + if(folders==null||folders.isEmpty()){ + logger.info("没有商品数据"); + return new ThirdApiRes().fail(250,"没有商品数据"); + } + + String newfolder=new FileUtils().getSyncTypeFlag(syncType,clientPath)+storeId+FileUtils.pathSeparator+folders.get(0)+FileUtils.pathSeparator; + upLoadZipToOss(newfolder);//上传文件到cos + return new ThirdApiRes().success("上传成功"); + } + + }