修改旷世sku审核
This commit is contained in:
1 parent
1518428aa3
commit
becdfc8d0d
8 files changed
+155
-55
No files matched your search
+5
-5
@@ -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);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
+112
-35
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -20,6 +20,13 @@ public interface RemoterThirdKsService {
|
||||
@PostMapping("/third-ks/sku-submit")
|
||||
R<KsSkuSubmitVo> skuSubmit(@RequestBody KsSkuSubmitDto dto);
|
||||
|
||||
/**
|
||||
* 常规SKU修改
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/third-ks/sku-edit")
|
||||
R<KsSkuEditVo> skuEdit(@RequestBody KsSkuEditDto dto, @RequestParam String ks_sku_id);
|
||||
|
||||
/**
|
||||
* 集合SKU提交审核(未公开)
|
||||
*/
|
||||
|
||||
+5
-7
@@ -2,14 +2,12 @@ package com.bsd.pjcloud.thirdparty.dto.ks;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class KsSkuEditDto {
|
||||
|
||||
/**
|
||||
* 该字段为超级收银员平台的sku_id,提交SKU审核后由系统返回,作为资源ID传递,是请求地址中的一部分,不需要提交到form表单
|
||||
*/
|
||||
private String ks_sku_id;
|
||||
|
||||
/**
|
||||
* 该字段为使用方系统sku_name,建议使用品牌名+商品名,如统一冰红茶
|
||||
*/
|
||||
@@ -23,7 +21,7 @@ public class KsSkuEditDto {
|
||||
/**
|
||||
* SKU图片仅在SKU因图片原因审核不通过的情况下支持修改,一旦SKU被审核通过,SKU图片将不再允许修改,如有相关需求,请重新申请SKU
|
||||
*/
|
||||
private String img_urls;
|
||||
private List<String> img_urls;
|
||||
|
||||
/**
|
||||
* 审核结果回调地址
|
||||
@@ -33,5 +31,5 @@ public class KsSkuEditDto {
|
||||
/**
|
||||
* 该字段为SKU所对应的规格,包含口味、容量、重量,taste表示口味,capacity表示容量,单位:ml,weight表示重量,单位:g
|
||||
*/
|
||||
private String specs;
|
||||
private Map<String, String> specs;
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.bsd.pjcloud.thirdparty.vo.ks;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class KsSkuEditVo {
|
||||
public class KsSkuEditVo extends KsBaseInnerVo {
|
||||
|
||||
/**
|
||||
* 该sku_id为使用方sku_id
|
||||
|
||||
+3
-3
@@ -49,10 +49,10 @@ public class ThirdKsApiController {
|
||||
}
|
||||
|
||||
@Inner
|
||||
@Operation(summary = "SKU审核结果主动获取")
|
||||
@Operation(summary = "常规SKU修改")
|
||||
@PostMapping("/sku-edit")
|
||||
public R<KsSkuEditVo> skuEdit(@RequestBody KsSkuEditDto dto) {
|
||||
return R.ok(thirdKsApiService.skuEdit(dto));
|
||||
public R<KsSkuEditVo> skuEdit(@RequestBody KsSkuEditDto dto, String ks_sku_id) {
|
||||
return R.ok(thirdKsApiService.skuEdit(dto, ks_sku_id));
|
||||
}
|
||||
|
||||
@Inner
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public interface ThirdKsApiService {
|
||||
/**
|
||||
* SKU审核结果主动获取
|
||||
*/
|
||||
KsSkuEditVo skuEdit(KsSkuEditDto dto);
|
||||
KsSkuEditVo skuEdit(KsSkuEditDto dto, String ks_sku_id);
|
||||
|
||||
/**
|
||||
* SKU删除
|
||||
|
||||
+21
-3
@@ -141,14 +141,32 @@ public class ThirdKsApiServiceImpl implements ThirdKsApiService {
|
||||
* SKU审核结果主动获取
|
||||
*/
|
||||
@Override
|
||||
public KsSkuEditVo skuEdit(KsSkuEditDto dto) {
|
||||
public KsSkuEditVo skuEdit(KsSkuEditDto dto, String ks_sku_id) {
|
||||
dto.setNotify_url(ksDiscernConfig.getCallbackBaseUrl() + ksDiscernConfig.getCallbackSkuUrl());
|
||||
String body = JSONUtil.toJsonStr(dto);
|
||||
long startTime = System.currentTimeMillis();
|
||||
KsBaseVo ksBaseVo = new KsBaseVo();
|
||||
KsApi.Api api = KsApi.SKU_EDIT.setBaseUrl(ksDiscernConfig.getBaseUrl()).setParams(BeanUtil.beanToMap(dto));
|
||||
KsApi.Api api = KsApi.SKU_EDIT.setBaseUrl(ksDiscernConfig.getBaseUrl())
|
||||
.setpath(ks_sku_id)
|
||||
.setBody(body)
|
||||
.setAccessKey(ksDiscernConfig.getAccessKey())
|
||||
.setSecretKey(ksDiscernConfig.getSecretKey())
|
||||
.setHost(ksDiscernConfig.getHost());
|
||||
ThirdDoorLogEntity logEntity = api.getInitLogEntity();
|
||||
logEntity.setReq(JSONUtil.toJsonStr(dto));
|
||||
try {
|
||||
|
||||
api.setBody(body);
|
||||
String res = api.getHttpRequest().execute().body();
|
||||
if (ObjectUtil.isEmpty(res)) throw new RuntimeException("response响应为空");
|
||||
logEntity.setRes(res);
|
||||
ksBaseVo = JSONUtil.toBean(res, KsBaseVo.class);
|
||||
if (!ksBaseVo.isSuccess()) {
|
||||
String errorLog = String.format("请求错误res|%s|url|%s|", res, api);
|
||||
log.error(errorLog);
|
||||
KsSkuEditVo errorVo = new KsSkuEditVo();
|
||||
errorVo.setMessage(ksBaseVo.getMsg());
|
||||
return errorVo;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String error = String.format("|%s||skuEdit|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
|
||||
log.error(error);
|
||||
|
||||
Reference in new issue
Block a user