Compare commits

..

3 Commits

Author SHA1 Message Date
958786cdf1 客户端代码提交 2025-07-25 15:53:29 +08:00
52c3942346 商品sukitem价格和库存修改 2025-07-25 15:53:17 +08:00
01d0a8a423 商品类型问题修复&同步时间间隔字段新增 2025-07-25 15:52:54 +08:00
13 changed files with 117 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package com.small.client.Schedule;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.small.client.Utils.CommonUtil;
import com.small.client.dto.CommentModel;
import com.small.client.dto.DataBaseInfo;
import com.small.client.service.SxDataService;
@ -93,11 +94,23 @@ public class DynamicTaskScheduler {
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()));
}
sxDataService.syncStoreData(dataBaseInfo,commentModel);
sxDataService.SyncBranchList(dataBaseInfo,commentModel);
sxDataService.SyncCategory(dataBaseInfo,commentModel);
sxDataService.SyncGoods(dataBaseInfo,commentModel);//todo 暂时同步全部的商品如果后期修改需要增加服务器的字段
try {
if(ObjectUtil.isNotEmpty(dataBaseInfo.getShopGapTime())){
long sleepTime= CommonUtil.convertExpressionToLong(dataBaseInfo.getShopGapTime());
Thread.sleep(sleepTime);//两分钟之后执行
}else {
Thread.sleep(1000*30);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
sxDataService.SyncVipList(dataBaseInfo,commentModel);
sxDataService.syncAtive(dataBaseInfo,commentModel);
sxDataService.syncAtiveShops(dataBaseInfo,commentModel);
isRuning=false;
}

View File

@ -140,4 +140,21 @@ public class CommonUtil {
}
}
/**
* 乘法转long如100*10*10
* @param expression
* @return
*/
public static long convertExpressionToLong(String expression) {
// 移除空格并按乘号分割
String[] parts = expression.replace(" ", "").split("\\*");
long result = 1L;
for (String part : parts) {
// 逐段转换为 long 并累乘
result *= Long.parseLong(part);
}
return result;
}
}

View File

@ -38,4 +38,7 @@ public class DataBaseInfo {
@ApiModelProperty(value = "刷新时间")
private Date refreshTime;
@ApiModelProperty(value = "间隔时间")
private String shopGapTime;
}

View File

@ -68,4 +68,7 @@ public class StoreDbConfig implements Serializable {
@ApiModelProperty(value = "是否双向同步(0:否,1:是)")
private String isTowSync="1";
@ApiModelProperty("商品同步间隔时间")
private String shopGapTime;
}

View File

@ -682,6 +682,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
dataBaseInfo.setCategoryName(storeDbConfig.getCategoryName());
dataBaseInfo.setRefreshTime(storeDbConfig.getRefreshTime());
dataBaseInfo.setIsTowSync(storeDbConfig.getIsTowSync());
dataBaseInfo.setShopGapTime(storeDbConfig.getShopGapTime());
return dataBaseInfo;
}
return new DataBaseInfo();

View File

@ -122,4 +122,9 @@ public class StoreDbConfig implements Serializable {
@ApiModelProperty(value = "更新优先方式(1:手动优先,2:自动优先),自动优先时根据平台给的商品自动切分上架,更新是才发挥作用")
@NotBlank(message = "更新优先方式不能为空")
private String priorityMode="1";
@TableField(value = "shop_gap_time",updateStrategy = FieldStrategy.NOT_EMPTY)
@ApiModelProperty(value = "商品同步间隔时间,由于商品同步时异步,要等同步完成才同步商品和活动,所以要设置间隔时间")
@NotBlank(message = "商品同步间隔时间不能为空")
private String shopGapTime;
}

View File

