Commit c0dc922e authored by chenzhao's avatar chenzhao

优化消防装备导入过慢

parent a24ce4a3
package com.yeejoin.equipmanage.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
......@@ -8,6 +9,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yeejoin.equipmanage.common.utils.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -305,9 +307,8 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
@Override
// @Transactional(rollbackFor = Exception.class)
public Object uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel) {
StringBuffer fireFightSysIdsBuffer = new StringBuffer();
Set<String> bizOrgCodes = new HashSet<>();
StringBuffer errBufferName= new StringBuffer();
StringBuffer erryy= new StringBuffer();
// StringBuffer errNum="0"; //失败条数
......@@ -491,11 +492,28 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
// list.add(equipmentSpecific);
// this.equipmentSpecificIndexSave(equipmentDetail, equipmentSpecific);
// }
List<Equipment> equipmentList;
if (redisUtils.hasKey("equip_equipDefinitions")) {
equipmentList = JSONObject.parseArray(redisUtils.get("equip_equipDefinitions").toString(), Equipment.class);;
} else {
QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
equipmentQueryWrapper.isNotNull("id");
equipmentList = equipmentMapper.selectList(equipmentQueryWrapper);
redisUtils.set("equip_equipDefinitions", JSONObject.toJSONString(equipmentList));
}
List<WarehouseStructure> warehouseStructures ;
if (redisUtils.hasKey("equip_warehouseStructures")) {
warehouseStructures = JSONObject.parseArray(redisUtils.get("equip_warehouseStructures").toString(), WarehouseStructure.class);
} else {
warehouseStructures = warehouseStructureService.list();
redisUtils.set("equip_warehouseStructures", JSONObject.toJSONString(warehouseStructures));
}
for (int i = 0; i < equipmentDetailDownloadVOS.size(); i++) {
try {
seveRK( equipmentDetailDownloadVOS.get(i), reginParams, agencyUserModel,
fireFightSysIdsBuffer,list, errBufferName ,erryy, i+1 );
fireFightSysIdsBuffer,list, errBufferName ,erryy, i+1,equipmentList ,warehouseStructures,bizOrgCodes);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -526,8 +544,18 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
String[] split = errBufferName.toString().split(",");
String date="上传成功:"+(equipmentDetailDownloadVOS.size()-(split!=null?split.length:0))+"条---上传失败:"+(split!=null?split.length:0)+"条(失败编号:"+errBufferName+"详情:"+erryy+")";
log.error(date);
//添加对于成功数据装备类型统计数据的刷新
StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
for (String bizOrgCode : bizOrgCodes) {
controllerProxy.refreshCount(bizOrgCode);
}
return date;
}
//添加对于成功数据装备类型统计数据的刷新 当所有数据完成时对已成功数据的单位进行最终统计 避免每一次循环带来的线程压力
StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
for (String bizOrgCode : bizOrgCodes) {
controllerProxy.refreshCount(bizOrgCode);
}
String[] split = errBufferName.toString().split(",");
String date="";
if(split!=null&&split.length>0&&!"".equals(split[0])){
......@@ -555,8 +583,9 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
List<EquipmentSpecific> list,
StringBuffer errBufferName,
StringBuffer erryy,
int rowNum
int rowNum,
List<Equipment> equipmentList,
List<WarehouseStructure> warehouseStructures, Set<String> bizOrgCodes
){
if (StringUtils.isEmpty(equipmentDetailDownloadVOS.getCode())) {
erryy.append("第" + rowNum + "器材编码为空,");
......@@ -577,11 +606,13 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
try {
//查询装备定义信息
QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
equipmentQueryWrapper.lambda().eq(Equipment::getCode, equipmentDetailDownloadVOS.getCode());
Equipment equipment = equipmentMapper.selectOne(equipmentQueryWrapper);
// equipmentQueryWrapper.lambda().eq(Equipment::getCode, equipmentDetailDownloadVOS.getCode());
// Equipment equipment = equipmentMapper.selectOne(equipmentQueryWrapper);
// 此处由于每次导入都需查装备定义导致导入缓慢,所以优化为加入缓存
Equipment equipment = equipmentList.stream().filter(x -> x.getCode().equals(equipmentDetailDownloadVOS.getCode())).collect(Collectors.toList()).get(0);
if (equipment == null) {
erryy.append(String.format("装备(器材)编码[%S]填写错误,请输入正确的装备(器材)编码!",equipmentDetailDownloadVOS.getCode()) + ",");
throw new RuntimeException(String.format("装备(器材)编码[%S]填写错误,请输入正确的装备(器材)编码!",equipmentDetailDownloadVOS.getCode()));
......@@ -602,15 +633,18 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
throw new RuntimeException(String.format("物联编码[%S]填写重复,请重新输入!",iotCode));
}
if(StringUtils.isNotEmpty(haveUsedIotPrefix) && Arrays.stream(haveUsedIotPrefix.split(",")).anyMatch(iotCode::startsWith)){
erryy.append(String.format("物联编码[%S]航班已占用,请重新输入!",iotCode)+ ",");
throw new BadRequest("物联编码航班已占用");
erryy.append(String.format("物联编码[%S]已占用,请重新输入!",iotCode)+ ",");
throw new BadRequest("物联编码已占用");
}
}
AtomicReference<String> fightSysIds = new AtomicReference<>("");
String fightingSysCodes = equipmentDetailDownloadVOS.getFightingSysCodes();
if (StringUtils.isNotBlank(fightingSysCodes)) {
String[] idsArr = fightingSysCodes.split("-");
List<FireFightingSystemEntity> fightingSystemList = fireFightingSystemService.getFightingSysByCodes(idsArr);
String[] codes = new String[]{};
String[] idsArr1 = fightingSysCodes.split("-");
String[] idsArr2 = fightingSysCodes.split(",");
codes = idsArr1.length >= idsArr2.length ? idsArr1 : idsArr2;
List<FireFightingSystemEntity> fightingSystemList = fireFightingSystemService.getFightingSysByCodes(codes);
if (!fightingSystemList.isEmpty()) {
fightingSystemList.stream().forEach(x -> {
String sysCodes = fightSysIds.get();
......@@ -640,9 +674,8 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
equipmentDetail.setName(equipmentDetailDownloadVOS.getName());
equipmentDetail.setArea(equipmentDetailDownloadVOS.getDescription());
equipmentDetail.setProductionDate(equipmentDetailDownloadVOS.getProductionDate());
equipmentDetail.setExpiryDate(equipmentDetailDownloadVOS.getExpiryDate());
equipmentDetail.setDeliveryDate(equipmentDetailDownloadVOS.getDeliveryDate());
equipmentDetail.setMaintenanceCycle(equipmentDetailDownloadVOS.getMaintenanceCycle());
equipmentDetail.setMaintenanceCycle(ObjectUtils.isEmpty(equipment.getMaintenanceCycle()) ? null : BigDecimal.valueOf(equipment.getMaintenanceCycle()));
// 导入新增所属单位
......@@ -675,7 +708,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
equipmentSpecific.setTeamId(fireTeam[1]);
}
// 导入新增所属单位
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getCompanyName())) {
String[] company = equipmentDetailDownloadVOS.getCompanyName().split("@");
equipmentSpecific.setAgencyId(company[1]);
......@@ -685,19 +717,19 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
}
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getSystemName())) {
String[] SystemName = equipmentDetailDownloadVOS.getSystemName().split("@");
equipmentSpecific.setSystemId(SystemName[1]);
}
// if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getSystemName())) {
// String[] SystemName = equipmentDetailDownloadVOS.getSystemName().split("@");
// equipmentSpecific.setSystemId(SystemName[1]);
// }
equipmentSpecificMapper.insert(equipmentSpecific);
StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
//添加对于装备类型统计数据的刷新
controllerProxy.refreshCount(equipmentSpecific.getBizOrgCode());
//位置编码不为空入库
if (equipmentDetailDownloadVOS != null && equipmentDetailDownloadVOS.getWarehouseStructCode() != null) {
QueryWrapper<WarehouseStructure> warehouseStructureQueryWrapper = new QueryWrapper<>();
warehouseStructureQueryWrapper.lambda().eq(WarehouseStructure::getCode, equipmentDetailDownloadVOS.getWarehouseStructCode());
WarehouseStructure warehouseStructure = warehouseStructureService.getOne(warehouseStructureQueryWrapper);
// QueryWrapper<WarehouseStructure> warehouseStructureQueryWrapper = new QueryWrapper<>();
// warehouseStructureQueryWrapper.lambda().eq(WarehouseStructure::getCode, equipmentDetailDownloadVOS.getWarehouseStructCode());
// WarehouseStructure warehouseStructure = warehouseStructureService.getOne(warehouseStructureQueryWrapper);
// 入库位置进行优化
WarehouseStructure warehouseStructure = warehouseStructures.stream().filter(x -> x.getCode().equals(equipmentDetailDownloadVOS.getWarehouseStructCode())).collect(Collectors.toList()).get(0);
if (warehouseStructure == null) {
erryy.append(String.format("货位编码[%S]填写错误,请输入正确的货位编码!",equipmentDetailDownloadVOS.getWarehouseStructCode())+ ",");
throw new RuntimeException(String.format("货位编码[%S]填写错误,请输入正确的货位编码!",equipmentDetailDownloadVOS.getWarehouseStructCode()));
......@@ -765,6 +797,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
}
list.add(equipmentSpecific);
this.equipmentSpecificIndexSave(equipmentDetail, equipmentSpecific);
bizOrgCodes.add(equipmentSpecific.getBizOrgCode());
platformTransactionManager.commit(transactionStatus);
} catch (Exception e) {
platformTransactionManager.rollback(transactionStatus);
......@@ -780,7 +813,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
// @Async
@Async
public void refreshCount(String bizOrgCode) {
equipmentSpecificSerivce.refreshStaData();
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment