商品模块代码提交

This commit is contained in:
Tankaikai
2025-02-18 15:17:45 +08:00
parent 78d7c32638
commit f8658d3386
3 changed files with 16 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import cn.hutool.extra.servlet.JakartaServletUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.czg.log.annotation.OperationLog; import com.czg.log.annotation.OperationLog;
import com.czg.log.enums.LogTypeEnum; import com.czg.log.enums.LogTypeEnum;
import com.czg.log.enums.OperationStatusEnum; import com.czg.log.enums.OperationStatusEnum;
@@ -99,7 +100,7 @@ public class OperationLogAspect {
log.set("shopId", shopId); log.set("shopId", shopId);
log.set("type", LogTypeEnum.INFO.value()); log.set("type", LogTypeEnum.INFO.value());
if(StrUtil.isNotBlank(errorInfo)){ if (StrUtil.isNotBlank(errorInfo)) {
log.set("type", LogTypeEnum.ERROR.value()); log.set("type", LogTypeEnum.ERROR.value());
} }
log.set("status", status); log.set("status", status);
@@ -119,10 +120,10 @@ public class OperationLogAspect {
Object[] args = joinPoint.getArgs(); Object[] args = joinPoint.getArgs();
Map<String, String> param = JakartaServletUtil.getParamMap(request); Map<String, String> param = JakartaServletUtil.getParamMap(request);
try { try {
String params = JSON.toJSONString(args[0]); String params = JSON.toJSONString(args[0], JSONWriter.Feature.WriteMapNullValue);
log.set("requestParams", params); log.set("requestParams", params);
boolean isJsonObject = JSONUtil.isTypeJSONObject(params); boolean isJsonObject = JSONUtil.isTypeJSONObject(params);
if(isJsonObject){ if (isJsonObject) {
JSONObject reqData = JSON.parseObject(params); JSONObject reqData = JSON.parseObject(params);
param.forEach(reqData::putIfAbsent); param.forEach(reqData::putIfAbsent);
log.set("requestParams", reqData.toJSONString()); log.set("requestParams", reqData.toJSONString());
@@ -132,6 +133,6 @@ public class OperationLogAspect {
} }
log.set("id", new SnowFlakeIDKeyGenerator().nextId()); log.set("id", new SnowFlakeIDKeyGenerator().nextId());
//保存到Redis队列里 //保存到Redis队列里
logProducer.saveLog(JSON.toJSONString(log.toUnderlineKeysMap())); logProducer.saveLog(JSON.toJSONString(log.toUnderlineKeysMap(), JSONWriter.Feature.WriteMapNullValue));
} }
} }

View File

@@ -104,7 +104,7 @@ public class ProductDTO implements Serializable {
/** /**
* 套餐内容 * 套餐内容
*/ */
private String groupSnap; private Object groupSnap;
/** /**
* 库存警戒线 * 库存警戒线
*/ */
@@ -222,4 +222,8 @@ public class ProductDTO implements Serializable {
public Object getSelectSpecInfo() { public Object getSelectSpecInfo() {
return JSON.parseObject(Convert.toStr(selectSpecInfo, "{}")); return JSON.parseObject(Convert.toStr(selectSpecInfo, "{}"));
} }
public Object getGroupSnap() {
return JSON.parseArray(Convert.toStr(groupSnap, "[]"));
}
} }

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.czg.enums.DeleteEnum; import com.czg.enums.DeleteEnum;
import com.czg.enums.YesNoEnum; import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
@@ -124,13 +125,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
} }
Product entity = BeanUtil.copyProperties(dto, Product.class); Product entity = BeanUtil.copyProperties(dto, Product.class);
entity.setImages(JSON.toJSONString(dto.getImages())); entity.setImages(JSON.toJSONString(dto.getImages(), JSONWriter.Feature.WriteMapNullValue));
entity.setGroupSnap("[]"); entity.setGroupSnap("[]");
//套餐 //套餐
if (ProductTypeEnum.PACKAGE.value().equals(dto.getType())) { if (ProductTypeEnum.PACKAGE.value().equals(dto.getType())) {
//套餐内容 //套餐内容
if (CollUtil.isNotEmpty(dto.getProGroupVo())) { if (CollUtil.isNotEmpty(dto.getProGroupVo())) {
entity.setGroupSnap(JSON.toJSONString(dto.getProGroupVo())); String groupSnap = JSON.toJSONString(dto.getProGroupVo(), JSONWriter.Feature.WriteMapNullValue);
entity.setGroupSnap(groupSnap);
} }
} }
entity.setIsDel(DeleteEnum.NORMAL.value()); entity.setIsDel(DeleteEnum.NORMAL.value());
@@ -163,13 +165,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
throw new CzgException("商品已存在"); throw new CzgException("商品已存在");
} }
Product entity = BeanUtil.copyProperties(dto, Product.class); Product entity = BeanUtil.copyProperties(dto, Product.class);
entity.setImages(JSON.toJSONString(dto.getImages())); entity.setImages(JSON.toJSONString(dto.getImages(), JSONWriter.Feature.WriteMapNullValue));
entity.setGroupSnap("[]"); entity.setGroupSnap("[]");
//套餐 //套餐
if (ProductTypeEnum.PACKAGE.value().equals(dto.getType())) { if (ProductTypeEnum.PACKAGE.value().equals(dto.getType())) {
//套餐内容 //套餐内容
if (CollUtil.isNotEmpty(dto.getProGroupVo())) { if (CollUtil.isNotEmpty(dto.getProGroupVo())) {
entity.setGroupSnap(JSON.toJSONString(dto.getProGroupVo())); entity.setGroupSnap(JSON.toJSONString(dto.getProGroupVo(), JSONWriter.Feature.WriteMapNullValue));
} }
} }
entity.setIsDel(DeleteEnum.NORMAL.value()); entity.setIsDel(DeleteEnum.NORMAL.value());