여러 객체의 한 필드에 대한 추가 삭제

4619 단어 대상
public void getAddAwardList(){
		
		model.setFisrtRow((model.getPage() - 1) * model.getRows());
		
		model.setLastRow(model.getRows());
		
		try {
			BaseDao dao=getDao();
			
			List<YouthModel> list = dao.selectForList("youth.getAddAwardList", model);
			HashMap<String ,Object> hm = new HashMap<String ,Object>();
			hm.put("total", dao.selectByCount("youth.getListCount", model));
			hm.put("rows", list);
			hm.put("success", true);
			this.doResponseWithJson(hm);
		} catch (Exception e) {
			e.printStackTrace();
			this.setData("    ");
			this.setSuccess(false);
			this.send();
		}
		
	}
	
/**
 * 
 * @param sqlString                :1,2,3
 * @param modelString     model       , :4
 * @return
 */
	private String removeSameValue(String sqlString, String modelString) {
		if (StringUtil.isEmpty(sqlString)) {
			return modelString;
		}
		String[] t = sqlString.split(",");

		TreeSet<String> tSet = new TreeSet<String>();
		for (int i = 0; i < t.length; i++) {
			tSet.add(t[i]);
		}
		tSet.add(modelString);
		String s = "";
		for (Iterator<String> it = tSet.iterator(); it.hasNext();) {

			s += it.next().toString() + ",";
		}
		s = s.substring(0, s.length() - 1);

		return s;
	}
	 

public void addAwardConfig(){
		
		try {
			BaseDao dao=getDao();
			//            id
			String id = model.getId();
			// in    ()  id     select * from ybc_youth where id in ($VALUE$)
			List<YouthModel>  retModel = dao.selectForList("youth.getAddAward", id);
			//    
			YouthModel tModel = new YouthModel();
			//    list
			List<YouthModel> sqlModelList = new ArrayList<YouthModel>();
			//    ,        id
			for (int i=0; i<retModel.size(); i++) {
				//          
				tModel = retModel.get(i);
				//      id        id  
				tModel.setYouthAward(this.removeSameValue(tModel.getYouthAward(), model.getYouthAward()));
				//      id  list
				sqlModelList.add(tModel);
			}
			//    
			dao.updateSql("youth.upt_youth", sqlModelList);
			
			this.setData("          ");
			this.setSuccess(true);
			this.send();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setData("          ,    :"+e.getMessage());
			this.setSuccess(false);
			this.send();
		}
	}

//     
private String removeList(String sqlString,String modelString){
	
	String[] sqlStr = sqlString.split(",");
	String[] modelStr = modelString.split(",");
	
	List<String> listA= java.util.Arrays.asList(sqlStr);
	List<String> listB= java.util.Arrays.asList(modelStr);
	
	Set setA = new TreeSet(listA);
	setA.removeAll(listB);		
	System.out.println(setA);
	
	String s = "";
	for (Iterator<String> it = setA.iterator(); it.hasNext();) {
		s += it.next().toString() + ",";
	}
	s = s.substring(0, s.length() - 1);
	return s;
}


public void removeAwardConfig(){
	try{
		BaseDao dao=getDao();
		
		String id =model.getId();
		List<YouthModel>  retModel = dao.selectForList("youth.getAddAward", id);
			System.out.println(retModel.size());
		YouthModel tModel = new YouthModel();
		List<YouthModel> sqlModelList = new ArrayList<YouthModel>();
		
		for (int i=0; i<retModel.size(); i++) {
			//          
			tModel = retModel.get(i);
			//      id        id  
			tModel.setYouthAward(this.removeList(tModel.getYouthAward(), model.getYouthAward())); 
			//      id  list
			sqlModelList.add(tModel);
		}
		dao.updateSql("youth.upt_youth", sqlModelList);
		
		this.setData("          ");
		this.setSuccess(true);
		this.send();
	}catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		this.setData("          ,    :"+e.getMessage());
		this.setSuccess(false);
		this.send();
	}
}

좋은 웹페이지 즐겨찾기