|
|
|
@ -12,8 +12,6 @@ import com.dreamchaser.depository_manage.entity.*; |
|
|
|
import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper; |
|
|
|
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; |
|
|
|
import com.dreamchaser.depository_manage.mapper.MaterialMapper; |
|
|
|
import com.dreamchaser.depository_manage.pojo.InventoryP; |
|
|
|
import com.dreamchaser.depository_manage.pojo.MaterialP; |
|
|
|
import com.dreamchaser.depository_manage.service.*; |
|
|
|
import com.dreamchaser.depository_manage.utils.*; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
@ -25,12 +23,10 @@ import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.Future; |
|
|
|
import java.util.concurrent.*; |
|
|
|
|
|
|
|
import static com.dreamchaser.depository_manage.utils.FileUtil.uploadFile; |
|
|
|
|
|
|
|
@ -65,6 +61,11 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
|
@Autowired |
|
|
|
ConstructionUnitMapper constructionUnitMapper; |
|
|
|
|
|
|
|
|
|
|
|
List<ExcelInfoByInventory> excelVosForInventory = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于导入物料名称 |
|
|
|
* |
|
|
|
@ -259,187 +260,65 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
|
return ResultVoUtil.error("上传Excel文件为空"); |
|
|
|
} |
|
|
|
|
|
|
|
List<ExcelInfoByInventory> excelVos = new ArrayList<>(); |
|
|
|
|
|
|
|
// 用于保存当前库位下的存储数量
|
|
|
|
Map<Integer, Integer> placeToQuantity = new HashMap<>(); |
|
|
|
|
|
|
|
// 判断当前库位码是否正确,并存入库位中
|
|
|
|
for (int i = 0; i < excelInfoByInventories.size(); i++) { |
|
|
|
// 获取当前库存记录
|
|
|
|
ExcelInfoByInventory excelInfoByInventory = excelInfoByInventories.get(i); |
|
|
|
|
|
|
|
// 获取库存明细名称
|
|
|
|
String mname = excelInfoByInventory.getMname(); |
|
|
|
// 获取当前库存明细规格
|
|
|
|
String version = excelInfoByInventory.getVersion(); |
|
|
|
// 用于查询当前物料中是否存在该记录
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("mname", mname); |
|
|
|
map.put("version", version); |
|
|
|
List<Material> materialPByCondition = materialService.findMaterialPByConditionForTable(map); |
|
|
|
if (materialPByCondition.size() == 0) { |
|
|
|
Material materialByCode = null; |
|
|
|
if (excelInfoByInventory.getCode() != null && !"".equals(excelInfoByInventory.getCode())) { |
|
|
|
materialByCode = materialService.findMaterialByCode(excelInfoByInventory.getCode()); |
|
|
|
} |
|
|
|
if (materialByCode == null) { |
|
|
|
// 如果没有当前物料
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getMname() + " 系统中并未存在该物料"; |
|
|
|
errMsg.add(msg); |
|
|
|
continue; |
|
|
|
// 获取当前总数
|
|
|
|
int totalVal = excelInfoByInventories.size(); |
|
|
|
|
|
|
|
if(totalVal > 0){ |
|
|
|
// 定义分页数量
|
|
|
|
double size = 10.0; |
|
|
|
|
|
|
|
// 定义线程数
|
|
|
|
int threadSize = (int) Math.ceil(totalVal / size); |
|
|
|
|
|
|
|
// 定义开启线程数目
|
|
|
|
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<ExcelInfoByInventory> excelInfoByInventoryList = new ArrayList<>(); |
|
|
|
List<String> dataIndexList = new ArrayList<>(); |
|
|
|
for (int i = 0; i < excelInfoByInventories.size(); i++) { |
|
|
|
if (((i + 1) % 100) == 0) { // 如果有10个开启线程进行处理
|
|
|
|
excelInfoByInventoryList.add(excelInfoByInventories.get(i)); |
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList,dataIndexList)); |
|
|
|
openThreadSize++; |
|
|
|
futureList.add(future); // 添加到结果集
|
|
|
|
excelInfoByInventoryList = new ArrayList<>(); // 情况列表
|
|
|
|
dataIndexList = new ArrayList<>(); |
|
|
|
} else { |
|
|
|
// 添加id到列表中
|
|
|
|
excelInfoByInventoryList.add(excelInfoByInventories.get(i)); |
|
|
|
dataIndexList.add(dataIndex.get(i)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
|
// 如果导入时输入库位信息
|
|
|
|
if (placeCode != null && !placeCode.isEmpty()) { |
|
|
|
Map<String, Object> placeMap = new HashMap<>(); |
|
|
|
placeMap.put("did", depositoryId); |
|
|
|
placeMap.put("kingdeecode", placeCode); |
|
|
|
// 根据仓库及库位码获取库位
|
|
|
|
List<Place> placeByCondition = placeService.findPlaceByCondition(placeMap); |
|
|
|
if (placeByCondition.size() > 0) { |
|
|
|
// 如果有库位
|
|
|
|
Place place = placeByCondition.get(0); |
|
|
|
// 如果库位有物料且该库位存放的物料为当前物料
|
|
|
|
int quantity = (int) (ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()) * 100); |
|
|
|
// 获取当前库位的剩余存储量
|
|
|
|
Integer pQuantity = placeToQuantity.get(place.getId()); |
|
|
|
if (pQuantity == null) { |
|
|
|
pQuantity = place.getMax() - place.getQuantity(); |
|
|
|
} |
|
|
|
if (quantity > pQuantity) { |
|
|
|
// 如果当前库位无法放下
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该库位无法存放当前数目的物料"; |
|
|
|
errMsg.add(msg); |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
excelVos.add(excelInfoByInventory); |
|
|
|
pQuantity -= quantity; |
|
|
|
placeToQuantity.put(place.getId(), pQuantity); |
|
|
|
} |
|
|
|
if (excelInfoByInventoryList.size() > 0) { |
|
|
|
// 如果有剩余,开启线程进行处理
|
|
|
|
Future<List<String>> future = completionService.submit(new disposeImportInventoryFileData(excelInfoByInventoryList,dataIndexList)); |
|
|
|
futureList.add(future); |
|
|
|
openThreadSize++; |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该仓库没有该库位"; |
|
|
|
errMsg.add(msg); |
|
|
|
continue; |
|
|
|
for (int i = 0; i < openThreadSize; i++) { |
|
|
|
List<String> strings = new ArrayList<>(); |
|
|
|
try { |
|
|
|
strings = completionService.take().get(); |
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} else { // 否则直接加入
|
|
|
|
excelInfoByInventory.setDepositoryCode("0"); // 设置默认库位
|
|
|
|
excelVos.add(excelInfoByInventory); |
|
|
|
errMsg.addAll(strings); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
readResult.put("dataList", excelVos); |
|
|
|
// 4.通过线程池开启一个线程去执行数据库操作,主线程继续往下执行
|
|
|
|
// 4.1开启一个线程
|
|
|
|
TaskCenterUtil taskCenterUtil = TaskCenterUtil.getTaskCenterUtil(); |
|
|
|
Future<Object> objectFuture = taskCenterUtil.submitTask(() -> { |
|
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
Map<String, Object> returnResult = new HashMap<>(); |
|
|
|
for (ExcelInfoByInventory excelInfoByInventory : excelVos) { |
|
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
|
insert.put("mname", excelInfoByInventory.getMname()); |
|
|
|
insert.put("version", excelInfoByInventory.getVersion()); |
|
|
|
|
|
|
|
|
|
|
|
Material material = materialService.findMaterialByMnameAndVersion(insert); |
|
|
|
if (material == null) { |
|
|
|
String code = excelInfoByInventory.getCode(); |
|
|
|
if (code != null && !"".equals(code)) { |
|
|
|
material = materialService.findMaterialByCode(code); |
|
|
|
} else { |
|
|
|
material = materialMapper.findMaterialByCondition(insert).get(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 添加库存记录
|
|
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
|
Double quantity = ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()); |
|
|
|
insert.put("tempPlaceCode", excelInfoByInventory.getDepositoryCode()); |
|
|
|
insert.put("quantity", String.valueOf(quantity)); |
|
|
|
insert.put("depositoryId", depositoryId); |
|
|
|
insert.put("depositoryCode", excelInfoByInventory.getDepositoryCode()); |
|
|
|
insert.put("mid", material.getId()); |
|
|
|
|
|
|
|
// 插入库存记录
|
|
|
|
materialService.insertInventoryForImport(insert); |
|
|
|
readResult.put("dataList", excelVosForInventory); |
|
|
|
|
|
|
|
// 将该物料同时放入默认库位中
|
|
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
|
Place placeById = null; |
|
|
|
Boolean isNew = (Boolean) insert.get("isNew"); |
|
|
|
if (isNew) { |
|
|
|
SplitInfo baseSplitInfoForMid = splitUnitService.findBaseSplitInfoForMid(material.getId()); |
|
|
|
double quantity_residue = 0; |
|
|
|
if (baseSplitInfoForMid != null) { |
|
|
|
quantity_residue = quantity - Math.floor(quantity); |
|
|
|
quantity = quantity - quantity_residue; |
|
|
|
} |
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
|
// 如果是新插入物料
|
|
|
|
if (placeCode == null || placeCode.isEmpty() || "0".equals(placeCode) || "0000".equals(placeCode) || "000000".equals(placeCode)) { // 如果没有输入库位
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
// 获取默认库位
|
|
|
|
placeById = placeService.findPlaceById(0); |
|
|
|
// 修改默认库位库存
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
|
placeService.UpdatePlace(placeById); |
|
|
|
// 添加库位与物料的映射
|
|
|
|
param.put("mid", insert.get("id")); |
|
|
|
param.put("pid", 0); |
|
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
|
placeService.addMaterialOnPlace(param); |
|
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
|
} else { |
|
|
|
// 如果输入的库位不是默认库位
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("did", depositoryId); |
|
|
|
param.put("kingdeecode", placeCode); |
|
|
|
// 获取要导入的库位
|
|
|
|
placeById = placeService.findPlaceByCondition(param).get(0); |
|
|
|
// 修改库位物料数量
|
|
|
|
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
|
placeService.UpdatePlace(placeById); |
|
|
|
|
|
|
|
// 如果没有对应关系
|
|
|
|
param.put("pid", placeById.getId()); |
|
|
|
param.put("mid", insert.get("id")); |
|
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
|
// 添加对应关系
|
|
|
|
placeService.addMaterialOnPlace(param); |
|
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
|
} |
|
|
|
|
|
|
|
if (baseSplitInfoForMid != null) { |
|
|
|
Map<String, Object> insertForSplitInfoStringObjectMap = new HashMap<>(); |
|
|
|
insertForSplitInfoStringObjectMap.put("depositoryId", depositoryId); |
|
|
|
insertForSplitInfoStringObjectMap.put("quantity", quantity_residue); |
|
|
|
insertForSplitInfoStringObjectMap.put("placeId", placeById.getId().toString()); |
|
|
|
insertForSplitInfoStringObjectMap.put("mid", material.getId()); |
|
|
|
insertForSplitInfoStringObjectMap.put("unit", baseSplitInfoForMid.getNewUnit()); |
|
|
|
SplitInventory splitInventoryByIidAndSid = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), baseSplitInfoForMid.getId()); |
|
|
|
int splitInfoScaleQuantity = splitUnitService.findSplitInfoScaleQuantity(baseSplitInfoForMid, -1); |
|
|
|
splitUnitService.realInInventoryToDepository(quantity_residue * splitInfoScaleQuantity, splitInventoryByIidAndSid, insertForSplitInfoStringObjectMap, baseSplitInfoForMid, placeAndMaterialByMidAndPid, true); |
|
|
|
if (insertForSplitInfoStringObjectMap.containsKey("applicationInId")) { |
|
|
|
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForSplitInfoStringObjectMap.get("applicationInId"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
success.add(excelInfoByInventory); |
|
|
|
} |
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVos)); |
|
|
|
returnResult.put("success", success); |
|
|
|
returnResult.put("errMsg", errMsg); |
|
|
|
return ResultVoUtil.returnResultVo(200, returnResult, "结果"); |
|
|
|
}); |
|
|
|
// 4.2删除临时文件
|
|
|
|
boolean deleteFile = FileUtil.deleteFile(new File(filePath)); |
|
|
|
if (!deleteFile) { |
|
|
|
@ -632,4 +511,240 @@ public class ExcelServiceImpl implements ExcelService { |
|
|
|
} |
|
|
|
return fileNameList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于执行库存导入方法 |
|
|
|
*/ |
|
|
|
public void executeImportForInventory(){ |
|
|
|
TaskCenterUtil taskCenterUtil = TaskCenterUtil.getTaskCenterUtil(); |
|
|
|
Future<Object> objectFuture = taskCenterUtil.submitTask(() -> { |
|
|
|
List<Object> success = new ArrayList<>(); |
|
|
|
Map<String, Object> returnResult = new HashMap<>(); |
|
|
|
for (ExcelInfoByInventory excelInfoByInventory : excelVosForInventory) { |
|
|
|
Map<String, Object> insert = new HashMap<>(); |
|
|
|
insert.put("mname", excelInfoByInventory.getMname()); |
|
|
|
insert.put("version", excelInfoByInventory.getVersion()); |
|
|
|
|
|
|
|
|
|
|
|
Material material = materialService.findMaterialByMnameAndVersion(insert); |
|
|
|
if (material == null) { |
|
|
|
String code = excelInfoByInventory.getCode(); |
|
|
|
if (code != null && !"".equals(code)) { |
|
|
|
material = materialService.findMaterialByCode(code); |
|
|
|
} else { |
|
|
|
material = materialMapper.findMaterialByCondition(insert).get(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 添加库存记录
|
|
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
|
Double quantity = ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()); |
|
|
|
insert.put("tempPlaceCode", excelInfoByInventory.getDepositoryCode()); |
|
|
|
insert.put("quantity", String.valueOf(quantity)); |
|
|
|
insert.put("depositoryId", depositoryId); |
|
|
|
insert.put("depositoryCode", excelInfoByInventory.getDepositoryCode()); |
|
|
|
insert.put("mid", material.getId()); |
|
|
|
|
|
|
|
// 插入库存记录
|
|
|
|
materialService.insertInventoryForImport(insert); |
|
|
|
|
|
|
|
// 将该物料同时放入默认库位中
|
|
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
|
Place placeById = null; |
|
|
|
Boolean isNew = (Boolean) insert.get("isNew"); |
|
|
|
if (isNew) { |
|
|
|
SplitInfo baseSplitInfoForMid = splitUnitService.findBaseSplitInfoForMid(material.getId()); |
|
|
|
double quantity_residue = 0; |
|
|
|
if (baseSplitInfoForMid != null) { |
|
|
|
quantity_residue = quantity - Math.floor(quantity); |
|
|
|
quantity = quantity - quantity_residue; |
|
|
|
} |
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = null; |
|
|
|
// 如果是新插入物料
|
|
|
|
if (placeCode == null || placeCode.isEmpty() || "0".equals(placeCode) || "0000".equals(placeCode) || "000000".equals(placeCode)) { // 如果没有输入库位
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
// 获取默认库位
|
|
|
|
placeById = placeService.findPlaceById(0); |
|
|
|
// 修改默认库位库存
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
|
placeService.UpdatePlace(placeById); |
|
|
|
// 添加库位与物料的映射
|
|
|
|
param.put("mid", insert.get("id")); |
|
|
|
param.put("pid", 0); |
|
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
|
placeService.addMaterialOnPlace(param); |
|
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
|
} else { |
|
|
|
// 如果输入的库位不是默认库位
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("did", depositoryId); |
|
|
|
param.put("kingdeecode", placeCode); |
|
|
|
// 获取要导入的库位
|
|
|
|
placeById = placeService.findPlaceByCondition(param).get(0); |
|
|
|
// 修改库位物料数量
|
|
|
|
|
|
|
|
placeById.setQuantity(placeById.getQuantity() + (int) (quantity * 100)); |
|
|
|
placeService.UpdatePlace(placeById); |
|
|
|
|
|
|
|
// 如果没有对应关系
|
|
|
|
param.put("pid", placeById.getId()); |
|
|
|
param.put("mid", insert.get("id")); |
|
|
|
param.put("quantity", (int) (quantity * 100)); |
|
|
|
// 添加对应关系
|
|
|
|
placeService.addMaterialOnPlace(param); |
|
|
|
placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toInteger(param.get("id"))); |
|
|
|
} |
|
|
|
|
|
|
|
if (baseSplitInfoForMid != null) { |
|
|
|
Map<String, Object> insertForSplitInfoStringObjectMap = new HashMap<>(); |
|
|
|
insertForSplitInfoStringObjectMap.put("depositoryId", depositoryId); |
|
|
|
insertForSplitInfoStringObjectMap.put("quantity", quantity_residue); |
|
|
|
insertForSplitInfoStringObjectMap.put("placeId", placeById.getId().toString()); |
|
|
|
insertForSplitInfoStringObjectMap.put("mid", material.getId()); |
|
|
|
insertForSplitInfoStringObjectMap.put("unit", baseSplitInfoForMid.getNewUnit()); |
|
|
|
SplitInventory splitInventoryByIidAndSid = splitUnitService.findSplitInventoryByIidAndSid(placeAndMaterialByMidAndPid.getId(), baseSplitInfoForMid.getId()); |
|
|
|
int splitInfoScaleQuantity = splitUnitService.findSplitInfoScaleQuantity(baseSplitInfoForMid, -1); |
|
|
|
splitUnitService.realInInventoryToDepository(quantity_residue * splitInfoScaleQuantity, splitInventoryByIidAndSid, insertForSplitInfoStringObjectMap, baseSplitInfoForMid, placeAndMaterialByMidAndPid, true); |
|
|
|
if (insertForSplitInfoStringObjectMap.containsKey("applicationInId")) { |
|
|
|
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForSplitInfoStringObjectMap.get("applicationInId"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
success.add(excelInfoByInventory); |
|
|
|
} |
|
|
|
log.info("【批量添加】批量添加数据:{}", JSON.toJSONString(excelVosForInventory)); |
|
|
|
returnResult.put("success", success); |
|
|
|
excelVosForInventory = new ArrayList<>(); |
|
|
|
// returnResult.put("errMsg", errMsg);
|
|
|
|
return ResultVoUtil.returnResultVo(200, returnResult, "结果"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于执行物料类型导入方法 |
|
|
|
*/ |
|
|
|
public void executeImportForMaterialType(){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于清空导入的数据 |
|
|
|
*/ |
|
|
|
public void clearImportFileData(){ |
|
|
|
excelVosForInventory = new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 用于处理导入的库存数据 |
|
|
|
*/ |
|
|
|
class disposeImportInventoryFileData implements Callable<List<String>> { |
|
|
|
|
|
|
|
/** |
|
|
|
* 待处理数据 |
|
|
|
*/ |
|
|
|
List<ExcelInfoByInventory> excelInfoByInventories; |
|
|
|
|
|
|
|
/** |
|
|
|
* 待处理数据对应在excel中的位置 |
|
|
|
*/ |
|
|
|
List<String> dataIndex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public disposeImportInventoryFileData(List<ExcelInfoByInventory> excelInfoByInventories, List<String> dataIndex) { |
|
|
|
this.excelInfoByInventories = excelInfoByInventories; |
|
|
|
this.dataIndex = dataIndex; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> call() throws Exception { |
|
|
|
/** |
|
|
|
* 定义错误信息 |
|
|
|
*/ |
|
|
|
List<String> errMsg = new ArrayList<>(); |
|
|
|
|
|
|
|
// 用于保存当前库位下的存储数量
|
|
|
|
Map<Integer, Integer> placeToQuantity = new HashMap<>(); |
|
|
|
// 判断当前库位码是否正确,并存入库位中
|
|
|
|
for (int i = 0; i < excelInfoByInventories.size(); i++) { |
|
|
|
// 获取当前库存记录
|
|
|
|
ExcelInfoByInventory excelInfoByInventory = excelInfoByInventories.get(i); |
|
|
|
|
|
|
|
// 获取库存明细名称
|
|
|
|
String mname = excelInfoByInventory.getMname(); |
|
|
|
// 获取当前库存明细规格
|
|
|
|
String version = excelInfoByInventory.getVersion(); |
|
|
|
// 用于查询当前物料中是否存在该记录
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("mname", mname); |
|
|
|
map.put("version", version); |
|
|
|
List<Material> materialPByCondition = materialService.findMaterialPByConditionForTable(map); |
|
|
|
if (materialPByCondition.size() == 0) { |
|
|
|
Material materialByCode = null; |
|
|
|
if (excelInfoByInventory.getCode() != null && !"".equals(excelInfoByInventory.getCode())) { |
|
|
|
materialByCode = materialService.findMaterialByCode(excelInfoByInventory.getCode()); |
|
|
|
} |
|
|
|
if (materialByCode == null) { |
|
|
|
// 如果没有当前物料
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getMname() + " 系统中并未存在该物料"; |
|
|
|
errMsg.add(msg); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
String placeCode = excelInfoByInventory.getDepositoryCode(); |
|
|
|
Integer depositoryId = excelInfoByInventory.getDepositoryId(); |
|
|
|
// 如果导入时输入库位信息
|
|
|
|
if (placeCode != null && !placeCode.isEmpty()) { |
|
|
|
Map<String, Object> placeMap = new HashMap<>(); |
|
|
|
placeMap.put("did", depositoryId); |
|
|
|
placeMap.put("kingdeecode", placeCode); |
|
|
|
// 根据仓库及库位码获取库位
|
|
|
|
List<Place> placeByCondition = placeService.findPlaceByCondition(placeMap); |
|
|
|
if (placeByCondition.size() > 0) { |
|
|
|
// 如果有库位
|
|
|
|
Place place = placeByCondition.get(0); |
|
|
|
// 如果库位有物料且该库位存放的物料为当前物料
|
|
|
|
int quantity = (int) (ObjectFormatUtil.toDouble(excelInfoByInventory.getQuantity()) * 100); |
|
|
|
// 获取当前库位的剩余存储量
|
|
|
|
Integer pQuantity = placeToQuantity.get(place.getId()); |
|
|
|
if (pQuantity == null) { |
|
|
|
pQuantity = place.getMax() - place.getQuantity(); |
|
|
|
} |
|
|
|
if (quantity > pQuantity) { |
|
|
|
// 如果当前库位无法放下
|
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该库位无法存放当前数目的物料"; |
|
|
|
errMsg.add(msg); |
|
|
|
} else { |
|
|
|
excelVosForInventory.add(excelInfoByInventory); |
|
|
|
pQuantity -= quantity; |
|
|
|
placeToQuantity.put(place.getId(), pQuantity); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
String s = dataIndex.get(i); |
|
|
|
String msg = s + "出现异常:" + excelInfoByInventory.getDepositoryCode() + " 该仓库没有该库位"; |
|
|
|
errMsg.add(msg); |
|
|
|
} |
|
|
|
} else { // 否则直接加入
|
|
|
|
excelInfoByInventory.setDepositoryCode("0"); // 设置默认库位
|
|
|
|
excelVosForInventory.add(excelInfoByInventory); |
|
|
|
} |
|
|
|
} |
|
|
|
return errMsg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|