feat:旷世提交、查询自己的商品

This commit is contained in:
dzc committed 2025-04-25 18:07:15 +08:00
1 parent fc292a9904
commit c084903129
14 files changed
+248 -37

No files matched your search

@@ -13,4 +13,9 @@ public class HardSpuDto extends HardSpuEntity {
private LocalDateTime[] createTimeList;
/**
* 分类不能为空
*/
private Boolean spuCategoryIdIsNotNull = false;
}
@@ -155,12 +155,20 @@ public class HardSpuEntity extends Model<HardSpuEntity> {
/**
* 旷世审核状态
* 0:待审核
* 1:审核中
* 2:审核通过
* 3:审核不通过
*/
@Schema(description = "旷世审核状态")
private String ksStatus;
/**
* 旷世审核状态标题
* 0:待审核
* 1:审核中
* 2:审核通过
* 3:审核不通过
*/
@Schema(description = "旷世审核状态标题")
private String ksStatusTitle;
@@ -0,0 +1,19 @@
package com.bsd.pjcloud.hard.api.feign;
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.feign.annotation.NoToken;
import com.bsd.pjcloud.thirdparty.dto.ks.KsSkuSubmitCallbackDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(contextId = "remoteHardSpuController", value = ServiceNameConstants.HARDWARE_SERVICE)
public interface RemoteHardSpuController {
@NoToken
@PostMapping("/sku-check-callback")
R skuCheckCallback(@RequestBody KsSkuSubmitCallbackDto dto);
}
@@ -1,3 +1,4 @@
com.bsd.pjcloud.hard.api.feign.RemoteHardDoorService
com.bsd.pjcloud.hard.api.feign.RemoteHardOrderService
com.bsd.pjcloud.hard.api.feign.RemoteHardThirdSelfZyService
com.bsd.pjcloud.hard.api.feign.RemoteHardSpuController
com.bsd.pjcloud.hard.api.feign.RemoteHardThirdSelfZyService
@@ -9,11 +9,13 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.hard.api.dto.spu.HardPutawayDto;
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuDto;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuJoinVo;
import com.bsd.pjcloud.hard.service.HardSpuService;
import com.bsd.pjcloud.thirdparty.dto.ks.KsSkuSubmitCallbackDto;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
@@ -42,6 +44,18 @@ public class HardSpuController {
private final HardSpuService hardSpuService;
/* ************************************* start callback start ************************************* */
@Inner
@Operation(summary = "商品审核回调", description = "商品审核回调")
@PostMapping("/sku-check-callback")
public R skuCheckCallback(@RequestBody KsSkuSubmitCallbackDto dto) {
hardSpuService.skuCheckCallback(dto);
return R.ok();
}
/* ************************************* end callback end ************************************* */
/* ************************************* start APP start ************************************* */
@Operation(summary = "app上架", description = "上架")
@@ -88,6 +102,13 @@ public class HardSpuController {
return R.ok();
}
@Operation(summary = "更新旷世商品审核进度", description = "更新旷世商品审核进度")
@GetMapping("/progress")
public R progress(@RequestParam Long id) {
hardSpuService.progress(id);
return R.ok();
}
@Operation(summary = "根据设备id智能柜编号查询商品", description = "根据设备id智能柜编号查询商品")
@GetMapping("/get-by-cabinet-no")
public R<List<Map<Integer, List<HardSpuJoinVo>>>> getByCabinetNo(@RequestParam Long hardId, @RequestParam String cabinetNo) {
@@ -108,7 +129,6 @@ public class HardSpuController {
return R.ok();
}
@Operation(summary = "下拉查询", description = "下拉查询")
@GetMapping("/select")
public R select(@ParameterObject Page page, @ParameterObject HardSpuDto dto) {
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuJoinVo;
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuVo;
import com.bsd.pjcloud.thirdparty.dto.ks.KsSkuSubmitCallbackDto;
import java.util.ArrayList;
import java.util.List;
@@ -31,6 +32,16 @@ public interface HardSpuService extends IService<HardSpuEntity> {
*/
Long create(HardSpuEntity entity);
/**
* 更新旷世商品审核进度
*/
void progress(Long id);
/**
* 商品审核回调
*/
void skuCheckCallback(KsSkuSubmitCallbackDto dto);
/**
* 编辑
*/
@@ -75,4 +86,5 @@ public interface HardSpuService extends IService<HardSpuEntity> {
* 扣减库存
*/
Boolean deductionSpuStock(HardDoorFlowEntity hardDoorFlow, List<DeductionSpuStockDto> list);
}
@@ -27,9 +27,8 @@ import com.bsd.pjcloud.hard.service.HardManagerService;
import com.bsd.pjcloud.hard.service.HardSpuJoinService;
import com.bsd.pjcloud.hard.service.HardSpuService;
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdKsService;
import com.bsd.pjcloud.thirdparty.dto.ks.KsBarcodeLikeDto;
import com.bsd.pjcloud.thirdparty.vo.ks.KsBarcodeLikeVo;
import com.bsd.pjcloud.thirdparty.vo.ks.KsSpuVo;
import com.bsd.pjcloud.thirdparty.dto.ks.*;
import com.bsd.pjcloud.thirdparty.vo.ks.*;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -82,25 +81,97 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
* 新增
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long create(HardSpuEntity entity) {
// if (existName(entity)) {
// throw new RuntimeException("商品名不能重复");
// }
String pic = entity.getPic();
pic = "https://nasa-voyager.oss-cn-beijing.aliyuncs.com/release/merchant_sku_img/watermark/202412021517-173bee3f2637499cb6b46e9b23d286c5.jpg";
if (ObjectUtil.isEmpty(pic)) {
throw new RuntimeException("请上传图片");
}
List<String> picList = Arrays.asList(pic.split(","));
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);
return entity.getId();
}
/**
* 更新旷世商品审核进度
*/
@Override
public void progress(Long id) {
HardSpuEntity detail = baseMapper.selectById(id);
if (ObjectUtil.isEmpty(detail)) {
throw new RuntimeException("商品不存在");
}
KsSkuResultDto dto = new KsSkuResultDto();
dto.setKs_sku_id(detail.getKsSkuId());
KsSkuResultVo vo = remoterThirdKsService.skuResult(dto).getData();
if (ObjectUtil.isEmpty(vo) || !vo.isSuccess()) throw new RuntimeException(vo.getMessage());
KsSkuResultVo.Result result = vo.getResult();
String comments = "";
if (ObjectUtil.isEmpty(vo.getComments())) {
comments = vo.getComments();
}
if (ObjectUtil.isNotEmpty(result)) {
HardSpuEntity update = new HardSpuEntity();
update.setId(detail.getId());
update.setKsStatus(result.getCode());
update.setKsStatusTitle(result.getDesc());
update.setKsComments(comments);
baseMapper.updateById(update);
}
}
/**
* 商品审核回调
*/
@Override
public void skuCheckCallback(KsSkuSubmitCallbackDto dto) {
if (ObjectUtil.isEmpty(dto) || ObjectUtil.isEmpty(dto.getKs_sku_id())) return;
HardSpuEntity detail = baseMapper.selectOne(new LambdaQueryWrapper<HardSpuEntity>().eq(HardSpuEntity::getKsSkuId, dto.getKs_sku_id()));
if (ObjectUtil.isEmpty(detail)) return;
KsSkuSubmitCallbackDto.Result result = dto.getResult();
String comments = "";
if (ObjectUtil.isEmpty(dto.getComments())) {
comments = dto.getComments();
}
if (ObjectUtil.isNotEmpty(result)) {
HardSpuEntity update = new HardSpuEntity();
update.setId(detail.getId());
update.setKsStatus(result.getCode());
update.setKsStatusTitle(result.getDesc());
update.setKsComments(comments);
baseMapper.updateById(update);
}
}
/**
* 编辑
*/
@Override
public Long edit(HardSpuEntity entity) {
// if (existName(entity)) {
// throw new RuntimeException("商品名不能重复");
// }
baseMapper.updateById(entity);
return entity.getId();
}
@@ -111,6 +182,18 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
@Override
public void delByIds(ArrayList<Long> list) {
if (ObjectUtil.isEmpty(list)) return;
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())) {
KsSkuDeleteDto dto = new KsSkuDeleteDto();
dto.setKs_sku_id(v.getKsSkuId());
KsSkuDeleteVo data = remoterThirdKsService.skuDelete(dto).getData();
if (ObjectUtil.isEmpty(data) || !data.isSuccess()) throw new RuntimeException(data.getMessage());
}
}
baseMapper.deleteByIds(list);
}
@@ -80,6 +80,11 @@
<if test="dto.spuCategoryId != null ">
and a.spu_category_id = #{dto.spuCategoryId}
</if>
<if test="dto.spuCategoryIdIsNotNull != null ">
<if test="dto.spuCategoryIdIsNotNull == true ">
and a.spu_category_id is not null
</if>
</if>
<if test="dto.status != null and dto.status != '' ">
and a.status = #{dto.status}
</if>
@@ -32,7 +32,7 @@ public class KsSkuSubmitCallbackDto {
* 2:审核通过
* 3:审核不通过
*/
private Integer code;
private String code;
private String desc;
@@ -2,6 +2,9 @@ package com.bsd.pjcloud.thirdparty.dto.ks;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class KsSkuSubmitDto {
/**
@@ -22,7 +25,7 @@ public class KsSkuSubmitDto {
/**
* 该字段为SKU不同方位视图,所需拍摄的图片数量及角度请参考商品建模文档,参数具体值为图片资源地址,如资源为使用方所属,请确保外部可以访问,请注意图片尺寸及质量,综合质量不佳可能会导致审核不通过。图片尺寸不小于1920*1080,压缩质量不低于70%,长宽比介于16:9同1:1之间。
*/
private String img_urls;
private List<String> img_urls;
/**
* 审核结果回调地址
@@ -32,6 +35,6 @@ public class KsSkuSubmitDto {
/**
* 该字段为SKU所对应的规格,包含口味、容量、重量,taste表示口味,capacity表示容量,单位:ml,weight表示重量,单位:g
*/
private String specs;
private Map<String, String> specs;
}
@@ -3,7 +3,7 @@ package com.bsd.pjcloud.thirdparty.vo.ks;
import lombok.Data;
@Data
public class KsSkuDeleteVo {
public class KsSkuDeleteVo extends KsBaseInnerVo {
/**
* 该sku_id为使用方sku_id
@@ -3,24 +3,27 @@ package com.bsd.pjcloud.thirdparty.vo.ks;
import lombok.Data;
@Data
public class KsSkuResultVo {
public class KsSkuResultVo extends KsBaseInnerVo {
/**
* 该字段返回结果为字典值,不同code代表不同结果
* <p>
* 0:待审核
* <p>
* 1:审核中
* <p>
* 2:审核通过
* <p>
* 3:审核不通过
*/
private String result;
private Result result;
/**
* 审核不通过时该字段才有值
*/
private String comments;
@Data
public static class Result {
private String code;
private String desc;
}
}
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.bsd.pjcloud.hard.api.feign.RemoteHardDoorService;
import com.bsd.pjcloud.hard.api.feign.RemoteHardSpuController;
import com.bsd.pjcloud.thirdparty.config.KsDiscernConfig;
import com.bsd.pjcloud.thirdparty.dto.ks.*;
import com.bsd.pjcloud.thirdparty.entity.door.ThirdDoorLogEntity;
@@ -14,7 +15,6 @@ import com.bsd.pjcloud.thirdparty.utils.ks.tool.KsRetailSignUtils;
import com.bsd.pjcloud.thirdparty.vo.ks.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -35,19 +35,37 @@ public class ThirdKsApiServiceImpl implements ThirdKsApiService {
private final ThirdDoorLogService doorLogService;
private final RemoteHardDoorService remoteHardDoorService;
private final RemoteHardSpuController remoteHardSpuController;
/**
* 常规SKU提交审核
*/
@Override
public KsSkuSubmitVo skuSubmit(KsSkuSubmitDto dto) {
dto.setNotify_url(ksDiscernConfig.getCallbackBaseUrl() + ksDiscernConfig.getCallbackSkuUrl());
long startTime = System.currentTimeMillis();
KsBaseVo ksBaseVo = new KsBaseVo();
KsApi.Api api = KsApi.SKU_SUBMIT.setBaseUrl(ksDiscernConfig.getBaseUrl()).setParams(BeanUtil.beanToMap(dto));
KsApi.Api api = KsApi.SKU_SUBMIT.setBaseUrl(ksDiscernConfig.getBaseUrl())
.setParams(BeanUtil.beanToMap(dto))
.setAccessKey(ksDiscernConfig.getAccessKey())
.setSecretKey(ksDiscernConfig.getSecretKey())
.setHost(ksDiscernConfig.getHost());
ThirdDoorLogEntity logEntity = api.getInitLogEntity();
logEntity.setReq(JSONUtil.toJsonStr(dto));
try {
String body = JSONUtil.toJsonStr(dto);
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|body|%s|", res, api, body);
log.error(errorLog);
KsSkuSubmitVo errorVo = new KsSkuSubmitVo();
errorVo.setMessage(ksBaseVo.getMsg());
return errorVo;
}
} catch (Exception e) {
String error = String.format("|%s||skuSubmit|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
@@ -89,11 +107,25 @@ public class ThirdKsApiServiceImpl implements ThirdKsApiService {
public KsSkuResultVo skuResult(KsSkuResultDto dto) {
long startTime = System.currentTimeMillis();
KsBaseVo ksBaseVo = new KsBaseVo();
KsApi.Api api = KsApi.SKU_RESULT.setBaseUrl(ksDiscernConfig.getBaseUrl()).setParams(BeanUtil.beanToMap(dto));
KsApi.Api api = KsApi.SKU_RESULT.setBaseUrl(ksDiscernConfig.getBaseUrl())
.setpath(dto.getKs_sku_id())
.setAccessKey(ksDiscernConfig.getAccessKey())
.setSecretKey(ksDiscernConfig.getSecretKey())
.setHost(ksDiscernConfig.getHost());
ThirdDoorLogEntity logEntity = api.getInitLogEntity();
logEntity.setReq(JSONUtil.toJsonStr(dto));
try {
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);
KsSkuResultVo errorVo = new KsSkuResultVo();
errorVo.setMessage(ksBaseVo.getMsg());
return errorVo;
}
} catch (Exception e) {
String error = String.format("|%s||skuResult|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
@@ -135,11 +167,25 @@ public class ThirdKsApiServiceImpl implements ThirdKsApiService {
public KsSkuDeleteVo skuDelete(KsSkuDeleteDto dto) {
long startTime = System.currentTimeMillis();
KsBaseVo ksBaseVo = new KsBaseVo();
KsApi.Api api = KsApi.SKU_DELETE.setBaseUrl(ksDiscernConfig.getBaseUrl()).setParams(BeanUtil.beanToMap(dto));
KsApi.Api api = KsApi.SKU_DELETE.setBaseUrl(ksDiscernConfig.getBaseUrl())
.setpath(dto.getKs_sku_id())
.setAccessKey(ksDiscernConfig.getAccessKey())
.setSecretKey(ksDiscernConfig.getSecretKey())
.setHost(ksDiscernConfig.getHost());
ThirdDoorLogEntity logEntity = api.getInitLogEntity();
logEntity.setReq(JSONUtil.toJsonStr(dto));
try {
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);
KsSkuDeleteVo errorVo = new KsSkuDeleteVo();
errorVo.setMessage(ksBaseVo.getMsg());
return errorVo;
}
} catch (Exception e) {
String error = String.format("|%s||skuDelete|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
@@ -318,7 +364,7 @@ public class ThirdKsApiServiceImpl implements ThirdKsApiService {
ThirdDoorLogEntity logEntity = api.getInitLogEntity();
logEntity.setReq(json);
try {
remoteHardSpuController.skuCheckCallback(dto);
} catch (Exception e) {
String error = String.format("|%s||callbackSKu|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace()));
log.error(error);
@@ -1,6 +1,7 @@
package com.bsd.pjcloud.thirdparty.utils.ks.api;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
@@ -35,7 +36,7 @@ public class KsApi {
public static final KsApi.Api SKU_SUBMIT_COLLECTION = KsApi.Api.builder().url("/openapi/sc/v1/sku/collection").bizType(ThirdDoorKsApiTypeEnum.SKU_SUBMIT).method(HttpPost.METHOD_NAME).contentType("application/json").build();
// SKU审核结果主动获取
public static final KsApi.Api SKU_RESULT = KsApi.Api.builder().url("/openapi/sc/v1/sku/%s").bizType(ThirdDoorKsApiTypeEnum.SKU_SUBMIT).method(HttpPost.METHOD_NAME).contentType("application/json").build();
public static final KsApi.Api SKU_RESULT = KsApi.Api.builder().url("/openapi/sc/v1/sku/%s").bizType(ThirdDoorKsApiTypeEnum.SKU_SUBMIT).method(HttpGet.METHOD_NAME).contentType("application/json").build();
// SKU识别结果回调通知
public static final KsApi.Api SKU_EDIT = KsApi.Api.builder().url("/callback").bizType(ThirdDoorKsApiTypeEnum.SKU_SUBMIT).method(HttpPatch.METHOD_NAME).contentType("application/json").build();
@@ -75,6 +76,8 @@ public class KsApi {
private Map<String, Object> params = new TreeMap<>();
private List<Object> path;
private String body;
private String method;
@@ -91,7 +94,6 @@ public class KsApi {
private String host = "";
private String requestId;
public KsApi.Api setBaseUrl(String baseUrl) {
@@ -119,14 +121,17 @@ public class KsApi {
return this;
}
public Api setpath(Object... path) {
this.url = String.format(this.url, path);
this.path = ListUtil.of(path);
return this;
}
public KsApi.Api setBody(String body) {
this.body = body;
return this;
}
/**
* 获取当前时间戳
*/
public Long getXRequestDate() {
return System.currentTimeMillis();
}
@@ -153,6 +158,7 @@ public class KsApi {
// 计算签名
Long currentTime = getXRequestDate();
String queryString = getQueryString();
if (ObjectUtil.isEmpty(queryString)) queryString = "";
String auth = KsRetailSignUtils.getSignAuth(getHost(), getUrl(), contentType, getMethod(), currentTime, getAccessKey(), getSecretKey(), getBody(), queryString);
String requestId = getXRequestDate() + RandomUtil.randomString(19);
setRequestId(requestId);
@@ -181,7 +187,7 @@ public class KsApi {
} else if (ObjectUtil.equals(method, HttpPatch.METHOD_NAME)) {
return HttpRequest.patch(fullPatch).header(getHeader()).body(getBody());
} else if (ObjectUtil.equals(method, HttpDelete.METHOD_NAME)) {
return HttpRequest.delete(fullPatch).header(getHeader()).body(getBody());
return HttpRequest.delete(fullPatch).header(getHeader());
} else {
return null;
}