| | |
| | | package com.dy.pipIrrTerminal.card; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoPr.PrWaterPriceMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeRechargeHistoryMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.*; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeManagementCard; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeRechargeHistory; |
| | | import com.dy.pipIrrGlobal.voSe.VoTermActiveCard; |
| | | import com.dy.pipIrrGlobal.voSe.VoTermRecharge; |
| | | import com.dy.pipIrrGlobal.voSe.*; |
| | | import com.dy.pipIrrTerminal.card.dto.*; |
| | | import com.dy.pipIrrTerminal.card.qo.QoCards; |
| | | import com.dy.pipIrrTerminal.card.qo.QoLostCards; |
| | | import com.dy.pipIrrTerminal.card.enums.CardStateENUM; |
| | | import com.dy.pipIrrTerminal.card.enums.LastOperateENUM; |
| | | import com.dy.pipIrrTerminal.card.enums.ManagementCardStateENUM; |
| | | import com.dy.pipIrrTerminal.card.enums.OperateTypeENUM; |
| | | import com.dy.pipIrrTerminal.card.enums.RechargeTypeENUM; |
| | | import com.dy.pipIrrTerminal.card.qo.QoTransaction; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | import com.dy.common.util.IDLongGenerator; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | @Autowired |
| | | private SeRechargeHistoryMapper seRechargeHistoryMapper; |
| | | |
| | | @Autowired |
| | | private SeManagerCardMapper seManagerCardMapper; |
| | | |
| | | @Autowired |
| | | private SeManagementCardMapper seManagementCardMapper; |
| | | |
| | | @Autowired |
| | | private IDLongGenerator idLongGenerator; |
| | | |
| | | @Value("${project.projectNo}") |
| | | private Integer projectNo; |
| | | |
| | | /** |
| | | * 根据水卡地址判断该卡是否可以开卡 |
| | | * |
| | | * @param cardAddr |
| | | * @return true:可以开卡 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以充值 |
| | | * |
| | | * @param po |
| | | * @return true:可以充值 |
| | | */ |
| | |
| | | |
| | | String stateName = Optional.ofNullable(seClientCardMapper.getCardStateByCardNum(po.getCardNum())).orElse(""); |
| | | // 单独充值时卡片必须为正常 |
| | | if((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("正常")) { |
| | | if ((po.getRechargeType() == RechargeTypeENUM.RECHARGE.getCode()) && !stateName.equals("正常")) { |
| | | map.put("msg", stateName + ", " + "水卡状态不支持当前操作"); |
| | | return map; |
| | | } |
| | |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以挂失 |
| | | * |
| | | * @param po |
| | | * @return true:可以报失 |
| | | */ |
| | |
| | | |
| | | Long cardNum = po.getCardNum(); |
| | | String stateName = seClientCardMapper.getCardStateByCardNum(cardNum); |
| | | if(stateName == null || stateName.equals("") || !stateName.equals("正常")) { |
| | | if (stateName == null || stateName.equals("") || !stateName.equals("正常")) { |
| | | map.put("msg", stateName + ", " + "水卡状态不支持当前操作"); |
| | | return map; |
| | | } |
| | |
| | | CardSimple card = new CardSimple(); |
| | | 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()); |
| | | // card.setProtocol(map_card.get("protocol").toString()); |
| | | |
| | | map.put("success", true); |
| | | map.put("content", card); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以解锁 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Map canUnlock(DtoUnlock po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | |
| | | Long cardNum = po.getCardNum(); |
| | | // 判断当前水卡是否为挂失状态且未补卡,仅已经挂失其未补卡的可以解锁 |
| | | if (!isLostAndUnreplaced(cardNum)) { |
| | | map.put("msg", "水卡状态不支持当前操作"); |
| | | 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); |
| | |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以补卡 |
| | | * |
| | | * @param po |
| | | * @return true:可以补卡 |
| | | */ |
| | |
| | | Long cardNum = po.getCardNum(); |
| | | Integer lostCount = seClientCardMapper.getLostCount(cardNum); |
| | | Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum); |
| | | if(lostCount == 0 || replacedCount > 0) { |
| | | if (lostCount == 0 || replacedCount > 0) { |
| | | map.put("msg", "水卡未挂失或已补卡,不能补卡"); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以补扣 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Map canRepay(DtoRepaySupplement 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; |
| | | } |
| | | |
| | | /** |
| | | * 根据水卡编号判断该卡是否可以返还 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Map canSupplement(DtoRepaySupplement 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; |
| | | } |
| | | |
| | | /** |
| | | * 根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用 |
| | | * |
| | | * @param clientId |
| | | * @return |
| | | */ |
| | |
| | | seClientCard.setClientid(po.getClientId()); |
| | | seClientCard.setMoney(po.getAmount()); |
| | | seClientCard.setState(CardStateENUM.INVALID.getCode()); |
| | | seClientCard.setOrderNo(orderNo); |
| | | if (po.getOriginalCardId() != null) { |
| | | // 补卡 |
| | | seClientCard.setOriginalCardId(po.getOriginalCardId()); |
| | |
| | | |
| | | /** |
| | | * 开卡附加充值 |
| | | * |
| | | * @param po |
| | | * @param cardNum |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map plusRecharge(ActiveCard po, Long cardNum) { |
| | | public Map plusRecharge(ActiveCard po, Long cardNum, String orderNo) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | |
| | | dtoRecharge.setMoney(0f); |
| | | dtoRecharge.setGift(0f); |
| | | dtoRecharge.setPrice(0f); |
| | | Map map_plusRecharge = addRecharge(dtoRecharge); |
| | | Map map_plusRecharge = addRecharge(dtoRecharge, orderNo); |
| | | if (!map_plusRecharge.get("success").equals(true)) { |
| | | map.put("msg", "开卡失败-充值异常"); |
| | | return map; |
| | |
| | | |
| | | /** |
| | | * 激活或补卡 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | Map map_cardNum = generateCardNum(po.getClientId()); |
| | | if(map_cardNum.get("success").equals(false)) { |
| | | if (map_cardNum.get("success").equals(false)) { |
| | | map.put("msg", map_cardNum.get("msg").toString()); |
| | | return map; |
| | | } |
| | |
| | | |
| | | String orderNo = generateOrderNo(); |
| | | Map map_addCardAndOperate = addCardAndOperate(po, cardNum, orderNo); |
| | | if(map_addCardAndOperate.get("success").equals(false)) { |
| | | if (map_addCardAndOperate.get("success").equals(false)) { |
| | | map.put("msg", map_addCardAndOperate.get("msg").toString()); |
| | | return map; |
| | | } |
| | | |
| | | if (amount != null && amount > 0 && originalCardId == null) { |
| | | Map map_plusRecharge = plusRecharge(po, cardNum); |
| | | if(map_plusRecharge.get("success").equals(false)) { |
| | | Map map_plusRecharge = plusRecharge(po, cardNum, orderNo); |
| | | if (map_plusRecharge.get("success").equals(false)) { |
| | | map.put("msg", map_plusRecharge.get("msg").toString()); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | Float balance = Optional.ofNullable(seClientCardMapper.getMoneyByCardNum(cardNum)).orElse(0f); |
| | | Float balance = Optional.ofNullable(seClientCardMapper.getMoneyByCardNum(cardNum, null)).orElse(0f); |
| | | Double waterPrice = prWaterPriceMapper.getPrice(); |
| | | |
| | | VoTermActiveCard voTermActiveCard = new VoTermActiveCard(); |
| | |
| | | |
| | | /** |
| | | * 充值 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map addRecharge(DtoRecharge po) { |
| | | public Map addRecharge(DtoRecharge po, String orderNo) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | |
| | | Map map_canRecharge = canRecharge(po); |
| | | if(map_canRecharge.get("success").equals(false)) { |
| | | if (map_canRecharge.get("success").equals(false)) { |
| | | map.put("msg", map_canRecharge.get("msg").toString()); |
| | | return map; |
| | | } |
| | |
| | | } |
| | | Long cardId = Long.parseLong(map_cardAndClient.get("cardId").toString()); |
| | | Long clientId = Long.parseLong(map_cardAndClient.get("clientId").toString()); |
| | | String orderNo = generateOrderNo(); |
| | | if (orderNo == null || orderNo.length() <= 0) { |
| | | orderNo = generateOrderNo(); |
| | | } |
| | | |
| | | /** |
| | | * 添加水卡充值操作记录 |
| | |
| | | seCardOperate.setRemarks(po.getRemarks()); |
| | | seCardOperate.setOperator(po.getOperator()); |
| | | seCardOperate.setOperateDt(new Date()); |
| | | seCardOperate.setOrderNo(orderNo); |
| | | seCardOperate.setOrderNo(orderNo + "p"); |
| | | seCardOperate.setOperateValid((byte) 1); |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); |
| | |
| | | seRechargeHistory.setOperator(po.getOperator()); |
| | | seRechargeHistory.setOperatedt(new Date()); |
| | | seRechargeHistory.setOperateValid((byte) 1); |
| | | seRechargeHistory.setOrderNo(orderNo); |
| | | seRechargeHistoryMapper.insert(seRechargeHistory); |
| | | Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); |
| | | if (rec_seRechargeHistory == 0) { |
| | |
| | | return map; |
| | | } |
| | | |
| | | VoTermRecharge voTermRecharge = new VoTermRecharge(); |
| | | VoTermCommon voTermRecharge = new VoTermCommon(); |
| | | voTermRecharge.setProjectNo(projectNo); |
| | | voTermRecharge.setCardNum(po.getCardNum()); |
| | | voTermRecharge.setOrderNo(orderNo); |
| | | voTermRecharge.setBalance(afterRecharge); |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | |
| | | |
| | | /** |
| | | * 补卡 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | map.put("content", null); |
| | | |
| | | Map map_canReissue = canReissue(po); |
| | | if(map_canReissue.get("success").equals(false)) { |
| | | if (map_canReissue.get("success").equals(false)) { |
| | | map.put("msg", map_canReissue.get("msg").toString()); |
| | | return map; |
| | | } |
| | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 挂失 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map reportLoss(DtoLoss po) { |
| | | Map map = new HashMap<>(); |
| | |
| | | map.put("content", null); |
| | | |
| | | Map map_canReportLoss = canReportLoss(po); |
| | | if(map_canReportLoss.get("success").equals(false)) { |
| | | if (map_canReportLoss.get("success").equals(false)) { |
| | | map.put("msg", map_canReportLoss.get("msg").toString()); |
| | | return map; |
| | | } |
| | |
| | | seClientCard.setLossdtdt(new Date()); |
| | | seClientCard.setState(CardStateENUM.LOSS.getCode()); |
| | | seClientCard.setLastoper(LastOperateENUM.LOSS.getCode()); |
| | | Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)).orElse(0); |
| | | Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)) |
| | | .orElse(0); |
| | | if (rec_updateClientCard == 0) { |
| | | map.put("msg", "挂失失败-农户卡修改异常"); |
| | | return map; |
| | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 解锁 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map unlock(DtoUnlock po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | |
| | | Map map_canUnlock = canUnlock(po); |
| | | if (map_canUnlock.get("success").equals(false)) { |
| | | map.put("msg", map_canUnlock.get("msg").toString()); |
| | | return map; |
| | | } |
| | | CardSimple card = (CardSimple) map_canUnlock.get("content"); |
| | | Long cardId = card.getCardId(); |
| | | Long clientId = card.getClientId(); |
| | | |
| | | /** |
| | | * 修改农户卡信息: |
| | | * 挂失时间 |
| | | * 最后操作类型-4 |
| | | */ |
| | | SeClientCard seClientCard = new SeClientCard(); |
| | | seClientCard.setId(cardId); |
| | | seClientCard.setUnlockdt(new Date()); |
| | | seClientCard.setMoney(po.getMoney()); |
| | | seClientCard.setState(CardStateENUM.NORMAL.getCode()); |
| | | seClientCard.setLastoper(LastOperateENUM.UNLOCK.getCode()); |
| | | Integer rec_updateClientCard = Optional.ofNullable(seClientCardMapper.updateByPrimaryKeySelective(seClientCard)) |
| | | .orElse(0); |
| | | if (rec_updateClientCard == 0) { |
| | | map.put("msg", "解锁失败-农户卡修改异常"); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 添加解锁记录 |
| | | */ |
| | | SeCardOperate seCardOperate = new SeCardOperate(); |
| | | seCardOperate.setCardId(cardId); |
| | | seCardOperate.setClientId(clientId); |
| | | seCardOperate.setMoney(po.getMoney()); |
| | | seCardOperate.setOperateType(OperateTypeENUM.UNLOCK.getCode()); |
| | | seCardOperate.setRemarks(po.getRemarks()); |
| | | seCardOperate.setOperator(po.getOperator()); |
| | | seCardOperate.setOperateDt(new Date()); |
| | | seCardOperate.setOperateValid((byte) 2); |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); |
| | | if (rec == 0) { |
| | | map.put("msg", "解锁失败-解锁记录写入异常"); |
| | | return map; |
| | | } |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 销卡 |
| | | * |
| | | * @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 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map repay(DtoRepaySupplement po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | String orderNo = generateOrderNo(); |
| | | Date operateTime = new Date(); |
| | | Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0); |
| | | |
| | | Map map_canRepay = canRepay(po); |
| | | if (map_canRepay.get("success").equals(false)) { |
| | | map.put("msg", map_canRepay.get("msg").toString()); |
| | | return map; |
| | | } |
| | | CardSimple card = (CardSimple) map_canRepay.get("content"); |
| | | Long cardId = card.getCardId(); |
| | | Long clientId = card.getClientId(); |
| | | |
| | | SeCardOperate seCardOperate = new SeCardOperate(); |
| | | seCardOperate.setCardId(cardId); |
| | | seCardOperate.setClientId(clientId); |
| | | seCardOperate.setMoney(po.getBalance()); |
| | | seCardOperate.setRefundAmount(po.getRepayMorny()); |
| | | seCardOperate.setOperateType(OperateTypeENUM.REFUND.getCode()); |
| | | seCardOperate.setRemarks(po.getRemarks()); |
| | | seCardOperate.setOperator(po.getOperator()); |
| | | seCardOperate.setOperateDt(operateTime); |
| | | seCardOperate.setOrderNo(orderNo); |
| | | seCardOperate.setOperateValid((byte) 1); |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | if (seCardOperate.getId() == 0) { |
| | | map.put("msg", "补扣失败-补扣记录写入异常"); |
| | | return map; |
| | | } |
| | | |
| | | VoRepaySupplement voRepaySupplement = new VoRepaySupplement(); |
| | | voRepaySupplement.setBalance(po.getBalance() - po.getRepayMorny()); |
| | | voRepaySupplement.setWaterPrice(waterPrice); |
| | | voRepaySupplement.setTime(operateTime); |
| | | voRepaySupplement.setOrderNo(orderNo); |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | map.put("content", voRepaySupplement); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 返还 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map supplement(DtoRepaySupplement po) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | String orderNo = generateOrderNo(); |
| | | Date operateTime = new Date(); |
| | | Double waterPrice = Optional.ofNullable(prWaterPriceMapper.getPrice()).orElse(0.0); |
| | | |
| | | Map map_canSupplement = canSupplement(po); |
| | | if (map_canSupplement.get("success").equals(false)) { |
| | | map.put("msg", map_canSupplement.get("msg").toString()); |
| | | return map; |
| | | } |
| | | CardSimple card = (CardSimple) map_canSupplement.get("content"); |
| | | Long cardId = card.getCardId(); |
| | | Long clientId = card.getClientId(); |
| | | |
| | | SeCardOperate seCardOperate = new SeCardOperate(); |
| | | seCardOperate.setCardId(cardId); |
| | | seCardOperate.setClientId(clientId); |
| | | seCardOperate.setMoney(po.getBalance()); |
| | | seCardOperate.setRefundAmount(po.getSupplementMoney()); |
| | | seCardOperate.setOperateType(OperateTypeENUM.SUPPLEMENT.getCode()); |
| | | seCardOperate.setRemarks(po.getRemarks()); |
| | | seCardOperate.setOperator(po.getOperator()); |
| | | seCardOperate.setOperateDt(operateTime); |
| | | seCardOperate.setOrderNo(orderNo); |
| | | seCardOperate.setOperateValid((byte) 1); |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | if (seCardOperate.getId() == 0) { |
| | | map.put("msg", "返还失败-返还记录写入异常"); |
| | | return map; |
| | | } |
| | | VoRepaySupplement voRepaySupplement = new VoRepaySupplement(); |
| | | voRepaySupplement.setBalance(po.getBalance() + po.getSupplementMoney()); |
| | | voRepaySupplement.setWaterPrice(waterPrice); |
| | | voRepaySupplement.setTime(operateTime); |
| | | voRepaySupplement.setOrderNo(orderNo); |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | map.put("content", voRepaySupplement); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 操作回调 |
| | | * |
| | | * @param po |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map callBack(DtoCallBack po) { |
| | | Map map = new HashMap<>(); |
| | |
| | | Integer operateType = po.getOperateType(); |
| | | String orderNumber = po.getOrderNumber(); |
| | | |
| | | // 先检查是否为管理卡 |
| | | if (operateType.equals(OperateTypeENUM.MANAGEMENT_CARD_WRITE.getCode().intValue())) { |
| | | // 管理类型卡写卡逻辑 |
| | | return handleManagementCardWrite(cardAddr, orderNumber); |
| | | } |
| | | |
| | | // 处理农户卡逻辑 |
| | | Long cardId = seClientCardMapper.getCardIdByAddr(cardAddr); |
| | | if (cardId == null || cardId.equals(0)) { |
| | | map.put("msg", "您指定的水卡不存在"); |
| | | return map; |
| | | } |
| | | |
| | | if(operateType == 1) { |
| | | if (operateType.equals(OperateTypeENUM.ACTIVE.getCode().intValue())) { |
| | | /** |
| | | * 开卡操作执行通知 |
| | | * 1.依据水卡地址、订单号将无效状态的操作记录改为有效 |
| | | * 2.依据水卡ID将无效状态的水卡记录改为有效 |
| | | * 3.如果开卡同步充值 |
| | | * 修改充值操作记录为有效 |
| | | * 修改充值历史记录为有效 |
| | | * 修改水卡表的操作信息 |
| | | * 1.依据订单号将无效状态的操作记录改为有效 |
| | | * 2.依据水卡ID将无效状态的水卡记录改为有效 |
| | | * 3.如果开卡同步充值 |
| | | * 修改充值操作记录为有效 |
| | | * 修改充值历史记录为有效 |
| | | * 修改水卡表的操作信息 |
| | | */ |
| | | Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); |
| | | Integer rec_card = turnCardValidByOrderNumber(orderNumber); |
| | | if (rec_ope == 0 || rec_card == 0) { |
| | | map.put("msg", "不存在未生效的水卡"); |
| | | return map; |
| | | } |
| | | |
| | | if (isMergeRecharge(cardId)) { |
| | | turnOperateValidByOrderNumber(orderNumber + "p"); |
| | | turnRechargeHistoryValidByOrderNumber(orderNumber); |
| | | updateCard(cardId, orderNumber + "p"); |
| | | } |
| | | } else if (operateType.equals(OperateTypeENUM.RECHARGE.getCode().intValue())) { |
| | | /** |
| | | * 充值操作执行通知 |
| | | * 1. 操作记录改为有效 |
| | | * 2. 充值历史记录改为有效 |
| | | * 3. 修改水卡表的操作信息 |
| | | */ |
| | | turnOperateValidByOrderNumber(orderNumber + "p"); |
| | | turnRechargeHistoryValidByOrderNumber(orderNumber); |
| | | updateCard(cardId, orderNumber + "p"); |
| | | } else if (operateType.equals(OperateTypeENUM.CANCEL.getCode().intValue())) { |
| | | /** |
| | | * 销卡操作执行通知 |
| | | * 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.equals(OperateTypeENUM.REISSUE.getCode().intValue())) { |
| | | /** |
| | | * 补卡操作执行通知 |
| | | * 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; |
| | | } |
| | | } else if (operateType.equals(OperateTypeENUM.REFUND.getCode().intValue())) { |
| | | /** |
| | | * 补扣操作执行通知 |
| | | * 1. 操作记录改为有效 |
| | | * 2. 修改水卡表操作信息及余额 |
| | | */ |
| | | Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); |
| | | Integer rec_card = updateCardInfo_repay(cardId, orderNumber); |
| | | if (rec_ope == 0 || rec_card == 0) { |
| | | map.put("msg", "补扣回调失败"); |
| | | return map; |
| | | } |
| | | } else if (operateType.equals(OperateTypeENUM.SUPPLEMENT.getCode().intValue())) { |
| | | /** |
| | | * 返还操作执行通知 |
| | | * 1. 操作记录改为有效 |
| | | * 2. 修改水卡表操作信息及余额 |
| | | */ |
| | | Integer rec_ope = turnOperateValidByOrderNumber(orderNumber); |
| | | Integer rec_card = updateCardInfo_supplement(cardId, orderNumber); |
| | | if (rec_ope == 0 || rec_card == 0) { |
| | | map.put("msg", "返还回调失败"); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | map.put("success", true); |
| | | map.put("msg", "操作成功"); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 处理管理类型卡写卡回调 |
| | | * |
| | | * @param cardAddr 卡地址 |
| | | * @param orderNumber 订单号 |
| | | * @return 处理结果 |
| | | */ |
| | | private Map<String, Object> handleManagementCardWrite(String cardAddr, String orderNumber) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("content", null); |
| | | |
| | | try { |
| | | // 根据卡地址和订单号查找管理卡 |
| | | SeManagementCard managementCard = seManagementCardMapper.selectOne( |
| | | com.baomidou.mybatisplus.core.toolkit.Wrappers.<SeManagementCard>lambdaQuery() |
| | | .eq(SeManagementCard::getCardAddr, cardAddr) |
| | | .eq(SeManagementCard::getOrderNo, orderNumber)); |
| | | |
| | | if (managementCard == null) { |
| | | map.put("msg", "未找到对应的管理卡记录"); |
| | | return map; |
| | | } |
| | | |
| | | // 更新管理卡状态为正常 |
| | | managementCard.setState(ManagementCardStateENUM.NORMAL.getCode()); |
| | | |
| | | int updateResult = seManagementCardMapper.updateByPrimaryKeySelective(managementCard); |
| | | if (updateResult > 0) { |
| | | map.put("success", true); |
| | | map.put("msg", "管理卡写卡完成,状态已更新为正常"); |
| | | } else { |
| | | map.put("msg", "管理卡状态更新失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("处理管理卡写卡回调异常", e); |
| | | map.put("msg", "处理管理卡写卡回调时发生异常:" + e.getMessage()); |
| | | } |
| | | |
| | | return map; |
| | | } |
| | | |
| | | // 根据订单号将操作记录改为有效 |
| | | public Integer turnOperateValidByOrderNumber(String orderNumber) { |
| | | return seCardOperateMapper.turnOperateValidByOrderNumber(orderNumber); |
| | | } |
| | | |
| | | // 根据订单号将水卡改为有效 |
| | | public Integer turnCardValidByOrderNumber(String orderNumber) { |
| | | return seClientCardMapper.turnCardValidByOrderNumber(orderNumber); |
| | | } |
| | | |
| | | // 根据订单号将充值历史改为有效 |
| | | public Integer turnRechargeHistoryValidByOrderNumber(String orderNumber) { |
| | | return seRechargeHistoryMapper.turnRechargeHistoryValidByOrderNumber(orderNumber); |
| | | } |
| | | |
| | | // 根据cardId判断是否是合并充值 |
| | | public Boolean isMergeRecharge(Long cardId) { |
| | | Integer plusRechargeCount = seCardOperateMapper.getPlusRechargeCount(cardId); |
| | | if (plusRechargeCount == 0) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // 修改水卡信息 |
| | | public Boolean updateCard(Long cardId, String orderNumber) { |
| | | VoAfterRecharge voAfterRecharge = seCardOperateMapper.getBalanceAfterRecharge(orderNumber); |
| | | |
| | | SeClientCard clientCard = new SeClientCard(); |
| | | clientCard.setId(cardId); |
| | | clientCard.setMoney(voAfterRecharge.getBalanceAfterRecharge()); |
| | | clientCard.setRechargedt(voAfterRecharge.getOperateTime()); |
| | | clientCard.setLastoper(LastOperateENUM.RECHARGE.getCode()); |
| | | Integer rec_updateClientCard = seClientCardMapper.updateByPrimaryKeySelective(clientCard); |
| | | if (rec_updateClientCard == null || rec_updateClientCard == 0) { |
| | | return false; |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 修改补扣水卡表记录及余额 |
| | | * |
| | | * @param cardId |
| | | * @param orderNumber |
| | | * @return |
| | | */ |
| | | public Integer updateCardInfo_repay(Long cardId, String orderNumber) { |
| | | VoRepaySupplementSimple po = seCardOperateMapper.getCardOperateByOrderNumber(orderNumber); |
| | | Float money = Optional.ofNullable(po.getMoney()).orElse(0f); |
| | | Float refundAmount = Optional.ofNullable(po.getRefundAmount()).orElse(0f); |
| | | Date operateTime = po.getOperateTime(); |
| | | |
| | | SeClientCard clientCard = new SeClientCard(); |
| | | clientCard.setId(cardId); |
| | | clientCard.setRefunddt(operateTime); |
| | | clientCard.setMoney(money - refundAmount); |
| | | clientCard.setState(CardStateENUM.NORMAL.getCode()); |
| | | clientCard.setLastoper(LastOperateENUM.REFUND.getCode()); |
| | | return seClientCardMapper.updateByPrimaryKeySelective(clientCard); |
| | | } |
| | | |
| | | /** |
| | | * 修改返还水卡表记录及余额 |
| | | * |
| | | * @param cardId |
| | | * @param orderNumber |
| | | * @return |
| | | */ |
| | | public Integer updateCardInfo_supplement(Long cardId, String orderNumber) { |
| | | VoRepaySupplementSimple po = seCardOperateMapper.getCardOperateByOrderNumber(orderNumber); |
| | | Float money = Optional.ofNullable(po.getMoney()).orElse(0f); |
| | | Float refundAmount = Optional.ofNullable(po.getRefundAmount()).orElse(0f); |
| | | Date operateTime = po.getOperateTime(); |
| | | |
| | | SeClientCard clientCard = new SeClientCard(); |
| | | clientCard.setId(cardId); |
| | | clientCard.setRefunddt(operateTime); |
| | | clientCard.setMoney(money + refundAmount); |
| | | clientCard.setState(CardStateENUM.NORMAL.getCode()); |
| | | clientCard.setLastoper(LastOperateENUM.WRITE_BACK.getCode()); |
| | | return seClientCardMapper.updateByPrimaryKeySelective(clientCard); |
| | | } |
| | | |
| | | /** |
| | | * 判断指定水卡是否为挂失状态且无补卡记录 |
| | | * |
| | | * @param cardNum |
| | | * @return |
| | | */ |
| | | public Boolean isLostAndUnreplaced(Long cardNum) { |
| | | Integer lostCount = seClientCardMapper.getLostCount(cardNum); |
| | | Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum); |
| | | if (lostCount > 0 && replacedCount == 0) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 读取水卡信息 |
| | | * |
| | | * @param cardAddr |
| | | * @return |
| | | */ |
| | | public VoTermCard readCard(String cardAddr) { |
| | | VoTermCard voTermCard = seClientCardMapper.getTermCardInfo(cardAddr); |
| | | if (voTermCard != null) { |
| | | return voTermCard; |
| | | } |
| | | |
| | | VoTermCard voTermManagerCard = seManagerCardMapper.getTermManagerCardInfo(cardAddr); |
| | | if (voTermManagerCard != null) { |
| | | return voTermManagerCard; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据指定条件获取水卡列表 |
| | | * |
| | | * @param vo 查询条件 |
| | | * @return 水卡列表 |
| | | */ |
| | | public QueryResultVo<List<VoCards>> getCards(QoCards vo) { |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo); |
| | | Long itemTotal = seClientCardMapper.getCardsCount(params); |
| | | |
| | | QueryResultVo<List<VoCards>> rsVo = new QueryResultVo<>(); |
| | | rsVo.pageSize = vo.pageSize; |
| | | rsVo.pageCurr = vo.pageCurr; |
| | | |
| | | if (itemTotal > 0) { |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | List<VoCards> list = seClientCardMapper.getCards(params); |
| | | rsVo.obj = list; |
| | | } else { |
| | | rsVo.obj = new ArrayList<>(); |
| | | rsVo.itemTotal = 0L; |
| | | } |
| | | |
| | | return rsVo; |
| | | } |
| | | |
| | | /** |
| | | * 获取已挂失的水卡列表 |
| | | * |
| | | * @param vo 查询条件 |
| | | * @return 已挂失的水卡列表 |
| | | */ |
| | | public QueryResultVo<List<VoCards>> getLostCards(QoLostCards vo) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("pageCurr", vo.pageCurr); |
| | | params.put("pageSize", vo.pageSize); |
| | | params.put("state", 2); // 挂失状态 |
| | | |
| | | Long itemTotal = seClientCardMapper.getLostCardsCount(params); |
| | | |
| | | QueryResultVo<List<VoCards>> rsVo = new QueryResultVo<>(); |
| | | rsVo.pageSize = vo.pageSize; |
| | | rsVo.pageCurr = vo.pageCurr; |
| | | |
| | | if (itemTotal > 0) { |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | List<VoCards> list = seClientCardMapper.getLostCards(params); |
| | | rsVo.obj = list; |
| | | } else { |
| | | rsVo.obj = new ArrayList<>(); |
| | | rsVo.itemTotal = 0L; |
| | | } |
| | | |
| | | return rsVo; |
| | | } |
| | | |
| | | /** |
| | | * 根据水卡编号获取卡信息 |
| | | * |
| | | * @param cardNum 水卡编号 |
| | | * @return 卡信息 |
| | | */ |
| | | public VoCardByClientNum getCardByCardNum(String cardNum) { |
| | | return seClientCardMapper.getCardByCardNum(cardNum); |
| | | } |
| | | |
| | | /** |
| | | * 创建管理卡 |
| | | * |
| | | * @param dto 创建管理卡DTO |
| | | * @return 创建结果 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Map<String, Object> createManagementCard(CreateManagementCardDto dto) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("success", false); |
| | | |
| | | try { |
| | | // 检查卡地址是否已存在 |
| | | if (isCardAddrExists(dto.getCardAddr())) { |
| | | result.put("msg", "创建失败-此卡地址已存在"); |
| | | return result; |
| | | } |
| | | |
| | | // 参考termActiveCard逻辑:生成订单号 |
| | | String orderNo = generateOrderNo(); |
| | | |
| | | // 使用IDLongGenerator生成唯一ID |
| | | Long id = idLongGenerator.generate(); |
| | | Date createTime = new Date(); |
| | | |
| | | // 构建管理卡对象 |
| | | SeManagementCard managementCard = SeManagementCard.builder() |
| | | .id(id) |
| | | .protocol(dto.getProtocol()) |
| | | .cardAddr(dto.getCardAddr()) |
| | | .securityCode(dto.getSecurityCode()) |
| | | .cardType(dto.getCardType()) |
| | | .createTime(createTime) |
| | | .orderNo(orderNo) |
| | | .districtCode(dto.getDistrictCode()) |
| | | .projectNo(dto.getProjectNo() != null ? dto.getProjectNo() : this.projectNo) |
| | | .ip(dto.getIp()) |
| | | .domain(dto.getDomain()) |
| | | .openClostTime(dto.getOpenClostTime()) |
| | | .remarks(dto.getRemarks()) |
| | | .state(ManagementCardStateENUM.UNWRITTEN.getCode()) // 默认状态为未写卡 |
| | | .build(); |
| | | |
| | | // 插入数据库 |
| | | int insertResult = seManagementCardMapper.insertSelective(managementCard); |
| | | |
| | | if (insertResult > 0) { |
| | | result.put("success", true); |
| | | result.put("content", orderNo); // 返回订单号 |
| | | result.put("msg", "请求成功"); |
| | | } else { |
| | | result.put("msg", "管理卡创建失败-数据库插入异常"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("创建管理卡异常: {}", e.getMessage(), e); |
| | | result.put("msg", "管理卡创建失败: " + e.getMessage()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 检查卡片地址是否已存在 |
| | | * |
| | | * @param cardAddr 卡片地址 |
| | | * @return true-已存在,false-不存在 |
| | | */ |
| | | public boolean isCardAddrExists(String cardAddr) { |
| | | // 使用一次查询检查两个表中是否存在该卡地址 |
| | | // 1. 管理卡表:所有记录都检查 |
| | | // 2. 农户水卡表:只检查正常(1)和挂失(3)状态的记录 |
| | | Long totalCount = seClientCardMapper.checkCardAddrExists(cardAddr); |
| | | return totalCount != null && totalCount > 0; |
| | | } |
| | | |
| | | /** |
| | | * 根据指定条件获取交易记录 |
| | | * |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | public Map getTransactions(QoTransaction vo) { |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | | // 补齐查询时间 |
| | | String operateTimeStart = vo.operateTimeStart; |
| | | String operateTimeStop = vo.operateTimeStop; |
| | | if (operateTimeStart != null) { |
| | | operateTimeStart = operateTimeStart + " 00:00:00"; |
| | | vo.setOperateTimeStart(operateTimeStart); |
| | | } |
| | | if (operateTimeStop != null) { |
| | | operateTimeStop = operateTimeStop + " 23:59:59"; |
| | | vo.setOperateTimeStop(operateTimeStop); |
| | | } |
| | | |
| | | // 生成查询参数 |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo); |
| | | |
| | | // 获取符合条件的记录数 |
| | | Long itemTotal = Optional.ofNullable(seCardOperateMapper.getTransactionRecordCount(params)).orElse(0L); |
| | | |
| | | 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(); |
| | | } |
| | | //元谋一期陆常丽需求把赠送金额与充值金额分开显示 |
| | | for (int i = list.size()-1; i >= 0 ; i--) { |
| | | Optional.ofNullable(list.get(i).getGift()).orElse(0d); |
| | | if (!list.get(i).getGift().equals(0d)){ |
| | | Double gift1 = list.get(i).getGift();//赠送金额 |
| | | String districtTitle = list.get(i).getDistrictTitle();//地址 |
| | | String clientNum = list.get(i).getClientNum();//农户编号 |
| | | String clientName = list.get(i).getClientName();//农户姓名 |
| | | String phone = list.get(i).getPhone();//手机号 |
| | | Date tradeTime = list.get(i).getTradeTime();//交易时间 |
| | | String orderNumber = list.get(i).getOrderNumber();//订单编号 |
| | | String cardNum = list.get(i).getCardNum();//卡编号 |
| | | String idCard = list.get(i).getIdCard();//身份证 |
| | | String cashierName = list.get(i).getCashierName();//操作人 |
| | | Double money = list.get(i).getMoney();//余额 |
| | | Double cardCost1 = list.get(i).getCardCost();//购卡金额 |
| | | Double tradeAmount = list.get(i).getTradeAmount();//交易金额 |
| | | Double waterCost1 = list.get(i).getWaterCost();//购水金额 |
| | | Double refundAmount1 = list.get(i).getRefundAmount();//返回金额 |
| | | String paymentName = list.get(i).getPaymentName();//支付方式 |
| | | String operateType = list.get(i).getOperateType();//业务类型 |
| | | String cardState = list.get(i).getCardState();//卡状态 |
| | | Long villageId = list.get(i).getVillageId();//村id |
| | | Long cashierId = list.get(i).getCashierId();//收银员id |
| | | |
| | | list.get(i).setGift(0d); |
| | | list.get(i).setMoney(money-gift1); |
| | | |
| | | VoTradeDetails voTradeDetail = new VoTradeDetails(); |
| | | voTradeDetail.setDistrictTitle(districtTitle);//2 |
| | | voTradeDetail.setClientNum(clientNum);//2 |
| | | voTradeDetail.setClientName(clientName);//2 |
| | | voTradeDetail.setPhone(phone);//2 |
| | | voTradeDetail.setOperateType("赠送");//2 |
| | | voTradeDetail.setTradeTime(tradeTime);//2 |
| | | voTradeDetail.setWaterCost(0d);//2 |
| | | voTradeDetail.setCardCost(0d);//2 |
| | | voTradeDetail.setGift(gift1);//2 |
| | | voTradeDetail.setTradeAmount(0d);//2 |
| | | voTradeDetail.setRefundAmount(refundAmount1);//2 |
| | | voTradeDetail.setMoney(money);//待2 |
| | | voTradeDetail.setPaymentName("赠送");//2 |
| | | voTradeDetail.setOrderNumber(orderNumber);//2 |
| | | voTradeDetail.setCardNum(cardNum);//2 |
| | | voTradeDetail.setIdCard(idCard);//2 |
| | | voTradeDetail.setCashierName(cashierName);//2 |
| | | voTradeDetail.setCashierId(cashierId);//2 |
| | | voTradeDetail.setCardState(cardState);//2 |
| | | voTradeDetail.setVillageId(villageId);//2 |
| | | |
| | | list.add(voTradeDetail); |
| | | itemTotal = itemTotal + 1; |
| | | } |
| | | } |
| | | list.sort(Comparator.comparing(VoTradeDetails::getTradeTime)); |
| | | rsVo.obj = list; |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | |
| | | // 遍历交易明细记录,汇总购水金额、购卡金额 |
| | | Double totalWaterCost = 0.0; |
| | | Double totalCardCost = 0.0; |
| | | 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("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 cardNum |
| | | * @return |
| | | */ |
| | | public Map getOperateRecordsAndMoney(Long cardNum, String cardAddr) { |
| | | |
| | | List<Map<String, Object>> list = Optional.ofNullable(seClientCardMapper.getOperateRecordsByCardNum(cardNum, cardAddr)).orElse(new ArrayList<>()); |
| | | Float mondy = Optional.ofNullable(seClientCardMapper.getMoneyByCardNum(cardNum, cardAddr)).orElse(0f); |
| | | Float amount = Optional.ofNullable(seClientCardMapper.sumRechargeByCardNum(cardNum, cardAddr)).orElse(0f); |
| | | |
| | | Map map = new HashMap(); |
| | | map.put("mondy", mondy); |
| | | map.put("amount", amount); |
| | | map.put("list", list); |
| | | return map; |
| | | } |
| | | } |