|
@@ -1,16 +1,19 @@
|
|
|
package com.kmall.admin.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.google.common.base.Joiner;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.kmall.admin.dao.GoodsProductDao;
|
|
|
import com.kmall.admin.dto.GoodsProductDto;
|
|
|
import com.kmall.admin.dto.PdProductDtoInfo;
|
|
|
import com.kmall.admin.entity.GoodsProductEntity;
|
|
|
import com.kmall.admin.service.GoodsProductService;
|
|
|
+import com.kmall.admin.service.GoodsService;
|
|
|
import com.kmall.admin.utils.ShiroUtils;
|
|
|
import com.kmall.admin.utils.data.response.ResponseMessage;
|
|
|
import com.kmall.admin.utils.oms.OmsSign;
|
|
|
import com.kmall.common.constant.Dict;
|
|
|
+import com.kmall.common.utils.R;
|
|
|
import com.kmall.common.utils.RRException;
|
|
|
import com.kmall.manager.manager.merch.OmsMerchProperties;
|
|
|
import okhttp3.Request;
|
|
@@ -23,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -41,6 +45,9 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
private GoodsProductDao goodsProductDao;
|
|
|
|
|
|
@Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private OmsMerchProperties omsMerchProperties;
|
|
|
|
|
|
@Override
|
|
@@ -60,11 +67,47 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
|
|
|
@Override
|
|
|
public int save(GoodsProductEntity goodsProduct) {
|
|
|
+ GoodsProductEntity entity = goodsProductDao.selectBySku(goodsProduct.getSku());
|
|
|
+ if (entity != null) {
|
|
|
+ throw new RRException("该sku已存在!");
|
|
|
+ }
|
|
|
+ entity = goodsProductDao.selectByBarcode(goodsProduct.getProdBarcode());
|
|
|
+ if (entity != null) {
|
|
|
+ throw new RRException("该产品条码已存在!");
|
|
|
+ }
|
|
|
+ goodsProduct.setStatus(Dict.productRecordStatus.item_00.getItem());
|
|
|
return goodsProductDao.save(goodsProduct);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public int update(GoodsProductEntity goodsProduct) {
|
|
|
+ GoodsProductEntity entity = goodsProductDao.selectBySku(goodsProduct.getSku());
|
|
|
+ if (entity == null) {
|
|
|
+ throw new RRException("该产品sku不存在!");
|
|
|
+ }
|
|
|
+ String status = entity.getStatus();
|
|
|
+ Map<String, String> restrictMsg = new HashMap<>();
|
|
|
+
|
|
|
+ restrictMsg.put(Dict.productRecordStatus.item_02.getItem(), "该数据正在审核中,无法修改");
|
|
|
+ restrictMsg.put(Dict.productRecordStatus.item_12.getItem(), "该数据正在审核中,无法修改");
|
|
|
+ restrictMsg.put(Dict.productRecordStatus.item_21.getItem(), "该数据已经备案成功,暂未更新,无法修改");
|
|
|
+
|
|
|
+ if (restrictMsg.containsKey(status)) {
|
|
|
+ throw new RRException(restrictMsg.get(status));
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> addStatus = new HashSet<>();
|
|
|
+ addStatus.add(Dict.productRecordStatus.item_00.getItem());
|
|
|
+ addStatus.add(Dict.productRecordStatus.item_01.getItem());
|
|
|
+ addStatus.add(Dict.productRecordStatus.item_03.getItem());
|
|
|
+ if (addStatus.contains(status)) {
|
|
|
+ goodsProduct.setStatus(Dict.productRecordStatus.item_00.getItem());
|
|
|
+ } else {
|
|
|
+ goodsProduct.setStatus(Dict.productRecordStatus.item_10.getItem());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return goodsProductDao.update(goodsProduct);
|
|
|
}
|
|
|
|
|
@@ -74,15 +117,15 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int deleteBatch(Integer[]mallGoodsProductSns) {
|
|
|
+ public int deleteBatch(Integer[] mallGoodsProductSns) {
|
|
|
return goodsProductDao.deleteBatch(mallGoodsProductSns);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void uploadExcel(List<GoodsProductDto> goodsProductDtoList) {
|
|
|
- if (Objects.nonNull(goodsProductDtoList) && goodsProductDtoList.size()>0){
|
|
|
- int count =1;
|
|
|
+ if (Objects.nonNull(goodsProductDtoList) && goodsProductDtoList.size() > 0) {
|
|
|
+ int count = 1;
|
|
|
for (GoodsProductDto goodsProductDto : goodsProductDtoList) {
|
|
|
if (StringUtils.isEmpty(goodsProductDto.getMerchSn())) {
|
|
|
throw new RRException("第" + count + "行的商户编号为空!");
|
|
@@ -109,10 +152,10 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
throw new RRException("第" + count + "行的品牌中文或品牌英文必填其中之一!");
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(goodsProductDto.getProdBrandCn()) && !StringUtils.isEmpty(goodsProductDto.getProdBrandEn())) {
|
|
|
- goodsProductDto.setProdBrand(goodsProductDto.getProdBrandCn()+"#&#"+goodsProductDto.getProdBrandEn());
|
|
|
- }else if (!StringUtils.isEmpty(goodsProductDto.getProdBrandCn()) && StringUtils.isEmpty(goodsProductDto.getProdBrandEn())){
|
|
|
+ goodsProductDto.setProdBrand(goodsProductDto.getProdBrandCn() + "#&#" + goodsProductDto.getProdBrandEn());
|
|
|
+ } else if (!StringUtils.isEmpty(goodsProductDto.getProdBrandCn()) && StringUtils.isEmpty(goodsProductDto.getProdBrandEn())) {
|
|
|
goodsProductDto.setProdBrand(goodsProductDto.getProdBrandCn());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
goodsProductDto.setProdBrand(goodsProductDto.getProdBrandEn());
|
|
|
}
|
|
|
if (StringUtils.isEmpty(goodsProductDto.getUnitCode())) {
|
|
@@ -148,12 +191,12 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
if (StringUtils.isEmpty(goodsProductDto.getLegalUnit2Qty())) {
|
|
|
throw new RRException("第" + count + "行的第二法定单位数量为空!");
|
|
|
}
|
|
|
- GoodsProductEntity queryProduct = goodsProductDao.selectByParams(goodsProductDto.getSku(), goodsProductDto.getMerchSn(),goodsProductDto.getThirdMerchSn());
|
|
|
- if (Objects.nonNull(queryProduct)){
|
|
|
- throw new RRException("该sku:"+queryProduct.getSku()+"已存在!");
|
|
|
+ GoodsProductEntity queryProduct = goodsProductDao.selectByParams(goodsProductDto.getSku(), goodsProductDto.getMerchSn(), goodsProductDto.getThirdMerchSn());
|
|
|
+ if (Objects.nonNull(queryProduct)) {
|
|
|
+ throw new RRException("该sku:" + queryProduct.getSku() + "已存在!");
|
|
|
}
|
|
|
GoodsProductEntity goodsProductEntity = new GoodsProductEntity();
|
|
|
- BeanUtils.copyProperties(goodsProductDto,goodsProductEntity);
|
|
|
+ BeanUtils.copyProperties(goodsProductDto, goodsProductEntity);
|
|
|
goodsProductEntity.setLegalUnit1Qty(new BigDecimal(goodsProductDto.getLegalUnit1Qty()));
|
|
|
goodsProductEntity.setLegalUnit2Qty(new BigDecimal(goodsProductDto.getLegalUnit2Qty()));
|
|
|
goodsProductEntity.setNetWeight(new BigDecimal(goodsProductDto.getNetWeight()));
|
|
@@ -165,20 +208,58 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
goodsProductEntity.setDeclPrice(new BigDecimal(goodsProductDto.getDeclPrice()));
|
|
|
goodsProductEntity.setCreateTime(new Date());
|
|
|
goodsProductEntity.setCreaterSn(ShiroUtils.getUserId().toString());
|
|
|
+ goodsProductEntity.setStatus(Dict.productRecordStatus.item_00.getItem());
|
|
|
goodsProductDao.save(goodsProductEntity);
|
|
|
- count ++;
|
|
|
+ count++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public String sendSelectProduct(Integer[] mallGoodsProductSns,String operateFlag) {
|
|
|
+ public String sendSelectProduct(Integer[] mallGoodsProductSns, String operateFlag) {
|
|
|
+ if (!Dict.operateFlag.item_1.getItem().equals(operateFlag) && !Dict.operateFlag.item_2.getItem().equals(operateFlag)) {
|
|
|
+ return "操作标识无法识别,请联系管理员";
|
|
|
+ }
|
|
|
List<GoodsProductEntity> goodsProductEntityList = goodsProductDao.selectByMallGoodsProductSns(mallGoodsProductSns);
|
|
|
+
|
|
|
+ Map<String, String> addRestrictMsg = new HashMap<>();
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_02.getItem(), "sku:%s,该sku备案正在审核中,请勿再次发送!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_03.getItem(), "sku:%s,该sku备案审核失败,请修改后再次发送!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_10.getItem(), "sku:%s,该sku备案为重新备案,请选择修改发送!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_11.getItem(), "sku:%s,该sku备案为重新备案,请选择修改发送!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_12.getItem(), "sku:%s,该sku备案为重新备案,且正在审核中!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_13.getItem(), "sku:%s,该sku备案为重新备案,请修改后选择修改发送!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_21.getItem(), "sku:%s,该sku备案已经备案成功,请重新抓取!");
|
|
|
+ addRestrictMsg.put(Dict.productRecordStatus.item_22.getItem(), "sku:%s,该sku备案已经备案成功,无法新增,如需修改,请编辑后选择修改发送!");
|
|
|
+
|
|
|
+ Map<String, String> updateRestrictMsg = new HashMap<>();
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_00.getItem(), "sku:%s,该sku为新增备案,请选择新增发送!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_01.getItem(), "sku:%s,该sku为新增备案,请选择新增发送!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_02.getItem(), "sku:%s,该sku为新增备案,且正在审核中!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_03.getItem(), "sku:%s,该sku为新增备案,请修改后选择新增发送!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_12.getItem(), "sku:%s,该sku备案正在审核中,请勿再次发送!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_13.getItem(), "sku:%s,该sku备案审核失败,请修改后再次发送!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_21.getItem(), "sku:%s,该sku备案已经备案成功,请重新抓取!");
|
|
|
+ updateRestrictMsg.put(Dict.productRecordStatus.item_22.getItem(), "sku:%s,该sku备案已经备案成功,如需修改,请编辑后选择修改发送!");
|
|
|
+ for (GoodsProductEntity entity : goodsProductEntityList) {
|
|
|
+ String status = entity.getStatus();
|
|
|
+ if (Dict.operateFlag.item_1.getItem().equals(operateFlag)) {
|
|
|
+ if (addRestrictMsg.containsKey(status)) {
|
|
|
+ String msg = addRestrictMsg.get(status);
|
|
|
+ return String.format(msg, entity.getSku());
|
|
|
+ }
|
|
|
+ } else if (Dict.operateFlag.item_2.getItem().equals(operateFlag)) {
|
|
|
+ if (updateRestrictMsg.containsKey(status)) {
|
|
|
+ String msg = updateRestrictMsg.get(status);
|
|
|
+ return String.format(msg, entity.getSku());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
List<GoodsProductDto> goodsProductDtoList = new ArrayList<>();
|
|
|
for (GoodsProductEntity goodsProductEntity : goodsProductEntityList) {
|
|
|
GoodsProductDto dto = new GoodsProductDto();
|
|
|
- BeanUtils.copyProperties(goodsProductEntity,dto);
|
|
|
+ BeanUtils.copyProperties(goodsProductEntity, dto);
|
|
|
dto.setLegalUnit1Qty(goodsProductEntity.getLegalUnit1Qty().toString());
|
|
|
dto.setLegalUnit2Qty(goodsProductEntity.getLegalUnit2Qty().toString());
|
|
|
dto.setNetWeight(goodsProductEntity.getNetWeight().toString());
|
|
@@ -194,14 +275,14 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
if (!"0".equals(result.getCode())) {
|
|
|
isPass = false;
|
|
|
}
|
|
|
- rollbackHandler(goodsProductDtoList, isPass);
|
|
|
+ callbackHandler(goodsProductDtoList, isPass);
|
|
|
return result.getMsg();
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
isPass = false;
|
|
|
e.printStackTrace();
|
|
|
LOGGER.error(e.getMessage());
|
|
|
}
|
|
|
- rollbackHandler(goodsProductDtoList, isPass);
|
|
|
+ callbackHandler(goodsProductDtoList, isPass);
|
|
|
return "请求失败,请联系管理员";
|
|
|
}
|
|
|
|
|
@@ -210,15 +291,22 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
public String sendAllProduct(String operateFlag) {
|
|
|
// 查询所有发送失败或者未发送的
|
|
|
Map<String, Object> condition = new HashMap<>();
|
|
|
- condition.put("isSend", "0,2");
|
|
|
+ if (Dict.operateFlag.item_1.getItem().equals(operateFlag)) {
|
|
|
+ condition.put("status", Dict.productRecordStatus.item_00.getItem() + "," + Dict.productRecordStatus.item_01.getItem());
|
|
|
+ } else if (Dict.operateFlag.item_2.getItem().equals(operateFlag)) {
|
|
|
+ condition.put("status", Dict.productRecordStatus.item_10.getItem() + "," + Dict.productRecordStatus.item_11.getItem());
|
|
|
+ } else {
|
|
|
+ return "操作标识无法识别,请联系管理员";
|
|
|
+ }
|
|
|
+
|
|
|
List<GoodsProductEntity> goodsProductEntityList = goodsProductDao.queryList(condition);
|
|
|
- if (goodsProductEntityList == null || goodsProductEntityList.size()==0){
|
|
|
- return "无数据,请添加数据";
|
|
|
+ if (goodsProductEntityList == null || goodsProductEntityList.size() == 0) {
|
|
|
+ return "没有要发送的数据";
|
|
|
}
|
|
|
List<GoodsProductDto> goodsProductDtoList = new ArrayList<>();
|
|
|
for (GoodsProductEntity goodsProductEntity : goodsProductEntityList) {
|
|
|
GoodsProductDto dto = new GoodsProductDto();
|
|
|
- BeanUtils.copyProperties(goodsProductEntity,dto);
|
|
|
+ BeanUtils.copyProperties(goodsProductEntity, dto);
|
|
|
dto.setLegalUnit1Qty(goodsProductEntity.getLegalUnit1Qty().toString());
|
|
|
dto.setLegalUnit2Qty(goodsProductEntity.getLegalUnit2Qty().toString());
|
|
|
dto.setNetWeight(goodsProductEntity.getNetWeight().toString());
|
|
@@ -234,14 +322,14 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
if (!"0".equals(result.getCode())) {
|
|
|
isPass = false;
|
|
|
}
|
|
|
- rollbackHandler(goodsProductDtoList, isPass);
|
|
|
+ callbackHandler(goodsProductDtoList, isPass);
|
|
|
return result.getMsg();
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
isPass = false;
|
|
|
e.printStackTrace();
|
|
|
LOGGER.error(e.getMessage());
|
|
|
}
|
|
|
- rollbackHandler(goodsProductDtoList, isPass);
|
|
|
+ callbackHandler(goodsProductDtoList, isPass);
|
|
|
return "请求失败,请联系管理员";
|
|
|
}
|
|
|
|
|
@@ -261,6 +349,7 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
param.put("isSend", Dict.goodsProductIsSend.item_1.getItem());
|
|
|
param.put("sendTime", new Date());
|
|
|
param.put("omsAuditStatus", Dict.omsAuditStatus.item_0.getItem());
|
|
|
+ param.put("updateStatusMode", 1);
|
|
|
return goodsProductDao.updateStatusBySkuBatch(skuList, param);
|
|
|
}
|
|
|
|
|
@@ -270,6 +359,7 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
param.put("isSend", Dict.goodsProductIsSend.item_2.getItem());
|
|
|
param.put("sendTime", new Date());
|
|
|
param.put("omsAuditStatus", Dict.omsAuditStatus.item_0.getItem());
|
|
|
+ param.put("updateStatusMode", 1);
|
|
|
return goodsProductDao.updateStatusBySkuBatch(skuList, param);
|
|
|
}
|
|
|
|
|
@@ -280,26 +370,38 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
param.put("omsAuditRemark", auditRemark);
|
|
|
param.put("omsCallbackTime", new Date());
|
|
|
param.put("omsAuditTime", auditTime);
|
|
|
+ param.put("updateStatusMode", 2);
|
|
|
return goodsProductDao.updateStatusBySkuBatch(Arrays.asList(sku), param);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String pullFromOms() {
|
|
|
+ try {
|
|
|
|
|
|
- private ResponseMessage requestOmsProduct(List<GoodsProductDto> goodsProductDtoList){
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "同步产品备案信息失败,请联系管理员";
|
|
|
+ }
|
|
|
+ return "同步成功";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ResponseMessage requestOmsProduct(List<GoodsProductDto> goodsProductDtoList) {
|
|
|
Map<String, String> sParaTemp = new TreeMap<String, String>();
|
|
|
PdProductDtoInfo pdProductDtoInfo = new PdProductDtoInfo();
|
|
|
pdProductDtoInfo.setPdProductDtoList(goodsProductDtoList);
|
|
|
sParaTemp.put("data", JSON.toJSONString(pdProductDtoInfo));
|
|
|
LOGGER.info("请求omsdata数据:" + sParaTemp.get("data"));
|
|
|
- sParaTemp.put("merchId",omsMerchProperties.getMerchSn());
|
|
|
- String timestamp = String.valueOf(System.currentTimeMillis()/1000);
|
|
|
+ sParaTemp.put("merchId", omsMerchProperties.getMerchSn());
|
|
|
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
sParaTemp.put("timestamp", timestamp);
|
|
|
//生成要请求给oms秘钥
|
|
|
// String sign = OmsSign.sign(sParaTemp,cus.getWaybill().get("secret-key"));
|
|
|
LOGGER.info("md5混淆码参数:" + omsMerchProperties.getMd5Salt());
|
|
|
- String sign = OmsSign.sign(sParaTemp,omsMerchProperties.getMd5Salt());
|
|
|
+ String sign = OmsSign.sign(sParaTemp, omsMerchProperties.getMd5Salt());
|
|
|
sParaTemp.put("sign", sign);
|
|
|
//构建Request
|
|
|
- String url = omsMerchProperties.getAddPdProductListUrl();
|
|
|
+ String url = omsMerchProperties.getAddPdProductListUrl();
|
|
|
Request request = com.kmall.admin.utils.oms.OkHttpUtils.buildRequest(url, JSON.toJSONString(sParaTemp));
|
|
|
LOGGER.info("oms的请求报文:" + request);
|
|
|
// 同步访问,返回结果字符串
|
|
@@ -312,19 +414,19 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- LOGGER.info("oms的响应报文"+responseString);
|
|
|
+ LOGGER.info("oms的响应报文" + responseString);
|
|
|
//解析响应数据
|
|
|
Gson gson = new Gson();
|
|
|
ResponseMessage result = gson.fromJson(responseString, ResponseMessage.class);
|
|
|
- if(result == null){
|
|
|
+ if (result == null) {
|
|
|
String info = "解析响应数据Result失败";
|
|
|
LOGGER.error("--- {}", info);
|
|
|
throw new RuntimeException(info);
|
|
|
}
|
|
|
- return result;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- private void rollbackHandler(List<GoodsProductDto> goodsProductDtoList, boolean pass){
|
|
|
+ private void callbackHandler(List<GoodsProductDto> goodsProductDtoList, boolean pass) {
|
|
|
List<String> skuList = goodsProductDtoList.stream().map(GoodsProductDto::getSku).collect(Collectors.toList());
|
|
|
if (pass) {
|
|
|
this.updateSendOmsPassStatus(skuList);
|
|
@@ -334,5 +436,4 @@ public class GoodsProductServiceImpl implements GoodsProductService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|