Compare commits
2 Commits
9ca7555ad3
...
24e26480f9
| Author | SHA1 | Date | |
|---|---|---|---|
| 24e26480f9 | |||
| 24ba57be22 |
@ -1,5 +1,7 @@
|
||||
package com.small.client.Schedule;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.small.client.dto.CommentModel;
|
||||
import com.small.client.dto.DataBaseInfo;
|
||||
import com.small.client.service.SxDataService;
|
||||
@ -44,7 +46,12 @@ public class DynamicTaskScheduler {
|
||||
}
|
||||
CommentModel commentModel =sxDataService.getCommentModel();
|
||||
DataBaseInfo enabledTask = sxDataService.getDataBaseInfo(commentModel);
|
||||
|
||||
if(enabledTask == null){
|
||||
return;
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(enabledTask.getRefreshTime())){
|
||||
commentModel.setSyncTime(DateUtil.formatDateTime(enabledTask.getRefreshTime()));
|
||||
}
|
||||
List<DataBaseInfo> enabledTasks=new ArrayList<>();
|
||||
enabledTasks.add(enabledTask);
|
||||
// 移除已禁用或删除的任务
|
||||
|
||||
@ -40,6 +40,9 @@ public class HttpUtils {
|
||||
|
||||
public static final String URL_SYNC_GET_STOR_DATA_RELEASE="/shop/sync/third/syncStoreDataRelease";//库存同步
|
||||
|
||||
|
||||
public static final String URL_SYNC_GOODS_NOTICE_UPLOAD_TO_OSS="/shop/sync/third/uploudToCos";//通知上传文件到cos
|
||||
|
||||
public static String postData(RestTemplate restTemplate, String url,Object modelObject){
|
||||
// 创建表单参数
|
||||
// MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package com.small.client.controller;
|
||||
|
||||
import com.small.client.Utils.HttpUtils;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.small.client.dto.CommentModel;
|
||||
import com.small.client.dto.DataBaseInfo;
|
||||
import com.small.client.dto.SyncGoodsSearchModel;
|
||||
import com.small.client.service.SxDataService;
|
||||
import com.small.client.service.WebClientService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -44,7 +45,16 @@ public class WebController {
|
||||
public void syncGoods(){
|
||||
log.info("syncGoods");
|
||||
//sxDataService.getAppSign();
|
||||
sxDataService.SyncGoods(new DataBaseInfo(),sxDataService.getCommentModel());
|
||||
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.SyncGoods(dataBaseInfo,commentModel);
|
||||
}
|
||||
|
||||
@RequestMapping("/synvip")
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package com.small.client.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class DataBaseInfo {
|
||||
@ApiModelProperty("数据库IP")
|
||||
@ -30,4 +33,7 @@ public class DataBaseInfo {
|
||||
|
||||
@ApiModelProperty(value = "操作时间")
|
||||
private String operDate;
|
||||
|
||||
@ApiModelProperty(value = "刷新时间")
|
||||
private Date refreshTime;
|
||||
}
|
||||
|
||||
@ -61,4 +61,8 @@ public class StoreDbConfig implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "备注信息")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "刷新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date refreshTime;
|
||||
}
|
||||
|
||||
@ -338,6 +338,13 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
folders.add(String.valueOf(i));
|
||||
syncCount+=sxSyncGoods.size();
|
||||
}
|
||||
//通知服务器上传cos
|
||||
HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_GOODS_NOTICE_UPLOAD_TO_OSS
|
||||
+"?appKey="+commentModel.getAppKey()
|
||||
+"&sign="+commentModel.getSign()
|
||||
+"&syncType="+DicEnum.MUAL_1.getCode(),
|
||||
JSONUtil.parseArray(folders));
|
||||
|
||||
//folders.add(String.valueOf(4));
|
||||
//folders.add(String.valueOf(5));
|
||||
log.info("商品分类总共有{}条数据,同步完成{}条",total,syncCount);
|
||||
@ -474,11 +481,11 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
commentModel.setAppKey(result.get("appKey"));
|
||||
commentModel.setStoreId(result.get("storeId"));
|
||||
//获取上次同步的最大时间
|
||||
File[] lastDateJsonFile = folder.listFiles((dir, name) -> name.endsWith(FileUtils.REFLESHDATE));
|
||||
if(lastDateJsonFile!=null&&lastDateJsonFile.length>0){
|
||||
String lastDate = new String(Files.readAllBytes(lastDateJsonFile[0].toPath()), StandardCharsets.UTF_8).trim();
|
||||
commentModel.setSyncTime(lastDate);
|
||||
}
|
||||
// File[] lastDateJsonFile = folder.listFiles((dir, name) -> name.endsWith(FileUtils.REFLESHDATE));
|
||||
// if(lastDateJsonFile!=null&&lastDateJsonFile.length>0){
|
||||
// String lastDate = new String(Files.readAllBytes(lastDateJsonFile[0].toPath()), StandardCharsets.UTF_8).trim();
|
||||
// commentModel.setSyncTime(lastDate);
|
||||
// }
|
||||
return commentModel;
|
||||
} catch (RuntimeException | IOException e) {
|
||||
throw new RuntimeException("密钥获取失败");
|
||||
@ -645,6 +652,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
dataBaseInfo.setSyncMode(storeDbConfig.getSyncMode());
|
||||
dataBaseInfo.setCronExpression(storeDbConfig.getCronExpression());
|
||||
dataBaseInfo.setCategoryName(storeDbConfig.getCategoryName());
|
||||
dataBaseInfo.setRefreshTime(storeDbConfig.getRefreshTime());
|
||||
return dataBaseInfo;
|
||||
}
|
||||
return new DataBaseInfo();
|
||||
|
||||
@ -645,9 +645,13 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl<ShopPageBaseMapper,
|
||||
}
|
||||
} else if (StrUtil.equals("2", type)) {
|
||||
String category_name = getParameter("name");
|
||||
String storeId = getParameter("store_id");
|
||||
if (StrUtil.isNotBlank(category_name)) {
|
||||
params.put("category_name", category_name);
|
||||
}
|
||||
if (StrUtil.isNotBlank(storeId)) {
|
||||
params.put("storeId", storeId);
|
||||
}
|
||||
|
||||
data = getProductCategoryList(page, rows, params);
|
||||
List<Map> items = (List<Map>) data.get("items");
|
||||
@ -1433,12 +1437,16 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl<ShopPageBaseMapper,
|
||||
private Map getProductCategoryList(Integer pageNum, Integer pageSize, Map params) {
|
||||
|
||||
String categoryName = (String) params.get("category_name");
|
||||
String storeId = (String) params.get("storeId");
|
||||
|
||||
QueryWrapper<ShopBaseProductCategory> 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)) {
|
||||
|
||||
@ -146,4 +146,14 @@ public class SyncThirdDataController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "通知上传商品文件到cos", notes = "通知上传商品文件到cos")
|
||||
@RequestMapping(value = "/uploudToCos", method = RequestMethod.POST)
|
||||
public ThirdApiRes uploudToCos(@RequestBody List<String> folders,
|
||||
@RequestParam String appKey,
|
||||
@RequestParam String sign,
|
||||
@RequestParam String syncType) {
|
||||
return syncThirdDataService.fileUploadToOss(appKey,sign,syncType,folders);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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<String> folders);
|
||||
}
|
||||
|
||||
@ -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<String> 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<StoreDbConfig> 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<String> folders) {
|
||||
SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
||||
.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("上传成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user