商品新增次日数量补全
This commit is contained in:
parent
d4833f235b
commit
eb87cbb900
@ -182,5 +182,9 @@ public class ShopProductItem implements Serializable {
|
||||
@TableField(exist=false)
|
||||
private String mergedUnitPrices;
|
||||
|
||||
@ApiModelProperty(value = "次日自动补满至")
|
||||
private Integer automatic;
|
||||
|
||||
@ApiModelProperty(value = "是否开启次日补全1开启,0不开启")
|
||||
private String is_open_automatic;
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.suisung.mall.shop.components.quartz.job;
|
||||
|
||||
|
||||
import cn.hutool.core.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import com.suisung.mall.common.modules.product.ShopProductItem;
|
||||
import com.suisung.mall.shop.config.SpringUtil;
|
||||
import com.suisung.mall.shop.product.service.ShopProductItemService;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 任务:用于次日更新商品的库存
|
||||
*/
|
||||
public class ProductItemAutoFillJob extends QuartzJobBean {
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
Logger logger = LoggerFactory.getLogger(ProductItemAutoFillJob.class);
|
||||
ShopProductItemService shopProductItemService= SpringUtil.getBean(ShopProductItemService.class);
|
||||
long startTime = System.nanoTime();
|
||||
logger.info("次日更新商品库存开始");
|
||||
// 更新商品库存
|
||||
QueryWrapper<ShopProductItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_open_automatic","1");
|
||||
long total= shopProductItemService.count(queryWrapper);
|
||||
Integer batchSize = 500;
|
||||
int pages= PageUtil.totalPage(Math.toIntExact(total), batchSize);
|
||||
for (int i=1;i<=pages;i++){
|
||||
Page<ShopProductItem> pageShopProductItem=shopProductItemService.lists(queryWrapper,i, batchSize);
|
||||
List<ShopProductItem> shopProductItems= pageShopProductItem.getRecords();
|
||||
shopProductItems= shopProductItems.stream()
|
||||
.peek(shopProductItem -> shopProductItem.setItem_quantity(shopProductItem.getAutomatic()))
|
||||
.collect(Collectors.toList());
|
||||
shopProductItemService.updateBatchById(shopProductItems);
|
||||
}
|
||||
|
||||
long endTime = System.nanoTime();
|
||||
long duration = (endTime - startTime);
|
||||
logger.info("更新商品库存结束,总共更新商品数量:{},耗时{}",total,duration / 1000000000);
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,6 @@ 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.*;
|
||||
@ -66,7 +65,6 @@ import com.suisung.mall.shop.product.service.*;
|
||||
import com.suisung.mall.shop.sixun.service.SxSyncGoodsService;
|
||||
import com.suisung.mall.shop.store.service.*;
|
||||
import com.suisung.mall.shop.sync.service.ProductMappingService;
|
||||
import com.suisung.mall.shop.sync.service.StoreDbConfigService;
|
||||
import com.suisung.mall.shop.user.service.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -488,6 +486,18 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
BigDecimal item_unit_points = Convert.toBigDecimal(productItemMap.get("item_unit_points"));
|
||||
BigDecimal item_unit_price = Convert.toBigDecimal(productItemMap.get("item_unit_price"));
|
||||
Integer item_quantity = Convert.toInt(productItemMap.get("item_quantity"));
|
||||
String is_open_automatic=Convert.toStr(productItemMap.get("is_open_automatic"),DicEnum.YESORNO_0.getCode());
|
||||
if(is_open_automatic.equals(DicEnum.YESORNO_1.getCode())){
|
||||
Integer automatic=Convert.toInt(productItemMap.get("automatic"),0);
|
||||
if(automatic<item_quantity){
|
||||
throw new ApiException("次日补全不能小于库存");
|
||||
}
|
||||
if(automatic<1){
|
||||
throw new ApiException("次日补全必须大于0");
|
||||
}
|
||||
item.setAutomatic(automatic);
|
||||
}
|
||||
item.setIs_open_automatic(is_open_automatic);
|
||||
Integer item_is_default = Convert.toInt(productItemMap.get("item_is_default"));
|
||||
String item_image_default = Convert.toStr(productItemMap.get("main_color_img"), default_image); // 主图
|
||||
List<String> item_image_other = Convert.toList(String.class, productItemMap.get("color_img"));
|
||||
@ -1643,6 +1653,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
}
|
||||
|
||||
Integer store_type = productSearchDTO.getStore_type();
|
||||
// Integer store_type = 1;
|
||||
if (CheckUtil.isNotEmpty(store_type)) {
|
||||
column_row.eq("store_type", store_type);
|
||||
}
|
||||
@ -2132,7 +2143,11 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(listProductsFuture1).get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String activity_type_ids = getParameter("activity_type_ids");
|
||||
product_item_rows.stream().forEach(s -> {
|
||||
String item_spec = Convert.toStr(s.get("item_spec"));
|
||||
@ -2141,20 +2156,22 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
s.put("item_name", item_names);
|
||||
});
|
||||
List<Map> productItems = new ArrayList<>();
|
||||
CompletableFuture<Void> listProductsFuture2 = CompletableFuture.runAsync(() -> {
|
||||
RequestContextHolder.setRequestAttributes(reqAttr, true);
|
||||
// CompletableFuture<Void> listProductsFuture2 = CompletableFuture.runAsync(() -> {
|
||||
// RequestContextHolder.setRequestAttributes(reqAttr, true);
|
||||
//判断是否秒杀商品,是秒杀商品就用秒杀价
|
||||
if (CheckUtil.isNotEmpty(activity_type_ids)) {
|
||||
List<Long> itemIds = product_item_rows.stream().map(e -> Convert.toLong(e.get("item_id"))).collect(Collectors.toList());
|
||||
productItems.addAll(getProductItemFromCategory(product_item_rows, itemIds, product_info_rows, productIndexList, productImages, item_rows));
|
||||
if(!itemIds.isEmpty()){
|
||||
productItems.addAll(getProductItemFromCategory(product_item_rows, itemIds, product_info_rows, productIndexList, productImages, item_rows));
|
||||
}
|
||||
}
|
||||
}, executor);
|
||||
// }, executor);
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(listProductsFuture1, listProductsFuture2).get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// try {
|
||||
// CompletableFuture.allOf(listProductsFuture1, listProductsFuture2).get();
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
product_item_rows.forEach(product_item_row -> {
|
||||
Long productId = Convert.toLong(product_item_row.get("product_id"));
|
||||
@ -2171,7 +2188,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
for (Map itemMap : productItems) {
|
||||
if (item_id.equals(Convert.toLong(itemMap.get("item_id")))) {
|
||||
BigDecimal flash_item_sale_price = Convert.toBigDecimal(itemMap.get("item_sale_price"));
|
||||
BigDecimal item_unit_price = Convert.toBigDecimal(itemMap.get("item_unit_price"));
|
||||
product_base_row.put("item_sale_price", flash_item_sale_price);
|
||||
product_item_row.put("item_unit_price",item_unit_price);//显示活动价
|
||||
product_item_row.put("activity_item_price",flash_item_sale_price);//显示活动价
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -2257,7 +2277,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// product_base_rows.forEach(product_base_row->{ todo重新结算价格
|
||||
// BigDecimal item_price= new BigDecimal(MapUtil.getStr(product_base_row,"item_unit_price","0"));
|
||||
// // JSONObject jsonObject=activity_item
|
||||
// });
|
||||
items = product_base_rows;
|
||||
}
|
||||
|
||||
@ -4409,6 +4432,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
Long itemId = Convert.toLong(((JSONObject) rule_row).get("item_id"));
|
||||
if (ObjectUtil.equal(itemId, item_id)) {
|
||||
item_row.put("item_sale_price", ((JSONObject) rule_row).get("price"));
|
||||
item_row.put("item_unit_price", ((JSONObject) rule_row).get("price"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -4422,7 +4446,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
for (Object rule_row : discount) {
|
||||
Long itemId = Convert.toLong(((JSONObject) rule_row).get("item_id"));
|
||||
if (ObjectUtil.equal(itemId, item_id)) {
|
||||
BigDecimal rate=((JSONObject) rule_row).getBigDecimal("rate").divide(new BigDecimal("100")).setScale(2,RoundingMode.HALF_UP);
|
||||
BigDecimal unit_price=new BigDecimal(MapUtil.getStr(item_row,"item_unit_price"));
|
||||
item_row.put("one_piece_discount", NumberUtil.div(Convert.toBigDecimal(((JSONObject) rule_row).get("rate")), 10));
|
||||
item_row.put("item_sale_price",unit_price.multiply(rate));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -997,6 +997,24 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
||||
}
|
||||
}
|
||||
|
||||
// 单件折扣
|
||||
if (ObjectUtil.equal(StateCode.ACTIVITY_TYPE_ONE_PIECE_DISCOUNT, activity_type_id) && CheckUtil.isNotEmpty(activity_id)) {
|
||||
Map activity_item_row = (Map) item_row.get("activity_item_row");
|
||||
JSONObject activity_rule = (JSONObject) activity_item_row.get("activity_rule");
|
||||
JSONArray discount = (JSONArray) activity_rule.get("discount");
|
||||
BigDecimal unit_price=((JSONObject) product_row).getBigDecimal("unit_price");
|
||||
if (discount != null) {
|
||||
for (Object rule_row : discount) {
|
||||
Long itemId = Convert.toLong(((JSONObject) rule_row).get("item_id"));
|
||||
if (ObjectUtil.equal(itemId, item_id)) {
|
||||
BigDecimal rate=((JSONObject) rule_row).getBigDecimal("rate");
|
||||
item_row.put("item_sale_price", unit_price.multiply(rate).divide(new BigDecimal("100"),RoundingMode.HALF_UP));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 限时秒杀
|
||||
Date time = new Date();
|
||||
QueryWrapper<ShopPlantformActivityItem> queryWrapper = new QueryWrapper<>();
|
||||
@ -2253,7 +2271,7 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
||||
* 一对多,如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,category_id");
|
||||
queryWrapper.select("product_id","GROUP_CONCAT(item_id SEPARATOR ',') AS mergedItemId","GROUP_CONCAT(item_unit_price SEPARATOR ',') AS mergedUnitPrices,min(category_id) as category_id");
|
||||
productNumbers.forEach(productNumber -> {
|
||||
queryWrapper.or(q->q.eq("store_id",store_id).eq("item_src_id",productNumber));
|
||||
});
|
||||
|
||||
3
sql/shop/dev/20250808_ddl.sql
Normal file
3
sql/shop/dev/20250808_ddl.sql
Normal file
@ -0,0 +1,3 @@
|
||||
alter table shop_product_item add automatic INTEGER DEFAULT NULL COMMENT '次日自动补满至';
|
||||
alter table shop_product_item add is_open_automatic varchar(1) not null DEFAULT '0' COMMENT '是否开启次日补全1开启,0不开启';
|
||||
alter table shop_product_item add index `index_is_open_automatic` (`is_open_automatic`) USING BTREE;
|
||||
Loading…
Reference in New Issue
Block a user