|
在Excel导入主子表数据时,导入成功(数据库中成功插入导入的数据),但是导入前鼠标所在行会新增一条乱的数据插入到数据库中,请问如何解决?
情况如下图所示:
在导入第一条数据时正常导入:
当导入第二条数据时(同一个Excel表格和mapping映射文件),导入的数据是正常的如下图所示:
但是鼠标所在的行(导入的第一条数据)明细表多添了一条数据:
当导入第三条数据时,鼠标所在的行又新增一条:
importExcel组件的代码我都没有改动,只添加了importExcelBeforeAction执行后事件,代码如下:
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import com.justep.model.ModelUtils;
import com.justep.system.data.KSQL;
import com.justep.system.util.BizUtils;
import com.justep.system.util.CommonUtils;
public class Dj_sgwhsjbsProcess {
public static void dj_sgwhsjbsProcessAfterImportExcelBeforeAction() throws Exception {
// System.out.println("========================");
Workbook workBook = (Workbook) ModelUtils.getRequestContext().getActionContext().getParameter("excel");
Sheet sheet = workBook.getSheetAt(1); // 获得sheet2中的数据明细
Sheet sheet1 = workBook.getSheetAt(0);// 获得sheet1中的数据主表
Cell c = sheet1.getRow(1).getCell(2);
c.setCellType(Cell.CELL_TYPE_STRING);
String value = c.getStringCellValue();// 获得资金筛选额度
String dwbm = sheet1.getRow(1).getCell(0).getStringCellValue();//单位编码
String dwmc = sheet1.getRow(1).getCell(1).getStringCellValue();//单位名称
String djbm = BizUtils.createNextSequenceString("SGWH", "0000");//单据编码
// 用来记录大额资金笔数
int count = 0;
// 用来记录大额资金总额
BigDecimal dezjze = new BigDecimal(0);
// 用来记录资金总额
BigDecimal zjze = new BigDecimal(0);
String uuid = CommonUtils.createGUID();// 主表主键
Iterator<Row> it = sheet.iterator();
Map map = new HashMap();
Row row = null;
Cell cell = null;
row = it.next();
while (it.hasNext()) {
row = it.next();
int i = 1;
Iterator<Cell> ce = row.cellIterator();
while (ce.hasNext()) {
cell = ce.next();
map.put(i++, cell);
}
System.out.println(map.get(5));
String ksql = "insert into ZJJG_DEZJSJBSMX mx " + "(mx,mx.fDESJBSMX_DWDM,mx.fDESJBSMX_DWMC,mx.fDESJBSMX_ZFDWMC,mx.fDESJBSMX_ZBID,mx.fDESJBSMX_ZJYTDM,mx.fDESJBSMX_ZJYTMS,mx.fDESJBSMX_ZJJE,mx.fDESJBSMX_SKDWMC,"
+ "mx.fDESJBSMX_SKFSFWJWQY) values('" + CommonUtils.createGUID() + "','"+dwbm+"','"+dwmc+"','"+dwmc+"'," + "'" + uuid + "','" + map.get(1).toString().substring(0, 2) + "','" + map.get(2) + "'," + map.get(3)
+ ",'" + map.get(4) + "','" + map.get(6).toString().substring(0, 1) + "')";
KSQL.executeUpdate(ksql, null, "/zjjg/zjbs/data", null);
if (new BigDecimal(map.get(3).toString()).compareTo(new BigDecimal(value)) > 0) {// 大额
count++;
dezjze = dezjze.add(new BigDecimal(map.get(3).toString()));
}
zjze = zjze.add(new BigDecimal(map.get(3).toString()));
}
String sql = "insert into ZJJG_DEZJSJBSZB zb (zb,zb.fDESJBSZB_DJBM,zb.fDESJBSZB_DJZT,zb.fDESJBSZB_DWDM,zb.fDESJBSZB_DWMC,zb.fDESJBSZB_SJLY,zb.fDESJBSZB_WHZZ,zb.DR,zb.fDESJBSZB_DEZJZE,zb.fDESJBSZB_ZJZE,zb.fDESJBSZB_DRDEZJBS,zb.fDESJBSZB_JESXED) values('"
+ uuid + "','"+djbm+"','0','"+dwbm+"','"+dwmc+"','sgbs','"+dwmc+"',0," + dezjze + ","
+ zjze + "," + count + "," + new BigDecimal(value) + ")";
KSQL.executeUpdate(sql, null, "/zjjg/zjbs/data", null);
}
}
|
|