| package com.dy.pipIrrTemp.statistics; | 
|   | 
| import com.dy.common.util.DateTime; | 
| import com.dy.pipIrrGlobal.daoSt.StClientAmountDayMapper; | 
| import com.dy.pipIrrGlobal.daoSt.StClientAmountMonthMapper; | 
| import com.dy.pipIrrGlobal.pojoSt.StClientAmountMonth; | 
| import com.dy.pipIrrGlobal.voSt.VoClientAmountStatistics; | 
| import com.dy.pipIrrTemp.util.StClientAmountConstant; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2024/12/30 09:52 | 
|  * @Description | 
|  */ | 
|   | 
| @Slf4j | 
| @Service | 
| public class StClientAmountMonthSv { | 
|   | 
|     protected StClientAmountDayMapper stClientAmountDayDao; | 
|   | 
|     protected StClientAmountMonthMapper stClientAmountMonthDao; | 
|   | 
|     @Autowired | 
|     private void setDao(StClientAmountDayMapper dao) { | 
|         this.stClientAmountDayDao = dao; | 
|     } | 
|   | 
|     @Autowired | 
|     private void setDao(StClientAmountMonthMapper dao) { | 
|         this.stClientAmountMonthDao = dao; | 
|     } | 
|   | 
|     /** | 
|      * 删除所有 | 
|      * @throws Exception | 
|      */ | 
|     public void deleteAllStClientAmountMonth() throws Exception { | 
|         stClientAmountMonthDao.deleteAll() ; | 
|     } | 
|   | 
|     /** | 
|      * 转存农户月取水量 | 
|      * | 
|      * @throws Exception | 
|      */ | 
|     public void statisticsClientAmountMonth() throws Exception { | 
|         //统计到昨天,今天的统计明日零晨定时任务统计 | 
|         Long curYm = Long.parseLong(DateTime.yyyy_MM().replaceAll("-", "")); | 
|         Long atMonth ; | 
|         for(int[] ym : StClientAmountConstant.yearMonthGrp) { | 
|             atMonth = Long.parseLong(ym[0] + "" + (ym[1] < 10?("0" + ym[1]):ym[1]) ) ; | 
|             if(atMonth <= curYm) { | 
|                 this.doSome(ym[0], ym[1]); | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     @Transactional | 
|     protected void doSome(Integer statisticsYear, Integer statisticsMonth){ | 
|         List<VoClientAmountStatistics> list = stClientAmountDayDao.statisticsByClient(statisticsYear, statisticsMonth) ; | 
|         if(list != null && list.size() > 0){ | 
|             List<StClientAmountMonth> listOfMonth = stClientAmountMonthDao.selectByYear(statisticsYear) ; | 
|             for(VoClientAmountStatistics vo : list){ | 
|                 StClientAmountMonth po = this.getDataOfClient(listOfMonth, vo.clientId) ; | 
|                 if(po == null){ | 
|                     po = new StClientAmountMonth() ; | 
|                     po.clientId = vo.clientId ; | 
|                     po.year = statisticsYear ; | 
|                 } | 
|                 this.setValue(statisticsMonth, vo, po); | 
|                 if(po.id == null) { | 
|                     stClientAmountMonthDao.insert(po); | 
|                 }else{ | 
|                     stClientAmountMonthDao.updateByPrimaryKeySelective(po) ; | 
|                 } | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     private StClientAmountMonth getDataOfClient(List<StClientAmountMonth> list, Long clientId){ | 
|         if(list != null && list.size() > 0){ | 
|             for(StClientAmountMonth vo : list){ | 
|                 if(vo.clientId.longValue() == clientId.longValue()){ | 
|                     //程序逻辑控制上,集合中只有一个对象 | 
|                     return vo ; | 
|                 } | 
|             } | 
|         } | 
|         return null ; | 
|     } | 
|   | 
|     private void setValue(Integer statisticsMonth, VoClientAmountStatistics vo, StClientAmountMonth po){ | 
|         switch (statisticsMonth) { | 
|             case 1: | 
|                 po.amount1 = vo.amount; | 
|                 po.money1 = vo.money; | 
|                 po.times1 = vo.times; | 
|                 break; | 
|             case 2: | 
|                 po.amount2 = vo.amount; | 
|                 po.money2 = vo.money; | 
|                 po.times2 = vo.times; | 
|                 break; | 
|             case 3: | 
|                 po.amount3 = vo.amount; | 
|                 po.money3 = vo.money; | 
|                 po.times3 = vo.times; | 
|                 break; | 
|             case 4: | 
|                 po.amount4 = vo.amount; | 
|                 po.money4 = vo.money; | 
|                 po.times4 = vo.times; | 
|                 break; | 
|             case 5: | 
|                 po.amount5 = vo.amount; | 
|                 po.money5 = vo.money; | 
|                 po.times5 = vo.times; | 
|                 break; | 
|             case 6: | 
|                 po.amount6 = vo.amount; | 
|                 po.money6 = vo.money; | 
|                 po.times6 = vo.times; | 
|                 break; | 
|             case 7: | 
|                 po.amount7 = vo.amount; | 
|                 po.money7 = vo.money; | 
|                 po.times7 = vo.times; | 
|                 break; | 
|             case 8: | 
|                 po.amount8 = vo.amount; | 
|                 po.money8 = vo.money; | 
|                 po.times8 = vo.times; | 
|                 break; | 
|             case 9: | 
|                 po.amount9 = vo.amount; | 
|                 po.money9 = vo.money; | 
|                 po.times9 = vo.times; | 
|                 break; | 
|             case 10: | 
|                 po.amount10 = vo.amount; | 
|                 po.money10 = vo.money; | 
|                 po.times10 = vo.times; | 
|                 break; | 
|             case 11: | 
|                 po.amount11 = vo.amount; | 
|                 po.money11 = vo.money; | 
|                 po.times11 = vo.times; | 
|                 break; | 
|             case 12: | 
|                 po.amount12 = vo.amount; | 
|                 po.money12 = vo.money; | 
|                 po.times12 = vo.times; | 
|                 break; | 
|         } | 
|     } | 
|   | 
| } |