|
@@ -984,9 +984,17 @@ public class StockManageAction implements IMINAction {
|
|
|
int num = 0;
|
|
|
|
|
|
List<String> stockIdList = new ArrayList<String>();
|
|
|
+
|
|
|
+ List<String> checkedWareName = new ArrayList<String>();
|
|
|
// 校验仓库的放在前面,避免部分数据提交后明细总重量不更新
|
|
|
for (int i = 0; i < goodsArray.size(); i++) {
|
|
|
Map<String, String> map = (Map<String, String>)goodsArray.get(i);
|
|
|
+ // 校验过的不再校验
|
|
|
+ if(checkedWareName.contains(map.get("warehouseName").trim())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ checkedWareName.add(map.get("warehouseName").trim());
|
|
|
+
|
|
|
OwnApWarehouseInfExample wareEx = new OwnApWarehouseInfExample(user.getBranchId());
|
|
|
wareEx.createCriteria().andNameEqualTo(map.get("warehouseName").trim()).andStateEqualTo("00");
|
|
|
wareEx.branchIdQuery();
|
|
@@ -1009,27 +1017,53 @@ public class StockManageAction implements IMINAction {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 检查过的订单信息
|
|
|
+ Map<String, ApOrderInf> orderInfMap = new HashMap<String, ApOrderInf>();
|
|
|
+ // 查询过的合同信息
|
|
|
+ Map<String, ApContractInf> contractInfMap = new HashMap<>();
|
|
|
+ // 查询过的合同信息
|
|
|
+ Map<String, ApContractDetail> contractInfDetailMap = new HashMap<>();
|
|
|
+ // 查询过的品牌
|
|
|
+ Map<String, ApBrandInf> brandInfMap = new HashMap<>();
|
|
|
+ // 查询过的产品
|
|
|
+ Map<String, ApProductInf> productInfMap = new HashMap<>();
|
|
|
+ // 查询过的规格信息
|
|
|
+ Map<String, ApProductSpecRel> productSpecRelMap = new HashMap<>();
|
|
|
+ // 查询过的仓库信息
|
|
|
+ Map<String, ApWarehouseInf> warehouseInfMap = new HashMap<>();
|
|
|
+ // 查询过的仓储合同信息
|
|
|
+ Map<String, ApWarehouseContract> warehouseContractMap = new HashMap<>();
|
|
|
+
|
|
|
for (int i = 0; i < goodsArray.size(); i++) {
|
|
|
Map<String, String> map = (Map<String, String>)goodsArray.get(i);
|
|
|
- if(modelType.equals("01")) {
|
|
|
- //校验订单是否存在
|
|
|
- ApOrderInfExample example = new ApOrderInfExample();
|
|
|
- example.createCriteria().andNameEqualTo(map.get("orderId").trim()).andStateNotEqualTo("04");
|
|
|
- List<ApOrderInf> orderInf = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApOrderInfMapper.class)
|
|
|
- .selectByExample(example);
|
|
|
- if(orderInf.size() <=0){
|
|
|
- throw new MINBusinessException("第"+(i+1)+"条数据订单信息不存在,请检查订单编号");
|
|
|
+
|
|
|
+ // 从查询过的数据中取数
|
|
|
+ ApOrderInf orderInf = orderInfMap.get(map.get("orderId").trim());
|
|
|
+ // 只校验未查询的订单
|
|
|
+ if(orderInf == null) {
|
|
|
+ if(modelType.equals("01")) {
|
|
|
+ //校验订单是否存在
|
|
|
+ ApOrderInfExample example = new ApOrderInfExample();
|
|
|
+ example.createCriteria().andNameEqualTo(map.get("orderId").trim()).andStateNotEqualTo("04");
|
|
|
+ List<ApOrderInf> orderInfList = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApOrderInfMapper.class)
|
|
|
+ .selectByExample(example);
|
|
|
+ if(orderInfList.size() <=0){
|
|
|
+ throw new MINBusinessException("第"+(i+1)+"条数据订单信息不存在,请检查订单编号");
|
|
|
+ }
|
|
|
+ orderInf = orderInfList.get(0);
|
|
|
+ orderInfMap.put(map.get("orderId").trim(), orderInfList.get(0));
|
|
|
}
|
|
|
- contractId = orderInf.get(0).getContractId();
|
|
|
- orderID = orderInf.get(0).getId();
|
|
|
}
|
|
|
+ contractId = orderInf.getContractId();
|
|
|
+ orderID = orderInf.getId();
|
|
|
|
|
|
//判断是否重复导入
|
|
|
ApWarehouseDetailExample deWxample = new ApWarehouseDetailExample();
|
|
|
deWxample.createCriteria().andTypeNotEqualTo("99").andOrderIdEqualTo(orderID)
|
|
|
.andBoxNoEqualTo(map.get("boxNo").trim()).andWeightEqualTo(map.get("weight").trim());
|
|
|
- List<ApWarehouseDetail> deList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ApWarehouseDetailMapper.class)
|
|
|
+ List<ApWarehouseDetail> deList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ApWarehouseDetailMapper.class)
|
|
|
.selectByExample(deWxample);
|
|
|
|
|
|
if(deList.size() > 0){
|
|
@@ -1037,81 +1071,131 @@ public class StockManageAction implements IMINAction {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- ApContractInf conTract = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApContractInfMapper.class)
|
|
|
- .selectByPrimaryKey(contractId);
|
|
|
+ // 从map中取数据,减少查询次数
|
|
|
+ ApContractInf conTract = contractInfMap.get(contractId);
|
|
|
+ if(conTract == null) {
|
|
|
+ conTract = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApContractInfMapper.class)
|
|
|
+ .selectByPrimaryKey(contractId);
|
|
|
+ if(conTract != null) {
|
|
|
+ contractInfMap.put(contractId, conTract);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(conTract!= null) {
|
|
|
conType = conTract.getContractType();
|
|
|
}
|
|
|
- ApContractDetailExample example1 = new ApContractDetailExample();
|
|
|
- example1.createCriteria().andContractIdEqualTo(contractId).andStateEqualTo("00");
|
|
|
- List<ApContractDetail> detail = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApContractDetailMapper.class)
|
|
|
- .selectByExample(example1);
|
|
|
- if(detail.size()>0) {
|
|
|
- price = detail.get(0).getPrice();
|
|
|
+
|
|
|
+ ApContractDetail contractDetail = contractInfDetailMap.get(contractId);
|
|
|
+ if(contractDetail == null) {
|
|
|
+ ApContractDetailExample example1 = new ApContractDetailExample();
|
|
|
+ example1.createCriteria().andContractIdEqualTo(contractId).andStateEqualTo("00");
|
|
|
+ List<ApContractDetail> detail = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApContractDetailMapper.class)
|
|
|
+ .selectByExample(example1);
|
|
|
+ if(detail.size()>0) {
|
|
|
+ price = detail.get(0).getPrice();
|
|
|
+ contractInfDetailMap.put(contractId, detail.get(0));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ price = contractDetail.getPrice();
|
|
|
}
|
|
|
+
|
|
|
+ // 获取品牌id
|
|
|
+ String brandId;
|
|
|
// 判断品牌是否存在
|
|
|
- ApBrandInfExample brandInfExample = new ApBrandInfExample();
|
|
|
- brandInfExample.createCriteria().andNameEqualTo(map.get("brand").trim())
|
|
|
- .andStateEqualTo("0");
|
|
|
- List<ApBrandInf> list = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApBrandInfMapper.class)
|
|
|
- .selectByExample(brandInfExample);
|
|
|
- if (list.size() == 0) {
|
|
|
- throw new MINBusinessException("第"+(i+1)+"条数据品牌不存在,请检查品牌名称");
|
|
|
+ ApBrandInf brandInf = brandInfMap.get(map.get("brand").trim());
|
|
|
+ if(brandInf == null) {
|
|
|
+ ApBrandInfExample brandInfExample = new ApBrandInfExample();
|
|
|
+ brandInfExample.createCriteria().andNameEqualTo(map.get("brand").trim())
|
|
|
+ .andStateEqualTo("0");
|
|
|
+ List<ApBrandInf> list = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApBrandInfMapper.class)
|
|
|
+ .selectByExample(brandInfExample);
|
|
|
+ if (list.size() == 0) {
|
|
|
+ throw new MINBusinessException("第"+(i+1)+"条数据品牌不存在,请检查品牌名称");
|
|
|
+ }
|
|
|
+ brandInfMap.put(map.get("brand").trim(), list.get(0));
|
|
|
+ brandId = list.get(0).getId();
|
|
|
+ } else {
|
|
|
+ brandId = brandInf.getId();
|
|
|
}
|
|
|
- // 获取品牌id
|
|
|
- String brandId = list.get(0).getId();
|
|
|
|
|
|
+ //获取产品id
|
|
|
+ String productId;
|
|
|
//判断产品是否存在
|
|
|
- ApProductInfExample productInfExample = new ApProductInfExample();
|
|
|
- productInfExample.createCriteria().andNameEqualTo(map.get("productName").trim())
|
|
|
-// .andBrandIdEqualTo(brandId)
|
|
|
- .andStateEqualTo("00");
|
|
|
- List<ApProductInf> list2 = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApProductInfMapper.class)
|
|
|
- .selectByExample(productInfExample);
|
|
|
- if(list2.size() == 0){
|
|
|
- throw new MINBusinessException("第"+(i+1)+"条数据产品不存在,请检查产品名称");
|
|
|
+ ApProductInf productInf = productInfMap.get(map.get("productName").trim());
|
|
|
+ if(productInf == null) {
|
|
|
+ ApProductInfExample productInfExample = new ApProductInfExample();
|
|
|
+ productInfExample.createCriteria().andNameEqualTo(map.get("productName").trim())
|
|
|
+ .andStateEqualTo("00");
|
|
|
+ List<ApProductInf> list2 = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApProductInfMapper.class)
|
|
|
+ .selectByExample(productInfExample);
|
|
|
+ if(list2.size() == 0){
|
|
|
+ throw new MINBusinessException("第"+(i+1)+"条数据产品不存在,请检查产品名称");
|
|
|
+ }
|
|
|
+ productInfMap.put(map.get("productName").trim(), list2.get(0));
|
|
|
+ productId = list2.get(0).getId();
|
|
|
+ } else {
|
|
|
+ productId = productInf.getId();
|
|
|
}
|
|
|
- //获取地址id
|
|
|
- String productId = list2.get(0).getId();
|
|
|
|
|
|
+ // 获取规格编号
|
|
|
+ String specNo;
|
|
|
//判断是商品规格是否正确
|
|
|
- ApProductSpecRelExample relExample = new ApProductSpecRelExample();
|
|
|
- relExample.createCriteria().andProductIdEqualTo(productId)
|
|
|
- .andValueEqualTo(map.get("standard").trim())
|
|
|
- .andStateEqualTo("0");
|
|
|
- List<ApProductSpecRel> list3 = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApProductSpecRelMapper.class)
|
|
|
- .selectByExample(relExample);
|
|
|
- if(list3.size() == 0){
|
|
|
- throw new MINBusinessException("第"+(i+1)+"条数据规格不存在,请检查规格值");
|
|
|
+ ApProductSpecRel productSpecRel = productSpecRelMap.get(productId + "_" + map.get("standard").trim());
|
|
|
+ if(productSpecRel == null) {
|
|
|
+ ApProductSpecRelExample relExample = new ApProductSpecRelExample();
|
|
|
+ relExample.createCriteria().andProductIdEqualTo(productId)
|
|
|
+ .andValueEqualTo(map.get("standard").trim())
|
|
|
+ .andStateEqualTo("0");
|
|
|
+ List<ApProductSpecRel> list3 = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApProductSpecRelMapper.class)
|
|
|
+ .selectByExample(relExample);
|
|
|
+ if(list3.size() == 0){
|
|
|
+ throw new MINBusinessException("第"+(i+1)+"条数据规格不存在,请检查规格值");
|
|
|
+ }
|
|
|
+ productSpecRelMap.put(productId + "_" + map.get("standard").trim(), list3.get(0));
|
|
|
+ specNo = list3.get(0).getSpecNo();
|
|
|
+ } else {
|
|
|
+ specNo = productSpecRel.getSpecNo();
|
|
|
}
|
|
|
|
|
|
- //校验仓库是否存在
|
|
|
- OwnApWarehouseInfExample wareEx = new OwnApWarehouseInfExample(user.getBranchId());
|
|
|
- wareEx.createCriteria().andNameEqualTo(map.get("warehouseName").trim()).andStateEqualTo("00");
|
|
|
- wareEx.branchIdQuery();
|
|
|
- List<ApWarehouseInf> warehouseList = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApWarehouseInfMapper.class)
|
|
|
- .selectByExample(wareEx);
|
|
|
- //获取仓库id
|
|
|
- String warehouseId = warehouseList.get(0).getId();
|
|
|
+ //获取仓库id, 可优化,前面已经查询过一次仓库信息 TODO
|
|
|
+ String warehouseId;
|
|
|
+ ApWarehouseInf warehouseInf = warehouseInfMap.get(map.get("warehouseName").trim());
|
|
|
+ if(warehouseInf == null) {
|
|
|
+ //校验仓库是否存在
|
|
|
+ OwnApWarehouseInfExample wareEx = new OwnApWarehouseInfExample(user.getBranchId());
|
|
|
+ wareEx.createCriteria().andNameEqualTo(map.get("warehouseName").trim()).andStateEqualTo("00");
|
|
|
+ wareEx.branchIdQuery();
|
|
|
+ List<ApWarehouseInf> warehouseList = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApWarehouseInfMapper.class)
|
|
|
+ .selectByExample(wareEx);
|
|
|
+ warehouseInfMap.put(map.get("warehouseName").trim(), warehouseList.get(0));
|
|
|
+ warehouseId = warehouseList.get(0).getId();
|
|
|
+ } else {
|
|
|
+ warehouseId = warehouseInf.getId();
|
|
|
+ }
|
|
|
|
|
|
- ApWarehouseContractExample awcEx = new ApWarehouseContractExample();
|
|
|
- awcEx.createCriteria().andWarehouseIdEqualTo(warehouseId)
|
|
|
- .andCompanyIdEqualTo(companyId)
|
|
|
- .andStateEqualTo("00")
|
|
|
- .andStartDateLessThanOrEqualTo(nowDate)
|
|
|
- .andEndDateGreaterThanOrEqualTo(nowDate)
|
|
|
- .andBranchIdEqualTo(user.getBranchId());
|
|
|
- List<ApWarehouseContract> awcList = Service.lookup(IMINDataBaseService.class)
|
|
|
- .getMybatisMapper(ApWarehouseContractMapper.class)
|
|
|
- .selectByExample(awcEx);
|
|
|
- if(awcList.size() == 0){
|
|
|
- throw new MINBusinessException("第"+(i+1)+"条合同信息有误,请检查仓库合同是否存在!");
|
|
|
+ // 校验仓储合同信息
|
|
|
+ ApWarehouseContract warehouseContract = warehouseContractMap.get(warehouseId);
|
|
|
+ if(warehouseContract == null) {
|
|
|
+ ApWarehouseContractExample awcEx = new ApWarehouseContractExample();
|
|
|
+ awcEx.createCriteria().andWarehouseIdEqualTo(warehouseId)
|
|
|
+ .andCompanyIdEqualTo(companyId)
|
|
|
+ .andStateEqualTo("00")
|
|
|
+ .andStartDateLessThanOrEqualTo(nowDate)
|
|
|
+ .andEndDateGreaterThanOrEqualTo(nowDate)
|
|
|
+ .andBranchIdEqualTo(user.getBranchId());
|
|
|
+ List<ApWarehouseContract> awcList = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ApWarehouseContractMapper.class)
|
|
|
+ .selectByExample(awcEx);
|
|
|
+ if(awcList.size() == 0){
|
|
|
+ throw new MINBusinessException("第"+(i+1)+"条合同信息有误,请检查仓库合同是否存在!");
|
|
|
+ }
|
|
|
+ warehouseContractMap.put(warehouseId, awcList.get(0));
|
|
|
}
|
|
|
|
|
|
//获取库存ID
|
|
@@ -1120,16 +1204,14 @@ public class StockManageAction implements IMINAction {
|
|
|
record.setId(id); //物流ID
|
|
|
|
|
|
// 00:单条记录 01:多条记录
|
|
|
- if(modelType.equals("00")) {
|
|
|
- record.setOrderId(orderID); //订单id
|
|
|
- }else if(modelType.equals("01")) {
|
|
|
+ if(modelType.equals("00") || modelType.equals("01")) {
|
|
|
record.setOrderId(orderID); //订单id
|
|
|
}
|
|
|
// 参与导入的orderId
|
|
|
orderIdMap.put(record.getOrderId(), record.getOrderId());
|
|
|
|
|
|
record.setWarehouseId(warehouseId); //仓库id
|
|
|
- record.setStandardId(list3.get(0).getSpecNo()); //商品规格id
|
|
|
+ record.setStandardId(specNo); //商品规格id
|
|
|
if(conType.equals("01")) {
|
|
|
record.setUnitPrice(price); //单价
|
|
|
}else {
|
|
@@ -1137,8 +1219,8 @@ public class StockManageAction implements IMINAction {
|
|
|
}
|
|
|
// 获取当前订单商品的库存表编号
|
|
|
Map<String,Object> stockmap = new HashMap<String,Object>();
|
|
|
- stockmap.put("warehouseId",warehouseList.get(0).getId()); //仓库名称
|
|
|
- stockmap.put("spId",list3.get(0).getSpecNo()); //产品名称
|
|
|
+ stockmap.put("warehouseId", warehouseId); //仓库名称
|
|
|
+ stockmap.put("spId", specNo); //产品名称
|
|
|
stockmap.put("orderId",orderID); //订单号
|
|
|
stockmap.put("stockType","00"); //入库:00 出库:01 冲正入库:02 冲正出库:03
|
|
|
stockmap.put("abfId", brandId);
|