| New file | 
|  |  |  | 
|---|
|  |  |  | 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.daoSt.StClientAmountYearMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSt.StClientAmountYear; | 
|---|
|  |  |  | 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 StClientAmountYearSv { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected StClientAmountDayMapper stClientAmountDayDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected StClientAmountMonthMapper stClientAmountMonthDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | protected StClientAmountYearMapper stClientAmountYearDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setDao(StClientAmountDayMapper dao) { | 
|---|
|  |  |  | this.stClientAmountDayDao = dao; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setDao(StClientAmountMonthMapper dao) { | 
|---|
|  |  |  | this.stClientAmountMonthDao = dao; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setDao(StClientAmountYearMapper dao) { | 
|---|
|  |  |  | this.stClientAmountYearDao = dao; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除所有 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void deleteAllStClientAmountYear() throws Exception { | 
|---|
|  |  |  | stClientAmountYearDao.deleteAll() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 转存农户年取水量 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void statisticsClientAmountYear() throws Exception { | 
|---|
|  |  |  | //统计到昨天,今天的统计明日零晨定时任务统计 | 
|---|
|  |  |  | Long curY = Long.parseLong(DateTime.yyyy().replaceAll("-", "")); | 
|---|
|  |  |  | Long atYear ; | 
|---|
|  |  |  | for(int[] ym : StClientAmountConstant.yearMonthGrp) { | 
|---|
|  |  |  | atYear = ym[0] + 0L ; | 
|---|
|  |  |  | if(atYear <= curY) { | 
|---|
|  |  |  | this.doSome(ym[0]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | protected void doSome(Integer statisticsYear){ | 
|---|
|  |  |  | List<VoClientAmountStatistics> list = stClientAmountMonthDao.statisticsByClient(statisticsYear) ; | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | List<StClientAmountYear> listOfYear = stClientAmountYearDao.selectByYear(statisticsYear) ; | 
|---|
|  |  |  | for(VoClientAmountStatistics vo : list){ | 
|---|
|  |  |  | StClientAmountYear po = this.getDataOfClient(listOfYear, vo.clientId) ; | 
|---|
|  |  |  | if(po == null){ | 
|---|
|  |  |  | po = new StClientAmountYear() ; | 
|---|
|  |  |  | po.clientId = vo.clientId ; | 
|---|
|  |  |  | po.year = statisticsYear ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.setValue(vo, po); | 
|---|
|  |  |  | if(po.id == null) { | 
|---|
|  |  |  | stClientAmountYearDao.insert(po); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | stClientAmountYearDao.updateByPrimaryKeySelective(po) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private StClientAmountYear getDataOfClient(List<StClientAmountYear> list, Long clientId){ | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | for(StClientAmountYear vo : list){ | 
|---|
|  |  |  | if(vo.clientId.longValue() == clientId.longValue()){ | 
|---|
|  |  |  | //程序逻辑控制上,集合中只有一个对象 | 
|---|
|  |  |  | return vo ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void setValue(VoClientAmountStatistics vo, StClientAmountYear po){ | 
|---|
|  |  |  | po.amount = vo.amount; | 
|---|
|  |  |  | po.money = vo.money; | 
|---|
|  |  |  | po.times = vo.times; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|