|  |  |  | 
|---|
|  |  |  | import com.dy.common.util.DateTime; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoTmp.ChangeMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoRm.RmIntakeAmountDay; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSt.VoIntake; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voTmp.VoRmIntakeAmountDay; | 
|---|
|  |  |  | 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.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private ChangeMapper dao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final int IntakeAmountDayFlag = 800 ;//2024-12-14统计元谋数据库实时数据,发现大于800的正确的数据不存在,而小于800的基本为正确数据 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setDao(ChangeMapper dao){ | 
|---|
|  |  |  | this.dao = dao; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //////////////////////////////////////// | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // 有关日统计 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | /////////////////////////////////////// | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 调整取水口日取水量统计 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void chIntakeAmountDay() throws Exception{ | 
|---|
|  |  |  | RmIntakeAmountDay lastAd = null ; | 
|---|
|  |  |  | List<VoIntake> list = dao.selectAllPrIntakes() ; | 
|---|
|  |  |  | 
|---|
|  |  |  | for(RmIntakeAmountDay ad : adList){ | 
|---|
|  |  |  | if(lastAd == null){ | 
|---|
|  |  |  | lastAd = ad ; | 
|---|
|  |  |  | if(lastAd.amount != null && lastAd.amount > IntakeAmountDayFlag){ | 
|---|
|  |  |  | if(lastAd.amount != null && lastAd.amount > StClientAmountConstant.IntakeAmountDayFlag){ | 
|---|
|  |  |  | this.doUpdateOneIntakeAmountDay(lastAd.id, 0.0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(ad.amount != null && ad.amount > IntakeAmountDayFlag){ | 
|---|
|  |  |  | if(ad.amount != null && ad.amount > StClientAmountConstant.IntakeAmountDayFlag){ | 
|---|
|  |  |  | if(ad.totalAmountLast != null && lastAd.totalAmountLast != null){ | 
|---|
|  |  |  | //重新计算日取水量 | 
|---|
|  |  |  | ad.amount = ad.totalAmountLast - lastAd.totalAmountLast; | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | ad.amount = 0.0 ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(ad.amount > IntakeAmountDayFlag){ | 
|---|
|  |  |  | if(ad.amount > StClientAmountConstant.IntakeAmountDayFlag){ | 
|---|
|  |  |  | //计算日取水量后,仍大于IntakeAmountDayFlag | 
|---|
|  |  |  | log.info("出现调整后的日取水量仍大于" | 
|---|
|  |  |  | + IntakeAmountDayFlag | 
|---|
|  |  |  | + StClientAmountConstant.IntakeAmountDayFlag | 
|---|
|  |  |  | + "的情况,数据id=" + ad.id | 
|---|
|  |  |  | + ",取水口id=" + ad.intakeId | 
|---|
|  |  |  | + ",日期=" + ad.dt | 
|---|
|  |  |  | 
|---|
|  |  |  | if(DateTime.daysBetweenyyyy_MM_dd(ad.dt, lastAd.dt) == 1){ | 
|---|
|  |  |  | //只相差一天 | 
|---|
|  |  |  | log.info("出现相差一天但日取水量大于" | 
|---|
|  |  |  | + IntakeAmountDayFlag | 
|---|
|  |  |  | + StClientAmountConstant.IntakeAmountDayFlag | 
|---|
|  |  |  | + "的情况,数据id=" + ad.id | 
|---|
|  |  |  | + ",取水口id=" + ad.intakeId | 
|---|
|  |  |  | + ",日期=" + ad.dt | 
|---|
|  |  |  | 
|---|
|  |  |  | //已经修改后的数值仍然大于IntakeAmountDayFlag,说明是大日未上报数据而积累下来,可以大于IntakeAmountDayFlag | 
|---|
|  |  |  | //ad.amount = ad.amount ; | 
|---|
|  |  |  | log.info("出现相差多天日取水量大于" | 
|---|
|  |  |  | + IntakeAmountDayFlag | 
|---|
|  |  |  | + StClientAmountConstant.IntakeAmountDayFlag | 
|---|
|  |  |  | + "的情况,数据id=" + ad.id | 
|---|
|  |  |  | + ",取水口id=" + ad.intakeId | 
|---|
|  |  |  | + ",日期=" + ad.dt | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.info("出现相差多天日取水量大于" | 
|---|
|  |  |  | + IntakeAmountDayFlag | 
|---|
|  |  |  | + StClientAmountConstant.IntakeAmountDayFlag | 
|---|
|  |  |  | + "并且属性totalAmountLast为null的情况,数据id=" + ad.id | 
|---|
|  |  |  | + ",取水口id=" + ad.intakeId | 
|---|
|  |  |  | + ",日期=" + ad.dt | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | int doUpdateOneIntakeAmountDay(Long id, Double amount){ | 
|---|
|  |  |  | protected int doUpdateOneIntakeAmountDay(Long id, Double amount){ | 
|---|
|  |  |  | return dao.updateOneIntakeAmountDay(id, amount); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除所有取水口日取水量统计 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //@Transactional | 
|---|
|  |  |  | //public void deleteAllIntakeAmountDay(){ | 
|---|
|  |  |  | //    dao.deleteAllIntakeAmountDay(); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除一些取水口日取水量统计 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void deleteSomeIntakeAmountDay(){ | 
|---|
|  |  |  | dao.deleteSomeIntakeAmountDay(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 统计取水口日取水量 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void statisticsIntakeAmountDay() throws Exception{ | 
|---|
|  |  |  | int nowYear = Integer.parseInt(DateTime.yyyy()) ; | 
|---|
|  |  |  | int nowMonth = Integer.parseInt(DateTime.MM()) ; | 
|---|
|  |  |  | int nowDay = Integer.parseInt(DateTime.dd()) ; | 
|---|
|  |  |  | Date startDt ; | 
|---|
|  |  |  | Date endDt ; | 
|---|
|  |  |  | List<VoRmIntakeAmountDay> list ; | 
|---|
|  |  |  | boolean stop = false ; | 
|---|
|  |  |  | for(int[] ym : StClientAmountConstant.yearMonthGrp) { | 
|---|
|  |  |  | int[] dates = DateTime.dayGrpInMonth(ym[0], ym[1]); | 
|---|
|  |  |  | for(int day: dates){ | 
|---|
|  |  |  | if(ym[0] == nowYear && ym[1] == nowMonth && day > nowDay){ | 
|---|
|  |  |  | stop = true ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!stop){ | 
|---|
|  |  |  | startDt = DateTime.dateFrom_yyyy_MM_dd_HH_mm_ss(ym[0] + "-" + ym[1] + "-" + day + " 00:00:00") ; | 
|---|
|  |  |  | endDt = DateTime.dateFrom_yyyy_MM_dd_HH_mm_ss(ym[0] + "-" + ym[1] + "-" + day + " 23:59:59") ; | 
|---|
|  |  |  | list = dao.statisticAllIntakeAmountDayFromOpenCloseValveHistory(startDt, endDt) ; | 
|---|
|  |  |  | this.doStatisticsIntakeAmountDay(ym[0], ym[1], day, list) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | break ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | protected void doStatisticsIntakeAmountDay(int year, int month, int day, List<VoRmIntakeAmountDay> list) throws Exception{ | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | Date date = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-" + day) ; | 
|---|
|  |  |  | for(VoRmIntakeAmountDay vo : list){ | 
|---|
|  |  |  | dao.updateOneIntakeAmountDay1(vo.intakeId, date, vo.amount, vo.money, vo.times); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //////////////////////////////////////// | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // 有关月统计 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | /////////////////////////////////////// | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除所有取水口月取水量统计 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void deleteAllIntakeAmountMonth(){ | 
|---|
|  |  |  | dao.deleteAllIntakeAmountMonth(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 统计取水口月取水量 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void statisticsIntakeAmountMonth() throws Exception{ | 
|---|
|  |  |  | int nowYear = Integer.parseInt(DateTime.yyyy()) ; | 
|---|
|  |  |  | int nowMonth = Integer.parseInt(DateTime.MM()) ; | 
|---|
|  |  |  | Date startDt ; | 
|---|
|  |  |  | Date endDt ; | 
|---|
|  |  |  | List<StIntakeAmountMonth> list ; | 
|---|
|  |  |  | for(int year = StClientAmountConstant.DealStartYear; year <= nowYear; year ++){ | 
|---|
|  |  |  | list = null ; | 
|---|
|  |  |  | if(year < nowYear){ | 
|---|
|  |  |  | for(int month = 1 ; month <= 12 ; month ++){ | 
|---|
|  |  |  | startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-01") ; | 
|---|
|  |  |  | endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-" + DateTime.endDayOfMonth(year, month)) ; | 
|---|
|  |  |  | list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ; | 
|---|
|  |  |  | this.doStatisticsIntakeAmountMonth(year, month, list) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | for(int month = 1 ; month <= nowMonth ; month ++){ | 
|---|
|  |  |  | startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-01") ; | 
|---|
|  |  |  | endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-" + DateTime.endDayOfMonth(year, month)) ; | 
|---|
|  |  |  | list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ; | 
|---|
|  |  |  | this.doStatisticsIntakeAmountMonth(year, month, list) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | protected void doStatisticsIntakeAmountMonth(int year, int month, List<StIntakeAmountMonth> list) throws Exception{ | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | for(StIntakeAmountMonth po : list){ | 
|---|
|  |  |  | po.year = year ; | 
|---|
|  |  |  | po.month = month ; | 
|---|
|  |  |  | dao.saveOneIntakeAmountMonth(po) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //////////////////////////////////////// | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // 有关年统计 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | /////////////////////////////////////// | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除所有取水口年取水量统计 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void deleteAllIntakeAmountYear(){ | 
|---|
|  |  |  | dao.deleteAllIntakeAmountYear(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 统计取水口月取水量 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void statisticsIntakeAmountYear() throws Exception{ | 
|---|
|  |  |  | int nowYear = Integer.parseInt(DateTime.yyyy()) ; | 
|---|
|  |  |  | Date startDt ; | 
|---|
|  |  |  | Date endDt ; | 
|---|
|  |  |  | List<StIntakeAmountYear> list ; | 
|---|
|  |  |  | for(int year = StClientAmountConstant.DealStartYear; year <= nowYear; year ++){ | 
|---|
|  |  |  | list = null ; | 
|---|
|  |  |  | startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-01-01") ; | 
|---|
|  |  |  | endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-12-31") ; | 
|---|
|  |  |  | list = dao.statisticAllIntakeAmountYearFromAmountDay(startDt, endDt) ; | 
|---|
|  |  |  | this.doStatisticsIntakeAmountYear(year, list) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | protected void doStatisticsIntakeAmountYear(int year, List<StIntakeAmountYear> list) throws Exception{ | 
|---|
|  |  |  | if(list != null && list.size() > 0){ | 
|---|
|  |  |  | for(StIntakeAmountYear po : list){ | 
|---|
|  |  |  | po.year = year ; | 
|---|
|  |  |  | dao.saveOneIntakeAmountYear(po) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|