|
|
@ -7,6 +7,7 @@ import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.oms.biz.func.basebrandinfo.BaseBrandInfo; |
|
|
|
import com.yxt.oms.biz.func.basegoodssku.BaseGoodsSkuDto; |
|
|
|
import com.yxt.oms.biz.func.basegoodssku.BaseGoodsSkuVo; |
|
|
|
import com.yxt.oms.biz.func.basegoodsskuextend.BaseGoodsSkuExtendDto; |
|
|
|
import com.yxt.oms.biz.func.basegoodsspudetail.BaseGoodsSpuDetailDto; |
|
|
|
import com.yxt.oms.biz.func.basegoodstype.BaseGoodsType; |
|
|
@ -15,12 +16,14 @@ import com.yxt.oms.biz.func.basemanufacturer.BaseManufacturer; |
|
|
|
import com.yxt.oms.biz.func.commonmethod.CommonMethod; |
|
|
|
import com.yxt.oms.biz.func.commonmethod.DataRule; |
|
|
|
import com.yxt.oms.feign.goods.basebrandinfo.BaseBrandInfoFeign; |
|
|
|
import com.yxt.oms.feign.goods.basegoodssku.BaseGoodsSkuFeign; |
|
|
|
import com.yxt.oms.feign.goods.basegoodsspu.*; |
|
|
|
import com.yxt.oms.feign.goods.basegoodstype.BaseGoodsTypeFeign; |
|
|
|
import com.yxt.oms.feign.goods.basegoodsunit.BaseGoodsUnitFeign; |
|
|
|
import com.yxt.oms.feign.goods.basemanufacturer.BaseManufacturerFeign; |
|
|
|
import com.yxt.oms.feign.goods.basegoodsspu.BaseGoodsSpuFeign; |
|
|
|
import com.yxt.oms.utils.ExcelUtil; |
|
|
|
import com.yxt.oms.utils.OrgPathQuery; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -59,6 +62,8 @@ public class BaseGoodsSpuService extends MybatisBaseService<BaseGoodsSpuMapper, |
|
|
|
BaseGoodsSpuFeign baseGoodsSpuFeign; |
|
|
|
@Autowired |
|
|
|
CommonMethod commonMethod; |
|
|
|
@Autowired |
|
|
|
BaseGoodsSkuFeign baseGoodsSkuFeign; |
|
|
|
|
|
|
|
|
|
|
|
public ResultBean<PagerVo<BaseGoodsSpuVo>> listPage(PagerQuery<BaseGoodsSpuQuery> pq) { |
|
|
@ -128,85 +133,183 @@ public class BaseGoodsSpuService extends MybatisBaseService<BaseGoodsSpuMapper, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean importExcel(MultipartFile file) throws IOException { |
|
|
|
// return baseGoodsSpuFeign.importExcel(file);
|
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
//檢查excel
|
|
|
|
ExcelUtil.checkFile(file); |
|
|
|
//解析excel
|
|
|
|
List<String[]> list = ExcelUtil.readExcel(file); |
|
|
|
if (!list.isEmpty()) { |
|
|
|
List tt = new ArrayList(); |
|
|
|
List<BaseGoodsSpuDto> tt1 = new ArrayList(); |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
BaseGoodsSpuDto dto =new BaseGoodsSpuDto(); |
|
|
|
String taxRate = StringUtils.isEmpty(list.get(i)[10]) ? null : list.get(i)[10]; |
|
|
|
if(StringUtils.isNotBlank(taxRate)){ |
|
|
|
if(!taxRate.contains(".")){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率格式不正确!"); |
|
|
|
} |
|
|
|
if(taxRate.length()>4){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率长度不正确!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
dto = this.packaging(list.get(i),dto); |
|
|
|
if (null == dto) { |
|
|
|
return rb.setMsg("导入失败,第" + (i + 1) + "行数据错误!"); |
|
|
|
} else { |
|
|
|
tt.add(dto); |
|
|
|
} |
|
|
|
public ResultBean importExcel(MultipartFile file, String orgPath) throws IOException { |
|
|
|
// return baseGoodsSpuFeign.importExcel(file);
|
|
|
|
ResultBean rb = new ResultBean().fail(); |
|
|
|
//檢查excel
|
|
|
|
ExcelUtil.checkFile(file); |
|
|
|
//解析excel
|
|
|
|
List<String[]> list = ExcelUtil.readExcel(file); |
|
|
|
OrgPathQuery q = new OrgPathQuery(); |
|
|
|
q.setOrgPath(orgPath); |
|
|
|
List<BaseGoodsSkuVo> vos1 = baseGoodsSkuFeign.listAllByOrg(q).getData(); |
|
|
|
if (!list.isEmpty()) { |
|
|
|
List<BaseGoodsSpuDto> tt = new ArrayList(); |
|
|
|
List<BaseGoodsImportVo> list1 = new ArrayList<>(); |
|
|
|
List<BaseGoodsSpuDto> tt1 = new ArrayList(); |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
BaseGoodsSpuDto dto = new BaseGoodsSpuDto(); |
|
|
|
String spuCode = StringUtils.isEmpty(list.get(i)[0]) ? null : list.get(i)[0]; |
|
|
|
if (StringUtils.isBlank(spuCode)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "商品编码为空!"); |
|
|
|
} |
|
|
|
tt1=a(tt); |
|
|
|
for (BaseGoodsSpuDto baseGoodsSpuDto : tt1) { |
|
|
|
String goodsTypeSid = StringUtils.isEmpty(baseGoodsSpuDto.getGoodsTypeSid()) ? null : baseGoodsSpuDto.getGoodsTypeSid(); |
|
|
|
if (StringUtils.isNotBlank(goodsTypeSid)) { |
|
|
|
BaseGoodsType baseGoodsType = baseGoodsTypeFeign.getTypeByName(goodsTypeSid).getData(); |
|
|
|
if (null != baseGoodsType) { |
|
|
|
baseGoodsSpuDto.setGoodsTypeSid(baseGoodsType.getSid()); |
|
|
|
} else { |
|
|
|
return rb.setMsg("商品分类:" + goodsTypeSid + "不存在,请先添加"); |
|
|
|
} |
|
|
|
String spuName = StringUtils.isEmpty(list.get(i)[2]) ? null : list.get(i)[2]; |
|
|
|
if (StringUtils.isBlank(spuName)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "商品名称为空!"); |
|
|
|
} |
|
|
|
String type = StringUtils.isEmpty(list.get(i)[6]) ? null : list.get(i)[6]; |
|
|
|
if (StringUtils.isBlank(type)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "商品分类为空!"); |
|
|
|
} |
|
|
|
String brand = StringUtils.isEmpty(list.get(i)[7]) ? null : list.get(i)[7]; |
|
|
|
if (StringUtils.isBlank(brand)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "品牌为空!"); |
|
|
|
} |
|
|
|
String cj = StringUtils.isEmpty(list.get(i)[8]) ? null : list.get(i)[8]; |
|
|
|
if (StringUtils.isBlank(cj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "厂家为空!"); |
|
|
|
} |
|
|
|
String unit = StringUtils.isEmpty(list.get(i)[9]) ? null : list.get(i)[9]; |
|
|
|
if (StringUtils.isBlank(unit)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "商品单位为空!"); |
|
|
|
} |
|
|
|
String taxRate = StringUtils.isEmpty(list.get(i)[10]) ? null : list.get(i)[10]; |
|
|
|
if (!isNumeric(taxRate)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率不是数字!"); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(taxRate)) { |
|
|
|
if (taxRate.contains("-")) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率不能为负数!"); |
|
|
|
} |
|
|
|
|
|
|
|
String brandSid = StringUtils.isEmpty(baseGoodsSpuDto.getBrandSid()) ? null : baseGoodsSpuDto.getBrandSid(); |
|
|
|
if (StringUtils.isNotBlank(brandSid)) { |
|
|
|
BaseBrandInfo brand = baseBrandInfoFeign.getBrandByName(brandSid).getData(); |
|
|
|
if (null != brand) { |
|
|
|
baseGoodsSpuDto.setBrandSid(brand.getSid()); |
|
|
|
} else { |
|
|
|
return rb.setMsg("商品品牌:" + brandSid + "不存在,请先添加"); |
|
|
|
} |
|
|
|
if (!taxRate.contains(".")) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率不是小数!"); |
|
|
|
} |
|
|
|
|
|
|
|
String manufacturerSid = StringUtils.isEmpty(baseGoodsSpuDto.getManufacturerSid()) ? null : baseGoodsSpuDto.getManufacturerSid(); |
|
|
|
if (StringUtils.isNotBlank(manufacturerSid)) { |
|
|
|
BaseManufacturer baseManufacturer = baseManufacturerFeign.getManufacturerByName(manufacturerSid).getData(); |
|
|
|
if (null != baseManufacturer) { |
|
|
|
baseGoodsSpuDto.setManufacturerSid(baseManufacturer.getSid()); |
|
|
|
} else { |
|
|
|
return rb.setMsg("商品厂家:" + manufacturerSid + "不存在,请先添加"); |
|
|
|
} |
|
|
|
if (taxRate.length() > 4) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率长度不正确!"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行税率为空!"); |
|
|
|
} |
|
|
|
String bzq = StringUtils.isEmpty(list.get(i)[11]) ? null : list.get(i)[11]; |
|
|
|
if (!isNumeric(bzq)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行保质期(天)不是数字!"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(bzq)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行保质期(天)为空!"); |
|
|
|
} |
|
|
|
String ggdm = StringUtils.isEmpty(list.get(i)[18]) ? null : list.get(i)[18]; |
|
|
|
boolean b=vos1.stream().anyMatch(o->o.getGoodsSkuCode().equals(ggdm)); |
|
|
|
if(b){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行规格代码已存在!"); |
|
|
|
} |
|
|
|
BaseGoodsImportVo vo = new BaseGoodsImportVo(); |
|
|
|
vo.setXh(String.valueOf(i + 1)); |
|
|
|
vo.setXpdm(ggdm); |
|
|
|
list1.add(vo); |
|
|
|
if (StringUtils.isBlank(ggdm)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行规格代码不正确!"); |
|
|
|
} |
|
|
|
String ggxh = StringUtils.isEmpty(list.get(i)[20]) ? null : list.get(i)[20]; |
|
|
|
if (StringUtils.isBlank(ggxh)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行规格型号为空!"); |
|
|
|
} |
|
|
|
String cgj = StringUtils.isEmpty(list.get(i)[21]) ? null : list.get(i)[21]; |
|
|
|
if (!isNumeric(cgj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行最后采购价不是数字!"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(cgj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行最后采购价为空!"); |
|
|
|
} |
|
|
|
String aqts = StringUtils.isEmpty(list.get(i)[22]) ? null : list.get(i)[22]; |
|
|
|
if (!isNumeric(aqts)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行库存安全天数不是数字!"); |
|
|
|
} |
|
|
|
String jjsx = StringUtils.isEmpty(list.get(i)[25]) ? null : list.get(i)[25]; |
|
|
|
if (!isNumeric(jjsx)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行库存警戒上线不是数字!"); |
|
|
|
} |
|
|
|
String jjxx = StringUtils.isEmpty(list.get(i)[26]) ? null : list.get(i)[26]; |
|
|
|
if (!isNumeric(jjxx)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行库存警戒下线不是数字!"); |
|
|
|
} |
|
|
|
String cbj = StringUtils.isEmpty(list.get(i)[27]) ? null : list.get(i)[27]; |
|
|
|
if (!isNumeric(cbj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行成本价不是数字!"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(cbj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行成本价为空!"); |
|
|
|
} |
|
|
|
String dpj = StringUtils.isEmpty(list.get(i)[28]) ? null : list.get(i)[28]; |
|
|
|
if (!isNumeric(dpj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行吊牌价不是数字!"); |
|
|
|
} |
|
|
|
String xsdj = StringUtils.isEmpty(list.get(i)[29]) ? null : list.get(i)[29]; |
|
|
|
if(!isNumeric(xsdj)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行销售单价不是数字!"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(xsdj)) { |
|
|
|
return rb.setMsg("第" + (i + 1) + "行销售单价为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
String goodsUnitSid = StringUtils.isEmpty(baseGoodsSpuDto.getGoodsUnitName()) ? null : baseGoodsSpuDto.getGoodsUnitName(); |
|
|
|
if (StringUtils.isNotBlank(goodsUnitSid)) { |
|
|
|
BaseGoodsUnit baseGoodsUnit = baseGoodsUnitFeign.getUnitByName(goodsUnitSid).getData(); |
|
|
|
if (null != baseGoodsUnit) { |
|
|
|
baseGoodsSpuDto.setGoodsUnitSid(baseGoodsUnit.getSid()); |
|
|
|
String bzjj = StringUtils.isEmpty(list.get(i)[30]) ? null : list.get(i)[30]; |
|
|
|
if(!isNumeric(bzjj)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行标准进价不是数字!"); |
|
|
|
} |
|
|
|
String dlj = StringUtils.isEmpty(list.get(i)[31]) ? null : list.get(i)[31]; |
|
|
|
if(!isNumeric(dlj)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行代理价不是数字!"); |
|
|
|
} |
|
|
|
String zk = StringUtils.isEmpty(list.get(i)[32]) ? null : list.get(i)[32]; |
|
|
|
if(!isNumeric(zk)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行折扣不是数字!"); |
|
|
|
} |
|
|
|
String zdls = StringUtils.isEmpty(list.get(i)[33]) ? null : list.get(i)[33]; |
|
|
|
if(!isNumeric(zdls)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行最低零售价不是数字!"); |
|
|
|
} |
|
|
|
String jf = StringUtils.isEmpty(list.get(i)[36]) ? null : list.get(i)[36]; |
|
|
|
if(!isNumeric(jf)){ |
|
|
|
return rb.setMsg("第" + (i + 1) + "行积分不是数字!"); |
|
|
|
} |
|
|
|
dto = this.packaging(list.get(i), dto); |
|
|
|
if (null == dto) { |
|
|
|
return rb.setMsg("导入失败,第" + (i + 1) + "行数据错误!"); |
|
|
|
} else { |
|
|
|
tt.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String, Long> nameCountMap = list1.stream() |
|
|
|
.collect(Collectors.groupingBy(BaseGoodsImportVo::getXpdm, Collectors.counting())); |
|
|
|
List<BaseGoodsImportVo> vos = list1.stream().filter(a -> nameCountMap.getOrDefault(a.getXpdm(), 0L) > 1).collect(Collectors.toList()); |
|
|
|
if (vos.size() != 0) { |
|
|
|
String a = ""; |
|
|
|
for (BaseGoodsImportVo vo : vos) { |
|
|
|
if (vo.getXpdm().equals(vos.get(0).getXpdm())) { |
|
|
|
if (StringUtils.isBlank(a)) { |
|
|
|
a = vo.getXh(); |
|
|
|
} else { |
|
|
|
return rb.setMsg("商品单位:" + goodsUnitSid + "不存在,请先添加"); |
|
|
|
a = a + "," + vo.getXh(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
baseGoodsSpuFeign.batchSave(tt1); |
|
|
|
return rb.success().setMsg("导入成功"); |
|
|
|
|
|
|
|
} else { |
|
|
|
return rb.setMsg("导入文件没有有效数据"); |
|
|
|
return rb.setMsg("导入失败,第" + a + "行规格代码数据重复!"); |
|
|
|
} |
|
|
|
tt1 = a(tt); |
|
|
|
return rb.success().setMsg("导入成功").setData(tt1); |
|
|
|
} else { |
|
|
|
return rb.setMsg("导入文件没有有效数据"); |
|
|
|
} |
|
|
|
} |
|
|
|
public ResultBean<String> batchSave(List<BaseGoodsSpuDto> dtos, String orgPath) { |
|
|
|
return baseGoodsSpuFeign.batchSave(dtos, orgPath); |
|
|
|
} |
|
|
|
public static boolean isNumeric(String strNum) { |
|
|
|
if (strNum == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return strNum.matches("-?\\d+(\\.\\d+)?"); |
|
|
|
} |
|
|
|
|
|
|
|
public List<BaseGoodsSpuDto> a(List<BaseGoodsSpuDto> dtos) { |
|
|
|
ResultBean rb=new ResultBean().fail(); |
|
|
|
List<BaseGoodsSpuDto> spus = new ArrayList<>();//spu list
|
|
|
|