添加终端报表和个人流水报表
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/bean/CustReportShowBean.java b/src/main/java/com/supwisdom/dlpay/restaurant/bean/CustReportShowBean.java
new file mode 100644
index 0000000..f459401
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/bean/CustReportShowBean.java
@@ -0,0 +1,238 @@
+package com.supwisdom.dlpay.restaurant.bean;
+
+
+public class CustReportShowBean {
+    private String custname;
+    private String deptname;
+    private String cardno;
+
+    //普通
+    private Double b_normalamt; //早餐
+    private Integer b_normalcnt;//早餐
+    private Double l_normalamt; //午餐
+    private Integer l_normalcnt;//午餐
+    private Double d_normalamt; //晚餐
+    private Integer d_normalcnt;//晚餐
+
+    //折扣
+    private Double b_discountamt; //早餐
+    private Integer b_discountcnt;//早餐
+    private Double l_discountamt; //午餐
+    private Integer l_discountcnt;//午餐
+    private Double d_discountamt; //晚餐
+    private Integer d_discountcnt;//晚餐
+
+    private Integer totdiscountcnt;//折扣总数
+    private Double totdiscountamt;//折扣总金额
+    private Double totfeeamt;//折扣金额
+
+    private Integer totnormalcnt;//普通总数
+    private Double totnormalamt;//普通总金额
+
+    private Integer totcnt;
+    private Double totamt;
+
+    public CustReportShowBean() {
+    }
+
+    public CustReportShowBean(String custname,String deptname,String cardno, Double b_normalamt, Integer b_normalcnt, Double l_normalamt, Integer l_normalcnt, Double d_normalamt, Integer d_normalcnt, Double b_discountamt, Integer b_discountcnt, Double l_discountamt, Integer l_discountcnt, Double d_discountamt, Integer d_discountcnt, Integer totdiscountcnt, Double totdiscountamt, Double totfeeamt, Integer totnormalcnt, Double totnormalamt, Integer totcnt, Double totamt) {
+        this.custname = custname;
+        this.deptname=deptname;
+        this.cardno=cardno;
+        this.b_normalamt = b_normalamt;
+        this.b_normalcnt = b_normalcnt;
+        this.l_normalamt = l_normalamt;
+        this.l_normalcnt = l_normalcnt;
+        this.d_normalamt = d_normalamt;
+        this.d_normalcnt = d_normalcnt;
+        this.b_discountamt = b_discountamt;
+        this.b_discountcnt = b_discountcnt;
+        this.l_discountamt = l_discountamt;
+        this.l_discountcnt = l_discountcnt;
+        this.d_discountamt = d_discountamt;
+        this.d_discountcnt = d_discountcnt;
+        this.totdiscountcnt = totdiscountcnt;
+        this.totdiscountamt = totdiscountamt;
+        this.totfeeamt = totfeeamt;
+        this.totnormalcnt = totnormalcnt;
+        this.totnormalamt = totnormalamt;
+        this.totcnt = totcnt;
+        this.totamt = totamt;
+    }
+
+    public String getCustname() {
+        return custname;
+    }
+
+    public void setCustname(String custname) {
+        this.custname = custname;
+    }
+
+    public String getDeptname() {
+        return deptname;
+    }
+
+    public void setDeptname(String deptname) {
+        this.deptname = deptname;
+    }
+
+    public String getCardno() {
+        return cardno;
+    }
+
+    public void setCardno(String cardno) {
+        this.cardno = cardno;
+    }
+
+    public Double getB_normalamt() {
+        return b_normalamt;
+    }
+
+    public void setB_normalamt(Double b_normalamt) {
+        this.b_normalamt = b_normalamt;
+    }
+
+    public Integer getB_normalcnt() {
+        return b_normalcnt;
+    }
+
+    public void setB_normalcnt(Integer b_normalcnt) {
+        this.b_normalcnt = b_normalcnt;
+    }
+
+    public Double getL_normalamt() {
+        return l_normalamt;
+    }
+
+    public void setL_normalamt(Double l_normalamt) {
+        this.l_normalamt = l_normalamt;
+    }
+
+    public Integer getL_normalcnt() {
+        return l_normalcnt;
+    }
+
+    public void setL_normalcnt(Integer l_normalcnt) {
+        this.l_normalcnt = l_normalcnt;
+    }
+
+    public Double getD_normalamt() {
+        return d_normalamt;
+    }
+
+    public void setD_normalamt(Double d_normalamt) {
+        this.d_normalamt = d_normalamt;
+    }
+
+    public Integer getD_normalcnt() {
+        return d_normalcnt;
+    }
+
+    public void setD_normalcnt(Integer d_normalcnt) {
+        this.d_normalcnt = d_normalcnt;
+    }
+
+    public Double getB_discountamt() {
+        return b_discountamt;
+    }
+
+    public void setB_discountamt(Double b_discountamt) {
+        this.b_discountamt = b_discountamt;
+    }
+
+    public Integer getB_discountcnt() {
+        return b_discountcnt;
+    }
+
+    public void setB_discountcnt(Integer b_discountcnt) {
+        this.b_discountcnt = b_discountcnt;
+    }
+
+    public Double getL_discountamt() {
+        return l_discountamt;
+    }
+
+    public void setL_discountamt(Double l_discountamt) {
+        this.l_discountamt = l_discountamt;
+    }
+
+    public Integer getL_discountcnt() {
+        return l_discountcnt;
+    }
+
+    public void setL_discountcnt(Integer l_discountcnt) {
+        this.l_discountcnt = l_discountcnt;
+    }
+
+    public Double getD_discountamt() {
+        return d_discountamt;
+    }
+
+    public void setD_discountamt(Double d_discountamt) {
+        this.d_discountamt = d_discountamt;
+    }
+
+    public Integer getD_discountcnt() {
+        return d_discountcnt;
+    }
+
+    public void setD_discountcnt(Integer d_discountcnt) {
+        this.d_discountcnt = d_discountcnt;
+    }
+
+    public Integer getTotdiscountcnt() {
+        return totdiscountcnt;
+    }
+
+    public void setTotdiscountcnt(Integer totdiscountcnt) {
+        this.totdiscountcnt = totdiscountcnt;
+    }
+
+    public Double getTotdiscountamt() {
+        return totdiscountamt;
+    }
+
+    public void setTotdiscountamt(Double totdiscountamt) {
+        this.totdiscountamt = totdiscountamt;
+    }
+
+    public Double getTotfeeamt() {
+        return totfeeamt;
+    }
+
+    public void setTotfeeamt(Double totfeeamt) {
+        this.totfeeamt = totfeeamt;
+    }
+
+    public Integer getTotnormalcnt() {
+        return totnormalcnt;
+    }
+
+    public void setTotnormalcnt(Integer totnormalcnt) {
+        this.totnormalcnt = totnormalcnt;
+    }
+
+    public Double getTotnormalamt() {
+        return totnormalamt;
+    }
+
+    public void setTotnormalamt(Double totnormalamt) {
+        this.totnormalamt = totnormalamt;
+    }
+
+    public Integer getTotcnt() {
+        return totcnt;
+    }
+
+    public void setTotcnt(Integer totcnt) {
+        this.totcnt = totcnt;
+    }
+
+    public Double getTotamt() {
+        return totamt;
+    }
+
+    public void setTotamt(Double totamt) {
+        this.totamt = totamt;
+    }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/bean/TermReportShowBean.java b/src/main/java/com/supwisdom/dlpay/restaurant/bean/TermReportShowBean.java
index d94958f..5f90bec 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/bean/TermReportShowBean.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/bean/TermReportShowBean.java
@@ -2,7 +2,7 @@
 
 
 public class TermReportShowBean {
-    private Integer termid;
+    private String termid;
 
     //普通
     private Double b_normalamt; //早餐
@@ -22,16 +22,45 @@
 
     private Integer totdiscountcnt;//折扣总数
     private Double totdiscountamt;//折扣总金额
-    private Double totfeetamt;//折扣金额
+    private Double totfeeamt;//折扣金额
 
     private Integer totnormalcnt;//普通总数
     private Double totnormalamt;//普通总金额
 
-    public Integer getTermid() {
+    private Integer totcnt;
+    private Double totamt;
+
+    public TermReportShowBean() {
+    }
+
+    public TermReportShowBean(String termid, Double b_normalamt, Integer b_normalcnt, Double l_normalamt, Integer l_normalcnt, Double d_normalamt, Integer d_normalcnt, Double b_discountamt, Integer b_discountcnt, Double l_discountamt, Integer l_discountcnt, Double d_discountamt, Integer d_discountcnt, Integer totdiscountcnt, Double totdiscountamt, Double totfeeamt, Integer totnormalcnt, Double totnormalamt, Integer totcnt, Double totamt) {
+        this.termid = termid;
+        this.b_normalamt = b_normalamt;
+        this.b_normalcnt = b_normalcnt;
+        this.l_normalamt = l_normalamt;
+        this.l_normalcnt = l_normalcnt;
+        this.d_normalamt = d_normalamt;
+        this.d_normalcnt = d_normalcnt;
+        this.b_discountamt = b_discountamt;
+        this.b_discountcnt = b_discountcnt;
+        this.l_discountamt = l_discountamt;
+        this.l_discountcnt = l_discountcnt;
+        this.d_discountamt = d_discountamt;
+        this.d_discountcnt = d_discountcnt;
+        this.totdiscountcnt = totdiscountcnt;
+        this.totdiscountamt = totdiscountamt;
+        this.totfeeamt = totfeeamt;
+        this.totnormalcnt = totnormalcnt;
+        this.totnormalamt = totnormalamt;
+        this.totcnt = totcnt;
+        this.totamt = totamt;
+    }
+
+    public String getTermid() {
         return termid;
     }
 
-    public void setTermid(Integer termid) {
+    public void setTermid(String termid) {
         this.termid = termid;
     }
 
@@ -147,12 +176,12 @@
         this.totdiscountamt = totdiscountamt;
     }
 
-    public Double getTotfeetamt() {
-        return totfeetamt;
+    public Double getTotfeeamt() {
+        return totfeeamt;
     }
 
-    public void setTotfeetamt(Double totfeetamt) {
-        this.totfeetamt = totfeetamt;
+    public void setTotfeeamt(Double totfeeamt) {
+        this.totfeeamt = totfeeamt;
     }
 
     public Integer getTotnormalcnt() {
@@ -170,4 +199,20 @@
     public void setTotnormalamt(Double totnormalamt) {
         this.totnormalamt = totnormalamt;
     }
+
+    public Integer getTotcnt() {
+        return totcnt;
+    }
+
+    public void setTotcnt(Integer totcnt) {
+        this.totcnt = totcnt;
+    }
+
+    public Double getTotamt() {
+        return totamt;
+    }
+
+    public void setTotamt(Double totamt) {
+        this.totamt = totamt;
+    }
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/controller/CustReportController.java b/src/main/java/com/supwisdom/dlpay/restaurant/controller/CustReportController.java
new file mode 100644
index 0000000..d812301
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/controller/CustReportController.java
@@ -0,0 +1,136 @@
+package com.supwisdom.dlpay.restaurant.controller;
+
+
+import com.supwisdom.dlpay.framework.domain.TOperator;
+import com.supwisdom.dlpay.framework.domain.TShopSettlement;
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.DateUtil;
+import com.supwisdom.dlpay.restaurant.bean.CustReportShowBean;
+import com.supwisdom.dlpay.restaurant.bean.TermReportSearchBean;
+import com.supwisdom.dlpay.restaurant.service.CustReportService;
+import com.supwisdom.dlpay.restaurant.service.DeviceDiscountRuleService;
+import com.supwisdom.dlpay.restaurant.service.ShopSettlementService;
+import com.supwisdom.dlpay.restaurant.service.StatementReportService;
+import com.supwisdom.dlpay.system.domain.TOperatorQueryLimit;
+import com.supwisdom.dlpay.system.service.OperatorService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.annotation.AuthenticationPrincipal;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Controller
+@RequestMapping("/custreport")
+public class CustReportController {
+
+    @Autowired
+    private SystemUtilService systemUtilService;
+    @Autowired
+    private CustReportService custReportService;
+    @Autowired
+    private StatementReportService statementReportService;
+    @Autowired
+    private DeviceDiscountRuleService deviceDiscountRuleService;
+    @Autowired
+    private OperatorService operatorService;
+    @Autowired
+    private ShopSettlementService shopSettlementService;
+
+    @RequestMapping("/index")
+    public String indexView(
+            @ModelAttribute("searchBean") TermReportSearchBean searchBean,
+            @AuthenticationPrincipal UserDetails operUser,
+            ModelMap model) {
+        String settledate = statementReportService.getMaxStatementDate();
+        String maxdate = DateUtil.reformatDatetime(settledate, "yyyyMMdd", "yyyy-MM-dd");
+        searchBean.setStartdate(settledate);
+        searchBean.setEnddate(settledate);
+        TOperator oper = (TOperator) operUser;
+        TOperatorQueryLimit limit=operatorService.getOperatorQueryLimit(oper.getOpercode());
+        if(null!=limit){
+            model.addAttribute("devgroupid",limit.getDevgroupid());
+            searchBean.setDevgroupid(limit.getDevgroupid());
+        }
+        List<TShopSettlement> lst = shopSettlementService.getAllShopSettlement();
+
+        model.addAttribute("shoplistForSelect", lst);
+        model.addAttribute("rulelist", deviceDiscountRuleService.getNormalDiscountRules());
+        model.addAttribute("showlist", custReportService.getCustReportSearchData(searchBean));
+        model.addAttribute("maxdate", maxdate);
+        model.addAttribute("opercode", oper == null ? "unknow" : oper.getOpercode());
+
+        return "restaurant/custreport/index";
+    }
+
+    @RequestMapping("/custreportlist")
+    public String getDataList(
+            @ModelAttribute("searchBean") TermReportSearchBean searchBean,
+            @AuthenticationPrincipal UserDetails operUser,
+            ModelMap map) {
+        try {
+
+            TOperator oper = (TOperator) operUser;
+            map.addAttribute("opercode", oper == null ? "unknow" : oper.getOpercode());
+            TOperatorQueryLimit limit=operatorService.getOperatorQueryLimit(oper.getOpercode());
+            if(null!=limit){
+                searchBean.setDevgroupid(limit.getDevgroupid());
+            }
+            List<CustReportShowBean> bean = custReportService.getCustReportSearchData(searchBean);
+
+            map.addAttribute("showlist",bean);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "restaurant/custreport/index::custreportTable";
+    }
+
+    @GetMapping("/excelexport")
+    public void excelExport(@ModelAttribute("searchBean") TermReportSearchBean searchBean,
+                            @AuthenticationPrincipal UserDetails operUser,
+                            HttpServletRequest request, HttpServletResponse response, ModelMap map){
+        try {
+            TOperator oper = (TOperator) operUser;
+            TOperatorQueryLimit limit=operatorService.getOperatorQueryLimit(oper.getOpercode());
+            if(null!=limit){
+                searchBean.setDevgroupid(limit.getDevgroupid());
+            }
+            List<CustReportShowBean> datalist = custReportService.getCustReportSearchData(searchBean);
+            String filename="终端消费报表";
+            custReportService.doCreateCustReportExcel(response, datalist, searchBean, filename, oper);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    @GetMapping("/print/printcustreport")
+    public String print(@ModelAttribute("searchBean") TermReportSearchBean searchBean,
+                        @RequestParam(value = "opercode",required = false) String opercode, ModelMap map) {
+        try {
+            TOperatorQueryLimit limit=operatorService.getOperatorQueryLimit(opercode);
+            if(null!=limit){
+                searchBean.setDevgroupid(limit.getDevgroupid());
+            }
+            map.addAttribute("showlist", custReportService.getCustReportSearchData(searchBean));
+
+            TOperator oper = statementReportService.getOperatorByOpercode(opercode);
+            map.addAttribute("opername", oper == null ? "unknow" : oper.getOpername());
+            map.addAttribute("period", custReportService.getCustReportSearchPeriod(searchBean));
+            map.addAttribute("printdatetime",DateUtil.reformatDatetime(systemUtilService.getSysdatetime().getHostdatetime(),DateUtil.DATETIME_FMT,"yyyy-MM-dd HH:mm:ss"));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "restaurant/custreport/print/report";
+    }
+
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/controller/TermReportController.java b/src/main/java/com/supwisdom/dlpay/restaurant/controller/TermReportController.java
index 0513687..19a2c6e 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/controller/TermReportController.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/controller/TermReportController.java
@@ -2,11 +2,14 @@
 
 
 import com.supwisdom.dlpay.framework.domain.TOperator;
+import com.supwisdom.dlpay.framework.domain.TShopSettlement;
 import com.supwisdom.dlpay.framework.service.SystemUtilService;
 import com.supwisdom.dlpay.framework.util.DateUtil;
 import com.supwisdom.dlpay.restaurant.bean.DailyReportSearchBean;
 import com.supwisdom.dlpay.restaurant.bean.TermReportSearchBean;
 import com.supwisdom.dlpay.restaurant.bean.TermReportShowBean;
+import com.supwisdom.dlpay.restaurant.service.DeviceDiscountRuleService;
+import com.supwisdom.dlpay.restaurant.service.ShopSettlementService;
 import com.supwisdom.dlpay.restaurant.service.TermReportService;
 import com.supwisdom.dlpay.restaurant.service.StatementReportService;
 import com.supwisdom.dlpay.system.domain.TOperatorQueryLimit;
@@ -36,7 +39,11 @@
     @Autowired
     private StatementReportService statementReportService;
     @Autowired
+    private DeviceDiscountRuleService deviceDiscountRuleService;
+    @Autowired
     private OperatorService operatorService;
+    @Autowired
+    private ShopSettlementService shopSettlementService;
 
     @RequestMapping("/index")
     public String indexView(
@@ -53,6 +60,10 @@
             model.addAttribute("devgroupid",limit.getDevgroupid());
             searchBean.setDevgroupid(limit.getDevgroupid());
         }
+        List<TShopSettlement> lst = shopSettlementService.getAllShopSettlement();
+
+        model.addAttribute("shoplistForSelect", lst);
+        model.addAttribute("rulelist", deviceDiscountRuleService.getNormalDiscountRules());
         model.addAttribute("showlist", termReportService.getTermReportSearchData(searchBean));
         model.addAttribute("maxdate", maxdate);
         model.addAttribute("opercode", oper == null ? "unknow" : oper.getOpercode());
@@ -94,7 +105,7 @@
                 searchBean.setDevgroupid(limit.getDevgroupid());
             }
             List<TermReportShowBean> datalist = termReportService.getTermReportSearchData(searchBean);
-            String filename="客户类别消费报表";
+            String filename="终端消费报表";
             termReportService.doCreateTermReportExcel(response, datalist, searchBean, filename, oper);
         } catch (Exception e) {
             e.printStackTrace();
@@ -119,7 +130,7 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return "restaurant/termreport/print/printtermreport";
+        return "restaurant/termreport/print/report";
     }
 
 
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/controller/TerminalReportController.java b/src/main/java/com/supwisdom/dlpay/restaurant/controller/TerminalReportController.java
deleted file mode 100644
index 3e86825..0000000
--- a/src/main/java/com/supwisdom/dlpay/restaurant/controller/TerminalReportController.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.supwisdom.dlpay.restaurant.controller;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-@Controller
-@RequestMapping("/terminalreport")
-public class TerminalReportController {
-
-  @RequestMapping("/index")
-  public String indexView() {
-    return "restaurant/terminalreport/index";
-  }
-
-}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/CustReportService.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/CustReportService.java
new file mode 100644
index 0000000..7d0a1fb
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/CustReportService.java
@@ -0,0 +1,25 @@
+package com.supwisdom.dlpay.restaurant.service;
+
+import com.supwisdom.dlpay.framework.domain.TOperator;
+import com.supwisdom.dlpay.restaurant.bean.CustReportShowBean;
+import com.supwisdom.dlpay.restaurant.bean.TermReportSearchBean;
+import com.supwisdom.dlpay.restaurant.bean.TermReportShowBean;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+public interface CustReportService {
+
+
+    @Transactional(rollbackFor = Exception.class,readOnly = true)
+    List<CustReportShowBean> getCustReportSearchData(TermReportSearchBean searchBean);
+
+    @Transactional(rollbackFor = Exception.class,readOnly = true)
+    String getCustReportSearchPeriod(TermReportSearchBean searchBean);
+
+    @Transactional(rollbackFor = Exception.class,readOnly = true)
+    void doCreateCustReportExcel(HttpServletResponse response, List<CustReportShowBean> datalist, TermReportSearchBean searchBean, String filename, TOperator oper);
+
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustReportServiceImpl.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustReportServiceImpl.java
new file mode 100644
index 0000000..3810cb5
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CustReportServiceImpl.java
@@ -0,0 +1,370 @@
+package com.supwisdom.dlpay.restaurant.service.impl;
+
+import com.supwisdom.dlpay.framework.domain.TOperator;
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.DateUtil;
+import com.supwisdom.dlpay.framework.util.MoneyUtil;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.restaurant.bean.CustReportShowBean;
+import com.supwisdom.dlpay.restaurant.bean.TermReportSearchBean;
+import com.supwisdom.dlpay.restaurant.bean.CustReportShowBean;
+import com.supwisdom.dlpay.restaurant.service.CustReportService;
+import com.supwisdom.dlpay.restaurant.service.TermReportService;
+import com.supwisdom.dlpay.restaurant.util.ExcelPoiUtil;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.hibernate.query.internal.NativeQueryImpl;
+import org.hibernate.transform.Transformers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class CustReportServiceImpl implements CustReportService {
+
+
+    @Autowired
+    private SystemUtilService systemUtilService;
+
+    @PersistenceContext
+    private EntityManager entityManager;
+
+    private static final Logger logger = LoggerFactory.getLogger(CustReportServiceImpl.class);
+
+    @Override
+    public List<CustReportShowBean> getCustReportSearchData(TermReportSearchBean searchBean) {
+        if (null != searchBean) {
+            String startdate = DateUtil.unParseToDateFormat(searchBean.getStartdate());
+            String enddate = DateUtil.unParseToDateFormat(searchBean.getEnddate());
+
+            StringBuffer sb = new StringBuffer("select c.custname,d.deptname,a.cardno ," +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='breakfast' then t.amount else 0 end) as b_normalamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='breakfast' then 1 else 0 end) as int4) as b_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota')  and t.mealtype='breakfast' then 1 else 0 end) as int4) as b_discountcnt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='breakfast' then t.amount else 0 end) as b_discountamt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='lunch' then t.amount else 0 end) as l_normalamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='lunch' then 1 else 0 end) as int4) as l_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='lunch' then 1 else 0 end) as int4) as l_discountcnt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='lunch' then t.amount else 0 end) as l_discountamt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='dinner' then t.amount else 0 end) as d_normalamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='dinner' then 1 else 0 end) as int4) as d_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then 1 else 0 end) as int4) as d_discountcnt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then t.amount else 0 end) as d_discountamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then 1 else 0 end) as int4) as totdiscountcnt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then t.amount else 0 end) as totdiscountamt," +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then t.managefee else 0 end) as totfeeamt," +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal'   then t.amount else 0 end) as totnormalamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal'  then 1 else 0 end) as int4) as totnormalcnt," +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 else t.amount end) as totamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 else 1 end)  as int4) as totcnt" +
+                    " from tb_transdtl t  " +
+                    " left join tb_device dev on t.termid=dev.id " +
+                    " left join tb_shopsettlement s on s.shopid=t.shopid" +
+                    " left join tb_discount_rule r on r.ruleid=t.ruleid" +
+                    " left join tb_customer c on t.custid=c.custid" +
+                    " left join tb_dept d on d.deptcode=c.deptcode" +
+                    " left join tb_card a on c.custid=a.custid" +
+                    " where t.status='success' " +
+                    " and t.accdate>=:startdate and t.accdate<=:enddate ") ;
+            if (!StringUtil.isEmpty(searchBean.getShopid())) {
+                sb.append( " and s.shopid = :shopid ");
+            }
+            if (!StringUtil.isEmpty(searchBean.getShopname())) {
+                sb.append( " and s.shopname like :shopname ");
+            }
+            if (null!=searchBean.getDevgroupid()) {
+                sb.append( " and dev.devgroupid = :groupid ");
+            }
+            if (null!=searchBean.getRuleid()) {
+                sb.append( " and r.ruleid = :ruleid ");
+            }
+            sb.append(" group by a.cardno,c.custname,d.deptname");
+            Query query = entityManager.createNativeQuery(sb.toString());
+            query.setParameter("startdate", startdate);
+            query.setParameter("enddate", enddate);
+            if (null!=searchBean.getDevgroupid()) {
+                query.setParameter("groupid", searchBean.getDevgroupid());
+            }
+            if (!StringUtil.isEmpty(searchBean.getShopid())) {
+                query.setParameter("shopid", searchBean.getShopid().trim()  );
+            }
+            if (!StringUtil.isEmpty(searchBean.getShopname())) {
+                query.setParameter("shopname","%" + searchBean.getShopname().trim() + "%");
+            }
+            if (null!=searchBean.getRuleid()) {
+                query.setParameter("ruleid", searchBean.getRuleid());
+            }
+            query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(CustReportShowBean.class));
+            List<CustReportShowBean> list = query.getResultList();
+            /*if (null != list){
+                CustReportShowBean tot=new CustReportShowBean("合 计","","",0d,0,0d,0,0d,0,0d,0,0d,0,
+                        0d,0,0,0d,0d,0,0d,0,0d);
+                for(CustReportShowBean b:list){
+                    tot.setB_discountamt(tot.getB_discountamt()+b.getB_discountamt());
+                    tot.setB_discountcnt(tot.getB_discountcnt()+b.getB_discountcnt());
+                    tot.setL_discountamt(tot.getL_discountamt()+b.getL_discountamt());
+                    tot.setL_discountcnt(tot.getL_discountcnt()+b.getL_discountcnt());
+                    tot.setD_discountamt(tot.getD_discountamt()+b.getD_discountamt());
+                    tot.setD_discountcnt(tot.getD_discountcnt()+b.getD_discountcnt());
+                    tot.setB_normalamt(tot.getB_normalamt()+b.getB_normalamt());
+                    tot.setB_normalcnt(tot.getB_normalcnt()+b.getB_normalcnt());
+                    tot.setL_normalamt(tot.getL_normalamt()+b.getL_normalamt());
+                    tot.setL_normalcnt(tot.getL_normalcnt()+b.getL_normalcnt());
+                    tot.setD_normalamt(tot.getD_normalamt()+b.getD_normalamt());
+                    tot.setD_normalcnt(tot.getD_normalcnt()+b.getD_normalcnt());
+                    tot.setTotdiscountamt(tot.getTotdiscountamt()+b.getTotdiscountamt());
+                    tot.setTotdiscountcnt(tot.getTotnormalcnt()+b.getTotdiscountcnt());
+                    tot.setTotfeeamt(tot.getTotfeeamt()+b.getTotfeeamt());
+                    tot.setTotnormalamt(tot.getTotnormalamt()+b.getTotnormalamt());
+                    tot.setTotnormalcnt(tot.getTotnormalcnt()+b.getTotnormalcnt());
+                    tot.setTotcnt(tot.getTotcnt()+b.getTotcnt());
+                    tot.setTotamt(tot.getTotamt()+b.getTotamt());
+                }
+                list.add(tot);
+                return list;
+            }*/
+        }
+        return new ArrayList<>(0);
+
+    }
+    @Override
+    public String getCustReportSearchPeriod(TermReportSearchBean searchBean) {
+        String startdate = DateUtil.unParseToDateFormat(searchBean.getStartdate());
+        String enddate = DateUtil.unParseToDateFormat(searchBean.getEnddate());
+        if (startdate.equals(enddate)) {
+            return DateUtil.reformatDatetime(startdate, "yyyyMMdd", "yyyy年MM月dd日");
+        } else {
+            return DateUtil.reformatDatetime(startdate, "yyyyMMdd", "yyyy年MM月dd日") + " ~ " + DateUtil.reformatDatetime(enddate, "yyyyMMdd", "yyyy年MM月dd日");
+        }
+    }
+
+
+    @Override
+    public void doCreateCustReportExcel(HttpServletResponse response, List<CustReportShowBean> datalist, TermReportSearchBean searchBean, String filename, TOperator oper) {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet("终端消费报表");
+
+        int columns = 22; //
+        sheet.setColumnWidth(0, ExcelPoiUtil.columnWidth(25)); //日期
+        for (int i = 3; i < columns; i++) {
+            sheet.setColumnWidth(i, ExcelPoiUtil.columnWidth(12));
+        }
+
+        //标题样式
+        HSSFCellStyle titleStyle = ExcelPoiUtil.creatStyle(workbook, "宋体", true, 20, HSSFCellStyle.ALIGN_CENTER, false); //设置单元格样式
+        //表头样式
+        HSSFCellStyle headStyle = ExcelPoiUtil.creatStyle(workbook, "宋体", true, 15, HSSFCellStyle.ALIGN_CENTER, true); //设置单元格样式
+        //正文样式 有边框-textStyle1 无边框-textStyle2
+        HSSFCellStyle textStyle1 = ExcelPoiUtil.creatStyle(workbook, "宋体", false, 10, HSSFCellStyle.ALIGN_CENTER, true); //设置单元格样式
+        HSSFCellStyle textStyle2 = ExcelPoiUtil.creatStyle(workbook, "宋体", false, 10, HSSFCellStyle.ALIGN_CENTER, false); //设置单元格样式
+
+
+        //TODO:创建标题
+        HSSFRow row0 = ExcelPoiUtil.createRow(sheet, 0, 800); //表格标题
+        ExcelPoiUtil.createCell(row0, 0, titleStyle, filename);
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, columns - 1)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
+
+        //TODO:创建表格页眉
+        HSSFRow row1 = ExcelPoiUtil.createRow(sheet, 1, 400);
+        ExcelPoiUtil.createCell(row1, 0, textStyle2, "区间");
+        ExcelPoiUtil.createCell(row1, 1, textStyle2, getCustReportSearchPeriod(searchBean));
+        ExcelPoiUtil.createCell(row1, 2, textStyle2, null);
+        ExcelPoiUtil.createCell(row1, 3, textStyle2, null);
+        ExcelPoiUtil.createCell(row1, 4, textStyle2, null);
+
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 4));
+        ExcelPoiUtil.createCell(row1, columns - 1, ExcelPoiUtil.creatStyle(workbook, "宋体", false, 10, HSSFCellStyle.ALIGN_RIGHT, false), "单位:元");
+
+        //TODO:创建表头(poi做多行合并,一定需要先绘制单元格,然后写入数据,最后合并)
+        HSSFRow row2 = ExcelPoiUtil.createRow(sheet, 2, 600);
+        ExcelPoiUtil.createCell(row2, 0, headStyle, "单位");
+        ExcelPoiUtil.createCell(row2, 1, headStyle, "姓名");
+        ExcelPoiUtil.createCell(row2, 2, headStyle, "卡号");
+        ExcelPoiUtil.createCell(row2, 3, headStyle, "非折扣交易");
+
+        ExcelPoiUtil.createCell(row2, 4, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 5, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 6, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 7, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 8, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 9, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 10, headStyle, null);
+
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 10)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
+
+        ExcelPoiUtil.createCell(row2, 11, headStyle, "折扣交易");
+        ExcelPoiUtil.createCell(row2, 12, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 13, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 14, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 15, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 16, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 17, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 18, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 19, headStyle, null);
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 11, 19)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
+
+
+        ExcelPoiUtil.createCell(row2, 20, headStyle, "交易笔\n数合计");
+        ExcelPoiUtil.createCell(row2, 21, headStyle, "交易金\n额合计");
+
+        HSSFRow row3 = ExcelPoiUtil.createRow(sheet, 3, 800);
+        HSSFRow row4 = ExcelPoiUtil.createRow(sheet, 4, 800);
+        ExcelPoiUtil.createCell(row4, 0, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 1, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 2, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 3, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 4, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 5, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 6, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 7, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 8, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 11, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 12, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 13, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 14, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 15, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 16, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 19, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 20, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 21, headStyle, null);
+
+        ExcelPoiUtil.createCell(row3, 0, headStyle, null);
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 0, 0)); //合并列
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 1, 1)); //合并列
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 2, 2)); //合并列
+
+        ExcelPoiUtil.createCell(row3, 3, headStyle, "早餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 4, headStyle, "早餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 5, headStyle, "午餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 6, headStyle, "午餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 7, headStyle, "晚餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 8, headStyle, "晚餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 9, headStyle, "非折扣\n交易小计");
+        ExcelPoiUtil.createCell(row3, 10, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 9, headStyle, "交易笔数小计");
+        ExcelPoiUtil.createCell(row4, 10, headStyle, "交易金额小计");
+
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 3, 3)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 4, 4)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 5, 5)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 6, 6)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 7, 7)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 8, 8)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 10));
+
+        ExcelPoiUtil.createCell(row3, 11, headStyle, "早餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 12, headStyle, "早餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 13, headStyle, "午餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 14, headStyle, "午餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 15, headStyle, "晚餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 16, headStyle, "晚餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 17, headStyle, "折扣\n交易小计");
+        ExcelPoiUtil.createCell(row3, 18, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 17, headStyle, "交易笔数小计");
+        ExcelPoiUtil.createCell(row4, 18, headStyle, "交易金额小计");
+
+        ExcelPoiUtil.createCell(row3, 19, headStyle, "餐补金额");
+        ExcelPoiUtil.createCell(row3, 20, headStyle, null);
+        ExcelPoiUtil.createCell(row3, 21, headStyle, null);
+
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 11, 11));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 12, 12));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 13, 13));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 14, 14));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 15, 15));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 16, 16));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 19, 19));
+        sheet.addMergedRegion(new CellRangeAddress(3, 3, 17, 18));
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 20, 20));
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 21, 21));
+
+        //TODO: 数据
+        int rowNum = 5;
+        if (StringUtil.isEmpty(datalist)) {
+            //无数据
+            HSSFRow row5 = ExcelPoiUtil.createRow(sheet, rowNum, 500);
+            ExcelPoiUtil.createCell(row4, 0, textStyle1, "无数据");
+            for (int n = 1; n < columns; n++) ExcelPoiUtil.createCell(row4, n, textStyle1, null);
+            sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, columns - 1)); //合并列
+        } else {
+            //有数据
+            for (int i = 0; i < datalist.size(); i++) {
+                CustReportShowBean detail = datalist.get(i);
+                HSSFRow row = ExcelPoiUtil.createRow(sheet, rowNum++, 500);
+                ExcelPoiUtil.createCell(row, 0, textStyle1, detail.getDeptname());
+                ExcelPoiUtil.createCell(row, 1, textStyle1, detail.getCustname());
+                ExcelPoiUtil.createCell(row, 2, textStyle1, detail.getCardno());
+                ExcelPoiUtil.createCell(row, 3, textStyle1, detail.getB_normalcnt()+"");
+                ExcelPoiUtil.createCell(row, 4, textStyle1, MoneyUtil.formatYuanToString(detail.getB_normalamt()));
+                ExcelPoiUtil.createCell(row, 5, textStyle1, detail.getL_normalcnt().toString());
+                ExcelPoiUtil.createCell(row, 6, textStyle1, MoneyUtil.formatYuanToString(detail.getL_normalamt())); //午餐
+                ExcelPoiUtil.createCell(row, 7, textStyle1, detail.getD_normalcnt().toString());
+                ExcelPoiUtil.createCell(row, 8, textStyle1, MoneyUtil.formatYuanToString(detail.getD_normalamt())); //晚餐
+                ExcelPoiUtil.createCell(row, 9, textStyle1, detail.getTotnormalcnt().toString());
+                ExcelPoiUtil.createCell(row, 10, textStyle1,MoneyUtil.formatYuanToString(detail.getTotnormalamt()));
+                ExcelPoiUtil.createCell(row, 11, textStyle1, detail.getB_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 12, textStyle1, MoneyUtil.formatYuanToString(detail.getB_discountamt()));
+                ExcelPoiUtil.createCell(row, 13, textStyle1, detail.getL_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 14, textStyle1, MoneyUtil.formatYuanToString(detail.getL_discountamt())); //午餐
+                ExcelPoiUtil.createCell(row, 15, textStyle1, detail.getD_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 16, textStyle1, MoneyUtil.formatYuanToString(detail.getD_discountamt())); //晚餐
+                ExcelPoiUtil.createCell(row, 17, textStyle1, detail.getTotdiscountcnt().toString());
+                ExcelPoiUtil.createCell(row, 18, textStyle1,MoneyUtil.formatYuanToString(detail.getTotdiscountamt()));
+                ExcelPoiUtil.createCell(row, 19, textStyle1, MoneyUtil.formatYuanToString(detail.getTotfeeamt()));
+                ExcelPoiUtil.createCell(row, 20, textStyle1, detail.getTotcnt().toString());
+                ExcelPoiUtil.createCell(row, 21, textStyle1,MoneyUtil.formatYuanToString(detail.getTotamt()));
+
+            }
+
+
+        }
+
+        //TODO: 表格页脚
+        HSSFCellStyle textStyle3 = ExcelPoiUtil.creatStyle(workbook, "宋体", false, 10, HSSFCellStyle.ALIGN_LEFT, false); //设置单元格样式
+        HSSFRow buttom = ExcelPoiUtil.createRow(sheet, ++rowNum, 400);
+        ExcelPoiUtil.createCell(buttom, 0, textStyle3, "制表人:" + (oper == null ? "unknow" : oper.getOpername()) + "  " + DateUtil.reformatDatetime(systemUtilService.getSysdatetime().getHostdatetime(), DateUtil.DATETIME_FMT, "yyyy-MM-dd HH:mm:ss"));
+        sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 2));  //合并列
+
+        //TODO: 审核信息
+        HSSFRow signRow10 = ExcelPoiUtil.createRow(sheet, rowNum + 3, 400);
+        ExcelPoiUtil.createCell(signRow10, 0, textStyle3, "大理州公安局警务保障处审核盖章:");
+        ExcelPoiUtil.createCell(signRow10, 6, textStyle3, "苍山饭店审核盖章:");
+        sheet.addMergedRegion(new CellRangeAddress(rowNum + 3, rowNum + 3, 0, 5));  //合并列
+        sheet.addMergedRegion(new CellRangeAddress(rowNum + 3, rowNum + 3, 6, columns - 1));  //合并列
+        HSSFRow signRow11 = ExcelPoiUtil.createRow(sheet, rowNum + 4, 400);
+        ExcelPoiUtil.createCell(signRow11, 0, textStyle3, "经办人:");
+        ExcelPoiUtil.createCell(signRow11, 6, textStyle3, "审核人:");
+        sheet.addMergedRegion(new CellRangeAddress(rowNum + 4, rowNum + 4, 0, 5));  //合并列
+        sheet.addMergedRegion(new CellRangeAddress(rowNum + 4, rowNum + 4, 6, columns - 1));  //合并列
+
+        HSSFRow signRow12 = ExcelPoiUtil.createRow(sheet, rowNum + 5, 400);
+        ExcelPoiUtil.createCell(signRow12, 0, textStyle3, "审核人:");
+        sheet.addMergedRegion(new CellRangeAddress(rowNum + 5, rowNum + 5, 0, 5));  //合并列
+
+
+        try {
+            response.setContentType("application/x-msdownload");
+            response.setHeader("Content-Disposition", "attachment;" + " filename=" + new String(filename.getBytes(), "ISO-8859-1") + ".xls");
+            OutputStream out = response.getOutputStream();
+            workbook.write(out);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/TermReportServiceImpl.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/TermReportServiceImpl.java
index 88476b5..2493657 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/TermReportServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/TermReportServiceImpl.java
@@ -42,42 +42,43 @@
 
     private static final Logger logger = LoggerFactory.getLogger(TermReportServiceImpl.class);
 
-
     @Override
     public List<TermReportShowBean> getTermReportSearchData(TermReportSearchBean searchBean) {
         if (null != searchBean) {
             String startdate = DateUtil.unParseToDateFormat(searchBean.getStartdate());
             String enddate = DateUtil.unParseToDateFormat(searchBean.getEnddate());
 
-            StringBuffer sb = new StringBuffer("select t.termid," +
+            StringBuffer sb = new StringBuffer("select cast (t.termid as VARCHAR) termid," +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='breakfast' then t.amount else 0 end) as b_normalamt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='breakfast' then 1 else 0 end) as b_normalcnt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota')  and t.mealtype='breakfast' then 1 else 0 end) as b_discountcnt, " +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='breakfast' then 1 else 0 end) as int4) as b_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota')  and t.mealtype='breakfast' then 1 else 0 end) as int4) as b_discountcnt, " +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='breakfast' then t.amount else 0 end) as b_discountamt, " +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='lunch' then t.amount else 0 end) as l_normalamt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='lunch' then 1 else 0 end) as l_normalcnt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='lunch' then 1 else 0 end) as l_discountcnt, " +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='lunch' then 1 else 0 end) as int4) as l_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='lunch' then 1 else 0 end) as int4) as l_discountcnt, " +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='lunch' then t.amount else 0 end) as l_discountamt, " +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='dinner' then t.amount else 0 end) as d_normalamt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='dinner' then 1 else 0 end) as d_normalcnt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then 1 else 0 end) as d_discountcnt, " +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then t.amount else 0 end) as d_discountmt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then 1 else 0 end) as totdiscountcnt, " +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal' and t.mealtype='dinner' then 1 else 0 end) as int4) as d_normalcnt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then 1 else 0 end) as int4) as d_discountcnt, " +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') and t.mealtype='dinner' then t.amount else 0 end) as d_discountamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then 1 else 0 end) as int4) as totdiscountcnt, " +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then t.amount else 0 end) as totdiscountamt," +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype in ('discount','reduction','quota') then t.managefee else 0 end) as totfeeamt," +
                     " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal'   then t.amount else 0 end) as totnormalamt," +
