yj
2020-03-13 2f2860b50f24e5e3598d223db03d43df61d95c97
fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractAuditRecordServiceImpl.java
@@ -1,24 +1,34 @@
package com.yeshi.fanli.service.impl.money.extract;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.yeshi.utils.DateUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.ExtractAuditRecordMapper;
import com.yeshi.fanli.dao.user.count.CountUserInfoDao;
import com.yeshi.fanli.dto.ChartTDO;
import com.yeshi.fanli.dto.money.ExtractOrderStatisticDTO;
import com.yeshi.fanli.entity.admin.count.CountUserInfo;
import com.yeshi.fanli.entity.admin.count.CountUserInfo.CountUserEnum;
import com.yeshi.fanli.entity.bus.user.ExtractAuditRecord;
import com.yeshi.fanli.service.inter.money.extract.ExtractAuditRecordService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
@Service
public class ExtractAuditRecordServiceImpl implements ExtractAuditRecordService {
   @Resource
   private ExtractAuditRecordMapper extractAuditRecordMapper;
   @Resource
   private CountUserInfoDao countUserInfoDao;
   @Override
   public List<ExtractAuditRecord> getList(int pageIndex, int pageSize, String key, String startTime, String endTime) {
@@ -106,21 +116,148 @@
   }
   @Override
   public List<Map<String, Object>> countAuditTotal(Integer state, Integer type, String years, String startTime,
         String endTime) throws Exception {
      return extractAuditRecordMapper.countAuditTotal(state, type, years, startTime, endTime);
   public List<CountUserInfo> getAuditCount(Date startTime, Date endTime, Integer state) throws Exception {
      // 重新查询统计今日以及空缺
      initAuditCount();
      return countUserInfoDao.query(CountUserEnum.extractAuditNumber, startTime, endTime, state);
   }
   // 初始化统计
   @Override
   public List<Map<String, Object>> countExtractApplyMoney(Integer state, Integer type, String years, String startTime,
         String endTime) throws Exception {
      return extractAuditRecordMapper.countExtractMoney(state, type, years, startTime, endTime);
   public void initAuditCount() {
      try {
         CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractAuditNumber);
         Date lastDay = null;
         if (lastRecord != null && lastRecord.getDay() != null) {
            lastDay = lastRecord.getDay();
         }
         if (lastDay == null) {
            lastDay = TimeUtil.parse("2017-07-19");
         }
         Date today = new Date();
         int betweenDays = DateUtil.daysBetween2(lastDay, today);
         if (betweenDays > 0) {
            for (int i = 0; i <= betweenDays; i++ ) {
               addRecordAuditCount(DateUtil.plusDay(i, lastDay));
            }
         }
         // 重新统计今日
         addRecordAuditCount(TimeUtil.getGernalTime(today.getTime()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   private void addRecordAuditCount(String preDay) throws Exception{
      for (int i = 1; i < 3; i++) {
         int count = extractAuditRecordMapper.countAuditTotal(i, preDay);
         CountUserInfo record = new CountUserInfo();
         record.setState(i);
         record.setNum(count);
         record.setId(StringUtil.Md5(preDay + CountUserEnum.extractAuditNumber.name())+ "-" + i);
         record.setDay(TimeUtil.parse(preDay));
         record.setType(CountUserEnum.extractAuditNumber);
         countUserInfoDao.save(record);
      }
   }
   @Override
   public List<CountUserInfo> getApplyMoney(Date startTime, Date endTime) throws Exception {
      // 重新查询统计今日以及空缺
      initApplyMoneyCount();
      return countUserInfoDao.query(CountUserEnum.extractApplyMoney, startTime, endTime);
   }
   // 初始化统计
   @Override
   public void initApplyMoneyCount() {
      try {
         CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractApplyMoney);
         Date lastDay = null;
         if (lastRecord != null && lastRecord.getDay() != null) {
            lastDay = lastRecord.getDay();
         }
         if (lastDay == null) {
            lastDay = TimeUtil.parse("2017-07-19");
         }
         Date today = new Date();
         int betweenDays = DateUtil.daysBetween2(lastDay, today);
         if (betweenDays > 0) {
            for (int i = 0; i <= betweenDays; i++ ) {
               addRecordApplyMoneyCount(DateUtil.plusDay(i, lastDay));
            }
         }
         // 重新统计今日
         addRecordApplyMoneyCount(TimeUtil.getGernalTime(today.getTime()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   private void addRecordApplyMoneyCount(String preDay) throws Exception{
      BigDecimal money = extractAuditRecordMapper.countApplyExtractMoney(preDay);
      if (money == null)
         money = new BigDecimal(0);
      CountUserInfo record = new CountUserInfo();
      record.setMoney(money);
      record.setId(StringUtil.Md5(preDay + CountUserEnum.extractApplyMoney.name()));
      record.setDay(TimeUtil.parse(preDay));
      record.setType(CountUserEnum.extractApplyMoney);
      countUserInfoDao.save(record);
   }
   @Override
   public List<Map<String, Object>> countExtractApplyNumber(Integer state, Integer type, String years,
         String startTime, String endTime) throws Exception {
      return extractAuditRecordMapper.countExtractApplyNumber(state, type, years, startTime, endTime);
   public List<CountUserInfo> geApplyNumber(Date startTime, Date endTime) throws Exception {
      // 重新查询统计今日以及空缺
      initApplyNumberCount();
      return countUserInfoDao.query(CountUserEnum.extractApplyNumber, startTime, endTime);
   }
   // 初始化统计
   @Override
   public void initApplyNumberCount() {
      try {
         CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractApplyNumber);
         Date lastDay = null;
         if (lastRecord != null && lastRecord.getDay() != null) {
            lastDay = lastRecord.getDay();
         }
         if (lastDay == null) {
            lastDay = TimeUtil.parse("2017-07-19");
         }
         Date today = new Date();
         int betweenDays = DateUtil.daysBetween2(lastDay, today);
         if (betweenDays > 0) {
            for (int i = 0; i <= betweenDays; i++ ) {
               addRecordCount(DateUtil.plusDay(i, lastDay));
            }
         }
         // 重新统计今日
         addRecordCount(TimeUtil.getGernalTime(today.getTime()));
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   private void addRecordCount(String preDay) throws Exception{
      int count = extractAuditRecordMapper.countApplyNumberByDay(preDay);
      CountUserInfo record = new CountUserInfo();
      record.setNum(count);
      record.setId(StringUtil.Md5(preDay + CountUserEnum.extractApplyNumber.name()));
      record.setDay(TimeUtil.parse(preDay));
      record.setType(CountUserEnum.extractApplyNumber);
      countUserInfoDao.save(record);
   }
}