xinyb
2024-08-30 f5cc47742dd3d2f2ffd8443ffc82a912683f7824
提交 | 用户 | age
a6a76f 1 package com.yc.action.personalized;
F 2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.List;
6 import java.util.Map;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9 import javax.servlet.http.HttpSession;
10 import org.apache.commons.lang.StringUtils;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Controller;
13 import org.springframework.web.bind.annotation.RequestMapping;
14 import com.google.gson.Gson;
15 import com.google.gson.reflect.TypeToken;
16 import com.yc.multiData.SpObserver;
17 import com.yc.service.personalized.PanelGridIfc;
18 import com.yc.utils.SessionKey;
19
20 @Controller
21 @SuppressWarnings("all")
22 public class PanelDataGridAction {
23
24     @Autowired
25     private PanelGridIfc gridIfc;
26
27     private boolean isSuperUser(HttpSession session) {
28     return "1".equals(session.getAttribute(SessionKey.SUPPER_USER));
29     }
30
31     @RequestMapping("/addPanelGridField.do")
32     public void addPanelGridField(HttpServletRequest request, HttpServletResponse response) throws IOException {
33     HttpSession session = request.getSession();
34     if (!isSuperUser(session)) {
35         response.sendError(404);
36         return;
37     }// //
38     String formId_str = request.getParameter("formId");
39     String fieldId = request.getParameter("fieldId");
40     String fieldname = request.getParameter("fieldName");
41     String width_str = request.getParameter("width");
42     String align = request.getParameter("align");
43     String bordertop_str = request.getParameter("borderTop");
44     String borderright_str = request.getParameter("borderRight");
45     String borderbottom_str = request.getParameter("borderBottom");
46     String borderleft_str = request.getParameter("borderLeft");
47     String bordercolor = request.getParameter("borderColor");
48     String sort_str = request.getParameter("sort");
49     String spremissfield = request.getParameter("sPremissField");
50     String dpremissfield = request.getParameter("dPremissField");
51     String fkefilter = request.getParameter("FKeFilter");
52     String linkformtype_str = request.getParameter("linkformtype");
53     String linkformid_str = request.getParameter("linkformid");
468e38 54     String displayformat = request.getParameter("displayformat");
906e37 55     String isUpdateReadForToDo=request.getParameter("isUpdateReadForToDo");
a6a76f 56
F 57     if (StringUtils.isBlank(formId_str) || StringUtils.isBlank(fieldId) || StringUtils.isBlank(fieldname) || StringUtils.isBlank(width_str)) {
58         printText(response, "{\"code\":\"error\",\"info\":\"字段名  字段描述  列宽  必须填写!\"}");
59         return;
60     }
61     int width = -1;
62     int formId = -1;
63     int bordertop = 0;
64     int borderright = 0;
65     int borderbottom = 0;
66     int borderleft = 0;
67     int sort = 0;
906e37 68     Integer isupdateread=0;
a6a76f 69     try {
F 70         width = Integer.parseInt(width_str);
71         formId = Integer.parseInt(formId_str);
72         if (bordertop_str != null) bordertop = Integer.parseInt(bordertop_str);
73         if (borderright_str != null) borderright = Integer.parseInt(borderright_str);
74         if (borderleft_str != null) borderleft = Integer.parseInt(borderleft_str);
75         if (borderbottom_str != null) borderbottom = Integer.parseInt(borderbottom_str);
76         if (sort_str != null) sort = Integer.parseInt(sort_str);
77         if (StringUtils.isBlank(linkformid_str)) linkformid_str = "-1";
78         if (StringUtils.isBlank(linkformtype_str)) linkformtype_str = "-1";
468e38 79         if (StringUtils.isBlank(displayformat)) displayformat = "";
906e37 80         if(isUpdateReadForToDo!=null)isupdateread=Integer.parseInt(isUpdateReadForToDo);
a6a76f 81     } catch (Exception e) {
F 82         printText(response, "{\"code\":\"error\",\"info\":\"列宽  边框信息  排列顺序 必须为整数!\"}");
83         return;
84     }
85     try {
86         Map<String, Object> temp = gridIfc.getField(formId, fieldId);
87         if (temp != null && temp.size() > 0) {
88         printText(response, "{\"code\":\"error\",\"info\":\"该字段名已经存在!\"}");
89         return;
90         }
91         // gridIfc.addFiled(formId, fieldId, fieldname, width, align, bordertop, borderright, borderbottom, borderleft, bordercolor, sort,
92         // spremissfield,dpremissfield,fkefilter,linkformid,linkformtype);
93         SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
906e37 94         gridIfc.addFiled(formId, fieldId, fieldname, width, align, bordertop, borderright, borderbottom, borderleft,
468e38 95                 bordercolor, sort, spremissfield, dpremissfield, fkefilter, linkformid_str, linkformtype_str,isupdateread,displayformat);
a6a76f 96
F 97         printText(response, "{\"code\":\"success\",\"info\":\"添加成功!\"}");
98     } catch (Exception e) {
99         e.printStackTrace();
100         printText(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
101     }finally{
102          SpObserver.setDBtoInstance();
103      }
104     }
105
106     @RequestMapping("/updatePanelGridField.do")
107     public void updatePanelGridField(HttpServletRequest request, HttpServletResponse response) throws IOException {
108     HttpSession session = request.getSession();
109     if (!isSuperUser(session)) {
110         response.sendError(404);
111         return;
112     }// //
113     String formId_str = request.getParameter("formId");
114     String fieldId = request.getParameter("fieldId");
115     String fieldname = request.getParameter("fieldName");
116     String width_str = request.getParameter("width");
117     String align = request.getParameter("align");
118     String bordertop_str = request.getParameter("borderTop");
119     String borderright_str = request.getParameter("borderRight");
120     String borderbottom_str = request.getParameter("borderBottom");
121     String borderleft_str = request.getParameter("borderLeft");
122     String bordercolor = request.getParameter("borderColor");
123     String sort_str = request.getParameter("sort");
124     String spremissfield = request.getParameter("sPremissField");
125     String dpremissfield = request.getParameter("dPremissField");
126     String fkefilter = request.getParameter("FKeFilter");
127     String linkformtype_str = request.getParameter("linkformtype");
128     String linkformid_str = request.getParameter("linkformid");
468e38 129     String displayformat = request.getParameter("displayformat");
906e37 130     String isUpdateReadForToDo=request.getParameter("isUpdateReadForToDo");
a6a76f 131     if (StringUtils.isBlank(formId_str) || StringUtils.isBlank(fieldId) || StringUtils.isBlank(fieldname) || StringUtils.isBlank(width_str)) {
F 132         printText(response, "{\"code\":\"error\",\"info\":\"字段名  字段描述  列宽  必须填写!\"}");
133         return;
134     }
135     int width = -1;
136     int formId = -1;
137     int bordertop = 0;
138     int borderright = 0;
139     int borderbottom = 0;
140     int borderleft = 0;
141     int sort = 0;
906e37 142     Integer isupdateread=0;
a6a76f 143     try {
F 144         width = Integer.parseInt(width_str);
145         formId = Integer.parseInt(formId_str);
146         if (bordertop_str != null) bordertop = Integer.parseInt(bordertop_str);
147         if (borderright_str != null) borderright = Integer.parseInt(borderright_str);
148         if (borderleft_str != null) borderleft = Integer.parseInt(borderleft_str);
149         if (borderbottom_str != null) borderbottom = Integer.parseInt(borderbottom_str);
150         if (sort_str != null) sort = Integer.parseInt(sort_str);
151         if (StringUtils.isBlank(linkformid_str)) linkformid_str = "-1";
152         if (StringUtils.isBlank(linkformtype_str)) linkformtype_str = "-1";
468e38 153         if (StringUtils.isBlank(displayformat)) displayformat = "";
906e37 154         if(isUpdateReadForToDo!=null)isupdateread=Integer.parseInt(isUpdateReadForToDo);
a6a76f 155     } catch (Exception e) {
F 156         printText(response, "{\"code\":\"error\",\"info\":\"列宽  边框信息  排列顺序  链接表号  链接表类型  必须为整数!\"}");
157         return;
158     }
159     try {
160         SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
906e37 161         gridIfc.updateFiled(formId, fieldId, fieldname, width, align, bordertop, borderright, borderbottom, borderleft,
468e38 162                 bordercolor, sort, spremissfield, dpremissfield, fkefilter, linkformid_str, linkformtype_str,isupdateread,displayformat);
a6a76f 163         printText(response, "{\"code\":\"success\",\"info\":\"修改成功!\"}");
F 164     } catch (Exception e) {
165         printText(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
166     }finally{
167          SpObserver.setDBtoInstance();
168      }
169     }
170
171     @RequestMapping("/delPanelGridField.do")
172     public void delPanelGridField(HttpServletRequest request, HttpServletResponse response) throws IOException {
173     HttpSession session = request.getSession();
174
175     String formId_str = request.getParameter("formId");
176     String fieldId = request.getParameter("fieldId");
177
178     if (StringUtils.isBlank(formId_str) || StringUtils.isBlank(fieldId)) return;
179
180     int formId = -1;
181     try {
182         formId = Integer.parseInt(formId_str);
183     } catch (Exception e) {
184         printText(response, "{\"code\":\"error\",\"info\":\"参数有误!\",\"field\":\"formid\"}");
185         return;
186     }
187     try {
188         SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
189         gridIfc.delField(formId, fieldId);
190         printText(response, "{\"code\":\"success\",\"info\":\"删除成功!\"}");
191     } catch (Exception e) {
192         e.printStackTrace();
193         printText(response, "{\"code\":\"error\",\"info\":\"删除出现异常!\"}");
194     }finally{
195          SpObserver.setDBtoInstance();
196      }
197
198     }
199
200     @RequestMapping("/getPanelGridField.do")
201     public void getPanelGridField(HttpServletRequest request, HttpServletResponse response) throws IOException {
202     HttpSession session = request.getSession();
203     if (!isSuperUser(session)) {
204         response.sendError(404);
205         return;
206     }// //
207     String formId_str = request.getParameter("formId");
208     String fieldId = request.getParameter("fieldId");
209     if (StringUtils.isBlank(formId_str) || StringUtils.isBlank(fieldId)) return;
210     int formId = -1;
211     try {
212         formId = Integer.parseInt(formId_str);
213     } catch (Exception e) {
214         return;
215         // printText(response,"{\"code\":\"error\",\"info\":\"删除出现异常!\"}");
216     }
217     try {
218         SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
219         Map<String, Object> map = gridIfc.getField(formId, fieldId);
220         if (map != null) {
906e37 221             if(map.get("isUpdateReadForToDo")==null){
X 222                 map.put("isUpdateReadForToDo",0);
223             }
a6a76f 224         Gson gson = new Gson();
F 225         String jsonData = gson.toJson(map, new TypeToken<Map<String, Object>>() {}.getType());
226         printText(response, jsonData);
227         }
228     } catch (Exception e) {
229         e.printStackTrace();
230     }finally{
231          SpObserver.setDBtoInstance();
232      }
233     }
234
235     @RequestMapping("/getPanelGridFields.do")
236     public void getPanelGridFields(HttpServletRequest request, HttpServletResponse response) throws IOException {
237     HttpSession session = request.getSession();
238     if (!isSuperUser(session)) {
239         response.sendError(404);
240         return;
241     }// //
242     String formId_str = request.getParameter("formId");
243     int formId = -1;
244     try {
245         formId = Integer.parseInt(formId_str);
246     } catch (Exception e) {
247         return;
248         // printText(response,"{\"code\":\"error\",\"info\":\"删除出现异常!\"}");
249     }
250     try {
251         SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
252         List<Map<String, Object>> map = gridIfc.getPanelGrid(formId, "formid,align,linkformid,fieldid,fieldname,width,sort");
253         if (map != null) {
254         Gson gson = new Gson();
255         String jsonData = gson.toJson(map, new TypeToken<List<Map<String, Object>>>() {}.getType());
256         StringBuilder sb = new StringBuilder();
257         sb.append("{\"rows\":").append(jsonData).append("}");
258         printText(response, sb.toString());
259         jsonData = null;
260         sb = null;
261         }
262     } catch (Exception e) {
263         e.printStackTrace();
264     }finally{
265          SpObserver.setDBtoInstance();
266      }
267     }
268
269     /**
270      * 输出信息到客户端
271      * 
272      * @param response
273      * @param str
274      * @throws IOException
275      */
276     public void printScript(HttpServletResponse response, String str) throws IOException {
277     response.setCharacterEncoding("utf-8");
278     response.setContentType("text/html;charset=utf-8");
279     PrintWriter out = response.getWriter();
280     out.write("<script type='text/javascript'>" + str + "</script>");
281     out.flush();
282     out.close();
283     }
284
285     public void printText(HttpServletResponse response, String str) throws IOException {
286     response.setCharacterEncoding("utf-8");
287     PrintWriter out = response.getWriter();
288     out.write(str);
289     out.flush();
290     out.close();
291     }
292 }