修改旷世sku审核

This commit is contained in:
dzc committed 2025-04-27 11:41:04 +08:00
1 parent 1518428aa3
commit becdfc8d0d
8 files changed
+155 -55

No files matched your search

@@ -32,6 +32,11 @@ public interface HardSpuService extends IService<HardSpuEntity> {
*/
Long create(HardSpuEntity entity);
/**
* 编辑
*/
Long edit(HardSpuEntity entity);
/**
* 更新旷世商品审核进度
*/
@@ -42,11 +47,6 @@ public interface HardSpuService extends IService<HardSpuEntity> {
*/
void skuCheckCallback(KsSkuSubmitCallbackDto dto);
/**
* 编辑
*/
Long edit(HardSpuEntity entity);
/**
* 删除
*/
@@ -1,7 +1,10 @@
package com.bsd.pjcloud.hard.service.impl.spu;
import cn.hutool.Hutool;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -38,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import java.util.regex.Pattern;
/**
* 硬件商品
@@ -86,37 +90,38 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
public Long create(HardSpuEntity entity) {
String pic = entity.getPic();
if (ObjectUtil.isEmpty(pic)) throw new RuntimeException("请上传图片");
String imageBaseUrl = ParamResolver.getStr("IMAGE_BASE_URL");
if (ObjectUtil.isEmpty(imageBaseUrl)) throw new RuntimeException("请配置图片基础路径");
List<String> picList = Arrays.asList(pic.split(","));
picList = picList.stream().map(v -> String.format("%s%s", imageBaseUrl, v)).toList();
entity.setSkuType(HardKsSkuTypeEnum.SELF.getType());
baseMapper.insert(entity);
if (ObjectUtil.equals(entity.getIsDefault(), YesNoEnum.NO.getCode())) {
return entity.getId();
}
// 发起旷世审核
KsSkuSubmitDto dto = new KsSkuSubmitDto();
dto.setSku_id(String.valueOf(entity.getId()));
dto.setSku_name(entity.getName());
dto.setImg_urls(picList);
Map<String, String> specs = new HashMap<>();
specs.put("taste", entity.getSpecsTaste());
specs.put("capacity", entity.getSpecsCapacity());
specs.put("weight", entity.getSpecsWeight());
dto.setSpecs(specs);
KsSkuSubmitVo data = remoterThirdKsService.skuSubmit(dto).getData();
if (ObjectUtil.isEmpty(data) || !data.isSuccess()) throw new RuntimeException(data.getMessage());
HardSpuEntity update = new HardSpuEntity();
update.setId(entity.getId());
update.setKsSkuId(data.getKs_sku_id());
update.setKsStatus("0");
update.setKsStatusTitle("待审核");
update.setKsComments("提交审核");
baseMapper.updateById(update);
submitKsSpu(entity);
return entity.getId();
}
/**
* 编辑
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long edit(HardSpuEntity entity) {
HardSpuEntity spuDetail = baseMapper.selectById(entity.getId());
if (ObjectUtil.isEmpty(spuDetail)) throw new RuntimeException("商品不存在");
baseMapper.updateById(entity);
// 修改sku审批
if (ObjectUtil.equals(entity.getIsDefault(), YesNoEnum.NO.getCode())) {
return entity.getId();
}
if (ObjectUtil.isEmpty(entity.getKsSkuId())) {
getSelf().submitKsSpu(spuDetail);
} else {
getSelf().editKsSpu(spuDetail);
}
return entity.getId();
}
/**
* 更新旷世商品审核进度
*/
@@ -168,24 +173,13 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
}
}
/**
* 编辑
*/
@Override
public Long edit(HardSpuEntity entity) {
baseMapper.updateById(entity);
return entity.getId();
}
/**
* 删除
*/
@Override
public void delByIds(ArrayList<Long> list) {
if (ObjectUtil.isEmpty(list)) return;
List<HardSpuEntity> spuList = baseMapper.selectList(new LambdaQueryWrapper<HardSpuEntity>()
.in(HardSpuEntity::getId, list)
);
List<HardSpuEntity> spuList = baseMapper.selectList(new LambdaQueryWrapper<HardSpuEntity>().in(HardSpuEntity::getId, list));
for (HardSpuEntity v : spuList) {
if (ObjectUtil.notEqual(v.getSkuType(), HardKsSkuTypeEnum.SELF.getType())) continue;
if (ObjectUtil.isNotEmpty(v.getKsSkuId())) {
@@ -472,6 +466,76 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
return true;
}
/**
* 发起旷世sku审核
*/
@Transactional(rollbackFor = Exception.class)
public void submitKsSpu(HardSpuEntity entity) {
String pic = entity.getPic();
pic = "https://nasa-voyager.oss-cn-beijing.aliyuncs.com/release/merchant_sku_img/watermark/202412021517-173bee3f2637499cb6b46e9b23d286c5.jpg";
List<String> picList = Arrays.asList(pic.split(","));
String imageBaseUrl = ParamResolver.getStr("IMAGE_BASE_URL");
if (ObjectUtil.isEmpty(imageBaseUrl)) throw new RuntimeException("请配置图片基础路径");
picList = picList.stream().map(v -> {
boolean isUrl = isValidUrl(v);
if (isUrl) return v;
return String.format("%s%s", imageBaseUrl, v);
}).toList();
// 发起旷世审核
KsSkuSubmitDto dto = new KsSkuSubmitDto();
dto.setSku_id(String.valueOf(entity.getId()));
dto.setSku_name(entity.getName());
dto.setImg_urls(picList);
Map<String, String> specs = new HashMap<>();
specs.put("taste", entity.getSpecsTaste());
specs.put("capacity", entity.getSpecsCapacity());
specs.put("weight", entity.getSpecsWeight());
dto.setSpecs(specs);
KsSkuSubmitVo data = remoterThirdKsService.skuSubmit(dto).getData();
if (ObjectUtil.isEmpty(data) || !data.isSuccess()) throw new RuntimeException(data.getMessage());
HardSpuEntity update = new HardSpuEntity();
update.setId(entity.getId());
update.setKsSkuId(data.getKs_sku_id());
update.setKsStatus("0");
update.setKsStatusTitle("待审核");
update.setKsComments("提交审核");
baseMapper.updateById(update);
}
/**
* 修改旷世sku审核
*/
@Transactional(rollbackFor = Exception.class)
public void editKsSpu(HardSpuEntity entity) {
String pic = entity.getPic();
pic = "https://nasa-voyager.oss-cn-beijing.aliyuncs.com/release/merchant_sku_img/watermark/202412021517-173bee3f2637499cb6b46e9b23d286c5.jpg";
List<String> picList = Arrays.asList(pic.split(","));
String imageBaseUrl = ParamResolver.getStr("IMAGE_BASE_URL");
if (ObjectUtil.isEmpty(imageBaseUrl)) throw new RuntimeException("请配置图片基础路径");
picList = picList.stream().map(v -> {
boolean isUrl = isValidUrl(v);
if (isUrl) return v;
return String.format("%s%s", imageBaseUrl, v);
}).toList();
// 修改旷世sku
KsSkuEditDto updateObj = new KsSkuEditDto();
updateObj.setSku_name(entity.getName());
updateObj.setImg_urls(picList);
Map<String, String> specs = new HashMap<>();
specs.put("taste", entity.getSpecsTaste());
specs.put("capacity", entity.getSpecsCapacity());
specs.put("weight", entity.getSpecsWeight());
updateObj.setSpecs(specs);
KsSkuEditVo vo = remoterThirdKsService.skuEdit(updateObj, entity.getKsSkuId()).getData();
if (ObjectUtil.isEmpty(vo) || !vo.isSuccess()) throw new RuntimeException(vo.getMessage());
HardSpuEntity update = new HardSpuEntity();
update.setId(entity.getId());
update.setKsStatus("0");
update.setKsStatusTitle("待审核");
update.setKsComments("提交审核");
baseMapper.updateById(update);
}
/**
* 商品是否重复
*/
@@ -486,8 +550,21 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
return count > 0;
}
public boolean isValidUrl(String url) {
if (StrUtil.isBlank(url)) {
return false;
}
String URL_REGEX = "^(https?|ftp)://[\\w.-]+(?:\\/[\\w.-]*)*";
Pattern URL_PATTERN = Pattern.compile(URL_REGEX);
return URL_PATTERN.matcher(url).matches();
}
private void disposeList(List<HardSpuVo> list, HardSpuDto dto) {
if (ObjectUtil.isEmpty(list)) return;
}
private HardSpuServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}