| | |
| | | |
| | | /*** |
| | | * 处理代码, gt-grid提交所有变化过的数据 |
| | | * |
| | | * |
| | | * @author 邓文峰 2010-3-24 |
| | | **/ |
| | | |
| | | @Controller |
| | | @RequestMapping("/gt38Grid.do") |
| | | public class GT38Grid extends com.yc.action.BaseAction { |
| | | private int formID;// 功能号 |
| | | @Autowired |
| | | private Grid38ServiceIfc gridService;// 表格处理的业务类 |
| | | @Autowired |
| | | private GridServiceIfc grids;// 表格处理的业务类 |
| | | @Autowired |
| | | TypeControlDao type38Ifc; |
| | | @Autowired |
| | | TypeControlDao typeControlDao; |
| | | @Autowired |
| | | Type38Ifc type38; |
| | | String StatisNames = ""; |
| | | StringBuilder str1 = new StringBuilder(); |
| | | Page page1 = new Page(); |
| | | /** |
| | | *正则表达式 是否有 sum,count,avg,min,max 这个字符 |
| | | */ |
| | | private static Pattern SUM_COUNT_AVG_MIN_MAX_PATTERN = Pattern.compile("[^\\w](sum|avg|min|max|count)[^\\w]"); |
| | | /** |
| | | *正则表达式 是否有 as 这个字符 |
| | | */ |
| | | private static Pattern AS_PATTERN = Pattern.compile("[^\\w]as\\s+"); |
| | | /** |
| | | * 正则表达式 以@开头的单词 |
| | | */ |
| | | private static Pattern START_WOROD_PATTERN = Pattern.compile("@.*?\\w+"); |
| | | @RequestMapping(params = "m=get") |
| | | // Integer grapht 增加一个参数作为图表统计调用 |
| | | public String createGrid(Integer grapht, Model model, |
| | | HttpServletRequest request, HttpServletResponse resp) |
| | | throws Exception { |
| | | // String |
| | | // datalist="4.按仓库、商品规格汇总,companyid,分组|4.按仓库、商品规格汇总,freestockSQM,汇总|4.按仓库、商品规格汇总,gradename2,分组|4.按仓库、商品规格汇总,special,分组|4.按仓库、商品规格汇总,stCode,分组|4.按仓库、商品规格汇总,stname,分组"; |
| | | try { |
| | | String root = request.getSession().getServletContext().getRealPath("/") |
| | | + "/"; |
| | | int formid = -1; |
| | | int pos=request.getParameter("pos")==null?1:Integer.parseInt(request.getParameter("pos")); |
| | | try { |
| | | formid = Integer.parseInt(EncodeUtil.base64Decode(request.getParameter("formIdHid"))); |
| | | } catch (NumberFormatException e1) { |
| | | log.debug(request.getParameter("formIdHid") + "转换数字格式出错", |
| | | e1.getCause()); |
| | | } |
| | | String StatisNames = EncodeUtil.base64Decode(request |
| | | .getParameter("StatisNames")); |
| | | String StatisID = EncodeUtil.base64Decode(request |
| | | .getParameter("StatisID")); |
| | | String datalist = ""; |
| | | List<Map<String, Object>> list = gridService.selectdata(formid, |
| | | StatisID); |
| | | Map<String, Object> mapObject = null; |
| | | PanelBean panelBean=new PanelBean(); |
| | | if(list==null||list.size()==0){ |
| | | throw new ApplicationException("请在【9828】维护好查询参数!"); |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject = list.get(i); |
| | | datalist += typeControlDao.getSelectAndCheckBoxss( |
| | | GridUtils.prossRowSetDataType_String(mapObject,"StatisID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"FieldID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"FieldAlias"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"StatisType"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"Sequence"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"DisplayWidth"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"displayformat"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"displayYN"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"isFilterZero"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"jionFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"jionFlagGroup"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"conFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"modfvalues"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"modfvalues2"), |
| | | GridUtils.prossRowSetDataType_String(mapObject,"fieldCaption"),panelBean) |
| | | ; |
| | | } |
| | | private int formID;// 功能号 |
| | | @Autowired |
| | | private Grid38ServiceIfc gridService;// 表格处理的业务类 |
| | | @Autowired |
| | | private GridServiceIfc grids;// 表格处理的业务类 |
| | | @Autowired |
| | | TypeControlDao type38Ifc; |
| | | @Autowired |
| | | TypeControlDao typeControlDao; |
| | | @Autowired |
| | | Type38Ifc type38; |
| | | String StatisNames = ""; |
| | | StringBuilder str1 = new StringBuilder(); |
| | | Page page1 = new Page(); |
| | | /** |
| | | * 正则表达式 是否有 sum,count,avg,min,max 这个字符 |
| | | */ |
| | | private static Pattern SUM_COUNT_AVG_MIN_MAX_PATTERN = Pattern.compile("[^\\w](sum|avg|min|max|count)[^\\w]"); |
| | | /** |
| | | * 正则表达式 是否有 as 这个字符 |
| | | */ |
| | | private static Pattern AS_PATTERN = Pattern.compile("[^\\w]as\\s+"); |
| | | /** |
| | | * 正则表达式 以@开头的单词 |
| | | */ |
| | | private static Pattern START_WOROD_PATTERN = Pattern.compile("@.*?\\w+"); |
| | | |
| | | this.StatisNames = StatisID; |
| | | try { |
| | | datalist = java.net.URLDecoder.decode(datalist.replace("%", "@~"), |
| | | "utf-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.debug(e.getCause().getMessage()); |
| | | } |
| | | String encodeWhere=request.getParameter("where"); |
| | | GridData data = new GridData(); |
| | | //保存不解码的where,直接传回前端 |
| | | data.setWhere38(encodeWhere); |
| | | String where =EncodeUtil.base64Decode(encodeWhere); |
| | | gridService.create38Grid(data, formid, root, |
| | | this.setWhere(this.replaceBlank(datalist)), StatisID); |
| | | data.setDatalist(this.replaceBlank(datalist)); |
| | | data.setWhere(where); |
| | | Grid grid = new Grid(); |
| | | grid.setFormID(formid); |
| | | grid.setWinType(data.winType + ""); |
| | | grid.setField(data.field); |
| | | grid.setWhere(data.where); |
| | | grid.setDatalist(data.datalist); |
| | | grid.setTbCols(data.totalCols); |
| | | grid.setPos(pos); |
| | | grid.setQueryStringBy38(request.getQueryString()); |
| | | grid.setTotalRowNum(request.getParameter("totalRowNum")==null?0:Integer.parseInt(request.getParameter("totalRowNum"))); |
| | | grid.setTotalPageNum(request.getParameter("totalPageNum")==null?0:Integer.parseInt(request.getParameter("totalPageNum"))); |
| | | Object object= loadByFunc(model, data, grid, request, resp, grapht, formid, |
| | | StatisNames,StatisID); |
| | | if(VersionUtils.getAPPTypeName(request) != null){//APP端 |
| | | Page page= (Page) object; |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("data", page.getData());//数据 |
| | | map.put("cols", data.getCols_app());//列名 |
| | | map.put("align", page.getResultMap());//对齐方式 |
| | | map.put("summary", page.getTbColsOut());//页脚汇总 |
| | | this.printJson(resp,GridUtils.toJson(map)); |
| | | return null; |
| | | }else{ |
| | | return String.valueOf(object); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | this.printJson(resp,e.getCause()!=null?e.getCause().getMessage():e.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | @RequestMapping(params = "m=get") |
| | | // Integer grapht 增加一个参数作为图表统计调用 |
| | | public String createGrid(Integer grapht, Model model, |
| | | HttpServletRequest request, HttpServletResponse resp) |
| | | throws Exception { |
| | | // String |
| | | // datalist="4.按仓库、商品规格汇总,companyid,分组|4.按仓库、商品规格汇总,freestockSQM,汇总|4.按仓库、商品规格汇总,gradename2,分组|4.按仓库、商品规格汇总,special,分组|4.按仓库、商品规格汇总,stCode,分组|4.按仓库、商品规格汇总,stname,分组"; |
| | | try { |
| | | String root = request.getSession().getServletContext().getRealPath("/") |
| | | + "/"; |
| | | int formid = -1; |
| | | int pos = request.getParameter("pos") == null ? 1 : Integer.parseInt(request.getParameter("pos")); |
| | | try { |
| | | formid = Integer.parseInt(EncodeUtil.base64Decode(request.getParameter("formIdHid"))); |
| | | } catch (NumberFormatException e1) { |
| | | log.debug(request.getParameter("formIdHid") + "转换数字格式出错", |
| | | e1.getCause()); |
| | | } |
| | | String StatisNames = EncodeUtil.base64Decode(request |
| | | .getParameter("StatisNames")); |
| | | String StatisID = EncodeUtil.base64Decode(request |
| | | .getParameter("StatisID")); |
| | | String datalist = ""; |
| | | List<Map<String, Object>> list = gridService.selectdata(formid, |
| | | StatisID); |
| | | Map<String, Object> mapObject = null; |
| | | PanelBean panelBean = new PanelBean(); |
| | | if (list == null || list.size() == 0) { |
| | | throw new ApplicationException("请在【9828】维护好查询参数!"); |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject = list.get(i); |
| | | datalist += typeControlDao.getSelectAndCheckBoxss( |
| | | GridUtils.prossRowSetDataType_String(mapObject, "StatisID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "FieldID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "FieldAlias"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "StatisType"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "Sequence"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "DisplayWidth"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "displayformat"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "displayYN"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "isFilterZero"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "jionFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "jionFlagGroup"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "conFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "modfvalues"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "modfvalues2"), |
| | | GridUtils.prossRowSetDataType_String(mapObject, "fieldCaption"), panelBean) |
| | | ; |
| | | } |
| | | |
| | | /** |
| | | * 生成38类型需要表格的标题列 StatisID,fieldid,StatisType|StatisID,fieldid,StatisType |
| | | * **/ |
| | | private String setWhere(String data) { |
| | | if ("".equalsIgnoreCase(data)) |
| | | return ""; |
| | | StringBuilder sb = new StringBuilder(); |
| | | String[] t = data.split("'"); |
| | | int i = 0; |
| | | for (String s : t) { |
| | | String[] st = s.split("#P#"); |
| | | if (i != 0) |
| | | sb.append(" or "); |
| | | sb.append(" (StatisID='" + st[0]).append("' and ") |
| | | .append(" fieldid= '" + st[1]).append("') "); |
| | | i++; |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | this.StatisNames = StatisID; |
| | | try { |
| | | datalist = java.net.URLDecoder.decode(datalist.replace("%", "@~"), |
| | | "utf-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.debug(e.getCause().getMessage()); |
| | | } |
| | | String encodeWhere = request.getParameter("where"); |
| | | GridData data = new GridData(); |
| | | //保存不解码的where,直接传回前端 |
| | | data.setWhere38(encodeWhere); |
| | | String where = EncodeUtil.base64Decode(encodeWhere); |
| | | gridService.create38Grid(data, formid, root, |
| | | this.setWhere(this.replaceBlank(datalist)), StatisID); |
| | | data.setDatalist(this.replaceBlank(datalist)); |
| | | data.setWhere(where); |
| | | Grid grid = new Grid(); |
| | | grid.setFormID(formid); |
| | | grid.setWinType(data.winType + ""); |
| | | grid.setField(data.field); |
| | | grid.setWhere(data.where); |
| | | grid.setDatalist(data.datalist); |
| | | grid.setTbCols(data.totalCols); |
| | | grid.setPos(pos); |
| | | grid.setQueryStringBy38(request.getQueryString()); |
| | | grid.setTotalRowNum(request.getParameter("totalRowNum") == null ? 0 : Integer.parseInt(request.getParameter("totalRowNum"))); |
| | | grid.setTotalPageNum(request.getParameter("totalPageNum") == null ? 0 : Integer.parseInt(request.getParameter("totalPageNum"))); |
| | | Object object = loadByFunc(model, data, grid, request, resp, grapht, formid, |
| | | StatisNames, StatisID); |
| | | if (VersionUtils.getAPPTypeName(request) != null) {//APP端 |
| | | Page page = (Page) object; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", page.getData());//数据 |
| | | map.put("cols", data.getCols_app());//列名 |
| | | map.put("align", page.getResultMap());//对齐方式 |
| | | map.put("summary", page.getTbColsOut());//页脚汇总 |
| | | this.printJson(resp, GridUtils.toJson(map)); |
| | | return null; |
| | | } else { |
| | | return String.valueOf(object); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | this.printJson(resp, e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 生成38类型显示所需要的数据 StatisID,fieldid,StatisType|StatisID,fieldid,StatisType |
| | | * **/ |
| | | private String[] setShow(String data) { |
| | | if ("".equalsIgnoreCase(data)) |
| | | return new String[] { "*", "" }; |
| | | String[] t = data.split("'"); |
| | | int i = 0; |
| | | int j = 0; |
| | | String sum = ""; |
| | | String order = ""; |
| | | String group = ""; |
| | | String as = ""; |
| | | String cv1 = ""; |
| | | int index = 0; |
| | | int y = 0; |
| | | int z = 0; |
| | | for (String s : t) { |
| | | /** |
| | | * 生成38类型需要表格的标题列 StatisID,fieldid,StatisType|StatisID,fieldid,StatisType |
| | | **/ |
| | | private String setWhere(String data) { |
| | | if ("".equalsIgnoreCase(data)) |
| | | return ""; |
| | | StringBuilder sb = new StringBuilder(); |
| | | String[] t = data.split("'"); |
| | | int i = 0; |
| | | for (String s : t) { |
| | | String[] st = s.split("#P#"); |
| | | if (i != 0) |
| | | sb.append(" or "); |
| | | sb.append(" (StatisID='" + st[0]).append("' and ") |
| | | .append(" fieldid= '" + st[1]).append("') "); |
| | | i++; |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | String[] st = s.split("#P#"); |
| | | if ("分组".equalsIgnoreCase(st[3].replaceAll("[\\s]", "")) |
| | | || "".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (i != 0) { |
| | | sum += ", "; |
| | | order += ", "; |
| | | group += ", "; |
| | | } |
| | | if (z != 0 && i == 0) { |
| | | sum += ", "; |
| | | order += ", "; |
| | | z = 0; |
| | | } |
| | | boolean groupFlg=true; |
| | | boolean orderFlg=true; |
| | | //存在有sum count avg min max,不能放在group by中 by danaus 18-10-26 |
| | | /** |
| | | * 生成38类型显示所需要的数据 StatisID,fieldid,StatisType|StatisID,fieldid,StatisType |
| | | **/ |
| | | private String[] setShow(String data) { |
| | | if ("".equalsIgnoreCase(data)) |
| | | return new String[]{"*", ""}; |
| | | String[] t = data.split("'"); |
| | | int i = 0; |
| | | int j = 0; |
| | | String sum = ""; |
| | | String order = ""; |
| | | String group = ""; |
| | | String as = ""; |
| | | String cv1 = ""; |
| | | int index = 0; |
| | | int y = 0; |
| | | int z = 0; |
| | | for (String s : t) { |
| | | |
| | | Matcher matcher= SUM_COUNT_AVG_MIN_MAX_PATTERN.matcher(st[1]); |
| | | if(matcher.find()) {//存在则在最后不需要增加这个值 |
| | | //group += st[1]; |
| | | //存在有 as +字段的情况需要去掉 |
| | | groupFlg=false; |
| | | } |
| | | String[] st = s.split("#P#"); |
| | | if ("分组".equalsIgnoreCase(st[3].replaceAll("[\\s]", "")) |
| | | || "".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (i != 0) { |
| | | sum += ", "; |
| | | order += ", "; |
| | | group += ", "; |
| | | } |
| | | if (z != 0 && i == 0) { |
| | | sum += ", "; |
| | | order += ", "; |
| | | z = 0; |
| | | } |
| | | boolean groupFlg = true; |
| | | boolean orderFlg = true; |
| | | //存在有sum count avg min max,不能放在group by中 by danaus 18-10-26 |
| | | |
| | | Matcher matcher = SUM_COUNT_AVG_MIN_MAX_PATTERN.matcher(st[1]); |
| | | if (matcher.find()) {//存在则在最后不需要增加这个值 |
| | | //group += st[1]; |
| | | //存在有 as +字段的情况需要去掉 |
| | | groupFlg = false; |
| | | } |
| | | |
| | | |
| | | matcher = AS_PATTERN.matcher(st[1]); |
| | | if (matcher.find()) {//存在 as 字段别名的情况, |
| | | //String filed=st[1].substring(matcher.end(),st[1].length());// accessoriesAmount |
| | | String sql = st[1].substring(0, matcher.start()); |
| | | order += sql+ " asc "; |
| | | orderFlg=false; |
| | | if(groupFlg){ |
| | | group += sql+" "; |
| | | groupFlg=false; |
| | | } |
| | | matcher = AS_PATTERN.matcher(st[1]); |
| | | if (matcher.find()) {//存在 as 字段别名的情况, |
| | | //String filed=st[1].substring(matcher.end(),st[1].length());// accessoriesAmount |
| | | String sql = st[1].substring(0, matcher.start()); |
| | | order += sql + " asc "; |
| | | orderFlg = false; |
| | | if (groupFlg) { |
| | | group += sql + " "; |
| | | groupFlg = false; |
| | | } |
| | | |
| | | } |
| | | if(orderFlg) order += st[1] + " asc "; |
| | | if(groupFlg) group += st[1]; |
| | | sum += st[1]; |
| | | i++; |
| | | } else if ("汇总".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | } |
| | | if (orderFlg) order += st[1] + " asc "; |
| | | if (groupFlg) group += st[1]; |
| | | sum += st[1]; |
| | | i++; |
| | | } else if ("汇总".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | |
| | | Matcher matcher= AS_PATTERN.matcher(st[1]); |
| | | String filed; |
| | | String sumsql; |
| | | // case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end as accessoriesAmount |
| | | //1,去掉 as accessoriesAmount |
| | | //--> case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end |
| | | //3,sum组装起来 sum(isnull(case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end ,0) |
| | | //4,最后再加上之前的去掉的 as accessoriesAmount,变成:sum(isnull(case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end ,0)) as accessoriesAmount |
| | | if(matcher.find()){//存在 as 字段别名的情况,在sum的情况下需要先去掉,组成好再重新加上 |
| | | filed=st[1].substring(matcher.end(),st[1].length());// accessoriesAmount |
| | | sumsql=st[1].substring(0,matcher.start()); |
| | | } |
| | | Matcher matcher = AS_PATTERN.matcher(st[1]); |
| | | String filed; |
| | | String sumsql; |
| | | // case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end as accessoriesAmount |
| | | //1,去掉 as accessoriesAmount |
| | | //--> case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end |
| | | //3,sum组装起来 sum(isnull(case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end ,0) |
| | | //4,最后再加上之前的去掉的 as accessoriesAmount,变成:sum(isnull(case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end ,0)) as accessoriesAmount |
| | | if (matcher.find()) {//存在 as 字段别名的情况,在sum的情况下需要先去掉,组成好再重新加上 |
| | | filed = st[1].substring(matcher.end(), st[1].length());// accessoriesAmount |
| | | sumsql = st[1].substring(0, matcher.start()); |
| | | } |
| | | // else if(st[1].indexOf("case")>-1){// 自定义字段列名,但又不是写 as 列名的情况 |
| | | // |
| | | // // case when isnull(acctcode,'') in ('5101004','1403004') then isnull(InAmount,0) else 0 end |
| | |
| | | // //sumsql=st[1]; |
| | | // |
| | | // } |
| | | else{ |
| | | filed=st[1]; |
| | | sumsql=st[1]; |
| | | } |
| | | else { |
| | | filed = st[1]; |
| | | sumsql = st[1]; |
| | | } |
| | | |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " sum(isnull(" + sumsql + ",0)) as " + filed; |
| | | order += ", "; |
| | | order += " sum(isnull(" + sumsql + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " sum(isnull(" + sumsql + ",0)) as " + filed; |
| | | order += " sum(isnull(" + sumsql + ",0)) asc"; |
| | | } |
| | | z++; |
| | | } else if ("自定义".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | //case when sum(isnull(balance,0)) >0 then sum(isnull(balance,0)) else 0 end as balance3 |
| | | if (j != 0 || sum.length() > 0) { |
| | | as = ""; |
| | | as += st[1]; |
| | | index = as.toLowerCase().lastIndexOf("end"); |
| | | cv1 = as.substring(0, index + 4).trim(); |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " sum(isnull(" + sumsql + ",0)) as " + filed; |
| | | order += ", "; |
| | | order += " sum(isnull(" + sumsql + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " sum(isnull(" + sumsql + ",0)) as " + filed; |
| | | order += " sum(isnull(" + sumsql + ",0)) asc"; |
| | | } |
| | | z++; |
| | | } else if ("自定义".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | //case when sum(isnull(balance,0)) >0 then sum(isnull(balance,0)) else 0 end as balance3 |
| | | if (j != 0 || sum.length() > 0) { |
| | | as = ""; |
| | | as += st[1]; |
| | | index = as.toLowerCase().lastIndexOf("end"); |
| | | cv1 = as.substring(0, index + 4).trim(); |
| | | |
| | | sum += ", "; |
| | | sum += st[1]; |
| | | order += ", "; |
| | | order += cv1 + " asc"; |
| | | y++; |
| | | j++; |
| | | sum += ", "; |
| | | sum += st[1]; |
| | | order += ", "; |
| | | order += cv1 + " asc"; |
| | | y++; |
| | | j++; |
| | | |
| | | } else { |
| | | as = ""; |
| | | as += st[1]; |
| | | index = as.indexOf("end"); |
| | | cv1 = as.toLowerCase().substring(0, index + 4); |
| | | sum += st[1] + "as" + cv1; |
| | | order += cv1 + " asc"; |
| | | } |
| | | z++; |
| | | } else if ("最大".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " max(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " max(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " max(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " max(isnull(" + st[1] + ",0)) asc"; |
| | | } |
| | | z++; |
| | | } else if ("最小".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " min(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " min(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " min(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " min(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } |
| | | z++; |
| | | } else if ("平均".equalsIgnoreCase(st[3].replaceAll(" ", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " avg(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " avg(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " avg(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " avg(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } |
| | | z++; |
| | | } else if ("个数".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " count(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | } else { |
| | | as = ""; |
| | | as += st[1]; |
| | | index = as.indexOf("end"); |
| | | cv1 = as.toLowerCase().substring(0, index + 4); |
| | | sum += st[1] + "as" + cv1; |
| | | order += cv1 + " asc"; |
| | | } |
| | | z++; |
| | | } else if ("最大".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " max(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " max(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " max(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " max(isnull(" + st[1] + ",0)) asc"; |
| | | } |
| | | z++; |
| | | } else if ("最小".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " min(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " min(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " min(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " min(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } |
| | | z++; |
| | | } else if ("平均".equalsIgnoreCase(st[3].replaceAll(" ", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " avg(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | order += " avg(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " avg(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " avg(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } |
| | | z++; |
| | | } else if ("个数".equalsIgnoreCase(st[3].replaceAll("[\\s]", ""))) { |
| | | if (j != 0 || sum.length() > 0) { |
| | | sum += ", "; |
| | | sum += " count(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += ", "; |
| | | |
| | | order += " count(isnull(" + st[1] + ",0)) asc"; |
| | | order += " count(isnull(" + st[1] + ",0)) asc"; |
| | | |
| | | j++; |
| | | } else { |
| | | sum += " count(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " count(isnull(" + st[1] + ",0)) asc"; |
| | | j++; |
| | | } else { |
| | | sum += " count(isnull(" + st[1] + ",0)) as " + st[1]; |
| | | order += " count(isnull(" + st[1] + ",0)) asc"; |
| | | |
| | | j++; |
| | | } |
| | | z++; |
| | | } |
| | | j++; |
| | | } |
| | | z++; |
| | | } |
| | | |
| | | // select a,b,c from t |
| | | // select case when esle end sum(a) as a,max(b) as b .... |
| | | // select a,b,c from t |
| | | // select case when esle end sum(a) as a,max(b) as b .... |
| | | |
| | | } |
| | | return new String[] { sum, order, group }; |
| | | } |
| | | private String selectdata(HttpSession session, HttpServletRequest request, |
| | | int formid, String StatisNames) throws ApplicationException{ |
| | | } |
| | | return new String[]{sum, order, group}; |
| | | } |
| | | |
| | | Map<String,String> sql=new HashMap<>(8); |
| | | Map<String,String> JionFlagMap=new HashMap<>(8); |
| | | List<Map<String, Object>> list = gridService.selectdata(formid, |
| | | StatisNames); |
| | | //1.组装值sql |
| | | for(Map map:list){ |
| | | StringBuffer havingstr=new StringBuffer(); |
| | | //针对 between and 或 not between and 的情况 作判断 ,因为需要取第二个值来组装sql |
| | | boolean isbetween=false; |
| | | //分组号 |
| | | int jionFlagGroup=0; |
| | | //关系符 |
| | | String jionflag=""; |
| | | //连接符 |
| | | String conFlag=""; |
| | | int isFilterZeros =GridUtils.prossRowSetDataType_Int(map,"isFilterZero"); |
| | | try{ |
| | | //分组号 |
| | | jionFlagGroup=GridUtils.prossRowSetDataType_Int(map,"jionFlagGroup"); |
| | | //关系符 |
| | | jionflag=GridUtils.prossRowSetDataType_String(map,"jionFlag"); |
| | | //连接符 |
| | | conFlag=GridUtils.prossRowSetDataType_String(map,"conFlag"); |
| | | }catch(Exception e){ |
| | | throw new ApplicationException("jionFlagGroup,jionFlag,conFlag没进行设置,请检查里面设置"); |
| | | } |
| | | if(isFilterZeros==0&&"".equals(conFlag.trim())) continue; |
| | | String StatisType = GridUtils.prossRowSetDataType_String(map,"StatisType"); |
| | | if(StatisType.equals("")) |
| | | StatisType= "分组"; |
| | | String FieldID = GridUtils.prossRowSetDataType_String(map,"FieldID"); |
| | | Matcher matcher= AS_PATTERN.matcher(FieldID); |
| | | //存在 as 字段别名的情况,在sum的情况下需要先去掉,组成好再重新加上 |
| | | if(matcher.find()){ |
| | | FieldID=FieldID.substring(0,matcher.start()); |
| | | } |
| | | //处理过滤空值和0 |
| | | if(isFilterZeros==1){ |
| | | havingstr.append(" ( "); |
| | | if (StatisType.equalsIgnoreCase("分组")) { |
| | | havingstr.append(" isnull(" + FieldID + ",'') <> '') "); |
| | | } else if (StatisType.equalsIgnoreCase("汇总")) { |
| | | havingstr.append(" sum("); |
| | | havingstr.append("isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("最大")) { |
| | | havingstr.append(" max("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("最小")) { |
| | | havingstr.append(" min("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("平均")) { |
| | | havingstr.append(" avg("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("个数")) { |
| | | havingstr.append(" count("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("自定义")) { |
| | | havingstr.append( FieldID + " <> 0) "); |
| | | } |
| | | } |
| | | //设置了连接符和比较符及选上过滤空值的情况 |
| | | if (jionflag != null && !jionflag.trim().equals("") && conFlag != null |
| | | && !conFlag.trim().equals("")) { |
| | | if (isFilterZeros == 1) |
| | | havingstr.append(" and ("); |
| | | else |
| | | havingstr.append(" ("); |
| | | private String selectdata(HttpSession session, HttpServletRequest request, |
| | | int formid, String StatisNames) throws ApplicationException { |
| | | |
| | | if (StatisType.equalsIgnoreCase("分组")) { |
| | | Map<String, String> sql = new HashMap<>(8); |
| | | Map<String, String> JionFlagMap = new HashMap<>(8); |
| | | List<Map<String, Object>> list = gridService.selectdata(formid, |
| | | StatisNames); |
| | | //1.组装值sql |
| | | for (Map map : list) { |
| | | StringBuffer havingstr = new StringBuffer(); |
| | | //针对 between and 或 not between and 的情况 作判断 ,因为需要取第二个值来组装sql |
| | | boolean isbetween = false; |
| | | //分组号 |
| | | int jionFlagGroup = 0; |
| | | //关系符 |
| | | String jionflag = ""; |
| | | //连接符 |
| | | String conFlag = ""; |
| | | int isFilterZeros = GridUtils.prossRowSetDataType_Int(map, "isFilterZero"); |
| | | try { |
| | | //分组号 |
| | | jionFlagGroup = GridUtils.prossRowSetDataType_Int(map, "jionFlagGroup"); |
| | | //关系符 |
| | | jionflag = GridUtils.prossRowSetDataType_String(map, "jionFlag"); |
| | | //连接符 |
| | | conFlag = GridUtils.prossRowSetDataType_String(map, "conFlag"); |
| | | } catch (Exception e) { |
| | | throw new ApplicationException("jionFlagGroup,jionFlag,conFlag没进行设置,请检查里面设置"); |
| | | } |
| | | if (isFilterZeros == 0 && "".equals(conFlag.trim())) continue; |
| | | String StatisType = GridUtils.prossRowSetDataType_String(map, "StatisType"); |
| | | if (StatisType.equals("")) |
| | | StatisType = "分组"; |
| | | String FieldID = GridUtils.prossRowSetDataType_String(map, "FieldID"); |
| | | Matcher matcher = AS_PATTERN.matcher(FieldID); |
| | | //存在 as 字段别名的情况,在sum的情况下需要先去掉,组成好再重新加上 |
| | | if (matcher.find()) { |
| | | FieldID = FieldID.substring(0, matcher.start()); |
| | | } |
| | | //处理过滤空值和0 |
| | | if (isFilterZeros == 1) { |
| | | havingstr.append(" ( "); |
| | | if (StatisType.equalsIgnoreCase("分组")) { |
| | | havingstr.append(" isnull(" + FieldID + ",'') <> '') "); |
| | | } else if (StatisType.equalsIgnoreCase("汇总")) { |
| | | havingstr.append(" sum("); |
| | | havingstr.append("isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("最大")) { |
| | | havingstr.append(" max("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("最小")) { |
| | | havingstr.append(" min("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("平均")) { |
| | | havingstr.append(" avg("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("个数")) { |
| | | havingstr.append(" count("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) <> 0) "); |
| | | } else if (StatisType.equalsIgnoreCase("自定义")) { |
| | | havingstr.append(FieldID + " <> 0) "); |
| | | } |
| | | } |
| | | //设置了连接符和比较符及选上过滤空值的情况 |
| | | if (jionflag != null && !jionflag.trim().equals("") && conFlag != null |
| | | && !conFlag.trim().equals("")) { |
| | | if (isFilterZeros == 1) |
| | | havingstr.append(" and ("); |
| | | else |
| | | havingstr.append(" ("); |
| | | |
| | | havingstr.append(" isnull(" + FieldID + ",'') "); |
| | | } else if (StatisType.equalsIgnoreCase("汇总")) { |
| | | if (StatisType.equalsIgnoreCase("分组")) { |
| | | |
| | | havingstr.append(" sum("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("最大")) { |
| | | havingstr.append(" isnull(" + FieldID + ",'') "); |
| | | } else if (StatisType.equalsIgnoreCase("汇总")) { |
| | | |
| | | havingstr.append(" max("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("最小")) { |
| | | havingstr.append(" sum("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("最大")) { |
| | | |
| | | havingstr.append(" min("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("平均")) { |
| | | havingstr.append(" max("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("最小")) { |
| | | |
| | | havingstr.append(" avg("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("个数")) { |
| | | havingstr.append(" min("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("平均")) { |
| | | |
| | | havingstr.append(" count("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("自定义")) { |
| | | havingstr.append(" avg("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("个数")) { |
| | | |
| | | havingstr.append(FieldID + ""); |
| | | } |
| | | havingstr.append(" count("); |
| | | havingstr.append(" isnull(" + FieldID + ",0)) "); |
| | | } else if (StatisType.equalsIgnoreCase("自定义")) { |
| | | |
| | | havingstr.append(FieldID + ""); |
| | | } |
| | | |
| | | |
| | | String modfvalues = (String) map.get("modfvalues"); |
| | | String modfvalues2 = (String) map.get("modfvalues2"); |
| | | java.util.regex.Matcher propsMatcher = START_WOROD_PATTERN.matcher(modfvalues); |
| | | while (propsMatcher.find()) { |
| | | try { |
| | | String tem = (String) session.getAttribute(propsMatcher.group().toLowerCase()); |
| | | modfvalues = modfvalues.replaceAll(propsMatcher.group(), tem); |
| | | } catch (Exception e) { |
| | | throw new ApplicationException(propsMatcher.group() + "不存在于会话中,请检查数据组权限设置"); |
| | | } |
| | | String modfvalues = (String) map.get("modfvalues"); |
| | | String modfvalues2 = (String) map.get("modfvalues2"); |
| | | java.util.regex.Matcher propsMatcher = START_WOROD_PATTERN.matcher(modfvalues); |
| | | while (propsMatcher.find()) { |
| | | try { |
| | | String tem = (String) session.getAttribute(propsMatcher.group().toLowerCase()); |
| | | modfvalues = modfvalues.replaceAll(propsMatcher.group(), tem); |
| | | } catch (Exception e) { |
| | | throw new ApplicationException(propsMatcher.group() + "不存在于会话中,请检查数据组权限设置"); |
| | | } |
| | | |
| | | } |
| | | if (conFlag.toLowerCase().indexOf("between") > -1 || |
| | | conFlag.toLowerCase().indexOf("not between") > -1 |
| | | ) { |
| | | isbetween = true; |
| | | } |
| | | if (isbetween && (modfvalues2 == null || modfvalues2.length() == 0)) { |
| | | throw new ApplicationException("between and 或 not between and 的第二个值没有设置,请检查[功能号:9936(检查对象内容)]里面设置"); |
| | | } |
| | | if (isbetween) { |
| | | propsMatcher = START_WOROD_PATTERN.matcher(modfvalues2); |
| | | while (propsMatcher.find()) { |
| | | modfvalues2 = modfvalues2.replaceAll(propsMatcher.group(), (String) session.getAttribute(propsMatcher.group().toLowerCase())); |
| | | } |
| | | havingstr.append(" " + conFlag) |
| | | .append(" " + modfvalues) |
| | | .append(" and ") |
| | | .append(modfvalues2); |
| | | } else if (conFlag.toLowerCase().indexOf("like") > -1 || |
| | | conFlag.toLowerCase().indexOf("not like") > -1) { |
| | | //处理有单引号情况 'dddd' |
| | | modfvalues = modfvalues.replaceAll("'", ""); |
| | | havingstr.append(" " + conFlag) |
| | | .append(" '%" + modfvalues + "%'"); |
| | | } |
| | | if (conFlag.toLowerCase().indexOf("between") > -1 || |
| | | conFlag.toLowerCase().indexOf("not between") > -1 |
| | | ) { |
| | | isbetween = true; |
| | | } |
| | | if (isbetween && (modfvalues2 == null || modfvalues2.length() == 0)) { |
| | | throw new ApplicationException("between and 或 not between and 的第二个值没有设置,请检查[功能号:9936(检查对象内容)]里面设置"); |
| | | } |
| | | if (isbetween) { |
| | | propsMatcher = START_WOROD_PATTERN.matcher(modfvalues2); |
| | | while (propsMatcher.find()) { |
| | | modfvalues2 = modfvalues2.replaceAll(propsMatcher.group(), (String) session.getAttribute(propsMatcher.group().toLowerCase())); |
| | | } |
| | | havingstr.append(" " + conFlag) |
| | | .append(" " + modfvalues) |
| | | .append(" and ") |
| | | .append(modfvalues2); |
| | | } else if (conFlag.toLowerCase().indexOf("like") > -1 || |
| | | conFlag.toLowerCase().indexOf("not like") > -1) { |
| | | //处理有单引号情况 'dddd' |
| | | modfvalues = modfvalues.replaceAll("'", ""); |
| | | havingstr.append(" " + conFlag) |
| | | .append(" '%" + modfvalues + "%'"); |
| | | |
| | | } else if (conFlag.toLowerCase().indexOf("in") > -1 || |
| | | conFlag.toLowerCase().indexOf("not in") > -1) { |
| | | //*****处理广陶 CS版兼容问题,增加单引号 by 2016-3-4 |
| | | String temp = ""; |
| | | String[] arr = modfvalues.split(","); |
| | | for (String r : arr) { |
| | | if (r.startsWith("'") && r.endsWith("'")) |
| | | temp += r + ","; |
| | | else { |
| | | // System.out.println("r---->>>>>>>>>>>"+r); |
| | | if (r.startsWith("'") || r.endsWith("'"))//存在一种情况需要去掉单引号 |
| | | temp += "'" + r.replaceAll("'", "") + "',"; |
| | | else |
| | | temp += "'" + r + "',"; |
| | | } |
| | | } |
| | | havingstr.append(" " + conFlag) |
| | | .append(" (" + temp.substring(0, temp.length() - 1) + ")"); |
| | | } else if (conFlag.toLowerCase().indexOf("in") > -1 || |
| | | conFlag.toLowerCase().indexOf("not in") > -1) { |
| | | //*****处理广陶 CS版兼容问题,增加单引号 by 2016-3-4 |
| | | String temp = ""; |
| | | String[] arr = modfvalues.split(","); |
| | | for (String r : arr) { |
| | | if (r.startsWith("'") && r.endsWith("'")) |
| | | temp += r + ","; |
| | | else { |
| | | // System.out.println("r---->>>>>>>>>>>"+r); |
| | | if (r.startsWith("'") || r.endsWith("'"))//存在一种情况需要去掉单引号 |
| | | temp += "'" + r.replaceAll("'", "") + "',"; |
| | | else |
| | | temp += "'" + r + "',"; |
| | | } |
| | | } |
| | | havingstr.append(" " + conFlag) |
| | | .append(" (" + temp.substring(0, temp.length() - 1) + ")"); |
| | | |
| | | } else { |
| | | havingstr.append(" " + conFlag) |
| | | .append(" " + modfvalues); |
| | | } |
| | | havingstr.append(" )");//当前项结束 |
| | | } |
| | | } else { |
| | | havingstr.append(" " + conFlag) |
| | | .append(" " + modfvalues); |
| | | } |
| | | havingstr.append(" )");//当前项结束 |
| | | } |
| | | |
| | | String temp=sql.get(jionFlagGroup+""); |
| | | if(temp==null) { |
| | | sql.put(jionFlagGroup + "", havingstr.toString()); |
| | | JionFlagMap.put(jionFlagGroup+"","".equals(jionflag.trim())?" and ":jionflag.trim()); |
| | | }else{//拼接 |
| | | if("".equals(jionflag.trim())){ jionflag=" and ";} |
| | | sql.put(jionFlagGroup+"",sql.get(jionFlagGroup+"")+"" +jionflag+havingstr.toString()); |
| | | } |
| | | } |
| | | String temp = sql.get(jionFlagGroup + ""); |
| | | if (temp == null) { |
| | | sql.put(jionFlagGroup + "", havingstr.toString()); |
| | | JionFlagMap.put(jionFlagGroup + "", "".equals(jionflag.trim()) ? " and " : jionflag.trim()); |
| | | } else {//拼接 |
| | | if ("".equals(jionflag.trim())) { |
| | | jionflag = " and "; |
| | | } |
| | | sql.put(jionFlagGroup + "", sql.get(jionFlagGroup + "") + "" + jionflag + havingstr.toString()); |
| | | } |
| | | } |
| | | //2.再拼接最终sql的顺序,根据分组和连接符拼接 |
| | | String st=""; |
| | | int index=0; |
| | | for(Map.Entry<String,String> entry:sql.entrySet()){ |
| | | String temJionFlag=""; |
| | | if(index>0) { |
| | | temJionFlag = JionFlagMap.get(entry.getKey()); |
| | | st = st +" "+ temJionFlag + " (" + entry.getValue() + ")"; |
| | | }else{ |
| | | st += entry.getValue(); |
| | | } |
| | | index++; |
| | | } |
| | | return st.equals("")?"":(" having ("+st+")"); |
| | | } |
| | | String st = ""; |
| | | int index = 0; |
| | | for (Map.Entry<String, String> entry : sql.entrySet()) { |
| | | String temJionFlag = ""; |
| | | if (index > 0) { |
| | | temJionFlag = JionFlagMap.get(entry.getKey()); |
| | | st = st + " " + temJionFlag + " (" + entry.getValue() + ")"; |
| | | } else { |
| | | st += entry.getValue(); |
| | | } |
| | | index++; |
| | | } |
| | | return st.equals("") ? "" : (" having (" + st + ")"); |
| | | } |
| | | |
| | | private void prossDisplayFormat(Page page){ |
| | | List list=page.getData(); |
| | | if(list==null||list.size()<0) {return;} |
| | | Map<String, Map<String, Object>> resultMap= (Map<String, Map<String, Object>>) page.getResultMap(); |
| | | for(int i=0;i<list.size();i++){ |
| | | //每行 |
| | | Map<String,Object> map=(Map<String,Object>)list.get(i); |
| | | if(map.containsKey("_ROWNO")) {map.remove("_ROWNO");} |
| | | for(Map.Entry<String, Object> entry : map.entrySet()) { |
| | | Map<String, Object> map2 = resultMap.get(entry.getKey().toLowerCase()); |
| | | if(map2!=null){ |
| | | String displayFormat = GridUtils.prossRowSetDataType_String(map2, "displayformat"); |
| | | if (StringUtils.isNotBlank(displayFormat)) { |
| | | if (displayFormat.indexOf("-") > 0) {//表示日期格式 |
| | | String displayformat[] = (map2.get("displayformat") + "").split("-"); |
| | | if (displayformat.length >= 2) { |
| | | SimpleDateFormat formatter = new SimpleDateFormat((map2.get("displayformat") + "")); |
| | | String dateString = formatter.format(entry.getValue()); |
| | | entry.setValue(dateString); |
| | | } |
| | | } else { |
| | | if (displayFormat.startsWith(",0")) { |
| | | private void prossDisplayFormat(Page page) { |
| | | List list = page.getData(); |
| | | if (list == null || list.size() < 0) { |
| | | return; |
| | | } |
| | | Map<String, Map<String, Object>> resultMap = (Map<String, Map<String, Object>>) page.getResultMap(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | //每行 |
| | | Map<String, Object> map = (Map<String, Object>) list.get(i); |
| | | if (map.containsKey("_ROWNO")) { |
| | | map.remove("_ROWNO"); |
| | | } |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | Map<String, Object> map2 = resultMap.get(entry.getKey().toLowerCase()); |
| | | if (map2 != null) { |
| | | String displayFormat = GridUtils.prossRowSetDataType_String(map2, "displayformat"); |
| | | if (StringUtils.isNotBlank(displayFormat)) { |
| | | if (displayFormat.indexOf("-") > 0) {//表示日期格式 |
| | | String displayformat[] = (map2.get("displayformat") + "").split("-"); |
| | | if (displayformat.length >= 2) { |
| | | SimpleDateFormat formatter = new SimpleDateFormat((map2.get("displayformat") + "")); |
| | | String dateString = formatter.format(entry.getValue()); |
| | | entry.setValue(dateString); |
| | | } |
| | | } else { |
| | | if (displayFormat.startsWith(",0")) { |
| | | |
| | | displayFormat = displayFormat.replace(",0", ",###"); |
| | | }else if(displayFormat.startsWith(",.")){ |
| | | displayFormat = displayFormat.replace(",", ",###"); |
| | | } |
| | | if(entry.getValue()!=null) { |
| | | entry.setValue(new DecimalFormat(displayFormat).format(Double.parseDouble(entry.getValue() + ""))); |
| | | }else{ |
| | | entry.setValue(entry.getValue()); |
| | | } |
| | | } |
| | | displayFormat = displayFormat.replace(",0", ",###"); |
| | | } else if (displayFormat.startsWith(",.")) { |
| | | displayFormat = displayFormat.replace(",", ",###"); |
| | | } |
| | | if (entry.getValue() != null) { |
| | | entry.setValue(new DecimalFormat(displayFormat).format(Double.parseDouble(entry.getValue() + ""))); |
| | | } else { |
| | | entry.setValue(entry.getValue()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //处理页脚汇总 |
| | | String tbColsOut=page.getTbColsOut(); |
| | | String newtbCols=page.getNewTbCols(); |
| | | if(StringUtils.isNotBlank(tbColsOut)&&!tbColsOut.contains("replace")){ |
| | | tbColsOut=tbColsOut.replaceAll("\\.#", "#"); |
| | | Map<String, Map<String, Object>> map= (Map<String, Map<String, Object>>) page.getResultMap(); |
| | | String[] strings=tbColsOut.split("#p#"); |
| | | String[] fileds=newtbCols.split(";");//取汇总字段 |
| | | int index=0; |
| | | for(String str:fileds){ |
| | | String[] cols=str.split("="); |
| | | Map<String, Object> formatMap=map.get(cols[0]); |
| | | String displayFormat=GridUtils.prossRowSetDataType_String(formatMap,"displayformat"); |
| | | if (StringUtils.isNotBlank(displayFormat)) { |
| | | if(displayFormat.startsWith(",0")){ |
| | | displayFormat=displayFormat.replace(",0",",###"); |
| | | }else if(displayFormat.startsWith(",.")){ |
| | | displayFormat=displayFormat.replace(",",",###"); |
| | | } |
| | | newtbCols=newtbCols.replace("#"+index,new DecimalFormat(displayFormat).format(Double.parseDouble(strings[index]))); |
| | | }else{ |
| | | newtbCols=newtbCols.replace("#"+index,new DecimalFormat("0.00").format(Double.parseDouble(strings[index]))); |
| | | } |
| | | index++; |
| | | } |
| | | page.setTbColsOut(newtbCols); |
| | | }else{ |
| | | page.setTbColsOut(""); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //处理页脚汇总 |
| | | String tbColsOut = page.getTbColsOut(); |
| | | String newtbCols = page.getNewTbCols(); |
| | | if (StringUtils.isNotBlank(tbColsOut) && !tbColsOut.contains("replace")) { |
| | | tbColsOut = tbColsOut.replaceAll("\\.#", "#"); |
| | | Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) page.getResultMap(); |
| | | String[] strings = tbColsOut.split("#p#"); |
| | | String[] fileds = newtbCols.split(";");//取汇总字段 |
| | | int index = 0; |
| | | for (String str : fileds) { |
| | | String[] cols = str.split("="); |
| | | Map<String, Object> formatMap = map.get(cols[0]); |
| | | String displayFormat = GridUtils.prossRowSetDataType_String(formatMap, "displayformat"); |
| | | if (StringUtils.isNotBlank(displayFormat)) { |
| | | if (displayFormat.startsWith(",0")) { |
| | | displayFormat = displayFormat.replace(",0", ",###"); |
| | | } else if (displayFormat.startsWith(",.")) { |
| | | displayFormat = displayFormat.replace(",", ",###"); |
| | | } |
| | | newtbCols = newtbCols.replace("#" + index, new DecimalFormat(displayFormat).format(Double.parseDouble(strings[index]))); |
| | | } else { |
| | | newtbCols = newtbCols.replace("#" + index, new DecimalFormat("0.00").format(Double.parseDouble(strings[index]))); |
| | | } |
| | | index++; |
| | | } |
| | | page.setTbColsOut(newtbCols); |
| | | } else { |
| | | page.setTbColsOut(""); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 38类型窗体调用函数 |
| | | * */ |
| | | @RequestMapping(params = "m=load") |
| | | public Object loadByFunc(Model model, GridData data, Grid grid, |
| | | HttpServletRequest request, HttpServletResponse resp, |
| | | Integer grapht, int formid, String StatisNames,String StatisID) throws Exception { |
| | | Page page =null; |
| | | if(request.getParameter("TGData")==null) { |
| | | page = JOSNUtils.setPageInfoData(data);// 第一步,照写 |
| | | }else { |
| | | page = this.setPageInfoTree(request);// 第一步,照写 |
| | | } |
| | | page.setTbCols(EncodeUtil.base64Encode(data.getTotalCols())); |
| | | this.formID = grid.getFormID(); |
| | | env = this.initEnv(request, this.formID, "", false); |
| | | String[] temp = this.setShow(grid.getDatalist());// 参数 |
| | | page.setOrderBy(temp[1]); |
| | | HttpSession session = request.getSession(); |
| | | String having = this.selectdata(session, request, formid, StatisID);//处理having |
| | | if (temp.length >= 3) { |
| | | page.setGroupby("".equalsIgnoreCase(temp[2]) ? "" : " group by " |
| | | + temp[2] + " " + having); |
| | | } else { |
| | | request.setAttribute("message", "没有定义输出的显示栏位!!!"); |
| | | } |
| | | /**/ |
| | | page.setWhere(grid.getWhere().replaceAll("\\\\", "")); |
| | | page.setFlag(grid.getFlag()); |
| | | String[] t = splitTable(grid.getWinType()); |
| | | page.setTableName(t[0]); |
| | | page.setParms(t[1]); |
| | | GTGrid gtGrid= (GTGrid) FactoryBean.getBean("GTGrid"); |
| | | String dataGroup=""; |
| | | dataGroup=gtGrid.prossDataGroup(request,this.formID,0); |
| | | if("".equals(page.getWhere())){ |
| | | page.setWhere(" 1 =1 "+dataGroup); |
| | | }else { |
| | | page.setWhere(page.getWhere() + dataGroup); |
| | | } |
| | | page.setDataGroup(dataGroup); |
| | | page.setSql(this.exprTOSql(page, temp[0])); |
| | | request.setAttribute("StatisNames", StatisNames); |
| | | request.setAttribute("formid", formid); |
| | | request.setAttribute("where", data.getWhere38()); |
| | | String dbid=request.getSession().getAttribute(SessionKey.DATA_BASE_ID)+""; |
| | | createDyTitle(data, request, dbid); |
| | | try { |
| | | SpObserver.setDBtoInstance("_"+dbid); |
| | | page.setUserCode(request.getSession().getAttribute(SessionKey.USERCODE)+""); |
| | | page.setUserName(request.getSession().getAttribute(SessionKey.USER_NAME)+""); |
| | | page.setFormid(grid.getFormID()); |
| | | if(VersionUtils.getAPPTypeName(request) != null){ |
| | | page.setPageNum(grid.getPos()); |
| | | } |
| | | type38Ifc.loadAllByFunc(page, env, false, StatisID, formid);// 第二步,调用相对应业务类取得数据 |
| | | if(page.getPos()>0){ |
| | | //表示不是第一页,分页功能不会再执行计总数和总页面和汇总操作,所以需要把前端传过来的做一个保存 |
| | | page.setTotalPageNum(grid.getTotalPageNum()); |
| | | page.setTotalRowNum(grid.getTotalRowNum()); |
| | | } |
| | | } catch (Exception e) { |
| | | //e.printStackTrace(); |
| | | /* this.print(resp, e.getMessage().split(";")[2]); */ |
| | | request.setAttribute("message", e.getCause()!=null?e.getCause().getMessage():e.getMessage()); |
| | | //return null; |
| | | }finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | //区分是app端还是pc端调用 |
| | | if(VersionUtils.getAPPTypeName(request) != null){ |
| | | //处理格式,app不需要再处理一次格式 |
| | | prossDisplayFormat(page); |
| | | /** |
| | | * 38类型窗体调用函数 |
| | | */ |
| | | @RequestMapping(params = "m=load") |
| | | public Object loadByFunc(Model model, GridData data, Grid grid, |
| | | HttpServletRequest request, HttpServletResponse resp, |
| | | Integer grapht, int formid, String StatisNames, String StatisID) throws Exception { |
| | | Page page = null; |
| | | if (request.getParameter("TGData") == null) { |
| | | page = JOSNUtils.setPageInfoData(data);// 第一步,照写 |
| | | } else { |
| | | page = this.setPageInfoTree(request);// 第一步,照写 |
| | | } |
| | | page.setTbCols(EncodeUtil.base64Encode(data.getTotalCols())); |
| | | this.formID = grid.getFormID(); |
| | | env = this.initEnv(request, this.formID, "", false); |
| | | String[] temp = this.setShow(grid.getDatalist());// 参数 |
| | | page.setOrderBy(temp[1]); |
| | | HttpSession session = request.getSession(); |
| | | String having = this.selectdata(session, request, formid, StatisID);//处理having |
| | | if (temp.length >= 3) { |
| | | page.setGroupby("".equalsIgnoreCase(temp[2]) ? "" : " group by " |
| | | + temp[2] + " " + having); |
| | | } else { |
| | | request.setAttribute("message", "没有定义输出的显示栏位!!!"); |
| | | } |
| | | /**/ |
| | | page.setWhere(grid.getWhere().replaceAll("\\\\", "")); |
| | | page.setFlag(grid.getFlag()); |
| | | String[] t = splitTable(grid.getWinType()); |
| | | page.setTableName(t[0]); |
| | | page.setParms(t[1]); |
| | | GTGrid gtGrid = (GTGrid) FactoryBean.getBean("GTGrid"); |
| | | String dataGroup = ""; |
| | | dataGroup = gtGrid.prossDataGroup(request, this.formID, 0); |
| | | if ("".equals(page.getWhere())) { |
| | | page.setWhere(" 1 =1 " + dataGroup); |
| | | } else { |
| | | page.setWhere(page.getWhere() + dataGroup); |
| | | } |
| | | page.setDataGroup(dataGroup); |
| | | page.setSql(this.exprTOSql(page, temp[0])); |
| | | request.setAttribute("StatisNames", StatisNames); |
| | | request.setAttribute("formid", formid); |
| | | request.setAttribute("where", data.getWhere38()); |
| | | String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + ""; |
| | | createDyTitle(data, request, dbid); |
| | | try { |
| | | SpObserver.setDBtoInstance("_" + dbid); |
| | | page.setUserCode(request.getSession().getAttribute(SessionKey.USERCODE) + ""); |
| | | page.setUserName(request.getSession().getAttribute(SessionKey.USER_NAME) + ""); |
| | | page.setFormid(grid.getFormID()); |
| | | if (VersionUtils.getAPPTypeName(request) != null) { |
| | | page.setPageNum(grid.getPos()); |
| | | } |
| | | type38Ifc.loadAllByFunc(page, env, false, StatisID, formid);// 第二步,调用相对应业务类取得数据 |
| | | if (page.getPos() > 0) { |
| | | //表示不是第一页,分页功能不会再执行计总数和总页面和汇总操作,所以需要把前端传过来的做一个保存 |
| | | page.setTotalPageNum(grid.getTotalPageNum()); |
| | | page.setTotalRowNum(grid.getTotalRowNum()); |
| | | } |
| | | } catch (Exception e) { |
| | | //e.printStackTrace(); |
| | | /* this.print(resp, e.getMessage().split(";")[2]); */ |
| | | request.setAttribute("message", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
| | | //return null; |
| | | } finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | //区分是app端还是pc端调用 |
| | | if (VersionUtils.getAPPTypeName(request) != null) { |
| | | //处理格式,app不需要再处理一次格式 |
| | | prossDisplayFormat(page); |
| | | |
| | | return page; |
| | | }else { |
| | | StringBuilder str = new StringBuilder(); |
| | | if(page.getPos()==0){ |
| | | String sql = "select optype,frozencols from gform where formid=" + formid + ""; |
| | | List<Map<String, Object>> list38 = type38.girddata(sql); |
| | | Map<String, Object> map38 = null; |
| | | int frozencols = 0; |
| | | for (int i = 0; i < list38.size(); i++) { |
| | | map38 = list38.get(i); |
| | | request.setAttribute("optype", GridUtils.prossRowSetDataType_Int(map38,"optype")); |
| | | request.getSession().setAttribute("optype38",GridUtils.prossRowSetDataType_Int(map38,"optype")); |
| | | frozencols = map38.get("frozencols") == null ? 0 : Integer |
| | | .parseInt(map38.get("frozencols") + ""); |
| | | } |
| | | String cosconfig[] = data.colsConfig.split("/>"); |
| | | str.append( |
| | | //Sorted='1' SortCols='bccname,amount' SortTypes='0,0' |
| | | "<Grid><Cfg id='T_" |
| | | + formid |
| | | + "'/><Cfg isNine='null' Paging='3' NoPager='1' Sorting='1' /><Cfg Deleting='0'/><Cfg SelectingText='1'/> <Cfg MinTagHeight='200' ConstHeight='1' ConstWidth='1' CacheTimeout='10' Cache='3' FilterLap='1' gType='38'/><Cfg Code='STACPYRJRZDNTB'/>") |
| | | .append("<Cfg totalCols='").append(data.totalCols) |
| | | .append("'/>"); |
| | | if (frozencols == 0) { |
| | | str.append("<Cols>").append(data.colsConfig) |
| | | .append("</Cols><Head>"); |
| | | } else if (frozencols < cosconfig.length) { |
| | | str.append("<LeftCols>"); |
| | | for (int i = 0; i < frozencols; i++) { |
| | | str.append(cosconfig[i] + "/>"); |
| | | } |
| | | str.append("</LeftCols>").append("<Cols>"); |
| | | for (int i = 0; i < cosconfig.length - frozencols; i++) { |
| | | str.append(cosconfig[i + frozencols] + "/>"); |
| | | } |
| | | str.append("</Cols><Head>"); |
| | | return page; |
| | | } else { |
| | | StringBuilder str = new StringBuilder(); |
| | | if (page.getPos() == 0) { |
| | | String sql = "select optype,frozencols from gform where formid=" + formid + ""; |
| | | List<Map<String, Object>> list38 = type38.girddata(sql); |
| | | Map<String, Object> map38 = null; |
| | | int frozencols = 0; |
| | | for (int i = 0; i < list38.size(); i++) { |
| | | map38 = list38.get(i); |
| | | request.setAttribute("optype", GridUtils.prossRowSetDataType_Int(map38, "optype")); |
| | | request.getSession().setAttribute("optype38", GridUtils.prossRowSetDataType_Int(map38, "optype")); |
| | | frozencols = map38.get("frozencols") == null ? 0 : Integer |
| | | .parseInt(map38.get("frozencols") + ""); |
| | | } |
| | | String cosconfig[] = data.colsConfig.split("/>"); |
| | | str.append( |
| | | //Sorted='1' SortCols='bccname,amount' SortTypes='0,0' |
| | | "<Grid><Cfg id='T_" |
| | | + formid |
| | | + "'/><Cfg isNine='null' Paging='3' NoPager='1' Sorting='1' /><Cfg Deleting='0'/><Cfg SelectingText='1'/> <Cfg MinTagHeight='200' ConstHeight='1' ConstWidth='1' CacheTimeout='10' Cache='3' FilterLap='1' gType='38'/><Cfg Code='STACPYRJRZDNTB'/>") |
| | | .append("<Cfg totalCols='").append(data.totalCols) |
| | | .append("'/>"); |
| | | if (frozencols == 0) { |
| | | str.append("<Cols>").append(data.colsConfig) |
| | | .append("</Cols><Head>"); |
| | | } else if (frozencols < cosconfig.length) { |
| | | str.append("<LeftCols>"); |
| | | for (int i = 0; i < frozencols; i++) { |
| | | str.append(cosconfig[i] + "/>"); |
| | | } |
| | | str.append("</LeftCols>").append("<Cols>"); |
| | | for (int i = 0; i < cosconfig.length - frozencols; i++) { |
| | | str.append(cosconfig[i + frozencols] + "/>"); |
| | | } |
| | | str.append("</Cols><Head>"); |
| | | |
| | | } else if (frozencols == cosconfig.length) { |
| | | str.append("<LeftCols>"); |
| | | for (int i = 0; i < frozencols; i++) { |
| | | str.append(cosconfig[i] + "/>"); |
| | | } |
| | | str.append("</LeftCols><Head>"); |
| | | } else if (frozencols > cosconfig.length) { |
| | | str.append("<Cols>").append(data.colsConfig) |
| | | .append("</Cols><Head>"); |
| | | } |
| | | str.append(data.header).append("</Head><Body><B Pos='" + page.getPos() + "'>"); |
| | | str.append(JOSNUtils.toJosn38(page)).append("</B>"); |
| | | for (int i = 1; i < page.getTotalPageNum(); i++) { |
| | | str.append("<B Count='"+page.getPageSize()+"'/>"); |
| | | } |
| | | str.append("</Body>"); |
| | | if (data.totalCols.length() == 0) { |
| | | str.append("<Toolbar Cells='Help,Pager' PagerType='Pager' PagerEditWidth='80'/></Grid>"); |
| | | } else { |
| | | str.append("<Foot><I id='Fix1' CanEdit='0'/></Foot><Toolbar Cells='Help,Pager' PagerType='Pager' PagerEditWidth='80'/></Grid>"); |
| | | } |
| | | }else { |
| | | str.append("<Grid><Body><B Pos='" + page.getPos() + "'>"); |
| | | str.append(JOSNUtils.toJosn38(page)).append("</B></Body></Grid>"); |
| | | } |
| | | model.addAttribute("data", str.toString().replaceAll("\"", "\\\\\"").replaceAll("\\t|\\n",""));//"号要转义 |
| | | model.addAttribute("StatisID", StatisID); |
| | | model.addAttribute("pageUrlPams", procssQueryString(grid,page)); |
| | | model.addAttribute("pageUrlPams2", grid.getQueryStringBy38()); |
| | | return "/public/template/grid38"; |
| | | } |
| | | } |
| | | private String procssQueryString(Grid grid,Page page){ |
| | | if(grid.getQueryStringBy38().contains("&pos=")) { |
| | | return grid.getQueryStringBy38().replaceAll("&pos=\\d", "&pos=" + (grid.getPos() + 1)); |
| | | //.replaceAll("&totalRowNum=\\d","&totalRowNum="+ page.getTotalRowNum()) |
| | | //.replaceAll("&totalPageNum=\\d","&totalPageNum="+page.getTotalPageNum()); |
| | | }else { |
| | | return grid.getQueryStringBy38() + "&pos=" + (grid.getPos() + 1)+"&totalRowNum="+ page.getTotalRowNum()+"&totalPageNum="+page.getTotalPageNum(); |
| | | } |
| | | } else if (frozencols == cosconfig.length) { |
| | | str.append("<LeftCols>"); |
| | | for (int i = 0; i < frozencols; i++) { |
| | | str.append(cosconfig[i] + "/>"); |
| | | } |
| | | str.append("</LeftCols><Head>"); |
| | | } else if (frozencols > cosconfig.length) { |
| | | str.append("<Cols>").append(data.colsConfig) |
| | | .append("</Cols><Head>"); |
| | | } |
| | | str.append(data.header).append("</Head><Body><B Pos='" + page.getPos() + "'>"); |
| | | str.append(JOSNUtils.toJosn38(page)).append("</B>"); |
| | | for (int i = 1; i < page.getTotalPageNum(); i++) { |
| | | str.append("<B Count='" + page.getPageSize() + "'/>"); |
| | | } |
| | | str.append("</Body>"); |
| | | if (data.totalCols.length() == 0) { |
| | | str.append("<Toolbar Cells='Help,Pager' PagerType='Pager' PagerEditWidth='80'/></Grid>"); |
| | | } else { |
| | | str.append("<Foot><I id='Fix1' CanEdit='0'/></Foot><Toolbar Cells='Help,Pager' PagerType='Pager' PagerEditWidth='80'/></Grid>"); |
| | | } |
| | | } else { |
| | | str.append("<Grid><Body><B Pos='" + page.getPos() + "'>"); |
| | | str.append(JOSNUtils.toJosn38(page)).append("</B></Body></Grid>"); |
| | | } |
| | | model.addAttribute("data", str.toString().replaceAll("\"", "\\\\\"").replaceAll("\\t|\\n", ""));//"号要转义 |
| | | model.addAttribute("StatisID", StatisID); |
| | | model.addAttribute("pageUrlPams", procssQueryString(grid, page)); |
| | | model.addAttribute("pageUrlPams2", grid.getQueryStringBy38()); |
| | | return "/public/template/grid38"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | public void createDyTitle(GridData data, HttpServletRequest request, String dbid) { |
| | | //处理动态标题 |
| | | String[] capTionArray =StringUtils.split(data.getGridcaption(),"|"); |
| | | Map<String,String> titleMap=new HashMap<>();//保存sql的原sql,用作之后替换data.header用 |
| | | String sqlStr=""; |
| | | //组装sql,一次性查询 |
| | | for(String str:capTionArray){ |
| | | if(StringUtils.isNotEmpty(str)&&str.startsWith("!")) { |
| | | String randomStr=RandomStringUtils.random(3, new char[]{'a','b','c','d','e','f'}); |
| | | if (StringUtils.isNotEmpty(str)) { |
| | | titleMap.put(randomStr, str); |
| | | sqlStr += "'" + randomStr + "='+" + str.replace("!", "").replaceAll("select", "")+ "+';'+"; |
| | | private String procssQueryString(Grid grid, Page page) { |
| | | if (grid.getQueryStringBy38().contains("&pos=")) { |
| | | return grid.getQueryStringBy38().replaceAll("&pos=\\d", "&pos=" + (grid.getPos() + 1)); |
| | | //.replaceAll("&totalRowNum=\\d","&totalRowNum="+ page.getTotalRowNum()) |
| | | //.replaceAll("&totalPageNum=\\d","&totalPageNum="+page.getTotalPageNum()); |
| | | } else { |
| | | return grid.getQueryStringBy38() + "&pos=" + (grid.getPos() + 1) + "&totalRowNum=" + page.getTotalRowNum() + "&totalPageNum=" + page.getTotalPageNum(); |
| | | } |
| | | |
| | | } |
| | | |
| | | public void createDyTitle(GridData data, HttpServletRequest request, String dbid) { |
| | | //处理动态标题 |
| | | String[] capTionArray = StringUtils.split(data.getGridcaption(), "|"); |
| | | Map<String, String> titleMap = new HashMap<>();//保存sql的原sql,用作之后替换data.header用 |
| | | String sqlStr = ""; |
| | | //组装sql,一次性查询 |
| | | for (String str : capTionArray) { |
| | | if (StringUtils.isNotEmpty(str) && str.startsWith("!")) { |
| | | String randomStr = RandomStringUtils.random(3, new char[]{'a', 'b', 'c', 'd', 'e', 'f'}); |
| | | if (StringUtils.isNotEmpty(str)) { |
| | | titleMap.put(randomStr, str); |
| | | sqlStr += "'" + randomStr + "='+" + str.replace("!", "").replaceAll("select", "") + "+';'+"; |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | if(sqlStr.endsWith("+")){ |
| | | sqlStr=sqlStr.substring(0,sqlStr.length()-5); |
| | | } |
| | | if(StringUtils.isNotEmpty(sqlStr)) { |
| | | //从where取值,替换参数 |
| | | sqlStr = SQLUtils.ReplaceSQLParameter(sqlStr, SQLUtils.processStringObject(data.getWhere(),"and","=")); |
| | | sqlStr = SQLUtils.prossSessionInfo(request, sqlStr); |
| | | //sqlStr = sqlStr.replaceAll("#", "&"); |
| | | //sqlStr>>select '!select dbo.fGetDynamicPeriodid(120301 , ''&mycompanyid&'',''&beginday&'',7)='+dbo.fGetDynamicPeriodid(120301 , 'LPCZ','2019-01-01',7)+';!select dbo.fGetDynamicPeriodid(120301, ''&mycompanyid&'',''&beginday&'',10 )='+ dbo.fGetDynamicPeriodid(120301, 'LPCZ','2019-01-01',10 ) |
| | | String result=null; |
| | | try { |
| | | SpObserver.setDBtoInstance("_"+dbid); |
| | | result= grids.getSimpleJdbcTemplate().queryForObject(" select "+sqlStr, String.class); |
| | | }finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | if (StringUtils.isNotEmpty(result)) { |
| | | Map<String,String> map=SQLUtils.processStringObject(result,";","="); |
| | | } |
| | | } |
| | | if (sqlStr.endsWith("+")) { |
| | | sqlStr = sqlStr.substring(0, sqlStr.length() - 5); |
| | | } |
| | | if (StringUtils.isNotEmpty(sqlStr)) { |
| | | //从where取值,替换参数 |
| | | sqlStr = SQLUtils.ReplaceSQLParameter(sqlStr, SQLUtils.processStringObject(data.getWhere(), "and", "=")); |
| | | sqlStr = SQLUtils.prossSessionInfo(request, sqlStr); |
| | | //sqlStr = sqlStr.replaceAll("#", "&"); |
| | | //sqlStr>>select '!select dbo.fGetDynamicPeriodid(120301 , ''&mycompanyid&'',''&beginday&'',7)='+dbo.fGetDynamicPeriodid(120301 , 'LPCZ','2019-01-01',7)+';!select dbo.fGetDynamicPeriodid(120301, ''&mycompanyid&'',''&beginday&'',10 )='+ dbo.fGetDynamicPeriodid(120301, 'LPCZ','2019-01-01',10 ) |
| | | String result = null; |
| | | try { |
| | | SpObserver.setDBtoInstance("_" + dbid); |
| | | result = grids.getSimpleJdbcTemplate().queryForObject(" select " + sqlStr, String.class); |
| | | } finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | if (StringUtils.isNotEmpty(result)) { |
| | | Map<String, String> map = SQLUtils.processStringObject(result, ";", "="); |
| | | |
| | | for (Map.Entry<String,String> entry:map.entrySet()) { |
| | | for (Map.Entry<String, String> entry : map.entrySet()) { |
| | | |
| | | data.header = data.header.replace(titleMap.get(entry.getKey()),entry.getValue());//把取得的值更新回标题定义 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | data.header = data.header.replace(titleMap.get(entry.getKey()), entry.getValue());//把取得的值更新回标题定义 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(params = "m=print38Excel") |
| | | protected void print2Excel(Integer grapht, Model model, |
| | | HttpServletRequest request, HttpServletResponse resp) |
| | | throws Exception { |
| | | // 为了组成page |
| | | String root = request.getSession().getServletContext().getRealPath("/") |
| | | + "/"; |
| | | int formid = -1; |
| | | @RequestMapping(params = "m=print38Excel") |
| | | protected void print2Excel(Integer grapht, Model model, |
| | | HttpServletRequest request, HttpServletResponse resp) |
| | | throws Exception { |
| | | // 为了组成page |
| | | String root = request.getSession().getServletContext().getRealPath("/") |
| | | + "/"; |
| | | int formid = -1; |
| | | |
| | | try { |
| | | formid = Integer.parseInt(new String(com.yc.utils.Base64 |
| | | .decode(request.getParameter("formIdHid").getBytes()))); |
| | | /* PanelServiceImpl panel=new PanelServiceImpl(); */ |
| | | } catch (NumberFormatException e1) { |
| | | log.debug(request.getParameter("formIdHid") + "转换数字格式出错", |
| | | e1.getCause()); |
| | | } |
| | | String StatisNames = null; |
| | | String sn = request.getParameter("StatisNames"); |
| | | String StatisID = request.getParameter("StatisID"); |
| | | if (sn != null) { |
| | | sn = sn.replaceAll("%2B", "+"); |
| | | sn = sn.replaceAll("%2F", "/"); |
| | | sn = sn.replaceAll("%3D", "="); |
| | | StatisNames = EncodeUtil.base64Decode(sn); |
| | | } |
| | | try { |
| | | formid = Integer.parseInt(new String(com.yc.utils.Base64 |
| | | .decode(request.getParameter("formIdHid").getBytes()))); |
| | | /* PanelServiceImpl panel=new PanelServiceImpl(); */ |
| | | } catch (NumberFormatException e1) { |
| | | log.debug(request.getParameter("formIdHid") + "转换数字格式出错", |
| | | e1.getCause()); |
| | | } |
| | | String StatisNames = null; |
| | | String sn = request.getParameter("StatisNames"); |
| | | String StatisID = request.getParameter("StatisID"); |
| | | if (sn != null) { |
| | | sn = sn.replaceAll("%2B", "+"); |
| | | sn = sn.replaceAll("%2F", "/"); |
| | | sn = sn.replaceAll("%3D", "="); |
| | | StatisNames = EncodeUtil.base64Decode(sn); |
| | | } |
| | | |
| | | // String StatisNames = new String(com.yc.utils.Base64.decode(request |
| | | // .getParameter("StatisNames").getBytes()), "utf-8"); |
| | | String datalist = ""; |
| | | List<Map<String, Object>> list = gridService.selectdata1(formid, |
| | | StatisID); |
| | | Map<String, Object> mapObject1 = null; |
| | | PanelBean panelBean=new PanelBean(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject1 = list.get(i); |
| | | try { |
| | | datalist += typeControlDao.getSelectAndCheckBoxss( |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"StatisID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"FieldID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"FieldAlias"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"StatisType"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"Sequence"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"DisplayWidth"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"displayformat"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"displayYN"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"isFilterZero"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"jionFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"jionFlagGroup"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"conFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"modfvalues"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"modfvalues2"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1,"fieldCaption"),panelBean); |
| | | }catch (Exception e){ |
| | | throw new ApplicationException(e.getMessage()); |
| | | } |
| | | } |
| | | try { |
| | | datalist = java.net.URLDecoder.decode(datalist.replace("%", "@~"), |
| | | "utf-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.debug(e.getCause().getMessage()); |
| | | } |
| | | // String StatisNames = new String(com.yc.utils.Base64.decode(request |
| | | // .getParameter("StatisNames").getBytes()), "utf-8"); |
| | | String datalist = ""; |
| | | List<Map<String, Object>> list = gridService.selectdata1(formid, |
| | | StatisID); |
| | | Map<String, Object> mapObject1 = null; |
| | | PanelBean panelBean = new PanelBean(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject1 = list.get(i); |
| | | try { |
| | | datalist += typeControlDao.getSelectAndCheckBoxss( |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "StatisID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "FieldID"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "FieldAlias"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "StatisType"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "Sequence"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "DisplayWidth"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "displayformat"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "displayYN"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "isFilterZero"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "jionFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "jionFlagGroup"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "conFlag"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "modfvalues"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "modfvalues2"), |
| | | GridUtils.prossRowSetDataType_String(mapObject1, "fieldCaption"), panelBean); |
| | | } catch (Exception e) { |
| | | throw new ApplicationException(e.getMessage()); |
| | | } |
| | | } |
| | | try { |
| | | datalist = java.net.URLDecoder.decode(datalist.replace("%", "@~"), |
| | | "utf-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.debug(e.getCause().getMessage()); |
| | | } |
| | | |
| | | try { |
| | | String where = new String(com.yc.utils.Base64.decode(request |
| | | .getParameter("where").getBytes()), "utf-8"); |
| | | GridData data = new GridData(); |
| | | gridService.create38Grid(data, formid, root, |
| | | this.setWhere(this.replaceBlank(datalist)), StatisID); |
| | | data.setDatalist(this.replaceBlank(datalist)); |
| | | data.setWhere(where); |
| | | Grid grid = new Grid(); |
| | | grid.setFormID(data.formID); |
| | | grid.setWinType(data.winType + ""); |
| | | grid.setField(data.field); |
| | | grid.setWhere(data.where); |
| | | grid.setDatalist(data.datalist); |
| | | Page page = JOSNUtils.setPageInfoData(data);// 第一步,照写 |
| | | this.formID = grid.getFormID(); |
| | | env = this.initEnv(request, this.formID, "", false); |
| | | String[] temp1 = this.setShow(grid.getDatalist());// 参数 |
| | | page.setOrderBy(temp1[1]); |
| | | HttpSession session = request.getSession(); |
| | | String having = this.selectdata(session, request, formid, |
| | | StatisNames); |
| | | if (temp1.length >= 3) { |
| | | page.setGroupby("".equalsIgnoreCase(temp1[2]) ? "" |
| | | : " group by " + temp1[2] + " " + having); |
| | | } else { |
| | | request.setAttribute("message", "没有定义输出的显示栏位!!!"); |
| | | } |
| | | /**/ |
| | | page.setWhere(grid.getWhere().replaceAll("\\\\", "")); |
| | | page.setFlag(grid.getFlag()); |
| | | String[] t = splitTable(grid.getWinType()); |
| | | page.setTableName(t[0]); |
| | | page.setParms(t[1]); |
| | | // 库存查询(1)-companyid#公司|编号;companyname#公司|名称;plantname#plantname;stcode#仓库|编号;matcode#物料|编码;unlimitstock#库存|实际库存#,0.00;ontransstock#库存|在途#,0.00;-18-unlimitstock#1||5|,0.00;ontransstock#1||6|,0.00; |
| | | page.setUserCode(request.getSession().getAttribute(SessionKey.USERCODE)+""); |
| | | page.setUserName(request.getSession().getAttribute(SessionKey.USER_NAME)+""); |
| | | page.setFormid(grid.getFormID()); |
| | | page.setPageSize(1000000); |
| | | page.setSql(this.exprTOSql(page, temp1[0])); |
| | | type38Ifc.loadAllByFunc(page, env, false, StatisID, formid);// 第二步,调用相对应业务类取得数据 |
| | | // 读取当前功能号哪些字段是需要导出的 |
| | | String s = StatisNames; |
| | | String g = ""; |
| | | String excelcount = ""; |
| | | int u=0; |
| | | int z=0; |
| | | Map<String, Object> mapObject = null; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject = list.get(i); |
| | | if ((Integer) mapObject.get("displayYN") == 1) { |
| | | u=i; |
| | | if(z!=0){ |
| | | u=u-z; |
| | | } |
| | | String fieldalias = mapObject.get("fieldalias") + ""; |
| | | String a = fieldalias.equals("") |
| | | || fieldalias.equals("null") ? mapObject |
| | | .get("FieldCaption") + "" : mapObject |
| | | .get("fieldalias") + ""; |
| | | int y = (mapObject.get("fieldid") + "").toLowerCase() |
| | | .lastIndexOf("as"); |
| | | try { |
| | | String where = new String(com.yc.utils.Base64.decode(request |
| | | .getParameter("where").getBytes()), "utf-8"); |
| | | GridData data = new GridData(); |
| | | gridService.create38Grid(data, formid, root, |
| | | this.setWhere(this.replaceBlank(datalist)), StatisID); |
| | | data.setDatalist(this.replaceBlank(datalist)); |
| | | data.setWhere(where); |
| | | Grid grid = new Grid(); |
| | | grid.setFormID(data.formID); |
| | | grid.setWinType(data.winType + ""); |
| | | grid.setField(data.field); |
| | | grid.setWhere(data.where); |
| | | grid.setDatalist(data.datalist); |
| | | Page page = JOSNUtils.setPageInfoData(data);// 第一步,照写 |
| | | this.formID = grid.getFormID(); |
| | | env = this.initEnv(request, this.formID, "", false); |
| | | String[] temp1 = this.setShow(grid.getDatalist());// 参数 |
| | | page.setOrderBy(temp1[1]); |
| | | HttpSession session = request.getSession(); |
| | | String having = this.selectdata(session, request, formid, |
| | | StatisNames); |
| | | if (temp1.length >= 3) { |
| | | page.setGroupby("".equalsIgnoreCase(temp1[2]) ? "" |
| | | : " group by " + temp1[2] + " " + having); |
| | | } else { |
| | | request.setAttribute("message", "没有定义输出的显示栏位!!!"); |
| | | } |
| | | /**/ |
| | | page.setWhere(grid.getWhere().replaceAll("\\\\", "")); |
| | | page.setFlag(grid.getFlag()); |
| | | String[] t = splitTable(grid.getWinType()); |
| | | page.setTableName(t[0]); |
| | | page.setParms(t[1]); |
| | | // 库存查询(1)-companyid#公司|编号;companyname#公司|名称;plantname#plantname;stcode#仓库|编号;matcode#物料|编码;unlimitstock#库存|实际库存#,0.00;ontransstock#库存|在途#,0.00;-18-unlimitstock#1||5|,0.00;ontransstock#1||6|,0.00; |
| | | page.setUserCode(request.getSession().getAttribute(SessionKey.USERCODE) + ""); |
| | | page.setUserName(request.getSession().getAttribute(SessionKey.USER_NAME) + ""); |
| | | page.setFormid(grid.getFormID()); |
| | | page.setPageSize(1000000); |
| | | page.setSql(this.exprTOSql(page, temp1[0])); |
| | | type38Ifc.loadAllByFunc(page, env, false, StatisID, formid);// 第二步,调用相对应业务类取得数据 |
| | | // 读取当前功能号哪些字段是需要导出的 |
| | | String titles = StatisNames; |
| | | String formatStrs = ""; |
| | | String excelcount = ""; |
| | | int u = 0; |
| | | int z = 0; |
| | | Map<String, Object> mapObject = null; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | mapObject = list.get(i); |
| | | if ((Integer) mapObject.get("displayYN") == 1) { |
| | | u = i; |
| | | if (z != 0) { |
| | | u = u - z; |
| | | } |
| | | String fieldalias = mapObject.get("fieldalias") + ""; |
| | | String filedTitle = org.apache.commons.lang3.StringUtils.isBlank(fieldalias) ? mapObject |
| | | .get("FieldCaption") + "" : mapObject |
| | | .get("fieldalias") + ""; |
| | | // 处理自定义字段名称的情况 : case when xxxx as doccode,取doccode作为名称 |
| | | final String[] byAsOfEnd = (mapObject.get("fieldid") + "").toLowerCase() |
| | | .split("\\s*\\b(?i)as\\b\\s*"); |
| | | String filedId = ""; |
| | | if (byAsOfEnd.length > 1) { |
| | | filedId = byAsOfEnd[1]; |
| | | } else { |
| | | filedId = byAsOfEnd[0]; |
| | | } |
| | | boolean isNotDisplayformat=org.apache.commons.lang3.StringUtils.isBlank(GridUtils.prossRowSetDataType_String(mapObject,"displayformat")); |
| | | if (isNotDisplayformat) { |
| | | formatStrs += filedId + "#" + filedTitle + ";"; |
| | | } else { |
| | | formatStrs += filedId + "#" + filedTitle + "#" |
| | | + mapObject.get("displayformat") + "" |
| | | + ";"; |
| | | } |
| | | if ((mapObject.get("StatisType") + "").equals("自定义")) { |
| | | |
| | | String fied =""; |
| | | if(y>0) |
| | | fied=(mapObject.get("fieldid") + "") |
| | | .substring( |
| | | y + 2, |
| | | (mapObject.get("fieldid") + "") |
| | | .length()).replace(" ", ""); |
| | | else |
| | | fied=mapObject.get("FieldID")+""; |
| | | if ((mapObject.get("sumfield") + "").equals("1")) { |
| | | excelcount += filedId |
| | | + "#1||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("2")) { |
| | | excelcount += filedId |
| | | + "#2||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("3")) { |
| | | excelcount += filedId |
| | | + "#3||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("6")) { |
| | | excelcount += filedId |
| | | + "#6||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("7")) { |
| | | excelcount += filedId |
| | | + "#7||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("5")) { |
| | | excelcount += filedId |
| | | + "#5|" |
| | | + filedId |
| | | + ":" |
| | | + (mapObject.get("funclinkname") == null |
| | | || mapObject.get("funclinkname") |
| | | .equals("") ? "" |
| | | : mapObject.get("funclinkname") |
| | | + "") |
| | | + "|" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } |
| | | |
| | | if (mapObject.get("displayformat") == null |
| | | || (mapObject.get("displayformat") + "") |
| | | .replace(" ", "").equals("")) { |
| | | g += fied + "#" + a + ";"; |
| | | } else { |
| | | g += fied + "#" + a + "#" |
| | | + mapObject.get("displayformat") + "" |
| | | + ";"; |
| | | } |
| | | if ((mapObject.get("StatisType") + "").equals("自定义")) { |
| | | } else { |
| | | if ((mapObject.get("sumfield") + "").equals("1")) { |
| | | excelcount += filedId |
| | | + "#1||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("2")) { |
| | | excelcount += filedId |
| | | + "#2||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("3")) { |
| | | excelcount += filedId |
| | | + "#3||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("6")) { |
| | | excelcount += filedId |
| | | + "#6||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("7")) { |
| | | excelcount += filedId |
| | | + "#7||" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("5")) { |
| | | excelcount += filedId |
| | | + "#5|" |
| | | + filedId |
| | | + ":" |
| | | + (mapObject.get("funclinkname") == null |
| | | || mapObject.get("funclinkname") |
| | | .equals("") ? "" |
| | | : mapObject.get("funclinkname") |
| | | + "") |
| | | + "|" |
| | | + u |
| | | + "|" |
| | | + (isNotDisplayformat? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } |
| | | |
| | | if ((mapObject.get("sumfield") + "").equals("1")) { |
| | | excelcount += fied |
| | | + "#1||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("2")) { |
| | | excelcount += fied |
| | | + "#2||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("3")) { |
| | | excelcount += fied |
| | | + "#3||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("6")) { |
| | | excelcount += fied |
| | | + "#6||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("7")) { |
| | | excelcount += fied |
| | | + "#7||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("5")) { |
| | | excelcount += fied |
| | | + "#5|" |
| | | + fied |
| | | + ":" |
| | | + (mapObject.get("funclinkname") == null |
| | | || mapObject.get("funclinkname") |
| | | .equals("") ? "" |
| | | : mapObject.get("funclinkname") |
| | | + "") |
| | | + "|" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } |
| | | } |
| | | } else { |
| | | z++; |
| | | } |
| | | } |
| | | titles = titles + ";pb#" + formatStrs + ";pb#" + "38" + ";pb#" + excelcount; |
| | | |
| | | } else { |
| | | if ((mapObject.get("sumfield") + "").equals("1")) { |
| | | excelcount += fied |
| | | + "#1||" |
| | | + u |
| | | + "|" |
| | | + ((mapObject.get("displayformat") == null || mapObject |
| | | .get("displayformat").equals("")) ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("2")) { |
| | | excelcount += fied |
| | | + "#2||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("3")) { |
| | | excelcount += fied |
| | | + "#3||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("6")) { |
| | | excelcount += fied |
| | | + "#6||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("7")) { |
| | | excelcount += fied |
| | | + "#7||" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } else if ((mapObject.get("sumfield") + "").equals("5")) { |
| | | excelcount += fied |
| | | + "#5|" |
| | | + fied |
| | | + ":" |
| | | + (mapObject.get("funclinkname") == null |
| | | || mapObject.get("funclinkname") |
| | | .equals("") ? "" |
| | | : mapObject.get("funclinkname") |
| | | + "") |
| | | + "|" |
| | | + u |
| | | + "|" |
| | | + (mapObject.get("displayformat") == null |
| | | || mapObject.get("displayformat") |
| | | .equals("") ? ",0.00" |
| | | : mapObject.get("displayformat") |
| | | + "").replace(" ", "") |
| | | + ";"; |
| | | } |
| | | if (request.getSession().getAttribute(SessionKey.USERCODE) == null) { |
| | | this.printJson(resp, "error;会话过期,请重新登录!"); |
| | | return; |
| | | } |
| | | if ("".equalsIgnoreCase(titles) || titles == null) { |
| | | this.printJson(resp, "error;未在9802设置有需要导出的内容或找不到相关的文件"); |
| | | return; |
| | | } |
| | | Map<String, Object> map = null; |
| | | String[] panel_name = null; |
| | | String[] panel_tfiled = null; |
| | | String local = ""; |
| | | page.setExcelTitle("fg=="); |
| | | Map<String, String> gmap = getTitle(page, 1);// 1表示取格线 |
| | | |
| | | } |
| | | }else{ |
| | | z++; |
| | | } |
| | | } |
| | | s = s + ";pb#" + g + ";pb#" + "38" + ";pb#" + excelcount; |
| | | String[] str = titles.split(";pb#"); |
| | | String[] temp = str[1].split(";"); |
| | | int len = temp.length; |
| | | String[] name = new String[len];// 字段说明 |
| | | String[] filed = new String[len];// 字段名 |
| | | setDyTtile(gmap, temp, name, filed); |
| | | // 然后写入excel文件 |
| | | page.setExcelTitle(str.length == 4 ? str[3] : ""); |
| | | |
| | | if (request.getSession().getAttribute(SessionKey.USERCODE) == null) { |
| | | this.printJson(resp, "error;会话过期,请重新登录!"); |
| | | return; |
| | | } |
| | | if ("".equalsIgnoreCase(s) || s == null) { |
| | | this.printJson(resp, "error;未在9802设置有需要导出的内容或找不到相关的文件"); |
| | | return; |
| | | } |
| | | Map<String, Object> map = null; |
| | | String[] panel_name = null; |
| | | String[] panel_tfiled = null; |
| | | String local = ""; |
| | | page.setExcelTitle("fg=="); |
| | | Map<String, String> gmap = getTitle(page, 1);// 1表示取格线 |
| | | File file1 = new File(request.getServletContext().getRealPath("/") |
| | | + "excel" |
| | | + File.separator |
| | | + request.getSession() |
| | | .getAttribute(SessionKey.DATA_BASE_ID) |
| | | + File.separator + formid + File.separator + "38"); |
| | | if (!file1.exists()) { |
| | | file1.mkdirs(); |
| | | } |
| | | String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + ""; |
| | | String path = request.getServletContext().getRealPath("/") |
| | | + "excel" |
| | | + File.separator |
| | | + dbid |
| | | + File.separator + formid + File.separator + "38" |
| | | + File.separator + str[0] + ".xlsx"; |
| | | |
| | | String[] str = s.split(";pb#"); |
| | | String[] temp = str[1].split(";"); |
| | | int len = temp.length; |
| | | String[] name = new String[len];// 字段说明 |
| | | String[] filed = new String[len];// 字段名 |
| | | setDyTtile(gmap, temp, name, filed); |
| | | // 然后写入excel文件 |
| | | page.setExcelTitle(str.length == 4 ? str[3] : ""); |
| | | File file = new File(path); |
| | | PoiExcelWriter poi = new PoiExcelWriter(); |
| | | String hostUrl = SettingKey.getHostUrl(request); |
| | | Map m = poi.writeExcel(dbid, str[0], page, name, filed, |
| | | panel_name, panel_tfiled, |
| | | map != null ? (List<?>) map.get("plist") : null, str[0], |
| | | local, "", hostUrl); |
| | | SXSSFWorkbook wb = (SXSSFWorkbook) m.get("wb"); |
| | | if (wb != null) { |
| | | resp.setContentType("application/msexcel"); |
| | | resp.setHeader("Content-Disposition", "attachment;Filename=" |
| | | + new String(str[0].getBytes("utf-8"), "ISO8859-1") |
| | | + ".xlsx"); |
| | | FileOutputStream fileOut = new FileOutputStream(file); |
| | | wb.write(fileOut); |
| | | fileOut.flush(); |
| | | fileOut.close(); |
| | | OutputStream os = resp.getOutputStream(); |
| | | try (FileInputStream fis = new FileInputStream(file)) { |
| | | int lens; |
| | | byte[] buffer = new byte[4096]; |
| | | while ((lens = fis.read(buffer)) > 0) { |
| | | os.write(buffer, 0, lens); |
| | | } |
| | | os.flush(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;" + e.getMessage()); |
| | | } finally { |
| | | os.close(); |
| | | } |
| | | excelRecords(formid, "38", map, file, request, page);// 导出数据审计记录执行方法 |
| | | wb.dispose(); |
| | | } |
| | | } catch (ParseException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;" + e.getMessage()); |
| | | |
| | | File file1 = new File(request.getServletContext().getRealPath("/") |
| | | + "excel" |
| | | + File.separator |
| | | + request.getSession() |
| | | .getAttribute(SessionKey.DATA_BASE_ID) |
| | | + File.separator + formid + File.separator + "38"); |
| | | if (!file1.exists()) { |
| | | file1.mkdirs(); |
| | | } |
| | | String dbid =request.getSession().getAttribute(SessionKey.DATA_BASE_ID)+""; |
| | | String path = request.getServletContext().getRealPath("/") |
| | | + "excel" |
| | | + File.separator |
| | | + dbid |
| | | + File.separator + formid + File.separator + "38" |
| | | + File.separator + str[0] + ".xlsx"; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;" + e.getMessage()); |
| | | } |
| | | |
| | | File file = new File(path); |
| | | PoiExcelWriter poi = new PoiExcelWriter(); |
| | | String hostUrl = SettingKey.getHostUrl(request); |
| | | Map m=poi.writeExcel(dbid, str[0], page, name, filed, |
| | | panel_name, panel_tfiled, |
| | | map != null ? (List<?>) map.get("plist") : null, str[0], |
| | | local,"",hostUrl); |
| | | SXSSFWorkbook wb = (SXSSFWorkbook)m.get("wb"); |
| | | if (wb != null) { |
| | | resp.setContentType("application/msexcel"); |
| | | resp.setHeader("Content-Disposition", "attachment;Filename=" |
| | | + new String(str[0].getBytes("utf-8"), "ISO8859-1") |
| | | + ".xlsx"); |
| | | FileOutputStream fileOut = new FileOutputStream(file); |
| | | wb.write(fileOut); |
| | | fileOut.flush(); |
| | | fileOut.close(); |
| | | OutputStream os = resp.getOutputStream(); |
| | | try (FileInputStream fis = new FileInputStream(file)) { |
| | | int lens; |
| | | byte[] buffer = new byte[4096]; |
| | | while ((lens = fis.read(buffer)) > 0) { |
| | | os.write(buffer, 0, lens); |
| | | } |
| | | os.flush(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;"+e.getMessage()); |
| | | }finally { |
| | | os.close(); |
| | | } |
| | | excelRecords(formid, "38", map, file, request, page);// 导出数据审计记录执行方法 |
| | | wb.dispose(); |
| | | } |
| | | } catch (ParseException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;" + e.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | this.printJson(resp, "error;" + e.getMessage()); |
| | | } |
| | | /** |
| | | * 把字符串进行分割处理 |
| | | * |
| | | * @param winType\ field 形式:frptmatstorage|companyid;stcode;matcode; |
| | | * @return String 形式:frptmatstorage |
| | | */ |
| | | private String[] splitTable(String winType) { |
| | | String[] temp = grids.getTableName(this.formID, winType).split("\\|"); |
| | | return new String[]{temp[0], temp[1]}; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 把字符串进行分割处理 |
| | | * |
| | | * @param winType\ |
| | | * field 形式:frptmatstorage|companyid;stcode;matcode; |
| | | * |
| | | * @return String 形式:frptmatstorage |
| | | * */ |
| | | private String[] splitTable(String winType) { |
| | | String[] temp = grids.getTableName(this.formID, winType).split("\\|"); |
| | | return new String[] { temp[0], temp[1] }; |
| | | } |
| | | |
| | | // 去除字符串中的换行符等 |
| | | public String replaceBlank(String str) { |
| | | if (str == null) { |
| | | return ""; |
| | | } |
| | | Pattern p = Pattern.compile("\t|\r|\n"); |
| | | Matcher m = p.matcher(str); |
| | | return m.replaceAll(" "); |
| | | } |
| | | // 去除字符串中的换行符等 |
| | | public String replaceBlank(String str) { |
| | | if (str == null) { |
| | | return ""; |
| | | } |
| | | Pattern p = Pattern.compile("\t|\r|\n"); |
| | | Matcher m = p.matcher(str); |
| | | return m.replaceAll(" "); |
| | | } |
| | | } |