1.sku上下架

This commit is contained in:
2024-07-24 18:02:58 +08:00
parent 0cf417322b
commit b00dc349d6
3 changed files with 66 additions and 5 deletions

View File

@@ -53,4 +53,7 @@ public interface TbProductSkuMapper {
@Select("select * from tb_product_sku where is_grounding=1 and product_id=#{id}")
List<TbProductSku> selectByProductCheckGrounding(@Param("id") Integer id);
@Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}")
List<TbProductSku> selectGroundingByProId(Integer id);
}

View File

@@ -53,6 +53,8 @@ public class TbProductSku implements Serializable {
private Integer isPauseSale = 0;
private Integer isDel;
private String specSnap;
private static final long serialVersionUID = 1L;
}

View File

@@ -9,6 +9,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
@@ -18,8 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Service
@Slf4j
@@ -41,9 +41,11 @@ public class ProductService {
@Autowired
TbProductSkuResultMapper tbProductSkuResultMapper;
@Autowired
private LimitSubmitAspect limitSubmitAspect;
public Result queryCategory(String shopId,Integer page,Integer pageSize){
public Result queryCategory(String shopId,Integer page,Integer pageSize){
PageHelperUtil.startPage(page, pageSize);
List<TbShopCategory> list=tbShopCategoryMapper.selectByAll(shopId);
PageInfo pageInfo=new PageInfo(list);
@@ -119,12 +121,66 @@ public class ProductService {
it.setTbProductSpec(tbProductSpec);
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
if(ObjectUtil.isEmpty(skuResult)){
skuResult=new TbProductSkuResult();
// 上下架对应的sku
String selectSpec = it.getSelectSpec();
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
HashSet<String> specSet = new HashSet<>();
tbProductSkus.forEach(item -> {
String specSnap = item.getSpecSnap();
if (specSnap != null) {
specSet.addAll(Arrays.asList(specSnap.split(",")));
}
});
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
if (tagSnap != null) {
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
JSONObject snapJSON;
JSONArray finalSnap = new JSONArray();
String finalValues = "";
HashMap<String, String> snapMap = new HashMap<>();
for (Object snap : tagSnaps) {
snapJSON = (JSONObject) snap;
String values = snapJSON.getString("value");
if (StrUtil.isNotBlank(values)) {
String[] valueList = values.split(",");
for (String value : valueList) {
if (specSet.contains(value)) {
finalValues = finalValues + (value) + ",";
}
}
if (StrUtil.isNotBlank(finalValues)) {
finalValues = StrUtil.removeSuffix(finalValues, ",");
snapJSON.put("value", finalValues);
finalSnap.add(snapJSON);
snapMap.put(snapJSON.getString("name"), snapJSON.getString("value"));
}
}
}
if (selectSpec != null) {
JSONArray selectSpecJSON = JSONObject.parseArray(selectSpec);
for (Object selectSpecInfo : selectSpecJSON) {
JSONObject specInfo = (JSONObject) selectSpecInfo;
specInfo.put("value", snapMap.get(specInfo.getString("name")).split(","));
specInfo.put("selectSpecResult", snapMap.get(specInfo.getString("name")).split(","));
}
it.setSelectSpec(selectSpecJSON.toJSONString());
}
skuResult.setTagSnap(finalSnap.toJSONString());
}
it.setProductSkuResult(skuResult);
// 查询sku信息
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
it.setSkuList(skuWithBLOBs);