-                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal'  then 1 else 0 end) as totnormalcnt" +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 when t.managefeetype ='normal'  then 1 else 0 end) as int4) as totnormalcnt," +
+                    " sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 else t.amount end) as totamt," +
+                    " cast(sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 else 1 end)  as int4) as totcnt" +
                     " from tb_transdtl t  " +
                     " left join tb_device dev on t.termid=dev.id " +
                     " left join tb_shopsettlement s on s.shopid=t.shopid" +
                     " left join tb_discount_rule r on r.ruleid=t.ruleid" +
                     " where t.status='success' " +
                     " and t.accdate>=:startdate and t.accdate<=:enddate ") ;
-            if (StringUtil.isEmpty(searchBean.getShopid())) {
+            if (!StringUtil.isEmpty(searchBean.getShopid())) {
                 sb.append( " and s.shopid = :shopid ");
             }
-            if (StringUtil.isEmpty(searchBean.getShopname())) {
-                sb.append( " and s.shopid like :shopname ");
+            if (!StringUtil.isEmpty(searchBean.getShopname())) {
+                sb.append( " and s.shopname like :shopname ");
             }
             if (null!=searchBean.getDevgroupid()) {
                 sb.append( " and dev.devgroupid = :groupid ");
@@ -85,17 +86,17 @@
             if (null!=searchBean.getRuleid()) {
                 sb.append( " and r.ruleid = :ruleid ");
             }
-            sb.append(" group by dev.devgroupid,t.termid,s.shopname");
+            sb.append(" group by t.termid");
             Query query = entityManager.createNativeQuery(sb.toString());
             query.setParameter("startdate", startdate);
             query.setParameter("enddate", enddate);
             if (null!=searchBean.getDevgroupid()) {
                 query.setParameter("groupid", searchBean.getDevgroupid());
             }
-            if (StringUtil.isEmpty(searchBean.getShopid())) {
+            if (!StringUtil.isEmpty(searchBean.getShopid())) {
                 query.setParameter("shopid", searchBean.getShopid().trim()  );
             }
-            if (StringUtil.isEmpty(searchBean.getShopname())) {
+            if (!StringUtil.isEmpty(searchBean.getShopname())) {
                 query.setParameter("shopname","%" + searchBean.getShopname().trim() + "%");
             }
             if (null!=searchBean.getRuleid()) {
@@ -103,7 +104,33 @@
             }
             query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(TermReportShowBean.class));
             List<TermReportShowBean> list = query.getResultList();
-            if (null != list) return list;
+            if (null != list){
+                TermReportShowBean tot=new TermReportShowBean("合 计",0d,0,0d,0,0d,0,0d,0,0d,0,
+                        0d,0,0,0d,0d,0,0d,0,0d);
+                for(TermReportShowBean b:list){
+                    tot.setB_discountamt(tot.getB_discountamt()+b.getB_discountamt());
+                    tot.setB_discountcnt(tot.getB_discountcnt()+b.getB_discountcnt());
+                    tot.setL_discountamt(tot.getL_discountamt()+b.getL_discountamt());
+                    tot.setL_discountcnt(tot.getL_discountcnt()+b.getL_discountcnt());
+                    tot.setD_discountamt(tot.getD_discountamt()+b.getD_discountamt());
+                    tot.setD_discountcnt(tot.getD_discountcnt()+b.getD_discountcnt());
+                    tot.setB_normalamt(tot.getB_normalamt()+b.getB_normalamt());
+                    tot.setB_normalcnt(tot.getB_normalcnt()+b.getB_normalcnt());
+                    tot.setL_normalamt(tot.getL_normalamt()+b.getL_normalamt());
+                    tot.setL_normalcnt(tot.getL_normalcnt()+b.getL_normalcnt());
+                    tot.setD_normalamt(tot.getD_normalamt()+b.getD_normalamt());
+                    tot.setD_normalcnt(tot.getD_normalcnt()+b.getD_normalcnt());
+                    tot.setTotdiscountamt(tot.getTotdiscountamt()+b.getTotdiscountamt());
+                    tot.setTotdiscountcnt(tot.getTotnormalcnt()+b.getTotdiscountcnt());
+                    tot.setTotfeeamt(tot.getTotfeeamt()+b.getTotfeeamt());
+                    tot.setTotnormalamt(tot.getTotnormalamt()+b.getTotnormalamt());
+                    tot.setTotnormalcnt(tot.getTotnormalcnt()+b.getTotnormalcnt());
+                    tot.setTotcnt(tot.getTotcnt()+b.getTotcnt());
+                    tot.setTotamt(tot.getTotamt()+b.getTotamt());
+                }
+                list.add(tot);
+                return list;
+            }
         }
         return new ArrayList<>(0);
 
@@ -125,7 +152,7 @@
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet("终端消费报表");
 
-        int columns = 10; //
+        int columns = 20; //
         sheet.setColumnWidth(0, ExcelPoiUtil.columnWidth(25)); //日期
         for (int i = 3; i < columns; i++) {
             sheet.setColumnWidth(i, ExcelPoiUtil.columnWidth(12));
@@ -158,58 +185,106 @@
 
         //TODO:创建表头(poi做多行合并,一定需要先绘制单元格,然后写入数据,最后合并)
         HSSFRow row2 = ExcelPoiUtil.createRow(sheet, 2, 600);
-        ExcelPoiUtil.createCell(row2, 0, headStyle, "序号");
-        ExcelPoiUtil.createCell(row2, 1, headStyle, "食堂");
+        ExcelPoiUtil.createCell(row2, 0, headStyle, "终端号");
+        ExcelPoiUtil.createCell(row2, 1, headStyle, "非折扣交易");
 
-        ExcelPoiUtil.createCell(row2, 2, headStyle, "含餐补消费支付");
+        ExcelPoiUtil.createCell(row2, 2, headStyle, null);
         ExcelPoiUtil.createCell(row2, 3, headStyle, null);
         ExcelPoiUtil.createCell(row2, 4, headStyle, null);
         ExcelPoiUtil.createCell(row2, 5, headStyle, null);
         ExcelPoiUtil.createCell(row2, 6, headStyle, null);
         ExcelPoiUtil.createCell(row2, 7, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 8, headStyle, null);
 
-        sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 7)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 8)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
 
-        ExcelPoiUtil.createCell(row2, 8, headStyle, "无餐补消费支付");
-        ExcelPoiUtil.createCell(row2, 9, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 9, headStyle, "折扣交易");
         ExcelPoiUtil.createCell(row2, 10, headStyle, null);
-        sheet.addMergedRegion(new CellRangeAddress(2, 2, 8, 10)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
+        ExcelPoiUtil.createCell(row2, 11, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 12, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 13, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 14, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 15, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 16, headStyle, null);
+        ExcelPoiUtil.createCell(row2, 17, headStyle, null);
+        sheet.addMergedRegion(new CellRangeAddress(2, 2, 9, 17)); //合并单元格CellRangeAddress构造参数依次表示 起始行,截至行,起始列, 截至列
 
 
-        ExcelPoiUtil.createCell(row2, 11, headStyle, "合计 消费金额");
-        ExcelPoiUtil.createCell(row2, 12, headStyle, "合计 消费笔数");
-        HSSFRow row3 = ExcelPoiUtil.createRow(sheet, 3, 800); //表头第二行
+        ExcelPoiUtil.createCell(row2, 18, headStyle, "交易笔\n数合计");
+        ExcelPoiUtil.createCell(row2, 19, headStyle, "交易金\n额合计");
+
+        HSSFRow row3 = ExcelPoiUtil.createRow(sheet, 3, 800);
+        HSSFRow row4 = ExcelPoiUtil.createRow(sheet, 4, 800);
+        ExcelPoiUtil.createCell(row4, 0, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 1, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 2, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 3, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 4, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 5, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 6, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 9, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 10, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 11, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 12, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 13, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 14, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 17, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 18, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 19, headStyle, null);
+
         ExcelPoiUtil.createCell(row3, 0, headStyle, null);
-        sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0)); //合并列
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 0, 0)); //合并列
 
