|
|
@@ -50,12 +50,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 配件批发商品表 服务实现类
|
|
|
@@ -299,138 +297,187 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, PjGoodsDe
|
|
|
if (CollectionUtils.isEmpty(data)) {
|
|
|
throw new SecurityException("导入数据不能为空");
|
|
|
}
|
|
|
-
|
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
- GoodsExcel goodsExcel = data.get(i);
|
|
|
- String type = goodsExcel.getGoodsTypeName();
|
|
|
- PjGoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
- if (goodsType == null) {
|
|
|
- throw new SecurityException("第" + (i + 2) + "行未添加分类或者分类不存在");
|
|
|
- }
|
|
|
+ String goodsTypeNames = data.stream().map(GoodsExcel::getGoodsTypeName).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<PjGoodsType> goodsTypeList = goodsTypeMapper.selectList(new LambdaQueryWrapper<PjGoodsType>()
|
|
|
+ .eq(PjGoodsType::getIsDeleted, 0)
|
|
|
+ .eq(PjGoodsType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply("find_in_set(cname,'" + goodsTypeNames + "')"));
|
|
|
+ String brands = data.stream().map(GoodsExcel::getBrand).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<PjBrandDesc> brandDescList = brandDescMapper.selectList(new LambdaQueryWrapper<PjBrandDesc>()
|
|
|
+ .eq(PjBrandDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjBrandDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply("find_in_set(cname,'" + brands + "')"));
|
|
|
+ String corpNames = data.stream().map(GoodsExcel::getCorpName).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<PjCorpsDesc> corpsDescList = corpsDescService.list(new LambdaQueryWrapper<PjCorpsDesc>()
|
|
|
+ .eq(PjCorpsDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsDesc::getCorpType, "GYS")
|
|
|
+ .apply("find_in_set(cname,'" + corpNames + "')"));
|
|
|
+ String goodsNames = data.stream().map(GoodsExcel::getCname).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<PjGoodsDesc> goodsDescList = baseMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply("find_in_set(cname,'" + goodsNames + "')"));
|
|
|
+ String salesCompanyNames = data.stream().map(GoodsExcel::getSalesCompanyName).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<Dept> deptList = new ArrayList<>();
|
|
|
+ R<List<Dept>> res = iSysClient.getDeptListIByName(AuthUtil.getTenantId(), salesCompanyNames);
|
|
|
+ if (res.isSuccess()) {
|
|
|
+ deptList = res.getData();
|
|
|
}
|
|
|
- data.forEach(e -> {
|
|
|
+ List<Dept> finalDeptList = deptList;
|
|
|
+ int q = 0;
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = new ArrayList<>();
|
|
|
+ for (GoodsExcel e : data) {
|
|
|
+ if (ObjectUtils.isNull(e.getCname())) {
|
|
|
+ throw new RuntimeException("商品名称不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getCode())) {
|
|
|
+ throw new RuntimeException("商品编码不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getGoodsTypeName())) {
|
|
|
+ throw new RuntimeException("商品分类不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getUnit())) {
|
|
|
+ throw new RuntimeException("计量单位不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getBrand())) {
|
|
|
+ throw new RuntimeException("品牌不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getSpecificationAndModel())) {
|
|
|
+ throw new RuntimeException("规格型号不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getBrandItem())) {
|
|
|
+ throw new RuntimeException("花纹不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getGoodsSize())) {
|
|
|
+ throw new RuntimeException("尺寸不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getSalesCompanyName())) {
|
|
|
+ throw new RuntimeException("所属公司名称不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(e.getWhether())) {
|
|
|
+ throw new RuntimeException("是否管理批次号不能为空");
|
|
|
+ }
|
|
|
+ q++;
|
|
|
Integer count = baseMapper.selectCount(Wrappers.<PjGoodsDesc>lambdaQuery()
|
|
|
.eq(PjGoodsDesc::getCode, e.getCode())
|
|
|
.eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
);
|
|
|
-
|
|
|
Integer countName = baseMapper.selectCount(Wrappers.<PjGoodsDesc>lambdaQuery()
|
|
|
.eq(PjGoodsDesc::getCname, e.getCname())
|
|
|
.eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
);
|
|
|
- String type = e.getGoodsTypeName();
|
|
|
- PjGoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
- if (goodsType != null) {
|
|
|
- PjGoodsDesc goodsDesc = new PjGoodsDesc();
|
|
|
- goodsDesc.setCode(e.getCode());
|
|
|
- goodsDesc.setCname(e.getCname());
|
|
|
- goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
- goodsDesc.setGoodsTypeName(e.getGoodsTypeName());
|
|
|
- goodsDesc.setUnit(e.getUnit());
|
|
|
- goodsDesc.setEnableOrNot(1);
|
|
|
-
|
|
|
- //获得品牌
|
|
|
- if (ObjectUtils.isNotNull(e.getBrand())) {
|
|
|
- PjBrandDesc brandDesc = brandDescMapper.selectOne(new LambdaQueryWrapper<PjBrandDesc>()
|
|
|
- .eq(PjBrandDesc::getIsDeleted, 0)
|
|
|
- .eq(PjBrandDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(PjBrandDesc::getCname, e.getBrand()));
|
|
|
-
|
|
|
- if (ObjectUtils.isNotNull(brandDesc)) {
|
|
|
- goodsDesc.setBrandId(brandDesc.getId());
|
|
|
- goodsDesc.setBrandName(e.getBrand());
|
|
|
- } else {
|
|
|
- throw new RuntimeException("品牌名称错误或品牌不存在");
|
|
|
- }
|
|
|
+ PjGoodsType goodsType = goodsTypeList.stream().filter(i -> i.getCname().equals(e.getGoodsTypeName())).findFirst().orElse(null);
|
|
|
+ if (goodsType == null) {
|
|
|
+ throw new SecurityException("第" + (q + 1) + "行未添加分类或者分类不存在");
|
|
|
+ }
|
|
|
+ PjGoodsDesc goodsDesc = new PjGoodsDesc();
|
|
|
+ goodsDesc.setCode(e.getCode());
|
|
|
+ goodsDesc.setCname(e.getCname());
|
|
|
+ goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
+ goodsDesc.setGoodsTypeName(e.getGoodsTypeName());
|
|
|
+ goodsDesc.setUnit(e.getUnit());
|
|
|
+ goodsDesc.setEnableOrNot(1);
|
|
|
+
|
|
|
+ //获得品牌
|
|
|
+ if (ObjectUtils.isNotNull(e.getBrand())) {
|
|
|
+ PjBrandDesc brandDesc = brandDescList.stream().filter(i -> i.getCname().equals(e.getBrand()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (brandDesc != null) {
|
|
|
+ goodsDesc.setBrandId(brandDesc.getId());
|
|
|
+ goodsDesc.setBrandName(e.getBrand());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("品牌名称错误或品牌不存在");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- goodsDesc.setSpecificationAndModel(e.getSpecificationAndModel());
|
|
|
- goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
- goodsDesc.setPlaceProduction(e.getPlaceProduction());
|
|
|
-
|
|
|
- // 获取供应商
|
|
|
- if (ObjectUtils.isNotNull(e.getCorpName())) {
|
|
|
- PjCorpsDesc corpByName = corpsDescService.getCorpsDesc(e.getCorpName(), "GYS");
|
|
|
- if (corpByName != null) {
|
|
|
- goodsDesc.setCorpId(corpByName.getId());
|
|
|
- goodsDesc.setCorpName(corpByName.getCname());
|
|
|
- } else {
|
|
|
- throw new RuntimeException("供应商" + e.getCorpName() + "不存在");
|
|
|
- }
|
|
|
+ goodsDesc.setSpecificationAndModel(e.getSpecificationAndModel());
|
|
|
+ goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
+ goodsDesc.setPlaceProduction(e.getPlaceProduction());
|
|
|
+
|
|
|
+ // 获取供应商
|
|
|
+ if (ObjectUtils.isNotNull(e.getCorpName())) {
|
|
|
+ PjCorpsDesc corpByName = corpsDescList.stream().filter(i -> i.getCname().equals(e.getCorpName()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (corpByName != null) {
|
|
|
+ goodsDesc.setCorpId(corpByName.getId());
|
|
|
+ goodsDesc.setCorpName(corpByName.getCname());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("供应商" + e.getCorpName() + "不存在");
|
|
|
}
|
|
|
- //获得所属公司
|
|
|
- if (StringUtil.isNotBlank(e.getSalesCompanyName())) {
|
|
|
- R<Dept> dept = iSysClient.getDeptIByName(AuthUtil.getTenantId(), e.getSalesCompanyName());
|
|
|
- if (dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())) {
|
|
|
- goodsDesc.setSalesCompanyId(dept.getData().getId());
|
|
|
- goodsDesc.setSalesCompanyName(dept.getData().getFullName());
|
|
|
- } else {
|
|
|
- throw new SecurityException("请输入正确的所属公司");
|
|
|
- }
|
|
|
+ }
|
|
|
+ //获得所属公司
|
|
|
+ if (StringUtil.isNotBlank(e.getSalesCompanyName())) {
|
|
|
+ Dept dept = finalDeptList.stream().filter(i -> i.getFullName().equals(e.getSalesCompanyName())).findFirst().orElse(null);
|
|
|
+ if (dept != null) {
|
|
|
+ goodsDesc.setSalesCompanyId(dept.getId());
|
|
|
+ goodsDesc.setSalesCompanyName(dept.getFullName());
|
|
|
} else {
|
|
|
- throw new SecurityException("请输入所属公司");
|
|
|
+ throw new SecurityException("请输入正确的所属公司");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ throw new SecurityException("请输入所属公司");
|
|
|
+ }
|
|
|
|
|
|
+ goodsDesc.setCnameInt(e.getCnameInt());
|
|
|
+ if (StringUtils.isNotBlank(e.getCnameInt())) {
|
|
|
goodsDesc.setCnameInt(e.getCnameInt());
|
|
|
- if (StringUtils.isNotBlank(e.getCnameInt())) {
|
|
|
- goodsDesc.setCnameInt(e.getCnameInt());
|
|
|
- } else {
|
|
|
- goodsDesc.setCnameInt(getCnameInt(e.getCname()));
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(e.getCname()));
|
|
|
+ }
|
|
|
|
|
|
- goodsDesc.setGoodsDescription(e.getGoodsDescription());
|
|
|
- if (ObjectUtils.isNotNull(e.getWhether()) && ("1".equals(e.getWhether()) || "0".equals(e.getWhether()))) {
|
|
|
- goodsDesc.setWhether(e.getWhether());
|
|
|
- } else {
|
|
|
- goodsDesc.setWhether("0");
|
|
|
+ goodsDesc.setGoodsDescription(e.getGoodsDescription());
|
|
|
+ if (ObjectUtils.isNotNull(e.getWhether()) && ("1".equals(e.getWhether()) || "0".equals(e.getWhether()))) {
|
|
|
+ goodsDesc.setWhether(e.getWhether());
|
|
|
+ } else {
|
|
|
+ goodsDesc.setWhether("0");
|
|
|
+ }
|
|
|
+ goodsDesc.setInventoryAlert(e.getInventoryAlert());
|
|
|
+ goodsDesc.setExplosionProof(e.getExplosionProof());
|
|
|
+ goodsDesc.setOriginalFactory(e.getOriginalFactory());
|
|
|
+ goodsDesc.setSelfRecovery(e.getSelfRecovery());
|
|
|
+ goodsDesc.setGoodsSize(e.getGoodsSize());
|
|
|
+ PjGoodsDesc one = goodsDescList.stream().filter(i -> i.getCname().equals(e.getCname())).findFirst().orElse(null);
|
|
|
+ if (one == null) {
|
|
|
+ if (count > 0) {
|
|
|
+ throw new ServiceException(goodsDesc.getCode() + "编码已存在");
|
|
|
}
|
|
|
- goodsDesc.setInventoryAlert(e.getInventoryAlert());
|
|
|
- goodsDesc.setExplosionProof(e.getExplosionProof());
|
|
|
- goodsDesc.setOriginalFactory(e.getOriginalFactory());
|
|
|
- goodsDesc.setSelfRecovery(e.getSelfRecovery());
|
|
|
- goodsDesc.setGoodsSize(e.getGoodsSize());
|
|
|
- // 如果名称相等 就认为重复
|
|
|
- LambdaQueryWrapper<PjGoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId());
|
|
|
- queryWrapper.eq(PjGoodsDesc::getCname, goodsDesc.getCname());
|
|
|
- queryWrapper.eq(PjGoodsDesc::getIsDeleted, 0);
|
|
|
- PjGoodsDesc one = baseMapper.selectOne(queryWrapper);
|
|
|
- if (one == null) {
|
|
|
- if (count > 0) {
|
|
|
- throw new ServiceException(goodsDesc.getCode() + "编码已存在");
|
|
|
- }
|
|
|
- if (countName > 0) {
|
|
|
- throw new ServiceException(goodsDesc.getCname() + "名称已存在");
|
|
|
- }
|
|
|
- goodsDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
- goodsDesc.setCreateTime(new Date());
|
|
|
- goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- baseMapper.insert(goodsDesc);
|
|
|
-
|
|
|
- PjGoodsTypeDesc goodsTypeDes = new PjGoodsTypeDesc();
|
|
|
- goodsTypeDes.setGoodsId(goodsDesc.getId());
|
|
|
- goodsTypeDes.setGoodsTypeId(goodsType.getId());
|
|
|
- goodsTypeDes.setCreateTime(new Date());
|
|
|
- goodsTypeDes.setTenantId(AuthUtil.getTenantId());
|
|
|
- goodsTypeDes.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsTypeDes.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- goodsTypeDescMapper.insert(goodsTypeDes);
|
|
|
- } else {
|
|
|
- if (count > 1) {
|
|
|
- throw new ServiceException(goodsDesc.getCode() + "编码已存在");
|
|
|
- }
|
|
|
- if (countName > 1) {
|
|
|
- throw new ServiceException(goodsDesc.getCname() + "名称已存在");
|
|
|
- }
|
|
|
- goodsDesc.setUpdateTime(new Date());
|
|
|
- goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
- baseMapper.updateById(goodsDesc);
|
|
|
+ if (countName > 0) {
|
|
|
+ throw new ServiceException(goodsDesc.getCname() + "名称已存在");
|
|
|
+ }
|
|
|
+ goodsDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
+ goodsDesc.setCreateTime(new Date());
|
|
|
+ goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
+ goodsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ } else {
|
|
|
+ if (count > 1) {
|
|
|
+ throw new ServiceException(goodsDesc.getCode() + "编码已存在");
|
|
|
+ }
|
|
|
+ if (countName > 1) {
|
|
|
+ throw new ServiceException(goodsDesc.getCname() + "名称已存在");
|
|
|
}
|
|
|
+ goodsDesc.setUpdateTime(new Date());
|
|
|
+ goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ goodsDesc.setId(one.getId());
|
|
|
}
|
|
|
- });
|
|
|
+ pjGoodsDescList.add(goodsDesc);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(pjGoodsDescList);
|
|
|
+ for (PjGoodsDesc e : pjGoodsDescList) {
|
|
|
+ PjGoodsDesc one = goodsDescList.stream().filter(i -> i.getCname().equals(e.getCname())).findFirst().orElse(null);
|
|
|
+ if (one == null) {
|
|
|
+ PjGoodsTypeDesc goodsTypeDes = new PjGoodsTypeDesc();
|
|
|
+ goodsTypeDes.setGoodsId(e.getId());
|
|
|
+ goodsTypeDes.setGoodsTypeId(Long.valueOf(e.getGoodsTypeId()));
|
|
|
+ goodsTypeDes.setCreateTime(new Date());
|
|
|
+ goodsTypeDes.setTenantId(AuthUtil.getTenantId());
|
|
|
+ goodsTypeDes.setCreateUser(AuthUtil.getUserId());
|
|
|
+ goodsTypeDes.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ goodsTypeDescMapper.insert(goodsTypeDes);
|
|
|
+ }
|
|
|
+ }
|
|
|
return R.success("ok");
|
|
|
}
|
|
|
|