Beispiel #1
0
	/**
	 * 选择单位 
	 * @return
	 */
	public String select(){
		//查询所有有效单位
		if (isAdminLogin()) {
			unitList=unitService.findByUser("1","");
		}else {
			unitList=unitService.findByUser("1",getLoginAdmin().getId());
		}
		return "select";
	}
Beispiel #2
0
	//保存
	public String save(){
		Users users=getLoginAdmin();
		unitMapper=MybatisSessionFactory.getSession().getMapper(UnitMapper.class);
		String result="0";
		String idname="";
		try {
			if (unit.getId()!=null&&unit.getId().trim().length()>0) {
				msg="修改";
				unitMapper.updateByPrimaryKey(unit);
				MybatisSessionFactory.getSession().commit();
				unitService.callUnitUpdatePro(unit.getId());
			}else {
				msg="添加";
				unit.setId(UUID.randomUUID().toString());
				unitMapper.insert(unit);
				MybatisSessionFactory.getSession().commit();
				idname="<属性>"+unit.getId()+"<属性>"+unit.getName();
			}
			result="1";
		} catch (Exception e) {
			try {
				MybatisSessionFactory.getSession().rollback();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			result="0";
			msg+="单位 "+unit.getName()+" 失败:"+e.toString();
		}
		msg+="单位 "+unit.getName()+" 成功"+idname;
		OperLogUtil.log(users.getLoginname(), msg, getHttpRequest());
		ResponseUtil.writeUTF(getHttpResponse(),result+msg);
		return null;
	}
Beispiel #3
0
	//删除
	public String del(){

		Users users=getLoginAdmin();
		unitMapper=MybatisSessionFactory.getSession().getMapper(UnitMapper.class);
		String result="0";
		try {
			if (unit.getId()!=null&&unit.getId().trim().length()>0) {
				//先看是否有子单位
				List<Unit> sons=unitMapper.selectUnitByparid(unit.getId());
				if (sons!=null && sons.size()>0) {
					//删除子单位
					for (int i = 0; i < sons.size(); i++) {
						unitService.callUnitDelPro(sons.get(i).getId());
						unitMapper.deleteByPrimaryKey(sons.get(i).getId());
					}
				}
				unitService.callUnitDelPro(unit.getId());
				unitMapper.deleteByPrimaryKey(unit.getId());
				MybatisSessionFactory.getSession().commit();
				result="1";
				msg="删除单位 "+unit.getName()+" 成功<属性>"+unit.getId();
			}else {
				msg="删除时没有获取到单位 "+unit.getName();
			}
		} catch (Exception e) {
			try {
				MybatisSessionFactory.getSession().rollback();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			result="0";
			msg="删除单位 "+unit.getName()+" 失败:"+e.toString();
		}
		OperLogUtil.log(users.getLoginname(), msg, getHttpRequest());
		ResponseUtil.writeUTF(getHttpResponse(),result+msg);
		return null;
	}
Beispiel #4
0
	public String son()
	{
		Users users=getLoginAdmin();
		List<Unit> list=null; 
		unitMapper=MybatisSessionFactory.getSession().getMapper(UnitMapper.class);
		if ("root".equals(root)) {
			//提取一级菜单 
			list=unitMapper.selectUnit("");
		}else {
			//提取子菜单
			list=unitMapper.selectUnit(root);
		}
		//生成树
		StringBuilder stringBuilder=new StringBuilder();
		stringBuilder.append("[");
		if (list!=null && list.size()>0) {
			for (int i = 0; i <list.size() ; i++) {
				if (!list.get(i).getId().equals(noid)) {
					if (!"[".equals(stringBuilder.toString())) {
						stringBuilder.append(",");
					}
					stringBuilder.append("{ \"text\": \"<a  onclick=");
					if (onclick!=null && onclick.trim().length()>0) {
						stringBuilder.append(onclick);
					}else {
						stringBuilder.append("showDetail");
					}
					stringBuilder.append("('");
					stringBuilder.append(list.get(i).getId());
					stringBuilder.append("','"+list.get(i).getName().replaceAll(" ", "")+"')>");
					stringBuilder.append(list.get(i).getName());
					stringBuilder.append("\", \"hasChildren\": ");
					if (unitService.hasChildren(list.get(i).getId())) {
						stringBuilder.append("true");
					}else {
						stringBuilder.append("false");
					}
					stringBuilder.append(",\"id\":\"");
					stringBuilder.append(list.get(i).getId());
					stringBuilder.append("\" }");
				}
			}
		}
		stringBuilder.append("]");
		ResponseUtil.writeUTF(getHttpResponse(), stringBuilder.toString());
		return null;
	}