Compare commits
2 Commits
e0bda00d71
...
9a94d9addd
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a94d9addd | |||
| e0430f3624 |
@ -31,7 +31,6 @@ public class WebController {
|
|||||||
public void synBrand(){
|
public void synBrand(){
|
||||||
log.info("synBrand");
|
log.info("synBrand");
|
||||||
// sxDataService.getAppSign();
|
// sxDataService.getAppSign();
|
||||||
|
|
||||||
sxDataService.SyncBranchList(new DataBaseInfo(),sxDataService.getCommentModel());
|
sxDataService.SyncBranchList(new DataBaseInfo(),sxDataService.getCommentModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -415,9 +415,7 @@ public class BaseDao {
|
|||||||
" from \n" +
|
" from \n" +
|
||||||
" ( \n" +
|
" ( \n" +
|
||||||
" select \n" +
|
" select \n" +
|
||||||
" ROW_NUMBER() OVER(partition by b.start_date, \n" +
|
" ROW_NUMBER() OVER(partition by b.other3 " +
|
||||||
" b.end_date, \n" +
|
|
||||||
" b.special_type,b.discount \n" +
|
|
||||||
" ORDER BY \n" +
|
" ORDER BY \n" +
|
||||||
" b.start_date) as rowId, \n" +
|
" b.start_date) as rowId, \n" +
|
||||||
" b.* \n" +
|
" b.* \n" +
|
||||||
@ -453,9 +451,7 @@ public class BaseDao {
|
|||||||
"from\n" +
|
"from\n" +
|
||||||
" (\n" +
|
" (\n" +
|
||||||
" select\n" +
|
" select\n" +
|
||||||
" ROW_NUMBER() OVER(partition by b.start_date,\n" +
|
" ROW_NUMBER() OVER(partition by b.other3 " +
|
||||||
" b.end_date,\n" +
|
|
||||||
" b.special_type\n" +
|
|
||||||
" ORDER BY\n" +
|
" ORDER BY\n" +
|
||||||
" b.start_date) as rowId,\n" +
|
" b.start_date) as rowId,\n" +
|
||||||
" b.*\n" +
|
" b.*\n" +
|
||||||
|
|||||||
@ -567,7 +567,7 @@ public class SxDataDao extends BaseDao{
|
|||||||
activeDto.setActivityTypeId(3);
|
activeDto.setActivityTypeId(3);
|
||||||
activeDto.setActiveMaxDesList(activeMaxDesList);
|
activeDto.setActiveMaxDesList(activeMaxDesList);
|
||||||
}
|
}
|
||||||
activeDto.setFlowNo(rs.getString("flow_no"));
|
activeDto.setFlowNo(rs.getString("other3"));
|
||||||
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
|
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
|
||||||
activeDto.setActivityStarttime(rs.getDate("start_date"));
|
activeDto.setActivityStarttime(rs.getDate("start_date"));
|
||||||
activeDto.setActivityEndtime(rs.getDate("end_date"));
|
activeDto.setActivityEndtime(rs.getDate("end_date"));
|
||||||
@ -657,9 +657,10 @@ public class SxDataDao extends BaseDao{
|
|||||||
activeShopInfo.setActivityName("满"+total1+"减"+max1+",满"+total2+"减"+max2);
|
activeShopInfo.setActivityName("满"+total1+"减"+max1+",满"+total2+"减"+max2);
|
||||||
activeShopInfo.setActivityTypeId(3);
|
activeShopInfo.setActivityTypeId(3);
|
||||||
}
|
}
|
||||||
|
activeShopInfo.setActivityItemMinQuantity(rs.getBigDecimal("sale_qty"));
|
||||||
activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
|
activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
|
||||||
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
|
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
|
||||||
activeShopInfo.setFlowNo(rs.getString("flow_no"));
|
activeShopInfo.setFlowNo(rs.getString("other3"));
|
||||||
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
|
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
|
||||||
activeShopInfo.setActivityState(1);//正常进行中
|
activeShopInfo.setActivityState(1);//正常进行中
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@ -44,4 +44,7 @@ public class ActiveShopInfo {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "活动id")
|
@ApiModelProperty(value = "活动id")
|
||||||
private String flowNo;
|
private String flowNo;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "购买下限")
|
||||||
|
private BigDecimal activityItemMinQuantity;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,10 +85,12 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
|||||||
// 总页数
|
// 总页数
|
||||||
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
|
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
|
||||||
List<SxSyncCategory> allSxSyncCategories= sxDataDao.findTBdItemClsList(dataBaseInfo);
|
List<SxSyncCategory> allSxSyncCategories= sxDataDao.findTBdItemClsList(dataBaseInfo);
|
||||||
|
List<ClsBrandDto> clsBrandDtoList=sxDataDao.getclsMapBrand(dataBaseInfo);
|
||||||
|
Map<String,String> clsBrandMap=getClsMapBrand(clsBrandDtoList);
|
||||||
int syncCount =0;
|
int syncCount =0;
|
||||||
for (int i = 1; i <=pages; i++) {
|
for (int i = 1; i <=pages; i++) {
|
||||||
List<SxSyncCategory> sxSyncCategories= sxDataDao.findTBdItemClsListPage(dataBaseInfo,i,SxDataDao.PAGESIZE);
|
List<SxSyncCategory> sxSyncCategories= sxDataDao.findTBdItemClsListPage(dataBaseInfo,i,SxDataDao.PAGESIZE);
|
||||||
List<SxCategoryModel> sxCategoryModelList= ConVToSxCategoryModel(sxSyncCategories,allSxSyncCategories);
|
List<SxCategoryModel> sxCategoryModelList= ConVToSxCategoryModel(sxSyncCategories,allSxSyncCategories,clsBrandMap);
|
||||||
JSONArray jsonArray =null;
|
JSONArray jsonArray =null;
|
||||||
String jsonString="";
|
String jsonString="";
|
||||||
try {
|
try {
|
||||||
@ -778,8 +780,21 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
|||||||
syncCount+=activeDtos.size();
|
syncCount+=activeDtos.size();
|
||||||
}
|
}
|
||||||
log.info("成功同步活动商品数据:"+syncCount);
|
log.info("成功同步活动商品数据:"+syncCount);
|
||||||
|
HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_REFRESH
|
||||||
|
+"?appKey="+commentModel.getAppKey()
|
||||||
|
+"&sign="+commentModel.getAppId(), new JSONArray());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String,String> getClsMapBrand(List<ClsBrandDto> clsBrandDtos){
|
||||||
|
Map<String,String> map=new HashMap();
|
||||||
|
if(!clsBrandDtos.isEmpty()){
|
||||||
|
clsBrandDtos.forEach(clsBrandDto->{
|
||||||
|
map.put(clsBrandDto.getItemClsname(),clsBrandDto.getCodeName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.suisung.mall.common.modules.store;
|
package com.suisung.mall.common.modules.store;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
@ -81,5 +82,6 @@ public class ShopStoreActivityItem implements Serializable {
|
|||||||
@ApiModelProperty(value = "积分商品已售数量")
|
@ApiModelProperty(value = "积分商品已售数量")
|
||||||
private Integer activity_points_product_sale_num;
|
private Integer activity_points_product_sale_num;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String product_group;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6223,7 +6223,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
List<ShopProductItem> shopProductItems= shopProductItemService.list(queryWrapper);
|
List<ShopProductItem> shopProductItems= shopProductItemService.list(queryWrapper);
|
||||||
Map<Long,Integer> countMap=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getProduct_id,ShopProductItem::getItem_quantity));
|
Map<Long,Integer> countMap=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getProduct_id,ShopProductItem::getItem_quantity));
|
||||||
items.forEach(shopProductIndex -> {
|
items.forEach(shopProductIndex -> {
|
||||||
shopProductIndex.put("item_quantity",MapUtil.getLong(countMap,shopProductIndex.get("product_id")));
|
shopProductIndex.put("itemQuantity",MapUtil.getLong(countMap,shopProductIndex.get("product_id")));
|
||||||
});
|
});
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2251,15 +2251,21 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
|||||||
* 一对多,如product_id:1002,item_number:120_121;数据格式为item_id,item_id item_unit_price,item_unit_price
|
* 一对多,如product_id:1002,item_number:120_121;数据格式为item_id,item_id item_unit_price,item_unit_price
|
||||||
* 最终组合item_id,item_id_item_unit_price,item_unit_price
|
* 最终组合item_id,item_id_item_unit_price,item_unit_price
|
||||||
*/
|
*/
|
||||||
queryWrapper.select("product_id","GROUP_CONCAT(item_id SEPARATOR ',') AS mergedItemId","GROUP_CONCAT(item_unit_price SEPARATOR ',') AS mergedUnitPrices");
|
queryWrapper.select("product_id","GROUP_CONCAT(item_id SEPARATOR ',') AS mergedItemId","GROUP_CONCAT(item_unit_price SEPARATOR ',') AS mergedUnitPrices,category_id");
|
||||||
productNumbers.forEach(productNumber -> {
|
productNumbers.forEach(productNumber -> {
|
||||||
queryWrapper.or(q->q.eq("store_id",store_id).eq("item_src_id",productNumber));
|
queryWrapper.or(q->q.eq("store_id",store_id).eq("item_src_id",productNumber));
|
||||||
});
|
});
|
||||||
queryWrapper.eq("store_id",store_id);
|
queryWrapper.eq("store_id",store_id);
|
||||||
queryWrapper.groupBy("product_id");
|
queryWrapper.groupBy("product_id");
|
||||||
List<ShopProductItem> shopProductItems= this.list(queryWrapper);
|
List<ShopProductItem> shopProductItems= this.list(queryWrapper);
|
||||||
Map map=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getProduct_id,shopProductItem->shopProductItem.getMergedItemId()
|
// Map map=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getProduct_id,shopProductItem->shopProductItem.getMergedItemId()
|
||||||
+"_"+shopProductItem.getMergedUnitPrices()));
|
// +"_"+shopProductItem.getMergedUnitPrices()));
|
||||||
|
Map<String,String> map=new HashMap();
|
||||||
|
shopProductItems.forEach(item -> {
|
||||||
|
map.put(String.valueOf(item.getProduct_id()),item.getMergedItemId()+"_"+item.getMergedUnitPrices());
|
||||||
|
map.put(item.getProduct_id()+":category_id",String.valueOf(item.getCategory_id()));
|
||||||
|
});
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,4 +20,5 @@ public interface ShopStoreActivityItemService extends IBaseService<ShopStoreActi
|
|||||||
|
|
||||||
List<Map> getNormalItem(List<Long> item_ids);
|
List<Map> getNormalItem(List<Long> item_ids);
|
||||||
|
|
||||||
|
Map<String,Long> getExistingActvieShopItem(List<String> activityIds,Integer storeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,4 +196,21 @@ public class ShopStoreActivityItemServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
return saveOrUpdate(activityItem);
|
return saveOrUpdate(activityItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Long> getExistingActvieShopItem( List<String> activityIds,Integer storeId) {
|
||||||
|
QueryWrapper<ShopStoreActivityItem> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("CONCAT_WS('-', activity_id, product_id,item_id) AS product_group,activity_item_id");
|
||||||
|
activityIds.forEach(activityId -> {
|
||||||
|
queryWrapper.or(q->q.eq("activity_id", activityId).eq("store_id", storeId));
|
||||||
|
});
|
||||||
|
Map<String, Long> result = new HashMap<>();
|
||||||
|
List<ShopStoreActivityItem> shopStoreActivityItems=list(queryWrapper);
|
||||||
|
shopStoreActivityItems.forEach(shopStoreActivityItem -> {
|
||||||
|
result.put(shopStoreActivityItem.getProduct_group(),shopStoreActivityItem.getActivity_item_id());
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,4 +45,7 @@ public class ActiveModel implements Serializable {
|
|||||||
@ApiModelProperty(value = "活动id")
|
@ApiModelProperty(value = "活动id")
|
||||||
private String flowNo;
|
private String flowNo;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "购买下限")
|
||||||
|
private BigDecimal activity_item_min_quantity;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,4 +44,7 @@ public class ActiveShopInfo {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "活动id")
|
@ApiModelProperty(value = "活动id")
|
||||||
private String flowNo;
|
private String flowNo;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "购买下限")
|
||||||
|
private BigDecimal activityItemMinQuantity;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -978,9 +978,6 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
.map(object->{
|
.map(object->{
|
||||||
final JSONObject jsonObj= (JSONObject) object;
|
final JSONObject jsonObj= (JSONObject) object;
|
||||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
||||||
shopStoreActivityBase.setActivity_name(jsonObj.getStr("activityName"));
|
|
||||||
shopStoreActivityBase.setActivity_state(jsonObj.getInt("activityState"));
|
|
||||||
shopStoreActivityBase.setActivity_starttime(jsonObj.getDate("activityStarttime"));
|
|
||||||
shopStoreActivityBase.setFlow_no(jsonObj.getStr("flowNo"));
|
shopStoreActivityBase.setFlow_no(jsonObj.getStr("flowNo"));
|
||||||
return shopStoreActivityBase;
|
return shopStoreActivityBase;
|
||||||
})
|
})
|
||||||
@ -992,7 +989,8 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
Map<String,String> resultMap=new HashMap<>();
|
Map<String,String> resultMap=new HashMap<>();
|
||||||
|
|
||||||
existing.forEach(shopStoreActivityBase -> {
|
existing.forEach(shopStoreActivityBase -> {
|
||||||
resultMap.put(shopStoreActivityBase.getActivity_name()+"_"+shopStoreActivityBase.getActivity_starttime().getTime()+"_"+shopStoreActivityBase.getActivity_state()+"_"+shopStoreActivityBase.getFlow_no(),shopStoreActivityBase.getActivity_id()+"__"+(StringUtils.isEmpty(shopStoreActivityBase.getActivity_rule())?"0":shopStoreActivityBase.getActivity_rule()));
|
resultMap.put(shopStoreActivityBase.getFlow_no(),
|
||||||
|
shopStoreActivityBase.getActivity_id()+"__"+(StringUtils.isEmpty(shopStoreActivityBase.getActivity_rule())?"0":shopStoreActivityBase.getActivity_rule()));
|
||||||
});
|
});
|
||||||
|
|
||||||
return resultMap;
|
return resultMap;
|
||||||
@ -1014,9 +1012,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
QueryWrapper<ShopStoreActivityBase> query = new QueryWrapper<>();
|
QueryWrapper<ShopStoreActivityBase> query = new QueryWrapper<>();
|
||||||
query.select("activity_name", "activity_state","activity_starttime","activity_rule","activity_endtime","activity_id","flow_no");
|
query.select("activity_name", "activity_state","activity_starttime","activity_rule","activity_endtime","activity_id","flow_no");
|
||||||
shopStoreActivityBases.forEach(shopStoreActivityBase -> {
|
shopStoreActivityBases.forEach(shopStoreActivityBase -> {
|
||||||
query.or(q -> q.eq("activity_name", shopStoreActivityBase.getActivity_name()).eq("activity_state",shopStoreActivityBase.getActivity_state())
|
query.or(q -> q.eq("flow_no",shopStoreActivityBase.getFlow_no())
|
||||||
.eq("activity_starttime",shopStoreActivityBase.getActivity_starttime())
|
|
||||||
.eq("flow_no",shopStoreActivityBase.getFlow_no())
|
|
||||||
.eq("store_id", storeId));
|
.eq("store_id", storeId));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
|||||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||||
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
||||||
|
import com.suisung.mall.common.modules.store.ShopStoreActivityItem;
|
||||||
import com.suisung.mall.common.modules.sync.StoreDbConfig;
|
import com.suisung.mall.common.modules.sync.StoreDbConfig;
|
||||||
import com.suisung.mall.common.modules.sync.SyncApp;
|
import com.suisung.mall.common.modules.sync.SyncApp;
|
||||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||||
@ -45,10 +46,10 @@ import com.suisung.mall.common.pojo.req.SyncThirdMemberReq;
|
|||||||
import com.suisung.mall.common.pojo.res.ThirdApiRes;
|
import com.suisung.mall.common.pojo.res.ThirdApiRes;
|
||||||
import com.suisung.mall.common.utils.I18nUtil;
|
import com.suisung.mall.common.utils.I18nUtil;
|
||||||
import com.suisung.mall.common.utils.StringUtils;
|
import com.suisung.mall.common.utils.StringUtils;
|
||||||
import com.suisung.mall.core.web.service.RedisService;
|
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
||||||
|
import com.suisung.mall.shop.chain.controller.admin.ShopChainItemController;
|
||||||
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
import com.suisung.mall.shop.page.service.OssService;
|
import com.suisung.mall.shop.page.service.OssService;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
||||||
@ -64,6 +65,7 @@ import com.suisung.mall.shop.sixun.service.SxSyncVipService;
|
|||||||
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||||
import com.suisung.mall.shop.sixun.utils.FileUtils;
|
import com.suisung.mall.shop.sixun.utils.FileUtils;
|
||||||
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
||||||
|
import com.suisung.mall.shop.store.service.ShopStoreActivityItemService;
|
||||||
import com.suisung.mall.shop.sync.Utils.ActiveShopJsonUtils;
|
import com.suisung.mall.shop.sync.Utils.ActiveShopJsonUtils;
|
||||||
import com.suisung.mall.shop.sync.Utils.BigDecimalFormatter;
|
import com.suisung.mall.shop.sync.Utils.BigDecimalFormatter;
|
||||||
import com.suisung.mall.shop.sync.Utils.ThreadFileUtils;
|
import com.suisung.mall.shop.sync.Utils.ThreadFileUtils;
|
||||||
@ -88,7 +90,6 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@ -173,6 +174,11 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ShopBaseProductBrandService productBrandService;
|
private ShopBaseProductBrandService productBrandService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopStoreActivityItemService shopStoreActivityItemService;
|
||||||
|
@Autowired
|
||||||
|
private ShopChainItemController item;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量保存商品的分类
|
* 批量保存商品的分类
|
||||||
*
|
*
|
||||||
@ -185,9 +191,9 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
||||||
}
|
}
|
||||||
//用gson保证与客户端的顺序一致
|
//用gson保证与客户端的顺序一致
|
||||||
List<SxCategoryModel> sxCategoryModelList=categoryListJSON.toList(SxCategoryModel.class);
|
List<SxCategoryModel> sxCategoryModelList = categoryListJSON.toList(SxCategoryModel.class);
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String jsonStr=gson.toJson(sxCategoryModelList);
|
String jsonStr = gson.toJson(sxCategoryModelList);
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
||||||
if (syncApp == null) {
|
if (syncApp == null) {
|
||||||
@ -223,9 +229,9 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
||||||
}
|
}
|
||||||
//用gson保证与客户端的顺序一致
|
//用gson保证与客户端的顺序一致
|
||||||
List<BrandModel> brandModels=brandListJSON.toList(BrandModel.class);
|
List<BrandModel> brandModels = brandListJSON.toList(BrandModel.class);
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String jsonStr=gson.toJson(brandModels);
|
String jsonStr = gson.toJson(brandModels);
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
||||||
if (syncApp == null) {
|
if (syncApp == null) {
|
||||||
@ -293,7 +299,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
}
|
}
|
||||||
//用gson保证与客户端的顺序一致
|
//用gson保证与客户端的顺序一致
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String jsonStr=gson.toJson(memberList);
|
String jsonStr = gson.toJson(memberList);
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
||||||
if (syncApp == null) {
|
if (syncApp == null) {
|
||||||
@ -305,11 +311,11 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
|
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
|
||||||
}
|
}
|
||||||
shopNumberSeqService.clearKeyStoreAccountBaseId();
|
shopNumberSeqService.clearKeyStoreAccountBaseId();
|
||||||
int count =0;
|
int count = 0;
|
||||||
try {
|
try {
|
||||||
count= baseBatchSaveOrUpdateMemberBatch(memberList, storeId);
|
count = baseBatchSaveOrUpdateMemberBatch(memberList, storeId);
|
||||||
}catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new ApiException(_("保存失败"+e.getMessage()));
|
throw new ApiException(_("保存失败" + e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// shopNumberSeqService.clearKeyStoreAccountBaseId();
|
// shopNumberSeqService.clearKeyStoreAccountBaseId();
|
||||||
@ -504,7 +510,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
String jsonStr = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
String jsonStr = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||||
//验证签名,签名不正确删除文件
|
//验证签名,签名不正确删除文件
|
||||||
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
SyncApp syncApp = syncAppService.checkAppSign(appKey, sign, jsonStr);
|
||||||
if(syncApp == null) {
|
if (syncApp == null) {
|
||||||
Files.delete(path);//删除文件
|
Files.delete(path);//删除文件
|
||||||
return new ThirdApiRes().fail(500, "文件上传失败:签名验证失败");
|
return new ThirdApiRes().fail(500, "文件上传失败:签名验证失败");
|
||||||
}
|
}
|
||||||
@ -573,14 +579,14 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
List<String> failMessage = new ArrayList<>();
|
List<String> failMessage = new ArrayList<>();
|
||||||
shopBaseProductCategoryService.getCategoryListByStoreId(storeId);
|
shopBaseProductCategoryService.getCategoryListByStoreId(storeId);
|
||||||
// getBrandMapByStoreId()
|
// getBrandMapByStoreId()
|
||||||
Map<String,Integer> brandMaps= productBrandService.getBrandMapByStoreId(storeId);
|
Map<String, Integer> brandMaps = productBrandService.getBrandMapByStoreId(storeId);
|
||||||
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
|
||||||
storeDbConfigQueryWrapper.eq("store_id", storeId);
|
storeDbConfigQueryWrapper.eq("store_id", storeId);
|
||||||
StoreDbConfig storeDbConfig = storeDbConfigService.getOne(storeDbConfigQueryWrapper);
|
StoreDbConfig storeDbConfig = storeDbConfigService.getOne(storeDbConfigQueryWrapper);
|
||||||
for (int i = 0; i < newFolders.size(); i++) {
|
for (int i = 0; i < newFolders.size(); i++) {
|
||||||
final int taskId = i;
|
final int taskId = i;
|
||||||
final String isNegativeAllowed=storeDbConfig.getIsNegativeAllowed();
|
final String isNegativeAllowed = storeDbConfig.getIsNegativeAllowed();
|
||||||
String priorityMode=storeDbConfig.getPriorityMode();
|
String priorityMode = storeDbConfig.getPriorityMode();
|
||||||
threadNum.incrementAndGet();
|
threadNum.incrementAndGet();
|
||||||
futures.add(executor.submit(() -> {
|
futures.add(executor.submit(() -> {
|
||||||
int count = 0;//失败重试机制,当失败重试一次,再次失败则记录到数据库中
|
int count = 0;//失败重试机制,当失败重试一次,再次失败则记录到数据库中
|
||||||
@ -590,7 +596,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
String fileName = "good_" + (taskId + 1) + ".txt";
|
String fileName = "good_" + (taskId + 1) + ".txt";
|
||||||
JSONArray jsonArray = new ThreadFileUtils().processFolder(taskName, newFolders.get(taskId));
|
JSONArray jsonArray = new ThreadFileUtils().processFolder(taskName, newFolders.get(taskId));
|
||||||
try {
|
try {
|
||||||
baseSaveOrUpdateGoodsBatch(jsonArray, storeId,isNegativeAllowed,priorityMode,brandMaps);
|
baseSaveOrUpdateGoodsBatch(jsonArray, storeId, isNegativeAllowed, priorityMode, brandMaps);
|
||||||
success.getAndIncrement();
|
success.getAndIncrement();
|
||||||
threadNum.decrementAndGet();
|
threadNum.decrementAndGet();
|
||||||
return "成功" + taskId;
|
return "成功" + taskId;
|
||||||
@ -660,7 +666,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncShopImages(Integer storeId){
|
public void syncShopImages(Integer storeId) {
|
||||||
syncShopImageService.syncMapingShopImages(storeId);
|
syncShopImageService.syncMapingShopImages(storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -899,77 +905,82 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType,Date refreshDate, List<String> folders) {
|
public ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType, Date refreshDate, List<String> folders) {
|
||||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) ) {
|
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign)) {
|
||||||
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
||||||
}
|
}
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
||||||
.select(SyncApp::getApp_key, SyncApp::getApp_secret,SyncApp::getStore_id)
|
.select(SyncApp::getApp_key, SyncApp::getApp_secret, SyncApp::getStore_id)
|
||||||
.eq(SyncApp::getApp_key, appKey)
|
.eq(SyncApp::getApp_key, appKey)
|
||||||
.eq(SyncApp::getApp_secret,sign));
|
.eq(SyncApp::getApp_secret, sign));
|
||||||
if (syncApp == null) {
|
if (syncApp == null) {
|
||||||
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
|
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
|
||||||
}
|
}
|
||||||
String storeId = syncApp.getStore_id();
|
String storeId = syncApp.getStore_id();
|
||||||
if(null==syncApp.getStore_id()|| syncApp.getStore_id().isEmpty()){
|
if (null == syncApp.getStore_id() || syncApp.getStore_id().isEmpty()) {
|
||||||
logger.info("商店id为空");
|
logger.info("商店id为空");
|
||||||
return new ThirdApiRes().fail(250,"商店id为空");
|
return new ThirdApiRes().fail(250, "商店id为空");
|
||||||
}
|
}
|
||||||
if(folders==null||folders.isEmpty()){
|
if (folders == null || folders.isEmpty()) {
|
||||||
logger.info("没有商品数据");
|
logger.info("没有商品数据");
|
||||||
return new ThirdApiRes().fail(250,"没有商品数据");
|
return new ThirdApiRes().fail(250, "没有商品数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
String newfolder=new FileUtils().getSyncTypeFlag(syncType,clientPath)+storeId+FileUtils.pathSeparator+folders.get(0)+FileUtils.pathSeparator;
|
String newfolder = new FileUtils().getSyncTypeFlag(syncType, clientPath) + storeId + FileUtils.pathSeparator + folders.get(0) + FileUtils.pathSeparator;
|
||||||
upLoadZipToOss(newfolder);//上传文件到cos
|
upLoadZipToOss(newfolder);//上传文件到cos
|
||||||
return new ThirdApiRes().success("上传成功");
|
return new ThirdApiRes().success("上传成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Async
|
|
||||||
public void syncActives(String appKey, String sign, JSONArray activeJsonArray) {
|
public void syncActives(String appKey, String sign, JSONArray activeJsonArray) {
|
||||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
||||||
logger.error("缺少必要参数!");
|
logger.error("缺少必要参数!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
List<ActiveModel> activeModelList= activeJsonArray.toList(ActiveModel.class);
|
List<ActiveModel> activeModelList = activeJsonArray.toList(ActiveModel.class);
|
||||||
Gson gson=new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
|
.setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
|
||||||
.create();
|
.create();
|
||||||
String gsonStr= gson.toJson(activeModelList);
|
String gsonStr = gson.toJson(activeModelList);
|
||||||
SyncApp syncAppO = syncAppService.checkAppSign(appKey,sign,gsonStr);
|
SyncApp syncAppO = syncAppService.checkAppSign(appKey, sign, gsonStr);
|
||||||
if (syncAppO == null) {
|
if (syncAppO == null) {
|
||||||
logger.error("签名有误!");
|
logger.error("签名有误!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String storeId = syncAppO.getStore_id();
|
String storeId = syncAppO.getStore_id();
|
||||||
//活动逻辑
|
//活动逻辑
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
batchSaveShopStoreActivityBase(activeJsonArray, Integer.valueOf(storeId));
|
batchSaveShopStoreActivityBase(activeJsonArray, Integer.valueOf(storeId));
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量新增或更新活动数据
|
* 批量新增或更新活动数据
|
||||||
|
*
|
||||||
* @param jsonArray
|
* @param jsonArray
|
||||||
*/
|
*/
|
||||||
private void batchSaveShopStoreActivityBase(JSONArray jsonArray,Integer storeId) {
|
private void batchSaveShopStoreActivityBase(JSONArray jsonArray, Integer storeId) {
|
||||||
List<ShopStoreActivityBase> addshopStoreActivityBaseList=new ArrayList<>();
|
List<ShopStoreActivityBase> addshopStoreActivityBaseList = new ArrayList<>();
|
||||||
List<ShopStoreActivityBase> updateShopStoreActivityBaseList=new ArrayList<>();
|
List<ShopStoreActivityBase> updateShopStoreActivityBaseList = new ArrayList<>();
|
||||||
Map<String, String> stringIntegerMap= checkExistingActive(jsonArray,storeId);
|
Map<String, String> stringIntegerMap = checkExistingActive(jsonArray, storeId);
|
||||||
AccountUserBase accountUserBase=new AccountUserBase();
|
AccountUserBase accountUserBase = new AccountUserBase();
|
||||||
accountUserBase.setUser_is_admin(1);
|
accountUserBase.setUser_is_admin(1);
|
||||||
accountUserBase.setStore_ids("1");
|
accountUserBase.setStore_ids("1");
|
||||||
AccountUserBase accountUserBases=accountService.findOneAccountUserBase(accountUserBase);
|
AccountUserBase accountUserBases = accountService.findOneAccountUserBase(accountUserBase);
|
||||||
Integer userId= accountUserBases.getUser_id();
|
Integer userId = accountUserBases.getUser_id();
|
||||||
jsonArray.stream().parallel().forEach(object->{
|
jsonArray.stream().parallel().forEach(object -> {
|
||||||
final JSONObject jsonObj= (JSONObject) object;
|
final JSONObject jsonObj = (JSONObject) object;
|
||||||
String activityName=jsonObj.getStr("activityName");
|
String activityName = jsonObj.getStr("activityName");
|
||||||
Integer activityTypeId=jsonObj.getInt("activityTypeId");
|
Integer activityTypeId = jsonObj.getInt("activityTypeId");
|
||||||
if(null==activityTypeId){
|
if (null == activityTypeId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
ShopStoreActivityBase shopStoreActivityBase = new ShopStoreActivityBase();
|
||||||
if (activityTypeId == 1) {
|
if (activityTypeId == 1) {
|
||||||
activityTypeId = StateCode.ACTIVITY_TYPE_LIMITED_DISCOUNT; //限时秒杀
|
activityTypeId = StateCode.ACTIVITY_TYPE_LIMITED_DISCOUNT; //限时秒杀
|
||||||
}
|
}
|
||||||
@ -977,21 +988,21 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
activityTypeId = StateCode.ACTIVITY_TYPE_ONE_PIECE_DISCOUNT; //折扣
|
activityTypeId = StateCode.ACTIVITY_TYPE_ONE_PIECE_DISCOUNT; //折扣
|
||||||
}
|
}
|
||||||
if (activityTypeId == 3) {
|
if (activityTypeId == 3) {
|
||||||
JSONArray activeMaxDesList=jsonObj.getJSONArray("activeMaxDesList");
|
JSONArray activeMaxDesList = jsonObj.getJSONArray("activeMaxDesList");
|
||||||
activityTypeId = StateCode.ACTIVITY_TYPE_REDUCTION; //满减
|
activityTypeId = StateCode.ACTIVITY_TYPE_REDUCTION; //满减
|
||||||
String rules= ActiveShopJsonUtils.getRules(activeMaxDesList);
|
String rules = ActiveShopJsonUtils.getRules(activeMaxDesList);
|
||||||
shopStoreActivityBase.setActivity_rule(rules);
|
shopStoreActivityBase.setActivity_rule(rules);
|
||||||
}
|
}
|
||||||
Date activityStarttime=jsonObj.getDate("activityStarttime");
|
Date activityStarttime = jsonObj.getDate("activityStarttime");
|
||||||
Date activityEndtime=jsonObj.getDate("activityEndtime");
|
Date activityEndtime = jsonObj.getDate("activityEndtime");
|
||||||
Integer activityState=jsonObj.getInt("activityState");
|
Integer activityState = jsonObj.getInt("activityState");
|
||||||
String flowNo=jsonObj.getStr("flowNo");
|
String flowNo = jsonObj.getStr("flowNo");
|
||||||
// Date activityReleasetime= jsonObj.getDate("activityReleasetime");
|
// Date activityReleasetime= jsonObj.getDate("activityReleasetime");
|
||||||
BigDecimal discount=jsonObj.getBigDecimal("discount");
|
BigDecimal discount = jsonObj.getBigDecimal("discount");
|
||||||
String key=activityName+"_"+activityStarttime.getTime()+"_"+activityState+"_"+flowNo;
|
|
||||||
shopStoreActivityBase.setActivity_state(activityState);
|
shopStoreActivityBase.setActivity_state(activityState);
|
||||||
shopStoreActivityBase.setActivity_name(activityName);
|
shopStoreActivityBase.setActivity_name(activityName);
|
||||||
shopStoreActivityBase.setActivity_type(1);//免费参与
|
shopStoreActivityBase.setActivity_type(1);//免费参与
|
||||||
|
shopStoreActivityBase.setActivity_title(activityName);
|
||||||
// shopStoreActivityBase.setActivity_releasetime(activityReleasetime);
|
// shopStoreActivityBase.setActivity_releasetime(activityReleasetime);
|
||||||
shopStoreActivityBase.setStore_id(storeId);
|
shopStoreActivityBase.setStore_id(storeId);
|
||||||
shopStoreActivityBase.setActivity_on_is_off(0);
|
shopStoreActivityBase.setActivity_on_is_off(0);
|
||||||
@ -1002,26 +1013,25 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
shopStoreActivityBase.setSubsite_id(0);
|
shopStoreActivityBase.setSubsite_id(0);
|
||||||
shopStoreActivityBase.setUser_id(userId);
|
shopStoreActivityBase.setUser_id(userId);
|
||||||
shopStoreActivityBase.setFlow_no(flowNo);
|
shopStoreActivityBase.setFlow_no(flowNo);
|
||||||
if(stringIntegerMap.containsKey(key)){//更新
|
if (stringIntegerMap.containsKey(flowNo)) {//更新
|
||||||
String keyVal= MapUtil.getStr(stringIntegerMap,key);
|
String keyVal = MapUtil.getStr(stringIntegerMap, flowNo);
|
||||||
shopStoreActivityBase.setActivity_id(MapUtil.getInt(stringIntegerMap,keyVal.split("_")[0]));
|
shopStoreActivityBase.setActivity_id(MapUtil.getInt(stringIntegerMap, keyVal.split("_")[0]));
|
||||||
synchronized(updateShopStoreActivityBaseList){
|
synchronized (updateShopStoreActivityBaseList) {
|
||||||
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
synchronized(addshopStoreActivityBaseList) {
|
synchronized (addshopStoreActivityBaseList) {
|
||||||
addshopStoreActivityBaseList.add(shopStoreActivityBase);
|
addshopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
if(CollectionUtil.isNotEmpty(addshopStoreActivityBaseList)){
|
if (CollectionUtil.isNotEmpty(addshopStoreActivityBaseList)) {
|
||||||
shopStoreActivityBaseService.saveBatch(addshopStoreActivityBaseList,addshopStoreActivityBaseList.size());
|
shopStoreActivityBaseService.saveBatch(addshopStoreActivityBaseList, addshopStoreActivityBaseList.size());
|
||||||
}
|
}
|
||||||
if(CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)){
|
if (CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)) {
|
||||||
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
||||||
}
|
}
|
||||||
logger.info("同步活动数据结束:共{}条数据更新,{}条数据新增",updateShopStoreActivityBaseList.size(),addshopStoreActivityBaseList.size());
|
logger.info("同步活动数据结束:共{}条数据更新,{}条数据新增", updateShopStoreActivityBaseList.size(), addshopStoreActivityBaseList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1029,135 +1039,191 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
* 将商品添加到活动
|
* 将商品添加到活动
|
||||||
* 1、找出匹配的活动
|
* 1、找出匹配的活动
|
||||||
* 2、新增商品到活动列表
|
* 2、新增商品到活动列表
|
||||||
|
*
|
||||||
* @param appKey
|
* @param appKey
|
||||||
* @param sign
|
* @param sign
|
||||||
* @param activeJsonArray
|
* @param activeJsonArray
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Async
|
|
||||||
public void syncActiveShops(String appKey, String sign, JSONArray activeJsonArray) {
|
public void syncActiveShops(String appKey, String sign, JSONArray activeJsonArray) {
|
||||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
||||||
logger.error("缺少必要参数!");
|
logger.error("缺少必要参数!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 验签、appid,必要参数判断
|
// 验签、appid,必要参数判断
|
||||||
List<ActiveShopInfo> activeShopInfos= activeJsonArray.toList(ActiveShopInfo.class);
|
List<ActiveShopInfo> activeShopInfos = activeJsonArray.toList(ActiveShopInfo.class);
|
||||||
Gson gson=new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
|
.setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
|
||||||
.registerTypeAdapter(BigDecimal.class,new BigDecimalTypeAdapter())
|
.registerTypeAdapter(BigDecimal.class, new BigDecimalTypeAdapter())
|
||||||
.create();
|
.create();
|
||||||
String gsonStr= gson.toJson(activeShopInfos);
|
String gsonStr = gson.toJson(activeShopInfos);
|
||||||
SyncApp syncAppO = syncAppService.checkAppSign(appKey,sign,gsonStr);
|
SyncApp syncAppO = syncAppService.checkAppSign(appKey, sign, gsonStr);
|
||||||
if (syncAppO == null) {
|
if (syncAppO == null) {
|
||||||
logger.error("签名有误!");
|
logger.error("签名有误!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String storeId = syncAppO.getStore_id();
|
String storeId = syncAppO.getStore_id();
|
||||||
//把商品添加到活动的逻辑
|
//把商品添加到活动的逻辑
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
batchAddActiveShopBase(activeJsonArray, Integer.valueOf(storeId));
|
batchAddActiveShopBase(activeJsonArray, Integer.valueOf(storeId));
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量新增或更新活动商品数据
|
* 批量新增或更新活动商品数据
|
||||||
|
*
|
||||||
* @param jsonArray
|
* @param jsonArray
|
||||||
*/
|
*/
|
||||||
private void batchAddActiveShopBase(JSONArray jsonArray,Integer storeId) {
|
private void batchAddActiveShopBase(JSONArray jsonArray, Integer storeId) {
|
||||||
List<ShopStoreActivityBase> updateShopStoreActivityBaseList=new ArrayList<>();
|
List<ShopStoreActivityBase> updateShopStoreActivityBaseList = new ArrayList<>();
|
||||||
Map<String, String> stringIntegerMap= checkExistingActive(jsonArray,storeId);
|
Map<String, String> stringIntegerMap = checkExistingActive(jsonArray, storeId);
|
||||||
List<String> productNumbers=new ArrayList<>();
|
List<String> productNumbers = new ArrayList<>();
|
||||||
jsonArray.stream().parallel().forEach(object->{
|
jsonArray.stream().parallel().forEach(object -> {
|
||||||
final JSONObject jsonObj= (JSONObject) object;
|
final JSONObject jsonObj = (JSONObject) object;
|
||||||
synchronized (productNumbers) {
|
synchronized (productNumbers) {
|
||||||
String itemNo=jsonObj.getStr("itemNo");
|
String itemNo = jsonObj.getStr("itemNo");
|
||||||
productNumbers.add(itemNo);
|
productNumbers.add(itemNo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Map<String,Long> shopProduckKeyMap=shopProductBaseService.getProductBasicIdByStore(storeId,productNumbers);//获取货架号对应的商品id
|
Map<String, Long> shopProduckKeyMap = shopProductBaseService.getProductBasicIdByStore(storeId, productNumbers);//获取货架号对应的商品id
|
||||||
Map<String,String> shopItemKeyMap=shopProductItemService.getProductItemIdByStore(storeId,productNumbers);//获取商品id对应的item的id
|
Map<String, String> shopItemKeyMap = shopProductItemService.getProductItemIdByStore(storeId, productNumbers);//获取商品id对应的item的id
|
||||||
|
|
||||||
Map<String,String> rulesChe=new HashMap();//存储rule格式activeId:rules,如果不存在则从数据库取,存在则从缓存取数据
|
List<String> activityIds = new ArrayList<>();
|
||||||
jsonArray.forEach(object->{
|
if (!stringIntegerMap.isEmpty()) {
|
||||||
final JSONObject jsonObj= (JSONObject) object;
|
stringIntegerMap.forEach((k, v) -> {
|
||||||
String activityName=jsonObj.getStr("activityName");
|
String activityId = v.split("__")[0];
|
||||||
Integer activityTypeId=jsonObj.getInt("activityTypeId");
|
activityIds.add(activityId);
|
||||||
if(null==activityTypeId){
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Long> shopStoreActvityItems = shopStoreActivityItemService.getExistingActvieShopItem(activityIds, storeId);
|
||||||
|
//activity_id, product_id,item_id
|
||||||
|
List<ShopStoreActivityItem> addShopStoreActivityItems = new ArrayList<>();
|
||||||
|
List<ShopStoreActivityItem> updteShopStoreActivityItems = new ArrayList<>();
|
||||||
|
Map<String, String> rulesChe = new HashMap();//存储rule格式activeId:rules,如果不存在则从数据库取,存在则从缓存取数据
|
||||||
|
jsonArray.forEach(object -> {
|
||||||
|
final JSONObject jsonObj = (JSONObject) object;
|
||||||
|
String activityName = jsonObj.getStr("activityName");
|
||||||
|
Integer activityTypeId = jsonObj.getInt("activityTypeId");
|
||||||
|
if (null == activityTypeId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String ruleType="";
|
String ruleType = "";
|
||||||
List<org.json.JSONObject> newItems=new ArrayList<>();
|
List<org.json.JSONObject> newItems = new ArrayList<>();
|
||||||
Long productId=null;
|
Long productId = null;
|
||||||
String itemNo=jsonObj.getStr("itemNo");
|
String itemNo = jsonObj.getStr("itemNo");
|
||||||
BigDecimal discount=jsonObj.getBigDecimal("discount");
|
BigDecimal discount = jsonObj.getBigDecimal("discount");
|
||||||
if(shopProduckKeyMap.containsKey(itemNo)){
|
if (shopProduckKeyMap.containsKey(itemNo)) {
|
||||||
productId= (Long) shopProduckKeyMap.get(itemNo);
|
productId = (Long) shopProduckKeyMap.get(itemNo);
|
||||||
}
|
}
|
||||||
if(null==productId){
|
if (null == productId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date activityStarttime=jsonObj.getDate("activityStarttime");
|
Date activityStarttime = jsonObj.getDate("activityStarttime");
|
||||||
Integer activityState=jsonObj.getInt("activityState");
|
Integer activityState = jsonObj.getInt("activityState");
|
||||||
String flowNo=jsonObj.getStr("flowNo");
|
String flowNo = jsonObj.getStr("flowNo");
|
||||||
|
if (stringIntegerMap.containsKey(flowNo)) {//更新
|
||||||
String key=activityName+"_"+activityStarttime.getTime()+"_"+activityState+"_"+flowNo;
|
String keyVal = MapUtil.getStr(stringIntegerMap, flowNo);
|
||||||
|
String activityId = keyVal.split("__")[0];
|
||||||
if(stringIntegerMap.containsKey(key)){//更新
|
String rules = "";
|
||||||
String keyVal=MapUtil.getStr(stringIntegerMap,key);
|
if (null != rulesChe.get(activityId)) {
|
||||||
String activityId=keyVal.split("_")[0];
|
rules = rulesChe.get(activityId);
|
||||||
String rules="";
|
} else {
|
||||||
if(null!=rulesChe.get(activityId)){
|
rules = keyVal.split("__")[1].equals("0") ? null : keyVal.split("_")[1];
|
||||||
rules=rulesChe.get(activityId);
|
|
||||||
}else {
|
|
||||||
rules=keyVal.split("__")[1].equals("0")?null:keyVal.split("_")[1];
|
|
||||||
}
|
}
|
||||||
String itemIds= shopItemKeyMap.get(productId);
|
String itemIds = shopItemKeyMap.get(String.valueOf(productId));
|
||||||
// if(null!=itemIds){
|
// if(null!=itemIds){
|
||||||
// itemIds= (String) shopItemKeyMap.get(String.valueOf(productId));
|
// itemIds= (String) shopItemKeyMap.get(String.valueOf(productId));
|
||||||
// }
|
// }
|
||||||
assert itemIds != null;
|
assert itemIds != null;
|
||||||
|
BigDecimal oldPrice;
|
||||||
|
BigDecimal specPrice;
|
||||||
|
BigDecimal newDiscout = new BigDecimal(1);
|
||||||
if (activityTypeId == 1) {//限时秒杀
|
if (activityTypeId == 1) {//限时秒杀
|
||||||
ruleType=ActiveShopJsonUtils.SECKILL;
|
ruleType = ActiveShopJsonUtils.SECKILL;
|
||||||
BigDecimal oldPrice=jsonObj.getBigDecimal("oldPrice");
|
oldPrice = jsonObj.getBigDecimal("oldPrice");
|
||||||
BigDecimal specPrice=jsonObj.getBigDecimal("specPrice");
|
specPrice = jsonObj.getBigDecimal("specPrice");
|
||||||
if(oldPrice.compareTo(BigDecimal.ZERO)>0&&specPrice.compareTo(BigDecimal.ZERO)>0){
|
if (oldPrice.compareTo(BigDecimal.ZERO) > 0 && specPrice.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
BigDecimal newDiscout=specPrice.divide(oldPrice,4, RoundingMode.HALF_UP);
|
newDiscout = specPrice.divide(oldPrice, 4, RoundingMode.HALF_UP);
|
||||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,newDiscout));//获取满减规则的itemid
|
newItems.addAll(getFulReduItemList(itemIds, ruleType, newDiscout));//获取满减规则的itemid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (activityTypeId == 2) {//折扣
|
if (activityTypeId == 2) {//折扣
|
||||||
if(discount.compareTo(BigDecimal.ZERO)<=0){
|
if (discount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
logger.error("商品折扣要大于0");
|
logger.error("商品折扣要大于0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ruleType=ActiveShopJsonUtils.DISCOUNT;
|
ruleType = ActiveShopJsonUtils.DISCOUNT;
|
||||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,discount));//获取满减规则的itemid
|
newItems.addAll(getFulReduItemList(itemIds, ruleType, discount));//获取满减规则的itemid
|
||||||
}
|
}
|
||||||
if (activityTypeId == 3) {//满减
|
if (activityTypeId == 3) {//满减
|
||||||
ruleType=ActiveShopJsonUtils.FULLREDUCE;
|
ruleType = ActiveShopJsonUtils.FULLREDUCE;
|
||||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,null));//获取满减规则的itemid
|
newItems.addAll(getFulReduItemList(itemIds, ruleType, null));//获取满减规则的itemid
|
||||||
}
|
}
|
||||||
|
|
||||||
String newRules= ActiveShopJsonUtils.buildPromotionRule(ruleType,rules,newItems);
|
String newRules = ActiveShopJsonUtils.buildPromotionRule(ruleType, rules, newItems);
|
||||||
rulesChe.put(activityId,newRules);
|
rulesChe.put(activityId, newRules);
|
||||||
}
|
String[] itemIdsArray = itemIds.split("_")[0].split(",");
|
||||||
|
String category_id = shopItemKeyMap.get(productId + ":category_id");
|
||||||
|
String unitprices = itemIds.split("_")[1];
|
||||||
|
String[] priceArray = unitprices.split(",");
|
||||||
|
for (int i = 0; i < itemIdsArray.length; i++) {
|
||||||
|
ShopStoreActivityItem shopStoreActivityItem = new ShopStoreActivityItem();
|
||||||
|
shopStoreActivityItem.setActivity_id(Integer.valueOf(activityId));
|
||||||
|
shopStoreActivityItem.setActivity_type_id(activityTypeId);
|
||||||
|
shopStoreActivityItem.setActivity_item_state(activityState);
|
||||||
|
shopStoreActivityItem.setActivity_item_starttime(activityStarttime);
|
||||||
|
shopStoreActivityItem.setActivity_item_endtime(jsonObj.getDate("activityEndtime"));
|
||||||
|
shopStoreActivityItem.setProduct_id(productId);
|
||||||
|
shopStoreActivityItem.setItem_id(Long.valueOf(itemIdsArray[i]));
|
||||||
|
shopStoreActivityItem.setActivity_item_min_quantity(jsonObj.getBigDecimal("activityItemMinQuantity").intValue());
|
||||||
|
shopStoreActivityItem.setCategory_id(Integer.valueOf(category_id));
|
||||||
|
shopStoreActivityItem.setStore_id(storeId);
|
||||||
|
|
||||||
|
String activityItemKey = activityId + "-" + productId + "-" + itemIdsArray[i];
|
||||||
|
Long shopActivyItemId = shopStoreActvityItems.get(activityItemKey);
|
||||||
|
if (newDiscout.compareTo(BigDecimal.ZERO) < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BigDecimal price = new BigDecimal(priceArray[i]).multiply(newDiscout).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
shopStoreActivityItem.setActivity_item_price(price);
|
||||||
|
if (ObjectUtil.isNotEmpty(shopActivyItemId)) {
|
||||||
|
shopStoreActivityItem.setActivity_item_id(shopActivyItemId);
|
||||||
|
updteShopStoreActivityItems.add(shopStoreActivityItem);
|
||||||
|
} else {
|
||||||
|
addShopStoreActivityItems.add(shopStoreActivityItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (!rulesChe.isEmpty()) {
|
||||||
if(!rulesChe.isEmpty()){
|
rulesChe.forEach((k, v) -> {
|
||||||
rulesChe.forEach((k,v)->{
|
if (StringUtils.isNotEmpty(v)) {
|
||||||
if(StringUtils.isNotEmpty(v)){
|
ShopStoreActivityBase shopStoreActivityBase = new ShopStoreActivityBase();
|
||||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
|
||||||
shopStoreActivityBase.setActivity_id(Integer.valueOf(k));
|
shopStoreActivityBase.setActivity_id(Integer.valueOf(k));
|
||||||
shopStoreActivityBase.setActivity_rule(v);
|
shopStoreActivityBase.setActivity_rule(v);
|
||||||
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)){
|
if (CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)) {
|
||||||
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CollectionUtil.isNotEmpty(addShopStoreActivityItems)) {
|
||||||
|
shopStoreActivityItemService.saveBatch(addShopStoreActivityItems, addShopStoreActivityItems.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CollectionUtil.isNotEmpty(updteShopStoreActivityItems)){
|
||||||
|
shopStoreActivityItemService.updateBatchById(updteShopStoreActivityItems,updteShopStoreActivityItems.size());
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("同步活动商品数据结束:更新共{}条活动数据,商品数据为{}条",updateShopStoreActivityBaseList.size(),jsonArray.size());
|
logger.info("同步活动商品数据结束:更新共{}条活动数据,商品数据为{}条",updateShopStoreActivityBaseList.size(),jsonArray.size());
|
||||||
|
logger.info("同步活动商品数据结束:新增数据{}条,更新{}条活动数据,商品数据为{}条",addShopStoreActivityItems.size(),updteShopStoreActivityItems.size(),jsonArray.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user