-        ExcelPoiUtil.createCell(row3, 1, headStyle, null);
-        sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1)); //合并列
+        ExcelPoiUtil.createCell(row3, 1, headStyle, "早餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 2, headStyle, "早餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 3, headStyle, "午餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 4, headStyle, "午餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 5, headStyle, "晚餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 6, headStyle, "晚餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 7, headStyle, "非折扣\n交易小计");
+        ExcelPoiUtil.createCell(row3, 8, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 7, headStyle, "交易笔数小计");
+        ExcelPoiUtil.createCell(row4, 8, headStyle, "交易金额小计");
 
-        ExcelPoiUtil.createCell(row3, 11, headStyle, null);
-        sheet.addMergedRegion(new CellRangeAddress(2, 3, 11, 11)); //合并列
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 1, 1)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 2, 2)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 3, 3)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 4, 4)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 5, 5)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 6, 6)); //合并行
+        sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 8));
 
-        ExcelPoiUtil.createCell(row3, 12, headStyle, null);
-        sheet.addMergedRegion(new CellRangeAddress(2, 3, 12, 12)); //合并列
+        ExcelPoiUtil.createCell(row3, 9, headStyle, "早餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 10, headStyle, "早餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 11, headStyle, "午餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 12, headStyle, "午餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 13, headStyle, "晚餐累计\n交易笔数");
+        ExcelPoiUtil.createCell(row3, 14, headStyle, "晚餐累计\n交易金额");
+        ExcelPoiUtil.createCell(row3, 15, headStyle, "折扣\n交易小计");
+        ExcelPoiUtil.createCell(row3, 16, headStyle, null);
+        ExcelPoiUtil.createCell(row4, 15, headStyle, "交易笔数小计");
+        ExcelPoiUtil.createCell(row4, 16, headStyle, "交易金额小计");
 
