|
|
@@ -17,7 +17,6 @@
|
|
|
package org.springblade.client.goods.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
@@ -33,21 +32,19 @@ import org.springblade.client.goods.mapper.*;
|
|
|
import org.springblade.client.goods.service.IGoodsDescService;
|
|
|
import org.springblade.client.vo.GoodsDescVO;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
-import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 商品详情表 服务实现类
|
|
|
@@ -58,8 +55,14 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc> implements IGoodsDescService {
|
|
|
- private GoodsTypeDescServiceImpl goodsTypeDescService; //商品-商品类别对应表
|
|
|
- private GoodsTypeServiceImpl goodsTypeService;//商品类别信息
|
|
|
+ /**
|
|
|
+ * 商品-商品类别对应表
|
|
|
+ */
|
|
|
+ private final GoodsTypeDescServiceImpl goodsTypeDescService;
|
|
|
+ /**
|
|
|
+ * 商品类别信息
|
|
|
+ */
|
|
|
+ private final GoodsTypeServiceImpl goodsTypeService;
|
|
|
private final GoodsTypeMapper goodsTypeMapper;
|
|
|
private final GoodsDescMapper goodsDescMapper;
|
|
|
private final GoodsPriceMapper goodsPriceMapper;
|
|
|
@@ -72,16 +75,16 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
|
|
|
@Override
|
|
|
public IPage<GoodsDescVO> selectGoodsDescPage(IPage<GoodsDescVO> page, GoodsDescVO goodsDesc) {
|
|
|
- //获取类别及子类别
|
|
|
- if (StringUtils.isNotBlank(goodsDesc.getGoodsTypeId())){
|
|
|
+ // 获取类别及子类别
|
|
|
+ if (StringUtils.isNotBlank(goodsDesc.getGoodsTypeId())) {
|
|
|
List<Long> longList = goodsTypeService.goodTypeIdList(goodsDesc.getGoodsTypeId());
|
|
|
goodsDesc.setGoodsTypeIdList(longList);
|
|
|
}
|
|
|
- return page.setRecords(baseMapper.selectGoodsDescPage(page, goodsDesc,AuthUtil.getTenantId()));
|
|
|
+ return page.setRecords(baseMapper.selectGoodsDescPage(page, goodsDesc, AuthUtil.getTenantId()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public GoodsDesc saveMessage(GoodsDesc goodsDesc) {
|
|
|
if (goodsDesc.getId() == null) {
|
|
|
goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
@@ -105,10 +108,10 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
* @param goodsTypeId
|
|
|
*/
|
|
|
public void saveType(Long goodId, String goodsTypeId) {
|
|
|
- goodsTypeDescService.remove(new QueryWrapper<GoodsTypeDesc>().eq("goods_id", goodId));
|
|
|
+ goodsTypeDescService.remove(new LambdaQueryWrapper<GoodsTypeDesc>().eq(GoodsTypeDesc::getGoodsId, goodId));
|
|
|
if (StringUtils.isNotBlank(goodsTypeId)) {
|
|
|
List<String> list = Arrays.asList(goodsTypeId.split(","));
|
|
|
- list.stream().forEach(item -> {
|
|
|
+ list.forEach(item -> {
|
|
|
GoodsTypeDesc goodsTypeDesc = new GoodsTypeDesc();
|
|
|
goodsTypeDesc.setTenantId(SecureUtil.getTenantId());
|
|
|
goodsTypeDesc.setCreateDept(Long.valueOf(SecureUtil.getDeptId()));
|
|
|
@@ -123,9 +126,9 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
|
|
|
@Override
|
|
|
public GoodsDesc getMessageById(GoodsDesc goodsDesc) {
|
|
|
- //获取商品详情
|
|
|
+ // 获取商品详情
|
|
|
GoodsDesc desc = baseMapper.selectById(goodsDesc.getId());
|
|
|
- //获取商品类别
|
|
|
+ // 获取商品类别
|
|
|
List<String> list = goodsTypeDescService.selectTypeId(goodsDesc.getId());
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
desc.setGoodsTypeId(String.join(",", list));
|
|
|
@@ -145,7 +148,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
.eq(GoodsDesc::getType, goodsDesc.getType())
|
|
|
.eq(GoodsDesc::getCode, goodsDesc.getCode())
|
|
|
.eq(GoodsDesc::getTenantId, goodsDesc.getTenantId())
|
|
|
- .eq(GoodsDesc::getIsDeleted,0)
|
|
|
+ .eq(GoodsDesc::getIsDeleted, 0)
|
|
|
);
|
|
|
if (count > 0) {
|
|
|
throw new ServiceException("名称已存在");
|
|
|
@@ -164,7 +167,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
.eq(GoodsDesc::getType, goodsDesc.getType())
|
|
|
.eq(GoodsDesc::getCname, goodsDesc.getCname())
|
|
|
.eq(GoodsDesc::getTenantId, goodsDesc.getTenantId())
|
|
|
- .eq(GoodsDesc::getIsDeleted,0)
|
|
|
+ .eq(GoodsDesc::getIsDeleted, 0)
|
|
|
);
|
|
|
if (count > 0) {
|
|
|
throw new ServiceException("名称已存在");
|
|
|
@@ -182,66 +185,61 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
- public void modify(GoodsDesc goodsDesc)
|
|
|
- {
|
|
|
- LambdaQueryWrapper<GoodsDesc> lambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(GoodsDesc::getType,0);
|
|
|
- lambdaQueryWrapper.eq(GoodsDesc::getIsDeleted,0);
|
|
|
- lambdaQueryWrapper.eq(GoodsDesc::getCode,goodsDesc.getCode());
|
|
|
- lambdaQueryWrapper.eq(GoodsDesc::getCname,goodsDesc.getCname());
|
|
|
- lambdaQueryWrapper.eq(GoodsDesc::getTenantId,AuthUtil.getTenantId());
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void modify(GoodsDesc goodsDesc) {
|
|
|
+ LambdaQueryWrapper<GoodsDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(GoodsDesc::getType, 0);
|
|
|
+ lambdaQueryWrapper.eq(GoodsDesc::getIsDeleted, 0);
|
|
|
+ lambdaQueryWrapper.eq(GoodsDesc::getCode, goodsDesc.getCode());
|
|
|
+ lambdaQueryWrapper.eq(GoodsDesc::getCname, goodsDesc.getCname());
|
|
|
+ lambdaQueryWrapper.eq(GoodsDesc::getTenantId, AuthUtil.getTenantId());
|
|
|
GoodsDesc selectOne = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
- if(selectOne != null && goodsDesc.getId() == null) {
|
|
|
+
|
|
|
+ if (selectOne != null && goodsDesc.getId() == null) {
|
|
|
throw new ServiceException("存在重复数据,请修改后添加");
|
|
|
- }else if (selectOne != null && goodsDesc.getId().longValue() != selectOne.getId().longValue()){
|
|
|
+ } else if (selectOne != null && goodsDesc.getId().longValue() != selectOne.getId().longValue()) {
|
|
|
throw new ServiceException("存在重复数据,请修改后添加");
|
|
|
}
|
|
|
|
|
|
List<GoodsFiles> filesList = goodsDesc.getFilesList();
|
|
|
- List<GoodsPrice> chilList=new ArrayList<>();
|
|
|
- if(CollectionUtils.isNotEmpty(goodsDesc.getBuyGoodsPrice()))
|
|
|
- {
|
|
|
+ List<GoodsPrice> chilList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsDesc.getBuyGoodsPrice())) {
|
|
|
chilList.addAll(goodsDesc.getBuyGoodsPrice());
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(goodsDesc.getSaleGoodsPrice()))
|
|
|
- {
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsDesc.getSaleGoodsPrice())) {
|
|
|
chilList.addAll(goodsDesc.getSaleGoodsPrice());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
Long id = goodsDesc.getId();
|
|
|
- //代表主表、子表都是新增,
|
|
|
- if(id==null)
|
|
|
- {
|
|
|
+ // 代表主表、子表都是新增,
|
|
|
+ if (id == null) {
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(goodsDesc.getCname()));
|
|
|
goodsDesc.setTenantId(AuthUtil.getTenantId());
|
|
|
goodsDesc.setCreateTime(new Date());
|
|
|
goodsDesc.setCreateUser(SecureUtil.getUserId());
|
|
|
- goodsDescMapper.insert(goodsDesc);
|
|
|
- if(!CollectionUtils.isEmpty(chilList))
|
|
|
- {
|
|
|
- chilList.forEach(e->{
|
|
|
- e.setTenantId(AuthUtil.getTenantId());
|
|
|
- e.setPid(goodsDesc.getId());
|
|
|
- e.setCreateTime(new Date());
|
|
|
- e.setCreateUser(SecureUtil.getUserId());
|
|
|
- goodsPriceMapper.insert(e);
|
|
|
- });
|
|
|
- }
|
|
|
- //文件上传
|
|
|
- if(!CollectionUtils.isEmpty(filesList))
|
|
|
- {
|
|
|
- filesList.forEach(k->{
|
|
|
- k.setTenantId(AuthUtil.getTenantId());
|
|
|
- k.setPid(goodsDesc.getId());
|
|
|
- k.setCreateTime(new Date());
|
|
|
- k.setCreateUser(SecureUtil.getUserId());
|
|
|
- goodsFilesMapper.insert(k);
|
|
|
- });
|
|
|
- }
|
|
|
- //商品规格明细
|
|
|
- if (CollectionUtils.isNotEmpty(goodsDesc.getGoodsSpecificationList())){
|
|
|
- goodsDesc.getGoodsSpecificationList().forEach( f->{
|
|
|
+ goodsDescMapper.insert(goodsDesc);
|
|
|
+ if (!CollectionUtils.isEmpty(chilList)) {
|
|
|
+ chilList.forEach(e -> {
|
|
|
+ e.setTenantId(AuthUtil.getTenantId());
|
|
|
+ e.setPid(goodsDesc.getId());
|
|
|
+ e.setCreateTime(new Date());
|
|
|
+ e.setCreateUser(SecureUtil.getUserId());
|
|
|
+ goodsPriceMapper.insert(e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 文件上传
|
|
|
+ if (!CollectionUtils.isEmpty(filesList)) {
|
|
|
+ filesList.forEach(k -> {
|
|
|
+ k.setTenantId(AuthUtil.getTenantId());
|
|
|
+ k.setPid(goodsDesc.getId());
|
|
|
+ k.setCreateTime(new Date());
|
|
|
+ k.setCreateUser(SecureUtil.getUserId());
|
|
|
+ goodsFilesMapper.insert(k);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 商品规格明细
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsDesc.getGoodsSpecificationList())) {
|
|
|
+ goodsDesc.getGoodsSpecificationList().forEach(f -> {
|
|
|
f.setTenantId(AuthUtil.getTenantId());
|
|
|
f.setPid(goodsDesc.getId());
|
|
|
f.setCreateTime(new Date());
|
|
|
@@ -249,30 +247,24 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
goodsSpecificationMapper.insert(f);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
- //主表修改,子表看情况
|
|
|
- else
|
|
|
- {
|
|
|
+ // 主表修改,子表看情况
|
|
|
+ else {
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(goodsDesc.getCname()));
|
|
|
goodsDescMapper.updateById(goodsDesc);
|
|
|
- //价格列表
|
|
|
- if(CollectionUtils.isNotEmpty(chilList))
|
|
|
- {
|
|
|
- chilList.forEach(e->{
|
|
|
- //新增
|
|
|
- if(e.getId()==null)
|
|
|
- {
|
|
|
+ // 价格列表
|
|
|
+ if (CollectionUtils.isNotEmpty(chilList)) {
|
|
|
+ chilList.forEach(e -> {
|
|
|
+ // 新增
|
|
|
+ if (e.getId() == null) {
|
|
|
e.setTenantId(AuthUtil.getTenantId());
|
|
|
e.setPid(goodsDesc.getId());
|
|
|
e.setCreateTime(new Date());
|
|
|
e.setCreateUser(SecureUtil.getUserId());
|
|
|
goodsPriceMapper.insert(e);
|
|
|
}
|
|
|
- //修改
|
|
|
- else
|
|
|
- {
|
|
|
+ // 修改
|
|
|
+ else {
|
|
|
e.setUpdateTime(new Date());
|
|
|
e.setUpdateUser(SecureUtil.getUserId());
|
|
|
goodsPriceMapper.updateById(e);
|
|
|
@@ -280,39 +272,35 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- //文件列表
|
|
|
- if(CollectionUtils.isNotEmpty(filesList))
|
|
|
- {
|
|
|
- filesList.forEach(k->{
|
|
|
- //新增
|
|
|
- if(k.getId()==null)
|
|
|
- {
|
|
|
+ // 文件列表
|
|
|
+ if (CollectionUtils.isNotEmpty(filesList)) {
|
|
|
+ filesList.forEach(k -> {
|
|
|
+ // 新增
|
|
|
+ if (k.getId() == null) {
|
|
|
k.setTenantId(AuthUtil.getTenantId());
|
|
|
k.setPid(goodsDesc.getId());
|
|
|
k.setCreateTime(new Date());
|
|
|
k.setCreateUser(SecureUtil.getUserId());
|
|
|
goodsFilesMapper.insert(k);
|
|
|
}
|
|
|
- //修改
|
|
|
- else
|
|
|
- {
|
|
|
+ // 修改
|
|
|
+ else {
|
|
|
k.setUpdateTime(new Date());
|
|
|
k.setUpdateUser(SecureUtil.getUserId());
|
|
|
goodsFilesMapper.updateById(k);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- //商品规格明细
|
|
|
- if (CollectionUtils.isNotEmpty(goodsDesc.getGoodsSpecificationList())){
|
|
|
- goodsDesc.getGoodsSpecificationList().forEach( f->{
|
|
|
- if (f.getId() == null){
|
|
|
+ // 商品规格明细
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsDesc.getGoodsSpecificationList())) {
|
|
|
+ goodsDesc.getGoodsSpecificationList().forEach(f -> {
|
|
|
+ if (f.getId() == null) {
|
|
|
f.setTenantId(AuthUtil.getTenantId());
|
|
|
f.setPid(goodsDesc.getId());
|
|
|
f.setCreateTime(new Date());
|
|
|
f.setCreateUser(SecureUtil.getUserId());
|
|
|
goodsSpecificationMapper.insert(f);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
f.setUpdateTime(new Date());
|
|
|
f.setUpdateUser(SecureUtil.getUserId());
|
|
|
goodsSpecificationMapper.updateById(f);
|
|
|
@@ -324,110 +312,84 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R importGoods(List<GoodsExcel> data, Boolean isCovered)
|
|
|
- {
|
|
|
+ public R importGoods(List<GoodsExcel> data, Boolean isCovered) {
|
|
|
|
|
|
- if(org.springframework.util.CollectionUtils.isEmpty(data))
|
|
|
- {
|
|
|
- throw new SecurityException("导入数据不能为空");
|
|
|
- }
|
|
|
- StringBuffer errMsg= new StringBuffer();
|
|
|
-
|
|
|
- for(int i=0;i<data.size();i++)
|
|
|
- {
|
|
|
- GoodsExcel goodsExcel = data.get(i);
|
|
|
- String type = goodsExcel.getType();
|
|
|
- GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
- if(goodsType==null)
|
|
|
- {
|
|
|
- errMsg.append("第"+i+"行未添加分类或者分类不存在,");
|
|
|
- }
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(data)) {
|
|
|
+ throw new SecurityException("导入数据不能为空");
|
|
|
+ }
|
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ GoodsExcel goodsExcel = data.get(i);
|
|
|
+ String type = goodsExcel.getType();
|
|
|
+ GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
+ if (goodsType == null) {
|
|
|
+ throw new SecurityException("第" + (i + 1) + "行未添加分类或者分类不存在");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- data.forEach(e->{
|
|
|
- String type = e.getType();
|
|
|
- GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
- if(goodsType!=null)
|
|
|
- {
|
|
|
- GoodsDesc goodsDesc=new GoodsDesc();
|
|
|
- goodsDesc.setCode(e.getCode());
|
|
|
- goodsDesc.setCname(e.getCname());
|
|
|
- goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
- goodsDesc.setBrand(e.getBrand());
|
|
|
- goodsDesc.setTypeno(e.getTypeNo());
|
|
|
- goodsDesc.setSpecsOne(e.getSpecsOne());
|
|
|
- goodsDesc.setLevel(e.getLevel());
|
|
|
- goodsDesc.setLevelOne(e.getLevelOne());
|
|
|
- goodsDesc.setMasterUnit(e.getMasterUnit());
|
|
|
- goodsDesc.setSlaveUnit(e.getSlaveUnit());
|
|
|
- goodsDesc.setSwapRate(e.getSwapRate());
|
|
|
- goodsDesc.setTinyNumber(e.getTinyNumber());
|
|
|
- goodsDesc.setTax(e.getTax());
|
|
|
- goodsDesc.setPrice(e.getPrice());
|
|
|
- goodsDesc.setEffectiveDay(e.getEffectiveDay());
|
|
|
- goodsDesc.setPlaceProduction(e.getPlaceProduction());
|
|
|
- goodsDesc.setCompany(e.getCompany());
|
|
|
- goodsDesc.setRemarks(e.getRemarks());
|
|
|
- goodsDesc.setType(0L);
|
|
|
- goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
- //获取供应商
|
|
|
- /*CorpsDesc corpsDesc = new CorpsDesc();
|
|
|
- corpsDesc.setCname(e.getCorpName());
|
|
|
- corpsDesc.setCorpType("GYS");*/
|
|
|
- CorpsDesc corpByName = corpsDescClient.getCorpsDesc(e.getCorpName(),"GYS");
|
|
|
- if (corpByName != null){
|
|
|
- goodsDesc.setCorpId(corpByName.getId());
|
|
|
- goodsDesc.setCorpName(corpByName.getCname());
|
|
|
- }
|
|
|
- //如果名称相等 就认为重复
|
|
|
- LambdaQueryWrapper<GoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(GoodsDesc::getTenantId,AuthUtil.getTenantId());
|
|
|
- queryWrapper.eq(GoodsDesc::getCname,goodsDesc.getCname());
|
|
|
- queryWrapper.eq(GoodsDesc::getIsDeleted,0);
|
|
|
- GoodsDesc one = goodsDescMapper.selectOne(queryWrapper);
|
|
|
- if(one==null)
|
|
|
- {
|
|
|
- goodsDesc.setCreateTime(new Date());
|
|
|
- goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- goodsDescMapper.insert(goodsDesc);
|
|
|
-
|
|
|
- GoodsTypeDesc goodsTypeDes=new GoodsTypeDesc();
|
|
|
- goodsTypeDes.setGoodsId(goodsDesc.getId());
|
|
|
- goodsTypeDes.setGoodsTypeId(goodsType.getId());
|
|
|
- goodsTypeDes.setCreateTime(new Date());
|
|
|
- goodsTypeDes.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsTypeDes.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- goodsTypeDescMapper.insert(goodsTypeDes);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- goodsDesc.setId(one.getId());
|
|
|
- goodsDesc.setUpdateTime(new Date());
|
|
|
- goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
- goodsDescMapper.updateById(goodsDesc);
|
|
|
- }
|
|
|
+ data.forEach(e -> {
|
|
|
+ String type = e.getType();
|
|
|
+ GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
+ if (goodsType != null) {
|
|
|
+ GoodsDesc goodsDesc = new GoodsDesc();
|
|
|
+ goodsDesc.setCode(e.getCode());
|
|
|
+ goodsDesc.setCname(e.getCname());
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(goodsDesc.getCname()));
|
|
|
+ goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
+ goodsDesc.setBrand(e.getBrand());
|
|
|
+ goodsDesc.setTypeno(e.getTypeNo());
|
|
|
+ goodsDesc.setSpecsOne(e.getSpecsOne());
|
|
|
+ goodsDesc.setLevel(e.getLevel());
|
|
|
+ goodsDesc.setLevelOne(e.getLevelOne());
|
|
|
+ goodsDesc.setMasterUnit(e.getMasterUnit());
|
|
|
+ goodsDesc.setSlaveUnit(e.getSlaveUnit());
|
|
|
+ goodsDesc.setSwapRate(e.getSwapRate());
|
|
|
+ goodsDesc.setTinyNumber(e.getTinyNumber());
|
|
|
+ goodsDesc.setTax(e.getTax());
|
|
|
+ goodsDesc.setPrice(e.getPrice());
|
|
|
+ goodsDesc.setEffectiveDay(e.getEffectiveDay());
|
|
|
+ goodsDesc.setPlaceProduction(e.getPlaceProduction());
|
|
|
+ goodsDesc.setCompany(e.getCompany());
|
|
|
+ goodsDesc.setRemarks(e.getRemarks());
|
|
|
+ goodsDesc.setType(0L);
|
|
|
+ goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
+ // 获取供应商
|
|
|
+ /*CorpsDesc corpsDesc = new CorpsDesc();
|
|
|
+ corpsDesc.setCname(e.getCorpName());
|
|
|
+ corpsDesc.setCorpType("GYS");*/
|
|
|
+ CorpsDesc corpByName = corpsDescClient.getCorpsDesc(e.getCorpName(), "GYS");
|
|
|
+ if (corpByName != null) {
|
|
|
+ goodsDesc.setCorpId(corpByName.getId());
|
|
|
+ goodsDesc.setCorpName(corpByName.getCname());
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ // 如果名称相等 就认为重复
|
|
|
+ LambdaQueryWrapper<GoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(GoodsDesc::getTenantId, AuthUtil.getTenantId());
|
|
|
+ queryWrapper.eq(GoodsDesc::getCname, goodsDesc.getCname());
|
|
|
+ queryWrapper.eq(GoodsDesc::getIsDeleted, 0);
|
|
|
+ GoodsDesc one = goodsDescMapper.selectOne(queryWrapper);
|
|
|
+ if (one == null) {
|
|
|
+ goodsDesc.setCreateTime(new Date());
|
|
|
+ goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
+ goodsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ goodsDescMapper.insert(goodsDesc);
|
|
|
|
|
|
+ GoodsTypeDesc goodsTypeDes = new GoodsTypeDesc();
|
|
|
+ goodsTypeDes.setGoodsId(goodsDesc.getId());
|
|
|
+ goodsTypeDes.setGoodsTypeId(goodsType.getId());
|
|
|
+ goodsTypeDes.setCreateTime(new Date());
|
|
|
+ goodsTypeDes.setCreateUser(AuthUtil.getUserId());
|
|
|
+ goodsTypeDes.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ goodsTypeDescMapper.insert(goodsTypeDes);
|
|
|
+ } else {
|
|
|
+ goodsDesc.setId(one.getId());
|
|
|
+ goodsDesc.setUpdateTime(new Date());
|
|
|
+ goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ goodsDescMapper.updateById(goodsDesc);
|
|
|
}
|
|
|
- });
|
|
|
- /* List<Boolean> booleanList = countList.stream().filter(e -> e == true).collect(Collectors.toList());
|
|
|
- if(data.size()>booleanList.size())
|
|
|
- {
|
|
|
- return R.fail("导入中的数据,分类字段不存在或者未填分类字段");
|
|
|
- }
|
|
|
- else if(data.size()==booleanList.size())
|
|
|
- {
|
|
|
- return R.success("导入成功");
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- throw new SecurityException("导入失败,请仔细检查导入数据");
|
|
|
- }*/
|
|
|
- return R.success("ok");
|
|
|
+ });
|
|
|
+ return R.success("ok");
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -436,14 +398,13 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
if (org.springframework.util.CollectionUtils.isEmpty(data)) {
|
|
|
throw new SecurityException("导入数据不能为空");
|
|
|
}
|
|
|
- StringBuffer errMsg = new StringBuffer();
|
|
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
GoodsInfoExcel goodsExcel = data.get(i);
|
|
|
String type = goodsExcel.getType();
|
|
|
GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
if (goodsType == null) {
|
|
|
- errMsg.append("第" + i + "行未添加分类或者分类不存在,");
|
|
|
+ throw new SecurityException("第" + (i + 1) + "行未添加分类或者分类不存在");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -453,6 +414,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
if (goodsType != null) {
|
|
|
GoodsDesc goodsDesc = new GoodsDesc();
|
|
|
BeanUtils.copyProperties(e, goodsDesc);
|
|
|
+ goodsDesc.setCnameInt(getCnameInt(goodsDesc.getCname()));
|
|
|
|
|
|
R<CorpsDesc> corpByName = corpsDescClient.getCorpByName(e.getCorpName(), AuthUtil.getTenantId());
|
|
|
if (corpByName.isSuccess() && corpByName.getData() != null) {
|
|
|
@@ -475,7 +437,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //获取供应商
|
|
|
+ // 获取供应商
|
|
|
goodsDesc.setTypeno(e.getTypeNo());
|
|
|
goodsDesc.setCntrVolumn(e.getCntrVolumn());
|
|
|
goodsDesc.setCartonWeight(e.getCartonWeight());
|
|
|
@@ -483,7 +445,7 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
goodsDesc.setSize(e.getSize());
|
|
|
goodsDesc.setType(0L);
|
|
|
goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
- //如果名称相等 就认为重复
|
|
|
+ // 如果名称相等 就认为重复
|
|
|
LambdaQueryWrapper<GoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(GoodsDesc::getTenantId, AuthUtil.getTenantId());
|
|
|
queryWrapper.eq(GoodsDesc::getCode, goodsDesc.getCode());
|
|
|
@@ -516,4 +478,11 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
return R.success("ok");
|
|
|
}
|
|
|
|
|
|
+ private String getCnameInt(String cname) {
|
|
|
+ String regex = "[^0-9]";
|
|
|
+ Pattern p = Pattern.compile(regex);
|
|
|
+ Matcher m = p.matcher(cname);
|
|
|
+ return m.replaceAll("").trim();
|
|
|
+ }
|
|
|
+
|
|
|
}
|