起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7175|回复: 12

[结贴] EXCEL导入时去重的问题

[复制链接]

59

主题

264

帖子

386

积分

中级会员

Rank: 3Rank: 3

积分
386
QQ
发表于 2017-7-7 20:22:21 | 显示全部楼层 |阅读模式
版本: 小版本号:
数据库: 服务器操作系统: 应用服务器:
客户端操作系统: 浏览器:
本帖最后由 zcgame 于 2017-7-12 13:10 编辑

excel导入,其中一个关系设置了唯一
怎么才能让不是唯一的继续留在界面而不是报错,把已经有过不是唯一的去掉呢?能不写代码么

1、在构建路径中添加/SA/excel/logic/code下的jar包
添加了个文件夹 论坛.png
[img]file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\199750882\QQ\WinTemp\RichOle\[5@AIU[THHWIH8L]}A24L32.png[/img]
2、在process中引用/SA/excel/logic/action和/SA/excel/logic/code目录
这个引用了
3、在动作设置中添加importExcelBeforeAction的执行后事件,代码如下
这个应该加哪个代码,只找到了一个好像是java的但是代码应该是js吧?
4、在w文件的excel导入组件的action属性中选择/SA/excel/logic/action/importExcel
这里引用动作只能找到
/SA/excel/logic/action
没有/SA/excel/logic/action/importExcel呀?
excel导入去重问题
http://bbs.wex5.com/forum.php?mod=viewthread&tid=111994
(出处: 起步软件技术论坛)
做个记录






91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36178
发表于 2017-7-10 09:28:05 | 显示全部楼层
1.是导入/BIZ/SA/excel/logic/code/lib下的jar,不是把目录导入
2.process文件的动作设置中添加action,做右边就有执行前后事件 action.png


3.可以手动写
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

59

主题

264

帖子

386

积分

中级会员

Rank: 3Rank: 3

积分
386
QQ
 楼主| 发表于 2017-7-11 12:13:10 | 显示全部楼层
本帖最后由 zcgame 于 2017-7-11 14:40 编辑

找到了。。。。。

  1.         public static void cuostomerProcessAfterImportExcelBeforeAction() {
  2.                           //  System.out.println("导入前");
  3.                 Workbook workBook=(Workbook) ModelUtils.getRequestContext().getActionContext().getParameter("excel");
  4.                 Sheet sheet=workBook.getSheetAt(0);
  5.                 List list=new ArrayList();//存放excel鉴别列的数据
  6.                 for(int i=1;i<=sheet.getLastRowNum();i++){
  7.                         Row row=sheet.getRow(i);
  8.                         Cell cell=row.getCell(0);//根据excel表中第一列数据进行校验
  9.                         Cell sName = row.getCell(3);
  10.                         if(list.contains(cell.getStringCellValue())){
  11.                                  System.out.println("execl导入的数据:编码"+cell + "在当前Excel表中重复");
  12.                               
  13.                                 row.removeCell(cell);//如果list存在和鉴别列相同的数据就删除
  14.                         }
  15.                         
  16.                          String ksql = "select a.sCode , a.sName from AZ_partner a where a.sCode = '"+cell.getStringCellValue()+"' and a.sName = '"+sName.getStringCellValue()+"' ";
  17.                         // System.out.print(ksql + "execl导入的数据");
  18.                          Table table = KSQL.select(ksql, null, "/AOZESYSTEM/CRM/data", null);
  19.                         Iterator it = table.iterator();
  20.                         if (it.hasNext()) {
  21.                                  System.out.println("execl导入的数据:编码/版本"+ cell+"/"+sName + "在当前数据库中重复");
  22.                                 row.removeCell(row.getCell(0));
  23.                         }else{
  24.                                 list.add(cell.getStringCellValue());//如果不存在就添加到list
  25.                         }
  26.               }  
  27.         }
复制代码

然后添加这个就可以了?这里 Cell sName = row.getCell(3);  这里的3是什么意思呢,是看哪里的?w文件的么?
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36178
发表于 2017-7-11 14:54:12 | 显示全部楼层
getCell这个是java操作excel中poi中的标准方法,获取excel中的行的第几个单元格
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

59

主题

264

帖子

386

积分

中级会员

Rank: 3Rank: 3

积分
386
QQ
 楼主| 发表于 2017-7-11 16:50:22 | 显示全部楼层
jishuang 发表于 2017-7-11 14:54
getCell这个是java操作excel中poi中的标准方法,获取excel中的行的第几个单元格

