fs-danaus
2024-03-16 a2ecbf17d6ba1c7b135fe10bb4cdfefa05b75add
提交 | 用户 | age
a6a76f 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
F 2 <%@page import="com.google.gson.JsonArray"%>
3 <%@page import="com.google.gson.JsonObject"%>
4 <%@page import="java.util.HashMap"%>
5 <%@page import="java.util.ArrayList"%>
6 <%@page import="java.util.List"%>
7 <%@page import="com.yc.factory.FactoryBean"%>
8 <%@page import="org.springframework.jdbc.support.rowset.SqlRowSet"%>
9 <%@page import="java.util.Map"%>
10 <%@page import="com.google.gson.Gson"%>
11 <%@page import="com.yc.service.top.Utils"%>
12 <%@page import="java.util.regex.*"%>
13 <%
14    Map<String,String> controls =new HashMap<String,String>();
15    @MapPut@
16    response.setCharacterEncoding("utf-8");
17    String field=request.getParameter("field");  //字段名
7cd6c6 18     String fieldName=request.getParameter("fieldname");//字段描述
a6a76f 19    String callback=request.getParameter("callback");
F 20    String params=request.getParameter("params");
21    int state=Integer.parseInt(request.getParameter("state"));//当前控件状态
22    Map<String,Object> sqlParams=null;
23    int fieldtype=0;
24    try{
25         fieldtype=Integer.parseInt(request.getParameter("fieldtype"));//获得字段类型   
26         if(null==field||"".equals(field.trim())){
27              out.write("{\"status\":1,\"info\":\"控件代码必须传递!\"}");
28              return;
29         }
30         if(!controls.containsKey(field)){
31              out.write("{\"status\":1,\"info\":\"\"}");//控件代码错误,请于系统管理员联系!
32              return;
33         }
34         if(params!=null){ 
35              try{
36                   Gson gson=new Gson();
37                   sqlParams=gson.fromJson(params,new com.google.gson.reflect.TypeToken<Map<String,String>>() {}.getType());
38              }catch(Exception e){
39                   out.write("{\"status\":1,\"info\":\"参数集合格式错误!错误提示  "+params+e.getMessage()+"\"}");
40                   return;
41              }
42              if(sqlParams==null){ 
43                   out.write("{\"status\":1,\"info\":\"参数为空!\"}");
44                   return;
45              }             
46              SqlRowSet rs=null;
47              try{
48                   //有需要组装的sql
49                   String dysql=com.yc.service.impl.DBHelper.getSqlWhere(controls.get(field), state, controls.get(field+"Where"));                 
50                   //替换字符串中的值 
51                   String sql=com.yc.service.impl.DBHelper.getValRepShi(dysql, session, sqlParams, false);
52                   JsonArray array=new JsonArray();
53                   JsonObject json=null;
54                   Utils utils=(Utils)FactoryBean.getBean("hq.daoUtils");
6efeaa 55                   rs=utils.getRowSet(sql);
X 56                   if(fieldtype==43){//42控件在下拉添加一个全选 xin 2023-6-2 10:39:19
57                       json=new JsonObject();
58                       json.addProperty("id", -1);
59                       json.addProperty("text", "全选");
60                       array.add(json);
61                   }
a6a76f 62                   while(rs.next()){
F 63                       switch(fieldtype){
64                         case 30://单选按钮
65                            array.add("");
66                            break;
67                         case 43:
68                         case 35:
69                         case 31://下拉框
70                         case 2:     
71                             json=new JsonObject();
72                             json.addProperty("id", rs.getString(1));
73                             json.addProperty("text", rs.getString(2));
74                             array.add(json);
75                            break;
76                         case 32://多选框
77                             break;
78                         default:            
79                            break;
80                     }
81                   }
82                   if((fieldtype==31||fieldtype==2)&&!callback.equals("")&&!callback.equals("0")){
83                         json=new JsonObject();
84                         json.addProperty("id", "pb_xinzen");
85                         json.addProperty("text", "<<新增>>");
86                         array.add(json);
87                   }
88                   out.write("{\"status\":0,\"info\":"+array.toString()+"}");
89             }catch(Exception e){
7cd6c6 90                  out.write("{\"status\":1,\"info\":\"系统功能-9802的字段:【"+field+"-"+fieldName+"】,设置(31类型控件sql)有错误,错误提示信息:"+(e.getCause()!=null?e.getCause().getMessage():e.getMessage())+"\"}");
a6a76f 91                  return;
F 92             }         
93       }else{
94             out.write("{\"status\":-1,\"info\":\"\"}");
95       }
96    }catch(NumberFormatException e){//字段类型错误
97        out.write("{\"status\":1,\"info\":\"控件类型参数错误!\"}");      
98        return;
99    }finally{
100       out.flush();      
101    }
102 %>