parent
3e32ea31d3
commit
fbabdc5763
|
|
@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
|
||||
import com.chaozhanggui.system.cashierservice.service.CartService;
|
||||
import com.chaozhanggui.system.cashierservice.service.ProductService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
|
|
@ -59,6 +60,21 @@ public class ProductController {
|
|||
(map.containsKey("productGroupId") && ObjectUtil.isNotEmpty(map.get("productGroupId"))) ? map.get("productGroupId").toString() : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询规格
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("querySpec")
|
||||
public Result querySpec(
|
||||
@RequestBody QuerySpecDTO querySpecDTO
|
||||
) {
|
||||
if (querySpecDTO.getProductId() == null) {
|
||||
return Result.fail("id不为空");
|
||||
}
|
||||
return Result.successWithData(productService.querySpec(querySpecDTO));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("queryProductSku")
|
||||
public Result queryProductSku(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.chaozhanggui.system.cashierservice.entity;
|
|||
import java.io.Serializable;
|
||||
|
||||
public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable {
|
||||
|
||||
private String tagSnap;
|
||||
|
||||
private String specInfo;
|
||||
|
||||
private String specSnap;
|
||||
|
|
@ -11,6 +14,14 @@ public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public String getTagSnap() {
|
||||
return tagSnap;
|
||||
}
|
||||
|
||||
public void setTagSnap(String tagSnap) {
|
||||
this.tagSnap = tagSnap;
|
||||
}
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class QuerySpecDTO {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public static class QuerySpec {
|
||||
private String name;
|
||||
private String value;
|
||||
}
|
||||
private Integer productId;
|
||||
private List<QuerySpec> querySpecList = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.*;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
|
|
@ -161,6 +162,80 @@ public class ProductService {
|
|||
return Result.success(CodeEnum.SUCCESS, concurrentMap);
|
||||
}
|
||||
|
||||
public JSONArray querySpec(QuerySpecDTO querySpecDTO) {
|
||||
TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId());
|
||||
if (tbProduct == null) {
|
||||
throw new MsgException("商品不存在");
|
||||
}
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(querySpecDTO.getProductId());
|
||||
|
||||
// 重组有效规格数据
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
HashMap<String, String> reverseTagSnapMap = new HashMap<>();
|
||||
JSONObject snapJSON;
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject)snap;
|
||||
reverseTagSnapMap.put(snapJSON.getString("value"), snapJSON.getString("name"));
|
||||
}
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(querySpecDTO.getProductId());
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
String specSnap = item.getSpecSnap();
|
||||
|
||||
ArrayList<QuerySpecDTO.QuerySpec> skuSpecList = new ArrayList<>();
|
||||
if (specSnap != null) {
|
||||
String[] split = specSnap.split(",");
|
||||
for (String snap : split) {
|
||||
reverseTagSnapMap.forEach((k, v) -> {
|
||||
if (k.contains(snap)) {
|
||||
skuSpecList.add(new QuerySpecDTO.QuerySpec(v, snap));
|
||||
}
|
||||
});
|
||||
}
|
||||
boolean isHave = false;
|
||||
for (QuerySpecDTO.QuerySpec spec : querySpecDTO.getQuerySpecList()) {
|
||||
for (QuerySpecDTO.QuerySpec querySpec : skuSpecList) {
|
||||
isHave = querySpec.equals(spec);
|
||||
if (isHave) break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (querySpecDTO.getQuerySpecList().isEmpty() || isHave) {
|
||||
specSet.addAll(Arrays.asList(split));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
|
||||
ArrayList<LinkedHashMap<String, Object>> data = new ArrayList<>();
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
LinkedHashMap<String, Object> finalValue = new LinkedHashMap<>();
|
||||
finalValue.put("info", value);
|
||||
finalValue.put("isGrounding", specSet.contains(value));
|
||||
data.add(finalValue);
|
||||
}
|
||||
if (!data.isEmpty()) {
|
||||
snapJSON.put("value", data);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return finalSnap;
|
||||
}
|
||||
|
||||
|
||||
public List<TbProduct> handleDate(List<TbProduct> products){
|
||||
if (!CollectionUtils.isEmpty(products)) {
|
||||
|
|
@ -235,12 +310,22 @@ public class ProductService {
|
|||
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
|
||||
return Result.fail("参数错误");
|
||||
}
|
||||
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag);
|
||||
|
||||
if (tbProductSkuWithBLOBs == null) {
|
||||
tbProductSkuWithBLOBs = new TbProductSkuWithBLOBs();
|
||||
tbProductSkuWithBLOBs.setNumber(0);
|
||||
tbProductSkuWithBLOBs.setSalePrice(BigDecimal.ZERO);
|
||||
tbProductSkuWithBLOBs.setOriginPrice(BigDecimal.ZERO);
|
||||
tbProductSkuWithBLOBs.setId(null);
|
||||
}else {
|
||||
if (StringUtils.isNotBlank(code)) {
|
||||
Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId);
|
||||
tbProductSkuWithBLOBs.setNumber(sum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs);
|
||||
|
||||
}
|
||||
|
|
@ -549,4 +634,5 @@ public class ProductService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,11 +362,11 @@
|
|||
</update>
|
||||
|
||||
<select id="selectByShopIdAndProductIdAndSpec" resultMap="ResultMapWithBLOBs">
|
||||
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0
|
||||
|
||||
select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0 and is_grounding=1
|
||||
<if test="spec != null and spec !=''">
|
||||
and spec_snap = #{spec}
|
||||
</if>
|
||||
limit 1
|
||||
</select>
|
||||
<select id="selectAll" resultType="com.chaozhanggui.system.cashierservice.entity.TbProductSku">
|
||||
select * from tb_product_sku
|
||||
|
|
|
|||
Loading…
Reference in New Issue