-        ExcelPoiUtil.createCell(row3, 2, headStyle, "早餐 金额");
-        ExcelPoiUtil.createCell(row3, 3, headStyle, "早餐 份数");
-        ExcelPoiUtil.createCell(row3, 4, headStyle, "午餐 金额");
-        ExcelPoiUtil.createCell(row3, 5, headStyle, "午餐 份数");
-        ExcelPoiUtil.createCell(row3, 6, headStyle, "晚餐 金额");
-        ExcelPoiUtil.createCell(row3, 7, headStyle, "晚餐 份数");
+        ExcelPoiUtil.createCell(row3, 17, headStyle, "餐补金额");
+        ExcelPoiUtil.createCell(row3, 18, headStyle, null);
+        ExcelPoiUtil.createCell(row3, 19, headStyle, null);
 
- //       ExcelPoiUtil.createCell(row3, 8, headStyle, "早餐 金额");
-        ExcelPoiUtil.createCell(row3, 8, headStyle, "早餐 份数");
-   //     ExcelPoiUtil.createCell(row3, 10, headStyle, "午餐 金额");
-        ExcelPoiUtil.createCell(row3, 9, headStyle, "午餐 份数");
- //       ExcelPoiUtil.createCell(row3, 12, headStyle, "晚餐 金额");
-        ExcelPoiUtil.createCell(row3, 10, headStyle, "晚餐 份数");
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 9, 9));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 10, 10));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 11, 11));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 12, 12));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 13, 13));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 14, 14));
+        sheet.addMergedRegion(new CellRangeAddress(3, 4, 17, 17));
+        sheet.addMergedRegion(new CellRangeAddress(3, 3, 15, 16));
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 18, 18));
+        sheet.addMergedRegion(new CellRangeAddress(2, 4, 19, 19));
 
         //TODO: 数据
