📄 uploadexcleserviceimpl.java
字号:
package com.iplan.portal.order.service;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;
import com.iplan.portal.framework.base.BaseService;
import com.iplan.portal.order.pojo.Customer;
import com.iplan.portal.order.pojo.OrderInfo;
import com.iplan.portal.order.pojo.Warehouse;
/**
* http://www.hao-se.cn
*
* @author ws
*/
public class UploadExcleServiceImpl extends BaseService implements
IUploadExcleService {
/** �? * */
private static final int ROW = 6;
/** �? * */
private static final int COL = 0;
public boolean uploadExcle(InputStream in, String userId, String areaId,
IOrderService orderService, ICustomerService customerService,
IWarehouseService warehouseService) {
boolean result = true;
Map customerMap = new HashMap();
Map warehouseMap = new HashMap();
try {
Workbook workbook = Workbook.getWorkbook(in);
// 读取缺货统计的sheet
Sheet rsNO = workbook.getSheet(0);
uploadNO(rsNO, userId, areaId, orderService, customerService,
warehouseService, customerMap, warehouseMap);
// 读取处理完毕的订单的sheet
Sheet rsOK = workbook.getSheet(1);
uploadOK(rsOK, userId, areaId, orderService, customerService,
warehouseService, customerMap, warehouseMap);
} catch (Exception e) {
result = false;
logger.error("Method:uploadExcle(...):上载Excle失败!", e);
}
return result;
}
private void uploadOK(Sheet rs, String userId, String areaId,
IOrderService orderService, ICustomerService customerService,
IWarehouseService warehouseService, Map customerMap,
Map warehouseMap) {
boolean isLast = false;
int index = 0;
Object signCustomer;
Object signWarehouse;
OrderInfo orderInfo;
Customer customer;
Warehouse warehouse;
String orderno = "";
Date orderdate = null;
String customername = "";
String warehouseid = "";
String printingdateStr = "";
Date printingdate = null;
while (!isLast) {
orderInfo = new OrderInfo();
try {
orderno = rs.getCell(COL, ROW + index).getContents();
} catch (Exception e) {
return;
}
if (orderno == null || "".equals(orderno)) {
return;
} else {
orderno = orderno.toUpperCase();
}
// orderdate = DateUtil.convertStringToDate(rs.getCell(COL + 1,
// ROW + index).getContents());
orderdate = convertCellType(rs.getCell(COL + 1, ROW + index));
customername = rs.getCell(COL + 2, ROW + index).getContents();
warehouseid = rs.getCell(COL + 3, ROW + index).getContents();
printingdateStr = rs.getCell(COL + 4, ROW + index).getContents();
if (printingdateStr != null && !"".equals(printingdateStr)) {
// printingdate = DateUtil.convertStringToDate(printingdateStr);
printingdate = convertCellType(rs.getCell(COL + 4, ROW + index));
}
orderInfo.setOrderNo(orderno);
orderInfo.setOrderDate(orderdate);
orderInfo.setCustomerName(customername);
orderInfo.setWarehouseId(warehouseid);
if (printingdate != null) {
orderInfo.setPrintingDate(printingdate);
orderInfo.setHandmadeFlg("NO");
} else {
orderInfo.setHandmade(printingdateStr);
orderInfo.setHandmadeFlg("OK");
}
orderInfo.setOk("OK");
orderInfo.setCreatetime(new Date());
orderInfo.setUpdatetime(new Date());
orderInfo.setUserId(userId);
orderInfo.setAreaid(areaId);
// 保存订单信息
orderService.saveOrderInfo(orderInfo);
if (customername != null && !"".equals(customername.trim())) {
signCustomer = customerMap.get(customername);
if (signCustomer == null) {
customer = new Customer();
customer.setCreatetime(new Date());
customer.setUpdatetime(new Date());
customer.setUserId(userId);
customer.setAreaid(areaId);
customer.setCustomerName(customername);
customer.setAddress("");
customerService.saveCustomer(customer);
customerMap.put(customername, customername);
}
}
if (warehouseid != null && !"".equals(warehouseid.trim())) {
signWarehouse = warehouseMap.get(warehouseid);
if (signWarehouse == null) {
warehouse = new Warehouse();
warehouse.setCreatetime(new Date());
warehouse.setUpdatetime(new Date());
warehouse.setWarehouseId(warehouseid);
warehouse.setWarehouseName(warehouseid);
warehouseService.saveWarehouse(warehouse);
warehouseMap.put(warehouseid, warehouseid);
}
}
index++;
}
}
private void uploadNO(Sheet rs, String userId, String areaId,
IOrderService orderService, ICustomerService customerService,
IWarehouseService warehouseService, Map customerMap,
Map warehouseMap) {
boolean isLast = false;
int index = 0;
Object signCustomer;
Object signWarehouse;
OrderInfo orderInfo;
Customer customer;
Warehouse warehouse;
String orderno = "";
Date orderdate;
String customername = "";
String warehouseid = "";
Date inputdate;
String effectiveinfo = "";
String printingdateStr = "";
Date printingdate = null;
String shorting = "";
String amount = "";
String track = "";
String remark = "";
while (!isLast) {
orderInfo = new OrderInfo();
try {
orderno = rs.getCell(COL, ROW + index).getContents();
} catch (Exception e) {
return;
}
if (orderno == null || "".equals(orderno)) {
return;
} else {
orderno = orderno.toUpperCase();
}
// orderdate = DateUtil.convertStringToDate(rs.getCell(COL + 1,
// ROW + index).getContents());
orderdate = convertCellType(rs.getCell(COL + 1, ROW + index));
customername = rs.getCell(COL + 2, ROW + index).getContents();
warehouseid = rs.getCell(COL + 3, ROW + index).getContents();
// inputdate = DateUtil.convertStringToDate(rs.getCell(COL + 4,
// ROW + index).getContents());
inputdate = convertCellType(rs.getCell(COL + 4, ROW + index));
effectiveinfo = rs.getCell(COL + 5, ROW + index).getContents();
printingdateStr = rs.getCell(COL + 6, ROW + index).getContents();
if (printingdateStr != null && !"".equals(printingdateStr)) {
// printingdate = DateUtil.convertStringToDate(printingdateStr);
printingdate = convertCellType(rs.getCell(COL + 6, ROW + index));
}
shorting = rs.getCell(COL + 7, ROW + index).getContents();
amount = rs.getCell(COL + 8, ROW + index).getContents();
track = rs.getCell(COL + 9, ROW + index).getContents();
remark = rs.getCell(COL + 10, ROW + index).getContents();
orderInfo.setOrderNo(orderno);
orderInfo.setOrderDate(orderdate);
orderInfo.setCustomerName(customername);
orderInfo.setWarehouseId(warehouseid);
orderInfo.setInputDate(inputdate);
orderInfo.setEffectiveInfo(effectiveinfo);
if (printingdate != null) {
orderInfo.setPrintingDate(printingdate);
orderInfo.setHandmadeFlg("NO");
} else {
orderInfo.setHandmade(printingdateStr);
orderInfo.setHandmadeFlg("OK");
}
orderInfo.setShorting(shorting);
orderInfo.setAmount(amount);
orderInfo.setTrack(track);
orderInfo.setRemark(remark);
orderInfo.setOk("NO");
orderInfo.setCreatetime(new Date());
orderInfo.setUpdatetime(new Date());
orderInfo.setUserId(userId);
orderInfo.setAreaid(areaId);
// 保存订单信息
orderService.saveOrderInfo(orderInfo);
if (customername != null && !"".equals(customername.trim())) {
signCustomer = customerMap.get(customername);
if (signCustomer == null) {
customer = new Customer();
customer.setCreatetime(new Date());
customer.setUpdatetime(new Date());
customer.setUserId(userId);
customer.setAreaid(areaId);
customer.setCustomerName(customername);
customer.setAddress("");
customerService.saveCustomer(customer);
customerMap.put(customername, customername);
}
}
if (warehouseid != null && !"".equals(warehouseid.trim())) {
signWarehouse = warehouseMap.get(warehouseid);
if (signWarehouse == null) {
warehouse = new Warehouse();
warehouse.setCreatetime(new Date());
warehouse.setUpdatetime(new Date());
warehouse.setWarehouseId(warehouseid);
warehouse.setWarehouseName(warehouseid);
warehouseService.saveWarehouse(warehouse);
warehouseMap.put(warehouseid, warehouseid);
}
}
index++;
}
}
private Date convertCellType(Cell cell) {
Date date = null;
if (cell.getType() == CellType.DATE) {
date = ((DateCell) cell).getDate();
}
return date;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -