1.查询商品返回规格上下架信息字段
This commit is contained in:
@@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller;
|
|||||||
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.service.ProductService;
|
import com.chaozhanggui.system.cashierservice.service.ProductService;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
@@ -58,6 +59,15 @@ public class ProductController {
|
|||||||
return productService.queryCommodityInfo(shopId,categoryId,commdityName,page,pageSize,masterId);
|
return productService.queryCommodityInfo(shopId,categoryId,commdityName,page,pageSize,masterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("querySpec")
|
||||||
|
public Result querySpec(
|
||||||
|
@RequestParam Integer shopId,
|
||||||
|
@RequestParam Integer productId
|
||||||
|
) {
|
||||||
|
return Result.success(CodeEnum.SUCCESS, productService.querySpec(shopId, productId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = "queryNewCommodityInfo")
|
@GetMapping(value = "queryNewCommodityInfo")
|
||||||
public Result queryNewCommodityInfo(
|
public Result queryNewCommodityInfo(
|
||||||
@RequestHeader("token") String token,
|
@RequestHeader("token") String token,
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.entity;
|
package com.chaozhanggui.system.cashierservice.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TbProductWithBLOBs extends TbProduct implements Serializable {
|
public class TbProductWithBLOBs extends TbProduct implements Serializable {
|
||||||
|
private Object groundingSpecInfo;
|
||||||
private String images;
|
private String images;
|
||||||
|
|
||||||
private String video;
|
private String video;
|
||||||
@@ -20,58 +24,34 @@ public class TbProductWithBLOBs extends TbProduct implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public List<?> getSkuList() {
|
public void setGroundingSpecInfo(Object groundingSpecInfo) {
|
||||||
return skuList;
|
this.groundingSpecInfo = groundingSpecInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSkuList(List<?> skuList) {
|
public void setSkuList(List<?> skuList) {
|
||||||
this.skuList = skuList;
|
this.skuList = skuList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImages() {
|
|
||||||
return images;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImages(String images) {
|
public void setImages(String images) {
|
||||||
this.images = images == null ? null : images.trim();
|
this.images = images == null ? null : images.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVideo() {
|
|
||||||
return video;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVideo(String video) {
|
public void setVideo(String video) {
|
||||||
this.video = video == null ? null : video.trim();
|
this.video = video == null ? null : video.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNotice() {
|
|
||||||
return notice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotice(String notice) {
|
public void setNotice(String notice) {
|
||||||
this.notice = notice == null ? null : notice.trim();
|
this.notice = notice == null ? null : notice.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupSnap() {
|
|
||||||
return groupSnap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupSnap(String groupSnap) {
|
public void setGroupSnap(String groupSnap) {
|
||||||
this.groupSnap = groupSnap == null ? null : groupSnap.trim();
|
this.groupSnap = groupSnap == null ? null : groupSnap.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSpecInfo() {
|
|
||||||
return specInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpecInfo(String specInfo) {
|
public void setSpecInfo(String specInfo) {
|
||||||
this.specInfo = specInfo == null ? null : specInfo.trim();
|
this.specInfo = specInfo == null ? null : specInfo.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelectSpec() {
|
|
||||||
return selectSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectSpec(String selectSpec) {
|
public void setSelectSpec(String selectSpec) {
|
||||||
this.selectSpec = selectSpec == null ? null : selectSpec.trim();
|
this.selectSpec = selectSpec == null ? null : selectSpec.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QuerySpecDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
private Integer productId;
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
|
|||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
|
import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect;
|
||||||
@@ -134,69 +135,7 @@ public class ProductService {
|
|||||||
it.setTbProductSpec(tbProductSpec);
|
it.setTbProductSpec(tbProductSpec);
|
||||||
|
|
||||||
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||||
|
|
||||||
|
|
||||||
// 上下架对应的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();
|
|
||||||
|
|
||||||
HashMap<String, String> snapMap = new HashMap<>();
|
|
||||||
for (Object snap : tagSnaps) {
|
|
||||||
StringBuilder finalValues = new StringBuilder();
|
|
||||||
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.append(value).append(",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(finalValues.toString())) {
|
|
||||||
finalValues = new StringBuilder(StrUtil.removeSuffix(finalValues.toString(), ","));
|
|
||||||
snapJSON.put("value", finalValues.toString());
|
|
||||||
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;
|
|
||||||
String name = snapMap.get(specInfo.getString("name"));
|
|
||||||
if (name != null) {
|
|
||||||
specInfo.put("value", name.split(","));
|
|
||||||
specInfo.put("selectSpecResult", name.split(","));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it.setSelectSpec(selectSpecJSON.toJSONString());
|
|
||||||
}
|
|
||||||
|
|
||||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
|
||||||
}
|
|
||||||
it.setProductSkuResult(skuResult);
|
it.setProductSkuResult(skuResult);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 查询sku信息
|
// 查询sku信息
|
||||||
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
|
List<TbProductSku> skuWithBLOBs = tbProductSkuMapper.selectByProductCheckGrounding(it.getId());
|
||||||
List<TbProductSku> skus = tbProductSkuMapper.selectByProductId(it.getId());
|
List<TbProductSku> skus = tbProductSkuMapper.selectByProductId(it.getId());
|
||||||
@@ -209,7 +148,7 @@ public class ProductService {
|
|||||||
}
|
}
|
||||||
it.setSkuList(skuWithBLOBs);
|
it.setSkuList(skuWithBLOBs);
|
||||||
|
|
||||||
|
it.setGroundingSpecInfo(querySpec(Integer.valueOf(shopId), it.getId()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
PageInfo pageInfo=new PageInfo(tbProductWithBLOBs);
|
PageInfo pageInfo=new PageInfo(tbProductWithBLOBs);
|
||||||
@@ -280,4 +219,80 @@ public class ProductService {
|
|||||||
producer.sendStockRecordMsg(data);
|
producer.sendStockRecordMsg(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void generateCombinations(List<List<String>> valuesList, int index, List<String> current, List<String> result) {
|
||||||
|
if (index == valuesList.size()) {
|
||||||
|
result.add(String.join(",", current));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String value : valuesList.get(index)) {
|
||||||
|
current.add(value);
|
||||||
|
generateCombinations(valuesList, index + 1, current, result);
|
||||||
|
current.remove(current.size() - 1); // 回溯
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object querySpec(Integer shopId, Integer productId) {
|
||||||
|
TbProduct tbProduct = tbProductMapper.selectByPrimaryKey(productId);
|
||||||
|
if (tbProduct == null) {
|
||||||
|
throw new MsgException("商品不存在");
|
||||||
|
}
|
||||||
|
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(productId);
|
||||||
|
|
||||||
|
// 重组有效规格数据
|
||||||
|
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||||
|
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(productId);
|
||||||
|
|
||||||
|
JSONArray finalSnap = new JSONArray();
|
||||||
|
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
if (tagSnap != null) {
|
||||||
|
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||||
|
List<List<String>> valuesList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 提取所有 value 的列表
|
||||||
|
for (int i = 0; i < tagSnaps.size(); i++) {
|
||||||
|
JSONObject jsonObject = tagSnaps.getJSONObject(i);
|
||||||
|
if (jsonObject.containsKey("value")) {
|
||||||
|
String[] values = jsonObject.getString("value").split(",");
|
||||||
|
valuesList.add(Arrays.asList(values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 生成所有可能的排列组合
|
||||||
|
generateCombinations(valuesList, 0, new ArrayList<>(), result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<HashMap<String, Object>> specList = new ArrayList<>();
|
||||||
|
tbProductSkus.forEach(item -> {
|
||||||
|
HashMap<String, Object> itemMap = new HashMap<>();
|
||||||
|
itemMap.put("specSnap", item.getSpecSnap());
|
||||||
|
itemMap.put("skuId", item.getId());
|
||||||
|
specList.add(itemMap);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<HashMap<String, Object>> otherVal = new ArrayList<>();
|
||||||
|
for (String res : result) {
|
||||||
|
boolean found = false;
|
||||||
|
for (HashMap<String, Object> spec : specList) {
|
||||||
|
if (res.equals(spec.get("specSnap").toString())) {
|
||||||
|
spec.put("isGrounding", true);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
HashMap<String, Object> itemMap = new HashMap<>();
|
||||||
|
itemMap.put("specSnap", res);
|
||||||
|
itemMap.put("skuId", null);
|
||||||
|
itemMap.put("isGrounding", false);
|
||||||
|
otherVal.add(itemMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
specList.addAll(otherVal);
|
||||||
|
return specList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
<result column="icon" jdbcType="VARCHAR" property="icon" />
|
<result column="icon" jdbcType="VARCHAR" property="icon" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, pay_type, pay_name, is_show_shortcut, shop_id, is_refundable, is_open_cash_drawer,
|
id, pay_type, pay_name, is_show_shortcut, shop_id, is_refundable, is_open_cash_drawer,
|
||||||
is_system, is_ideal, is_display, sorts, created_at, updated_at, icon
|
is_system, is_ideal, is_display, sorts, created_at, updated_at, icon
|
||||||
</sql>
|
</sql>
|
||||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
select
|
select
|
||||||
<include refid="Base_Column_List" />
|
<include refid="Base_Column_List" />
|
||||||
from tb_shop_pay_type
|
from tb_shop_pay_type
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
@@ -32,15 +32,15 @@
|
|||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</delete>
|
</delete>
|
||||||
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopPayType">
|
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopPayType">
|
||||||
insert into tb_shop_pay_type (id, pay_type, pay_name,
|
insert into tb_shop_pay_type (id, pay_type, pay_name,
|
||||||
is_show_shortcut, shop_id, is_refundable,
|
is_show_shortcut, shop_id, is_refundable,
|
||||||
is_open_cash_drawer, is_system, is_ideal,
|
is_open_cash_drawer, is_system, is_ideal,
|
||||||
is_display, sorts, created_at,
|
is_display, sorts, created_at,
|
||||||
updated_at, icon)
|
updated_at, icon)
|
||||||
values (#{id,jdbcType=INTEGER}, #{payType,jdbcType=VARCHAR}, #{payName,jdbcType=VARCHAR},
|
values (#{id,jdbcType=INTEGER}, #{payType,jdbcType=VARCHAR}, #{payName,jdbcType=VARCHAR},
|
||||||
#{isShowShortcut,jdbcType=TINYINT}, #{shopId,jdbcType=VARCHAR}, #{isRefundable,jdbcType=TINYINT},
|
#{isShowShortcut,jdbcType=TINYINT}, #{shopId,jdbcType=VARCHAR}, #{isRefundable,jdbcType=TINYINT},
|
||||||
#{isOpenCashDrawer,jdbcType=TINYINT}, #{isSystem,jdbcType=TINYINT}, #{isIdeal,jdbcType=TINYINT},
|
#{isOpenCashDrawer,jdbcType=TINYINT}, #{isSystem,jdbcType=TINYINT}, #{isIdeal,jdbcType=TINYINT},
|
||||||
#{isDisplay,jdbcType=TINYINT}, #{sorts,jdbcType=INTEGER}, #{createdAt,jdbcType=BIGINT},
|
#{isDisplay,jdbcType=TINYINT}, #{sorts,jdbcType=INTEGER}, #{createdAt,jdbcType=BIGINT},
|
||||||
#{updatedAt,jdbcType=BIGINT}, #{icon,jdbcType=VARCHAR})
|
#{updatedAt,jdbcType=BIGINT}, #{icon,jdbcType=VARCHAR})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopPayType">
|
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopPayType">
|
||||||
@@ -205,4 +205,4 @@
|
|||||||
|
|
||||||
select count(id) from tb_shop_pay_type where shop_id=#{shopId} and is_display=1 and pay_type=#{payType}
|
select count(id) from tb_shop_pay_type where shop_id=#{shopId} and is_display=1 and pay_type=#{payType}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user