关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 12831|回复: 6

[代码生成器] datagrid多次触发

[复制链接]
发表于 2018-5-13 18:34:50 | 显示全部楼层 |阅读模式
做报表的时候发现datagrid方法多次触发,且pageNumber自动改变。触发情景:刚进入页面时多次加载;点击查询时多次加载
1.png


这个是我的jsp报表页面。需要动态生成列
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
  2. <%@include file="/context/mytags.jsp" %>
  3. <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  4. <div class="easyui-layout" fit="true">
  5.     <div region="center" style="padding:0px;border:0px">

  6.         <t:datagrid name="techownReportList" checkbox="true" pagination="true" fitColumns="true" title="账号明细查询"
  7.                     actionUrl="techownAccountDetailsController.do?datagrid" idField="id" fit="true" queryMode="group">
  8.             <t:dgCol title="主键" field="id" hidden="true" queryMode="single" width="120"></t:dgCol>
  9.             <t:dgCol title="API账号" field="apiname" queryMode="group" width="120"></t:dgCol>
  10.             <t:dgCol title="客户经理" field="sale" queryMode="group" width="120"></t:dgCol>
  11.             <t:dgCol title="账号名称" field="accountname" query="true" queryMode="single" width="120"></t:dgCol>
  12.             <t:dgCol title="客户简称" field="customershort" query="true" queryMode="single" width="120"></t:dgCol>
  13.             <t:dgCol title="单价" field="price" queryMode="group" width="120"></t:dgCol>
  14.             <t:dgCol title="账号行业分类" field="industryclassification" queryMode="group" width="120"></t:dgCol>
  15.             <t:dgCol title="账号类型" field="accounttype" queryMode="group" width="120"></t:dgCol>
  16.             <t:dgCol title="计费方式" field="billingway" queryMode="group" width="120"></t:dgCol>
  17.             <t:dgCol title="付费方式" field="paymentway" queryMode="group" width="120"></t:dgCol>
  18.             <t:dgCol title="当月合计" field="summonth" queryMode="group" width="120"></t:dgCol>
  19.             <t:dgCol title="日期" field="date" formatter="yyyy-MM-dd" hidden="true" query="true" queryMode="group"
  20.                      width="120"></t:dgCol>
  21.             <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
  22.         </t:datagrid>
  23.     </div>
  24. </div>
  25. <script type="text/javascript">
  26.     var options = {};
  27.     $(function () {
  28.         var accountname = $("input[name='accountname']").val();
  29.         var customershort = $("input[name='customershort']").val();
  30.         var date_begin = $("input[name='date_begin']").val();
  31.         var date_end = $("input[name='date_end']").val();
  32.         //初始化
  33.         $("#techownReportList").datagrid({
  34.             type: 'POST',
  35.             nowrap: false,
  36.             striped: true,
  37.             fit: true,
  38.             width: 1024,
  39.             height: 500,
  40.             url: '',
  41.             pageSize: 10,
  42.             remoteSort: false,
  43.             pagination: true,
  44.             rownumbers: true,
  45.             singleSelect: true,
  46.             fitColumns: false,
  47.             queryParams: {
  48.                 accountname: accountname,
  49.                 customershort: customershort,
  50.                 date_begin: date_begin,
  51.                 date_end: date_end,
  52.             }
  53.         });
  54.         fetchData(date_begin, date_end);
  55.     });

  56.     function fetchData(date_begin, date_end) {
  57.         var accountname = $("input[name='accountname']").val();
  58.         var customershort = $("input[name='customershort']").val();
  59.         var date_begin = $("input[name='date_begin']").val();
  60.         var date_end = $("input[name='date_end']").val();
  61.         if (date_begin == undefined && date_end == undefined) {

  62.         }
  63.         if (date_end == undefined && date_begin != undefined) {

  64.         }
  65.         var s = "";
  66.         s = "[[";
  67.         s = s + "{field:'id',title:'主键',width:120,hidden:'true',frozenColumn:'true'},{field:'apiname',title:'API账号',width:120,frozenColumn:'true'},{field:'sale',title:'客户经理',width:120,frozenColumn:'true'},{field:'accountname',title:'账号名称',width:120,frozenColumn:'true'},{field:'customershort',title:'客户简称',width:120,frozenColumn:'true'},{field:'price',title:'单价',width:120,frozenColumn:'true'},{field:'industryclassification',title:'账号行业分类',width:120,frozenColumn:'true'},{field:'accounttype',title:'账号类型',width:120,frozenColumn:'true'},{field:'billingway',title:'计费方式',width:120,frozenColumn:'true'},{field:'paymentway',title:'付费方式',width:120,frozenColumn:'true'},{field:'summonth',title:'当月合计',width:120,frozenColumn:'true'},";

  68.         if (dateIsBig(date_begin, date_end)) {
  69.             var dates = getDates(date_begin, date_end);
  70.             for (var i = 0; i < dates.length; i++) {
  71.                 s = s + "{field:'" + dates[i] + "',title:'" + dates[i] + "',width:120,frozenColumn:'true'},"
  72.             }
  73.         }
  74.         s = s.substring(0, s.length - 1);
  75.         s = s + "]]";
  76.         options = {};
  77.         options.url = 'techownAccountDetailsController.do?datagrid&field=id,apiname,apiname_begin,apiname_end,sale,sale_begin,sale_end,accountname,customershort,price,price_begin,price_end,industryclassification,industryclassification_begin,industryclassification_end,accounttype,accounttype_begin,accounttype_end,billingway,billingway_begin,billingway_end,paymentway,paymentway_begin,paymentway_end,summonth,summonth_begin,summonth_end,date,date_begin,date_end';
  78.         options.queryParams = {
  79.             accountname: accountname,
  80.             customershort: customershort,
  81.             date_begin: date_begin,
  82.             date_end: date_end,
  83.         };
  84.         options.columns = eval(s);

  85.         $('#techownReportList').datagrid(options);
  86.         $('#techownReportList').datagrid('reload');

  87.     }

  88.     function dateIsBig(date_begin, date_end) {
  89.         if (date_begin.undefined && date_end.undefined) {
  90.             return false
  91.         } else {
  92.             var start = new Date(date_begin.replace("-", "/").replace("-", "/"));
  93.             var end = new Date(date_end.replace("-", "/").replace("-", "/"));
  94.             if (start <= end) {
  95.                 return true;
  96.             } else {
  97.                 return false;
  98.             }
  99.         }
  100.     }

  101.     function getDates(date_begin, date_end) {
  102.         var ab = date_begin.split("-");
  103.         var ae = date_end.split("-");
  104.         var db = new Date();
  105.         db.setUTCFullYear(ab[0], ab[1] - 1, ab[2]);
  106.         var de = new Date();
  107.         de.setUTCFullYear(ae[0], ae[1] - 1, ae[2]);
  108.         var unixDb = db.getTime();
  109.         var unixDe = de.getTime();
  110.         var dates = [];
  111.         for (var k = unixDb; k <= unixDe;) {
  112.             dates.push((new Date(parseInt(k))).format());
  113.             k = k + 24 * 60 * 60 * 1000;
  114.         }
  115.         return dates;
  116.     }

  117.     Date.prototype.format = function () {
  118.         var s = '';
  119.         s += this.getFullYear() + '-';          // 获取年份。
  120.         s += (this.getMonth() + 1) >= 10 ? (this.getMonth() + 1) : "0" + (this.getMonth() + 1) + "-";         // 获取月份。
  121.         s += this.getDate() >= 10 ? this.getDate() : "0" + this.getDate();                 // 获取日。
  122.         return (s);                          // 返回日期。
  123.     };

  124.     //导出
  125.     function ExportXls() {
  126.         JeecgExcelExport("techownAccountDetailsController.do?exportXls", "techownReportList");
  127.     }

  128.     function techownReportListsearch() {
  129.         var date_begin = $("input[name='date_begin']").val();
  130.         var date_end = $("input[name='date_end']").val();
  131.         fetchData(date_begin, date_end);
  132.         try {
  133.             if (!$("#techownReportListForm").Validform({tiptype: 3}).check()) {
  134.                 return false;
  135.             }
  136.         } catch (e) {

  137.         }
  138.         if (true) {
  139.             var queryParams = $('#techownReportList').datagrid('options').queryParams;
  140.             $('#techownReportListtb').find('*').each(function () {
  141.                 queryParams[$(this).attr('name')] = $(this).val();
  142.             });
  143.             $('#techownReportList').datagrid({
  144.                 url: 'techownAccountDetailsController.do?datagrid&field=id,apiname,apiname_begin,apiname_end,sale,sale_begin,sale_end,accountname,customershort,price,price_begin,price_end,industryclassification,industryclassification_begin,industryclassification_end,accounttype,accounttype_begin,accounttype_end,billingway,billingway_begin,billingway_end,paymentway,paymentway_begin,paymentway_end,summonth,summonth_begin,summonth_end,date,date_begin,date_end,',
  145.                 pageNumber: 1,
  146.             });
  147.         }
  148.     }
  149. </script>
