| | |
| | | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; |
| | | import com.dy.pipIrrGlobal.daoRm.RmOpenCloseValveHistoryMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.*; |
| | | import com.dy.pipIrrGlobal.pojoSe.*; |
| | | 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 org.springframework.stereotype.Service; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 添加开卡记录 |
| | | * |
| | | * @param po 水卡操作对象 |
| | | * @return 开卡记录主键 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据农户编号获取5级行政区划代码,开卡使用 |
| | | * |
| | | * @param clientNum 农户编号 |
| | | * @return 5级行政区划代码 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用 |
| | | * |
| | | * @param clientId |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据行政区划串模块查询水卡编号,开卡使用 |
| | | * |
| | | * @param areaCode |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据行政区划串模糊查询管理卡编号,创建管理卡使用 |
| | | * |
| | | * @param areaCode |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 创建管理卡 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据农户编号获取农户ID,开卡使用 |
| | | * |
| | | * @param clientNum |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 添加水卡操作对象,各操作都使用 |
| | | * |
| | | * @param po 水卡操作对象 |
| | | * @return 操作记录主键 |
| | | */ |
| | |
| | | /** |
| | | * 添加充值记录 |
| | | * 修改农户信息、添加水卡操作记录、添加充值记录 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | Long operator = po.getOperator(); |
| | | Date rechargeTime = new Date(); |
| | | |
| | | // 验证水卡状态是否支持当前操作 |
| | | // 获取水卡状态 |
| | | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse(""); |
| | | if(stateName.length() == 0 || !stateName.equals("正常")) { |
| | | |
| | | // 单独充值时卡片必须为正常 |
| | | 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()); |
| | | } |
| | | |
| | |
| | | clientId = Long.parseLong(map.get("clientId").toString()); |
| | | |
| | | /** |
| | | * 修改农户卡信息: |
| | | * 补卡时间 |
| | | * 最后操作类型-2 |
| | | */ |
| | | |
| | | // 根据支付方式ID获取支付方式名称 |
| | | SePaymentMethod sePaymentMethod = sePaymentMethodMapper.selectByPrimaryKey(paymentId); |
| | | String paymentName = sePaymentMethod.getName(); |
| | | |
| | | * 充值时不修改农户卡信息,收到成功通知后再修改:余额、充值时间、最后操作类型 |
| | | SeClientCard seClientCard = new SeClientCard(); |
| | | seClientCard.setId(cardId); |
| | | seClientCard.setMoney(afterRecharge); |
| | | seClientCard.setRechargedt(rechargeTime); |
| | | //if(paymentName != null && paymentName.equals("换卡")) { |
| | | // seClientCard.setLastoper(LastOperateENUM.CHANGE_RECHARGE.getCode ()); |
| | | //}else { |
| | | // seClientCard.setLastoper(LastOperateENUM.RECHARGE.getCode ()); |
| | | //} |
| | | 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()); |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 添加水卡充值操作记录 |
| | |
| | | seCardOperate.setMoney(money); |
| | | seCardOperate.setTradeAmount(amount); |
| | | seCardOperate.setGift(gift); |
| | | //if(paymentName != null && paymentName.equals("换卡")) { |
| | | // seCardOperate.setOperateType(OperateTypeENUM.CHANGE_RECHARGE.getCode()); |
| | | //}else { |
| | | // seCardOperate.setOperateType(OperateTypeENUM.RECHARGE.getCode()); |
| | | //} |
| | | seCardOperate.setOperateType(OperateTypeENUM.RECHARGE.getCode()); |
| | | seCardOperate.setPaymentId(paymentId); |
| | | seCardOperate.setPrice(price); |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取充值记录 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取充值记录,管理平台充值列表使用,APP未使用 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取返还记录,管理平台充值列表使用 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取水卡消费记录,管理平台使用 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取交易记录 |
| | | * |
| | | * @param vo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取开卡记录 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取补卡记录 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取通用操作记录 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据指定条件获取收据列表 |
| | | * |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 判断指定水卡是否为挂失状态且无补卡记录 |
| | | * |
| | | * @param cardNum 水卡编号 |
| | | * @return 是否已挂失未补卡 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 修改农户水卡 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取项目编号 |
| | | * |
| | | * @return |
| | | */ |
| | | public String getProjectNo() { |
| | |
| | | |
| | | /** |
| | | * 根据水卡编号获取其挂失时退款金额(补卡时判断使用) |
| | | * |
| | | * @param cardNum |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据水卡地址判断该卡是否可以开卡 |
| | | * |
| | | * @param cardAddr |
| | | * @return |
| | | */ |
| | | public Boolean canActiveCard(String cardAddr) { |
| | | |
| | | // 指定水卡地址的水卡数量 |
| | | // 指定水卡地址的水卡数量,无效卡片排除在外 |
| | | Long cardCount = Optional.ofNullable(seClientCardMapper.getCountByCardAddr(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); |
| | | } |
| | | } |