-        int rowNum = 4;
+        int rowNum = 5;
         if (StringUtil.isEmpty(datalist)) {
             //无数据
-            HSSFRow row4 = ExcelPoiUtil.createRow(sheet, rowNum, 500);
+            HSSFRow row5 = ExcelPoiUtil.createRow(sheet, rowNum, 500);
             ExcelPoiUtil.createCell(row4, 0, textStyle1, "无数据");
             for (int n = 1; n < columns; n++) ExcelPoiUtil.createCell(row4, n, textStyle1, null);
             sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, columns - 1)); //合并列
@@ -218,22 +293,26 @@
             for (int i = 0; i < datalist.size(); i++) {
                 TermReportShowBean detail = datalist.get(i);
                 HSSFRow row = ExcelPoiUtil.createRow(sheet, rowNum++, 500);
-  /*              ExcelPoiUtil.createCell(row, 0, textStyle1,""+ detail.getRownum());
-                ExcelPoiUtil.createCell(row, 1, textStyle1, detail.getGroupname());
-                ExcelPoiUtil.createCell(row, 2, textStyle1, MoneyUtil.formatYuanToString(detail.getIbtotalamt()));
-                ExcelPoiUtil.createCell(row, 3, textStyle1, detail.getIbtotalcnt().toString());
-                ExcelPoiUtil.createCell(row, 4, textStyle1, MoneyUtil.formatYuanToString(detail.getIltotalamt())); //午餐
-                ExcelPoiUtil.createCell(row, 5, textStyle1, detail.getIltotalcnt().toString());
-                ExcelPoiUtil.createCell(row, 6, textStyle1, MoneyUtil.formatYuanToString(detail.getIdtotalamt())); //晚餐
-                ExcelPoiUtil.createCell(row, 7, textStyle1, detail.getIdtotalcnt().toString());
-
-                ExcelPoiUtil.createCell(row, 8, textStyle1, detail.getObtotalcnt().toString());
-                ExcelPoiUtil.createCell(row, 9, textStyle1, detail.getOltotalcnt().toString());
-                ExcelPoiUtil.createCell(row, 10, textStyle1, detail.getOdtotalcnt().toString());
-
-                ExcelPoiUtil.createCell(row, 11, textStyle1, MoneyUtil.formatYuanToString(detail.getIdtotalamt()+detail.getIbtotalamt()+detail.getIltotalamt())); //总计
-                ExcelPoiUtil.createCell(row, 12, textStyle1, detail.getIdtotalcnt()+detail.getIbtotalcnt()+detail.getIltotalcnt()+detail.getOdtotalcnt()+detail.getOltotalcnt()+detail.getObtotalcnt()+"");
-*/
+                ExcelPoiUtil.createCell(row, 0, textStyle1, detail.getTermid());
+                ExcelPoiUtil.createCell(row, 1, textStyle1, detail.getB_normalcnt()+"");
+                ExcelPoiUtil.createCell(row, 2, textStyle1, MoneyUtil.formatYuanToString(detail.getB_normalamt()));
+                ExcelPoiUtil.createCell(row, 3, textStyle1, detail.getL_normalcnt().toString());
+                ExcelPoiUtil.createCell(row, 4, textStyle1, MoneyUtil.formatYuanToString(detail.getL_normalamt())); //午餐
+                ExcelPoiUtil.createCell(row, 5, textStyle1, detail.getD_normalcnt().toString());
+                ExcelPoiUtil.createCell(row, 6, textStyle1, MoneyUtil.formatYuanToString(detail.getD_normalamt())); //晚餐
+                ExcelPoiUtil.createCell(row, 7, textStyle1, detail.getTotnormalcnt().toString());
+                ExcelPoiUtil.createCell(row, 8, textStyle1,MoneyUtil.formatYuanToString(detail.getTotnormalamt()));
+                ExcelPoiUtil.createCell(row, 9, textStyle1, detail.getB_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 10, textStyle1, MoneyUtil.formatYuanToString(detail.getB_discountamt()));
+                ExcelPoiUtil.createCell(row, 11, textStyle1, detail.getL_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 12, textStyle1, MoneyUtil.formatYuanToString(detail.getL_discountamt())); //午餐
+                ExcelPoiUtil.createCell(row, 13, textStyle1, detail.getD_discountcnt().toString());
+                ExcelPoiUtil.createCell(row, 14, textStyle1, MoneyUtil.formatYuanToString(detail.getD_discountamt())); //晚餐
+                ExcelPoiUtil.createCell(row, 15, textStyle1, detail.getTotdiscountcnt().toString());
+                ExcelPoiUtil.createCell(row, 16, textStyle1,MoneyUtil.formatYuanToString(detail.getTotdiscountamt()));
+                ExcelPoiUtil.createCell(row, 17, textStyle1, MoneyUtil.formatYuanToString(detail.getTotfeeamt()));
+                ExcelPoiUtil.createCell(row, 18, textStyle1, detail.getTotcnt().toString());
+                ExcelPoiUtil.createCell(row, 19, textStyle1,MoneyUtil.formatYuanToString(detail.getTotamt()));
 
             }
 