复制代码
以下是我的controller类
  1. package com.jeecg.techown.controller;

  2. import com.jeecg.techown.dao.TechownAccountDetailsDao;
  3. import com.jeecg.techown.entity.TechownAccountDetailsEntity;
  4. import com.jeecg.techown.util.ExportXlsUtil;
  5. import io.swagger.annotations.Api;
  6. import org.apache.log4j.Logger;
  7. import org.jeecgframework.core.common.controller.BaseController;
  8. import org.jeecgframework.core.common.model.json.DataGrid;
  9. import org.jeecgframework.tag.core.easyui.TagUtil;
  10. import org.jeecgframework.web.system.service.SystemService;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.servlet.ModelAndView;

  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import javax.validation.Validator;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;

  21. /**
  22. * @author onlineGenerator
  23. * @version V1.0
  24. * @Title: Controller
  25. * @Description: 账号明细汇总
  26. * @date 2018-03-26 10:29:03
  27. */
  28. @Api(value = "TechownAccountDetails", description = "账号明细汇总", tags = "techownAccountDetailsController")
  29. @Controller
  30. @RequestMapping("/techownAccountDetailsController")
  31. public class TechownAccountDetailsController extends BaseController {
  32.     /**
  33.      * Logger for this class
  34.      */
  35.     private static final Logger logger = Logger.getLogger(TechownAccountDetailsController.class);

  36.     @Autowired
  37.     private SystemService systemService;
  38.     @Autowired
  39.     private Validator validator;
  40.     @Autowired
  41.     private TechownAccountDetailsDao techownAccountDetailsDao;

  42.     /**
  43.      * 账号明细汇总列表 页面跳转
  44.      *
  45.      * @return
  46.      */
  47.     @RequestMapping(params = "list")
  48.     public ModelAndView list(HttpServletRequest request) {
  49.         return new ModelAndView("com/jeecg/techown/techownAccountDetailsList");
  50.     }

  51.     /**
  52.      * easyui AJAX请求数据
  53.      *
  54.      * @param request
  55.      * @param response
  56.      * @param dataGrid
  57.      * @param
  58.      */

  59.     @RequestMapping(params = "datagrid")
  60.     public void datagrid(TechownAccountDetailsEntity techownAccountDetailsEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  61.         //查询所有账号信息
  62.         Integer pageNumber = dataGrid.getPage();
  63.         Integer pageSize = dataGrid.getRows();
  64.         Integer beginLimit = (pageNumber - 1) * pageSize;
  65.         Integer endLimit = pageSize;
  66.         System.out.println("打印几次------" + pageNumber + "===" + pageSize);
  67.         List<Map<String, Object>> list = techownAccountDetailsDao.getAccountDetails("%" + techownAccountDetailsEntity.getAccountname() + "%", "%" + techownAccountDetailsEntity.getCustomershort() + "%", beginLimit, endLimit);
  68.         List<String> dates = getMonthBetweenDate(techownAccountDetailsEntity.getDate_begin(), techownAccountDetailsEntity.getDate_end());
  69.         Map<String, Map<String, Object>> extMap = new HashMap<String, Map<String, Object>>();
  70.         for (int i = 0; i < list.size(); i++) {
  71.             Map<String, Object> map = list.get(i);
  72.             if (dates != null) {
  73.                 for (int j = 0; j < dates.size(); j++) {
  74.                     Integer each = techownAccountDetailsDao.getEachApiSendByDate(list.get(i).get("apiname").toString(), dates.get(j));
  75.                     map.put(dates.get(j), each == null ? 0 : each);
  76.                 }
  77.                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  78.                 String begin = techownAccountDetailsEntity.getDate_begin() == null ? "" : sdf.format(techownAccountDetailsEntity.getDate_begin());
  79.                 String end = techownAccountDetailsEntity.getDate_end() == null ? "" : sdf.format(techownAccountDetailsEntity.getDate_end());
  80.                 Integer summonth = techownAccountDetailsDao.getSumApiSendByDate(list.get(i).get("apiname").toString(), begin, end);
  81.                 map.put("summonth", summonth == null ? 0 : summonth);
  82.             }
  83.             extMap.put(list.get(i).get("ID").toString(), map);
  84.         }
  85.         dataGrid.setTotal(techownAccountDetailsDao.getAccountDetailsCount("%" + techownAccountDetailsEntity.getAccountname() + "%", "%" + techownAccountDetailsEntity.getCustomershort() + "%"));
  86.         TagUtil.datagrid(response, dataGrid, extMap);
  87.     }

  88.     public static List<String> getMonthBetweenDate(Date beginDate, Date endDate) {
  89.         List<String> lDate = new ArrayList<String>();
  90.         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  91.         if (beginDate != null && endDate != null) {
  92.             if (beginDate.getTime() == endDate.getTime()) {
  93.                 return null;
  94.             }
  95.             lDate.add(sdf.format(beginDate));//把开始时间加入集合
  96.             Calendar cal = Calendar.getInstance();
  97.             //使用给定的 Date 设置此 Calendar 的时间
  98.             cal.setTime(beginDate);
  99.             boolean bContinue = true;
  100.             while (bContinue) {
  101.                 //根据日历的规则,为给定的日历字段添加或减去指定的时间量
  102.                 cal.add(Calendar.DAY_OF_MONTH, 1);
  103.                 // 测试此日期是否在指定日期之后
  104.                 if (endDate.after(cal.getTime())) {
  105.                     Date m = cal.getTime();
  106.                     lDate.add(sdf.format(m));
  107.                 } else {
  108.                     break;
  109.                 }
  110.             }
  111.             lDate.add(sdf.format(endDate));//把结束时间加入集合
  112.         }
  113.         return lDate;
  114.     }


  115.     /**
  116.      * 导出excel
  117.      *
  118.      * @param request
  119.      * @param response
  120.      */
  121.     @RequestMapping(params = "exportXls", method = RequestMethod.GET)
  122.     public void exportXls(TechownAccountDetailsEntity techownAccountDetailsEntity, HttpServletRequest request, HttpServletResponse response) throws Exception {
  123.         List<Map<String, Object>> list = techownAccountDetailsDao.getAccountDetailsAll(techownAccountDetailsEntity.getAccountname(), techownAccountDetailsEntity.getCustomershort());
  124.         List<String> dates = getMonthBetweenDate(techownAccountDetailsEntity.getDate_begin(), techownAccountDetailsEntity.getDate_end());
  125.         List<Map<String, Object>> extMap = new ArrayList<>();
  126.         Map<String, Object> map = new HashMap<String, Object>();
  127.         map.put("apiname", "API账号");
  128.         map.put("sale", "客户经理");
  129.         map.put("accountname", "账号名称");
  130.         map.put("customershort", "客户简称");
  131.         map.put("price", "单价");
  132.         map.put("industryclassification", "账号行业分类");
  133.         map.put("accounttype", "账号类型");
  134.         map.put("billingway", "计费方式");
  135.         map.put("paymentway", "付费方式");
  136.         map.put("summonth", "当月合计");
  137.         for (int m = 0; m < dates.size(); m++) {
  138.             map.put(dates.get(m), dates.get(m));
  139.         }
  140.         extMap.add(map);
  141.         for (int i = 0; i < list.size(); i++) {
  142.             map = list.get(i);
  143.             if (dates != null) {
  144.                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  145.                 Integer summonth = techownAccountDetailsDao.getSumApiSendByDate(list.get(i).get("apiname").toString(), sdf.format(techownAccountDetailsEntity.getDate_begin()), sdf.format(techownAccountDetailsEntity.getDate_end()));
  146.                 map.put("summonth", summonth == null ? 0 : summonth);
  147.                 for (int j = 0; j < dates.size(); j++) {
  148.                     Integer each = techownAccountDetailsDao.getEachApiSendByDate(list.get(i).get("apiname").toString(), dates.get(j));
  149.                     map.put(dates.get(j), each == null ? 0 : each);
  150.                 }
  151.             }
  152.             extMap.add(map);
  153.         }
  154.         String fileName = new String(("账号明细汇总" + ".xls").getBytes(), "iso-8859-1");
  155.         ExportXlsUtil.setResponse(response, fileName, extMap);
  156.     }
  157. }
