| | |
| | | package com.dy.pipIrrTerminal.card; |
| | | |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; |
| | |
| | | import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; |
| | | import com.dy.pipIrrGlobal.voSe.VoAfterRecharge; |
| | | import com.dy.pipIrrGlobal.voSe.VoTermActiveCard; |
| | | import com.dy.pipIrrGlobal.voSe.VoTermRecharge; |
| | | import com.dy.pipIrrGlobal.voSe.VoTermCommon; |
| | | import com.dy.pipIrrTerminal.card.dto.*; |
| | | import com.dy.pipIrrTerminal.card.enums.CardStateENUM; |
| | | import com.dy.pipIrrTerminal.card.enums.LastOperateENUM; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | card.setCardId(Long.parseLong(map_card.get("cardId").toString())); |
| | | card.setClientId(Long.parseLong(map_card.get("clientId").toString())); |
| | | card.setProtocol(map_card.get("protocol").toString()); |
| | | |
| | | map.put("success", true); |
| | | map.put("content", card); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以注销 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Map canCancel(DtoCancel po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | |
| | | Long cardNum = po.getCardNum(); |
| | | String stateName = seClientCardMapper.getCardStateByCardNum(cardNum); |
| | | if(stateName == null || stateName.equals("") || !stateName.equals("正常")) { |
| | | map.put("msg", stateName + ", " + "水卡状态不支持当前操作"); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 依据水卡编号获取水卡表主键及农户编号 |
| | | */ |
| | | Map map_card = Optional.ofNullable(seClientCardMapper.getCardIdAndClientNum(cardNum)).orElse(new HashMap()); |
| | | if (map_card == null || map_card.size() <= 0) { |
| | | map.put("msg", "卡号错误,该卡不存在"); |
| | | return map; |
| | | } |
| | | CardSimple card = new CardSimple(); |
| | | card.setCardId(Long.parseLong(map_card.get("cardId").toString())); |
| | | card.setClientId(Long.parseLong(map_card.get("clientId").toString())); |
| | | |
| | | map.put("success", true); |
| | | map.put("content", card); |
| | |
| | | return map; |
| | | } |
| | | |
| | | VoTermRecharge voTermRecharge = new VoTermRecharge(); |
| | | VoTermCommon voTermRecharge = new VoTermCommon(); |
| | | voTermRecharge.setProjectNo(projectNo); |
| | | voTermRecharge.setCardNum(po.getCardNum()); |
| | | voTermRecharge.setOrderNo(orderNo); |
| | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 挂失 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map reportLoss(DtoLoss po) { |
| | | Map map = new HashMap<>(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 销卡 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map cancel(DtoCancel po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | String orderNo = generateOrderNo(); |
| | | |
| | | Map map_canCancel = canCancel(po); |
| | | if(map_canCancel.get("success").equals(false)) { |
| | | map.put("msg", map_canCancel.get("msg").toString()); |
| | | return map; |
| | | } |
| | | CardSimple card = (CardSimple) map_canCancel.get("content"); |
| | | Long cardId = card.getCardId(); |
| | | Long clientId = card.getClientId(); |
| | | |
| | | SeCardOperate seCardOperate = new SeCardOperate(); |
| | | seCardOperate.setCardId(cardId); |
| | | seCardOperate.setClientId(clientId); |
| | | seCardOperate.setTradeAmount(-po.getRefund()); |
| | | seCardOperate.setPaymentId(po.getRefundType()); |
| | | seCardOperate.setOperateType(OperateTypeENUM.CANCEL.getCode()); |
| | | seCardOperate.setRemarks(po.getRemarks()); |
| | | seCardOperate.setOperator(po.getOperator()); |
| | | seCardOperate.setOperateDt(new Date()); |
| | | seCardOperate.setOrderNo(orderNo); |
| | | seCardOperate.setOperateValid((byte) 1); |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | if (seCardOperate.getId() == 0) { |
| | | map.put("msg", "销卡失败-销卡记录写入异常"); |
| | | return map; |
| | | } |
| | | |
| | | VoTermCommon voTermCandel = new VoTermCommon(); |
| | | voTermCandel.setProjectNo(projectNo); |
| | | voTermCandel.setCardNum(po.getCardNum()); |
| | | voTermCandel.setOrderNo(orderNo); |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | map.put("content", voTermCandel); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 操作回调 |
| | | * @param po |
| | | * @return |
| | |
| | | turnRechargeHistoryValidByOrderNumber(orderNumber); |
| | | updateCard(cardId, orderNumber+"p"); |
| | | } |
| | | } else if (operateType == 2) { |
| | | /** |
| | | * 充值操作执行通知 |
| | | * 1. 操作记录改为有效 |
| | | * 2. 充值历史记录改为有效 |
| | | * 3. 修改水卡表的操作信息 |
| | | */ |
| | | turnOperateValidByOrderNumber(orderNumber + "p"); |
| | | turnRechargeHistoryValidByOrderNumber(orderNumber); |
| | | updateCard(cardId, orderNumber+"p"); |
| | | }else if (operateType == 3) { |
| | | /** |
| | | * 销卡操作执行通知 |
| | | * 1. 操作记录改为有效 |
| | | * 2. 修改水卡表操作信息及余额 |
| | | */ |
| | | |
| | | Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); |
| | | Integer rec_card = updateCardInfo(cardId, orderNumber); |
| | | if (rec_ope == 0 || rec_card == 0) { |
| | | map.put("msg", "销卡回调失败"); |
| | | return map; |
| | | } |
| | | |
| | | } else if (operateType == 4) { |
| | | /** |
| | | * 补卡操作执行通知 |
| | | * 1. 新水卡记录改为有效 |
| | | * 2. 开卡操作记录改为有效 |
| | | * 3. 如果存在退还金额 |
| | | * 清空原卡余额 |
| | | */ |
| | | Integer rec_card = turnCardValidByOrderNumber(orderNumber); |
| | | Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); |
| | | emptyCardBalance(orderNumber); |
| | | if (rec_card == 0 || rec_ope == 0) { |
| | | map.put("msg", "补卡回调失败"); |
| | | return map; |
| | | } |
| | | |
| | | } |
| | | |
| | | map.put("success", true); |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 如果补卡时退还了金额,清空挂失卡余额 |
| | | * @param orderNumber |
| | | */ |
| | | public Integer emptyCardBalance(String orderNumber) { |
| | | Integer rec_empty = 0; |
| | | Float noTradeAmount = seCardOperateMapper.getNoTradeAmount(orderNumber); |
| | | if(noTradeAmount != null && noTradeAmount > 0) { |
| | | rec_empty = seClientCardMapper.emptyCardBalance(orderNumber); |
| | | } |
| | | return rec_empty; |
| | | } |
| | | |
| | | /** |
| | | * 修改注销水卡表的记录及余额(0) |
| | | * @param orderNumber |
| | | * @return |
| | | */ |
| | | public Integer updateCardInfo(Long cardId, String orderNumber) { |
| | | Date operateTime = seCardOperateMapper.getOperateTime(orderNumber); |
| | | |
| | | SeClientCard clientCard = new SeClientCard(); |
| | | clientCard.setId(cardId); |
| | | clientCard.setCanceldt(operateTime); |
| | | clientCard.setMoney(0f); |
| | | clientCard.setState(CardStateENUM.CANCELLED.getCode()); |
| | | clientCard.setLastoper(LastOperateENUM.CANCEL.getCode()); |
| | | return seClientCardMapper.updateByPrimaryKeySelective(clientCard); |
| | | } |
| | | } |