优化商品导入,提高速度
This commit is contained in:
@@ -845,4 +845,8 @@ public class DepotItemService {
|
||||
public List<DepotItemVoBatchNumberList> getBatchNumberList(String name, Long depotId, String barCode, String batchNumber){
|
||||
return depotItemMapperEx.getBatchNumberList(name, depotId, barCode, batchNumber);
|
||||
}
|
||||
|
||||
public Long getCountByMaterialAndDepot(Long mId, Long depotId) {
|
||||
return depotItemMapperEx.getCountByMaterialAndDepot(mId, depotId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,9 +585,6 @@ public class MaterialService {
|
||||
mList.add(m);
|
||||
}
|
||||
}
|
||||
logService.insertLog("商品",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
Long mId = 0L;
|
||||
for(MaterialWithInitStock m: mList) {
|
||||
//判断该商品是否存在,如果不存在就新增,如果存在就更新
|
||||
@@ -596,7 +593,7 @@ public class MaterialService {
|
||||
if(materials.size()<=0) {
|
||||
materialMapper.insertSelective(m);
|
||||
List<Material> newList = getMaterialListByParam(m.getName(),m.getModel(),m.getColor(),m.getStandard(),m.getUnit(),m.getUnitId(), basicBarCode);
|
||||
if(newList!=null && newList.size()>0) {
|
||||
if(newList.size()>0) {
|
||||
mId = newList.get(0).getId();
|
||||
}
|
||||
} else {
|
||||
@@ -637,19 +634,23 @@ public class MaterialService {
|
||||
Map<Long, BigDecimal> stockMap = m.getStockMap();
|
||||
Long depotId = null;
|
||||
for(Depot depot: depotList){
|
||||
depotId = depot.getId();
|
||||
BigDecimal stock = stockMap.get(depot.getId());
|
||||
//初始库存-先清除再插入
|
||||
MaterialInitialStockExample example = new MaterialInitialStockExample();
|
||||
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(depot.getId());
|
||||
materialInitialStockMapper.deleteByExample(example);
|
||||
if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
|
||||
depotId = depot.getId();
|
||||
//新增初始库存
|
||||
insertInitialStockByMaterialAndDepot(depotId, mId, stock, null, null);
|
||||
//更新当前库存
|
||||
depotItemService.updateCurrentStockFun(mId, depotId);
|
||||
}
|
||||
//新增或更新当前库存
|
||||
insertOrUpdateCurrentStockByMaterialAndDepot(depotId, mId, stock);
|
||||
}
|
||||
}
|
||||
logService.insertLog("商品",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
info.code = 200;
|
||||
info.data = "导入成功";
|
||||
} catch (BusinessRunTimeException e) {
|
||||
@@ -761,6 +762,19 @@ public class MaterialService {
|
||||
materialInitialStockMapper.insertSelective(materialInitialStock); //存入初始库存
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前库存
|
||||
* @param depotId
|
||||
* @param mId
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void deleteCurrentStockByMaterialAndDepot(Long depotId, Long mId){
|
||||
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
|
||||
example.createCriteria().andDepotIdEqualTo(depotId).andMaterialIdEqualTo(mId)
|
||||
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
materialCurrentStockMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入当前库存
|
||||
* @param depotId
|
||||
@@ -776,6 +790,25 @@ public class MaterialService {
|
||||
materialCurrentStockMapper.insertSelective(materialCurrentStock); //存入初始库存
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或更新当前库存
|
||||
* @param depotId
|
||||
* @param mId
|
||||
* @param stock
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void insertOrUpdateCurrentStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock){
|
||||
Long billCount = depotItemService.getCountByMaterialAndDepot(mId, depotId);
|
||||
if(billCount == 0) {
|
||||
deleteCurrentStockByMaterialAndDepot(depotId, mId);
|
||||
if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
|
||||
insertCurrentStockByMaterialAndDepot(depotId, mId, stock);
|
||||
}
|
||||
} else {
|
||||
depotItemService.updateCurrentStockFun(mId, depotId);
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaterialVo4Unit> getMaterialEnableSerialNumberList(String q, Integer offset, Integer rows)throws Exception {
|
||||
List<MaterialVo4Unit> list =null;
|
||||
try{
|
||||
|
||||
Reference in New Issue
Block a user