|  |  | 
 |  |  | package com.dy.rtuMw.server.rtuData.dbSv; | 
 |  |  |  | 
 |  |  | import com.dy.common.util.NumUtil; | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.pipIrrGlobal.daoBa.BaClientMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoPr.PrControllerTrampMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoRm.*; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper; | 
 |  |  | import com.dy.pipIrrGlobal.pojoBa.BaClient; | 
 |  |  | import com.dy.pipIrrGlobal.pojoPr.PrController; | 
 |  |  | import com.dy.pipIrrGlobal.pojoPr.PrControllerTramp; | 
 |  |  | import com.dy.pipIrrGlobal.pojoRm.*; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClient; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoCardInfo1; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | 
 |  |  | @Service() | 
 |  |  | public class DbSv { | 
 |  |  |     @Autowired | 
 |  |  |     private SeClientCardMapper seClientCardMapperDao;//农户水卡DAO | 
 |  |  |     private SeClientCardMapper seClientCardDao;//农户水卡DAO | 
 |  |  |     @Autowired | 
 |  |  |     private SeVirtualCardMapper seVirtualCardMapper;//农户虚拟水卡DAO | 
 |  |  |     private SeVirtualCardMapper seVirtualCardDao ;//虚拟卡相关DAO | 
 |  |  |     @Autowired | 
 |  |  |     private PrControllerTrampMapper prControllerTrampMapperDao;//流浪控制器DAO | 
 |  |  |     @Autowired | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RmWorkReportHistoryMapper rmWorkReportHistoryMapperDao ;//控制器历史工作报数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmIntakeAmountDayLastMapper rmIntakeAmountDayLastMapperDao ;//取水口取水和漏损统计最新数据DAO | 
 |  |  |     private RmIntakeAmountDayLastMapper rmIntakeAmountDayLastMapperDao ;//取水口取水统计最新数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmIntakeAmountDayMapper rmIntakeAmountDayMapperDao ;//取水口取水和漏损统计DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmLossLastMapper rmLossLastMapperDao ;//控制器漏损水量统计最新数据DAO | 
 |  |  |     private RmClientAmountDayLastMapper rmClientAmountDayLastMapperDao ;//农户日用水量统计最新数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmLossHistoryMapper rmLossHistoryMapperDao ;//控制器漏损水量统计历史数据DAO | 
 |  |  |     private RmClientAmountDayMapper rmClientAmountDayMapperDao ;//农户日用水量统计数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmLossDayLastMapper rmLossLastMapperDao ;//控制器漏损水量统计最新数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmLossDayMapper rmLossHistoryMapperDao ;//控制器漏损水量统计历史数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmCommandHistoryMapper rmCommandHistoryDao ;//远程命令日志相关 | 
 |  |  |     @Autowired | 
 |  |  |     private SeVirtualCardMapper seVirtualCardDao ;//虚拟卡相关 | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RmTimingReportHistoryMapper rmTimingReportHistoryDao; // 定点上报历史数据DAO | 
 |  |  | 
 |  |  |     private RmOnHourReportHistoryMapper rmOnHourReportHistoryDao; // 整点上报历史数据DAO | 
 |  |  |     @Autowired | 
 |  |  |     private RmOnHourReportLastMapper rmOnHourReportLastDao; // 整点上报最新数据DAO | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     //@Autowired | 
 |  |  |     //@Lazy | 
 |  |  | 
 |  |  |         SeClient vo = null ; | 
 |  |  |         if(NumUtil.isPlusIntNumber(icCardNo)){ | 
 |  |  |             Long icCardNoLong = Long.parseLong(icCardNo) ; | 
 |  |  |             Map<String, Object> map = seClientCardMapperDao.getClientIdAndNameByCardAddrAndCardNo(icCardAddr, icCardNoLong) ; | 
 |  |  |             Map<String, Object> map = seClientCardDao.getClientIdAndNameByCardAddrAndCardNo(icCardAddr, icCardNoLong) ; | 
 |  |  |             if(map != null && map.size() > 0) { | 
 |  |  |                 vo = new SeClient() ; | 
 |  |  |                 vo.setId(Long.parseLong(map.get("clientId").toString())); | 
 |  |  | 
 |  |  |         SeClient vo = null ; | 
 |  |  |         if(NumUtil.isPlusIntNumber(icCardNo)){ | 
 |  |  |             Long icCardNoLong = Long.parseLong(icCardNo) ; | 
 |  |  |             Map<String, Object> map = seVirtualCardMapper.getClientIdAndNameByVsCardNo(icCardNoLong) ; | 
 |  |  |             Map<String, Object> map = seVirtualCardDao.getClientIdAndNameByVsCardNo(icCardNoLong) ; | 
 |  |  |             if(map != null && map.size() > 0) { | 
 |  |  |                 vo = new SeClient() ; | 
 |  |  |                 vo.setId(Long.parseLong(map.get("clientId").toString())); | 
 |  |  | 
 |  |  |     // | 
 |  |  |     //////////////////////////////////////////////// | 
 |  |  |     /** | 
 |  |  |      * 得到控制器漏损水量统计最新记录 | 
 |  |  |      * 得到最新记录 | 
 |  |  |      * @param intakeId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 保存控制器漏损水量统计最新记录 | 
 |  |  |      * 保存最新记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  | 
 |  |  |         this.rmIntakeAmountDayLastMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |   /** | 
 |  |  |      * 保存控制器漏损水量统计最新记录 | 
 |  |  |      * 保存记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  | 
 |  |  |         this.rmIntakeAmountDayMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 保存控制器漏损水量统计最新记录 | 
 |  |  |      * 保存最新记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateRmIntakeAmountLast(RmIntakeAmountDay po){ | 
 |  |  |         this.rmIntakeAmountDayMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     public void updateRmIntakeAmountLast(RmIntakeAmountDayLast po){ | 
 |  |  |         this.rmIntakeAmountDayLastMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 保存控制器漏损水量统计最新记录 | 
 |  |  |      * 保存历史记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 得到控制器漏损水量统计历史记录中的最新记录 | 
 |  |  |      * 得到符合条件的历史记录 | 
 |  |  |      * @param id | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         return rmIntakeAmountDayMapperDao.selectByPrimaryKey(id) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     ///////////////////////////////////////////////// | 
 |  |  |     // | 
 |  |  |     // 农户日用水量及花费统计功能 | 
 |  |  |     // | 
 |  |  |     //////////////////////////////////////////////// | 
 |  |  |     /** | 
 |  |  |      * 得到最新记录 | 
 |  |  |      * @param clientId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmClientAmountDayLast getRmClientAmountLast(Long clientId){ | 
 |  |  |         List<RmClientAmountDayLast> list = rmClientAmountDayLastMapperDao.selectByClientId(clientId) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 保存最新记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void saveRmClientAmountLast(RmClientAmountDayLast po){ | 
 |  |  |         this.rmClientAmountDayLastMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 保存记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void saveRmClientAmountDay(RmClientAmountDay po){ | 
 |  |  |         this.rmClientAmountDayMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 更新最新记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateRmClientAmountLast(RmClientAmountDayLast po){ | 
 |  |  |         this.rmClientAmountDayLastMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 更新记录 | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateRmClientAmountDay(RmClientAmountDay po){ | 
 |  |  |         this.rmClientAmountDayMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 得到控制器漏损水量统计最新记录 | 
 |  |  |      * 得到符合条件的历史记录 | 
 |  |  |      * @param id | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmClientAmountDay getRmClientAmountDay(Long id){ | 
 |  |  |         return rmClientAmountDayMapperDao.selectByPrimaryKey(id) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 得到符合条件的历史记录 | 
 |  |  |      * @param clientId | 
 |  |  |      * @param dt | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmIntakeAmountDay getRmIntakeAmountLastByDate(Date dt){ | 
 |  |  |         List<RmIntakeAmountDay> list = rmIntakeAmountDayMapperDao.selectByDate(dt) ; | 
 |  |  |     public RmClientAmountDay getRmClientAmountByClientAndDate(Long clientId, Date dt){ | 
 |  |  |         List<RmClientAmountDay> list = rmClientAmountDayMapperDao.selectByClientAndDate(clientId, dt) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 得到控制器漏损水量统计历史记录中的某日记录 | 
 |  |  |      * @param dt | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmIntakeAmountDay getRmIntakeAmountDayByDate(Date dt){ | 
 |  |  |         List<RmIntakeAmountDay> list = rmIntakeAmountDayMapperDao.selectByDate(dt) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     ///////////////////////////////////////////////// | 
 |  |  |     // | 
 |  |  | 
 |  |  |      * @param intakeId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmLossLast getRmLossLast(Long intakeId){ | 
 |  |  |         List<RmLossLast> list = rmLossLastMapperDao.selectByIntakeId(intakeId) ; | 
 |  |  |     public RmLossDayLast getRmLossLast(Long intakeId){ | 
 |  |  |         List<RmLossDayLast> list = rmLossLastMapperDao.selectByIntakeId(intakeId) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void saveRmLossLast(RmLossLast po){ | 
 |  |  |     public void saveRmLossLast(RmLossDayLast po){ | 
 |  |  |         this.rmLossLastMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |   /** | 
 |  |  | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void saveRmLossHistory(RmLossHistory po){ | 
 |  |  |     public void saveRmLossHistory(RmLossDay po){ | 
 |  |  |         this.rmLossHistoryMapperDao.insert(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateRmLossLast(RmLossLast po){ | 
 |  |  |     public void updateRmLossLast(RmLossDayLast po){ | 
 |  |  |         this.rmLossLastMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  | 
 |  |  |      * @param po | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateRmLossHistory(RmLossHistory po){ | 
 |  |  |     public void updateRmLossHistory(RmLossDay po){ | 
 |  |  |         this.rmLossHistoryMapperDao.updateByPrimaryKey(po) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |      * @param id | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmLossHistory getRmLossHistory(Long id){ | 
 |  |  |     public RmLossDay getRmLossHistory(Long id){ | 
 |  |  |         return rmLossHistoryMapperDao.selectByPrimaryKey(id) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |      * @param dt | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmLossLast getRmLossLastByDate(Date dt){ | 
 |  |  |         List<RmLossLast> list = rmLossLastMapperDao.selectByDate(dt) ; | 
 |  |  |     public RmLossDayLast getRmLossLastByDate(Date dt){ | 
 |  |  |         List<RmLossDayLast> list = rmLossLastMapperDao.selectByDate(dt) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  | 
 |  |  |      * @param dt | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public RmLossHistory getRmLossHistoryByDate(Date dt){ | 
 |  |  |         List<RmLossHistory> list = rmLossHistoryMapperDao.selectByDate(dt) ; | 
 |  |  |     public RmLossDay getRmLossHistoryByDate(Date dt){ | 
 |  |  |         List<RmLossDay> list = rmLossHistoryMapperDao.selectByDate(dt) ; | 
 |  |  |         if(list != null && list.size() > 0){ | 
 |  |  |             return list.get(0) ; | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     ////////////////////////////////////////////////////// | 
 |  |  |     // | 
 |  |  |     // IC卡相关 | 
 |  |  |     // | 
 |  |  |     ////////////////////////////////////////////////////// | 
 |  |  |     /** | 
 |  |  |      * 得到农户卡 | 
 |  |  |      * @param cardAddr | 
 |  |  |      * @param cardNo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public VoCardInfo1 getIcCard(String cardAddr, String cardNo){ | 
 |  |  |         if(NumUtil.isPlusIntNumber(cardNo)){ | 
 |  |  |             Long icCardNoLong = Long.parseLong(cardNo) ; | 
 |  |  |             List<VoCardInfo1> list = seClientCardDao.getCardsByAddrAndNum(cardAddr, icCardNoLong) ; | 
 |  |  |             if(list != null && list.size() > 0){ | 
 |  |  |                 return list.get(0) ; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 得到农户虚拟卡 | 
 |  |  |      * @param cardNo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public VoCardInfo1 getVirIcCard(String cardNo){ | 
 |  |  |         if(NumUtil.isPlusIntNumber(cardNo)){ | 
 |  |  |             Long icCardNoLong = Long.parseLong(cardNo) ; | 
 |  |  |             List<VoCardInfo1> list = seVirtualCardDao.getCardsByNum(icCardNoLong) ; | 
 |  |  |             if(list != null && list.size() > 0){ | 
 |  |  |                 return list.get(0) ; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return null ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 更新实体卡剩余金额 | 
 |  |  |      * @param id | 
 |  |  |      * @param remainMoney | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateIcCardRemainMoney(Long id , Double remainMoney){ | 
 |  |  |         seClientCardDao.updateMoney(id,remainMoney); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 更新虚拟卡剩余金额 | 
 |  |  |      * @param id | 
 |  |  |      * @param remainMoney | 
 |  |  |      */ | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateVirIcCardRemainMoney(Long id , Double remainMoney){ | 
 |  |  |         seVirtualCardDao.updateMoney(id,remainMoney); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     ////////////////////////////////////////////////////// | 
 |  |  | 
 |  |  |     public RmCommandHistory getCommandLog(String commandId){ | 
 |  |  |         return rmCommandHistoryDao.selectByPrimaryKey(Long.parseLong(commandId)) ; | 
 |  |  |     } | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public void updateCommandLog(RmCommandHistory po){ | 
 |  |  |         rmCommandHistoryDao.updateByPrimaryKey(po) ; | 
 |  |  |     } |