@ -83,7 +83,7 @@ public class ShopBaseProductSpecServiceImpl extends BaseServiceImpl<ShopBaseProd
specs.forEach(item -> {
QueryWrapper<ShopProductSpecItem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("spec_id", item.getSpec_id())
.eq("store_id", Integer.valueOf(store_id));
.eq("store_id", store_id);
queryWrapper.orderByAsc("spec_item_order");
queryWrapper.orderByAsc("spec_item_id");
item.setSpecItems(itemService.getItems(queryWrapper));

View File

@ -25,6 +25,7 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
@ -81,7 +82,7 @@ public class ShopBaseProductTypeServiceImpl extends BaseServiceImpl<ShopBaseProd
@Override
public Map getType(String type_id) {
String storeId = ContextUtil.getCurrentUser().getStore_id();
String storeId = Objects.requireNonNull(ContextUtil.getCurrentUser()).getStore_id();
QueryWrapper<ShopBaseProductType> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type_id", type_id);
queryWrapper.eq("store_id", storeId);
@ -91,8 +92,7 @@ public class ShopBaseProductTypeServiceImpl extends BaseServiceImpl<ShopBaseProd
data.put("brands", brandService.getBrandsByIds(shopBaseProductType.getType_brand_ids()));
// Integer store_id = Convert.toInt(userInfoService.getUser().getStore_id());
Integer store_id =1;
data.put("specs", specService.getSpecsByIds(shopBaseProductType.getType_spec_ids(), store_id));
data.put("specs", specService.getSpecsByIds(shopBaseProductType.getType_spec_ids(), Integer.valueOf(storeId)));
return data;
@ -102,10 +102,11 @@ public class ShopBaseProductTypeServiceImpl extends BaseServiceImpl<ShopBaseProd
public Map getType(String type_id, Long product_id) {
Map data = getType(type_id);
//todo 分销商业务去除吧
if (CheckUtil.isNotEmpty(product_id)) {
//读取商品判断是否为供应商分销商品
ShopProductBase shopProductBase = shopProductBaseService.get(product_id);
if (!shopProductBase.getProduct_src_id().equals(0)) {
if (!shopProductBase.getProduct_src_id().equals(0L)) {
ShopProductIndex shopProductIndex = shopProductIndexService.get(shopProductBase.getProduct_src_id());
if (shopProductIndex != null) {

View File

@ -83,5 +83,18 @@ public class ShopProductItemController {
.orderByAsc("item_id");
return CommonResult.success(shopProductItemService.find(queryWrapper));
}
/**
* 编辑库存和价格
* @param shopProductItem
* @return
*/
@ApiOperation(value = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑", notes = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑")
@RequestMapping(value = "/editQuantity", method = RequestMethod.POST)
public CommonResult editQuantity(ShopProductItem shopProductItem) {
return shopProductItemService.editQuantity(shopProductItem);
}
}

View File

@ -1,6 +1,7 @@
package com.suisung.mall.shop.product.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.edu.vo.EduCourseDetailVO;
import com.suisung.mall.common.modules.product.ShopProductItem;
import com.suisung.mall.common.pojo.dto.EduCourseDetailDTO;
@ -84,4 +85,11 @@ public interface ShopProductItemService extends IBaseService<ShopProductItem> {
* @return
*/
void batchUpdateByCondition(List<ShopProductItem> shopProductItemList);
/**
* 功能描述:
* 修改item的价格和库存
* @param: ShopProductItem
*/
CommonResult editQuantity(ShopProductItem shopProductItem);
}

View File

@ -17,6 +17,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.api.ResultCode;
import com.suisung.mall.common.api.StateCode;
import com.suisung.mall.common.constant.ConfigConstant;
@ -61,6 +62,7 @@ import com.suisung.mall.shop.user.service.ShopUserProductBrowseService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
@ -2290,4 +2292,48 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
shopProductItemMapper.updateBatchByProductId(shopProductItemList,shopProductItemList.get(0).getItem_enable());
}
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult editQuantity(ShopProductItem shopProductItem) {
QueryWrapper<ShopProductItem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("product_id",shopProductItem.getProduct_id());
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
if(CollUtil.isEmpty(oldShopProductItemList)){
return CommonResult.failed("不存在商品sku");
}
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){
return CommonResult.failed("库存不能为空");
}
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
return CommonResult.failed("价格不能为空");
}
BigDecimal item_unit_price =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
ShopProductIndex shopProductIndex=new ShopProductIndex();
if(item_unit_price_old.compareTo(item_unit_price)>0){
ShopProductBase shopProductBase=new ShopProductBase();
shopProductBase.setProduct_id(shopProductItem.getProduct_id());
shopProductBase.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
shopProductBaseService.updateById(shopProductBase);
}
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0){
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
}
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
shopProductIndexService.updateById(shopProductIndex);
}
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
shopProductItemService.updateById(oldShopProductItem);
return CommonResult.success();
}
}

View File

@ -0,0 +1 @@
alter table store_db_config add shop_gap_time varchar(64) NOT NULL DEFAULT '1000*60*2' COMMENT '商品间隔时间,由于商品同步时异步,要等同步完成才同步商品和活动,所以要设置间隔时间';

View File

@ -0,0 +1 @@
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`) VALUES ('/admin/shop/shop-product-item/editQuantity', 'index', 'master', '', '0', '/admin/shop/shop-product-item/editQuantity');