diff --git a/src/main/resources/templates/restaurant/custreport/index.html b/src/main/resources/templates/restaurant/custreport/index.html
new file mode 100644
index 0000000..87e4681
--- /dev/null
+++ b/src/main/resources/templates/restaurant/custreport/index.html
@@ -0,0 +1,252 @@
+<div class="layui-card">
+    <div class="layui-card-header">
+        <h2 class="header-title">个人流水报表</h2>
+        <span class="layui-breadcrumb pull-right">
+          <a href="#">报表中心</a>
+          <a><cite>个人流水报表</cite></a>
+        </span>
+    </div>
+    <div class="layui-card-body">
+        <input type="hidden" id="custreport-hidden-maxdate" th:value="${maxdate}"/>
+
+        <div class="layui-form" lay-filter="custreport-search-form">
+            <div class="layui-form-item" style="margin-bottom: 0;">
+                <div class="layui-inline">
+                    <label class="layui-form-label"> 商户:</label>
+                    <div class="layui-input-inline">
+                        <select name="shopid" id="custreport-search-shopid">
+                            <option value="" selected>全部</option>
+                            <option th:each="shop : ${shoplistForSelect}" th:value="${shop.shopid}">[[${shop.shopname}]]</option>
+                        </select>
+                    </div>
+                </div>
+                <div class="layui-inline">
+                    <label class="layui-form-label">餐补规则:</label>
+                    <div class="layui-input-inline" style="height: 38px">
+                        <select  id="custreport-search-ruleid">
+                            <option value=""  selected>全部</option>
+                            <option th:each="rl:${rulelist}" th:value="${rl.ruleid}"
+                                    th:text="${rl.rulename}"></option>
+                        </select>
+                    </div>
+                </div>
+
+            </div>
+
+            <div class="layui-form-item" style="margin-bottom: 0; ">
+                <div class="layui-inline">
+                    <label class="layui-form-label">汇总日期</label>
+                    <div class="layui-input-inline">
+                        <input type="text" name="startdate" id="custreport-search-startdate" placeholder="起始日期"
+                               th:value="${maxdate}"
+                               autocomplete="off" class="layui-input"/>
+                    </div>
+                    <div class="layui-form-mid">-</div>
+                    <div class="layui-input-inline">
+                        <input type="text" name="enddate" id="custreport-search-enddate" placeholder="截止日期"
+                               th:value="${maxdate}"
+                               autocomplete="off" class="layui-input"/>
+                    </div>
+                </div>
+                <div class="layui-inline">
+                    <button id="custreport-search-btn" class="layui-btn icon-btn" data-type="search"><i
+                            class="layui-icon">&#xe615;</i>搜索
+                    </button>
+                </div>
+
+            </div>
+
+        </div>
+    </div>
+    <div class="layui-card-body">
+        <div class="layui-form toolbar">
+            <div class="layui-btn-group">
+                <button id="shopreport-custreport-export-excel"
+                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
+                        class="layui-icon layui-icon-export"></i>导出
+                </button>
+                <button id="shopreport-custreport-print-table"
+                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
+                        class="layui-icon layui-icon-print"></i>打印
+                </button>
+            </div>
+        </div>
+        <table class="layui-table sw-table" id="shopreport-custreport-table"
+               th:fragment="custreportTable">
+            <thead>
+            <tr>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">部门</th>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">姓名</th>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">卡号</th>
+                <th colspan="8" style="text-align: center;min-width: 100px;">非折扣交易</th>
+                <th colspan="9" style="text-align: center;">折扣交易</th>
+                <th rowspan="4" style="text-align: center;">交易笔数<br/>合计</th>
+                <th rowspan="4" style="text-align: center;">交易金额<br/>合计</th>
+            </tr>
+            <tr>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">非折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">餐补金额</th>
+            </tr>
+            <tr>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+            </tr>
+            </thead>
+
+            <tbody id="shopreport-custreport-tbody" th:data-startdate="${searchBean.startdate}" th:data-enddate="${searchBean.enddate}"  th:data-opercode="${opercode}">
+            <tr th:if="${null==showlist || showlist.size()==0}">
+                <td colspan="23">无数据</td>
+            </tr>
+            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}">
+                <tr>
+                    <td style="font-weight: bold;" th:text="${data.deptname}"></td>
+                    <td style="font-weight: bold;" th:text="${data.custname}"></td>
+                    <td style="font-weight: bold;" th:text="${data.cardno}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totnormalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totnormalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totdiscountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totdiscountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totfeeamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totamt,1,2)}"></td>
+
+                </tr>
+
+            </div>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+
+<script>
+    layui.use(['form', 'layer', 'element', 'laydate', 'treeSelect'], function () {
+        var layer = layui.layer;
+        var $ = layui.jquery;
+        var treeSelect = layui.treeSelect;
+        var laydate = layui.laydate;
+
+
+        laydate.render({
+            elem: '#custreport-search-startdate',
+            max: $("#custreport-hidden-maxdate").val(),
+            trigger: 'click'
+        });
+        laydate.render({
+            elem: '#shopreport-labercount-search-enddate',
+            max: $("#custreport-hidden-maxdate").val(),
+            trigger: 'click'
+        });
+
+        $('#custreport-search-btn').click(function () {
+            var shopid = $("#custreport-search-shopid").val();
+            var ruleid = $("#custreport-search-ruleid").val();
+            var startdate = $("#custreport-search-startdate").val();
+            var enddate = $("#custreport-search-enddate").val();
+            $.ajax({
+                url: '[[@{/custreport/custreportlist}]]',
+                type: "POST",
+                data: {
+                    shopid: shopid,
+                    startdate:startdate,
+                    enddate:enddate,
+                    ruleid: ruleid,
+                    _csrf: $("meta[name='_csrf_token']").attr("value")
+                },
+                success: function (data) {
+                    $("#shopreport-custreport-table").html(data);
+                    layer.closeAll('loading');
+                },
+                error: function (status, err) {
+                    layer.closeAll('loading');
+                    layer.msg('查询失败了', {icon: 2});
+                }
+            });
+        });
+
+        $("#shopreport-custreport-export-excel").click(function(){
+            var startdate= $("#shopreport-custreport-tbody").attr("data-startdate");
+            var enddate= $("#shopreport-custreport-tbody").attr("data-enddate");
+            var shopid = $("#custreport-search-shopid").val();
+            var ruleid = $("#custreport-search-ruleid").val();
+            var dataUrl='[[@{/custreport/excelexport}]]?startdate='+startdate+'&enddate='+enddate+'&shopid='+shopid+'&ruleid='+ruleid;
+            var xhr = new XMLHttpRequest();
+            xhr.responseType = "blob"; //设置响应类型为blob类型
+            xhr.onload = function () {
+                debugger
+                if (this.status == "200") {
+                    //获取响应文件流 
+                    var blob = this.response;
+                    // 转换完成,创建一个a标签用于下载
+                    var aElem = document.createElement('a');
+                    aElem.href = window.URL.createObjectURL(blob);
+                    aElem.download = "客户类别消费报表.xls";
+                    aElem.onload = function (e) {
+                        window.URL.revokeObjectURL(aElem.href);
+                    };
+                    $("body").append(aElem);  // 修复firefox中无法触发click
+                    aElem.click();
+                    $(aElem).remove();
+
+                }else if(this.status == "403"){
+                    layer.msg('无导出资源权限', {icon: 2});
+                } else {
+                    layer.msg('导出excel失败了', {icon: 2});
+                }
+            }
+            xhr.open("GET", dataUrl, true);
+            xhr.send();
+        });
+
+        var LODOP; //声明为全局变量
+        $("#shopreport-custreport-print-table").click(function(){
+            var startdate= $("#shopreport-custreport-tbody").attr("data-startdate");
+            var enddate= $("#shopreport-custreport-tbody").attr("data-enddate");
+            var shopid = $("#custreport-search-shopid").val();
+            var ruleid = $("#custreport-search-ruleid").val();
+
+            var opercode = $("#shopreport-custreport-tbody").attr("data-opercode");
+            var url = '/custreport/print/printcustreport?startdate=' + startdate + '&enddate=' + enddate +'&shopid='+shopid+'&ruleid='+ruleid+  '&opercode=' + opercode;
+
+            LODOP = getLodop();
+            LODOP.PRINT_INIT("个人流水报表");
+            LODOP.SET_PRINT_PAGESIZE(2, 0, 0,"A4");
+            LODOP.ADD_PRINT_URL(30, 20, "95%", "90%", encodeURI(url));
+            LODOP.ADD_PRINT_HTM("95%", "48%", 150, 50, "<font style='font-size:12px'><span tdata='pageNO'>##</span>/<span tdata='pageCount'>&nbsp;&nbsp;##</span></font>");
+            LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
+            LODOP.SET_PRINT_STYLEA(0, "HOrient", 3);
+            LODOP.SET_PRINT_STYLEA(0, "VOrient", 3);
+            LODOP.SET_SHOW_MODE("NP_NO_RESULT", true);
+            LODOP.SET_PRINT_MODE("FULL_WIDTH_FOR_OVERFLOW",true);
+            LODOP.PREVIEW();
+        });
+
+    });
+</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/restaurant/custreport/print/report.html b/src/main/resources/templates/restaurant/custreport/print/report.html
new file mode 100644
index 0000000..7dfecd6
--- /dev/null
+++ b/src/main/resources/templates/restaurant/custreport/print/report.html
@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
+<head>
+    <meta charset="UTF-8">
+    <title>客户消费报表</title>
+
+    <link rel="stylesheet" th:href="@{/static/libs/layui/css/layui.css}"/>
+    <link rel="stylesheet" th:href="@{/static/custom/css/custom.css}"/>
+</head>
+<body>
+<div class="layui-card">
+    <div class="layui-card-header" style="text-align: center;">
+        <h1>客户消费报表</h1>
+    </div>
+    <div class="layui-card-body">
+        <div class="layui-form toolbar">
+            <div style="float: left;padding-left: 3px;" th:text="${'区间:'+period}"></div>
+            <div style="float: right;" th:text="'单位:元'"></div>
+        </div>
+        <table class="layui-table sw-table sw-print">
+            <thead>
+            <tr>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">单位</th>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">姓名</th>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">卡号</th>
+                <th colspan="8" style="text-align: center;min-width: 100px;">非折扣交易</th>
+                <th colspan="9" style="text-align: center;">折扣交易</th>
+                <th rowspan="4" style="text-align: center;">交易笔数<br/>合计</th>
+                <th rowspan="4" style="text-align: center;">交易金额<br/>合计</th>
+            </tr>
+            <tr>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">非折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">餐补金额</th>
+            </tr>
+            <tr>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+            </tr>
+            </thead>
+            <tbody>
+            <tr th:if="${null==showlist || showlist.size()==0}">
+                <td colspan="23">无数据</td>
+            </tr>
+            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}">
+                <tr>
+                    <td style="font-weight: bold;" th:text="${data.deptname}"></td>
+                    <td style="font-weight: bold;" th:text="${data.custname}"></td>
+                    <td style="font-weight: bold;" th:text="${data.cardno}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totnormalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totnormalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totdiscountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totdiscountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totfeeamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totamt,1,2)}"></td>
+                </tr>
+            </div>
+            </tbody>
+        </table>
+        <div class="layui-form toolbar">
+            <div style="float: left;padding-left: 3px;"
+                 th:text="${'制表人:'+opername+' &nbsp;&nbsp; '+ printdatetime}"></div>
+        </div>
+    </div>
+    <div class="layui-card-body" style="margin-top: 25px;">
+        <table class="sw-print-sign">
+            <tr>
+                <td width="50%">大理州公安局警务保障处审核盖章:</td>
+                <td width="50%">苍山饭店审核盖章:</td>
+            </tr>
+            <tr>
+                <td>经办人:</td>
+                <td>审核人:</td>
+            </tr>
+            <tr>
+                <td>审核人:</td>
+
+            </tr>
+        </table>
+    </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/main/resources/templates/restaurant/terminalreport/index.html b/src/main/resources/templates/restaurant/terminalreport/index.html
deleted file mode 100644
index 301dc5e..0000000
--- a/src/main/resources/templates/restaurant/terminalreport/index.html
+++ /dev/null
@@ -1,148 +0,0 @@
-<div class="layui-card">
-    <div class="layui-card-header">
-        <h2 class="header-title">终端消费报表</h2>
-        <span class="layui-breadcrumb pull-right">
-          <a href="#">报表中心</a>
-          <a><cite>终端消费报表</cite></a>
-        </span>
-    </div>
-    <div class="layui-card-body">
-        <div class="layui-form" lay-filter="terminalreport-search-form">
-            <div class="layui-form-item" style="margin-bottom: 0;">
-                <div class="layui-inline">
-                    <label class="layui-form-label">商户编号</label>
-                    <div class="layui-input-inline">
-                        <input type="text" name="shopno" id="terminalreport-search-shopno"
-                               autocomplete="off" class="layui-input"/>
-                    </div>
-
-                </div>
-                <div class="layui-inline">
-                    <label class="layui-form-label">商户名称</label>
-                    <div class="layui-input-inline">
-                        <input type="text" name="shopname" id="terminalreport-search-shopname"
-                               autocomplete="off" class="layui-input"/>
-                    </div>
-                </div>
-            </div>
-            <div class="layui-form-item" style="margin-bottom: 0; ">
-                <div class="layui-inline">
-                    <label class="layui-form-label">报表区间</label>
-                    <div class="layui-input-inline">
-                        <input type="text" name="interval" id="terminalreport-search-interval"
-                               autocomplete="off" class="layui-input"/>
-                    </div>
-                </div>
-                <div class="layui-inline">
-                    <label class="layui-form-label">餐补规则</label>
-                    <div class="layui-input-inline">
-                        <select name="ruleid" id="terminalreport-search-ruleid">
-                            <option value="" selected>全部</option>
-                        </select>
-                    </div>
-                </div>
-
-                <div class="layui-inline">
-                    <button id="terminalreport-search-btn" class="layui-btn icon-btn" data-type="search"><i
-                            class="layui-icon">&#xe615;</i>搜索
-                    </button>
-                </div>
-            </div>
-        </div>
-    </div>
-    <div class="layui-card-body">
-        <div class="layui-form toolbar">
-            <div class="layui-btn-group">
-                <button id="shopreport-terminalreport-export-excel"
-                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
-                        class="layui-icon layui-icon-export"></i>导出
-                </button>
-                <button id="shopreport-terminalreport-print-table"
-                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
-                        class="layui-icon layui-icon-print"></i>打印
-                </button>
-            </div>
-        </div>
-        <table class="layui-table sw-table" id="shopreport-terminalreport-table"
-               th:fragment="terminalreportTable">
-            <thead>
-            <tr>
-                <th rowspan="4" style="text-align: center;min-width: 60px;" >终端编号</th>
-                <th colspan="8" style="text-align: center;min-width: 100px;">非折扣交易</th>
-                <th colspan="9" style="text-align: center;">折扣交易</th>
-                <th rowspan="4" style="text-align: center;">交易笔数<br/>合计</th>
-                <th rowspan="4" style="text-align: center;">交易金额<br/>合计</th>
-            </tr>
-            <tr>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
-                <th colspan="2" style="text-align: center;min-width: 60px;">非折扣交易小计</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
-                <th colspan="2" style="text-align: center;min-width: 60px;">折扣交易小计</th>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">餐补金额</th>
-            </tr>
-            <tr>
-                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
-                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
-                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
-                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
-            </tr>
-            </thead>
-            <tr th:if="${null==showlist || showlist.size()==0}">
-                <td colspan="23">无数据</td>
-            </tr>
-            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}">
-                <tr>
-
-                </tr>
-            </div>
-            </tbody>
-        </table>
-    </div>
-</div>
-
-
-<script>
-    layui.use(['form', 'layer', 'element', 'laydate', 'treeSelect'], function () {
-        var layer = layui.layer;
-        var $ = layui.jquery;
-        var treeSelect = layui.treeSelect;
-
-        $('#terminalreport-search-btn').click(function () {
-            var shopno = $("#terminalreport-search-shopno").val();
-            var shopname = $("#terminalreport-search-shopname").val();
-            var interval = $("#terminalreport-search-interval").val();
-            var ruleid = $("#terminalreport-search-ruleid").val();
-
-            $.ajax({
-                url: '[[@{/terminalreport/terminalreportlist}]]',
-                type: "POST",
-                data: {
-                    shopno: shopno,
-                    shopname: shopname,
-                    interval: interval,
-                    ruleid: ruleid,
-                    _csrf: $("meta[name='_csrf_token']").attr("value")
-                },
-                success: function (data) {
-                    $("#shopreport-terminalreport-table").html(data);
-                    layer.closeAll('loading');
-                },
-                error: function (status, err) {
-                    layer.closeAll('loading');
-                    layer.msg('查询失败了', {icon: 2});
-                }
-            });
-        });
-
-    });
-</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/restaurant/termreport/index.html b/src/main/resources/templates/restaurant/termreport/index.html
index 653cb67..6a0c31b 100644
--- a/src/main/resources/templates/restaurant/termreport/index.html
+++ b/src/main/resources/templates/restaurant/termreport/index.html
@@ -1,104 +1,140 @@
 <div class="layui-card">
     <div class="layui-card-header">
