package com.yc.action.new38action; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import java.util.Map; import com.google.gson.Gson; import com.yc.entity.Json38; import com.yc.multiData.SpObserver; import com.yc.service.new38type.Type38Ifc; import com.yc.utils.SessionKey; @Controller @SuppressWarnings("all") public class Type38action extends com.yc.action.BaseAction { @Autowired Type38Ifc type38service; String formid = ""; @RequestMapping("/gridsave.do") public void gridsave(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); String dat1 = request.getParameter("content").replace("\\", ""); // System.out.println(dat1); String saisid = request.getParameter("saisid"); String formid = request.getParameter("formid"); // Gson gson = new Gson(); Json38 gt = gson.fromJson(dat1, new com.google.gson.reflect.TypeToken() { }.getType()); String usercode = (session.getAttribute(SessionKey.HRCODE) == null ? "" : (String) session.getAttribute(SessionKey.HRCODE)); try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); type38service.updatePanelDatas(gt, saisid, formid, usercode); this.printJson(response, "{\"code\":\"" + formid + "\",\"info\":\"" + saisid + "\"}"); } catch (Exception e) { // TODO: handle exception this.printJson(response, "{\"code\":\"" + e.getMessage() + "\",\"info\":\"" + saisid + "\"}"); } finally { SpObserver.setDBtoInstance(); } } /* * 数据设置的数据处理 */ @RequestMapping("/gridsave1.do") public void gridsave1(HttpServletRequest request, HttpServletResponse response) throws IOException { String dat1 = request.getParameter("content").replace("\\", ""); // System.out.println(dat1); String saisid = request.getParameter("saisid"); String formid = request.getParameter("formid"); Gson gson = new Gson(); Json38 gt = gson.fromJson(dat1, new com.google.gson.reflect.TypeToken() { }.getType()); try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); type38service.PanelDatas(gt, saisid, formid); this.printJson(response, "{\"code\":\"" + formid + "\",\"info\":\"" + saisid + "\"}"); } catch (Exception e) { // TODO: handle exception this.printJson(response, "{\"code\":\"" + e.getMessage() + "\",\"info\":\"" + saisid + "\"}"); } finally { SpObserver.setDBtoInstance(); } } /* * * 判断是否是私有的 */ @RequestMapping("/contrast.do") public void contrast(HttpServletRequest request, HttpServletResponse response, String saisid, String formid) throws IOException { List> list=null; String sql = "select usercode from _sysStatis where statisid=" + "'" + saisid + "'" + " and formid=" + formid + ""; try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); list = type38service.selectzdy(sql); } finally { SpObserver.setDBtoInstance(); } Map map = null; String usercodes = ""; for (int i = 0; i < list.size(); i++) { map = list.get(i); usercodes = (String) map.get("usercode") == null ? "" : (String) map.get("usercode"); } if (usercodes.equals("") || usercodes == null) { this.printJson(response, "{\"code\":\"success\",\"info\":\"success\"}"); } else { this.printJson(response, "{\"code\":\"error\",\"info\":\"success\"}"); } } /* * * 判断是否存在相同的名字 */ @RequestMapping("/statiscontrast.do") public void statiscontrast(HttpServletRequest request, HttpServletResponse response, String saisid, String formid) throws IOException { List> list=null; String sql = "select usercode from _sysStatis where statisid=" + "'" + saisid + "'" + " and formid=" + formid + ""; try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); list = type38service.selectzdy(sql); } finally { SpObserver.setDBtoInstance(); } if (list.size() != 0) { this.printJson(response, "{\"code\":\"error\",\"info\":\"error\"}"); } else { this.printJson(response, "{\"code\":\"success\",\"info\":\"success\"}"); } } /* * * 执行删除操作 */ @RequestMapping("/datadelete.do") public void datadelete(HttpServletRequest request, HttpServletResponse response, String saisid, String formid) throws IOException { String sql = "delete from _sysStatisDetail where formid=" + formid + " and StatisID=" + "'" + saisid + "'" + " "; sql = sql + " " + "delete from _sysStatis where formid=" + formid + " and StatisID=" + "'" + saisid + "'" + " "; try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); type38service.delPanelData(sql); this.printJson(response, "{\"code\":\"success\",\"info\":\"success\"}"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); this.printJson(response, "{\"code\":\"error\",\"info\":\"" + e.getMessage().toString() + "\"}"); } finally { SpObserver.setDBtoInstance(); } } public List> get38TypeInfo(HttpServletRequest request, HttpServletResponse response, int formId){ HttpSession session = request.getSession(); List> list=null; try { SpObserver.setDBtoInstance("_" + request.getSession() .getAttribute(SessionKey.DATA_BASE_ID)); String usercode = (session.getAttribute(SessionKey.HRCODE) == null ? "" : (String) session.getAttribute(SessionKey.HRCODE)); String isSuperUser = (String) session.getAttribute(SessionKey.SUPPER_USER); String statisIds=null; Map perssionMap =((Map>)session.getAttribute(SessionKey.PERSSION)).get(formId+""); if(perssionMap!=null&&!"1".equals(isSuperUser)){ //不是管理员才需要增加权限设置 statisIds= (String) perssionMap.get("statisIds");//38类型汇总项权限 } list = type38service.selecttype(formId, usercode,statisIds); return list; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping("/getType38.do") public void getType38(HttpServletRequest request, HttpServletResponse response, int formId) throws Exception { Gson gson = new Gson(); String data = gson.toJson(get38TypeInfo(request,response,formId)); StringBuilder sb = new StringBuilder(); sb.append(data); this.printJson(response, sb.toString()); } private String getEndTd(String tdSel, int colNo, int tiI, StringBuffer sbFieldset, StringBuffer sBuffer) { if (tiI < 5 && tiI > 0) { tdSel += " "; } if (sbFieldset.length() > 0) { if (tdSel.trim().length() > 0) { sbFieldset.append("").append(tdSel) .append("
"); } sbFieldset.append(""); tdSel = ""; } if (tdSel.toCharArray().length > 0) {// 未分组显示的情况 sbFieldset.append(tdSel); } try { tdSel = getTr38(sBuffer, sbFieldset.toString()); } catch (Exception e) { e.printStackTrace(); } return tdSel; } private String getTr38(StringBuffer sBuffer, String tdSel) throws Exception { sBuffer.append("\r\n"); sBuffer.append(tdSel); sBuffer.append("\r\n"); return ""; } @RequestMapping("/aaa.do") public void aaa(HttpServletRequest request, HttpServletResponse response, String id) throws IOException { formid = id; } public void printText(HttpServletResponse response, String str) throws IOException { response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); out.write(str); out.flush(); out.close(); } }