文件上传页面
后台代码:
@Override
public Map
{
long supplierId = 0;
Supplier supplier = null;
if (context.getMemberId() != 0)
{
supplier = supplierService.getSupplierByMemberId(context.getMemberId());
}
if (ObjectUtils.notNull(supplier))
{
supplierId = supplier.getId();
}
if (isCover)
{
List
if (ObjectUtils.notEmpty(steelResources))
{
for (SteelResource steelResource : steelResources)
{
if (SteelResource.STATUS_SELL == steelResource.getStatus()
&& (steelResource.getOnboardItems() > 0 || steelResource.getOnboardQty() > 0))
{
resourcePriceSummaryThread.collect(steelResource.getSummaryCode());
}
}
}
try
{
mqService.append(DocumentUtil.STEELRESOURCE_PUBLISH_QUEUE, supplierId + "|d");
}
catch (MQException e)
{
e.printStackTrace();
}
}
Map
// 不能正确解析的资源
List
// 可以正确解析的资源列表
List
// 如果上传的Excel中有捆包号相同的资源,则只保留一条
Map
// 当前解析的进度
cacheService.set("precent" + randomNum, "0");
// 对上传的资源进行解析,处理
List
try
{
// 当前解析的进度
cacheService.set("precent" + randomNum, "10");
// excel传入解析后的资源
excelResourcesList = importShopResource(content, context.getMemberId());
// 当前解析的进度
cacheService.set("precent" + randomNum, "20");
}
catch (Exception e)
{
e.printStackTrace();
}
// 正确解析了的资源条数
int rightResourcesSize = 0;
// 不能正确解析的资源条数
int wrongResourcesSize = 0;
// 捆包号重复的资源条数
int samePackgeNoResourcesSize = 0;
if (excelResourcesList != null)
{
int count = 0;
int percent = 20;
for (ResourceInventoryParseDTO resource : excelResourcesList)
{
count++;
// 解析错误标志
int[] wrongFlag = new int[9];
// 解析错误的原因
String wrongReason = "";
ResourceDTO resourceDTO = new ResourceDTO();
// 获取上传资源的品名、材质、规格、品牌产地、仓库
String breedAlias = resource.getCategoryAlias();
String materialAlias = resource.getMaterialAlias();
String specAlias = resource.getSpecAlias();
String brandAlias = resource.getFactoryAlias();
String warehouseAlias = resource.getWarehouseAlias();
// 解析品名
MarketBreed breed = catalogService.getMarketBreedByKey(breedAlias.replace(" ", ""));
if (StringUtils.isTrimEmpty(breedAlias))
{
// 缺失品名的情况直接跳过
wrongReason += "品名缺失 ";
continue;
}
else if (ObjectUtils.isNull(breed))
{
breed = catalogService.getMarketBreedByBreedAlias(breedAlias);
if (ObjectUtils.isNull(breed))
{
wrongReason += "品名非标 ";
wrongFlag[0] = 1;
resourceDTO.setBreed(breedAlias);
}
else
{
resourceDTO.setBreed(breed.getName());
resourceDTO.setBreedId(breed.getId());
}
}
else
{
resourceDTO.setBreed(breed.getName());
resourceDTO.setBreedId(breed.getId());
}
// 解析规格
if (StringUtils.isTrimEmpty(specAlias))
{
wrongReason += "规格缺失 ";
wrongFlag[1] = 1;
}
else if (specAlias.length() > 60)
{
wrongReason += "规格过长 ";
wrongFlag[1] = 1;
}
else
{
resourceDTO.setSpec(specAlias);
}
// 解析牌号material
if (StringUtils.isTrimEmpty(materialAlias))
{
wrongReason += "牌号为空 ";
wrongFlag[2] = 1;
}
else if (materialAlias.length() > 60)
{
wrongReason += "牌号长度过长 ";
wrongFlag[2] = 1;
}
else
{
resourceDTO.setMaterial(materialAlias);
}
// 解析产地/品牌brand
if (StringUtils.isTrimEmpty(brandAlias))
{
wrongReason += "产地/品牌为空 ";
wrongFlag[3] = 1;
}
else if (brandAlias.length() > 60)
{
wrongReason += "产地/品牌过长 ";
wrongFlag[3] = 1;
}
else
{
resourceDTO.setBrand(brandAlias);
}
// 解析仓库 同时解析交货地
Warehouse warehouseEntity = catalogService.getWarehouseByKey(warehouseAlias.replace(" ", ""));
if (StringUtils.isTrimEmpty(warehouseAlias))
{
wrongReason += "仓库为空 ";
wrongFlag[4] = 1;
}
else if (warehouseAlias.length() > 20)
{
wrongReason += "仓库名称过长 ";
wrongFlag[4] = 1;
}
else
{
if (ObjectUtils.isNull(warehouseEntity))
{
String warehouse = catalogService.getAliasWarehouse(warehouseAlias);
if (StringUtils.isTrimEmpty(warehouse))
{
wrongReason += "仓库名称非标 ";
wrongFlag[4] = 1;
resourceDTO.setWarehouse(warehouseAlias);
resourceDTO.setCity(resource.getAreaName());
}
else
{
resourceDTO.setWarehouse(warehouse);
// 获取仓库对应的城市
City city = catalogService.getCityByWarehouse(warehouse);
if (ObjectUtils.notNull(city))
{
resourceDTO.setCity(city.getName());
resourceDTO.setCityId(city.getId());
}
}
}
else
{
resourceDTO.setWarehouse(warehouseEntity.getName());
// 获取仓库对应的城市
City city = catalogService.getCityByWarehouse(warehouseEntity.getName());
if (ObjectUtils.notNull(city))
{
resourceDTO.setCity(city.getName());
resourceDTO.setCityId(city.getId());
}
}
}
// 解析计重方式 0-理重 1-过磅2-抄码
String weightWay = resource.getWeightWay();
if (!StringUtils.isTrimEmpty(weightWay) && "过磅".equals(weightWay.trim()))
{
resourceDTO.setWeightWay(1);
}
else if (!StringUtils.isTrimEmpty(weightWay) && "抄码".equals(weightWay.trim()))
{
resourceDTO.setWeightWay(2);
}
else
{
resourceDTO.setWeightWay(0);
}
// 解析件重件重不大于100
Double averageQty = resource.getAverageQty();
if (averageQty == null)
{
wrongReason += "件重为空 ";
wrongFlag[5] = 1;
}
else if (averageQty < 0 || averageQty >= 100)
{
wrongReason += "件重不能小于0且不能大于100 ";
wrongFlag[5] = 1;
}
else
{
resourceDTO.setAverageQty(averageQty);
}
// 解析件数
Integer inItems = resource.getInItems();
if (inItems == null)
{
wrongReason += "件数为空 ";
wrongFlag[6] = 1;
}
else if (inItems <= 0)
{
wrongReason += "件数必须要>=0 ";
wrongFlag[6] = 1;
}
else
{
resourceDTO.setInItems(inItems);
resourceDTO.setInQty(NumberTools.multi(inItems, averageQty));
}
// 解析发布价格
Double onboardPrice = resource.getBasePrice();
if (onboardPrice == null)
{
wrongReason += "发布价格为空 ";
wrongFlag[7] = 1;
}
else
{
resourceDTO.setOnboardPrice(onboardPrice);
}
// 解析备注
String note = resource.getRemark();
if (StringUtils.notTrimEmpty(note))
{
if (note.length() > 200)
{
wrongReason += "备注长度过长 ";
}
else
{
resourceDTO.setNote(note);
}
}
// 拿到捆包号
String serialNo = resource.getPackageNo();
try
{
BigDecimal bd = new BigDecimal(serialNo);
serialNo = bd.toPlainString();
}
catch (Exception e)
{
// 转换出问题说明是非纯数字
serialNo = resource.getPackageNo();
}
if (StringUtils.isTrimEmpty(serialNo))
{
// 允许捆包号为空,捆包号为空,如果品名、仓库并非非标,则解析正确,保存
resourceDTO.setSerialNo("");
if (StringUtils.isTrimEmpty(wrongReason))
{
rightResourcesList.add(resourceDTO);
rightResourcesSize++;
}
else
{
resourceDTO.setWrongReson(wrongReason);
resourceDTO.setWrongFlag(wrongFlag);
wrongResourcesList.add(resourceDTO);
wrongResourcesSize++;
}
}
else
{
// 解决Excel中资源捆包号冲突的问题
if (noSamePackageNoMap.get(serialNo) != null)
{
continue;
}
List
.querySteelResourceByMemberIdAndSerialNo(context.getMemberId(), serialNo);
if (ObjectUtils.notNull(steelResources) && !steelResources.isEmpty())
{
wrongFlag[8] = 1;
wrongReason += "捆包号重复 ";
resourceDTO.setWrongReson(wrongReason);
resourceDTO.setWrongFlag(wrongFlag);
samePackgeNoResourcesSize++;
resourceDTO.setSerialNo(serialNo);
}
else
{
resourceDTO.setWrongReson(wrongReason);
resourceDTO.setWrongFlag(wrongFlag);
resourceDTO.setSerialNo(serialNo);
}
noSamePackageNoMap.put(resourceDTO.getSerialNo(), resourceDTO);
}
//每循环一次,统计循环次数,计算进度
percent = (int) (20 + NumberTools.multi(NumberTools.div(count, excelResourcesList.size()), 60));
cacheService.set("precent" + randomNum, percent + "");
}
// 如果上传的资源有捆包号重复的,则前边一条被后边一条覆盖
for (Entry
{
if (StringUtils.isTrimEmpty(entry.getValue().getWrongReson()))
{
rightResourcesList.add(entry.getValue());
rightResourcesSize++;
}
else
{
wrongResourcesList.add(entry.getValue());
wrongResourcesSize++;
}
}
// 解析正确的资源将直接保存
if (!rightResourcesList.isEmpty())
{
// 获取供应商组ID
List
if (ObjectUtils.notNull(supplierGroupList) && !supplierGroupList.isEmpty())
{
marketResourcePublish(rightResourcesList, supplierGroupList.get(0), context, supplierId);
}
}
returnMap.put("wrongResourcesList", wrongResourcesList);
returnMap.put("rightResourcesSize", rightResourcesSize);
returnMap.put("wrongResourcesSize", wrongResourcesSize);
returnMap.put("samePackgeNoResourcesSize", samePackgeNoResourcesSize);
cacheService.set("wrongResourceDataMap" + randomNum, JSON.toJSONString(returnMap), 120);
// 当前解析的进度
cacheService.set("precent" + randomNum, "100", 120);
}
return returnMap;
}
/**
*
* @description: 跳转到显示进度条的页面
* @param request
* @return
* @author: matao
* @createTime:2015年6月25日 下午8:09:13
*/
@RequestMapping(value = "/excel_publish_progress")
public ModelAndView excelPublishProgress(@RequestParam(required = true) String randomNum)
{
return new ModelAndView("/resource/inventory/excel_publish_progress", "randomNum", randomNum);
}
进度条窗口页面:
//展示错误的数据
@Override
public Map
{
Map
String precent = cacheService.get("precent" + randomNum);
returnMap.put("precent", precent);
if (NumberUtils.parseInt(precent) == 100)
{
String wrongResourceData = cacheService.get("wrongResourceDataMap" + randomNum);
if (StringUtils.notTrimEmpty(wrongResourceData))
{
JSONObject jsonObject = JSONObject.parseObject(wrongResourceData);
returnMap.put("wrongResourcesList", jsonObject.get("wrongResourcesList"));
returnMap.put("wrongResourcesSize", jsonObject.get("wrongResourcesSize"));
returnMap.put("rightResourcesSize", jsonObject.get("rightResourcesSize"));
returnMap.put("samePackgeNoResourcesSize", jsonObject.get("samePackgeNoResourcesSize"));
}
}
return returnMap;
}
错误数据展示页面