-        <h2 class="header-title">终端消费表</h2>
+        <h2 class="header-title">终端消费报表</h2>
         <span class="layui-breadcrumb pull-right">
           <a href="#">报表中心</a>
-          <a><cite>终端消费表</cite></a>
+          <a><cite>终端消费报表</cite></a>
         </span>
     </div>
     <div class="layui-card-body">
+        <input type="hidden" id="termreport-hidden-maxdate" th:value="${maxdate}"/>
+
         <div class="layui-form" lay-filter="termreport-search-form">
-            <input type="hidden" id="termreport-hidden-maxdate" th:value="${maxdate}" />
-            <input type="hidden" id="termreport-hidden-devgroupid" th:value="${devgroupid}"/>
             <div class="layui-form-item" style="margin-bottom: 0;">
                 <div class="layui-inline">
-                    <label class="layui-form-label">记账日期</label>
+                    <label class="layui-form-label"> 商户:</label>
                     <div class="layui-input-inline">
-                        <input type="text" name="startdate" id="termreport-search-startdate" placeholder="起始日期" th:value="${maxdate}"
+                        <select name="shopid" id="termreport-search-shopid">
+                            <option value="" selected>全部</option>
+                            <option th:each="shop : ${shoplistForSelect}" th:value="${shop.shopid}">[[${shop.shopname}]]</option>
+                        </select>
+                    </div>
+                </div>
+                <div class="layui-inline">
+                    <label class="layui-form-label">餐补规则:</label>
+                    <div class="layui-input-inline" style="height: 38px">
+                        <select  id="termreport-search-ruleid">
+                            <option value=""  selected>全部</option>
+                            <option th:each="rl:${rulelist}" th:value="${rl.ruleid}"
+                                    th:text="${rl.rulename}"></option>
+                        </select>
+                    </div>
+                </div>
+
+            </div>
+
+            <div class="layui-form-item" style="margin-bottom: 0; ">
+                <div class="layui-inline">
+                    <label class="layui-form-label">汇总日期</label>
+                    <div class="layui-input-inline">
+                        <input type="text" name="startdate" id="termreport-search-startdate" placeholder="起始日期"
+                               th:value="${maxdate}"
                                autocomplete="off" class="layui-input"/>
                     </div>
                     <div class="layui-form-mid">-</div>
                     <div class="layui-input-inline">
-                        <input type="text" name="enddate" id="termreport-search-enddate" placeholder="截止日期" th:value="${maxdate}"
+                        <input type="text" name="enddate" id="termreport-search-enddate" placeholder="截止日期"
+                               th:value="${maxdate}"
                                autocomplete="off" class="layui-input"/>
                     </div>
                 </div>
-
-                <div class="layui-inline">
-                    <label class="layui-form-label">选择设备组</label>
-                    <div class="layui-input-block">
-                        <input type="text" name="groupid" id="termreport-search-devgroup" lay-filter="termreport-search-devgroup-filter"
-                               autocomplete="off" class="layui-input"/>
-                    </div>
-                </div>
-
                 <div class="layui-inline">
                     <button id="termreport-search-btn" class="layui-btn icon-btn" data-type="search"><i
                             class="layui-icon">&#xe615;</i>搜索
                     </button>
                 </div>
+
             </div>
+
         </div>
     </div>
     <div class="layui-card-body">
         <div class="layui-form toolbar">
             <div class="layui-btn-group">
-                <button id="shopreport-termreport-export-excel" class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i class="layui-icon layui-icon-export"></i>导出</button>
-                <button id="shopreport-termreport-print-table" class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i class="layui-icon layui-icon-print"></i>打印</button>
+                <button id="shopreport-termreport-export-excel"
+                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
+                        class="layui-icon layui-icon-export"></i>导出
+                </button>
+                <button id="shopreport-termreport-print-table"
+                        class="layui-btn layui-btn-sm layui-btn-primary sw-print"><i
+                        class="layui-icon layui-icon-print"></i>打印
+                </button>
             </div>
         </div>
-        <table class="layui-table sw-table" id="shopreport-termreport-table" th:fragment="termreportTable">
+        <table class="layui-table sw-table" id="shopreport-termreport-table"
+               th:fragment="termreportTable">
             <thead>
             <tr>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">序号</th>
-                <th rowspan="3" style="text-align: center;min-width: 100px;">食堂</th>
-                <th colspan="6" style="text-align: center;">含餐补消费支付</th>
-                <th colspan="3" style="text-align: center;">无餐补消费支付</th>
-                <th  rowspan="3" style="text-align: center;">消费金额</th>
-                <th  rowspan="3" style="text-align: center;">合计消费次数</th>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">终端编号</th>
+                <th colspan="8" style="text-align: center;min-width: 100px;">非折扣交易</th>
+                <th colspan="9" style="text-align: center;">折扣交易</th>
+                <th rowspan="4" style="text-align: center;">交易笔数<br/>合计</th>
+                <th rowspan="4" style="text-align: center;">交易金额<br/>合计</th>
             </tr>
             <tr>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>份数</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>份数</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>份数</th>
-                <!--<th rowspan="2" style="text-align: center;min-width: 60px;">正价金额<br/>小计</th>-->
-              <!--  <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>份数</th>
-             <!--   <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>份数</th>
-          <!--      <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>份数</th>
-
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">非折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">餐补金额</th>
+            </tr>
+            <tr>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
             </tr>
             </thead>
+
             <tbody id="shopreport-termreport-tbody" th:data-startdate="${searchBean.startdate}" th:data-enddate="${searchBean.enddate}"  th:data-opercode="${opercode}">
             <tr th:if="${null==showlist || showlist.size()==0}">
-                <td colspan="13">无数据</td>
+                <td colspan="23">无数据</td>
             </tr>
-            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}" >
-
+            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}">
                 <tr>
-                    <td style="font-weight: bold;" th:text="${data.rownum}"></td>
-                    <td style="font-weight: bold;" th:text="${data.groupname}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.ibtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.ibtotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.iltotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.iltotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.idtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.idtotalcnt}"></td>
-               <!--     <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.obtotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.obtotalcnt}"></td>
-            <!--        <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.oltotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.oltotalcnt}"></td>
-                 <!--   <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.odtotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.odtotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.ibtotalamt+data.iltotalamt+data.idtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.ibtotalcnt+data.iltotalcnt+data.idtotalcnt+data.obtotalcnt+data.oltotalcnt+data.odtotalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${data.termid}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totnormalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totnormalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totdiscountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totdiscountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totfeeamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totamt,1,2)}"></td>
 
                 </tr>
+
             </div>
             </tbody>
         </table>
@@ -107,45 +143,11 @@
 
 
 <script>
