截取长度分组 拼sql

List<ZxLab> list = (List<ZxLab>) systemBaseDAO.findAll(
					"from ZxLab where _dingdan = '" + _dingdan + "' and _synflag = 'N' order by _rel", pageSize, 1);
			System.out.println("from ZxLab where _dingdan = '" + _dingdan + "' and _synflag = 'N' order by _rel");
			List<LabUI> listlab = new ArrayList<LabUI>();
			if (list != null && list.size() <= pageSize) {
    
    
				String rel = "";
				String sql = "";
				for (int i = 0; i < list.size(); i++) {
    
    
					rel = list.get(i).get_rel();
					if (i == 0) {
    
    
						sql = " select left(a.lot,len(a.lot)-7) lot,sum(a.qty+0) qty  from (select _lot1 lot , _qty1 qty from middle_box where (_lot1 <> '' and"
								+ " _lot1 is not null ) and (_rel = '" + rel + "' or _rel = '" + rel + "' or _rel = '"
								+ rel + "' or _rel = '" + rel + "' or _rel = '" + rel + "') "
								+ " union all select _lot2 lot,_qty2 qty from middle_box where (_lot2 <> '' and _lot2 is not null) and (_rel = '"
								+ rel + "' or " + " _rel = '" + rel + "' or _rel = '" + rel + "' or _rel = '" + rel
								+ "' or _rel = '" + rel + "' ) "
								+ " union all select _lot3 lot,_qty3 qty from middle_box where (_lot3 <> '' and _lot3 is not null) and (_rel = '"
								+ rel + "' or _rel ='" + rel + "'" + "or  _rel = '" + rel + "' or  _rel ='" + rel
								+ "' or _rel ='" + rel + "')) a group by left(a.lot,len(a.lot)-7) ";
					} else {
    
    
						sql += " union all  select left(a.lot,len(a.lot)-7) lot,sum(a.qty+0) qty  from (select _lot1 lot , _qty1 qty from middle_box where (_lot1 <> '' and"
								+ " _lot1 is not null ) and (_rel = '" + rel + "' or _rel = '" + rel + "' or _rel = '"
								+ rel + "' or _rel = '" + rel + "' or _rel = '" + rel + "') "
								+ " union all select _lot2 lot,_qty2 qty from middle_box where (_lot2 <> '' and _lot2 is not null) and (_rel = '"
								+ rel + "' or " + " _rel = '" + rel + "' or _rel = '" + rel + "' or _rel = '" + rel
								+ "' or _rel = '" + rel + "' ) "
								+ " union all select _lot3 lot,_qty3 qty from middle_box where (_lot3 <> '' and _lot3 is not null) and (_rel = '"
								+ rel + "' or _rel ='" + rel + "'" + "or  _rel = '" + rel + "' or  _rel ='" + rel
								+ "' or _rel ='" + rel + "')) a group by  left(a.lot,len(a.lot)-7) ";
					}

				}
				System.out.println(sql);
				// 怎么取值呢?
				List<ZxLab> listzx = (List<ZxLab>) DBUtils.getListBy(sql, ZxLab.class);
				System.out.println();
				request.setAttribute("listzx", listzx);

			}

猜你喜欢

转载自blog.csdn.net/liufeifeihuawei/article/details/108485804
今日推荐