2
回答
sqlServer重复插入数据。
终于搞明白,存储TCO原来是这样算的>>>   

如题,sqlserver 2008 时不时的就会插入重复数据,一摸一样。

问题情境:

    一个车辆违章的记录系统,当有车辆违章时便会从车辆卡口数据库获取车牌等信息到本系统数据库,并给违章人员发送短信,但刚刚发现车辆卡口数据库的一个数据只有一条,但是在本系统可以看到100条,都是一样的。不知是为什么,很疑惑?望各位给个解决思路,我也会继续寻找问题原因。

举报
masterkgw
发帖于2个月前 2回/128阅
/**
	 * @desc 查询最新的车辆违章记录
	 */
	private List<Map<String, Object>> getNewCarIllegalInfo() {
		List<Long> alarmIds = this.jdbcTemplate.queryForList("select alarm_id from fs_car_illegal_info f where f.illegal_time=(select max(illegal_time) from fs_car_illegal_info)", Long.class);
		if(null != alarmIds && alarmIds.size() > 0) {
			Long	alarmId = alarmIds.get(0);
			String cols = "alarm_id, tollgate_code, plate_code, plate_color, vehicle_brand, vehicle_color, vehicle_type, vehicle_speed, alarm_time, pic1_name";
			List<Map<String, Object>> list = this.jdbcTemplate2.queryForList("select "+cols+" from tbl_vehicle_alarm where alarm_id > ? ", new Object[]{alarmId});
			return list;
		}else {
			return null;
		}
	}
	
 /**保存**/
@Override
	public void saveCarIllegalInfo(String[] str) {
		List<Map<String, Object>> mapList = this.getNewCarIllegalInfo();
		
		int speed = new Integer(PropertiesUtil.getPropertiesValue("param", "speeding"));
		
		for(Map<String, Object> map : mapList) {
			FsCarIllegalInfo info = new FsCarIllegalInfo();
			info.setAlarmId((Long)map.get(str[0]));
			String cameraNo = (String)map.get(str[1]);
			info.setCameraNo(cameraNo);
			info.setCarNo((String)map.get(str[2]));
			info.setCarNoColor((String)map.get(str[3]));
			if(Arrays.asList(Constant.wtbm).contains(cameraNo)) {
				info.setIllegalType("CL-WT");
			} else {
				info.setIllegalType("CL-CS");
			}
			info.setCameraName(PropertiesUtil.getPropertiesValue("param", cameraNo));
			// 是否是学校车辆
			FsCarInfo carInfo = (FsCarInfo) this.iBaseDao.getObjectByHql("from FsCarInfo f where f.carCode = ? ", info.getCarNo());
			if(null != carInfo) {
				info.setIsSchool(0);
				// 发送短信
				FsAdmin admin = carInfo.getApplyUser();
				if(null != admin) {
					if(StringUtils.isNotBlank(admin.getPhone())) {
						if(info.getIllegalType().equals("CL-WT")) {
							sender.sendMessageImmediately(admin.getPhone(),"【北】"+"摄像机:"+info.getCameraName()+"检测到您违章停车.");
						} else {
							int s = (int) map.get(str[7]);
							if(s >= speed) {
								sender.sendMessageImmediately(admin.getPhone(),"【北】"+"摄像机:"+info.getCameraName()+"检测到您超速行驶.");
							}
						}
					}
				}
				info.setIsSend(0);
			} else {
				info.setIsSchool(1);
				info.setIsSend(1);
			}
			
			info.setCarColor((String)map.get(str[5]));
			info.setCarType((String)map.get(str[6]));
			info.setIllegalTime((Date)map.get(str[8]));
			info.setCreateTime((Date)map.get(str[8]));
			info.setImgPath((String) map.get(str[9]));
			info.setCampus(PropertiesUtil.getPropertiesValue("param", "campus.distribute"));
			this.iBaseDao.insertObject(info);
		}
	}

 

顶部