优化商品导入,提高速度

This commit is contained in:
季圣华
2022-05-13 18:25:57 +08:00
parent 7ea99431dd
commit 4a51ea98b4
6 changed files with 62 additions and 16 deletions

View File

@@ -101,10 +101,10 @@ public class TenantConfig {
/**
* 性能分析拦截器,不建议生产使用
*/
@Bean
public PerformanceInterceptor performanceInterceptor(){
return new PerformanceInterceptor();
}
// @Bean
// public PerformanceInterceptor performanceInterceptor(){
// return new PerformanceInterceptor();
// }
}

View File

@@ -325,7 +325,7 @@ public class MaterialController {
StringUtil.toNull(standard), StringUtil.toNull(model), StringUtil.toNull(color), StringUtil.toNull(weight),
StringUtil.toNull(expiryNum), StringUtil.toNull(enableSerialNumber), StringUtil.toNull(enableBatchNumber),
StringUtil.toNull(remark), StringUtil.toNull(categoryId));
String[] names = {"条码", "名称", "规格", "型号", "颜色", "类别", "扩展信息", "单位", "基础重量", "保质期", "采购价", "售价", "售价", "最低售价", "备注", "状态", "序列号", "批号"};
String[] names = {"条码", "名称", "规格", "型号", "颜色", "类别", "扩展信息", "单位", "基础重量", "保质期", "采购价", "售价", "售价", "最低售价", "备注", "状态", "序列号", "批号"};
String title = "商品信息";
List<String[]> objects = new ArrayList<>();
if (null != dataList) {
@@ -342,8 +342,8 @@ public class MaterialController {
objs[8] = m.getWeight() == null? "" : m.getWeight().toString();
objs[9] = m.getExpiryNum() == null? "" : m.getExpiryNum().toString();
objs[10] = m.getPurchaseDecimal() == null? "" : m.getPurchaseDecimal().toString();
objs[11] = m.getWholesaleDecimal() == null? "" : m.getWholesaleDecimal().toString();
objs[12] = m.getCommodityDecimal() == null? "" : m.getCommodityDecimal().toString();
objs[11] = m.getCommodityDecimal() == null? "" : m.getCommodityDecimal().toString();
objs[12] = m.getWholesaleDecimal() == null? "" : m.getWholesaleDecimal().toString();
objs[13] = m.getLowDecimal() == null? "" : m.getLowDecimal().toString();
objs[14] = m.getRemark();
objs[15] = m.getEnabled() ? "启用" : "禁用";

View File

@@ -154,6 +154,9 @@ public interface DepotItemMapperEx {
@Param("name") String name,
@Param("depotId") Long depotId,
@Param("barCode") String barCode,
@Param("batchNumber") String batchNumber
);
@Param("batchNumber") String batchNumber);
Long getCountByMaterialAndDepot(
@Param("mId") Long mId,
@Param("depotId") Long depotId);
}

View File

@@ -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);
}
}

View File

@@ -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{

View File

@@ -608,4 +608,10 @@
group by batch_number
order by expiration_date asc
</select>
<select id="getCountByMaterialAndDepot" resultType="java.lang.Long">
select count(1) from jsh_depot_item di
where di.material_id=#{mId} and di.depot_id=#{depotId}
and ifnull(di.delete_flag,'0') !='1'
</select>
</mapper>