<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.google.gson.JsonArray"%> <%@page import="com.google.gson.JsonObject"%> <%@page import="java.util.HashMap"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@page import="com.yc.factory.FactoryBean"%> <%@page import="org.springframework.jdbc.support.rowset.SqlRowSet"%> <%@page import="java.util.Map"%> <%@page import="com.google.gson.Gson"%> <%@page import="com.yc.service.top.Utils"%> <%@page import="java.util.regex.*"%> <% Map controls =new HashMap(); @MapPut@ response.setCharacterEncoding("utf-8"); String field=request.getParameter("field"); //字段名 String fieldName=request.getParameter("fieldname");//字段描述 String callback=request.getParameter("callback"); String params=request.getParameter("params"); int state=Integer.parseInt(request.getParameter("state"));//当前控件状态 Map sqlParams=null; int fieldtype=0; try{ fieldtype=Integer.parseInt(request.getParameter("fieldtype"));//获得字段类型 if(null==field||"".equals(field.trim())){ out.write("{\"status\":1,\"info\":\"控件代码必须传递!\"}"); return; } if(!controls.containsKey(field)){ out.write("{\"status\":1,\"info\":\"\"}");//控件代码错误,请于系统管理员联系! return; } if(params!=null){ try{ Gson gson=new Gson(); sqlParams=gson.fromJson(params,new com.google.gson.reflect.TypeToken>() {}.getType()); }catch(Exception e){ out.write("{\"status\":1,\"info\":\"参数集合格式错误!错误提示 "+params+e.getMessage()+"\"}"); return; } if(sqlParams==null){ out.write("{\"status\":1,\"info\":\"参数为空!\"}"); return; } SqlRowSet rs=null; try{ //有需要组装的sql String dysql=com.yc.service.impl.DBHelper.getSqlWhere(controls.get(field), state, controls.get(field+"Where")); //替换字符串中的值 String sql=com.yc.service.impl.DBHelper.getValRepShi(dysql, session, sqlParams, false); JsonArray array=new JsonArray(); JsonObject json=null; Utils utils=(Utils)FactoryBean.getBean("hq.daoUtils"); rs=utils.getRowSet(sql); if(fieldtype==43){//42控件在下拉添加一个全选 xin 2023-6-2 10:39:19 json=new JsonObject(); json.addProperty("id", -1); json.addProperty("text", "全选"); array.add(json); } while(rs.next()){ switch(fieldtype){ case 30://单选按钮 array.add(""); break; case 43: case 35: case 31://下拉框 case 2: json=new JsonObject(); json.addProperty("id", rs.getString(1)); json.addProperty("text", rs.getString(2)); array.add(json); break; case 32://多选框 break; default: break; } } if((fieldtype==31||fieldtype==2)&&!callback.equals("")&&!callback.equals("0")){ json=new JsonObject(); json.addProperty("id", "pb_xinzen"); json.addProperty("text", "<<新增>>"); array.add(json); } out.write("{\"status\":0,\"info\":"+array.toString()+"}"); }catch(Exception e){ out.write("{\"status\":1,\"info\":\"系统功能-9802的字段:【"+field+"-"+fieldName+"】,设置(31类型控件sql)有错误,错误提示信息:"+(e.getCause()!=null?e.getCause().getMessage():e.getMessage())+"\"}"); return; } }else{ out.write("{\"status\":-1,\"info\":\"\"}"); } }catch(NumberFormatException e){//字段类型错误 out.write("{\"status\":1,\"info\":\"控件类型参数错误!\"}"); return; }finally{ out.flush(); } %>