|
|
@@ -2,6 +2,7 @@ package com.etotem.cfc.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
@@ -452,6 +453,9 @@ wrapper.in(Product::getId, productIds)
|
|
|
* 管理员创建商品(直接上架)
|
|
|
*/
|
|
|
public Result<ProductDTO> adminCreate(Product product) {
|
|
|
+ // 最低可见级别:空串规整为 NULL(NULL=所有用户含未登录可见),
|
|
|
+ // 避免管理端 el-select 清空提交 '' 导致商品对所有用户不可见
|
|
|
+ normalizeMinVisibleLevel(product);
|
|
|
product.setStatus("on_shelf");
|
|
|
product.setCreatedAt(new Date());
|
|
|
product.setUpdatedAt(new Date());
|
|
|
@@ -481,10 +485,32 @@ wrapper.in(Product::getId, productIds)
|
|
|
product.setUpdatedAt(new Date());
|
|
|
// 保留原状态不变,避免被覆盖
|
|
|
product.setStatus(existing.getStatus());
|
|
|
+ // 最低可见级别:空串规整为 NULL(NULL=所有用户含未登录可见),
|
|
|
+ // 避免管理端 el-select 清空提交 '' 导致商品对所有用户不可见
|
|
|
+ boolean clearMinVisibleLevel = normalizeMinVisibleLevel(product);
|
|
|
productMapper.updateById(product);
|
|
|
+ // updateById 默认忽略 null 字段,清空时需显式将 min_visible_level 置 NULL
|
|
|
+ if (clearMinVisibleLevel) {
|
|
|
+ productMapper.update(null, new LambdaUpdateWrapper<Product>()
|
|
|
+ .eq(Product::getId, product.getId())
|
|
|
+ .set(Product::getMinVisibleLevel, null));
|
|
|
+ }
|
|
|
return Result.success(ProductDTO.from(productMapper.selectById(product.getId())));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 最低可见级别空串归一化:'' → NULL。
|
|
|
+ *
|
|
|
+ * @return true 表示发生了空串清空(需要显式把列置为 NULL,因为 updateById 忽略 null 字段)
|
|
|
+ */
|
|
|
+ private boolean normalizeMinVisibleLevel(Product product) {
|
|
|
+ if (product.getMinVisibleLevel() != null && product.getMinVisibleLevel().trim().isEmpty()) {
|
|
|
+ product.setMinVisibleLevel(null);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 管理员更新商品(含测评扩展信息)
|
|
|
*/
|