NutzCN Logo
问答 这么判断for第一次新增 第二次重复数据不执行
发布于 2553天前 作者 少年不再年少 2497 次浏览 复制 上一个帖子 下一个帖子
标签:
进入------1
2017-11-29 11:26:40,726 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?) 
    | 1 |   2 |                   3 | 4 |
    |---|-----|---------------------|---|
    | 1 | 112 | 2017-11-29 10:57:32 | 1 |
  For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(1,112,'2017-11-29 10:57:32',1) "
进入------39
-----------新增成功
2017-11-29 11:26:40,766 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?) 
    |  1 |   2 |                   3 | 4 |
    |----|-----|---------------------|---|
    | 39 | 112 | 2017-11-29 10:57:32 | 1 |
  For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(39,112,'2017-11-29 10:57:32',1) "
进入------1
-----------新增成功
2017-11-29 11:26:40,879 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?) 
    | 1 |   2 |                   3 | 4 |
    |---|-----|---------------------|---|
    | 1 | 112 | 2017-11-29 10:57:30 | 1 |
  For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(1,112,'2017-11-29 10:57:30',1) "
进入------39
-----------新增成功
2017-11-29 11:26:40,916 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?) 
    |  1 |   2 |                   3 | 4 |
    |----|-----|---------------------|---|
    | 39 | 112 | 2017-11-29 10:57:30 | 1 |
  For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(39,112,'2017-11-29 10:57:30',1) "
-----------新增成功
11 回复
if (fetch.isEmpty()) {
			for (Statistics statistics2 : statistics) {
				for (PreinstallApk preinstallApk : preinstallApks) {
					for (Device dev : device) {
						if (statistics2.getDate_Time().getTime() > preinstallApk.getUploadDateTime().getTime()) {
							if (num <= 4) {
								System.err.println("进入------" + preinstallApk.getId());
								Quantity.setApkId(preinstallApk.getId()); // APK ID
								Quantity.setDeviceId(dev.getId()); // 手机 ID
								Quantity.setCreatetime(sdf.format(statistics2.getDate_Time())); // 更新时间
								Quantity.setTime(num); // 次数
								Quantity = dao.insert(Quantity); // 插入数据
								System.out.println("-----------新增成功");

							}
						}
					}
				}
			}

你自己也说是“重复数据”了

正确这样日志

```
进入------1
2017-11-29 11:26:40,726 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?)

For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(1,112,'2017-11-29 10:57:32',1) "

进入------39
-----------新增成功
2017-11-29 11:26:40,916 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(?,?,?,?)
For example:> "INSERT INTO t_activating_quantity(q_apkId,q_deviceId,q_createtime,q_time) VALUES(39,112,'2017-11-29 10:57:30',1) "
-----------新增成功

这是你程序内部自己的算法问题
自己解决吧,cant help you

我找到原因了,执行第一次数据把第2条也新增了,执行第二次数据把第一次数据的也新增了  ,我还没找到解决方案

这个有问题

			"select * from t_activating_quantity   where  q_createtime in (select max(q_createtime) from t_activating_quantity  $cnd )");
		for (PreinstallApk preinstallApk : preinstallApks) {
			cnd.or("q_apkId", "=", preinstallApk.getId());
			System.err.println("=---1" + cnd.or("q_apkId", "=", preinstallApk.getId()));
		}
		for (Device devices : device) {
			cnd.or("q_deviceId", "=", devices.getId());
			System.err.println("=---" + cnd.or("q_deviceId", "=", devices.getId()));
		}

日志
=---1 WHERE q_apkId=1 OR q_apkId=1
=---1 WHERE q_apkId=1 OR q_apkId=1 OR q_apkId=39 OR q_apkId=39
=--- WHERE q_apkId=1 OR q_apkId=1 OR q_apkId=39 OR q_apkId=39 OR q_deviceId=112 OR q_deviceId=112

System.err.println("=---1" + cnd.or("q_apkId", "=", preinstallApk.getId()));
这句打印语句中的 cnd.or("q_apkId", "=", preinstallApk.getId())
本身会改变cnd

改成这样
System.err.println("=---1" + cnd);

System.err.println("=---1" + cnd);
System.err.println("=---" + cnd);
=---1 WHERE q_apkId=1
=---1 WHERE q_apkId=1 OR q_apkId=39
=--- WHERE q_apkId=1 OR q_apkId=39 OR q_deviceId=112
2017-11-29 14:37:23,355 org.nutz.dao.impl.sql.run.NutDao

```

添加回复
请先登陆
回到顶部