package com.yc.action.personalized;
|
|
import java.io.IOException;
|
import java.io.PrintWriter;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import com.google.gson.Gson;
|
import com.google.gson.JsonParseException;
|
import com.google.gson.reflect.TypeToken;
|
import com.yc.multiData.SpObserver;
|
import com.yc.service.personalized.PanelGridIfc;
|
import com.yc.service.personalized.PanelUserGridIfc;
|
import com.yc.utils.SessionKey;
|
|
@Controller
|
public class PanelUserLayoutAction {
|
|
|
@Autowired
|
private PanelUserGridIfc userGridIfc;
|
|
@Autowired
|
private PanelGridIfc gridIfc;
|
|
|
@RequestMapping("/savePanelUserLayout.do")
|
public void updateGroup(HttpServletRequest request,
|
HttpServletResponse response) throws IOException {
|
String jsonData = request.getParameter("jsonData");
|
String formId_str = request.getParameter("formId");
|
String showRowNumber_str = request.getParameter("showrownumber");
|
if(StringUtils.isBlank(jsonData))
|
return;
|
Gson gson = new Gson();
|
try{
|
int formId = Integer.parseInt(formId_str);
|
int showRowNumber = -1;
|
if(!StringUtils.isBlank(showRowNumber_str))
|
showRowNumber = Integer.parseInt(showRowNumber_str);
|
String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
|
List<Map<String,String>> saveList = gson.fromJson(jsonData, new TypeToken<List<Map<String,String>>>(){}.getType());
|
SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
List<Map<String,Object>> tmp = userGridIfc.getGridCfg(userCode, formId);
|
if(tmp!=null&&tmp.size()>0){
|
userGridIfc.deleteGridCfg(formId, userCode);
|
userGridIfc.addGridCfg(formId,userCode,saveList);
|
}else{
|
userGridIfc.addGridCfg(formId, userCode, saveList);
|
}
|
userGridIfc.updateShowNumber(formId, userCode, showRowNumber>100?100:showRowNumber);
|
print(response, "{\"code\":\"success\",\"info\":\"保存成功!\"}");
|
}catch(NumberFormatException e){
|
print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
|
}catch (JsonParseException e) {
|
print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
|
}catch (Exception e) {
|
e.printStackTrace();
|
print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
|
}finally{
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping("/restorePanelUserLayout.do")
|
public void restorePanelUserLayout(HttpServletRequest request,
|
HttpServletResponse response) throws IOException {
|
String formId_str = request.getParameter("formId");
|
try{
|
SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
int formid = Integer.parseInt(formId_str);
|
String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
|
userGridIfc.deleteGridCfg(formid, userCode);
|
print(response, "{\"code\":\"success\",\"info\":\"保存成功!\"}");
|
}catch (NumberFormatException e) {
|
print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
|
}catch (Exception e) {
|
e.printStackTrace();
|
print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
|
}finally{
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping("/getPanelUserLayout.do")
|
public void getUserLayout(HttpServletRequest request,
|
HttpServletResponse response) throws IOException {
|
String formId_str = request.getParameter("formId");
|
try{
|
SpObserver.setDBtoInstance("_"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
int formid = Integer.parseInt(formId_str);
|
String userCode = (String)request.getSession().getAttribute(SessionKey.USERCODE);
|
List<Map<String,Object>> gridInfo =userGridIfc.getGridCfg(userCode,formid);
|
// String showRow = null;
|
if(gridInfo==null||gridInfo.size()==0){
|
gridInfo=gridIfc.getPanelGrid(formid,"formid,fieldid,fieldname,align,width,sort,1 as isshow ");
|
if(gridInfo==null||gridInfo.size()==0)return;
|
}
|
Gson gson = new Gson();
|
String jsonData = gson.toJson(gridInfo, new TypeToken<List<Map<String,Object>>>(){}.getType());
|
StringBuilder sb = new StringBuilder();
|
sb.append("{\"rows\":").append(jsonData).append("}");
|
print(response, sb.toString());
|
jsonData = null;
|
sb = null;
|
}catch (NumberFormatException e) {
|
print(response, "{\"code\":\"error\",\"info\":\"数据格式转换有误!\"}");
|
}catch (Exception e) {
|
e.printStackTrace();
|
print(response, "{\"code\":\"error\",\"info\":\"出现异常!\"}");
|
}finally{
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 输出信息到客户端
|
*
|
* @param response
|
* @param str
|
* @throws IOException
|
*/
|
public void print(HttpServletResponse response, String str)
|
throws IOException {
|
response.setCharacterEncoding("utf-8");
|
PrintWriter out = response.getWriter();
|
out.write(str);
|
out.flush();
|
out.close();
|
}
|
}
|