更新逻辑修改

This commit is contained in:
liyj 2025-11-08 10:11:17 +08:00
parent 44794636f7
commit d1ef71669e
5 changed files with 129 additions and 44 deletions

View File

@ -96,13 +96,25 @@ public class DynamicTaskScheduler {
commentModel =sxDataService.getCommentModel();
}
DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel);
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()));
if(dataBaseInfo==null||StringUtils.isEmpty(dataBaseInfo.getUserName())){
return;
}
String refreshTime="";
if(ObjectUtil.isNotEmpty(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())){
@ -114,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;
}

View File

@ -515,20 +515,22 @@ public class SxDataDao extends BaseDao{
int count = 0;
Set<Map.Entry> sme=map.entrySet();
for (Map.Entry entry : sme) {
String key=entry.getKey().toString();
String[] splitKey = key.split("-");
if(splitKey.length!=2){
continue;
}
String itemNo = splitKey[1];
BigDecimal stock_qty= (BigDecimal) entry.getValue();
if(stock_qty.compareTo(BigDecimal.ZERO)==0){
continue;
}
String itemNo = (String) entry.getKey();
ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(itemNo);
BigDecimal unitPrice = productQuantityConsumptionDto.getUnitPrice();
RmSaleflow rmSaleflow=new RmSaleflow();
rmSaleflow.setItemNo(itemNo);
rmSaleflow.setSalePrice(unitPrice);
rmSaleflow.setSaleQnty(stock_qty);
rmSaleflow.setSourcePrice(unitPrice);
rmSaleflow.setFlownoRand(productQuantityConsumptionDto.getOrderId());//随机子单号 设置网上订单号
ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(key);
if(productQuantityConsumptionDto.getSaleAmount().compareTo(BigDecimal.ZERO)==0){
continue;
}
RmSaleflow rmSaleflow = getRmSaleflow(productQuantityConsumptionDto, itemNo, stock_qty);
rmSaleflow= fixRmSaleFlow(rmSaleflow,brachNo,itemInfoMap,dataBaseInfo.getSaleAccount());
TRmPayflow trmPayflow=fixTRmPayflow(rmSaleflow);
@ -587,6 +589,25 @@ public class SxDataDao extends BaseDao{
}
}
/**
* 封装对象
* @param productQuantityConsumptionDto
* @param itemNo
* @param stock_qty
* @return
*/
private RmSaleflow getRmSaleflow(ProductQuantityConsumptionDto productQuantityConsumptionDto, String itemNo, BigDecimal stock_qty) {
BigDecimal unitPrice = productQuantityConsumptionDto.getUnitPrice();
RmSaleflow rmSaleflow=new RmSaleflow();
rmSaleflow.setItemNo(itemNo);
rmSaleflow.setSalePrice(unitPrice);
rmSaleflow.setSaleQnty(stock_qty);
rmSaleflow.setSaleMoney(productQuantityConsumptionDto.getSaleAmount());
// rmSaleflow.setSourcePrice(unitPrice);
rmSaleflow.setFlownoRand(productQuantityConsumptionDto.getOrderId());//随机子单号 设置网上订单号
return rmSaleflow;
}
/**
* 补充字段
* @param rmSaleflow
@ -597,7 +618,8 @@ public class SxDataDao extends BaseDao{
rmSaleflow.setFlowId(1);
String orderId=rmSaleflow.getFlownoRand();
String[] orderIdSplits= orderId.split("_");
String DateStr=DateUtil.format(new java.util.Date(),"yyyyMMdd");
//String DateStr=DateUtil.format(new java.util.Date(),"yyyyMMdd");
String DateStr=orderIdSplits[1];
String number= String.format("%04d", Integer.valueOf(orderIdSplits[orderIdSplits.length-1]));
String flowNo="99"+DateStr+number;
rmSaleflow.setFlowNo(flowNo);//订单号 todo
@ -612,17 +634,18 @@ public class SxDataDao extends BaseDao{
rmSaleflow.setSaleQnty(saleQnty);
rmSaleflow.setRetQnty(BigDecimal.ZERO);
}
BigDecimal saleMoney=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty());
if(rmSaleflow.getSaleQnty().compareTo(BigDecimal.ZERO)<0){
saleMoney=saleMoney.multiply(new BigDecimal("-1"));
}
rmSaleflow.setSaleMoney(saleMoney);
// BigDecimal saleMoney=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty());
// if(rmSaleflow.getSaleQnty().compareTo(BigDecimal.ZERO)<0){
// saleMoney=saleMoney.multiply(new BigDecimal("-1"));
// }
// rmSaleflow.setSaleMoney(saleMoney);
//判断取值 end
//数据库查询取值start todo
ItemInfo itemInfo=itemInfoMap.get(rmSaleflow.getItemNo());
if(itemInfo!=null){
rmSaleflow.setInPrice(itemInfo.getPrice());
rmSaleflow.setSourcePrice(itemInfo.getSalePrice());
rmSaleflow.setOperDate(new Timestamp(System.currentTimeMillis()));
}
rmSaleflow.setBranchNo(branchNo);
@ -654,11 +677,12 @@ public class SxDataDao extends BaseDao{
TRmPayflow rmPayflow=new TRmPayflow();
rmPayflow.setFlowId(rmSaleflow.getFlowId());
rmPayflow.setFlowNo(rmSaleflow.getFlowNo());
BigDecimal saleAmount=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty()).setScale(2, RoundingMode.HALF_UP);
if(saleAmount.compareTo(BigDecimal.ZERO)<0){
saleAmount=saleAmount.multiply(new BigDecimal("-1"));
}
rmPayflow.setSaleAmount(saleAmount);
// BigDecimal saleAmount=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty()).setScale(2, RoundingMode.HALF_UP);
// if(saleAmount.compareTo(BigDecimal.ZERO)<0){
// saleAmount=saleAmount.multiply(new BigDecimal("-1"));
// }
// rmPayflow.setSaleAmount(saleAmount);
rmPayflow.setSaleAmount(rmSaleflow.getSaleMoney());
rmPayflow.setBranchNo(rmSaleflow.getBranchNo());
rmPayflow.setPayWay("RMB");//人民币
rmPayflow.setSellWay(rmSaleflow.getSellWay());
@ -666,7 +690,7 @@ public class SxDataDao extends BaseDao{
rmPayflow.setVipNo(null);
rmPayflow.setCoinNo("RMB");//
rmPayflow.setCoinRate(new BigDecimal("1"));//利率
rmPayflow.setPayAmount(saleAmount);
rmPayflow.setPayAmount(rmSaleflow.getSaleMoney());
rmPayflow.setOperDate(new Timestamp(System.currentTimeMillis()));
rmPayflow.setOperId(rmSaleflow.getOperId());
rmPayflow.setCounterNo(rmSaleflow.getCounterNo());
@ -712,7 +736,11 @@ public class SxDataDao extends BaseDao{
Set<Map.Entry> sme=map.entrySet();
String where = "where 1=1 and ";
List<String> itemNos = sme.stream()
.map(entry -> (String) entry.getKey())
.map(entry -> {
String key= (String) entry.getKey();
String[] split = key.split("-");
return split[1];
})
.collect(Collectors.toList());
where += SqlBuilder.buildInCondition("item_no", itemNos);
ResultDto resultDto= this.baseFindList(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),
@ -738,6 +766,9 @@ public class SxDataDao extends BaseDao{
if(StringUtils.isNotEmpty(rs.getString("item_clsno"))){
itemInfo.setItemClsno(rs.getString("item_clsno").trim());
}
if(StringUtils.isNotEmpty(rs.getString("sale_price"))){
itemInfo.setSalePrice(rs.getBigDecimal("sale_price"));
}
resultMap.put(itemNo,itemInfo);
}
} catch (SQLException e) {

View File

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

View File

@ -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);
}

View File

@ -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,7 +356,7 @@ 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 " +
@ -619,10 +635,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<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
@ -766,10 +782,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<ProductQuantityConsumptionDto> productQuantityConsumptionDtoList =
JSONUtil.toList(jsonObject.getStr("result"),ProductQuantityConsumptionDto.class);
JSONUtil.toList(jsonStr,ProductQuantityConsumptionDto.class);
if(!productQuantityConsumptionDtoList.isEmpty()){
Map map = productQuantityConsumptionDtoList.stream()
.collect(Collectors.groupingBy(
@ -783,17 +802,18 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
Map<String,ProductQuantityConsumptionDto> 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())){
@ -804,7 +824,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);
@ -829,7 +849,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
syncCount+=activeDtos.size();
}
log.info("成功同步活动数据:"+syncCount);
return true;
}
@Override