|
|
@ -8,10 +8,13 @@ import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig; |
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig; |
|
|
import com.alibaba.excel.write.metadata.fill.FillWrapper; |
|
|
import com.alibaba.excel.write.metadata.fill.FillWrapper; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.dreamchaser.depository_manage.controller.WebSocketController; |
|
|
import com.dreamchaser.depository_manage.entity.*; |
|
|
import com.dreamchaser.depository_manage.entity.*; |
|
|
import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper; |
|
|
import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper; |
|
|
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|
|
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|
|
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|
|
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|
|
|
|
|
import com.dreamchaser.depository_manage.security.pool.ExcelFileInfoPool; |
|
|
import com.dreamchaser.depository_manage.service.*; |
|
|
import com.dreamchaser.depository_manage.service.*; |
|
|
import com.dreamchaser.depository_manage.utils.*; |
|
|
import com.dreamchaser.depository_manage.utils.*; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -62,19 +65,14 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
ConstructionUnitMapper constructionUnitMapper; |
|
|
ConstructionUnitMapper constructionUnitMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ExcelInfoByInventory> excelVosForInventory = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用于导入物料名称 |
|
|
* 用于导入物料名称 |
|
|
* |
|
|
* |
|
|
* @param file |
|
|
* @param file |
|
|
* @param excelInfo |
|
|
|
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public ResultVo importExcelMaterial(MultipartFile file, String excelInfo) { |
|
|
public ResultVo importExcelMaterial(MultipartFile file, UserByPort userByPort) { |
|
|
// 1.入参校验
|
|
|
// 1.入参校验
|
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
@ -91,51 +89,79 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
return ResultVoUtil.error("【导入Excel文件】生成的Excel文件的路径为空"); |
|
|
return ResultVoUtil.error("【导入Excel文件】生成的Excel文件的路径为空"); |
|
|
} |
|
|
} |
|
|
// 3.读取excel文件
|
|
|
// 3.读取excel文件
|
|
|
Map<String, Object> readResult = new HashMap<>(); |
|
|
Map<String, Object> readResult = excelutil.simpleExcelRead(filePath, ExcelInfoForMaterial.class); |
|
|
if ("material".equals(excelInfo)) { |
|
|
List<ExcelInfoForMaterial> excelVosForMaterialList = (List<ExcelInfoForMaterial>) readResult.get("dataList"); |
|
|
readResult = excelutil.simpleExcelRead(filePath, ExcelInfo.class); |
|
|
|
|
|
} |
|
|
|
|
|
List<ExcelInfo> excelVos = (List<ExcelInfo>) readResult.get("dataList"); |
|
|
|
|
|
List<String> errMsg = (List<String>) readResult.get("errMsg"); |
|
|
List<String> errMsg = (List<String>) readResult.get("errMsg"); |
|
|
boolean empty = CollectionUtil.isEmpty(excelVos); |
|
|
List<String> dataIndex = (List<String>) readResult.get("dataIndex"); |
|
|
if ((CollectionUtil.isEmpty(excelVos) && errMsg.size() < 1) || (excelVos.size() < 2 && errMsg.size() < 1)) { |
|
|
boolean empty = CollectionUtil.isEmpty(excelVosForMaterialList); |
|
|
|
|
|
if ((CollectionUtil.isEmpty(excelVosForMaterialList) && errMsg.size() < 1) || (excelVosForMaterialList.size() < 2 && errMsg.size() < 1)) { |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
} |
|
|
} |
|
|
// 4.通过线程池开启一个线程去执行数据库操作,主线程继续往下执行
|
|
|
|
|
|
// 4.1开启一个线程
|
|
|
|
|
|
TaskCenterUtil taskCenterUtil = TaskCenterUtil.getTaskCenterUtil(); |
|
|
// 获取当前总数
|
|
|
taskCenterUtil.submitTask(() -> { |
|
|
int totalVal = excelVosForMaterialList.size(); |
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
|
|
Map<String, Object> returnResult = new HashMap<>(); |
|
|
if (totalVal > 0) { |
|
|
for (ExcelInfo excelVo : excelVos) { |
|
|
// 初始化
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
ExcelFileInfoPool.addUserExcelMaterialInfo(userByPort.getNumber(), Collections.synchronizedList(new ArrayList<>())); |
|
|
param.put("mname", excelVo.getMname()); |
|
|
// 定义分页数量
|
|
|
|
|
|
double size = 100.0; |
|
|
param.put("code", excelVo.getCode()); |
|
|
|
|
|
param.put("unit", excelVo.getUnit()); |
|
|
// 定义线程数
|
|
|
param.put("version", excelVo.getVersion()); |
|
|
int threadSize = (int) Math.ceil(totalVal / size); |
|
|
param.put("texture", excelVo.getTexture()); |
|
|
|
|
|
Long typeId = excelVo.getTypeId(); |
|
|
// 定义开启线程数目
|
|
|
if (typeId != null) { |
|
|
int openThreadSize = 0; |
|
|
param.put("typeId", typeId); |
|
|
// 开启对应数量的线程
|
|
|
}else{ |
|
|
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|
|
String typeName = excelVo.getTypeName(); |
|
|
// 线程结果集
|
|
|
MaterialType materialTypeByName = materialTypeService.findMaterialTypeByName(typeName); |
|
|
List<Future<List<String>>> futureList = new ArrayList<Future<List<String>>>(); |
|
|
param.put("typeId", materialTypeByName.getOldId()); |
|
|
|
|
|
|
|
|
// 1.定义CompletionService
|
|
|
|
|
|
CompletionService<List<String>> completionService = new ExecutorCompletionService<>(exs); |
|
|
|
|
|
|
|
|
|
|
|
// 定义组合id列表
|
|
|
|
|
|
List<ExcelInfoForMaterial> excelInfoForMaterialS = new ArrayList<>(); |
|
|
|
|
|
List<String> dataIndexList = new ArrayList<>(); |
|
|
|
|
|
System.out.println(excelVosForMaterialList.size()); |
|
|
|
|
|
for (int i = 0; i < excelVosForMaterialList.size(); i++) { |
|
|
|
|
|
if (((i + 1) % 100) == 0) { // 如果有个开启线程进行处理
|
|
|
|
|
|
excelInfoForMaterialS.add(excelVosForMaterialList.get(i)); |
|
|
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportMaterialFileData(excelInfoForMaterialS, dataIndexList, userByPort)); |
|
|
|
|
|
openThreadSize++; |
|
|
|
|
|
futureList.add(future); // 添加到结果集
|
|
|
|
|
|
excelInfoForMaterialS = new ArrayList<>(); // 情况列表
|
|
|
|
|
|
dataIndexList = new ArrayList<>(); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 添加id到列表中
|
|
|
|
|
|
excelInfoForMaterialS.add(excelVosForMaterialList.get(i)); |
|
|
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (excelInfoForMaterialS.size() > 0) { |
|
|
|
|
|
// 如果有剩余,开启线程进行处理
|
|
|
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportMaterialFileData(excelInfoForMaterialS, dataIndexList, userByPort)); |
|
|
|
|
|
futureList.add(future); |
|
|
|
|
|
openThreadSize++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
|
|
|
List<String> strings = new ArrayList<>(); |
|
|
|
|
|
try { |
|
|
|
|
|
strings = completionService.take().get(); |
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
param.put("id", excelVo.getId()); |
|
|
errMsg.addAll(strings); |
|
|
param.put("brand", excelVo.getBrand()); |
|
|
|
|
|
param.put("price", excelVo.getPrice() == null ? "0" : excelVo.getPrice()); |
|
|
|
|
|
materialService.insertMaterial(param); |
|
|
|
|
|
success.add(excelVo); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
System.out.println(ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber()).size()); |
|
|
|
|
|
|
|
|
|
|
|
readResult.put("dataList", ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber())); |
|
|
|
|
|
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos)); |
|
|
|
|
|
returnResult.put("success", success); |
|
|
|
|
|
returnResult.put("errMsg", errMsg); |
|
|
|
|
|
return ResultVoUtil.returnResultVo(200, returnResult, "结果"); |
|
|
|
|
|
}); |
|
|
|
|
|
// 4.2删除临时文件
|
|
|
// 4.2删除临时文件
|
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
if (!deleteFile) { |
|
|
if (!deleteFile) { |
|
|
@ -153,7 +179,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public ResultVo importExcelMaterialType(MultipartFile file) { |
|
|
public ResultVo importExcelMaterialType(MultipartFile file, UserByPort userByPort) { |
|
|
// 1.入参校验
|
|
|
// 1.入参校验
|
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
@ -171,44 +197,81 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} |
|
|
} |
|
|
// 3.读取excel文件
|
|
|
// 3.读取excel文件
|
|
|
Map<String, Object> readResult = excelutil.simpleExcelRead(filePath, ExcelInfoByMT.class); |
|
|
Map<String, Object> readResult = excelutil.simpleExcelRead(filePath, ExcelInfoByMT.class); |
|
|
List<ExcelInfoByMT> excelVos = (List<ExcelInfoByMT>) readResult.get("dataList"); |
|
|
List<ExcelInfoByMT> excelInfoByMTList = (List<ExcelInfoByMT>) readResult.get("dataList"); |
|
|
List<String> errMsg = (List<String>) readResult.get("errMsg"); |
|
|
List<String> errMsg = (List<String>) readResult.get("errMsg"); |
|
|
boolean empty = CollectionUtil.isEmpty(excelVos); |
|
|
List<String> dataIndex = (List<String>) readResult.get("dataIndex"); |
|
|
if ((CollectionUtil.isEmpty(excelVos) && errMsg.size() < 1) || (excelVos.size() < 2 && errMsg.size() < 1)) { |
|
|
boolean empty = CollectionUtil.isEmpty(excelInfoByMTList); |
|
|
|
|
|
if ((CollectionUtil.isEmpty(excelInfoByMTList) && errMsg.size() < 1) || (excelInfoByMTList.size() < 2 && errMsg.size() < 1)) { |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
} |
|
|
} |
|
|
if ((CollectionUtil.isEmpty(excelVos) && errMsg.size() < 1) || (excelVos.size() < 2 && errMsg.size() < 1)) { |
|
|
if ((CollectionUtil.isEmpty(excelInfoByMTList) && errMsg.size() < 1) || (excelInfoByMTList.size() < 2 && errMsg.size() < 1)) { |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
log.error("【导入Excel文件】上传Excel文件{}为空", file.getOriginalFilename()); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
} |
|
|
} |
|
|
// 4.通过线程池开启一个线程去执行数据库操作,主线程继续往下执行
|
|
|
|
|
|
// 4.1开启一个线程
|
|
|
|
|
|
TaskCenterUtil taskCenterUtil = TaskCenterUtil.getTaskCenterUtil(); |
|
|
// 获取当前总数
|
|
|
taskCenterUtil.submitTask(() -> { |
|
|
int totalVal = excelInfoByMTList.size(); |
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
|
|
Map<String, Object> returnResult = new HashMap<>(); |
|
|
if (totalVal > 0) { |
|
|
|
|
|
// 初始化
|
|
|
for (int i = 0; i < excelVos.size(); i++) { |
|
|
ExcelFileInfoPool.addUserExcelMaterialTypeInfo(userByPort.getNumber(), Collections.synchronizedList(new ArrayList<>())); |
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
// 定义分页数量
|
|
|
ExcelInfoByMT info = excelVos.get(i); |
|
|
double size = 100.0; |
|
|
insert.put("oldId", info.getOldId()); |
|
|
|
|
|
insert.put("tname", info.getTname()); |
|
|
// 定义线程数
|
|
|
insert.put("introduce", info.getIntroduce()); |
|
|
int threadSize = (int) Math.ceil(totalVal / size); |
|
|
if (info.getParentId() == null) { |
|
|
|
|
|
insert.put("materialTypeId", 0); |
|
|
// 定义开启线程数目
|
|
|
|
|
|
int openThreadSize = 0; |
|
|
|
|
|
// 开启对应数量的线程
|
|
|
|
|
|
ExecutorService exs = Executors.newFixedThreadPool(threadSize); |
|
|
|
|
|
// 线程结果集
|
|
|
|
|
|
List<Future<List<String>>> futureList = new ArrayList<Future<List<String>>>(); |
|
|
|
|
|
|
|
|
|
|
|
// 1.定义CompletionService
|
|
|
|
|
|
CompletionService<List<String>> completionService = new ExecutorCompletionService<>(exs); |
|
|
|
|
|
|
|
|
|
|
|
// 定义组合id列表
|
|
|
|
|
|
List<ExcelInfoByMT> excelInfoByMTS = new ArrayList<>(); |
|
|
|
|
|
List<String> dataIndexList = new ArrayList<>(); |
|
|
|
|
|
for (int i = 0; i < excelInfoByMTList.size(); i++) { |
|
|
|
|
|
if (((i + 1) % 100) == 0) { // 如果有10个开启线程进行处理
|
|
|
|
|
|
excelInfoByMTS.add(excelInfoByMTList.get(i)); |
|
|
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportMaterialTypeFileData(excelInfoByMTS, dataIndexList, userByPort)); |
|
|
|
|
|
openThreadSize++; |
|
|
|
|
|
futureList.add(future); // 添加到结果集
|
|
|
|
|
|
excelInfoByMTS = new ArrayList<>(); // 情况列表
|
|
|
|
|
|
dataIndexList = new ArrayList<>(); |
|
|
} else { |
|
|
} else { |
|
|
insert.put("materialTypeId", info.getParentId()); |
|
|
// 添加id到列表中
|
|
|
|
|
|
excelInfoByMTS.add(excelInfoByMTList.get(i)); |
|
|
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (excelInfoByMTS.size() > 0) { |
|
|
|
|
|
// 如果有剩余,开启线程进行处理
|
|
|
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportMaterialTypeFileData(excelInfoByMTS, dataIndexList, userByPort)); |
|
|
|
|
|
futureList.add(future); |
|
|
|
|
|
openThreadSize++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
|
|
|
List<String> strings = new ArrayList<>(); |
|
|
|
|
|
try { |
|
|
|
|
|
strings = completionService.take().get(); |
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
materialTypeService.insertMaterialType(insert); |
|
|
errMsg.addAll(strings); |
|
|
success.add(info); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
readResult.put("dataList", ExcelFileInfoPool.getUserExcelMaterialTypeInfo(userByPort.getNumber())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos)); |
|
|
|
|
|
returnResult.put("success", success); |
|
|
|
|
|
returnResult.put("errMsg", errMsg); |
|
|
|
|
|
return ResultVoUtil.returnResultVo(200, returnResult, "结果"); |
|
|
|
|
|
}); |
|
|
|
|
|
// 4.2删除临时文件
|
|
|
// 4.2删除临时文件
|
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
if (!deleteFile) { |
|
|
if (!deleteFile) { |
|
|
@ -217,8 +280,6 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} |
|
|
} |
|
|
log.info("【导入Excel文件】删除临时文件成功,临时文件路径为:{}", filePath); |
|
|
log.info("【导入Excel文件】删除临时文件成功,临时文件路径为:{}", filePath); |
|
|
return ResultVoUtil.returnResultVo(200, readResult, "结果"); |
|
|
return ResultVoUtil.returnResultVo(200, readResult, "结果"); |
|
|
// return ResultVoUtil.success(excelVos);
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,7 +290,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public ResultVo importExcelInventory(MultipartFile file) { |
|
|
public ResultVo importExcelInventory(MultipartFile file, UserByPort userByPort) { |
|
|
// 1.入参校验
|
|
|
// 1.入参校验
|
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
ResultVo<String> checkExcelParam = excelutil.checkExcelParam(file); |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
if (!checkExcelParam.checkSuccess()) { |
|
|
@ -263,9 +324,13 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
// 获取当前总数
|
|
|
// 获取当前总数
|
|
|
int totalVal = excelInfoByInventories.size(); |
|
|
int totalVal = excelInfoByInventories.size(); |
|
|
|
|
|
|
|
|
if(totalVal > 0){ |
|
|
if (totalVal > 0) { |
|
|
|
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
|
|
ExcelFileInfoPool.addUserExcelInventoryInfo(userByPort.getNumber(), Collections.synchronizedList(new ArrayList<>())); |
|
|
|
|
|
|
|
|
// 定义分页数量
|
|
|
// 定义分页数量
|
|
|
double size = 10.0; |
|
|
double size = 100.0; |
|
|
|
|
|
|
|
|
// 定义线程数
|
|
|
// 定义线程数
|
|
|
int threadSize = (int) Math.ceil(totalVal / size); |
|
|
int threadSize = (int) Math.ceil(totalVal / size); |
|
|
@ -287,7 +352,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
if (((i + 1) % 100) == 0) { // 如果有10个开启线程进行处理
|
|
|
if (((i + 1) % 100) == 0) { // 如果有10个开启线程进行处理
|
|
|
excelInfoByInventoryList.add(excelInfoByInventories.get(i)); |
|
|
excelInfoByInventoryList.add(excelInfoByInventories.get(i)); |
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList,dataIndexList)); |
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList, dataIndexList, userByPort)); |
|
|
openThreadSize++; |
|
|
openThreadSize++; |
|
|
futureList.add(future); // 添加到结果集
|
|
|
futureList.add(future); // 添加到结果集
|
|
|
excelInfoByInventoryList = new ArrayList<>(); // 情况列表
|
|
|
excelInfoByInventoryList = new ArrayList<>(); // 情况列表
|
|
|
@ -300,7 +365,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} |
|
|
} |
|
|
if (excelInfoByInventoryList.size() > 0) { |
|
|
if (excelInfoByInventoryList.size() > 0) { |
|
|
// 如果有剩余,开启线程进行处理
|
|
|
// 如果有剩余,开启线程进行处理
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList,dataIndexList)); |
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList, dataIndexList, userByPort)); |
|
|
futureList.add(future); |
|
|
futureList.add(future); |
|
|
openThreadSize++; |
|
|
openThreadSize++; |
|
|
} |
|
|
} |
|
|
@ -317,7 +382,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readResult.put("dataList", excelVosForInventory); |
|
|
readResult.put("dataList", ExcelFileInfoPool.getUserExcelInventoryInfo(userByPort.getNumber())); |
|
|
|
|
|
|
|
|
// 4.2删除临时文件
|
|
|
// 4.2删除临时文件
|
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
@ -516,125 +581,208 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
/** |
|
|
/** |
|
|
* 用于执行库存导入方法 |
|
|
* 用于执行库存导入方法 |
|
|
*/ |
|
|
*/ |
|
|
public void executeImportForInventory(){ |
|
|
public void executeImportForInventory(UserByPort userByPort) { |
|
|
TaskCenterUtil taskCenterUtil = TaskCenterUtil.getTaskCenterUtil(); |
|
|
List<Object> success = new ArrayList<>(); |
|
|
Future<Object> objectFuture = taskCenterUtil.submitTask(() -> { |
|
|
String number = userByPort.getNumber(); |
|
|
List<Object> success = new ArrayList<>(); |
|
|
List<ExcelInfoByInventory> excelVosForInventory = ExcelFileInfoPool.getUserExcelInventoryInfo(number); |
|
|
Map<String, Object> returnResult = new HashMap<>(); |
|
|
for (int i = 0; i < excelVosForInventory.size(); i++) { |
|
|
for (ExcelInfoByInventory excelInfoByInventory : excelVosForInventory) { |
|
|
ExcelInfoByInventory excelInfoByInventory = excelVosForInventory.get(i); |
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
insert.put("mname", excelInfoByInventory.getMname()); |
|
|
insert.put("mname", excelInfoByInventory.getMname()); |
|
|
insert.put("version", excelInfoByInventory.getVersion()); |
|
|
insert.put("version", excelInfoByInventory.getVersion()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Material material = materialService.findMaterialByMnameAndVersion(insert); |
|
|
Material material = materialService.findMaterialByMnameAndVersion(insert); |
|
|
if (material == null) { |
|
|
if (material == null) { |
|
|
String code = excelInfoByInventory.getCode(); |
|
|
String code = excelInfoByInventory.getCode(); |
|
|
if (code != null && !"".equals(code)) { |
|
|
if (code != null && !"".equals(code)) { |
|
|
material = materialService.findMaterialByCode(code); |
|
|
material = materialService.findMaterialByCode(code); |
|
|
} else { |
|
|
} else { |
|
|
material = materialMapper.findMaterialByCondition(insert).get(0); |
|
|
material = materialMapper.findMaterialByCondition(insert).get(0); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 添加库存记录
|
|
|
// 添加库存记录
|
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
Double quantity = ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()); |
|
|
Double quantity = ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()); |
|
|
insert.put("tempPlaceCode", excelInfoByInventory.getDepositoryCode()); |
|
|
insert.put("tempPlaceCode", excelInfoByInventory.getDepositoryCode()); |
|
|
insert.put("quantity", String.valueOf(quantity)); |
|
|
insert.put("quantity", String.valueOf(quantity)); |
|
|
insert.put("depositoryId", depositoryId); |
|
|
insert.put("depositoryId", depositoryId); |
|
|
insert.put("depositoryCode", excelInfoByInventory.getDepositoryCode()); |
|
|
insert.put("depositoryCode", excelInfoByInventory.getDepositoryCode()); |
|
|
insert.put("mid", material.getId()); |
|
|
insert.put("mid", material.getId()); |
|
|
|
|
|
|
|
|
// 插入库存记录
|
|
|
// 插入库存记录
|
|
|
materialService.insertInventoryForImport(insert); |
|
|
materialService.insertInventoryForImport(insert); |
|
|
|
|
|
|
|
|
// 将该物料同时放入默认库位中
|
|
|
// 将该物料同时放入默认库位中
|
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
Place placeById = null; |
|
|
Place placeById = null; |
|
|
Boolean isNew = (Boolean) insert.get("isNew"); |
|
|
Boolean isNew = (Boolean) insert.get("isNew"); |
|
|
if (isNew) { |
|
|
if (isNew) { |
|
|
SplitInfo baseSplitInfoForMid = splitUnitService.findBaseSplitInfoForMid(material.getId()); |
|
|
SplitInfo baseSplitInfoForMid = splitUnitService.findBaseSplitInfoForMid(material.getId()); |
|
|
double quantity_residue = 0; |
|
|
double quantity_residue = 0; |
|
|
if (baseSplitInfoForMid != null) { |
|
|
if (baseSplitInfoForMid != null) { |
|
|
quantity_residue = quantity - Math.floor(quantity); |
|
|
quantity_residue = quantity - Math.floor(quantity); |
|
|
quantity = quantity - quantity_residue; |
|
|
quantity = quantity - quantity_residue; |
|
|
} |
|
|
} |
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
// 如果是新插入物料
|
|
|
// 如果是新插入物料
|
|
|
if (placeCode == null || placeCode.isEmpty() || "0".equals(placeCode) || "0000".equals(placeCode) || "000000".equals(placeCode)) { // 如果没有输入库位
|
|
|
if (placeCode == null || placeCode.isEmpty() || "0".equals(placeCode) || "0000".equals(placeCode) || "000000".equals(placeCode)) { // 如果没有输入库位
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
// 获取默认库位
|
|
|
// 获取默认库位
|
|
|
placeById = placeService.findPlaceById(0); |
|
|
placeById = placeService.findPlaceById(0); |
|
|
// 修改默认库位库存
|
|
|
// 修改默认库位库存
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
placeService.UpdatePlace(placeById); |
|
|
placeService.UpdatePlace(placeById); |
|
|
// 添加库位与物料的映射
|
|
|
// 添加库位与物料的映射
|
|
|
param.put("mid", insert.get("id")); |
|
|
param.put("mid", insert.get("id")); |
|
|
param.put("pid", 0); |
|
|
param.put("pid", 0); |
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
placeService.addMaterialOnPlace(param); |
|
|
placeService.addMaterialOnPlace(param); |
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
} else { |
|
|
} else { |
|
|
// 如果输入的库位不是默认库位
|
|
|
// 如果输入的库位不是默认库位
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
param.put("did", depositoryId); |
|
|
param.put("did", depositoryId); |
|
|
param.put("kingdeecode", placeCode); |
|
|
param.put("kingdeecode", placeCode); |
|
|
// 获取要导入的库位
|
|
|
// 获取要导入的库位
|
|
|
placeById = placeService.findPlaceByCondition(param).get(0); |
|
|
placeById = placeService.findPlaceByCondition(param).get(0); |
|
|
// 修改库位物料数量
|
|
|
// 修改库位物料数量
|
|
|
|
|
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
placeService.UpdatePlace(placeById); |
|
|
placeService.UpdatePlace(placeById); |
|
|
|
|
|
|
|
|
// 如果没有对应关系
|
|
|
// 如果没有对应关系
|
|
|
param.put("pid", placeById.getId()); |
|
|
param.put("pid", placeById.getId()); |
|
|
param.put("mid", insert.get("id")); |
|
|
param.put("mid", insert.get("id")); |
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
// 添加对应关系
|
|
|
// 添加对应关系
|
|
|
placeService.addMaterialOnPlace(param); |
|
|
placeService.addMaterialOnPlace(param); |
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (baseSplitInfoForMid != null) { |
|
|
if (baseSplitInfoForMid != null) { |
|
|
Map<String, Object> insertForSplitInfoStringObjectMap = new HashMap<>(); |
|
|
Map<String, Object> insertForSplitInfoStringObjectMap = new HashMap<>(); |
|
|
insertForSplitInfoStringObjectMap.put("depositoryId", depositoryId); |
|
|
insertForSplitInfoStringObjectMap.put("depositoryId", depositoryId); |
|
|
insertForSplitInfoStringObjectMap.put("quantity", quantity_residue); |
|
|
insertForSplitInfoStringObjectMap.put("quantity", quantity_residue); |
|
|
insertForSplitInfoStringObjectMap.put("placeId", placeById.getId().toString()); |
|
|
insertForSplitInfoStringObjectMap.put("placeId", placeById.getId().toString()); |
|
|
insertForSplitInfoStringObjectMap.put("mid", material.getId()); |
|
|
insertForSplitInfoStringObjectMap.put("mid", material.getId()); |
|
|
insertForSplitInfoStringObjectMap.put("unit", baseSplitInfoForMid.getNewUnit()); |
|
|
insertForSplitInfoStringObjectMap.put("unit", baseSplitInfoForMid.getNewUnit()); |
|
|
SplitInventory splitInventoryByIidAndSid = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), baseSplitInfoForMid.getId()); |
|
|
SplitInventory splitInventoryByIidAndSid = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), baseSplitInfoForMid.getId()); |
|
|
int splitInfoScaleQuantity = splitUnitService.findSplitInfoScaleQuantity(baseSplitInfoForMid, -1); |
|
|
int splitInfoScaleQuantity = splitUnitService.findSplitInfoScaleQuantity(baseSplitInfoForMid, -1); |
|
|
splitUnitService.realInInventoryToDepository(quantity_residue * splitInfoScaleQuantity, splitInventoryByIidAndSid, insertForSplitInfoStringObjectMap, baseSplitInfoForMid, placeAndMaterialByMidAndPid, true); |
|
|
splitUnitService.realInInventoryToDepository(quantity_residue * splitInfoScaleQuantity, splitInventoryByIidAndSid, insertForSplitInfoStringObjectMap, baseSplitInfoForMid, placeAndMaterialByMidAndPid, true); |
|
|
if (insertForSplitInfoStringObjectMap.containsKey("applicationInId")) { |
|
|
if (insertForSplitInfoStringObjectMap.containsKey("applicationInId")) { |
|
|
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForSplitInfoStringObjectMap.get("applicationInId"))); |
|
|
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForSplitInfoStringObjectMap.get("applicationInId"))); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
success.add(excelInfoByInventory); |
|
|
|
|
|
if ((i + 1) % 100 == 0 || excelVosForInventory.size() - 1 == i) { |
|
|
|
|
|
// 如果凑够100条或者已经循环完成 发送消息
|
|
|
|
|
|
try { |
|
|
|
|
|
WebSocketController.sendInfo(JSONObject.toJSONString(success), number); |
|
|
|
|
|
success = new ArrayList<>(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
success.add(excelInfoByInventory); |
|
|
|
|
|
} |
|
|
} |
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForInventory)); |
|
|
} |
|
|
returnResult.put("success", success); |
|
|
ExcelFileInfoPool.removeUserExcelInventoryInfo(number); |
|
|
excelVosForInventory = new ArrayList<>(); |
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForInventory)); |
|
|
// returnResult.put("errMsg", errMsg);
|
|
|
|
|
|
return ResultVoUtil.returnResultVo(200, returnResult, "结果"); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用于执行物料类型导入方法 |
|
|
* 用于执行物料类型导入方法 |
|
|
*/ |
|
|
*/ |
|
|
public void executeImportForMaterialType(){ |
|
|
public void executeImportForMaterialType(UserByPort userByPort) { |
|
|
|
|
|
// 4.通过线程池开启一个线程去执行数据库操作,主线程继续往下执行
|
|
|
|
|
|
// 4.1开启一个线程
|
|
|
|
|
|
|
|
|
|
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
|
|
String number = userByPort.getNumber(); |
|
|
|
|
|
List<ExcelInfoByMT> excelVosForMaterialType = ExcelFileInfoPool.getUserExcelMaterialTypeInfo(number); |
|
|
|
|
|
for (int i = 0; i < excelVosForMaterialType.size(); i++) { |
|
|
|
|
|
ExcelInfoByMT excelInfoByMT = excelVosForMaterialType.get(i); |
|
|
|
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
|
|
|
ExcelInfoByMT info = excelInfoByMT; |
|
|
|
|
|
insert.put("oldId", info.getOldId()); |
|
|
|
|
|
insert.put("tname", info.getTname()); |
|
|
|
|
|
insert.put("introduce", info.getIntroduce()); |
|
|
|
|
|
if (info.getParentId() == null) { |
|
|
|
|
|
insert.put("materialTypeId", 0); |
|
|
|
|
|
} else { |
|
|
|
|
|
insert.put("materialTypeId", info.getParentId()); |
|
|
|
|
|
} |
|
|
|
|
|
materialTypeService.insertMaterialType(insert); |
|
|
|
|
|
success.add(info); |
|
|
|
|
|
if ((i + 1) % 100 == 0 || excelVosForMaterialType.size() - 1 == i) { |
|
|
|
|
|
// 如果凑够100条或者已经循环完成 发送消息
|
|
|
|
|
|
try { |
|
|
|
|
|
WebSocketController.sendInfo(JSONObject.toJSONString(success), number); |
|
|
|
|
|
success = new ArrayList<>(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(number); |
|
|
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterialType)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用于执行物料导入方法 |
|
|
|
|
|
*/ |
|
|
|
|
|
public void executeImportForMaterial(UserByPort userByPort) { |
|
|
|
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
|
|
String number = userByPort.getNumber(); |
|
|
|
|
|
List<ExcelInfoForMaterial> excelVosForMaterial = ExcelFileInfoPool.getUserExcelMaterialInfo(number); |
|
|
|
|
|
for (int i = 0; i < excelVosForMaterial.size(); i++) { |
|
|
|
|
|
ExcelInfoForMaterial excelVo = excelVosForMaterial.get(i); |
|
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
|
|
param.put("mname", excelVo.getMname()); |
|
|
|
|
|
param.put("code", excelVo.getCode()); |
|
|
|
|
|
param.put("unit", excelVo.getUnit()); |
|
|
|
|
|
param.put("version", excelVo.getVersion()); |
|
|
|
|
|
param.put("texture", excelVo.getTexture()); |
|
|
|
|
|
Long typeId = excelVo.getTypeId(); |
|
|
|
|
|
if (typeId != null) { |
|
|
|
|
|
param.put("typeId", typeId); |
|
|
|
|
|
} else { |
|
|
|
|
|
String typeName = excelVo.getTypeName(); |
|
|
|
|
|
MaterialType materialTypeByName = materialTypeService.findMaterialTypeByName(typeName); |
|
|
|
|
|
param.put("typeId", materialTypeByName.getOldId()); |
|
|
|
|
|
} |
|
|
|
|
|
param.put("id", excelVo.getId()); |
|
|
|
|
|
param.put("brand", excelVo.getBrand()); |
|
|
|
|
|
param.put("price", excelVo.getPrice() == null ? "0" : excelVo.getPrice()); |
|
|
|
|
|
materialService.insertMaterial(param); |
|
|
|
|
|
success.add(excelVo); |
|
|
|
|
|
if ((i + 1) % 100 == 0 || excelVosForMaterial.size() - 1 == i) { |
|
|
|
|
|
// 如果凑够100条或者已经循环完成 发送消息
|
|
|
|
|
|
try { |
|
|
|
|
|
WebSocketController.sendInfo(JSONObject.toJSONString(success), number); |
|
|
|
|
|
success = new ArrayList<>(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
ExcelFileInfoPool.removeUserExcelMaterialInfo(number); |
|
|
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForMaterial)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 用于清空导入的数据 |
|
|
* 用于清空导入的数据 |
|
|
*/ |
|
|
*/ |
|
|
public void clearImportFileData(){ |
|
|
public void clearImportFileData(UserByPort userByPort) { |
|
|
excelVosForInventory = new ArrayList<>(); |
|
|
ExcelFileInfoPool.removeUserExcelInventoryInfo(userByPort.getNumber()); |
|
|
|
|
|
ExcelFileInfoPool.removeUserExcelMaterialInfo(userByPort.getNumber()); |
|
|
|
|
|
ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(userByPort.getNumber()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -653,11 +801,16 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
*/ |
|
|
*/ |
|
|
List<String> dataIndex; |
|
|
List<String> dataIndex; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 当前用户 |
|
|
|
|
|
*/ |
|
|
|
|
|
UserByPort userByPort; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public disposeImportInventoryFileData(List<ExcelInfoByInventory> excelInfoByInventories, List<String> dataIndex) { |
|
|
public disposeImportInventoryFileData(List<ExcelInfoByInventory> excelInfoByInventories, List<String> dataIndex, UserByPort userByPort) { |
|
|
this.excelInfoByInventories = excelInfoByInventories; |
|
|
this.excelInfoByInventories = excelInfoByInventories; |
|
|
this.dataIndex = dataIndex; |
|
|
this.dataIndex = dataIndex; |
|
|
|
|
|
this.userByPort = userByPort; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@ -722,7 +875,7 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该库位无法存放当前数目的物料"; |
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该库位无法存放当前数目的物料"; |
|
|
errMsg.add(msg); |
|
|
errMsg.add(msg); |
|
|
} else { |
|
|
} else { |
|
|
excelVosForInventory.add(excelInfoByInventory); |
|
|
ExcelFileInfoPool.getUserExcelInventoryInfo(userByPort.getNumber()).add(excelInfoByInventory); |
|
|
pQuantity -= quantity; |
|
|
pQuantity -= quantity; |
|
|
placeToQuantity.put(place.getId(), pQuantity); |
|
|
placeToQuantity.put(place.getId(), pQuantity); |
|
|
} |
|
|
} |
|
|
@ -734,17 +887,152 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
} |
|
|
} |
|
|
} else { // 否则直接加入
|
|
|
} else { // 否则直接加入
|
|
|
excelInfoByInventory.setDepositoryCode("0"); // 设置默认库位
|
|
|
excelInfoByInventory.setDepositoryCode("0"); // 设置默认库位
|
|
|
excelVosForInventory.add(excelInfoByInventory); |
|
|
ExcelFileInfoPool.getUserExcelInventoryInfo(userByPort.getNumber()).add(excelInfoByInventory); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return errMsg; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用于处理导入的物料类型数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
class disposeImportMaterialTypeFileData implements Callable<List<String>> { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 待处理数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<ExcelInfoByMT> excelInfoByMTS; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 待处理数据对应在excel中的位置 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<String> dataIndex; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 当前用户 |
|
|
|
|
|
*/ |
|
|
|
|
|
UserByPort userByPort; |
|
|
|
|
|
|
|
|
|
|
|
public disposeImportMaterialTypeFileData(List<ExcelInfoByMT> excelInfoByMT, List<String> dataIndex, UserByPort userByPort) { |
|
|
|
|
|
this.excelInfoByMTS = excelInfoByMT; |
|
|
|
|
|
this.userByPort = userByPort; |
|
|
|
|
|
this.dataIndex = dataIndex; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<String> call() throws Exception { |
|
|
|
|
|
/** |
|
|
|
|
|
* 定义错误信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<String> errMsg = new ArrayList<>(); |
|
|
|
|
|
for (int i = 0; i < excelInfoByMTS.size(); i++) { |
|
|
|
|
|
ExcelInfoByMT excelInfoByMT = excelInfoByMTS.get(i); |
|
|
|
|
|
// 根据类型编码获取对应物料类型
|
|
|
|
|
|
MaterialType materialTypeByOldId = materialTypeService.findMaterialTypeByOldId(excelInfoByMT.getOldId()); |
|
|
|
|
|
if (materialTypeByOldId != null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
errMsg.add(s + "出现异常,编码为" + excelInfoByMT.getOldId() + "已存在对应类型"); |
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
ExcelFileInfoPool.getUserExcelMaterialTypeInfo(userByPort.getNumber()).add(excelInfoByMT); |
|
|
} |
|
|
} |
|
|
return errMsg; |
|
|
return errMsg; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 用于处理导入的物料数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
class disposeImportMaterialFileData implements Callable<List<String>> { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 待处理数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<ExcelInfoForMaterial> excelInfoByMaterialS; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 待处理数据对应在excel中的位置 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<String> dataIndex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 当前用户 |
|
|
|
|
|
*/ |
|
|
|
|
|
UserByPort userByPort; |
|
|
|
|
|
|
|
|
|
|
|
public disposeImportMaterialFileData(List<ExcelInfoForMaterial> excelInfoByMaterialS, List<String> dataIndex, UserByPort userByPort) { |
|
|
|
|
|
this.excelInfoByMaterialS = excelInfoByMaterialS; |
|
|
|
|
|
this.dataIndex = dataIndex; |
|
|
|
|
|
this.userByPort = userByPort; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<String> call() throws Exception { |
|
|
|
|
|
/** |
|
|
|
|
|
* 定义错误信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
List<String> errMsg = new ArrayList<>(); |
|
|
|
|
|
for (int i = 0; i < excelInfoByMaterialS.size(); i++) { |
|
|
|
|
|
ExcelInfoForMaterial excelInfoForMaterial = excelInfoByMaterialS.get(i); |
|
|
|
|
|
Map<String, Object> paramForMaterial = new HashMap<>(); |
|
|
|
|
|
String mname = excelInfoForMaterial.getMname(); |
|
|
|
|
|
if (mname == null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常,未填写物料名称"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
paramForMaterial.put("mname", mname); |
|
|
|
|
|
paramForMaterial.put("version", excelInfoForMaterial.getVersion()); |
|
|
|
|
|
Material material = materialMapper.findMaterialByMnameAndVersion(paramForMaterial); |
|
|
|
|
|
if (material != null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常,名称为:" + mname + ",型号为:" + excelInfoForMaterial.getVersion() + "的物料已存在"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (excelInfoForMaterial.getCode() != null) { |
|
|
|
|
|
Material materialByCode = materialMapper.findMaterialByCode(excelInfoForMaterial.getCode()); |
|
|
|
|
|
if (materialByCode != null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常,编码为:" + excelInfoForMaterial.getCode() + "的物料已存在"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (excelInfoForMaterial.getTypeId() == null) { |
|
|
|
|
|
if (excelInfoForMaterial.getTypeName() == null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常,未填写物料类型"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} else { |
|
|
|
|
|
MaterialType materialTypeByName = materialTypeService.findMaterialTypeByName(excelInfoForMaterial.getTypeName()); |
|
|
|
|
|
if (materialTypeByName == null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常" + excelInfoForMaterial.getTypeName() + "的物料类型不存在"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
MaterialType materialTypeByOldId = materialTypeService.findMaterialTypeByOldId(excelInfoForMaterial.getTypeId()); |
|
|
|
|
|
if (materialTypeByOldId == null) { |
|
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
|
|
String msg = s + "出现异常,类型编码为" + excelInfoForMaterial.getTypeId() + "的物料类型不存在"; |
|
|
|
|
|
errMsg.add(msg); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
ExcelFileInfoPool.getUserExcelMaterialInfo(userByPort.getNumber()).add(excelInfoForMaterial); |
|
|
|
|
|
} |
|
|
|
|
|
return errMsg; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|