|
自定义的代码。非生成器。
查询正常。但当多页时,选择最后页。然后录入条件,点击查询,会多次加载datagrid方法。求解
JSP代码- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
- <%@include file="/context/mytags.jsp" %>
- <t:base type="jquery,easyui,tools,DatePicker"></t:base>
- <div class="easyui-layout" fit="true">
- <div region="center" style="padding:0px;border:0px">
- <t:datagrid name="techownReportList" checkbox="false" pagination="true" fitColumns="false" title="账号明细汇总"
- actionUrl="" idField="id" fit="true" queryMode="group">
- <t:dgCol title="主键" field="id" hidden="true" queryMode="single" width="120"></t:dgCol>
- <t:dgCol title="API账号" field="apiname" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="客户经理" field="sale" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="账号名称" field="accountname" query="true" queryMode="single" width="120"></t:dgCol>
- <t:dgCol title="客户简称" field="customershort" query="true" queryMode="single" width="120"></t:dgCol>
- <t:dgCol title="单价" field="price" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="账号行业分类" field="industryclassification" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="账号类型" field="accounttype" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="计费方式" field="billingway" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="付费方式" field="paymentway" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="当月合计" field="summonth" queryMode="group" width="120"></t:dgCol>
- <t:dgCol title="日期" field="date" formatter="yyyy-MM-dd" hidden="true" query="true" queryMode="group"
- width="120"></t:dgCol>
- <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
- </t:datagrid>
- </div>
- </div>
- <script type="text/javascript">
- $(document).ready(function () {
- });
- $(function () {
- var date_begin = $("input[name='date_begin']").val();
- var date_end = $("input[name='date_end']").val();
- fetchData(date_begin, date_end);
- });
- function fetchData(date_begin, date_end) {
- var accountname = $("input[name='accountname']").val();
- var customershort = $("input[name='customershort']").val();
- if (date_begin == undefined && date_end == undefined) {
- date_begin = new Date();
- date_end = new Date();
- }
- if (date_end == undefined && date_begin != undefined) {
- date_end = new Date();
- }
- var s = "";
- s = "[[";
- 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'},";
- if (dateIsBig(date_begin, date_end)) {
- var dates = getDates(date_begin, date_end);
- for (var i = 0; i < dates.length; i++) {
- s = s + "{field:'" + dates[i] + "',title:'" + dates[i] + "',width:120,frozenColumn:'true'},"
- }
- }
- s = s.substring(0, s.length - 1);
- s = s + "]]";
- options = {};
- 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';
- options.queryParams = {
- accountname: accountname,
- customershort: customershort,
- date_begin: date_begin,
- date_end: date_end,
- };
- options.columns = eval(s);
- $('#techownReportList').datagrid(options);
- }
- function dateIsBig(date_begin, date_end) {
- if (date_begin.undefined && date_end.undefined) {
- return false
- } else {
- var start = new Date(date_begin.replace("-", "/").replace("-", "/"));
- var end = new Date(date_end.replace("-", "/").replace("-", "/"));
- if (start <= end) {
- return true;
- } else {
- return false;
- }
- }
- }
- function getDates(date_begin, date_end) {
- var ab = date_begin.split("-");
- var ae = date_end.split("-");
- var db = new Date();
- db.setFullYear(ab[0], ab[1] - 1, ab[2]);
- var de = new Date();
- de.setFullYear(ae[0], ae[1] - 1, ae[2]);
- var unixDb = db.getTime();
- var unixDe = de.getTime();
- var dates = [];
- console.log(date_begin);
- for (var k = unixDb; k <= unixDe;) {
- dates.push((new Date(parseInt(k))).format());
- k = k + 24 * 60 * 60 * 1000;
- }
- return dates;
- }
- Date.prototype.format = function () {
- var s = '';
- s += this.getFullYear() + '-'; // 获取年份。
- s += (this.getMonth() + 1) >= 10 ? (this.getMonth() + 1) : "0" + (this.getMonth() + 1) + "-"; // 获取月份。
- s += this.getDate() >= 10 ? this.getDate() : "0" + this.getDate(); // 获取日。
- return (s); // 返回日期。
- };
- //导出
- function ExportXls() {
- JeecgExcelExport("techownAccountDetailsController.do?exportXls", "techownReportList");
- }
- function techownReportListsearch() {
- var date_begin = $("input[name='date_begin']").val();
- var date_end = $("input[name='date_end']").val();
- fetchData(date_begin, date_end);
- }
- </script>
复制代码 controller代码- package com.jeecg.details.controller;
- import com.jeecg.details.dao.TechownAccountDetailsDao;
- import com.jeecg.details.entity.TechownAccountDetailsEntity;
- import com.jeecg.utils.ExportXlsUtil;
- import io.swagger.annotations.Api;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.common.controller.BaseController;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.servlet.ModelAndView;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.validation.Validator;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @author onlineGenerator
- * @version V1.0
- * @Title: Controller
- * @Description: 账号明细汇总
- * @date 2018-03-26 10:29:03
- */
- @Api(value = "TechownAccountDetails", description = "账号明细汇总", tags = "techownAccountDetailsController")
- @Controller
- @RequestMapping("/techownAccountDetailsController")
- public class TechownAccountDetailsController extends BaseController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(TechownAccountDetailsController.class);
- @Autowired
- private SystemService systemService;
- @Autowired
- private Validator validator;
- @Autowired
- private TechownAccountDetailsDao techownAccountDetailsDao;
- /**
- * 账号明细汇总列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "list")
- public ModelAndView list(HttpServletRequest request) {
- return new ModelAndView("com/jeecg/details/techownAccountDetailsList");
- }
- /**
- * easyui AJAX请求数据
- *
- * @param request
- * @param response
- * @param dataGrid
- * @param
- */
- @RequestMapping(params = "datagrid")
- public void datagrid(TechownAccountDetailsEntity techownAccountDetailsEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- //查询所有账号信息
- Integer pageNumber = dataGrid.getPage();
- Integer pageSize = dataGrid.getRows();
- Integer beginLimit = (pageNumber - 1) * pageSize;
- Integer endLimit = pageSize;
- System.out.println("打印几次------" + pageNumber + "===" + pageSize);
- String accountname = techownAccountDetailsEntity.getAccountname() == "" ? null : "%" + techownAccountDetailsEntity.getAccountname() + "%";
- String customersort = techownAccountDetailsEntity.getCustomershort() == "" ? null : "%" + techownAccountDetailsEntity.getCustomershort() + "%";
- List<Map<String, Object>> list = techownAccountDetailsDao.getAccountDetails(accountname, customersort, beginLimit, endLimit);
- List<String> dates = getMonthBetweenDate(techownAccountDetailsEntity.getDate_begin(), techownAccountDetailsEntity.getDate_end());
- Map<String, Map<String, Object>> extMap = new HashMap<String, Map<String, Object>>();
- for (int i = 0; i < list.size(); i++) {
- Map<String, Object> map = list.get(i);
- if (dates != null) {
- String apinameEach = String.valueOf(list.get(i).get("apiname"));
- for (int j = 0; j < dates.size(); j++) {
- Integer each = techownAccountDetailsDao.getEachApiSendByDate(apinameEach, dates.get(j));
- map.put(dates.get(j), each == null ? 0 : each);
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String begin = sdf.format(techownAccountDetailsEntity.getDate_begin() == null ? new Date() : techownAccountDetailsEntity.getDate_begin());
- String end = sdf.format(techownAccountDetailsEntity.getDate_end() == null ? new Date() : techownAccountDetailsEntity.getDate_end());
- Integer summonth = techownAccountDetailsDao.getSumApiSendByDate(apinameEach, begin, end);
- map.put("summonth", summonth == null ? 0 : summonth);
- }
- extMap.put(list.get(i).get("ID").toString(), map);
- }
- dataGrid.setTotal(techownAccountDetailsDao.getAccountDetailsCount(accountname, customersort));
- TagUtil.datagrid2(response, dataGrid, extMap);
- }
- public static List<String> getMonthBetweenDate(Date beginDate, Date endDate) {
- List<String> lDate = new ArrayList<String>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- if (beginDate != null && endDate != null) {
- if (beginDate.getTime() == endDate.getTime()) {
- return null;
- }
- lDate.add(sdf.format(beginDate));//把开始时间加入集合
- Calendar cal = Calendar.getInstance();
- //使用给定的 Date 设置此 Calendar 的时间
- cal.setTime(beginDate);
- boolean bContinue = true;
- while (bContinue) {
- //根据日历的规则,为给定的日历字段添加或减去指定的时间量
- cal.add(Calendar.DAY_OF_MONTH, 1);
- // 测试此日期是否在指定日期之后
- if (endDate.after(cal.getTime())) {
- Date m = cal.getTime();
- lDate.add(sdf.format(m));
- } else {
- break;
- }
- }
- lDate.add(sdf.format(endDate));//把结束时间加入集合
- }
- return lDate;
- }
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXls", method = RequestMethod.GET)
- public void exportXls(TechownAccountDetailsEntity techownAccountDetailsEntity, HttpServletRequest request, HttpServletResponse response) throws Exception {
- List<Map<String, Object>> list = techownAccountDetailsDao.getAccountDetailsAll(techownAccountDetailsEntity.getAccountname(), techownAccountDetailsEntity.getCustomershort());
- List<String> dates = getMonthBetweenDate(techownAccountDetailsEntity.getDate_begin(), techownAccountDetailsEntity.getDate_end());
- List<Map<String, Object>> extMap = new ArrayList<>();
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("apiname", "API账号");
- map.put("sale", "客户经理");
- map.put("accountname", "账号名称");
- map.put("customershort", "客户简称");
- map.put("price", "单价");
- map.put("industryclassification", "账号行业分类");
- map.put("accounttype", "账号类型");
- map.put("billingway", "计费方式");
- map.put("paymentway", "付费方式");
- map.put("summonth", "当月合计");
- for (int m = 0; m < dates.size(); m++) {
- map.put(dates.get(m), dates.get(m));
- }
- extMap.add(map);
- for (int i = 0; i < list.size(); i++) {
- map = list.get(i);
- if (dates != null) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Integer summonth = techownAccountDetailsDao.getSumApiSendByDate(list.get(i).get("apiname").toString(), sdf.format(techownAccountDetailsEntity.getDate_begin()), sdf.format(techownAccountDetailsEntity.getDate_end()));
- map.put("summonth", summonth == null ? 0 : summonth);
- for (int j = 0; j < dates.size(); j++) {
- Integer each = techownAccountDetailsDao.getEachApiSendByDate(list.get(i).get("apiname").toString(), dates.get(j));
- map.put(dates.get(j), each == null ? 0 : each);
- }
- }
- extMap.add(map);
- }
- String fileName = new String(("账号明细汇总" + ".xls").getBytes(), "iso-8859-1");
- ExportXlsUtil.setResponse(response, fileName, extMap);
- }
- }
复制代码 视频地址
链接:https://pan.baidu.com/s/1gIE4iLz0UVn0CEu8wwuScQ 密码:r296
|
|