统计任务
diff --git a/config/application-devel-pg-xkx.properties b/config/application-devel-pg-xkx.properties
index 2b52a50..09f071c 100644
--- a/config/application-devel-pg-xkx.properties
+++ b/config/application-devel-pg-xkx.properties
@@ -31,6 +31,7 @@
 payapi.logintime=0 0/20 * * * ?
 #restaurant.chkdtltask.cron=0 0/3 * * * ?
 restaurant.chkdtltask.cron=-
+restaurant.statement.cron=-
 
 # payapi setting
 payapi.url=http://localhost:8080/payapi
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/bean/DtlStatBean.java b/src/main/java/com/supwisdom/dlpay/restaurant/bean/DtlStatBean.java
new file mode 100644
index 0000000..c341ea0
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/bean/DtlStatBean.java
@@ -0,0 +1,25 @@
+package com.supwisdom.dlpay.restaurant.bean;
+
+public interface DtlStatBean {
+  String getAccdate();
+
+  String getDeptcode();
+
+  Integer getCusttype();
+
+  Integer getGroupid();
+
+  Integer getTermid();
+
+  String getMealtype();
+
+  String getPaytype();
+
+  Integer getTotalcnt();
+
+  Double getTotalamt();
+
+  Integer getFeecnt();
+
+  Double getFeeamt();
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeptDao.java b/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeptDao.java
new file mode 100644
index 0000000..fdcb31d
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeptDao.java
@@ -0,0 +1,15 @@
+package com.supwisdom.dlpay.restaurant.dao;
+
+import com.supwisdom.dlpay.restaurant.domain.TDept;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface DeptDao extends JpaRepository<TDept, String> {
+
+  @Query("from TDept t where t.status='normal' ")
+  List<TDept> findNormalDept();
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeviceDao.java b/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeviceDao.java
index ae81ff4..067df28 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeviceDao.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/dao/DeviceDao.java
@@ -37,5 +37,8 @@
 
     TDevice findByDevphyid(String devphyid);
 
+    @Query("from TDevice where state=1 and checkstatus='normal' ")
+    List<TDevice> findNormalDevices();
+
 
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/dao/RptMealsDtlDao.java b/src/main/java/com/supwisdom/dlpay/restaurant/dao/RptMealsDtlDao.java
new file mode 100644
index 0000000..558c98f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/dao/RptMealsDtlDao.java
@@ -0,0 +1,10 @@
+package com.supwisdom.dlpay.restaurant.dao;
+
+import com.supwisdom.dlpay.restaurant.domain.TRptMealsDtl;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface RptMealsDtlDao extends JpaRepository<TRptMealsDtl, String> {
+  void deleteAllByCheckdate(String accdate);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/dao/TransDtlDao.java b/src/main/java/com/supwisdom/dlpay/restaurant/dao/TransDtlDao.java
index ee2b0e8..1c5f920 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/dao/TransDtlDao.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/dao/TransDtlDao.java
@@ -2,6 +2,7 @@
 
 
 import com.supwisdom.dlpay.framework.data.CountAmountBean;
+import com.supwisdom.dlpay.restaurant.bean.DtlStatBean;
 import com.supwisdom.dlpay.restaurant.bean.ManageFeeAmtBean;
 import com.supwisdom.dlpay.restaurant.bean.SalesAmtBean;
 import com.supwisdom.dlpay.restaurant.domain.TTransDtl;
@@ -61,4 +62,15 @@
 
     @Query("select count(t.billno) as totalcnt,sum(t.amount) as totalamt from TTransDtl t where t.status='success' and t.accdate=?1 ")
     CountAmountBean getLocalTransdtlSumInfo(String accdate);
+
+    @Query(value = "select t.accdate,cust.deptcode,cust.custtype,dev.devgroupid as groupid,t.termid,t.mealtype,t.core_sourcetype as paytype, " +
+        "sum(case when t.revflag=1 then 0 when t.transtype='revert' then 0 else 1 end) as totalcnt,sum(amount) as totalamt, " +
+        "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 feecnt, " +
+        "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 feeamt " +
+        "from tb_transdtl t  " +
+        "left join tb_customer cust on t.custid=cust.custid " +
+        "left join tb_device dev on t.termid=dev.id " +
+        "where t.status='success' and t.accdate=?1 " +
+        "group by t.accdate,cust.deptcode,cust.custtype,dev.devgroupid,t.termid,t.mealtype,t.core_sourcetype ", nativeQuery = true)
+    List<DtlStatBean> getTransdtlStatinfo(String accdate);
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCheckDetail.java b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCheckDetail.java
index 33c9e78..c5400a1 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCheckDetail.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCheckDetail.java
@@ -13,7 +13,7 @@
   @Id
   @GenericGenerator(name = "ckidGenerator", strategy = "uuid")
   @GeneratedValue(generator = "ckidGenerator")
-  @Column(name = "ID", nullable = false, length = 32)
+  @Column(name = "ID", unique = true, nullable = false, length = 32)
   private String id;
 
   @Column(name = "ACCDATE", nullable = false, length = 8)
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCustomer.java b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCustomer.java
index 5a107d4..276225b 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCustomer.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TCustomer.java
@@ -22,6 +22,8 @@
     private String status;
     private String checkstatus;
 
+    private String deptcode;
+
     @Id
     @GenericGenerator(name = "idGenerator", strategy = "uuid")
     @GeneratedValue(generator = "idGenerator")
@@ -129,4 +131,13 @@
     public void setCheckstatus(String checkstatus) {
         this.checkstatus = checkstatus;
     }
+
+    @Column(name = "DEPTCODE", length = 32)
+    public String getDeptcode() {
+        return deptcode;
+    }
+
+    public void setDeptcode(String deptcode) {
+        this.deptcode = deptcode;
+    }
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TDept.java b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TDept.java
new file mode 100644
index 0000000..b901fdc
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TDept.java
@@ -0,0 +1,88 @@
+package com.supwisdom.dlpay.restaurant.domain;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "TB_DEPT",
+    indexes = {@Index(name = "UK_DEPT_DEPTNO", unique = true, columnList = "DEPTNO")})
+public class TDept {
+  @Id
+  @SequenceGenerator(name = "pk_dept_deptcode", sequenceName = "SEQ_DEPTCODE", allocationSize = 1, initialValue = 10)
+  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pk_dept_deptcode")
+  @Column(name="DEPTCODE", nullable = false, length = 32)
+  private String deptcode; //ID
+
+  @Column(name="DEPTNO", nullable = false, length = 20)
+  private String deptno;  //部门编号,可能会要修改,不能为主键,唯一索引
+
+  @Column(name="DEPTNAME", precision = 600)
+  private String deptname; //部门名称
+
+  @Column(name="FDEPTCODE", nullable = false, length = 32)
+  private String fdeptcode; //上级部门
+
+  @Column(name="ENAME", precision = 600)
+  private String ename; //部门英文名称
+
+  @Column(name="STATUS", nullable = false, precision = 600)
+  private String status; //normal-正常;closed-删除
+
+  @Column(name="LASTSAVED", length = 20)
+  private String lastsaved; //最后更新时间
+
+  public String getDeptcode() {
+    return deptcode;
+  }
+
+  public void setDeptcode(String deptcode) {
+    this.deptcode = deptcode;
+  }
+
+  public String getDeptno() {
+    return deptno;
+  }
+
+  public void setDeptno(String deptno) {
+    this.deptno = deptno;
+  }
+
+  public String getDeptname() {
+    return deptname;
+  }
+
+  public void setDeptname(String deptname) {
+    this.deptname = deptname;
+  }
+
+  public String getFdeptcode() {
+    return fdeptcode;
+  }
+
+  public void setFdeptcode(String fdeptcode) {
+    this.fdeptcode = fdeptcode;
+  }
+
+  public String getEname() {
+    return ename;
+  }
+
+  public void setEname(String ename) {
+    this.ename = ename;
+  }
+
+  public String getStatus() {
+    return status;
+  }
+
+  public void setStatus(String status) {
+    this.status = status;
+  }
+
+  public String getLastsaved() {
+    return lastsaved;
+  }
+
+  public void setLastsaved(String lastsaved) {
+    this.lastsaved = lastsaved;
+  }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TRptMealsDtl.java b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TRptMealsDtl.java
new file mode 100644
index 0000000..7496b1d
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TRptMealsDtl.java
@@ -0,0 +1,165 @@
+package com.supwisdom.dlpay.restaurant.domain;

+

+

+import org.hibernate.annotations.GenericGenerator;

+

+import javax.persistence.*;

+

+@Entity

+@Table(name = "TB_RPT_MEALSDTL",

+    indexes = {@Index(name = "UK_RPT_MEALSDTL", unique = true, columnList = "checkdate,deptcode,custtype,devgroupid,deviceid,mealtype,paytype")})

+public class TRptMealsDtl {

+

+  //日期  部门  人员类别  设备组(商户)  设备  餐次  支付方式  总次数 总金额  补贴次数 补贴金额

+  @Id

+  @GenericGenerator(name = "midGenerator", strategy = "uuid")

+  @GeneratedValue(generator = "midGenerator")

+  @Column(name = "ID", unique = true, nullable = false, length = 32)

+  private String id;

+

+  @Column(name = "CHECKDATE", nullable = false, length = 8)

+  private String checkdate; //日期

+

+  @Column(name = "DEPTCODE", nullable = false, length = 32)

+  private String deptcode; //部门

+

+  @Column(name = "CUSTTYPE", nullable = false, precision = 9)

+  private Integer custtype; //人员类别

+

+  @Column(name = "DEVGROUPID", nullable = false, precision = 9)

+  private Integer devgroupid; //设备组(商户)

+

+  @Column(name = "DEVICEID", nullable = false, length = 9)

+  private Integer deviceid; //设备

+

+  @Column(name = "MEALTYPE", nullable = false, length = 20)

+  private String mealtype; //餐次

+

+  @Column(name = "PAYTYPE", nullable = false, length = 32)

+  private String paytype; //支付方式

+

+  @Column(name = "TOTALCNT", precision = 9, scale = 0)

+  private Integer totalcnt;

+

+  @Column(name = "TOTALAMT", precision = 15, scale = 2)

+  private Double totalamt;

+

+  @Column(name = "FEECNT", precision = 9, scale = 0)

+  private Integer feecnt;

+

+  @Column(name = "FEEAMT", precision = 15, scale = 2)

+  private Double feeamt;

+

+  public TRptMealsDtl() {

+  }

+

+  public TRptMealsDtl(String checkdate, String deptcode, Integer custtype, Integer devgroupid, Integer deviceid, String mealtype, String paytype, Integer totalcnt, Double totalamt, Integer feecnt, Double feeamt) {

+    this.checkdate = checkdate;

+    this.deptcode = deptcode;

+    this.custtype = custtype;

+    this.devgroupid = devgroupid;

+    this.deviceid = deviceid;

+    this.mealtype = mealtype;

+    this.paytype = paytype;

+    this.totalcnt = totalcnt;

+    this.totalamt = totalamt;

+    this.feecnt = feecnt;

+    this.feeamt = feeamt;

+  }

+

+  public String getId() {

+    return id;

+  }

+

+  public void setId(String id) {

+    this.id = id;

+  }

+

+  public String getCheckdate() {

+    return checkdate;

+  }

+

+  public void setCheckdate(String checkdate) {

+    this.checkdate = checkdate;

+  }

+

+  public String getDeptcode() {

+    return deptcode;

+  }

+

+  public void setDeptcode(String deptcode) {

+    this.deptcode = deptcode;

+  }

+

+  public Integer getCusttype() {

+    return custtype;

+  }

+

+  public void setCusttype(Integer custtype) {

+    this.custtype = custtype;

+  }

+

+  public Integer getDevgroupid() {

+    return devgroupid;

+  }

+

+  public void setDevgroupid(Integer devgroupid) {

+    this.devgroupid = devgroupid;

+  }

+

+  public Integer getDeviceid() {

+    return deviceid;

+  }

+

+  public void setDeviceid(Integer deviceid) {

+    this.deviceid = deviceid;

+  }

+

+  public String getMealtype() {

+    return mealtype;

+  }

+

+  public void setMealtype(String mealtype) {

+    this.mealtype = mealtype;

+  }

+

+  public String getPaytype() {

+    return paytype;

+  }

+

+  public void setPaytype(String paytype) {

+    this.paytype = paytype;

+  }

+

+  public Integer getTotalcnt() {

+    return totalcnt;

+  }

+

+  public void setTotalcnt(Integer totalcnt) {

+    this.totalcnt = totalcnt;

+  }

+

+  public Double getTotalamt() {

+    return totalamt;

+  }

+

+  public void setTotalamt(Double totalamt) {

+    this.totalamt = totalamt;

+  }

+

+  public Integer getFeecnt() {

+    return feecnt;

+  }

+

+  public void setFeecnt(Integer feecnt) {

+    this.feecnt = feecnt;

+  }

+

+  public Double getFeeamt() {

+    return feeamt;

+  }

+

+  public void setFeeamt(Double feeamt) {

+    this.feeamt = feeamt;

+  }

+}
\ No newline at end of file
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/CheckTransdtlService.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/CheckTransdtlService.java
index a488d67..781a740 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/CheckTransdtlService.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/CheckTransdtlService.java
@@ -65,4 +65,19 @@
 
   @Transactional(rollbackFor = Exception.class)
   TCheckCtl doConfirmCheckFile(TCheckCtl ctl, TCheckFile checkFile);
+
+  @Transactional(rollbackFor = Exception.class, readOnly = true)
+  TCheckCtl getSystemCheckCtl();
+
+  @Transactional(rollbackFor = Exception.class)
+  String doGetStatementDate();
+
+  @Transactional(rollbackFor = Exception.class)
+  String doSwitchStatementDate(String statdate);
+
+  @Transactional(rollbackFor = Exception.class)
+  boolean doClearStatmentMealsDtl(String statdate);
+
+  @Transactional(rollbackFor = Exception.class)
+  boolean doStatmentMealsDtl(String statdate);
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CheckTransdtlServiceImpl.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CheckTransdtlServiceImpl.java
index 551fdcb..6f2eea3 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CheckTransdtlServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/CheckTransdtlServiceImpl.java
@@ -1,23 +1,20 @@
 package com.supwisdom.dlpay.restaurant.service.impl;
 
 import com.supwisdom.dlpay.api.bean.DownloadShopBillData;
+import com.supwisdom.dlpay.framework.dao.BusinessparaDao;
 import com.supwisdom.dlpay.framework.dao.ShopSettlementDao;
 import com.supwisdom.dlpay.framework.data.CountAmountBean;
 import com.supwisdom.dlpay.framework.data.ExistBean;
+import com.supwisdom.dlpay.framework.domain.TBusinesspara;
 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.framework.util.MoneyUtil;
 import com.supwisdom.dlpay.framework.util.StringUtil;
 import com.supwisdom.dlpay.framework.util.TradeDict;
-import com.supwisdom.dlpay.restaurant.dao.CheckCtlDao;
-import com.supwisdom.dlpay.restaurant.dao.CheckDetailDao;
-import com.supwisdom.dlpay.restaurant.dao.CheckFileDao;
-import com.supwisdom.dlpay.restaurant.dao.TransDtlDao;
-import com.supwisdom.dlpay.restaurant.domain.TCheckCtl;
-import com.supwisdom.dlpay.restaurant.domain.TCheckDetail;
-import com.supwisdom.dlpay.restaurant.domain.TCheckFile;
-import com.supwisdom.dlpay.restaurant.domain.TTransDtl;
+import com.supwisdom.dlpay.restaurant.bean.DtlStatBean;
+import com.supwisdom.dlpay.restaurant.dao.*;
+import com.supwisdom.dlpay.restaurant.domain.*;
 import com.supwisdom.dlpay.restaurant.service.CheckTransdtlService;
 import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
 import org.apache.commons.beanutils.BeanUtils;
@@ -48,7 +45,21 @@
   @Autowired
   private CheckDetailDao checkDetailDao;
   @Autowired
+  private BusinessparaDao businessparaDao;
+  @Autowired
   private SystemUtilService systemUtilService;
+  @Autowired
+  private RptMealsDtlDao rptMealsDtlDao;
+  @Autowired
+  private DeviceDao deviceDao;
+  @Autowired
+  private CustTypeDao custTypeDao;
+  @Autowired
+  private DeptDao deptDao;
+  @Autowired
+  private DeviceGroupDao deviceGroupDao;
+  @Autowired
+  private MealTypeDao mealTypeDao;
 
   private static final Logger logger = LoggerFactory.getLogger(CheckTransdtlServiceImpl.class);
 
@@ -183,7 +194,7 @@
   }
 
   @Override
-  public TCheckFile doUpdateCheckFile(TCheckFile checkFile){
+  public TCheckFile doUpdateCheckFile(TCheckFile checkFile) {
     return checkFileDao.save(checkFile);
   }
 
@@ -345,4 +356,107 @@
     return checkCtlDao.save(ctl);
   }
 
+  @Override
+  public TCheckCtl getSystemCheckCtl() {
+    return checkCtlDao.getById(RestaurantConstant.CHECK_TRANSDTL_CTLID);
+  }
+
+  @Override
+  public String doGetStatementDate() {
+    TBusinesspara businesspara = businessparaDao.findByParakeyForUpdate(RestaurantConstant.TRANSDTL_STATEMENT_LASTDATE);
+    if (null == businesspara) {
+      businesspara = new TBusinesspara();
+      businesspara.setParakey(RestaurantConstant.TRANSDTL_STATEMENT_LASTDATE);
+      businesspara.setParaval(getMinTransdate());
+      businessparaDao.save(businesspara);
+    }
+    return businesspara.getParaval();
+  }
+
+  @Override
+  public String doSwitchStatementDate(String statdate) {
+    TBusinesspara businesspara = businessparaDao.findByParakeyForUpdate(RestaurantConstant.TRANSDTL_STATEMENT_LASTDATE);
+    businesspara.setParaval(DateUtil.getNewDay(statdate, 1));
+    businessparaDao.save(businesspara);
+    return businesspara.getParaval();
+  }
+
+  @Override
+  public boolean doClearStatmentMealsDtl(String statdate) {
+    rptMealsDtlDao.deleteAllByCheckdate(statdate);
+    return true;
+  }
+
+  @Override
+  public boolean doStatmentMealsDtl(String statdate) {
+    List<DtlStatBean> list = transDtlDao.getTransdtlStatinfo(statdate);
+    List<TRptMealsDtl> data = new ArrayList<>(0);
+    if (!StringUtil.isEmpty(list)) {
+      for (DtlStatBean bean : list) {
+        TRptMealsDtl tmd = new TRptMealsDtl();
+        tmd.setCheckdate(bean.getAccdate());
+        tmd.setDeptcode(bean.getDeptcode() == null ? "unknow" : bean.getDeptcode());
+        tmd.setCusttype(bean.getCusttype() == null ? -1 : bean.getCusttype());
+        tmd.setDevgroupid(bean.getGroupid() == null ? -1 : bean.getGroupid());
+        tmd.setDeviceid(bean.getTermid() == null ? -1 : bean.getTermid());
+        tmd.setMealtype(bean.getMealtype() == null ? "unknow" : bean.getMealtype());
+        tmd.setPaytype(bean.getPaytype() == null ? "citizenCard" : bean.getPaytype());
+        tmd.setTotalcnt(bean.getTotalcnt());
+        tmd.setTotalamt(bean.getTotalamt());
+        tmd.setFeecnt(bean.getFeecnt());
+        tmd.setFeeamt(bean.getFeeamt());
+        data.add(tmd);
+      }
+    } else {
+      //当天无交易记录,插入一条全零记录
+      TRptMealsDtl tmd = new TRptMealsDtl();
+      tmd.setCheckdate(statdate);
+      tmd.setDeptcode(getDefaultDeptcode());
+      tmd.setCusttype(getDefaultCusttype());
+      tmd.setDevgroupid(getDefaultDevgroupid());
+      tmd.setDeviceid(getDefaultDeviceid());
+      tmd.setMealtype(getDefaultMealtype());
+      tmd.setPaytype("citizenCard");
+      tmd.setTotalcnt(0);
+      tmd.setTotalamt(0D);
+      tmd.setFeecnt(0);
+      tmd.setFeeamt(0D);
+      data.add(tmd);
+    }
+    rptMealsDtlDao.saveAll(data);
+    return true;
+  }
+
+  private String getDefaultDeptcode() {
+    List<TDept> list = deptDao.findNormalDept();
+    if (!StringUtil.isEmpty(list)) return list.get(0).getDeptcode();
+    return "unknow";
+  }
+
+  private Integer getDefaultCusttype() {
+    List<TCustType> list = custTypeDao.findAll();
+    if (!StringUtil.isEmpty(list)) return list.get(0).getCusttypeid();
+    return -1;
+  }
+
+  private Integer getDefaultDevgroupid() {
+    List<TDeviceGroup> list = deviceGroupDao.findAll();
+    if (!StringUtil.isEmpty(list)) return list.get(0).getDevgroupid();
+    return -1;
+  }
+
+  private Integer getDefaultDeviceid() {
+    List<TDevice> list = deviceDao.findNormalDevices();
+    if (!StringUtil.isEmpty(list)) return list.get(0).getId();
+    return -1;
+
+  }
+
+  private String getDefaultMealtype() {
+    List<TMealtype> list = mealTypeDao.findAllByOrderByEndtime();
+    if (!StringUtil.isEmpty(list)) return list.get(0).getMealtype();
+    return "unknow";
+  }
+
+
 }
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java b/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java
new file mode 100644
index 0000000..cb256eb
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/task/TransdtlStatementTask.java
@@ -0,0 +1,79 @@
+package com.supwisdom.dlpay.restaurant.task;
+
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.DateUtil;
+import com.supwisdom.dlpay.restaurant.domain.TCheckCtl;
+import com.supwisdom.dlpay.restaurant.service.CheckTransdtlService;
+import net.javacrumbs.shedlock.core.SchedulerLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 流水统计任务
+ */
+@Component
+@EnableScheduling
+public class TransdtlStatementTask {
+  @Autowired
+  private SystemUtilService systemUtilService;
+  @Autowired
+  private CheckTransdtlService checkTransdtlService;
+
+  private static final Logger logger = LoggerFactory.getLogger(TransdtlStatementTask.class);
+
+
+  @Scheduled(cron = "${restaurant.statement.cron}")
+  @SchedulerLock(name = "RestaurantStatementTask", lockAtMostForString = "PT10M")
+  public void doStatementTask() {
+    try {
+      long t1 = System.currentTimeMillis();
+      logger.info("=================== 【流水统计任务】开始: ===================");
+
+      TCheckCtl checkCtl = checkTransdtlService.getSystemCheckCtl();
+      if (null == checkCtl) {
+        logger.error("还未与核心平台对账!");
+        return;
+      }
+      String enddate = checkCtl.getCheckdate();
+      if (!checkCtl.getCheckOk()) enddate = DateUtil.getNewDay(checkCtl.getCheckdate(), -1); //已对账的日期
+      String startdate = checkTransdtlService.doGetStatementDate(); //上次统计的日期
+      if (DateUtil.compareDatetime(startdate, enddate, "yyyyMMdd") < 0) {
+        logger.info("对【" + startdate + " ~ " + enddate + "】的流水进行统计:");
+      }
+
+      String statdate = startdate;
+      while (DateUtil.compareDatetime(statdate, enddate, "yyyyMMdd") <= 0) {
+        try {
+          if (doStatementProcess(statdate)) {
+            statdate = checkTransdtlService.doSwitchStatementDate(statdate); //统计日期加1;
+          }
+        } catch (Exception e) {
+          e.printStackTrace();
+          break;
+        }
+      }
+
+      long t2 = System.currentTimeMillis();
+      logger.info("=================== 【流水统计任务】结束,耗时 " + (t2 - t1) + " ms ===================");
+    } catch (Exception e) {
+      logger.error("【流水统计任务】报错:" + e.getMessage());
+      e.printStackTrace();
+    }
+  }
+
+  public boolean doStatementProcess(String statdate) throws Exception {
+    logger.info("对【" + statdate + "】的流水进行统计:");
+
+    boolean result = false;
+    if (checkTransdtlService.doClearStatmentMealsDtl(statdate)) {
+      result = checkTransdtlService.doStatmentMealsDtl(statdate); //TB_RPT_MEALSDTL表数据统计
+    }
+
+    return result;
+  }
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/util/RestaurantConstant.java b/src/main/java/com/supwisdom/dlpay/restaurant/util/RestaurantConstant.java
index e9afa21..80933c7 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/util/RestaurantConstant.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/util/RestaurantConstant.java
@@ -75,5 +75,5 @@
     public static final String CHKDTL_RESOLVED_HANGUP="hangup"; //挂起
 
 
-
+    public static final String TRANSDTL_STATEMENT_LASTDATE = "transdtl.statement.lastdate"; //统计日期
 }
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f1cb684..a606a3a 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -33,4 +33,6 @@
 
 # 对账任务
 restaurant.chkdtltask.cron=27 3/10 * * * ?
+# 统计任务
+restaurant.statement.cron=0 7/10 * * * ?