//下载 货代填写价格 模板
public void doDownloadHuoDaiPrice(){
try {
hyMonthInquiryList = new ArrayList<HyMonthInquiryFO>();
//设置货代编码
queryData.setGoodsAgentCode(super.getUserContext().getOrgaId());
DboList hyMonthInquirysBj = getHyMonthInquiryBO().getHyMonthInquirysNotBj(super.getQueryContext());
for(int i=0; i<hyMonthInquirysBj.size(); i++){
HyMonthInquiry tmpHyMonthInquiry = (HyMonthInquiry) hyMonthInquirysBj.get(i);
tmpHyMonthInquiry.setLocalLanguage(super.getLanguage());
HyMonthInquiryFO tmpHyMonthInquiryFo = new HyMonthInquiryFO();
BeanUtils.copy(tmpHyMonthInquiry, tmpHyMonthInquiryFo);
codeToName(tmpHyMonthInquiryFo,tmpHyMonthInquiry);
}
String EXL = "HY_MONTH_INQUIRY_PRICE";
ExcelGeneralOperate ex = new ExcelGeneralOperate();
String fileName = ex.doGeneralExportValue(hyMonthInquirysBj, EXL);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ly_time = sdf.format(new java.util.Date());
String filePath = SystemConfigs.GENDMS_FILE_PATH + "/" + SystemConfigs.TEMP_FILE_DIR + "/" + fileName;
fileName = "未报价的月度询盘信息(" + ly_time + ").xls";
OdDownloadLog downLog = this.getOdDownloadLogBO().createLog(fileName, fileName, filePath,"",fileName);
super.outSuccess(downLog.getId());
}catch (Exception e) {
e.printStackTrace();
super.outFailure(e.getMessage());
}
}
//导入报价信息
public void importHyMonthInquiryInfo(){
UserTransaction transaction = TransactionFactory.getInstance().createTransaction();
try{
transaction.begin();
String path = SystemConfigs.GENDMS_FILE_PATH + File.separatorChar + SystemConfigs.TEMP_FILE_DIR + File.separatorChar + UUIDHexGenerator.getInstance().generate()+".xls";
FileHelper.copyFile(file, path);
List<ImportExcelErrorFO> errorList = this.getHyMonthInquiryBO().importHyMonthInquiryInfo(path,super.getQueryContext());
if(errorList.size()>0){
transaction.rollback();
//返回错误提示
StringBuffer s = new StringBuffer(JSONArray.fromObject(errorList).toString());
outJsonStringForUpload("{success:false, data:" + s.toString() + "}");
}else{
transaction.commit();
super.outSuccessHtml("成功");
}
} catch (Exception e) {
transaction.rollback();
e.printStackTrace();
LogHome.getLog().error(e.getMessage(),e);
super.outFailureForUploadReplace(e.getMessage());
}
}
//导入月度询盘报价
public List<ImportExcelErrorFO> importHyMonthInquiryInfo(String path, IBoQueryContext queryContext) throws Exception {
DboList list = new DboList();
InputStream inStream = null;
long userId = StringHelper.getUserSession().getId();
List<ImportExcelErrorFO> errorList = new ArrayList<ImportExcelErrorFO>();
try {
inStream = new FileInputStream(path);
HSSFWorkbook wb = new HSSFWorkbook(inStream);
HSSFSheet sheet = wb.getSheetAt(0);
errorList = this.validationHyMonthInquiryItem(sheet, list,queryContext);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (inStream != null) {
inStream.close();
}
}
if (errorList.size()==0){
//如果没有错误批量导入
try {
for (int i = 0, count = list.size(); i < count; i++) {
HyMonthInquiryItem item = (HyMonthInquiryItem) list.get(i);
super.composeCreator(item, userId);
String id = item.getId();
DboList hyShipTypeList = this.getHyMonthInquiryDAO().queryShipType(id);
for (int b=0;b<hyShipTypeList.size();b++ ) {
GenericDO shipType = hyShipTypeList.get(b);
if (shipType.getAttrString("SHIP_TYPE").equals("集装箱")) {
item.setBillingUnit("/柜");
} else {
item.setBillingUnit("/立方米");
}
}
super.updateObject(item);
}
} catch (Exception e) {
e.printStackTrace();
//数据库执行异常
ImportExcelErrorFO error = new ImportExcelErrorFO();
error.setErrorMsg(e.getMessage());
errorList.add(error);
}
}
return errorList;
}
private List<ImportExcelErrorFO> validationHyMonthInquiryItem(HSSFSheet sheet, DboList list,IBoQueryContext queryContext) throws Exception {
HSSFRow row = null;
int rowNum = ExcelUtil.countRows(sheet);
int currentRow = 1;
List<ImportExcelErrorFO> errorList = new ArrayList<ImportExcelErrorFO>();
String temp = "";
HSSFRow testRow = sheet.getRow(currentRow);
if (testRow != null) {
} else {
ImportExcelErrorFO error = new ImportExcelErrorFO();
error.setErrorMsg("模板中无数据");
errorList.add(error);
return errorList;
}
for (int i = currentRow; i <= rowNum; i++, currentRow++) {
row = sheet.getRow(currentRow);
if (row == null) {
continue;
}
HyMonthInquiryItem hyMonthInquiryItem = new HyMonthInquiryItem();
StringBuffer errorString = new StringBuffer();
ImportExcelErrorFO excelError = new ImportExcelErrorFO();
excelError.setRowNum("第" + (currentRow + 1) + "行");
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(0), i, ( short) 0) + "", "");
String hyGoodsAgentNametemp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(1), i, ( short) 1) + "", "");
String batchNo = temp;
if (!"".equals(temp)) {
//根据批次号 货代名称判断是否已经报价
DboList hyMonthInquiryList = this.getHyMonthInquiryDAO().queryhyMonthInquiryById(queryContext, temp, hyGoodsAgentNametemp);
GenericDO tmpHyMonthInquiry = hyMonthInquiryList.get(0);
if (tmpHyMonthInquiry.getAttrString("QUOTATION")!= null) {
errorString.append("导入失败![报价信息已存在]");
}
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(5), i, (short) 5) + "", "");
if (!"".equals(temp)) {
try {
hyMonthInquiryItem.setVoyageMin(temp);
} catch (Exception e) {
errorString.append("第" + (6) + "列 最小航程不能为空 ;");
}
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(6), i, (short) 6) + "", "");
if (!"".equals(temp)) {
hyMonthInquiryItem.setVoyageMax(temp);
} else {
errorString.append("第" + (7) + "列 最大航程不能为空 ;");
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(7), i, (short) 7) + "", "");
if (!"".equals(temp) && !temp.equals("0") && Double.valueOf(temp)>0) {
hyMonthInquiryItem.setQuotation(Double.valueOf(temp));
} else {
errorString.append("第" + (8) + "列 货代报价不能为空或者为0,批次号["+batchNo+"];");
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(8), i, (short) 8) + "", "");
if (!"".equals(temp)) {
hyMonthInquiryItem.setShippingSample(temp);
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(9), i, (short) 9) + "", "");
if (!"".equals(temp)) {
hyMonthInquiryItem.setHdNote(temp);
}
temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(10), i, (short) 10) + "", "");
if (!"".equals(temp)) {
hyMonthInquiryItem.setId(temp);
}
if(errorString.length() != 0){
excelError.setErrorMsg(errorString.toString());
errorList.add(excelError);
}
else{
list.add(hyMonthInquiryItem);
}
}
return errorList;
}
stuts批量导入
最新推荐文章于 2024-07-22 21:03:46 发布