复制代码
发表于 2018-5-13 18:56:29 | 显示全部楼层
你的jeecg是什么版本? 默认功能是否也有这个问题,还是只是你自己开发的页面有这个问题
 楼主| 发表于 2018-5-13 18:59:37 | 显示全部楼层
admin 发表于 2018-5-13 18:56
你的jeecg是什么版本? 默认功能是否也有这个问题,还是只是你自己开发的页面有这个问题 ...

版本3.7.3  默认的没有这个问题  这个页面是我在3.7.2时候开发的  导出过来的
发表于 2018-5-13 19:37:03 | 显示全部楼层
那你得自己排查问题了
 楼主| 发表于 2018-5-13 19:57:59 | 显示全部楼层
admin 发表于 2018-5-13 19:37
那你得自己排查问题了

查到问题是在fetchdata上  但这个代码也是你们给我的=。=
 楼主| 发表于 2018-5-13 20:33:32 | 显示全部楼层
admin 发表于 2018-5-13 19:37
那你得自己排查问题了

http://www.jeecg.org/forum.php?m ... amp;page=1#pid14604
 楼主| 发表于 2018-5-13 20:44:38 | 显示全部楼层
admin 发表于 2018-5-13 19:37
那你得自己排查问题了

仔细跟3.7.2版本对比  3.7.3版本缺少了 TagUtil.datagrid2方法。我就替换成了 TagUtil.datagrid方法。出现跳页问题。 TagUtil.datagrid2虽然也加载多次,但不跳页。也就是并不是我的方法的问题。我估计是中间哪里出了问题。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表