现在不重复的数据不报错了,但是一有重复的数据就报错
2017-07-11 16:41:04 excute stream action, params:{"accept":"application/json","action":"importExcel","actionFlag":"__action_0__","activity":"UserActivity1","contentType":"json","executeContext":"","executor":"","parameters":{"config":{"@type":"xml","xml":"<config use-default=\"true\" to=\"DB\" excel-file=\"D:\\BeX5.3.7\\apache-tomcat\\temp\\680b5999-f311-4bb4-a81f-fcf33c865369.excel.tmp\" mapping-file=\"D:\\BeX5.3.7\\apache-tomcat\\temp\\da5439f2-4ff3-4116-ab31-852ffab21759.excel.tmp\"><data><concept name=\"TBK_TaokeResult\"><relation name=\"TBK_TaokeResult\" type=\"String\"/><relation name=\"calcCheckBox\" type=\"String\"/><relation name=\"fCommission\" type=\"Float\"/><relation name=\"fContact\" type=\"String\"/><relation name=\"fEndTime\" type=\"Date\"/><relation name=\"fGetTime\" type=\"Date\"/><relation name=\"fMoney\" type=\"String\"/><relation name=\"fName\" type=\"String\"/><relation name=\"fOrderNum\" type=\"String\"/><relation name=\"fPlan\" type=\"String\"/><relation name=\"fPrice\" type=\"String\"/><relation name=\"fShop\" type=\"String\"/><relation name=\"fStartTime\" type=\"Date\"/><relation name=\"fVol\" type=\"Integer\"/><relation name=\"version\" type=\"Integer\"/></concept></data></config>"},"createActionParam":{"action":"createTBK_TaokeResultAction","activity":"UserActivity1","parameters":{"table":{"@type":"table","rows":[],"userdata":{"idColumnDefine":"TBK_TaokeResult","idColumnName":"TBK_TaokeResult","idColumnType":"String","model":"/TBK/TaokeResult/data","relationAlias":"fCommission,fContact,fEndTime,fGetTime,fMoney,fName,fOrderNum,fPlan,fPrice,fShop,fStartTime,fVol,version","relationTypes":"Float,String,Date,Date,String,String,String,String,String,String,Date,Integer,Integer","relations":"TBK_TaokeResult.fCommission,TBK_TaokeResult.fContact,TBK_TaokeResult.fEndTime,TBK_TaokeResult.fGetTime,TBK_TaokeResult.fMoney,TBK_TaokeResult.fName,TBK_TaokeResult.fOrderNum,TBK_TaokeResult.fPlan,TBK_TaokeResult.fPrice,TBK_TaokeResult.fShop,TBK_TaokeResult.fStartTime,TBK_TaokeResult.fVol,TBK_TaokeResult.version","updateMode":"whereVersion"}}},"process":"/TBK/TaokeResult/process/TaokeResult/taokeResultProcess"},"saveActionParam":{"action":"saveTBK_TaokeResultAction","activity":"UserActivity1","parameters":{"table":{"@type":"table","rows":[],"userdata":{"idColumnDefine":"TBK_TaokeResult","idColumnName":"TBK_TaokeResult","idColumnType":"String","model":"/TBK/TaokeResult/data","relationAlias":"fCommission,fContact,fEndTime,fGetTime,fMoney,fName,fOrderNum,fPlan,fPrice,fShop,fStartTime,fVol,version","relationTypes":"Float,String,Date,Date,String,String,String,String,String,String,Date,Integer,Integer","relations":"TBK_TaokeResult.fCommission,TBK_TaokeResult.fContact,TBK_TaokeResult.fEndTime,TBK_TaokeResult.fGetTime,TBK_TaokeResult.fMoney,TBK_TaokeResult.fName,TBK_TaokeResult.fOrderNum,TBK_TaokeResult.fPlan,TBK_TaokeResult.fPrice,TBK_TaokeResult.fShop,TBK_TaokeResult.fStartTime,TBK_TaokeResult.fVol,TBK_TaokeResult.version","updateMode":"whereVersion"}}},"process":"/TBK/TaokeResult/process/TaokeResult/taokeResultProcess"}},"process":"/TBK/TaokeResult/process/TaokeResult/taokeResultProcess"}
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.justep.system.action.Engine.invokeActions(Native Method)
        at com.justep.system.action.Engine.invokeActions(Unknown Source)
        at com.justep.business.server.BusinessServer.doAction(Unknown Source)
        at com.justep.business.server.BusinessServer.doExcute(Unknown Source)
        at com.justep.business.server.BusinessServer.excute(Unknown Source)
        at com.justep.business.server.BusinessServer.excute(Unknown Source)
        at com.justep.business.server.BusinessServerServlet.execService(Unknown Source)
        at com.justep.business.server.BusinessServerServlet.service(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at com.justep.x.bs.BusinessServerServlet.service(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.justep.system.action.Engine.invokeAction(Native Method)
        at com.justep.system.action.Engine.invokeAction(Unknown Source)
        at com.justep.model.impl.UtilImplementInstance.invokeAction(Unknown Source)
        at com.justep.model.impl.UtilImplementInstance.invokeAction(Unknown Source)
        at com.justep.system.action.ActionUtils.invokeAction(Unknown Source)
        at com.justep.excel.ImportGenerator.generate(ImportGenerator.java:146)
        at Excel.importExcel(Excel.java:88)
        ... 27 more
Caused by: com.justep.exception.BusinessException: 编码: JUSTEP150210; 提示: 执行KSQL出错, KSQL: INSERT INTO TBK_TaokeResult TBK_TaokeResult(TBK_TaokeResult, TBK_TaokeResult.version, TBK_TaokeResult.fCommission, TBK_TaokeResult.fContact, TBK_TaokeResult.fEndTime, TBK_TaokeResult.fGetTime, TBK_TaokeResult.fMoney, TBK_TaokeResult.fName, TBK_TaokeResult.fOrderNum, TBK_TaokeResult.fPlan, TBK_TaokeResult.fPrice, TBK_TaokeResult.fShop, TBK_TaokeResult.fStartTime, TBK_TaokeResult.fVol) VALUES (:TBK_TaokeResult, :version, :fCommission, :fContact, :fEndTime, :fGetTime, :fMoney, :fName, :fOrderNum, :fPlan, :fPrice, :fShop, :fStartTime, :fVol)
        at com.justep.exception.BusinessException.create(Unknown Source)
        at com.justep.system.data.impl.TableUtilsImplement.ksqlInsert(Unknown Source)
        at com.justep.system.data.impl.TableUtilsImplement.ksqlExecuteUpdate(Unknown Source)
        at com.justep.system.data.KSQL.executeUpdate(Unknown Source)
        at com.justep.system.data.KSQL.executeUpdate(Unknown Source)
        at com.justep.system.data.impl.TableImpl.insert(Unknown Source)
        at com.justep.system.data.impl.TableImpl.save(Unknown Source)
        at com.justep.system.data.impl.TableImpl.save(Unknown Source)
        at com.justep.system.data.BizData.save(Unknown Source)
        at BizProcedure.save(BizProcedure.java:18)
        ... 38 more
Caused by: com.justep.exception.BusinessException: 编码: JUSTEP150039; 提示: 执行sql: INSERT INTO TBK_TAOKERESULT (TBK_TAOKERESULT.fID, TBK_TAOKERESULT.VERSION, TBK_TAOKERESULT.FCOMMISSION, TBK_TAOKERESULT.FCONTACT, TBK_TAOKERESULT.FENDTIME, TBK_TAOKERESULT.FGETTIME, TBK_TAOKERESULT.FMONEY, TBK_TAOKERESULT.FNAME, TBK_TAOKERESULT.FORDERNUM, TBK_TAOKERESULT.FPLAN, TBK_TAOKERESULT.FPRICE, TBK_TAOKERESULT.FSHOP, TBK_TAOKERESULT.FSTARTTIME, TBK_TAOKERESULT.FVOL) VALUES ( ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ), binds: [75B0F4C90CAC4E2EBE0E0AD3B6CFD4C7, 0, 0.25, null, 2017-06-26, 2017-06-26, 87, li492896334, 28602871519788168, 营销计划, 348, 达得利箱包旗舰店, 2017-06-15, 1]出错
        at com.justep.exception.BusinessException.create(Unknown Source)
        at com.justep.system.ksql.KSQLUtils.execSqlUpdate(Unknown Source)
        ... 47 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '28602871519788168' for key 'IDX_TBK_TAOKERESULT_FORDERNUM'
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
        at com.mysql.jdbc.Util.getInstance(Util.java:383)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
        at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
        at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
        ... 48 more

能帮我看下么
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36178
发表于 2017-7-11 17:04:41 | 显示全部楼层
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '28602871519788168' for key 'IDX_TBK_TAOKERESULT_FORDERNUM'

插入的数据重复了
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

59

主题

264

帖子

386

积分

中级会员

Rank: 3Rank: 3

积分
386
QQ
 楼主| 发表于 2017-7-11 17:29:05 | 显示全部楼层
本帖最后由 zcgame 于 2017-7-11 18:09 编辑
jishuang 发表于 2017-7-11 17:04
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate ent ...

已经弄好了,是抄的代码没弄懂意思,代码是2个关系的。而我只要判断一个。另想请教下
row.removeCell(cell);//如果list存在和鉴别列相同的数据就删除
这个只是删除了这个单元格,有没有办法删除单元格所在的行?


我是先展示到UI的,不是直接写入DB,所以整行删除了,是不是就不会有很多空着的行?直接省下筛选过的点保存就可以了?
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36178
发表于 2017-7-12 08:58:55 | 显示全部楼层
import.mapping.xml  代码如下  只需要在relation节点 增加Check=“true” 就行
设置了吗?
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

24

主题

93

帖子

339

积分

中级会员

Rank: 3Rank: 3

积分
339
QQ
发表于 2017-7-12 11:18:47 | 显示全部楼层
jishuang 发表于 2017-7-12 08:58
import.mapping.xml  代码如下  只需要在relation节点 增加Check=“true” 就行
设置了吗? ...

这个checktrue是必填的意思吧?还是说重复也会做检查,重复的跳过,不重复的导入,类似于sql的ignore,现在这种循环查询删除,数据量大的时候效率太慢了
回复 支持 反对

使用道具 举报

59

主题

264

帖子

386

积分

中级会员

Rank: 3Rank: 3

积分
386
QQ
 楼主| 发表于 2017-7-12 13:02:31 | 显示全部楼层
半夏。未夏 发表于 2017-7-12 11:18
这个checktrue是必填的意思吧?还是说重复也会做检查,重复的跳过,不重复的导入,类似于sql的ignore,现 ...

你那边有更好的办法么?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2025-6-20 07:54 , Processed in 0.066292 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表