|
|
@@ -33,12 +33,14 @@ 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.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 商品详情表 服务实现类
|
|
|
@@ -319,68 +321,99 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void importGoods(List<GoodsExcel> data, Boolean isCovered)
|
|
|
+ public R importGoods(List<GoodsExcel> data, Boolean isCovered)
|
|
|
{
|
|
|
try {
|
|
|
if(org.springframework.util.CollectionUtils.isEmpty(data))
|
|
|
{
|
|
|
throw new SecurityException("导入数据不能为空");
|
|
|
}
|
|
|
+ //统计正确数据行数
|
|
|
+ List<Boolean> countList=new ArrayList<>();
|
|
|
+
|
|
|
data.forEach(e->{
|
|
|
- GoodsDesc goodsDesc=new GoodsDesc();
|
|
|
- goodsDesc.setCode(e.getCode());
|
|
|
- goodsDesc.setCname(e.getCname());
|
|
|
- goodsDesc.setTypeno(e.getTypeNo());
|
|
|
- goodsDesc.setBrand(e.getBrand());
|
|
|
- goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
- goodsDesc.setSpecs(e.getSpecs());
|
|
|
- goodsDesc.setType(0L);
|
|
|
- goodsDesc.setCategory(e.getCategory());
|
|
|
- goodsDesc.setCategoryitem(e.getCategoryitem());
|
|
|
- goodsDesc.setUnit(e.getUnit());
|
|
|
- goodsDesc.setPackgeunit(e.getPackgeunit());
|
|
|
- goodsDesc.setRemarks(e.getRemarks());
|
|
|
- goodsDesc.setGoodsTypeId(e.getTypeId());
|
|
|
- goodsDesc.setEname(e.getEname());
|
|
|
- goodsDesc.setNameDescription(e.getNameDescription());
|
|
|
- goodsDesc.setCnameDescription(e.getCnameDescription());
|
|
|
- goodsDesc.setCustomCode(e.getCustomCode());
|
|
|
- goodsDesc.setCustomName(e.getCustomName());
|
|
|
- goodsDesc.setCustomEname(e.getCustomEname());
|
|
|
- if(e.getCustomRate()!=null)
|
|
|
- {
|
|
|
- goodsDesc.setCustomRate(new BigDecimal(e.getCustomRate()));
|
|
|
- }
|
|
|
- //如果名称相等 就认为重复
|
|
|
- LambdaQueryWrapper<GoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(GoodsDesc::getCname,goodsDesc.getCname());
|
|
|
- queryWrapper.eq(GoodsDesc::getIsDeleted,0);
|
|
|
- GoodsDesc one = goodsDescMapper.selectOne(queryWrapper);
|
|
|
- if(one==null)
|
|
|
+ String type = e.getType();
|
|
|
+ GoodsType goodsType = goodsTypeMapper.selectGoodsTypeCname(type, AuthUtil.getTenantId());
|
|
|
+ if(goodsType!=null)
|
|
|
{
|
|
|
- goodsDesc.setCreateTime(new Date());
|
|
|
- goodsDesc.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsDesc.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- goodsDescMapper.insert(goodsDesc);
|
|
|
+ countList.add(true);
|
|
|
+ GoodsDesc goodsDesc=new GoodsDesc();
|
|
|
+ goodsDesc.setCode(e.getCode());
|
|
|
+ goodsDesc.setCname(e.getCname());
|
|
|
+ goodsDesc.setTypeno(e.getTypeNo());
|
|
|
+ goodsDesc.setBrand(e.getBrand());
|
|
|
+ goodsDesc.setBrandItem(e.getBrandItem());
|
|
|
+ goodsDesc.setSpecs(e.getSpecs());
|
|
|
+ goodsDesc.setType(0L);
|
|
|
+ goodsDesc.setCategory(e.getCategory());
|
|
|
+ goodsDesc.setCategoryitem(e.getCategoryitem());
|
|
|
+ goodsDesc.setUnit(e.getUnit());
|
|
|
+ goodsDesc.setPackgeunit(e.getPackgeunit());
|
|
|
+ goodsDesc.setRemarks(e.getRemarks());
|
|
|
+ goodsDesc.setGoodsTypeId(e.getTypeId());
|
|
|
+ goodsDesc.setEname(e.getEname());
|
|
|
+ goodsDesc.setNameDescription(e.getNameDescription());
|
|
|
+ goodsDesc.setCnameDescription(e.getCnameDescription());
|
|
|
+ goodsDesc.setCustomCode(e.getCustomCode());
|
|
|
+ goodsDesc.setCustomName(e.getCustomName());
|
|
|
+ goodsDesc.setCustomEname(e.getCustomEname());
|
|
|
+ goodsDesc.setGoodsTypeId(String.valueOf(goodsType.getId()));
|
|
|
+ if(e.getCustomRate()!=null)
|
|
|
+ {
|
|
|
+ goodsDesc.setCustomRate(new BigDecimal(e.getCustomRate()));
|
|
|
+ }
|
|
|
+ //如果名称相等 就认为重复
|
|
|
+ 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(Long.valueOf(e.getTypeId()));
|
|
|
- goodsTypeDes.setCreateTime(new Date());
|
|
|
- goodsTypeDes.setCreateUser(AuthUtil.getUserId());
|
|
|
- goodsTypeDes.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- goodsTypeDescMapper.insert(goodsTypeDes);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- goodsDesc.setId(one.getId());
|
|
|
- goodsDesc.setUpdateTime(new Date());
|
|
|
- goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
- goodsDescMapper.updateById(goodsDesc);
|
|
|
+ countList.add(false);
|
|
|
}
|
|
|
});
|
|
|
- } catch (Exception e) {
|
|
|
- throw new SecurityException("请仔细检查导入数据");
|
|
|
+ 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("导入失败,请仔细检查导入数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ throw new SecurityException("导入失败,请仔细检查导入数据");
|
|
|
}
|
|
|
}
|
|
|
|