-    layui.use(['form', 'layer',  'element', 'laydate','treeSelect'], function () {
-        var laydate = layui.laydate;
+    layui.use(['form', 'layer', 'element', 'laydate', 'treeSelect'], function () {
         var layer = layui.layer;
         var $ = layui.jquery;
         var treeSelect = layui.treeSelect;
-
-        treeSelect.render({
-            elem: '#termreport-search-devgroup',
-            data: '[[@{/whitelistbind/devgrouptree}]]',
-            type: 'get',
-            placeholder: '选择设备组',
-            search: false,
-            style: {
-                folder: {
-                    enable: false
-                },
-                line: {
-                    enable: true
-                }
-            },
-            // 点击回调
-            click: function (d) {
-                var treeNode = d.current;
-                console.log(treeNode);
-                if(treeNode.grouptype == 'branch'){
-                    layer.msg("请选择末级商户", {icon: 2, time:1500});
-                    $("#dailyreport-search-devgroup").val("");
-                    treeSelect.revokeNode('termreport-search-devgroup-filter');
-                    return false;
-                }
-                return true;
-            },
-            success: function (d) {
-                let limit= $("#termreport-hidden-devgroupid").val();
-                treeSelect.checkNode(
-                    'termreport-search-devgroup-filter',
-                    limit);
-            }
-        });
+        var laydate = layui.laydate;
 
 
         laydate.render({
@@ -154,31 +156,24 @@
             trigger: 'click'
         });
         laydate.render({
-            elem: '#termreport-search-enddate',
+            elem: '#shopreport-labercount-search-enddate',
             max: $("#termreport-hidden-maxdate").val(),
             trigger: 'click'
         });
 
         $('#termreport-search-btn').click(function () {
+            var shopid = $("#termreport-search-shopid").val();
+            var ruleid = $("#termreport-search-ruleid").val();
             var startdate = $("#termreport-search-startdate").val();
             var enddate = $("#termreport-search-enddate").val();
-            var groupid = $("#termreport-search-devgroup").val();
-            if (null == startdate || "" == $.trim(startdate)) {
-                layer.msg('请选择起始日期', {icon: 2, time: 1500});
-                return;
-            }
-            if (null == enddate || "" == $.trim(enddate)) {
-                layer.msg('请选择截止日期', {icon: 2, time: 1500});
-                return;
-            }
-
             $.ajax({
                 url: '[[@{/termreport/termreportlist}]]',
                 type: "POST",
                 data: {
-                    startdate: startdate,
-                    enddate: enddate,
-                    groupid: groupid,
+                    shopid: shopid,
+                    startdate:startdate,
+                    enddate:enddate,
+                    ruleid: ruleid,
                     _csrf: $("meta[name='_csrf_token']").attr("value")
                 },
                 success: function (data) {
@@ -195,9 +190,9 @@
         $("#shopreport-termreport-export-excel").click(function(){
             var startdate= $("#shopreport-termreport-tbody").attr("data-startdate");
             var enddate= $("#shopreport-termreport-tbody").attr("data-enddate");
-            var groupid = $("#termreport-search-devgroup").val();
-
-            var dataUrl='[[@{/termreport/excelexport}]]?startdate='+startdate+'&enddate='+enddate+'&groupid='+groupid;
+            var shopid = $("#termreport-search-shopid").val();
+            var ruleid = $("#termreport-search-ruleid").val();
+            var dataUrl='[[@{/termreport/excelexport}]]?startdate='+startdate+'&enddate='+enddate+'&shopid='+shopid+'&ruleid='+ruleid;
             var xhr = new XMLHttpRequest();
             xhr.responseType = "blob"; //设置响应类型为blob类型
             xhr.onload = function () {
@@ -230,13 +225,14 @@
         $("#shopreport-termreport-print-table").click(function(){
             var startdate= $("#shopreport-termreport-tbody").attr("data-startdate");
             var enddate= $("#shopreport-termreport-tbody").attr("data-enddate");
-            var groupid = $("#termreport-search-devgroup").val();
+            var shopid = $("#termreport-search-shopid").val();
+            var ruleid = $("#termreport-search-ruleid").val();
 
             var opercode = $("#shopreport-termreport-tbody").attr("data-opercode");
-            var url = '/termreport/print/printtermreport?startdate=' + startdate + '&enddate=' + enddate +'&groupid=' + groupid+  '&opercode=' + opercode;
+            var url = '/termreport/print/printtermreport?startdate=' + startdate + '&enddate=' + enddate +'&shopid='+shopid+'&ruleid='+ruleid+  '&opercode=' + opercode;
 
             LODOP = getLodop();
-            LODOP.PRINT_INIT("客户类别消费报表");
+            LODOP.PRINT_INIT("终端消费报表");
             LODOP.SET_PRINT_PAGESIZE(2, 0, 0,"A4");
             LODOP.ADD_PRINT_URL(30, 20, "95%", "90%", encodeURI(url));
             LODOP.ADD_PRINT_HTM("95%", "48%", 150, 50, "<font style='font-size:12px'><span tdata='pageNO'>##</span>/<span tdata='pageCount'>&nbsp;&nbsp;##</span></font>");
diff --git a/src/main/resources/templates/restaurant/termreport/print/printcusttypereport.html b/src/main/resources/templates/restaurant/termreport/print/printcusttypereport.html
deleted file mode 100644
index db3c0b2..0000000
--- a/src/main/resources/templates/restaurant/termreport/print/printcusttypereport.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE html>
-<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
-<head>
-    <meta charset="UTF-8">
-    <title>人员类别消费表</title>
-
-    <link rel="stylesheet" th:href="@{/static/libs/layui/css/layui.css}"/>
-    <link rel="stylesheet" th:href="@{/static/custom/css/custom.css}"/>
-</head>
-<body>
-<div class="layui-card">
-    <div class="layui-card-header" style="text-align: center;">
-        <h1>人员类别消费表</h1>
-    </div>
-    <div class="layui-card-body">
-        <div class="layui-form toolbar">
-            <div style="float: left;padding-left: 3px;" th:text="${'区间:'+period}"></div>
-            <div style="float: right;" th:text="'单位:元'"></div>
-        </div>
-        <table class="layui-table sw-table sw-print">
-            <thead>
-            <tr>
-                <th rowspan="3" style="text-align: center;min-width: 60px;">序号<br/> <br/> </th>
-                <th rowspan="3" style="text-align: center;min-width: 160px;">食堂<br/> <br/> </th>
-                <th colspan="6" style="text-align: center;">含餐补消费支付</th>
-                <th colspan="6" style="text-align: center;">无餐补消费支付</th>
-                <th  rowspan="3" style="text-align: center;min-width: 60px;">合计<br/>消费<br/>金额</th>
-                <th  rowspan="3" style="text-align: center;min-width: 60px;">合计<br/>消费<br/>次数</th>
-            </tr>
-            <tr>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>份数</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>份数</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>金额</th>
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>份数</th>
-              <!--  <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">早餐<br/>份数</th>
-             <!--   <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">午餐<br/>份数</th>
-              <!--  <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>金额</th>-->
-                <th rowspan="2" style="text-align: center;min-width: 60px;">晚餐<br/>份数</th>
-
-            </tr>
-            </thead>
-            <tbody>
-            <tr th:if="${null==showlist || showlist.size()==0}">
-                <td colspan="16">无数据</td>
-            </tr>
-            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}" >
-
-                <tr>
-                    <td style="font-weight: bold;" th:text="${data.rownum}"></td>
-                    <td style="font-weight: bold;" th:text="${data.groupname}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.ibtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.ibtotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.iltotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.iltotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.idtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.idtotalcnt}"></td>
-                  <!--  <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.obtotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.obtotalcnt}"></td>
-                 <!--   <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.oltotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.oltotalcnt}"></td>
-                  <!--  <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.odtotalamt,1,2)}"></td>-->
-                    <td style="font-weight: bold;" th:text="${data.odtotalcnt}"></td>
-                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.ibtotalamt+data.iltotalamt+data.idtotalamt,1,2)}"></td>
-                    <td style="font-weight: bold;" th:text="${data.ibtotalcnt+data.iltotalcnt+data.idtotalcnt+data.obtotalcnt+data.oltotalcnt+data.odtotalcnt}"></td>
-
-                </tr>
-            </div>
-            </tbody>
-        </table>
-        <div class="layui-form toolbar">
-            <div style="float: left;padding-left: 3px;" th:text="${'制表人:'+opername+' &nbsp;&nbsp; '+ printdatetime}"></div>
-        </div>
-    </div>
-    <div class="layui-card-body" style="margin-top: 25px;">
-        <table class="sw-print-sign">
-            <tr>
-                <td width="50%">大理州公安局警务保障处审核盖章:</td>
-                <td width="50%">苍山饭店审核盖章:</td>
-            </tr>
-            <tr>
-                <td>经办人:</td>
-                <td>审核人:</td>
-            </tr>
-            <tr>
-                <td>审核人:</td>
-
-            </tr>
-            <tr>
-                <td colspan="2">&nbsp;</td>
-            </tr>
-            <tr>
-                <td colspan="2">&nbsp;</td>
-            </tr>
-            <!--            <tr>-->
-            <!--                <td>市民卡公司审核盖章:</td>-->
-            <!--                <td>建桥园审核盖章:</td>-->
-            <!--            </tr>-->
-            <!--            <tr>-->
-            <!--                <td>审核人:</td>-->
-            <!--                <td>审核人:</td>-->
-            <!--            </tr>-->
-        </table>
-    </div>
-</div>
-</body>
-</html>
\ No newline at end of file
diff --git a/src/main/resources/templates/restaurant/termreport/print/report.html b/src/main/resources/templates/restaurant/termreport/print/report.html
new file mode 100644
index 0000000..7184207
--- /dev/null
+++ b/src/main/resources/templates/restaurant/termreport/print/report.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
+<head>
+    <meta charset="UTF-8">
+    <title>终端消费报表</title>
+
+    <link rel="stylesheet" th:href="@{/static/libs/layui/css/layui.css}"/>
+    <link rel="stylesheet" th:href="@{/static/custom/css/custom.css}"/>
+</head>
+<body>
+<div class="layui-card">
+    <div class="layui-card-header" style="text-align: center;">
+        <h1>终端消费报表</h1>
+    </div>
+    <div class="layui-card-body">
+        <div class="layui-form toolbar">
+            <div style="float: left;padding-left: 3px;" th:text="${'区间:'+period}"></div>
+            <div style="float: right;" th:text="'单位:元'"></div>
+        </div>
+        <table class="layui-table sw-table sw-print">
+            <thead>
+            <tr>
+                <th rowspan="4" style="text-align: center;min-width: 60px;">终端编号</th>
+                <th colspan="8" style="text-align: center;min-width: 100px;">非折扣交易</th>
+                <th colspan="9" style="text-align: center;">折扣交易</th>
+                <th rowspan="4" style="text-align: center;">交易笔数<br/>合计</th>
+                <th rowspan="4" style="text-align: center;">交易金额<br/>合计</th>
+            </tr>
+            <tr>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">非折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">早餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">午餐累计<br/>交易金额</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易笔数</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">晚餐累计<br/>交易金额</th>
+                <th colspan="2" style="text-align: center;min-width: 60px;">折扣交易小计</th>
+                <th rowspan="3" style="text-align: center;min-width: 60px;">餐补金额</th>
+            </tr>
+            <tr>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易笔数<br/>小计</th>
+                <th style="text-align: center;min-width: 60px;">交易金额<br/>小计</th>
+            </tr>
+            </thead>
+            <tbody>
+            <tr th:if="${null==showlist || showlist.size()==0}">
+                <td colspan="23">无数据</td>
+            </tr>
+            <div th:remove="tag" th:if="${null!=showlist && showlist.size()>0}" th:each="data:${showlist}">
+                <tr>
+                    <td style="font-weight: bold;" th:text="${data.termid}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_normalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_normalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totnormalcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totnormalamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.b_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.b_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.l_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.l_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.d_discountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.d_discountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totdiscountcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totdiscountamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totfeeamt,1,2)}"></td>
+                    <td style="font-weight: bold;" th:text="${data.totcnt}"></td>
+                    <td style="font-weight: bold;" th:text="${#numbers.formatDecimal(data.totamt,1,2)}"></td>
+                </tr>
+            </div>
+            </tbody>
+        </table>
+        <div class="layui-form toolbar">
+            <div style="float: left;padding-left: 3px;"
+                 th:text="${'制表人:'+opername+' &nbsp;&nbsp; '+ printdatetime}"></div>
+        </div>
+    </div>
+    <div class="layui-card-body" style="margin-top: 25px;">
+        <table class="sw-print-sign">
+            <tr>
+                <td width="50%">大理州公安局警务保障处审核盖章:</td>
+                <td width="50%">苍山饭店审核盖章:</td>
+            </tr>
+            <tr>
+                <td>经办人:</td>
+                <td>审核人:</td>
+            </tr>
+            <tr>
+                <td>审核人:</td>
+
+            </tr>
+        </table>
+    </div>
+</div>
+</body>
+</html>
\ No newline at end of file