|
|
@@ -25,7 +25,6 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
@@ -36,6 +35,7 @@ import org.springblade.salesPart.brand.mapper.BrandDescMapper;
|
|
|
import org.springblade.salesPart.corps.service.ICorpsDescService;
|
|
|
import org.springblade.salesPart.entity.*;
|
|
|
import org.springblade.salesPart.excel.GoodsExcel;
|
|
|
+import org.springblade.salesPart.excel.GoodsPointsExcel;
|
|
|
import org.springblade.salesPart.goods.mapper.GoodsDescMapper;
|
|
|
import org.springblade.salesPart.goods.mapper.GoodsTypeDescMapper;
|
|
|
import org.springblade.salesPart.goods.mapper.GoodsTypeMapper;
|
|
|
@@ -172,10 +172,10 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, PjGoodsDe
|
|
|
goodsDesc.setEnableOrNot(1);
|
|
|
baseMapper.insert(goodsDesc);
|
|
|
} else {
|
|
|
- if (count.stream().filter(e-> !e.getId().equals(goodsDesc.getId())).count() > 1) {
|
|
|
+ if (count.stream().filter(e -> !e.getId().equals(goodsDesc.getId())).count() > 1) {
|
|
|
throw new ServiceException("编码已存在");
|
|
|
}
|
|
|
- if (countName.stream().filter(e-> !e.getId().equals(goodsDesc.getId())).count() > 1) {
|
|
|
+ if (countName.stream().filter(e -> !e.getId().equals(goodsDesc.getId())).count() > 1) {
|
|
|
throw new ServiceException("名称已存在");
|
|
|
}
|
|
|
if (1 == goodsDesc.getEnableOrNot()) {
|
|
|
@@ -463,7 +463,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, PjGoodsDe
|
|
|
goodsDesc.setOriginalFactory(e.getOriginalFactory());
|
|
|
goodsDesc.setSelfRecovery(e.getSelfRecovery());
|
|
|
goodsDesc.setGoodsSize(e.getGoodsSize());
|
|
|
- if(ObjectUtils.isNotNull(e.getGoodIds())){
|
|
|
+ if (ObjectUtils.isNotNull(e.getGoodIds())) {
|
|
|
BigDecimal balanceQuantity = stockDescList.stream().filter(item -> item.getCname().equals(e.getCname()))
|
|
|
.map(PjStockDesc::getBalanceQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if (balanceQuantity.compareTo(new BigDecimal("0")) != 0) {
|
|
|
@@ -473,7 +473,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, PjGoodsDe
|
|
|
goodsDesc.setUpdateTime(new Date());
|
|
|
goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
goodsDesc.setId(Long.parseLong(e.getGoodIds()));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
PjGoodsDesc one = goodsDescList.stream().filter(i -> i.getCname().equals(e.getCname())).findFirst().orElse(null);
|
|
|
if (one == null) {
|
|
|
if (count > 0) {
|
|
|
@@ -604,7 +604,209 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, PjGoodsDe
|
|
|
|
|
|
@Override
|
|
|
public List<PjGoodsDesc> selectGoodsList(String tenantId, String goodsIds) {
|
|
|
- return baseMapper.selectListNotTenantId(tenantId,goodsIds);
|
|
|
+ return baseMapper.selectListNotTenantId(tenantId, goodsIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R importDescPoints(List<GoodsPointsExcel> data, boolean b) {
|
|
|
+ if (CollectionUtils.isEmpty(data)) {
|
|
|
+ throw new SecurityException("导入数据不能为空");
|
|
|
+ }
|
|
|
+ for (GoodsPointsExcel e : data) {
|
|
|
+ e.setCname(e.getCname().trim());
|
|
|
+ e.setCode(e.getCode().trim());
|
|
|
+ e.setSpecificationAndModel(e.getSpecificationAndModel().trim());
|
|
|
+ }
|
|
|
+ String goodsTypeNames = data.stream().map(GoodsPointsExcel::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(GoodsPointsExcel::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(GoodsPointsExcel::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(GoodsPointsExcel::getCname).distinct().filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ List<PjGoodsDesc> goodsDescList = baseMapper.selectList(new LambdaQueryWrapper<PjGoodsDesc>()
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjGoodsDesc::getWhetherIntegral, 1)
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply("find_in_set(cname,'" + goodsNames + "')"));
|
|
|
+ String salesCompanyNames = data.stream().map(GoodsPointsExcel::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();
|
|
|
+ }
|
|
|
+ List<Dept> finalDeptList = deptList;
|
|
|
+ List<String> cnameList = data.stream().map(GoodsPointsExcel::getCname).distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (cnameList.size() != data.size()) {
|
|
|
+ throw new RuntimeException("商品名称存在重复");
|
|
|
+ }
|
|
|
+ List<String> codeList = data.stream().map(GoodsPointsExcel::getCode).distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ if (codeList.size() != data.size()) {
|
|
|
+ throw new RuntimeException("商品编号存在重复");
|
|
|
+ }
|
|
|
+ String cnames = String.join(",", cnameList);
|
|
|
+ List<PjStockDesc> stockDescList = stockDescService.list(new LambdaQueryWrapper<PjStockDesc>()
|
|
|
+ .eq(PjStockDesc::getIsDeleted, 0)
|
|
|
+ .eq(PjStockDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .apply("find_in_set(cname,'" + cnames + "')"));
|
|
|
+ int q = 0;
|
|
|
+ List<PjGoodsDesc> pjGoodsDescList = new ArrayList<>();
|
|
|
+ for (GoodsPointsExcel 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.getSalesCompanyName())) {
|
|
|
+ throw new RuntimeException("所属公司名称不能为空");
|
|
|
+ }
|
|
|
+ q++;
|
|
|
+ Integer count = baseMapper.selectCount(Wrappers.<PjGoodsDesc>lambdaQuery()
|
|
|
+ .eq(PjGoodsDesc::getCode, e.getCode())
|
|
|
+ .eq(PjGoodsDesc::getWhetherIntegral, 1)
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+ Integer countName = baseMapper.selectCount(Wrappers.<PjGoodsDesc>lambdaQuery()
|
|
|
+ .eq(PjGoodsDesc::getCname, e.getCname())
|
|
|
+ .eq(PjGoodsDesc::getWhetherIntegral, 1)
|
|
|
+ .eq(PjGoodsDesc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjGoodsDesc::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+ 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);
|
|
|
+ goodsDesc.setWhetherIntegral("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.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())) {
|
|
|
+ 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("请输入正确的所属公司");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new SecurityException("请输入所属公司");
|
|
|
+ }
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(e.getCname()));
|
|
|
+ goodsDesc.setGoodsDescription(e.getGoodsDescription());
|
|
|
+ goodsDesc.setWhether("0");
|
|
|
+ if (ObjectUtils.isNotNull(e.getGoodIds())) {
|
|
|
+ BigDecimal balanceQuantity = stockDescList.stream().filter(item -> item.getCname().equals(e.getCname()))
|
|
|
+ .map(PjStockDesc::getBalanceQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (balanceQuantity.compareTo(new BigDecimal("0")) != 0) {
|
|
|
+ goodsDesc.setWhether(null);
|
|
|
+ }
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(goodsDesc.getCname()));
|
|
|
+ goodsDesc.setUpdateTime(new Date());
|
|
|
+ goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ goodsDesc.setId(Long.parseLong(e.getGoodIds()));
|
|
|
+ } else {
|
|
|
+ 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() + "编码已存在");
|
|
|
+ }
|
|
|
+ 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() + "名称已存在");
|
|
|
+ }
|
|
|
+ BigDecimal balanceQuantity = stockDescList.stream().filter(item -> item.getCname().equals(e.getCname()))
|
|
|
+ .map(PjStockDesc::getBalanceQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (balanceQuantity.compareTo(new BigDecimal("0")) != 0) {
|
|
|
+ goodsDesc.setWhether(null);
|
|
|
+ }
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(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("导入成功,请及时同步商品信息");
|
|
|
}
|
|
|
|
|
|
/**
|