|  |  | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.common.webUtil.QueryResultVo; | 
 |  |  | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeClientMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeGeneralMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoRm.RmOpenCloseValveHistoryMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.*; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeManagerCard; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; | 
 |  |  | import com.dy.pipIrrGlobal.voRm.VoExpend; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.*; | 
 |  |  | import com.dy.pipIrrSell.cardOperate.dto.DtoRecharge; | 
 |  |  | import com.dy.pipIrrSell.cardOperate.enums.OperateTypeENUM; | 
 |  |  | import com.dy.pipIrrSell.cardOperate.qo.*; | 
 |  |  | import com.dy.pipIrrSell.clientCard.CardStateENUM; | 
 |  |  | import com.dy.pipIrrSell.clientCard.ClientCardSv; | 
 |  |  | import com.dy.pipIrrSell.clientCard.LastOperateENUM; | 
 |  |  | import com.dy.pipIrrSell.result.SellResultCode; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.apache.dubbo.common.utils.PojoUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import java.text.DecimalFormat; | 
 |  |  | import java.time.Duration; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BaSettingsMapper baSettingsMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SeManagerCardMapper seManagerCardMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SePaymentMethodMapper sePaymentMethodMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SeRechargeHistoryMapper seRechargeHistoryMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RmOpenCloseValveHistoryMapper rmOpenCloseValveHistoryMapper; | 
 |  |  |  | 
 |  |  |     @Value("${project.projectNo}") | 
 |  |  |     private Integer projectNo; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加开卡记录 | 
 |  |  |      * | 
 |  |  |      * @param po 水卡操作对象 | 
 |  |  |      * @return 开卡记录主键 | 
 |  |  |      */ | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据农户编号获取5级行政区划代码,开卡使用 | 
 |  |  |      * | 
 |  |  |      * @param clientNum 农户编号 | 
 |  |  |      * @return 5级行政区划代码 | 
 |  |  |      */ | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用 | 
 |  |  |      * | 
 |  |  |      * @param clientId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Long getAreaCodeById(Long clientId) { | 
 |  |  |         return seClientMapper.getAreaCodeById(clientId); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据行政区划串模块查询水卡编号,开卡使用 | 
 |  |  |      * | 
 |  |  |      * @param areaCode | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     String getCardNumOfMax(String areaCode) { | 
 |  |  |     public String getCardNumOfMax(String areaCode) { | 
 |  |  |         return seClientCardMapper.getCardNumOfMax(areaCode); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据行政区划串模糊查询管理卡编号,创建管理卡使用 | 
 |  |  |      * | 
 |  |  |      * @param areaCode | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public String getManagerCardNumOfMax(String areaCode) { | 
 |  |  |         return seManagerCardMapper.getManagerCardNumOfMax(areaCode); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 创建管理卡 | 
 |  |  |      * | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Long addManagerCard(SeManagerCard po) { | 
 |  |  |         seManagerCardMapper.insert(po); | 
 |  |  |         return po.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据农户编号获取农户ID,开卡使用 | 
 |  |  |      * | 
 |  |  |      * @param clientNum | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加水卡操作对象,各操作都使用 | 
 |  |  |      * | 
 |  |  |      * @param po 水卡操作对象 | 
 |  |  |      * @return 操作记录主键 | 
 |  |  |      */ | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加充值记录 | 
 |  |  |      * 修改农户信息、添加充值记录 | 
 |  |  |      * 修改农户信息、添加水卡操作记录、添加充值记录 | 
 |  |  |      * | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public BaseResponse<Boolean> addRecharge(DtoRecharge po){ | 
 |  |  |     public BaseResponse<Boolean> addRecharge(DtoRecharge po) { | 
 |  |  |         /** | 
 |  |  |          * cardId           水卡编号(依据水卡编号获取) | 
 |  |  |          * clientId         农户编号(依据水卡编号获取) | 
 |  |  | 
 |  |  |         Long operator = po.getOperator(); | 
 |  |  |         Date rechargeTime = new Date(); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // 验证水卡状态是否支持当前操作 | 
 |  |  |         // 获取水卡状态 | 
 |  |  |         String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); | 
 |  |  |         if(stateName.length() == 0 || !stateName.equals("正常")) { | 
 |  |  |             return BaseResponseUtils.buildFail(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
 |  |  |  | 
 |  |  |         // 单独充值时卡片必须为正常 | 
 |  |  |         if (remarks.trim().equals("充值") && !stateName.equals("正常")) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开卡同步充值时允许卡片为无效状态,得到通知后自动变更为有效 | 
 |  |  |         if (!remarks.trim().equals("充值") && !stateName.equals("正常") && !stateName.equals("无效卡片")) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 依据水卡编号获取水卡表主键及农户编号 | 
 |  |  |          */ | 
 |  |  |         Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); | 
 |  |  |         if(map == null || map.size() <= 0) { | 
 |  |  |             return BaseResponseUtils.buildFail(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
 |  |  |         if (map == null || map.size() <= 0) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(SellResultCode.CARD_NUMBER_MISTAKE.getMessage()); | 
 |  |  |         } | 
 |  |  |         cardId = Long.parseLong(map.get("cardId").toString()); | 
 |  |  |         clientId = Long.parseLong(map.get("clientId").toString()); | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 修改农户卡信息: | 
 |  |  |          *      补卡时间 | 
 |  |  |          *      最后操作类型-2 | 
 |  |  |          * 充值时不修改农户卡信息,收到成功通知后再修改:余额、充值时间、最后操作类型 | 
 |  |  |          SeClientCard seClientCard = new SeClientCard(); | 
 |  |  |          seClientCard.setId(cardId); | 
 |  |  |          seClientCard.setMoney(afterRecharge); | 
 |  |  |          seClientCard.setRechargedt(rechargeTime); | 
 |  |  |          seClientCard.setLastoper(LastOperateENUM.RECHARGE.getCode ()); | 
 |  |  |          Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
 |  |  |          if(rec_updateClientCard == 0) { | 
 |  |  |          return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
 |  |  |          } | 
 |  |  |          */ | 
 |  |  |         SeClientCard seClientCard = new SeClientCard(); | 
 |  |  |         seClientCard.setId(cardId); | 
 |  |  |         seClientCard.setMoney(afterRecharge); | 
 |  |  |         seClientCard.setRechargedt(rechargeTime); | 
 |  |  |         seClientCard.setLastoper(LastOperateENUM.RECHARGE.getCode ()); | 
 |  |  |         Integer rec_updateClientCard = Optional.ofNullable(clientCardSv.UpdateClientCard(seClientCard)).orElse(0); | 
 |  |  |         if(rec_updateClientCard == 0) { | 
 |  |  |             return BaseResponseUtils.buildFail(SellResultCode.RECHARGE_FAIL_WRITE_CLIENT_CARD_ERROR.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 添加充值记录 | 
 |  |  |          * 添加水卡充值操作记录 | 
 |  |  |          */ | 
 |  |  |         SeCardOperate seCardOperate = new SeCardOperate(); | 
 |  |  |         seCardOperate.setCardId(cardId); | 
 |  |  | 
 |  |  |         seCardOperate.setRemarks(remarks); | 
 |  |  |         seCardOperate.setOperator(operator); | 
 |  |  |         seCardOperate.setOperateDt(rechargeTime); | 
 |  |  |  | 
 |  |  |         seCardOperate.setOperateValid((byte) 1); | 
 |  |  |         seCardOperateMapper.insert(seCardOperate); | 
 |  |  |         Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); | 
 |  |  |         if(rec == 0) { | 
 |  |  |             return BaseResponseUtils.buildFail(SellResultCode.REPLACE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); | 
 |  |  |         if (rec == 0) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return BaseResponseUtils.buildSuccess(true) ; | 
 |  |  |         /** | 
 |  |  |          * 添加充值历史记录 | 
 |  |  |          */ | 
 |  |  |         SeRechargeHistory seRechargeHistory = new SeRechargeHistory(); | 
 |  |  |         seRechargeHistory.setCardid(cardId); | 
 |  |  |         seRechargeHistory.setClientid(clientId); | 
 |  |  |         seRechargeHistory.setMoney(money); | 
 |  |  |         seRechargeHistory.setAmount(amount); | 
 |  |  |         seRechargeHistory.setGift(gift); | 
 |  |  |         seRechargeHistory.setAfterrecharge(afterRecharge); | 
 |  |  |         seRechargeHistory.setPaymentid(paymentId); | 
 |  |  |         seRechargeHistory.setPrice(price); | 
 |  |  |         seRechargeHistory.setRemarks(remarks); | 
 |  |  |         seRechargeHistory.setOperator(operator); | 
 |  |  |         seRechargeHistory.setOperatedt(rechargeTime); | 
 |  |  |         seRechargeHistory.setOperateValid((byte) 1); | 
 |  |  |         seRechargeHistoryMapper.insert(seRechargeHistory); | 
 |  |  |         Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); | 
 |  |  |         if (rec_seRechargeHistory == 0) { | 
 |  |  |             return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_HISTORY_ERROR.getMessage()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Map map_response = new HashMap(); | 
 |  |  |         map_response.put("projectNo", String.format("%02x", projectNo)); | 
 |  |  |         map_response.put("orderNumber", rec); | 
 |  |  |         map_response.put("cardNum", cardNum); | 
 |  |  |         return BaseResponseUtils.buildSuccess(map_response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取充值记录 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public QueryResultVo<List<VoRecharge>> getRecharges(QoRecharge queryVo) { | 
 |  |  |         //完善查询充值记录的起止时间 | 
 |  |  |         String rechargeTimeStart = queryVo.rechargeTimeStart; | 
 |  |  |         String rechargeTimeStop = queryVo.rechargeTimeStop; | 
 |  |  |         if(rechargeTimeStart != null) { | 
 |  |  |             rechargeTimeStart = rechargeTimeStart + " 00:00:00"; | 
 |  |  |             queryVo.setRechargeTimeStart(rechargeTimeStart); | 
 |  |  |         } | 
 |  |  |         if(rechargeTimeStop != null) { | 
 |  |  |             rechargeTimeStop = rechargeTimeStop + " 23:59:59"; | 
 |  |  |             queryVo.setRechargeTimeStop(rechargeTimeStop); | 
 |  |  |         } | 
 |  |  |         //String rechargeTimeStart = queryVo.rechargeTimeStart; | 
 |  |  |         //String rechargeTimeStop = queryVo.rechargeTimeStop; | 
 |  |  |         //if(rechargeTimeStart != null) { | 
 |  |  |         //    rechargeTimeStart = rechargeTimeStart + " 00:00:00"; | 
 |  |  |         //    queryVo.setRechargeTimeStart(rechargeTimeStart); | 
 |  |  |         //} | 
 |  |  |         //if(rechargeTimeStop != null) { | 
 |  |  |         //    rechargeTimeStop = rechargeTimeStop + " 23:59:59"; | 
 |  |  |         //    queryVo.setRechargeTimeStop(rechargeTimeStop); | 
 |  |  |         //} | 
 |  |  |  | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getRecordCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoRecharge>> rsVo = new QueryResultVo<>() ; | 
 |  |  |         rsVo.pageSize = queryVo.pageSize ; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr ; | 
 |  |  |         QueryResultVo<List<VoRecharge>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getRecharges(params); | 
 |  |  |         return rsVo ; | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取充值记录,管理平台充值列表使用,APP未使用 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public QueryResultVo<List<VoRechargeNew>> getRechargesNew(QoRecharge queryVo) { | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getRechargesCountNew(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoRechargeNew>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getRechargesNew(params); | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取返还记录,管理平台充值列表使用 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public QueryResultVo<List<VoRefund>> getRefunds(QoRecharge queryVo) { | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getRefundsCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoRefund>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getRefunds(params); | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取水卡消费记录,管理平台使用 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public QueryResultVo<List<VoExpend>> getExpends(QoRecharge queryVo) { | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
 |  |  |  | 
 |  |  |         Long itemTotal = rmOpenCloseValveHistoryMapper.getExpendsCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoExpend>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = rmOpenCloseValveHistoryMapper.getExpends(params); | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取交易记录 | 
 |  |  |      * | 
 |  |  |      * @param vo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Map getTransactions(QoTransaction vo){ | 
 |  |  |     public Map getTransactions(QoTransaction vo) { | 
 |  |  |         DecimalFormat df = new DecimalFormat("0.00"); | 
 |  |  |         // 补齐查询时间 | 
 |  |  |         String operateTimeStart = vo.operateTimeStart; | 
 |  |  |         String operateTimeStop = vo.operateTimeStop; | 
 |  |  |         if(operateTimeStart != null) { | 
 |  |  |         if (operateTimeStart != null) { | 
 |  |  |             operateTimeStart = operateTimeStart + " 00:00:00"; | 
 |  |  |             vo.setOperateTimeStart(operateTimeStart); | 
 |  |  |         } | 
 |  |  |         if(operateTimeStop != null) { | 
 |  |  |         if (operateTimeStop != null) { | 
 |  |  |             operateTimeStop = operateTimeStop + " 23:59:59"; | 
 |  |  |             vo.setOperateTimeStop(operateTimeStop); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 生成查询参数 | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo); | 
 |  |  |  | 
 |  |  |         // 获取符合条件的记录数 | 
 |  |  |         Long itemTotal = Optional.ofNullable(seCardOperateMapper.getTransactionRecordCount(params)).orElse(0L); | 
 |  |  |  | 
 |  |  |         List<VoTradeDetails> list = seCardOperateMapper.getTransactions(params); | 
 |  |  |         if(list.size() == 0) { | 
 |  |  |         QueryResultVo<List<VoTradeDetails>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = vo.pageSize; | 
 |  |  |         rsVo.pageCurr = vo.pageCurr; | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |  | 
 |  |  |         rsVo.obj = seCardOperateMapper.getTransactions(params); | 
 |  |  |         List<VoTradeDetails> list = rsVo.obj; | 
 |  |  |         if (list.size() == 0) { | 
 |  |  |             return new HashMap(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 遍历交易明细记录,汇总购水金额、购卡金额 | 
 |  |  |         Double totalWaterCost = 0.0; | 
 |  |  |         Double totalCardCost = 0.0; | 
 |  |  |         JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); | 
 |  |  |         for(int i = 0; i < array.size(); i++) { | 
 |  |  |         Double totalGift = 0.0; | 
 |  |  |         Double totalRefund = 0.0; | 
 |  |  |  | 
 |  |  |         JSONArray array = JSONArray.parseArray(JSON.toJSONString(list)); | 
 |  |  |         for (int i = 0; i < array.size(); i++) { | 
 |  |  |             JSONObject job = array.getJSONObject(i); | 
 |  |  |             Double waterCost = Optional.ofNullable(job.getDouble("waterCost")).orElse(0.0); | 
 |  |  |             Double cardCost = Optional.ofNullable(job.getDouble("cardCost")).orElse(0.0); | 
 |  |  |             Double gift = Optional.ofNullable(job.getDouble("gift")).orElse(0.0); | 
 |  |  |             Double refundAmount = Optional.ofNullable(job.getDouble("refundAmount")).orElse(0.0); | 
 |  |  |  | 
 |  |  |             totalWaterCost = totalWaterCost + waterCost; | 
 |  |  |             totalCardCost = totalCardCost + cardCost; | 
 |  |  |             totalGift = totalGift + gift; | 
 |  |  |             totalRefund = totalRefund + refundAmount; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Map map_record = new HashMap(); | 
 |  |  |         map_record.put("itemTotal", itemTotal); | 
 |  |  |         map_record.put("list", list); | 
 |  |  |         map_record.put("list", rsVo); | 
 |  |  |  | 
 |  |  |         Map map_result = new HashMap(); | 
 |  |  |         map_result.put("waterCost", df.format(totalWaterCost)); | 
 |  |  |         map_result.put("cardCost", df.format(totalCardCost)); | 
 |  |  |         map_result.put("gift", df.format(totalGift)); | 
 |  |  |         map_result.put("refund", df.format(totalRefund)); | 
 |  |  |  | 
 |  |  |         map_result.put("records", map_record); | 
 |  |  |  | 
 |  |  |         return map_result; | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取开卡记录 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         //完善查询充值记录的起止时间 | 
 |  |  |         String activeTimeStart = queryVo.activeTimeStart; | 
 |  |  |         String activeTimeStop = queryVo.activeTimeStop; | 
 |  |  |         if(activeTimeStart != null) { | 
 |  |  |         if (activeTimeStart != null) { | 
 |  |  |             activeTimeStart = activeTimeStart + " 00:00:00"; | 
 |  |  |             queryVo.setActiveTimeStart(activeTimeStart); | 
 |  |  |         } | 
 |  |  |         if(activeTimeStop != null) { | 
 |  |  |         if (activeTimeStop != null) { | 
 |  |  |             activeTimeStop = activeTimeStop + " 23:59:59"; | 
 |  |  |             queryVo.setActiveTimeStop(activeTimeStop); | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getActiveCardRecordCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoActiveCard>> rsVo = new QueryResultVo<>() ; | 
 |  |  |         QueryResultVo<List<VoActiveCard>> rsVo = new QueryResultVo<>(); | 
 |  |  |  | 
 |  |  |         rsVo.pageSize = queryVo.pageSize ; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr ; | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getActiveCards(params); | 
 |  |  |         return rsVo ; | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取补卡记录 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         //完善查询充值记录的起止时间 | 
 |  |  |         String reissueCardTimeStart = queryVo.reissueCardTimeStart; | 
 |  |  |         String reissueCardTimeStop = queryVo.reissueCardTimeStop; | 
 |  |  |         if(reissueCardTimeStart != null) { | 
 |  |  |         if (reissueCardTimeStart != null) { | 
 |  |  |             reissueCardTimeStart = reissueCardTimeStart + " 00:00:00"; | 
 |  |  |             queryVo.setReissueCardTimeStart(reissueCardTimeStart); | 
 |  |  |         } | 
 |  |  |         if(reissueCardTimeStop != null) { | 
 |  |  |         if (reissueCardTimeStop != null) { | 
 |  |  |             reissueCardTimeStop = reissueCardTimeStop + " 23:59:59"; | 
 |  |  |             queryVo.setReissueCardTimeStop(reissueCardTimeStop); | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getReissueCardRecordCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoReissueCard>> rsVo = new QueryResultVo<>() ; | 
 |  |  |         QueryResultVo<List<VoReissueCard>> rsVo = new QueryResultVo<>(); | 
 |  |  |  | 
 |  |  |         rsVo.pageSize = queryVo.pageSize ; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr ; | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getReissueCards(params); | 
 |  |  |         return rsVo ; | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取IC卡注销记录 | 
 |  |  |      * 根据指定条件获取通用操作记录 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |         //完善查询充值记录的起止时间 | 
 |  |  |         String timeStart = queryVo.getTimeStart(); | 
 |  |  |         String timeStop = queryVo.getTimeStop(); | 
 |  |  |         if(timeStart != null) { | 
 |  |  |         if (timeStart != null) { | 
 |  |  |             timeStart = timeStart + " 00:00:00"; | 
 |  |  |             queryVo.setTimeStart(timeStart); | 
 |  |  |         } | 
 |  |  |         if(timeStop != null) { | 
 |  |  |         if (timeStop != null) { | 
 |  |  |             timeStop = timeStop + " 23:59:59"; | 
 |  |  |             queryVo.setTimeStop(timeStop); | 
 |  |  |         } | 
 |  |  | 
 |  |  |  | 
 |  |  |         Long itemTotal = Optional.ofNullable(seCardOperateMapper.getCommonOperationRecordCount(params)).orElse(0L); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoOperate>> rsVo = new QueryResultVo<>() ; | 
 |  |  |         QueryResultVo<List<VoOperate>> rsVo = new QueryResultVo<>(); | 
 |  |  |  | 
 |  |  |         rsVo.pageSize = queryVo.pageSize ; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr ; | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         rsVo.obj = seCardOperateMapper.getCommonOperations(params); | 
 |  |  |         return rsVo ; | 
 |  |  |         return rsVo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据指定条件获取收据列表 | 
 |  |  |      * | 
 |  |  |      * @param queryVo | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Map getReceipts(QoReceipt queryVo) { | 
 |  |  |         if (queryVo.getTimeStart() != null && queryVo.getTimeStart() != "") { | 
 |  |  |             queryVo.setTimeStart(queryVo.getTimeStart() + " 00:00:00"); | 
 |  |  |         } | 
 |  |  |         if (queryVo.getTimeStop() != null && queryVo.getTimeStop() != "") { | 
 |  |  |             queryVo.setTimeStop(queryVo.getTimeStop() + " 23:59:59"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); | 
 |  |  |  | 
 |  |  |         DecimalFormat df = new DecimalFormat("#.00"); | 
 |  |  | 
 |  |  |  | 
 |  |  |         Long itemTotal = seCardOperateMapper.getReceiptsRecordCount(params); | 
 |  |  |  | 
 |  |  |         QueryResultVo<List<VoReceipt>> rsVo = new QueryResultVo<>() ; | 
 |  |  |         rsVo.pageSize = queryVo.pageSize ; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr ; | 
 |  |  |         QueryResultVo<List<VoReceipt>> rsVo = new QueryResultVo<>(); | 
 |  |  |         rsVo.pageSize = queryVo.pageSize; | 
 |  |  |         rsVo.pageCurr = queryVo.pageCurr; | 
 |  |  |  | 
 |  |  |         rsVo.calculateAndSet(itemTotal, params); | 
 |  |  |         //rsVo.obj = seCardOperateMapper.getReceipts(params); | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 判断指定水卡是否为挂失状态且无补卡记录 | 
 |  |  |      * | 
 |  |  |      * @param cardNum 水卡编号 | 
 |  |  |      * @return 是否已挂失未补卡 | 
 |  |  |      */ | 
 |  |  |     public Boolean isLostAndUnreplaced(Long cardNum) { | 
 |  |  |         Integer rec = seClientCardMapper.isLostAndUnreplaced(cardNum); | 
 |  |  |         if(rec != null && rec > 0) { | 
 |  |  |             return false; | 
 |  |  |         Integer lostCount = seClientCardMapper.getLostCount(cardNum); | 
 |  |  |         Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum); | 
 |  |  |         if (lostCount > 0 && replacedCount == 0) { | 
 |  |  |             return true; | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |         return false; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改农户水卡 | 
 |  |  |      * | 
 |  |  |      * @param po | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取项目编号 | 
 |  |  |      * | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public String getProjectNo() { | 
 |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡编号获取其挂失时退款金额(补卡时判断使用) | 
 |  |  |      * | 
 |  |  |      * @param cardNum | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Double getTradeAmountByCardNo(Long cardNum) { | 
 |  |  |         return seCardOperateMapper.getTradeAmountByCardNo(cardNum); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡地址判断该卡是否可以开卡 | 
 |  |  |      * | 
 |  |  |      * @param cardAddr | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Boolean canActiveCard(String cardAddr) { | 
 |  |  |  | 
 |  |  |         // 指定水卡地址的水卡数量,无效卡片排除在外 | 
 |  |  |         Long cardCount = Optional.ofNullable(seClientCardMapper.getCountByCardAddr(cardAddr)).orElse(0L); | 
 |  |  |         if (cardCount == 0) { | 
 |  |  |             return true; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 指定水卡地址且正常状态或挂失状态的水卡数量 | 
 |  |  |         cardCount = Optional.ofNullable(seClientCardMapper.getCountByCardAddrAndState(cardAddr)).orElse(0L); | 
 |  |  |         if (cardCount == 0) { | 
 |  |  |             return true; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return false; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 依据水卡地址获取水卡编号 | 
 |  |  |      * | 
 |  |  |      * @param cardAddr | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Long getCardIdByAddr(String cardAddr) { | 
 |  |  |         return seClientCardMapper.getCardIdByAddr(cardAddr); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 依据水卡地址将最后一条无效状态的指定操作记录改为有效 | 
 |  |  |      * | 
 |  |  |      * @param cardAddr | 
 |  |  |      * @param operateType | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Integer turnCardValidByAddr(String cardAddr, Integer operateType) { | 
 |  |  |         return seClientCardMapper.turnCardValidByAddr(cardAddr, operateType); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡ID、操作类型获取获取最后一条记录,判断开卡是否同步充值使用 | 
 |  |  |      * | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Integer turnOperateValidByCardId(Long cardId, Integer operateType) { | 
 |  |  |         return seCardOperateMapper.turnOperateValidByCardId(cardId, operateType); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 依据水卡ID将最后一条无效状态的充值历史记录改为有效 | 
 |  |  |      * | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Integer turnRechargeHistoryValidByCardId(Long cardId) { | 
 |  |  |         return seRechargeHistoryMapper.turnRechargeHistoryValidByCardId(cardId); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡ID判断是否为开卡时同步充值 | 
 |  |  |      * 该水卡ID不存在开卡记录或充值记录则返回false | 
 |  |  |      * 如果开卡操作与充值操作时间间隔超过30秒则返回false | 
 |  |  |      * 如果充值金额大于0且充值前余额为0则返回true | 
 |  |  |      * | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Boolean isMergeRecharge(Long cardId) { | 
 |  |  |         SeCardOperate activeCard = seCardOperateMapper.getCardOperate(1, cardId); | 
 |  |  |         SeCardOperate recharge = seCardOperateMapper.getCardOperate(2, cardId); | 
 |  |  |         if (activeCard == null || recharge == null) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Duration duration = Duration.between(activeCard.getOperateDt().toInstant(), recharge.getOperateDt().toInstant()); | 
 |  |  |         if (duration.toSeconds() > 30) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Float money = Optional.ofNullable(recharge.getMoney()).orElse(0f); | 
 |  |  |         Float tradeAmount = Optional.ofNullable(recharge.getTradeAmount()).orElse(0f); | 
 |  |  |  | 
 |  |  |         if (tradeAmount > 0 && money == 0) { | 
 |  |  |             return true; | 
 |  |  |         } else { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 根据水卡ID从操作记录表中取出:余额、交易金额、赠送金额,求和得到水卡余额 | 
 |  |  |      * 将余额更新到水卡表中 | 
 |  |  |      * | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Boolean updateCard(Long cardId) { | 
 |  |  |         SeCardOperate recharge = seCardOperateMapper.getCardOperate(2, cardId); | 
 |  |  |         if (recharge == null) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         Float money = Optional.ofNullable(recharge.getMoney()).orElse(0f); | 
 |  |  |         Float amount = Optional.ofNullable(recharge.getTradeAmount()).orElse(0f); | 
 |  |  |         Float gift = Optional.ofNullable(recharge.getGift()).orElse(0f); | 
 |  |  |  | 
 |  |  |         SeClientCard clientCard = new SeClientCard(); | 
 |  |  |         clientCard.setId(cardId); | 
 |  |  |         clientCard.setMoney(money + amount + gift); | 
 |  |  |         clientCard.setRechargedt(recharge.getOperateDt()); | 
 |  |  |         clientCard.setLastoper(LastOperateENUM.RECHARGE.getCode()); | 
 |  |  |         Integer rec_updateClientCard = seClientCardMapper.updateByPrimaryKeySelective(clientCard); | 
 |  |  |         if (rec_updateClientCard == null || rec_updateClientCard == 0) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 如果补卡时转移了退还金额,清空挂失卡余额 | 
 |  |  |      * @param operateType | 
 |  |  |      * @param cardId | 
 |  |  |      */ | 
 |  |  |     public void emptyCardBalance(Integer operateType, Long cardId) { | 
 |  |  |         SeCardOperate cardOperate = seCardOperateMapper.getCardOperate(operateType, cardId); | 
 |  |  |         if(cardOperate != null) { | 
 |  |  |             Float noTradeAmount = cardOperate.getNoTradeAmount(); | 
 |  |  |             if(noTradeAmount != null && noTradeAmount > 0) { | 
 |  |  |                 Long originalCardId = seClientCardMapper.getOriginalCardIdByCardId(cardId); | 
 |  |  |                 if(originalCardId != null) { | 
 |  |  |                     SeClientCard clientCard = new SeClientCard(); | 
 |  |  |                     clientCard.setId(cardId); | 
 |  |  |                     clientCard.setMoney(0f); | 
 |  |  |                     seClientCardMapper.updateByPrimaryKeySelective(clientCard); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改注销水卡表的记录及余额(0) | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Integer updateCancels(Integer operateType, Long cardId) { | 
 |  |  |         SeCardOperate cardOperate = seCardOperateMapper.getCardOperate(operateType, cardId); | 
 |  |  |         Date cancelTime = Optional.ofNullable(cardOperate.getOperateDt()).orElse(new Date()); | 
 |  |  |  | 
 |  |  |         SeClientCard clientCard = new SeClientCard(); | 
 |  |  |         clientCard.setId(cardId); | 
 |  |  |         clientCard.setCanceldt(cancelTime); | 
 |  |  |         clientCard.setMoney(0f); | 
 |  |  |         clientCard.setState(CardStateENUM.CANCELLED.getCode()); | 
 |  |  |         clientCard.setLastoper(LastOperateENUM.CANCEL.getCode()); | 
 |  |  |         return seClientCardMapper.updateByPrimaryKeySelective(clientCard); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 修改补扣水卡表的操作信息及余额 | 
 |  |  |      * @param operateType | 
 |  |  |      * @param cardId | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public Integer updateRefund(Integer operateType, Long cardId) { | 
 |  |  |         SeCardOperate cardOperate = seCardOperateMapper.getCardOperate(operateType, cardId); | 
 |  |  |         Date refundTime = Optional.ofNullable(cardOperate.getOperateDt()).orElse(new Date()); | 
 |  |  |         Float money = cardOperate.getMoney(); | 
 |  |  |         Float refund = cardOperate.getRefundAmount(); | 
 |  |  |  | 
 |  |  |         SeClientCard clientCard = new SeClientCard(); | 
 |  |  |         clientCard.setId(cardId); | 
 |  |  |         clientCard.setRefunddt(refundTime); | 
 |  |  |         clientCard.setMoney(money + refund); | 
 |  |  |         clientCard.setLastoper(LastOperateENUM.REFUND.getCode()); | 
 |  |  |         return seClientCardMapper.updateByPrimaryKeySelective(clientCard); | 
 |  |  |     } | 
 |  |  | } |