|
|
@@ -37,6 +37,7 @@ 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.*;
|
|
|
|
|
|
/**
|
|
|
@@ -320,51 +321,66 @@ public class GoodsDescServiceImpl extends ServiceImpl<GoodsDescMapper, GoodsDesc
|
|
|
@Transactional
|
|
|
public void importGoods(List<GoodsExcel> data, Boolean isCovered)
|
|
|
{
|
|
|
- if(org.springframework.util.CollectionUtils.isEmpty(data))
|
|
|
- {
|
|
|
- throw new SecurityException("导入数据不能为空");
|
|
|
- }
|
|
|
- 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());
|
|
|
- //如果名称相等 就认为重复
|
|
|
- LambdaQueryWrapper<GoodsDesc> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(GoodsDesc::getCname,goodsDesc.getCname());
|
|
|
- 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);
|
|
|
- }
|
|
|
- else
|
|
|
+ try {
|
|
|
+ if(org.springframework.util.CollectionUtils.isEmpty(data))
|
|
|
{
|
|
|
- one.setUpdateTime(new Date());
|
|
|
- one.setUpdateUser(AuthUtil.getUserId());
|
|
|
- goodsDescMapper.updateById(one);
|
|
|
+ throw new SecurityException("导入数据不能为空");
|
|
|
}
|
|
|
- });
|
|
|
+ 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());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ goodsDesc.setId(one.getId());
|
|
|
+ goodsDesc.setUpdateTime(new Date());
|
|
|
+ goodsDesc.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ goodsDescMapper.updateById(goodsDesc);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new SecurityException("请仔细检查导入数据");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|