fs-danaus
2022-11-14 12560372988b49cc9465e92c32d852db2d0e8612
提交 | 用户 | 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
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import org.apache.commons.lang.StringUtils;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Controller;
14 import org.springframework.web.bind.annotation.RequestMapping;
15
16 import com.google.gson.Gson;
17 import com.google.gson.JsonParseException;
18 import com.google.gson.reflect.TypeToken;
19 import com.yc.multiData.SpObserver;
20 import com.yc.service.personalized.PanelGridIfc;
21 import com.yc.service.personalized.PanelUserGridIfc;
22 import com.yc.utils.SessionKey;
23
24 @Controller
25 public class PanelUserLayoutAction {
26
27     
28     @Autowired
29     private PanelUserGridIfc userGridIfc;
30     
31     @Autowired
32     private PanelGridIfc gridIfc;
33
34     
35     @RequestMapping("/savePanelUserLayout.do")
36     public void updateGroup(HttpServletRequest request,
37             HttpServletResponse response) throws IOException {
38         String jsonData = request.getParameter("jsonData");
39         String formId_str = request.getParameter("formId");
40         String showRowNumber_str = request.getParameter("showrownumber");
41         if(StringUtils.isBlank(jsonData))
42             return;
43         Gson gson = new Gson();
44         try{
45             int formId = Integer.parseInt(formId_str);
46             int showRowNumber = -1;
47             if(!StringUtils.isBlank(showRowNumber_str))
48                 showRowNumber = Integer.parseInt(showRowNumber_str);
49             String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
50             List<Map<String,String>> saveList = gson.fromJson(jsonData, new TypeToken<List<Map<String,String>>>(){}.getType());
51             SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
52             List<Map<String,Object>> tmp = userGridIfc.getGridCfg(userCode, formId);
53             if(tmp!=null&&tmp.size()>0){
54                 userGridIfc.deleteGridCfg(formId, userCode);
55                 userGridIfc.addGridCfg(formId,userCode,saveList);
56             }else{
57                 userGridIfc.addGridCfg(formId, userCode, saveList);
58             }
59             userGridIfc.updateShowNumber(formId, userCode, showRowNumber>100?100:showRowNumber);
60             print(response, "{\"code\":\"success\",\"info\":\"保存成功!\"}");
61         }catch(NumberFormatException e){
62             print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
63         }catch (JsonParseException e) {
64             print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
65         }catch (Exception e) {
66             e.printStackTrace();
67             print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
68         }finally{
69              SpObserver.setDBtoInstance();
70          }
71     }
72     
73     @RequestMapping("/restorePanelUserLayout.do")
74     public void restorePanelUserLayout(HttpServletRequest request,
75             HttpServletResponse response) throws IOException {
76         String formId_str = request.getParameter("formId");
77         try{
78             SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
79             int formid = Integer.parseInt(formId_str);
80             String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
81             userGridIfc.deleteGridCfg(formid, userCode);
82             print(response, "{\"code\":\"success\",\"info\":\"保存成功!\"}");
83         }catch (NumberFormatException e) {
84             print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
85         }catch (Exception e) {
86             e.printStackTrace();
87             print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
88         }finally{
89              SpObserver.setDBtoInstance();
90          }
91     }
92     
93     @RequestMapping("/getPanelUserLayout.do")
94     public void getUserLayout(HttpServletRequest request,
95             HttpServletResponse response) throws IOException {
96         String formId_str = request.getParameter("formId");
97         try{
98             SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
99             int formid = Integer.parseInt(formId_str);
100             String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
101             List<Map<String,Object>> gridInfo =userGridIfc.getGridCfg(userCode,formid);
102 //            String showRow = null;
103             if(gridInfo==null||gridInfo.size()==0){
104                 gridInfo=gridIfc.getPanelGrid(formid,"formid,fieldid,fieldname,align,width,sort,1 as isshow ");
105                 if(gridInfo==null||gridInfo.size()==0)return;
106             }
107             Gson gson = new Gson();
108             String jsonData = gson.toJson(gridInfo, new TypeToken<List<Map<String,Object>>>(){}.getType());
109             StringBuilder sb = new StringBuilder();
110             sb.append("{\"rows\":").append(jsonData).append("}");
111             print(response, sb.toString());
112             jsonData = null;
113             sb = null;
114         }catch (NumberFormatException e) {
115             print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
116         }catch (Exception e) {
117             e.printStackTrace();
118             print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
119         }finally{
120              SpObserver.setDBtoInstance();
121          }
122     }
123
124     /**
125      * 输出信息到客户端
126      * 
127      * @param response
128      * @param str
129      * @throws IOException
130      */
131     public void print(HttpServletResponse response, String str)
132             throws IOException {
133         response.setCharacterEncoding("utf-8");
134         PrintWriter out = response.getWriter();
135         out.write(str);
136         out.flush();
137         out.close();
138     }
139 }