Ejemplo n.º 1
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;
	}
Ejemplo n.º 2
0
	//改变所属单位
	public String par(){

		Users users=getLoginAdmin();
		String result="0";
		msg="改变菜单 "+unit.getName()+" 的所属菜单为 "+parname+" ";
		try {
			if (unit.getId()!=null&&unit.getId().trim().length()>0) {
				unitMapper=MybatisSessionFactory.getSession().getMapper(UnitMapper.class);
				unitMapper.updatePar(unit);
				MybatisSessionFactory.getSession().commit();
				result="1";
				msg+="成功<属性>"+unit.getId()+"<属性>"+unit.getParid();
			}else {
				msg="删除时没有获取到菜单 "+unit.getName();
			}
		} catch (Exception e) {
			try {
				MybatisSessionFactory.getSession().rollback();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
			result="0";
			msg+="失败:"+e.toString();
		}
		OperLogUtil.log(users.getLoginname(), msg, getHttpRequest());
		ResponseUtil.writeUTF(getHttpResponse(),result+msg);
		return null;
	}
Ejemplo n.º 3
0
	//保存
	public String find(){
		String result="0";
		StringBuilder sb=new StringBuilder();
		try {
			if (unit.getId()!=null && unit.getId().trim().length()>0) {
				unitMapper=MybatisSessionFactory.getSession().getMapper(UnitMapper.class);
				Unit currUnit=unitMapper.selectByPrimaryKey(unit.getId().trim());
				if (currUnit!=null) {
					sb.append(currUnit.getId());
					sb.append("<属性>");
					sb.append(currUnit.getName()!=null?currUnit.getName():"");
					sb.append("<属性>");
					sb.append(currUnit.getIsok());
					sb.append("<属性>");
					sb.append(currUnit.getOrdernum()!=null?currUnit.getOrdernum():"");
					sb.append("<属性>");
					sb.append(currUnit.getParid());
					sb.append("<属性>");
					sb.append(currUnit.getIsmail());
					result="1";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			result="0";	
		}
		ResponseUtil.writeUTF(getHttpResponse(),result+sb.toString());
		return null;
	}
Ejemplo n.º 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;
	}
Ejemplo n.º 5
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;
	}