|
@@ -1098,6 +1098,288 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
+ public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
|
|
|
+ SysUserEntity user = ShiroUtils.getUserEntity();
|
|
|
+ String merchSn = user.getMerchSn();
|
|
|
+ boolean isFail = false;
|
|
|
+ List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
|
|
|
+ failSuppGoodsSnList = new ArrayList<>(),
|
|
|
+ failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
|
|
|
+ failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
|
|
|
+ failMerchUserGoodsSnList = new ArrayList<>();
|
|
|
+// List<String> failGoodsSnList = new ArrayList<>();
|
|
|
+ List<String> failGoodsTypeList = new ArrayList<>();
|
|
|
+ if (goodsEntityList != null && goodsEntityList.size() > 0) {
|
|
|
+ for (int i = 0; i < goodsEntityList.size(); i++) {
|
|
|
+ GoodsDto goodsDto = goodsEntityList.get(i);
|
|
|
+ GoodsEntity goodsEntity = new GoodsEntity();
|
|
|
+ Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
|
|
|
+ ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
|
|
|
+ builder.put("goodsSn", "商品编码");
|
|
|
+ builder.put("thirdPartyMerchCode", "第三方商户代码");
|
|
|
+ builder.put("goodsBizType", "货品业务类型");
|
|
|
+ builder.put("name", "商品名称");
|
|
|
+ builder.put("isOnSaleStr", "上架");
|
|
|
+ builder.put("goodsUnit", "商品单位");
|
|
|
+ builder.put("isHotStr", "热销");
|
|
|
+ builder.put("prodBarcode", "产品条码");
|
|
|
+ builder.put("supplierName", "供应商");
|
|
|
+ builder.put("goodsNumber", "商品总库存");
|
|
|
+ R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ } else {
|
|
|
+ if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
|
|
|
+ // 海关信息,普通货物可不添加
|
|
|
+ builder.put("goodsRate", "商品税率");
|
|
|
+ builder.put("sku", "SKU");
|
|
|
+ builder.put("brand", "产品品牌");
|
|
|
+ builder.put("unitName", "计量单位");
|
|
|
+ builder.put("oriCntName", "原产国");
|
|
|
+ builder.put("cusGoodsCode", "海关商品编码");
|
|
|
+ builder.put("ciqProdModel", "国检规格型号");
|
|
|
+ builder.put("cusDeclEle", "海关申报要素");
|
|
|
+ builder.put("cusRecCode", "海关备案编号");
|
|
|
+ }
|
|
|
+ r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //业务类型校验
|
|
|
+ if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
|
|
|
+ if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
|
|
|
+ || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
|
|
|
+ || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
|
|
|
+ isFail = true;
|
|
|
+ failTypeGoodsSnList.add(goodsDto.getSku());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
|
|
|
+ if(thirdMerchantBizEntity != null){
|
|
|
+ goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
|
|
|
+ goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
|
|
|
+
|
|
|
+ if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
|
|
|
+ if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
|
|
|
+ isFail = true;
|
|
|
+ failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{//商户不存在
|
|
|
+ isFail = true;
|
|
|
+ failMerchGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验商品信息是否已存在
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("isSame", "true");
|
|
|
+ map.put("sku", goodsDto.getSku());
|
|
|
+ map.put("goodsSn", goodsDto.getGoodsSn());
|
|
|
+ map.put("goodsBizType", goodsDto.getGoodsBizType());
|
|
|
+// List<GoodsEntity> list = querySame(map);
|
|
|
+// if (list != null && list.size() != 0) {
|
|
|
+// isFail = true;
|
|
|
+// if(goodsDto.getSku()!=null) {
|
|
|
+// failSameSkuList.add(goodsDto.getSku());
|
|
|
+// }
|
|
|
+// failGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+// failGoodsTypeList.add(goodsDto.getGoodsBizType());
|
|
|
+// }
|
|
|
+ //校验产品条码是否存在
|
|
|
+ goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
|
|
|
+ //热销商品校验
|
|
|
+ if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
|
|
|
+ || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
|
|
|
+ if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
|
|
|
+ isFail = true;
|
|
|
+ failHotGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(thirdMerchantBizEntity != null) {
|
|
|
+ SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
|
|
|
+ if (supplierEntity == null) {
|
|
|
+ //导入没有查到供货商,执行新增
|
|
|
+ MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
|
|
|
+ if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
|
|
|
+ isFail = true;
|
|
|
+ failSuppGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ }
|
|
|
+
|
|
|
+ supplierEntity = new SupplierEntity();
|
|
|
+ supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
|
|
|
+ supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
|
|
|
+ supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
|
|
|
+ supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
|
|
|
+ supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
|
|
|
+ supplierEntity.setIsShow("0");
|
|
|
+
|
|
|
+ supplierDao.save(supplierEntity);
|
|
|
+ goodsEntity.setSupplierId(supplierEntity.getId());
|
|
|
+ } else {
|
|
|
+ goodsEntity.setSupplierId(supplierEntity.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
|
|
|
+ SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
|
|
|
+ if (sysCusUnitCodeEntity == null) {
|
|
|
+ isFail = true;
|
|
|
+ failUnitGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ } else {
|
|
|
+ goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
|
|
|
+ }
|
|
|
+ //原产国
|
|
|
+ SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
|
|
|
+ if (sysCusNationCodeEntity == null) {
|
|
|
+ isFail = true;
|
|
|
+ failNationGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
+ } else {
|
|
|
+ goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(goodsDto.getGoodsRate().indexOf("%") != -1){
|
|
|
+ goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+
|
|
|
+ goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
|
|
|
+ goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
|
|
|
+ goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
|
|
|
+ goodsEntity.setSku(goodsDto.getSku());
|
|
|
+ goodsEntity.setName(goodsDto.getName());
|
|
|
+ goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
|
|
|
+ goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
|
|
|
+ goodsEntity.setBrand(goodsDto.getBrand());
|
|
|
+ goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
|
|
|
+ goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
|
|
|
+ goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
|
|
|
+ goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
|
|
|
+ goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
|
|
|
+ goodsEntity.setIsNew(0);
|
|
|
+ goodsEntity.setUpdateUserId(user.getUserId());
|
|
|
+ goodsEntity.setAddTime(new Date());
|
|
|
+ goodsEntity.setCreateTime(new Date());
|
|
|
+ goodsEntity.setUpdateTime(new Date());
|
|
|
+ goodsEntity.setModTime(new Date());
|
|
|
+ goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
|
|
|
+
|
|
|
+ if(!isFail){
|
|
|
+ GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
|
|
|
+ if(goods!=null) {// 修改商品
|
|
|
+ goodsEntity.setId(goods.getId());
|
|
|
+ goodsEntity.setVideoUrl(goods.getVideoUrl());
|
|
|
+ goodsEntity.setListPicUrl(goods.getListPicUrl());
|
|
|
+ goodsEntity.setPrimaryPicUrl(goods.getPrimaryPicUrl());
|
|
|
+ goodsDao.update(goodsEntity);
|
|
|
+ }else{
|
|
|
+ goodsDao.save(goodsEntity);
|
|
|
+ }
|
|
|
+ // 修改产品
|
|
|
+ ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
|
|
|
+
|
|
|
+ GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
|
|
|
+ // 普通货物暂不添加商品规格
|
|
|
+ if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
|
|
|
+ // 添加商品规格
|
|
|
+ GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
|
|
|
+ if(specificationEntity == null) {
|
|
|
+ goodsSpecification.setGoodsId(goodsEntity.getId());
|
|
|
+ goodsSpecification.setValue(goodsEntity.getCiqProdModel());
|
|
|
+ goodsSpecification.setSpecificationId(1);
|
|
|
+ goodsSpecificationDao.save(goodsSpecification);
|
|
|
+ }else {
|
|
|
+ goodsSpecification.setValue(goodsDto.getCiqProdModel());
|
|
|
+ goodsSpecification.setId(specificationEntity.getId());
|
|
|
+ goodsSpecificationDao.update(goodsSpecification);
|
|
|
+ }
|
|
|
+ if(product == null){
|
|
|
+ product = new ProductEntity();
|
|
|
+ product.setGoodsSn(goodsDto.getGoodsSn());
|
|
|
+ product.setGoodsId(goodsEntity.getId());
|
|
|
+ product.setGoodsDefault(0);
|
|
|
+ product.setGoodsNumber(goodsEntity.getGoodsNumber());
|
|
|
+ product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
|
|
|
+ product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
+ productDao.save(product);
|
|
|
+ }else{
|
|
|
+ product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
+ product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
|
|
|
+ productDao.update(product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
|
|
|
+ exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
|
|
|
+ exportExceptionDataEntity.setUserId(user.getUserId().intValue());
|
|
|
+ exportExceptionDataEntity.setCreateTime(new Date());
|
|
|
+ exportExceptionDataEntity.setModTime(new Date());
|
|
|
+ exportExceptionDataEntity.setMerchSn(merchSn);
|
|
|
+ exportExceptionDataEntity.setStoreId(user.getStoreId());
|
|
|
+ if(exportDataType == 1) {
|
|
|
+ exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
|
|
|
+ }else{
|
|
|
+ exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+// if(failGoodsSnList != null && failGoodsSnList.size() > 0){
|
|
|
+// if(failSameSkuList.size()>0) {
|
|
|
+// exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
|
|
|
+// failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
|
|
|
+// goodsUtils.save(exportExceptionDataEntity);
|
|
|
+// throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+// }else{
|
|
|
+// exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
|
|
|
+// failGoodsTypeList + "】的商品信息");
|
|
|
+// goodsUtils.save(exportExceptionDataEntity);
|
|
|
+// throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+// }
|
|
|
+// }
|
|
|
+ if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
|
|
|
+ exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
|
|
|
+ goodsUtils.save(exportExceptionDataEntity);
|
|
|
+ throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId) {
|
|
|
return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
|
|
|
}
|