Compare commits
3 Commits
003e1b8d86
...
a22ec2ebf7
| Author | SHA1 | Date | |
|---|---|---|---|
| a22ec2ebf7 | |||
| ef79fe601b | |||
| 310f827782 |
@ -0,0 +1,29 @@
|
||||
package com.small.client.Utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BigDecimalFormatter {
|
||||
public static String formatWithoutTrailingZeros(BigDecimal number) {
|
||||
if (number == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 去除末尾0并转换为普通字符串表示
|
||||
BigDecimal stripped = number.stripTrailingZeros();
|
||||
String result = stripped.toPlainString();
|
||||
|
||||
// 处理结果为负0的情况(返回"0"而不是"-0")
|
||||
if (result.startsWith("-0")) {
|
||||
if (result.indexOf('.') == -1) {
|
||||
if (result.length() == 2) { // "-0"
|
||||
return "0";
|
||||
} else if (result.matches("-0+")) { // "-000"
|
||||
return "0";
|
||||
}
|
||||
} else if (result.matches("-0\\.0*")) { // "-0.0" 或 "-0.00"
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.small.client.Utils;
|
||||
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.small.client.dto.StoreDbConfig;
|
||||
@ -40,9 +41,12 @@ 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 final String URL_SYNC_ACTIVE="/shop/sync/third/syncAtive";//同步活动到服务器
|
||||
|
||||
public static final String URL_SYNC_ACTIVE_SHOP="/shop/sync/third/syncAtiveShop";//同步活动商品到服务器
|
||||
|
||||
public static String postData(RestTemplate restTemplate, String url,Object modelObject){
|
||||
// 创建表单参数
|
||||
// MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
@ -103,4 +107,5 @@ public class HttpUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -93,4 +93,15 @@ public class WebController {
|
||||
sxDataService.syncStoreData(new DataBaseInfo(),sxDataService.getCommentModel());
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/syncActives")
|
||||
public void syncActives(){
|
||||
sxDataService.syncAtive(new DataBaseInfo(),sxDataService.getCommentModel());
|
||||
}
|
||||
|
||||
@RequestMapping("/syncActives")
|
||||
public void syncAtiveShops(){
|
||||
sxDataService.syncAtiveShops(new DataBaseInfo(),sxDataService.getCommentModel());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -244,5 +244,100 @@ public class BaseDao {
|
||||
return resultDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* 带分页数据
|
||||
* @param ip
|
||||
* @param username
|
||||
* @param password
|
||||
* @param dataBaseName
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public ResultDto baseFindSpecListPage(String ip, String username, String password,Integer portNumber, String dataBaseName, int pageNo, int pageSize,String where){
|
||||
Connection connection=getConnection(ip,username,password,portNumber,dataBaseName);
|
||||
int start=(pageNo-1)*pageSize+1;
|
||||
int end=pageNo*pageSize;
|
||||
// String sql=" select * from( " +
|
||||
// " select ROW_NUMBER() OVER(ORDER BY %s) as rowId,* from %s %s" +
|
||||
// " ) as r where rowId between %s and %s";
|
||||
|
||||
String sql = "select * from( \n" +
|
||||
" select \n" +
|
||||
" ROW_NUMBER() OVER(order by t.flow_no) as rownum, \n" +
|
||||
" t.* \n" +
|
||||
" from \n" +
|
||||
" ( \n" +
|
||||
" select \n" +
|
||||
" ROW_NUMBER() OVER(partition by b.start_date, \n" +
|
||||
" b.end_date, \n" +
|
||||
" b.special_type,b.discount \n" +
|
||||
" ORDER BY \n" +
|
||||
" b.start_date) as rowId, \n" +
|
||||
" b.* \n" +
|
||||
" from \n" +
|
||||
" t_rm_spec_price b %s \n" +
|
||||
" )t \n" +
|
||||
" where \n" +
|
||||
" t.rowId = 1 \n" +
|
||||
" )t where rownum between %s and %s ";
|
||||
|
||||
sql=String.format(sql,where,start,end);
|
||||
log.info(sql);
|
||||
ResultDto resultDto=new ResultDto();
|
||||
ResultSet rs=null;
|
||||
try {
|
||||
PreparedStatement ps= connection.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
log.info("数据库查询异常方法{},异常信息{}","com.suisung.mall.shop.sixun.dao.BaseDao.baseFindSpecListPage",e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
resultDto.setResultSet(rs);
|
||||
resultDto.setConnection(connection);
|
||||
return resultDto;
|
||||
}
|
||||
|
||||
public Integer getBaseSpecTotal(String ip, String username, String password,Integer portNumber, String dataBaseName,String where){
|
||||
int total=0;
|
||||
Connection connection=getConnection(ip,username,password,portNumber,dataBaseName);
|
||||
try {
|
||||
String sql = "select\n" +
|
||||
" COUNT(1)\n" +
|
||||
"from\n" +
|
||||
" (\n" +
|
||||
" select\n" +
|
||||
" ROW_NUMBER() OVER(partition by b.start_date,\n" +
|
||||
" b.end_date,\n" +
|
||||
" b.special_type\n" +
|
||||
" ORDER BY\n" +
|
||||
" b.start_date) as rowId,\n" +
|
||||
" b.*\n" +
|
||||
" from\n" +
|
||||
" t_rm_spec_price b %s \n" +
|
||||
")t\n" +
|
||||
"where\n" +
|
||||
" t.rowId = 1";
|
||||
sql=String.format(sql,where);
|
||||
log.info(sql);
|
||||
PreparedStatement ps= connection.prepareStatement(sql);
|
||||
ResultSet rs=ps.executeQuery();
|
||||
while (rs.next()){
|
||||
total=rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.info("数据库查询异常方法{},异常信息{}","com.suisung.mall.shop.sixun.dao.BaseDao.getBaseSpecTotal",e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package com.small.client.dao;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.small.client.Utils.BigDecimalFormatter;
|
||||
import com.small.client.dto.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -498,28 +500,169 @@ public class SxDataDao extends BaseDao{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新库存为负数的数据,避免超卖
|
||||
*获取促销活动价格 时段特价单
|
||||
* @param dataBaseInfo
|
||||
* @throws SQLException
|
||||
* @return
|
||||
*/
|
||||
public void baseUpdateImBrancStock(DataBaseInfo dataBaseInfo) throws SQLException {
|
||||
Connection connection=getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword()
|
||||
,dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName());
|
||||
String sql = "update t_im_branch_stock set stock_qty= 0,oper_date=? where stock_qty<0";
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
try (PreparedStatement ps = connection.prepareStatement(sql)) {
|
||||
ps.setTimestamp(1,timestamp);
|
||||
ps.executeUpdate();
|
||||
}catch (RuntimeException e){
|
||||
throw new RuntimeException(e.getMessage());
|
||||
public List<ActiveDto> getActiveList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
|
||||
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
|
||||
ResultDto resultDto=baseFindSpecListPage(dataBaseInfo.getIp()
|
||||
,dataBaseInfo.getUserName()
|
||||
,dataBaseInfo.getPassword()
|
||||
,dataBaseInfo.getDbPort()
|
||||
,dataBaseInfo.getDataBaseName()
|
||||
,pageNo
|
||||
,pageSize
|
||||
,where);
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
List<ActiveDto> activeDtos=new ArrayList<>();
|
||||
try {
|
||||
while (rs.next()) {
|
||||
ActiveDto activeDto=new ActiveDto();
|
||||
String specialType=rs.getString("special_type").trim();
|
||||
if(specialType.equals("6")||specialType.equals("G")){//折扣
|
||||
BigDecimal discount=rs.getBigDecimal("discount");
|
||||
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("discount").multiply(new BigDecimal(10)));
|
||||
activeDto.setActivityName(rs.getString(discountStr+"折商品"));
|
||||
activeDto.setActivityTypeId(2);
|
||||
activeDto.setDiscount(discount);
|
||||
}
|
||||
if(specialType.equals("0")){//特价(秒杀)
|
||||
activeDto.setActivityName(rs.getString("限时特价秒杀"));
|
||||
activeDto.setActivityTypeId(1);
|
||||
}
|
||||
if(specialType.equals("E")){//满减
|
||||
String total1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price"));
|
||||
String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price"));
|
||||
String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1")));
|
||||
String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
|
||||
activeDto.setActivityName(rs.getString("满")+total1+"减"+max1+",满"+total2+"减"+max2);
|
||||
List<ActiveMaxDes> activeMaxDesList=new ArrayList<>();
|
||||
ActiveMaxDes activeMaxDes=new ActiveMaxDes();
|
||||
activeMaxDes.setMaxNum(rs.getBigDecimal("spe_price"));
|
||||
activeMaxDes.setTotal(rs.getBigDecimal("old_price"));
|
||||
activeMaxDesList.add(activeMaxDes);
|
||||
BigDecimal new_price1=rs.getBigDecimal("new_price1");
|
||||
BigDecimal old_price1=rs.getBigDecimal("old_price1");
|
||||
if(new_price1.compareTo(BigDecimal.ZERO)>0&&old_price1.compareTo(BigDecimal.ZERO)>0){
|
||||
ActiveMaxDes activeMaxDes2=new ActiveMaxDes();
|
||||
activeMaxDes2.setMaxNum(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1")));
|
||||
activeMaxDes2.setTotal(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
|
||||
activeMaxDesList.add(activeMaxDes2);
|
||||
}
|
||||
activeDto.setActivityTypeId(3);
|
||||
activeDto.setActiveMaxDesList(activeMaxDesList);
|
||||
}
|
||||
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
|
||||
activeDto.setActivityStarttime(rs.getDate("start_date"));
|
||||
activeDto.setActivityEndtime(rs.getDate("end_date"));
|
||||
if(DateUtil.compare(activeDto.getActivityEndtime(),DateUtil.date())>0){
|
||||
activeDto.setActivityState(1);//正常进行中
|
||||
}else {
|
||||
activeDto.setActivityState(2);//结束
|
||||
}
|
||||
activeDtos.add(activeDto);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}finally {
|
||||
if (connection!=null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
return activeDtos;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public Integer getActiveCount(DataBaseInfo dataBaseInfo){
|
||||
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
|
||||
return getBaseSpecTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
|
||||
where);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public Integer getAllSpecCount(DataBaseInfo dataBaseInfo){
|
||||
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
|
||||
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),
|
||||
dataBaseInfo.getDataBaseName(),T_RM_SPEC_PRICE,where);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 折扣商品
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public List<ActiveShopInfo> getAllSpecPriceList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
|
||||
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
|
||||
ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp()
|
||||
,dataBaseInfo.getUserName()
|
||||
,dataBaseInfo.getPassword()
|
||||
,dataBaseInfo.getDbPort()
|
||||
,dataBaseInfo.getDataBaseName()
|
||||
,T_RM_SPEC_PRICE
|
||||
,ITEM_NO
|
||||
,pageNo
|
||||
,pageSize
|
||||
,where);
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
List<ActiveShopInfo> activeShopInfos=new ArrayList<>();
|
||||
try {
|
||||
while (rs.next()) {
|
||||
ActiveShopInfo activeShopInfo=new ActiveShopInfo();
|
||||
activeShopInfo.setItemNo(rs.getString("item_no").trim());
|
||||
String specialType=rs.getString("special_type").trim();
|
||||
if(specialType.equals("6")||specialType.equals("G")){//折扣
|
||||
BigDecimal discount=rs.getBigDecimal("discount");
|
||||
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10)));
|
||||
activeShopInfo.setActivityName(rs.getString(discountStr+"折商品"));
|
||||
activeShopInfo.setActivityTypeId(2);
|
||||
}
|
||||
if(specialType.equals("0")){//特价(秒杀)
|
||||
activeShopInfo.setActivityName(rs.getString("限时特价秒杀"));
|
||||
activeShopInfo.setOldPrice(rs.getBigDecimal("old_price"));
|
||||
activeShopInfo.setSpecPrice(rs.getBigDecimal("spec_price"));
|
||||
activeShopInfo.setActivityTypeId(1);
|
||||
}
|
||||
if(specialType.equals("E")){//满减
|
||||
String total1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price"));
|
||||
String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price"));
|
||||
String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1")));
|
||||
String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
|
||||
activeShopInfo.setActivityName(rs.getString("满")+total1+"减"+max1+",满"+total2+"减"+max2);
|
||||
activeShopInfo.setActivityTypeId(3);
|
||||
}
|
||||
activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
|
||||
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
|
||||
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
|
||||
activeShopInfo.setActivityState(1);//正常进行中
|
||||
}else {
|
||||
activeShopInfo.setActivityState(2);//结束
|
||||
}
|
||||
activeShopInfos.add(activeShopInfo);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return activeShopInfos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
45
client/src/main/java/com/small/client/dto/ActiveDto.java
Normal file
45
client/src/main/java/com/small/client/dto/ActiveDto.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.small.client.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ActiveDto implements Serializable {
|
||||
|
||||
|
||||
@ApiModelProperty(value = "活动名称")
|
||||
private String activityName;
|
||||
|
||||
@ApiModelProperty(value = "活动类型 1秒杀;2单件折扣,3满减")
|
||||
private Integer activityTypeId;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动开始时间")
|
||||
private Date activityStarttime;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动结束时间")
|
||||
private Date activityEndtime;
|
||||
|
||||
@ApiModelProperty(value = "活动状态(ENUM):0-未开启;1-正常;2-已结束;3-管理员关闭;4-商家关闭")
|
||||
private Integer activityState;
|
||||
|
||||
@ApiModelProperty(value = "发布时间")
|
||||
private Date activityReleasetime;
|
||||
|
||||
@ApiModelProperty(value = "折扣")
|
||||
private BigDecimal discount;
|
||||
|
||||
@ApiModelProperty(value = "满减规则")
|
||||
private List<ActiveMaxDes> activeMaxDesList;
|
||||
|
||||
}
|
||||
13
client/src/main/java/com/small/client/dto/ActiveMaxDes.java
Normal file
13
client/src/main/java/com/small/client/dto/ActiveMaxDes.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.small.client.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class ActiveMaxDes {
|
||||
|
||||
private BigDecimal total;
|
||||
|
||||
private BigDecimal maxNum;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.small.client.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ActiveShopInfo {
|
||||
|
||||
@ApiModelProperty(value = "商品编号")
|
||||
private String itemNo;
|
||||
|
||||
@ApiModelProperty(value = "活动名称")
|
||||
private String activityName;
|
||||
|
||||
@ApiModelProperty(value = "活动类型 1秒杀;2单件折扣,3满减")
|
||||
private Integer activityTypeId;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动开始时间")
|
||||
private Date activityStarttime;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动结束时间")
|
||||
private Date activityEndtime;
|
||||
|
||||
@ApiModelProperty(value = "折扣")
|
||||
private BigDecimal discount;
|
||||
|
||||
@ApiModelProperty(value = "活动状态(ENUM):0-未开启;1-正常;2-已结束;3-管理员关闭;4-商家关闭")
|
||||
private Integer activityState;
|
||||
|
||||
@ApiModelProperty(value = "原价")
|
||||
private BigDecimal oldPrice;//原价
|
||||
|
||||
@ApiModelProperty(value = "折后价")
|
||||
private BigDecimal specPrice;//折后价
|
||||
}
|
||||
@ -133,8 +133,8 @@ public abstract class SxDataAbstService {
|
||||
for (SxSyncGoods sxSyncGood:sxSyncGoods){
|
||||
sxGoosModel=new SxGoosModel();
|
||||
sxGoosModel.setProduct_name(sxSyncGood.getItem_subname());
|
||||
sxGoosModel.setProduct_number(sxSyncGood.getItem_no().trim());// todo
|
||||
sxGoosModel.setProduct_barcode(sxSyncGood.getItem_subno());// todo
|
||||
sxGoosModel.setProduct_number(sxSyncGood.getItem_no().trim());//
|
||||
sxGoosModel.setProduct_barcode(sxSyncGood.getItem_no().trim());//
|
||||
|
||||
sxGoosModel.setFirst_category_name(commonCache.get(sxSyncGood.getSmall_cls_name()));// todo
|
||||
sxGoosModel.setSecond_category_name("");// todo
|
||||
|
||||
@ -57,4 +57,19 @@ public interface SxDataService {
|
||||
*/
|
||||
void syncStoreData(DataBaseInfo dataBaseInfo,CommentModel commentModel);
|
||||
|
||||
|
||||
/**
|
||||
* 同步商品活动
|
||||
* @param commentModel
|
||||
* @return
|
||||
*/
|
||||
void syncAtive(DataBaseInfo dataBaseInfo,CommentModel commentModel);
|
||||
|
||||
/**
|
||||
* 同步活动商品
|
||||
* @param commentModel
|
||||
* @return
|
||||
*/
|
||||
void syncAtiveShops(DataBaseInfo dataBaseInfo,CommentModel commentModel);
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -319,7 +321,8 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
List<SpecPriceDto> discountList= getDiscountFromCache(dataBaseInfo);
|
||||
List<SpecPriceDto> specPriceDtoList= getSpecPriceFromCache(dataBaseInfo);
|
||||
specPriceDtoList.addAll(discountList);
|
||||
|
||||
Date tenMinutesAgo = Date.from(Instant.now());//刷新时间
|
||||
Date refreshDate= DateUtil.date(tenMinutesAgo);
|
||||
List<String> folders=new ArrayList<>();
|
||||
for (int i = 1; i <=pages; i++) {
|
||||
List<SxSyncGoods> sxSyncGoods= sxDataDao.findBditemInfoListPage(dataBaseInfo,i,SxDataDao.PAGESIZE);
|
||||
@ -342,7 +345,8 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_GOODS_NOTICE_UPLOAD_TO_OSS
|
||||
+"?appKey="+commentModel.getAppKey()
|
||||
+"&sign="+commentModel.getSign()
|
||||
+"&syncType="+DicEnum.MUAL_1.getCode(),
|
||||
+"&syncType="+DicEnum.MUAL_1.getCode()
|
||||
+"&refreshDate="+refreshDate,
|
||||
JSONUtil.parseArray(folders));
|
||||
|
||||
//folders.add(String.valueOf(4));
|
||||
@ -675,9 +679,95 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
|
||||
}
|
||||
}
|
||||
|
||||
private String checkUpdate(){
|
||||
@Override
|
||||
public void syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
|
||||
String where="where 1=1";
|
||||
Integer total =0;
|
||||
if(DicEnum.SYNCTYPE_02.getCode().equals(dataBaseInfo.getSyncType())){
|
||||
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
|
||||
where+=" and b.modify_date>'"+commentModel.getSyncTime()+"' ";
|
||||
where+=" or b.build_date>'"+commentModel.getSyncTime()+"' ";
|
||||
}
|
||||
if(StringUtils.isNotEmpty(dataBaseInfo.getOperDate())){
|
||||
where+=" and t.oper_date>'"+dataBaseInfo.getOperDate()+"' ";
|
||||
}
|
||||
}
|
||||
dataBaseInfo.setWhere(where);
|
||||
total = sxDataDao.getActiveCount(dataBaseInfo);
|
||||
if(total==0){
|
||||
log.info("暂无活动同步");
|
||||
return;
|
||||
}
|
||||
// 总页数
|
||||
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
|
||||
int syncCount =0;
|
||||
String encryptedData= getPrimaryKey();
|
||||
Date tenMinutesAgo = Date.from(Instant.now());//刷新时间
|
||||
Date refreshDate= DateUtil.date(tenMinutesAgo);
|
||||
for (int i = 1; i <=pages; i++) {
|
||||
List<ActiveDto> activeDtos= sxDataDao.getActiveList(dataBaseInfo,i,SxDataDao.PAGESIZE);
|
||||
String jsonString="";
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
jsonString = objectMapper.writeValueAsString(activeDtos);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE
|
||||
+"?primaryKey="+encryptedData, jsonString);
|
||||
if (!HttpUtils.SUCCESSCODE.equals(code)) {
|
||||
continue;
|
||||
}
|
||||
syncCount+=activeDtos.size();
|
||||
}
|
||||
log.info("成功同步活动数据:"+syncCount);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncAtiveShops(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
|
||||
String where="where 1=1";
|
||||
Integer total =0;
|
||||
if(DicEnum.SYNCTYPE_02.getCode().equals(dataBaseInfo.getSyncType())){
|
||||
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
|
||||
where+=" and b.modify_date>'"+commentModel.getSyncTime()+"' ";
|
||||
where+=" or b.build_date>'"+commentModel.getSyncTime()+"' ";
|
||||
}
|
||||
if(StringUtils.isNotEmpty(dataBaseInfo.getOperDate())){
|
||||
where+=" and t.oper_date>'"+dataBaseInfo.getOperDate()+"' ";
|
||||
}
|
||||
}
|
||||
dataBaseInfo.setWhere(where);
|
||||
total = sxDataDao.getAllSpecCount(dataBaseInfo);
|
||||
if(total==0){
|
||||
log.info("暂无活动商品同步");
|
||||
return;
|
||||
}
|
||||
// 总页数
|
||||
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
|
||||
int syncCount =0;
|
||||
String encryptedData= getPrimaryKey();
|
||||
Date tenMinutesAgo = Date.from(Instant.now());//刷新时间
|
||||
Date refreshDate= DateUtil.date(tenMinutesAgo);//todo 要记录刷新时间
|
||||
for (int i = 1; i <=pages; i++) {
|
||||
List<ActiveShopInfo> activeDtos= sxDataDao.getAllSpecPriceList(dataBaseInfo,i,SxDataDao.PAGESIZE);
|
||||
String jsonString="";
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
jsonString = objectMapper.writeValueAsString(activeDtos);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE_SHOP
|
||||
+"?primaryKey="+encryptedData, jsonString);
|
||||
if (!HttpUtils.SUCCESSCODE.equals(code)) {
|
||||
continue;
|
||||
}
|
||||
syncCount+=activeDtos.size();
|
||||
}
|
||||
log.info("成功同步活动商品数据:"+syncCount);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -174,13 +174,13 @@ public class ShopProductItem implements Serializable {
|
||||
@ApiModelProperty(value = "乐观锁")
|
||||
private Integer version;
|
||||
|
||||
// @ApiModelProperty(value = "产品名称")
|
||||
// @TableField(exist=false)
|
||||
// private String productName;
|
||||
@ApiModelProperty(value = "产品itemId组合 用,分开")
|
||||
@TableField(exist=false)
|
||||
private String mergedItemId;
|
||||
|
||||
// @ApiModelProperty(value = "商品SKU(JSON):{'uniq_id':[item_id, price, url]}")
|
||||
// @TableField(exist=false)
|
||||
// private String product_uniqid;
|
||||
@ApiModelProperty(value = "产品价格组合 用,分开")
|
||||
@TableField(exist=false)
|
||||
private String mergedUnitPrices;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package com.suisung.mall.common.modules.store;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.Version;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -15,6 +12,8 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.baomidou.mybatisplus.annotation.FieldStrategy.NOT_EMPTY;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 活动表-通过插件实现
|
||||
@ -37,67 +36,87 @@ public class ShopStoreActivityBase implements Serializable {
|
||||
private Integer activity_id;
|
||||
|
||||
@ApiModelProperty(value = "店铺编号")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer store_id;
|
||||
|
||||
@ApiModelProperty(value = "用户编号")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer user_id;
|
||||
|
||||
@ApiModelProperty(value = "活动名称")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String activity_name;
|
||||
|
||||
@ApiModelProperty(value = "活动标题")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String activity_title;
|
||||
|
||||
@ApiModelProperty(value = "活动说明")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String activity_remark;
|
||||
|
||||
@ApiModelProperty(value = "套餐编号")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_combo_id;
|
||||
|
||||
@ApiModelProperty(value = "活动类型")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_type_id;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动开始时间")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Date activity_starttime;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "活动结束时间")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Date activity_endtime;
|
||||
|
||||
@ApiModelProperty(value = "活动状态(ENUM):0-未开启;1-正常;2-已结束;3-管理员关闭;4-商家关闭")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_state;
|
||||
|
||||
@ApiModelProperty(value = "活动规则(json):不检索{rule_id:{}, rule_id:{}}")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String activity_rule;
|
||||
|
||||
@ApiModelProperty(value = "参与类型(ENUM):1-免费参与;2-积分参与;3-购买参与")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_type;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_order;
|
||||
|
||||
@ApiModelProperty(value = "活动是否完成(ENUM):0-未完成;1-已完成;2-已解散(目前用于团购)")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_is_finish;
|
||||
|
||||
@ApiModelProperty(value = "单品优惠商品编号")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String item_id;
|
||||
|
||||
@ApiModelProperty(value = "分站id")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer subsite_id;
|
||||
|
||||
@ApiModelProperty(value = "活动使用等级(DOT)")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private String activity_use_level;
|
||||
|
||||
@ApiModelProperty(value = "发布时间")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Date activity_releasetime;
|
||||
|
||||
@ApiModelProperty(value = "活动是否线上或线下:0:线上,1:线下")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_on_is_off;
|
||||
|
||||
@ApiModelProperty(value = "分享次数")
|
||||
@TableField(updateStrategy = NOT_EMPTY)
|
||||
private Integer activity_share_num;
|
||||
|
||||
@Version
|
||||
|
||||
@ -289,4 +289,13 @@ public interface ShopProductBaseService extends IBaseService<ShopProductBase> {
|
||||
List<List<ShopProductImage>> shopProductImageList,
|
||||
List<ShopProductValidPeriod> shopProductValidPeriodList,
|
||||
List<ShopProductAssistIndex> shopProductAssistIndexList);
|
||||
|
||||
/**
|
||||
* 加载商品
|
||||
* @param store_id
|
||||
* @return
|
||||
*/
|
||||
Map getProductBasicIdByStore(Integer store_id);
|
||||
|
||||
void clearBasicIdByStore(Integer store_id);
|
||||
}
|
||||
|
||||
@ -70,4 +70,13 @@ public interface ShopProductItemService extends IBaseService<ShopProductItem> {
|
||||
|
||||
int lockSkuStock(Long itemId, int cart_quantity);
|
||||
|
||||
/**
|
||||
* 加载商品
|
||||
* @param store_id
|
||||
* @return
|
||||
*/
|
||||
Map getProductItemIdByStore(Integer store_id);
|
||||
|
||||
void clearProductItemIdByStore(Integer store_id);
|
||||
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ import com.suisung.mall.common.utils.CSVUtils;
|
||||
import com.suisung.mall.common.utils.CheckUtil;
|
||||
import com.suisung.mall.common.utils.CommonUtil;
|
||||
import com.suisung.mall.common.utils.I18nUtil;
|
||||
import com.suisung.mall.core.web.service.RedisService;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.activity.service.ShopActivityGroupbookingService;
|
||||
import com.suisung.mall.shop.base.service.*;
|
||||
@ -68,6 +69,7 @@ import com.suisung.mall.shop.sixun.service.SxSyncGoodsService;
|
||||
import com.suisung.mall.shop.store.service.*;
|
||||
import com.suisung.mall.shop.sync.Utils.ProductPriceCalculator;
|
||||
import com.suisung.mall.shop.sync.Utils.ShopJsonUtils;
|
||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
||||
import com.suisung.mall.shop.sync.service.ProductMappingService;
|
||||
import com.suisung.mall.shop.user.service.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -211,7 +213,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
|
||||
@Autowired
|
||||
private ProductMappingService productMappingService;
|
||||
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@Override
|
||||
@ -5417,6 +5419,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
newShopProductAssistIndexList,updateShopProductAssistIndexList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行批量操作(新增和更新分开处理)
|
||||
*/
|
||||
@ -6151,6 +6154,26 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getProductBasicIdByStore(Integer store_id) {
|
||||
String key=redisService.get(RedisKey.STORESHOPPRODUCTKEY)+":"+store_id;
|
||||
if(null!=redisService.get(key)){
|
||||
return (Map) redisService.get(key);
|
||||
}
|
||||
QueryWrapper<ShopProductBase> queryWrapper=new QueryWrapper();
|
||||
queryWrapper.select("product_number","product_id");
|
||||
List<ShopProductBase> shopProductBaseList= this.list(queryWrapper);
|
||||
Map map= shopProductBaseList.stream().collect(Collectors.toMap(shopBase->shopBase.getProduct_number(),shopBase->shopBase.getProduct_id()));
|
||||
redisService.set(RedisKey.STORESHOPPRODUCTKEY,map,60*10);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearBasicIdByStore(Integer store_id) {
|
||||
String key=redisService.get(RedisKey.STORESHOPPRODUCTKEY)+":"+store_id;
|
||||
if(null!=redisService.get(key)){
|
||||
redisService.del(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ import com.suisung.mall.shop.product.mapper.ShopProductItemMapper;
|
||||
import com.suisung.mall.shop.product.pojo.vo.ProductVo;
|
||||
import com.suisung.mall.shop.product.service.*;
|
||||
import com.suisung.mall.shop.store.service.*;
|
||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
||||
import com.suisung.mall.shop.user.service.ShopUserFavoritesItemService;
|
||||
import com.suisung.mall.shop.user.service.ShopUserProductBrowseService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
@ -2243,6 +2244,36 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getProductItemIdByStore(Integer store_id) {
|
||||
String key= RedisKey.STORESHOPPRODUCITEMTKEY+":"+store_id;
|
||||
if(null!=redisService.get(key)){
|
||||
return (Map) redisService.get(key);
|
||||
}
|
||||
QueryWrapper<ShopProductItem> queryWrapper = new QueryWrapper<>();
|
||||
/**
|
||||
* 一对多,如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
|
||||
*/
|
||||
queryWrapper.select("product_id","GROUP_CONCAT(item_id SEPARATOR ',') AS mergedItemId","GROUP_CONCAT(item_unit_price SEPARATOR ',') AS mergedUnitPrices");
|
||||
queryWrapper.eq("store_id",store_id);
|
||||
queryWrapper.groupBy("product_id");
|
||||
List<ShopProductItem> shopProductItems= this.list(queryWrapper);
|
||||
|
||||
Map map=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getProduct_id,shopProductItem->shopProductItem.getMergedItemId()
|
||||
+"_"+shopProductItem.getMergedUnitPrices()));
|
||||
redisService.set(key,map,60*10);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearProductItemIdByStore(Integer store_id) {
|
||||
String key= RedisKey.STORESHOPPRODUCITEMTKEY+":"+store_id;
|
||||
if(null!=redisService.get(key)){
|
||||
redisService.del(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理库存缓存
|
||||
*
|
||||
@ -2257,4 +2288,6 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,224 @@
|
||||
package com.suisung.mall.shop.sync.Utils;
|
||||
|
||||
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ActiveShopJsonUtils {
|
||||
|
||||
public static final String FULLREDUCE="fullReduce";//满减
|
||||
public static final String DISCOUNT="discount";//折扣
|
||||
public static final String SECKILL="seckill";//秒杀
|
||||
/**
|
||||
* 生成满减活动的规则
|
||||
* @param jsonArray
|
||||
* @return
|
||||
*/
|
||||
public static String getRules(cn.hutool.json.JSONArray jsonArray){
|
||||
cn.hutool.json.JSONObject activity_rule = new cn.hutool.json.JSONObject();
|
||||
List<Map> rules = new ArrayList<>();
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
cn.hutool.json.JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
Map rule = new HashMap();
|
||||
rule.put("total", BigDecimalFormatter.formatWithoutTrailingZeros(jsonObject.getBigDecimal("total")));
|
||||
rule.put("max_num", BigDecimalFormatter.formatWithoutTrailingZeros(jsonObject.getBigDecimal("maxNum")));
|
||||
rule.put("item", new ArrayList());
|
||||
rules.add(rule);
|
||||
activity_rule.put("rule", rules);
|
||||
}
|
||||
return JSONUtil.toJsonStr(activity_rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建促销规则JSON(支持批量添加商品)
|
||||
* @param type 促销类型: fullReduce(满减), discount(折扣), seckill(秒杀)
|
||||
* @param dbRuleStr 数据库中的规则字符串
|
||||
* @param newItems 要添加的新商品列表
|
||||
* @return 更新后的JSON字符串
|
||||
*/
|
||||
public static String buildPromotionRule(String type, String dbRuleStr, List<JSONObject> newItems) {
|
||||
JSONObject ruleObj;
|
||||
|
||||
// 解析或初始化基础JSON结构
|
||||
if (dbRuleStr == null || dbRuleStr.trim().isEmpty()) {
|
||||
ruleObj = createBaseRule(type);
|
||||
} else {
|
||||
ruleObj = new JSONObject(dbRuleStr);
|
||||
}
|
||||
|
||||
// 根据类型处理商品数据
|
||||
switch (type) {
|
||||
case FULLREDUCE:
|
||||
handleFullReduce(ruleObj, newItems);
|
||||
break;
|
||||
case DISCOUNT:
|
||||
handleDiscount(ruleObj, newItems);
|
||||
break;
|
||||
case SECKILL:
|
||||
handleSeckill(ruleObj, newItems);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的促销类型: " + type);
|
||||
}
|
||||
|
||||
return ruleObj.toString();
|
||||
}
|
||||
|
||||
// 创建基础规则结构
|
||||
private static JSONObject createBaseRule(String type) {
|
||||
JSONObject ruleObj = new JSONObject();
|
||||
ruleObj.put("discount", new JSONArray());
|
||||
ruleObj.put("rule", new JSONArray());
|
||||
|
||||
JSONObject requirement = new JSONObject();
|
||||
JSONObject buy = new JSONObject();
|
||||
buy.put("item", new JSONArray());
|
||||
buy.put("subtotal", "");
|
||||
requirement.put("buy", buy);
|
||||
ruleObj.put("requirement", requirement);
|
||||
|
||||
// 满减类型添加默认规则
|
||||
if ("fullReduce".equals(type)) {
|
||||
JSONObject ruleItem = new JSONObject();
|
||||
ruleItem.put("item", new JSONArray());
|
||||
ruleObj.getJSONArray("rule").put(ruleItem);
|
||||
}
|
||||
|
||||
return ruleObj;
|
||||
}
|
||||
|
||||
// 处理满减类型(批量)
|
||||
private static void handleFullReduce(JSONObject ruleObj, List<JSONObject> newItems) {
|
||||
JSONArray itemArray = ruleObj.getJSONObject("requirement")
|
||||
.getJSONObject("buy")
|
||||
.getJSONArray("item");
|
||||
|
||||
// 获取现有商品ID集合用于去重
|
||||
Set<Integer> existingItems = new HashSet<>();
|
||||
for (int i = 0; i < itemArray.length(); i++) {
|
||||
existingItems.add(itemArray.getInt(i));
|
||||
}
|
||||
|
||||
// 添加新商品ID(去重)
|
||||
for (JSONObject item : newItems) {
|
||||
int itemId = item.getInt("item_id");
|
||||
if (!existingItems.contains(itemId)) {
|
||||
itemArray.put(itemId);
|
||||
existingItems.add(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理折扣类型(批量)
|
||||
private static void handleDiscount(JSONObject ruleObj, List<JSONObject> newItems) {
|
||||
JSONArray discountArray = ruleObj.getJSONArray("discount");
|
||||
|
||||
// 创建索引用于快速查找
|
||||
Set<String> existingIds = new HashSet<>();
|
||||
for (int i = 0; i < discountArray.length(); i++) {
|
||||
existingIds.add(discountArray.getJSONObject(i).getString("item_id"));
|
||||
}
|
||||
|
||||
// 添加新商品(去重)
|
||||
for (JSONObject item : newItems) {
|
||||
String itemId = item.getString("item_id");
|
||||
|
||||
// 检查是否已存在相同商品
|
||||
boolean exists = existingIds.contains(itemId);
|
||||
|
||||
// 如果存在则更新,否则添加
|
||||
if (exists) {
|
||||
// 更新现有商品折扣率
|
||||
for (int i = 0; i < discountArray.length(); i++) {
|
||||
JSONObject discountItem = discountArray.getJSONObject(i);
|
||||
if (discountItem.getString("item_id").equals(itemId)) {
|
||||
discountItem.put("rate", item.getString("rate"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 添加新商品
|
||||
JSONObject discountItem = new JSONObject();
|
||||
discountItem.put("item_id", itemId);
|
||||
discountItem.put("rate", item.getString("rate"));
|
||||
discountArray.put(discountItem);
|
||||
existingIds.add(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理秒杀类型(批量)
|
||||
private static void handleSeckill(JSONObject ruleObj, List<JSONObject> newItems) {
|
||||
JSONArray discountArray = ruleObj.getJSONArray("discount");
|
||||
|
||||
// 创建索引用于快速查找
|
||||
Set<Integer> existingIds = new HashSet<>();
|
||||
for (int i = 0; i < discountArray.length(); i++) {
|
||||
existingIds.add(discountArray.getJSONObject(i).getInt("item_id"));
|
||||
}
|
||||
|
||||
// 添加新商品(去重)
|
||||
for (JSONObject item : newItems) {
|
||||
int itemId = item.getInt("item_id");
|
||||
|
||||
// 检查是否已存在相同商品
|
||||
boolean exists = existingIds.contains(itemId);
|
||||
|
||||
// 如果存在则更新,否则添加
|
||||
if (exists) {
|
||||
// 更新现有商品价格
|
||||
for (int i = 0; i < discountArray.length(); i++) {
|
||||
JSONObject seckillItem = discountArray.getJSONObject(i);
|
||||
if (seckillItem.getInt("item_id") == itemId) {
|
||||
seckillItem.put("price", item.getInt("price"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 添加新商品
|
||||
JSONObject seckillItem = new JSONObject();
|
||||
seckillItem.put("item_id", itemId);
|
||||
seckillItem.put("price", item.getInt("price"));
|
||||
discountArray.put(seckillItem);
|
||||
existingIds.add(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 示例使用
|
||||
String dbRule = ""; // 模拟从数据库读取的规则字符串
|
||||
|
||||
// 创建折扣商品列表
|
||||
JSONObject discountItem1 = new JSONObject().put("item_id", "24839").put("rate", "15");
|
||||
JSONObject discountItem2 = new JSONObject().put("item_id", "24840").put("rate", "20");
|
||||
List<JSONObject> discountItems = Arrays.asList(discountItem1, discountItem2);
|
||||
|
||||
// 构建折扣规则
|
||||
String discountResult = buildPromotionRule("discount", dbRule, discountItems);
|
||||
System.out.println("折扣结果:\n" + discountResult);
|
||||
|
||||
// 创建满减商品列表
|
||||
JSONObject fullReduceItem1 = new JSONObject().put("item_id", 24915);
|
||||
JSONObject fullReduceItem2 = new JSONObject().put("item_id", 24916);
|
||||
List<JSONObject> fullReduceItems = Arrays.asList(fullReduceItem1, fullReduceItem2);
|
||||
|
||||
// 构建满减规则
|
||||
String fullReduceResult = buildPromotionRule("fullReduce", "", fullReduceItems);
|
||||
System.out.println("\n满减结果:\n" + fullReduceResult);
|
||||
|
||||
// 创建秒杀商品列表
|
||||
JSONObject seckillItem1 = new JSONObject().put("item_id", 24850).put("price", 8);
|
||||
JSONObject seckillItem2 = new JSONObject().put("item_id", 24851).put("price", 12);
|
||||
List<JSONObject> seckillItems = Arrays.asList(seckillItem1, seckillItem2);
|
||||
|
||||
// 构建秒杀规则
|
||||
String seckillResult = buildPromotionRule("seckill", null, seckillItems);
|
||||
System.out.println("\n秒杀结果:\n" + seckillResult);
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -151,8 +152,36 @@ public class SyncThirdDataController {
|
||||
public ThirdApiRes uploudToCos(@RequestBody List<String> folders,
|
||||
@RequestParam String appKey,
|
||||
@RequestParam String sign,
|
||||
@RequestParam Date refreshDate,
|
||||
@RequestParam String syncType) {
|
||||
return syncThirdDataService.fileUploadToOss(appKey,sign,syncType,folders);
|
||||
return syncThirdDataService.fileUploadToOss(appKey,sign,syncType,refreshDate,folders);
|
||||
}
|
||||
|
||||
/**
|
||||
* todo test
|
||||
* 目前只同步满减和折扣
|
||||
* @param appKey
|
||||
* @param sign
|
||||
* @param activeJsonArray
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "同步活动数据", notes = "同步商品数据")
|
||||
@RequestMapping(value = "/syncAtive", method = RequestMethod.POST)
|
||||
public ThirdApiRes syncAtive(@RequestParam String appKey,
|
||||
@RequestParam String sign,
|
||||
@RequestBody JSONArray activeJsonArray) {
|
||||
syncThirdDataService.syncActives(appKey,sign,activeJsonArray);
|
||||
return new ThirdApiRes().success("服务器已执行活动数据操作");
|
||||
}
|
||||
|
||||
//todo test
|
||||
@ApiOperation(value = "同步活动商品数据", notes = "同步活动商品数据")
|
||||
@RequestMapping(value = "/syncAtiveShop", method = RequestMethod.POST)
|
||||
public ThirdApiRes syncAtiveShop(@RequestParam String appKey,
|
||||
@RequestParam String sign,
|
||||
@RequestBody JSONArray activeJsonArray) {
|
||||
syncThirdDataService.syncActiveShops(appKey,sign,activeJsonArray);
|
||||
return new ThirdApiRes().success("服务器已执行活动数据操作");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -15,4 +15,7 @@ public class RedisKey {
|
||||
|
||||
public static final String STOREDATAPRODUCTSPECITEM="storedata:ProductSpecItem";
|
||||
|
||||
public static final String STORESHOPPRODUCTKEY="storedata:shopProductkey";
|
||||
|
||||
public static final String STORESHOPPRODUCITEMTKEY="storedata:shopProductItemKey";
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -130,10 +131,29 @@ public interface SyncThirdDataService {
|
||||
|
||||
|
||||
/**
|
||||
*上传文件到cos
|
||||
* @param appKey
|
||||
* @param sign
|
||||
* @param folders
|
||||
* @return
|
||||
*/
|
||||
ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType, List<String> folders);
|
||||
ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType, Date refreshDate, List<String> folders);
|
||||
|
||||
/**
|
||||
*同步活动
|
||||
* @param appKey
|
||||
* @param sign
|
||||
* @param activeJsonArray
|
||||
* @return
|
||||
*/
|
||||
void syncActives(String appKey, String sign, JSONArray activeJsonArray);
|
||||
|
||||
/**
|
||||
*同步活动商品
|
||||
* @param appKey
|
||||
* @param sign
|
||||
* @param activeJsonArray
|
||||
* @return
|
||||
*/
|
||||
void syncActiveShops(String appKey, String sign, JSONArray activeJsonArray);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ 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.map.MapUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -29,10 +30,12 @@ import com.suisung.mall.common.modules.pay.PayUserResource;
|
||||
import com.suisung.mall.common.modules.product.*;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreBase;
|
||||
import com.suisung.mall.common.pojo.req.SyncThirdMemberReq;
|
||||
import com.suisung.mall.common.utils.DateTimeUtils;
|
||||
import com.suisung.mall.common.utils.I18nUtil;
|
||||
import com.suisung.mall.common.utils.JsonUtil;
|
||||
import com.suisung.mall.common.utils.StringUtils;
|
||||
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
||||
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||
@ -45,6 +48,7 @@ import com.suisung.mall.shop.product.service.ShopProductItemService;
|
||||
import com.suisung.mall.shop.product.service.impl.ShopProductBaseServiceImpl;
|
||||
import com.suisung.mall.shop.product.service.impl.ShopProductItemServiceImpl;
|
||||
import com.suisung.mall.shop.sixun.dto.SxGoosModel;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||
import com.suisung.mall.shop.sync.service.ProductMappingService;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
@ -89,7 +93,7 @@ public abstract class SyncBaseThirdSxAbstract{
|
||||
private ShopBaseProductSpecService shopBaseProductSpecService;
|
||||
|
||||
@Autowired
|
||||
private ProductMappingService productMappingService;
|
||||
private ShopStoreActivityBaseService shopStoreActivityBaseService;
|
||||
|
||||
/**
|
||||
* 对商品分类进行保存
|
||||
@ -662,10 +666,9 @@ public abstract class SyncBaseThirdSxAbstract{
|
||||
shopProductItem.setItem_quantity(99); // 库存
|
||||
shopProductItem.setItem_weight(new BigDecimal("0"));//切割重量
|
||||
}
|
||||
|
||||
shopProductItem.setItem_quantity_frozen(0);
|
||||
shopProductItem.setItem_number(jsonObj.getStr("product_number"));// SKU商家编码
|
||||
shopProductItem.setItem_barcode(jsonObj.getStr("product_number")); // 条形码正常情况下就是货号
|
||||
shopProductItem.setItem_barcode(jsonObj.getStr("product_barcode")); // 条形码正常情况下就是货号
|
||||
shopProductItem.setItem_is_default(1);
|
||||
shopProductItem.setItem_enable(shopProductBase.getProduct_state_id());
|
||||
|
||||
@ -813,4 +816,46 @@ public abstract class SyncBaseThirdSxAbstract{
|
||||
return shopBaseProductSpecService.list(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查哪些活动已经存在 根据活动名称+活动状态
|
||||
*/
|
||||
public Map<String, String> checkExistingActive(JSONArray jsonArray,Integer storeId) {
|
||||
List<ShopStoreActivityBase> storeProductPairs = jsonArray.stream()
|
||||
.map(object->{
|
||||
final JSONObject jsonObj= (JSONObject) object;
|
||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
||||
shopStoreActivityBase.setActivity_name(jsonObj.getStr("activityName"));
|
||||
shopStoreActivityBase.setActivity_state(jsonObj.getInt("activityState"));
|
||||
shopStoreActivityBase.setActivity_starttime(jsonObj.getDate("activityStarttime"));
|
||||
return shopStoreActivityBase;
|
||||
})
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ShopStoreActivityBase> existing = batchGetByAtiveShopBase(storeProductPairs,storeId);
|
||||
return existing.stream()
|
||||
.collect(Collectors.toMap(
|
||||
shopStoreActivityBase -> shopStoreActivityBase.getActivity_title()+"_"+shopStoreActivityBase.getActivity_starttime().getTime()+"_"+shopStoreActivityBase.getActivity_state(),
|
||||
shopStoreActivityBase->shopStoreActivityBase.getActivity_id()+"_"+shopStoreActivityBase.getActivity_rule()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据店铺和货号查询商品
|
||||
*/
|
||||
private List<ShopStoreActivityBase> batchGetByAtiveShopBase(List<ShopStoreActivityBase> shopStoreActivityBases,Integer storeId) {
|
||||
if (CollUtil.isEmpty(shopStoreActivityBases)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
QueryWrapper<ShopStoreActivityBase> query = new QueryWrapper<>();
|
||||
query.select("activity_name", "activity_state");
|
||||
shopStoreActivityBases.forEach(shopStoreActivityBase -> {
|
||||
query.or(q -> q.eq("activity_name", shopStoreActivityBase.getActivity_name()).eq("activity_state",shopStoreActivityBase.getActivity_state())
|
||||
.eq("activity_starttime",shopStoreActivityBase.getActivity_starttime())
|
||||
.eq("store_id", storeId));
|
||||
});
|
||||
|
||||
return shopStoreActivityBaseService.list(query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,21 +12,25 @@ 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.map.MapUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.api.StateCode;
|
||||
import com.suisung.mall.common.enums.DicEnum;
|
||||
import com.suisung.mall.common.modules.base.ShopBaseProductBrand;
|
||||
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncGoods;
|
||||
import com.suisung.mall.common.modules.sixun.SxSyncVip;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
||||
import com.suisung.mall.common.modules.sync.StoreDbConfig;
|
||||
import com.suisung.mall.common.modules.sync.SyncApp;
|
||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||
@ -40,6 +44,8 @@ import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
||||
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||
import com.suisung.mall.shop.page.service.OssService;
|
||||
import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
||||
import com.suisung.mall.shop.product.service.ShopProductItemService;
|
||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||
import com.suisung.mall.shop.sixun.dao.SxDataDao;
|
||||
import com.suisung.mall.shop.sixun.dto.DataBaseInfo;
|
||||
@ -50,6 +56,9 @@ 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.store.service.ShopStoreActivityBaseService;
|
||||
import com.suisung.mall.shop.sync.Utils.ActiveShopJsonUtils;
|
||||
import com.suisung.mall.shop.sync.Utils.BigDecimalFormatter;
|
||||
import com.suisung.mall.shop.sync.Utils.ThreadFileUtils;
|
||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
||||
import com.suisung.mall.shop.sync.service.*;
|
||||
@ -72,6 +81,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -134,6 +145,13 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
@Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}")
|
||||
private String TENGXUN_DEFA;
|
||||
|
||||
@Autowired
|
||||
private ShopProductBaseService shopProductBaseService;
|
||||
|
||||
@Autowired
|
||||
private ShopProductItemService shopProductItemService;
|
||||
@Autowired
|
||||
private ShopStoreActivityBaseService shopStoreActivityBaseService;
|
||||
/**
|
||||
* 批量保存商品的分类
|
||||
*
|
||||
@ -826,28 +844,309 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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为空");
|
||||
public ThirdApiRes fileUploadToOss(String appKey, String sign, String syncType,Date refreshDate, List<String> folders) {
|
||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) ) {
|
||||
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
|
||||
}
|
||||
if (folders == null || folders.isEmpty()) {
|
||||
// 验签、appid,必要参数判断
|
||||
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));
|
||||
if (syncApp == null) {
|
||||
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
|
||||
}
|
||||
String storeId = syncApp.getStore_id();
|
||||
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, "没有商品数据");
|
||||
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
|
||||
//更新当前的获取时间,用户客户端获取
|
||||
try {
|
||||
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
|
||||
storeDbConfigQueryWrapper.eq("store_id", storeId);
|
||||
StoreDbConfig storeDbConfig=storeDbConfigService.getOne(storeDbConfigQueryWrapper);
|
||||
if(ObjectUtil.isNotEmpty(storeDbConfig)){
|
||||
storeDbConfig.setRefreshTime(refreshDate);
|
||||
storeDbConfigService.saveOrUpdate(storeDbConfig);
|
||||
}
|
||||
}catch (RuntimeException e){
|
||||
logger.error("同步时间失败"+e.getMessage());
|
||||
}
|
||||
return new ThirdApiRes().success("上传成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void syncActives(String appKey, String sign, JSONArray activeJsonArray) {
|
||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
||||
logger.error("缺少必要参数!");
|
||||
return;
|
||||
}
|
||||
// 验签、appid,必要参数判断
|
||||
SyncApp syncAppO = 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));
|
||||
if (syncAppO == null) {
|
||||
logger.error("签名有误!");
|
||||
return;
|
||||
}
|
||||
String storeId = syncAppO.getStore_id();
|
||||
//活动逻辑
|
||||
batchSaveShopStoreActivityBase(activeJsonArray, Integer.valueOf(storeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增或更新活动数据
|
||||
* @param jsonArray
|
||||
*/
|
||||
private void batchSaveShopStoreActivityBase(JSONArray jsonArray,Integer storeId) {
|
||||
List<ShopStoreActivityBase> addshopStoreActivityBaseList=new ArrayList<>();
|
||||
List<ShopStoreActivityBase> updateShopStoreActivityBaseList=new ArrayList<>();
|
||||
Map<String, String> stringIntegerMap= checkExistingActive(jsonArray,storeId);
|
||||
jsonArray.stream().parallel().forEach(object->{
|
||||
final JSONObject jsonObj= (JSONObject) object;
|
||||
String activityName=jsonObj.getStr("activityName");
|
||||
Integer activityTypeId=jsonObj.getInt("activityTypeId");
|
||||
if(null==activityTypeId){
|
||||
return;
|
||||
}
|
||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
||||
if (activityTypeId == 1) {
|
||||
activityTypeId = StateCode.ACTIVITY_TYPE_LIMITED_DISCOUNT; //限时秒杀
|
||||
}
|
||||
if (activityTypeId == 2) {
|
||||
activityTypeId = StateCode.ACTIVITY_TYPE_ONE_PIECE_DISCOUNT; //折扣
|
||||
}
|
||||
if (activityTypeId == 3) {
|
||||
JSONArray activeMaxDesList=jsonObj.getJSONArray("activeMaxDesList");
|
||||
activityTypeId = StateCode.ACTIVITY_TYPE_REDUCTION; //满减
|
||||
String rules= ActiveShopJsonUtils.getRules(activeMaxDesList);
|
||||
shopStoreActivityBase.setActivity_rule(rules);
|
||||
}
|
||||
Date activityStarttime=jsonObj.getDate("activityStarttime");
|
||||
Date activityEndtime=jsonObj.getDate("activityEndtime");
|
||||
Integer activityState=jsonObj.getInt("activityState");
|
||||
Date activityReleasetime= jsonObj.getDate("activityReleasetime");
|
||||
BigDecimal discount=jsonObj.getBigDecimal("discount");
|
||||
String key=activityName+"_"+activityStarttime.getTime()+"_"+activityState;
|
||||
shopStoreActivityBase.setActivity_state(activityState);
|
||||
shopStoreActivityBase.setActivity_name(activityName);
|
||||
shopStoreActivityBase.setActivity_type(1);//免费参与
|
||||
shopStoreActivityBase.setActivity_releasetime(activityReleasetime);
|
||||
shopStoreActivityBase.setStore_id(storeId);
|
||||
shopStoreActivityBase.setActivity_on_is_off(0);
|
||||
shopStoreActivityBase.setActivity_type_id(activityTypeId);
|
||||
shopStoreActivityBase.setActivity_starttime(activityStarttime);
|
||||
shopStoreActivityBase.setActivity_endtime(activityEndtime);
|
||||
shopStoreActivityBase.setActivity_state(activityState);
|
||||
shopStoreActivityBase.setSubsite_id(0);
|
||||
if(stringIntegerMap.containsKey(key)){//更新
|
||||
String keyVal= MapUtil.getStr(stringIntegerMap,key);
|
||||
shopStoreActivityBase.setActivity_id(MapUtil.getInt(stringIntegerMap,keyVal.split("_")[0]));
|
||||
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||
}else {
|
||||
addshopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||
}
|
||||
|
||||
});
|
||||
if(CollectionUtil.isNotEmpty(addshopStoreActivityBaseList)){
|
||||
shopStoreActivityBaseService.saveBatch(addshopStoreActivityBaseList,addshopStoreActivityBaseList.size());
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)){
|
||||
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将商品添加到活动
|
||||
* 1、找出匹配的活动
|
||||
* 2、新增商品到活动列表
|
||||
* @param appKey
|
||||
* @param sign
|
||||
* @param activeJsonArray
|
||||
*/
|
||||
@Override
|
||||
@Async
|
||||
public void syncActiveShops(String appKey, String sign, JSONArray activeJsonArray) {
|
||||
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(activeJsonArray)) {
|
||||
logger.error("缺少必要参数!");
|
||||
return;
|
||||
}
|
||||
// 验签、appid,必要参数判断
|
||||
SyncApp syncAppO = 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));
|
||||
if (syncAppO == null) {
|
||||
logger.error("签名有误!");
|
||||
return;
|
||||
}
|
||||
String storeId = syncAppO.getStore_id();
|
||||
//把商品添加到活动的逻辑
|
||||
batchAddActiveShopBase(activeJsonArray, Integer.valueOf(storeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增或更新活动商品数据
|
||||
* @param jsonArray
|
||||
*/
|
||||
private void batchAddActiveShopBase(JSONArray jsonArray,Integer storeId) {
|
||||
List<ShopStoreActivityBase> updateShopStoreActivityBaseList=new ArrayList<>();
|
||||
Map<String, String> stringIntegerMap= checkExistingActive(jsonArray,storeId);
|
||||
Map shopProduckKeyMap=shopProductBaseService.getProductBasicIdByStore(storeId);//获取货架号对应的商品id
|
||||
Map shopItemKeyMap=shopProductItemService.getProductItemIdByStore(storeId);//获取商品id对应的item的id
|
||||
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;
|
||||
}
|
||||
String ruleType="";
|
||||
List<org.json.JSONObject> newItems=new ArrayList<>();
|
||||
ShopStoreActivityBase shopStoreActivityBase=new ShopStoreActivityBase();
|
||||
Integer productId=null;
|
||||
String itemNo=jsonObj.getStr("itemNo");
|
||||
BigDecimal discount=jsonObj.getBigDecimal("discount");
|
||||
if(shopProduckKeyMap.containsKey(itemNo)){
|
||||
productId= (Integer) shopProduckKeyMap.get(itemNo);
|
||||
}
|
||||
if(null==productId){
|
||||
return;
|
||||
}
|
||||
|
||||
Date activityStarttime=jsonObj.getDate("activityStarttime");
|
||||
Integer activityState=jsonObj.getInt("activityState");
|
||||
|
||||
String key=activityName+"_"+activityStarttime.getTime()+"_"+activityState;
|
||||
|
||||
if(stringIntegerMap.containsKey(key)){//更新
|
||||
String keyVal=MapUtil.getStr(stringIntegerMap,key);
|
||||
String activityId=keyVal.split("_")[0];
|
||||
String rules="";
|
||||
if(null!=rulesChe.get(activityId)){
|
||||
rules=rulesChe.get(activityId);
|
||||
}else {
|
||||
rules=keyVal.split("_")[1];
|
||||
}
|
||||
String itemIds= (String) shopItemKeyMap.get(productId);
|
||||
if(null!=itemIds){
|
||||
itemIds= (String) shopItemKeyMap.get(String.valueOf(productId));
|
||||
}
|
||||
assert itemIds != null;
|
||||
if (activityTypeId == 1) {//限时秒杀
|
||||
ruleType=ActiveShopJsonUtils.SECKILL;
|
||||
BigDecimal oldPrice=jsonObj.getBigDecimal("oldPrice");
|
||||
BigDecimal specPrice=jsonObj.getBigDecimal("specPrice");
|
||||
if(oldPrice.compareTo(BigDecimal.ZERO)>0&&specPrice.compareTo(BigDecimal.ZERO)>0){
|
||||
BigDecimal newDiscout=specPrice.divide(oldPrice,4, RoundingMode.HALF_UP);
|
||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,newDiscout));//获取满减规则的itemid
|
||||
}
|
||||
}
|
||||
if (activityTypeId == 2) {//折扣
|
||||
if(discount.compareTo(BigDecimal.ZERO)<=0){
|
||||
logger.error("商品折扣要大于0");
|
||||
return;
|
||||
}
|
||||
ruleType=ActiveShopJsonUtils.DISCOUNT;
|
||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,discount));//获取满减规则的itemid
|
||||
}
|
||||
if (activityTypeId == 3) {//满减
|
||||
ruleType=ActiveShopJsonUtils.FULLREDUCE;
|
||||
newItems.addAll(getFulReduItemList(itemIds,ruleType,null));//获取满减规则的itemid
|
||||
}
|
||||
shopStoreActivityBase.setActivity_id(MapUtil.getInt(stringIntegerMap,activityId));
|
||||
String newRules= ActiveShopJsonUtils.buildPromotionRule(ruleType,rules,newItems);
|
||||
rulesChe.put(activityId,newRules);
|
||||
shopStoreActivityBase.setActivity_rule(rules);
|
||||
updateShopStoreActivityBaseList.add(shopStoreActivityBase);
|
||||
}
|
||||
|
||||
});
|
||||
if(CollectionUtil.isNotEmpty(updateShopStoreActivityBaseList)){
|
||||
shopStoreActivityBaseService.updateBatchById(updateShopStoreActivityBaseList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 一对多,如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
|
||||
* 满减的切割规则的itemid
|
||||
* @param itemPrice
|
||||
* @return
|
||||
*/
|
||||
private List<org.json.JSONObject> getFulReduItemList(String itemPrice,String activeType,BigDecimal discount){
|
||||
List<org.json.JSONObject> newItems=new ArrayList<>();
|
||||
String [] itemPriceArray=itemPrice.split("_");
|
||||
String itemIds=itemPriceArray[0];
|
||||
String unitPrices=itemPriceArray[1];
|
||||
switch (activeType){
|
||||
case ActiveShopJsonUtils.DISCOUNT:
|
||||
if(itemIds.contains(",")){
|
||||
String [] itemIdsArray=itemIds.split(",");
|
||||
for (String itemId : itemIdsArray) {
|
||||
org.json.JSONObject jsonObject = new org.json.JSONObject();
|
||||
jsonObject.put("item_id", itemId);
|
||||
jsonObject.put("rate", BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(100))));
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
}else {
|
||||
org.json.JSONObject jsonObject=new org.json.JSONObject();
|
||||
jsonObject.put("item_id",itemIds);
|
||||
jsonObject.put("rate", BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(100))));
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
break;
|
||||
case ActiveShopJsonUtils.FULLREDUCE:
|
||||
if(itemIds.contains(",")){
|
||||
String [] itemIdsArray=itemIds.split(",");
|
||||
for(String itemId:itemIdsArray){
|
||||
org.json.JSONObject jsonObject=new org.json.JSONObject();
|
||||
jsonObject.put("item_id",itemId);
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
}else {
|
||||
org.json.JSONObject jsonObject=new org.json.JSONObject();
|
||||
jsonObject.put("item_id",itemIds);
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
break;
|
||||
case ActiveShopJsonUtils.SECKILL:
|
||||
if(itemIds.contains(",")){
|
||||
String [] unitPricesArray=unitPrices.split(",");
|
||||
String [] itemIdsArray=itemIds.split(",");
|
||||
for (int i=0;i<itemIdsArray.length;i++) {
|
||||
org.json.JSONObject jsonObject = new org.json.JSONObject();
|
||||
jsonObject.put("item_id", itemIdsArray[i]);
|
||||
jsonObject.put("price", BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(unitPricesArray[i]))));
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
}else {
|
||||
org.json.JSONObject jsonObject=new org.json.JSONObject();
|
||||
jsonObject.put("item_id",itemIds);
|
||||
jsonObject.put("price", BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(unitPrices))));
|
||||
newItems.add(jsonObject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return newItems;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user