| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrWechat.virtualCard; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoPr.PrIntakeMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoPr.PrIntakeVcMapper; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.daoSe.*; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoIr.IrPlanOperate; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoPr.PrIntakeVc; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoSe.*; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voPr.VoIntakeSimple; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoOrders; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoRechargeProfile; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoVcRecharge; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.irrigatePlan.enums.OperateTypeENUM; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.result.WechatResultCode; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.DtoRegist; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.dto.DtoVirtualCard; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.enums.LastOperateENUM; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.enums.OrderStateENUM; | 
|---|
|  |  |  | import com.dy.pipIrrWechat.virtualCard.qo.QoVcRecharge; | 
|---|
|  |  |  | 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 java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author ZhuBaoMin | 
|---|
|  |  |  | * @date 2024-07-15 9:39 | 
|---|
|  |  |  | * @LastEditTime 2024-07-15 9:39 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class VirtualCardSv { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeVirtualCardMapper seVirtualCardMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeVcRechargeMapper seVcRechargeMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeVcRefundMapper seVcRefundMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeVcRefundItemMapper seVcRefundItemMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeClientMapper seClientMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeVcOperateMapper seVcOperateMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SeRechargeProfileMapper seRechargeProfileMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PrIntakeMapper prIntakeMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PrIntakeVcMapper prIntakeVcMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${vc.alarmValue}") | 
|---|
|  |  |  | private Integer alarmValue; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据农户ID获取5级行政区划代码,注册虚拟卡使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param clientId 农户ID | 
|---|
|  |  |  | * @return 5级行政区划代码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long getAreaCodeById(Long clientId) { | 
|---|
|  |  |  | return seClientMapper.getAreaCodeById(clientId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取农户全部虚拟卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<VoVirtualCard> getVCs(Long clientId) { | 
|---|
|  |  |  | return seVirtualCardMapper.getVCs(alarmValue, clientId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据虚拟卡ID获取虚拟卡对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vcId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public VoVirtualCard getVcById(Long vcId) { | 
|---|
|  |  |  | return seVirtualCardMapper.getVcById(vcId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 注册虚拟卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long insertVirtualCard(SeVirtualCard po) { | 
|---|
|  |  |  | seVirtualCardMapper.insert(po); | 
|---|
|  |  |  | return po.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据农户ID及虚拟卡ID获取正常状态的虚拟卡对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param clientId | 
|---|
|  |  |  | * @param vcId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public SeVirtualCard getVcByClientIdAndVcId(Long clientId, Long vcId) { | 
|---|
|  |  |  | return seVirtualCardMapper.getVcByClientIdAndVcId(clientId, vcId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据虚拟卡ID注销虚拟卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param clientId | 
|---|
|  |  |  | * @param vcId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer cancelVc(Long clientId, Long vcId) { | 
|---|
|  |  |  | return seVirtualCardMapper.cancelVc(clientId, vcId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据行政区划串模糊查询虚拟卡编号,注册虚拟卡使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param areaCode | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String getVcCardNumOfMax(String areaCode) { | 
|---|
|  |  |  | return seVirtualCardMapper.getVcCardNumOfMax(areaCode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** 废弃 | 
|---|
|  |  |  | * 验证农户是否拥有指定名称的虚拟卡 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //public Integer getRecordCountByName(DtoRegist po) { | 
|---|
|  |  |  | //    return seVirtualCardMapper.getRecordCountByName(po.getClientId(), po.getVcName()); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改虚拟卡 | 
|---|
|  |  |  | * 充值、消费、申请退款、审核退款时需要修改虚拟卡的:余额、最后操作、最后操作时间 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer updateVirtualCard(SeVirtualCard po) { | 
|---|
|  |  |  | return seVirtualCardMapper.updateByPrimaryKeySelective(po); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据虚拟卡编号获取虚拟卡对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param virtualId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public SeVirtualCard selectVirtuCardById(Long virtualId) { | 
|---|
|  |  |  | return seVirtualCardMapper.selectByPrimaryKey(virtualId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加虚拟卡充值记录 | 
|---|
|  |  |  | * JSAPI下单后生成部分充值记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return -1:虚拟卡不存在,0:添加充值记录失败 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //public BaseResponse<Boolean> insertVCRecharge(DtoVirtualCard po) { | 
|---|
|  |  |  | public Long insertVCRecharge(DtoVirtualCard po) { | 
|---|
|  |  |  | String orderNumber = po.getOrderNumber(); | 
|---|
|  |  |  | Long virtualId = po.getVirtualId(); | 
|---|
|  |  |  | Long clientId = po.getClientId(); | 
|---|
|  |  |  | Double rechargeAmount = po.getRechargeAmount(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证该虚拟卡账户是否存在并取出当前账户余额 | 
|---|
|  |  |  | SeVirtualCard seVirtualCard = seVirtualCardMapper.selectByPrimaryKey(virtualId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (seVirtualCard == null) { | 
|---|
|  |  |  | return -1L; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double money = seVirtualCard.getMoney(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 添加充值记录 | 
|---|
|  |  |  | SeVcRecharge seVcRecharge = new SeVcRecharge(); | 
|---|
|  |  |  | seVcRecharge.setVcId(virtualId); | 
|---|
|  |  |  | seVcRecharge.setClientId(clientId); | 
|---|
|  |  |  | seVcRecharge.setMoney(money); | 
|---|
|  |  |  | seVcRecharge.setOrderNumber(orderNumber); | 
|---|
|  |  |  | seVcRecharge.setRechargeAmount(rechargeAmount); | 
|---|
|  |  |  | seVcRecharge.setOrderTime(new Date()); | 
|---|
|  |  |  | seVcRecharge.setOrderState(OrderStateENUM.NON_PAYMENT.getCode()); | 
|---|
|  |  |  | seVcRechargeMapper.insert(seVcRecharge); | 
|---|
|  |  |  | Long rechargeId = seVcRecharge.getId(); | 
|---|
|  |  |  | if (rechargeId == null) { | 
|---|
|  |  |  | return 0L; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return rechargeId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据订单号获取虚拟卡充值对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param orderNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public SeVcRecharge getVCRechargeByorderNumber(String orderNumber) { | 
|---|
|  |  |  | return seVcRechargeMapper.getVCRechargeByorderNumber(orderNumber); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改虚拟卡充值记录 | 
|---|
|  |  |  | * 微信支付通知后: | 
|---|
|  |  |  | * 1. 更新充值表:充值后余额、支付完成时间、订单状态 | 
|---|
|  |  |  | * 2. 更新虚拟卡表:账户余额、最后操作、最后操作时间 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param orderNumber 订单编号 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public BaseResponse<Boolean> updateVCRecharge(String orderNumber, Date rechargeTime) { | 
|---|
|  |  |  | SeVcRecharge seVcRecharge = seVcRechargeMapper.getVCRechargeByorderNumber(orderNumber); | 
|---|
|  |  |  | if (seVcRecharge == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long virtualId = seVcRecharge.getVcId(); | 
|---|
|  |  |  | Double money = seVcRecharge.getMoney(); | 
|---|
|  |  |  | Double rechargeAmount = seVcRecharge.getRechargeAmount(); | 
|---|
|  |  |  | Double afterRrecharge = money + rechargeAmount; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | seVcRecharge.setAfterRecharge(afterRrecharge); | 
|---|
|  |  |  | seVcRecharge.setRechargeTime(rechargeTime); | 
|---|
|  |  |  | seVcRecharge.setOrderState(OrderStateENUM.PAID.getCode()); | 
|---|
|  |  |  | Integer rec = seVcRechargeMapper.updateByPrimaryKeySelective(seVcRecharge); | 
|---|
|  |  |  | if (rec == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SeVirtualCard seVirtualCard = seVirtualCardMapper.selectByPrimaryKey(virtualId); | 
|---|
|  |  |  | if (seVirtualCard == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.VIRTUAL_CARD_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | seVirtualCard.setMoney(afterRrecharge); | 
|---|
|  |  |  | seVirtualCard.setLastOperate(LastOperateENUM.RECHARGE.getCode()); | 
|---|
|  |  |  | seVirtualCard.setLastOperateTime(new Date()); | 
|---|
|  |  |  | Integer rec2 = seVirtualCardMapper.updateByPrimaryKeySelective(seVirtualCard); | 
|---|
|  |  |  | if (rec2 == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(WechatResultCode.RECHARGE_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改虚拟卡充值记录(废弃) | 
|---|
|  |  |  | * 微信小程序支付通知后修改:余额、充值后余额、充值完成时间 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer updateVCRecharge(SeVcRecharge po) { | 
|---|
|  |  |  | return seVcRechargeMapper.updateByPrimaryKeySelective(po); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据虚拟卡号获取订单列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param virtualId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<VoOrders> selectOrders(Long virtualId) { | 
|---|
|  |  |  | List<VoOrders> rsVo = seVcRechargeMapper.getOrders(virtualId); | 
|---|
|  |  |  | return rsVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据退款ID获取退款对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param refundId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public SeVcRefund selectRefundByRefundId(Long refundId) { | 
|---|
|  |  |  | return seVcRefundMapper.selectByPrimaryKey(refundId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加退款申请 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long addRefund(SeVcRefund po) { | 
|---|
|  |  |  | seVcRefundMapper.insert(po); | 
|---|
|  |  |  | return po.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改退款记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer updateRefund(SeVcRefund po) { | 
|---|
|  |  |  | return seVcRefundMapper.updateByPrimaryKeySelective(po); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据订单号获取其各笔退款金额 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param orderNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<Integer> selectRefundAmount(String orderNumber) { | 
|---|
|  |  |  | List<Integer> rsVo = seVcRefundMapper.getRefundAmount(orderNumber); | 
|---|
|  |  |  | return rsVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加退款分项 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long addRefundItem(SeVcRefundItem po) { | 
|---|
|  |  |  | seVcRefundItemMapper.insert(po); | 
|---|
|  |  |  | return po.getRefundId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 编辑退款分项 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer updateRefundItem(SeVcRefundItem po) { | 
|---|
|  |  |  | return seVcRefundItemMapper.updateByPrimaryKeySelective(po); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据订单号生成退款单号 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param orderNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String generateRefundNumber(String orderNumber) { | 
|---|
|  |  |  | String refundNumber = seVcRefundItemMapper.getLastRefundNumber(orderNumber); | 
|---|
|  |  |  | if (refundNumber == null) { | 
|---|
|  |  |  | refundNumber = orderNumber + "01"; | 
|---|
|  |  |  | return refundNumber; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String a = String.format("%02d", (Integer.parseInt(refundNumber.substring(29, 30).trim()) + 1)); | 
|---|
|  |  |  | return a; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据订单号获取充值金额,调用退款申请接口使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param orderNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Double getRechargeAmountByOrderNumber(String orderNumber) { | 
|---|
|  |  |  | return seVcRechargeMapper.getRechargeAmountByOrderNumber(orderNumber); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据退款通知接口返回的退款单号反查退款ID,查询该退款ID下未退款记录数量 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param refundNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Integer getNoRefundedCount(String refundNumber) { | 
|---|
|  |  |  | return seVcRefundItemMapper.getNoRefundedCount(refundNumber); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据退款单号获取退款ID,退款通知后更新退款表所需 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param refundNumber | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long getRefundIdByRefundNumber(String refundNumber) { | 
|---|
|  |  |  | return seVcRefundItemMapper.getRefundIdByRefundNumber(refundNumber); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取虚拟卡充值记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param dtoVcRecharge | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public QueryResultVo<List<VoVcRecharge>> getVcRechargeRecords(QoVcRecharge dtoVcRecharge) { | 
|---|
|  |  |  | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(dtoVcRecharge); | 
|---|
|  |  |  | Long itemTotal = seVirtualCardMapper.getRechargeRecordCount(params); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryResultVo<List<VoVcRecharge>> rsVo = new QueryResultVo<>(); | 
|---|
|  |  |  | rsVo.pageSize = dtoVcRecharge.pageSize; | 
|---|
|  |  |  | rsVo.pageCurr = dtoVcRecharge.pageCurr; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rsVo.calculateAndSet(itemTotal, params); | 
|---|
|  |  |  | rsVo.obj = seVirtualCardMapper.getVcRechargeRecords(params); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return rsVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加虚拟卡操作记录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Long insertVcOperate(SeVcOperate po) { | 
|---|
|  |  |  | seVcOperateMapper.insert(po); | 
|---|
|  |  |  | return po.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取虚拟卡常用充值金额配置 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<VoRechargeProfile> gerRechargeProfiles() { | 
|---|
|  |  |  | return seRechargeProfileMapper.gerRechargeProfiles(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 注册虚拟卡 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param clientId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map addVC(Long clientId, Double money) { | 
|---|
|  |  |  | // 获取5级行政区划串areaCode | 
|---|
|  |  |  | Long areaCodeL = getAreaCodeById(clientId); | 
|---|
|  |  |  | if (areaCodeL == null) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", WechatResultCode.AREA_CODE_MISTAKE.getMessage()); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String areaCode = String.valueOf(areaCodeL); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据行政区划串(areaCode)在虚拟卡表中针对虚拟卡编号(vcNum)进行模糊查询 | 
|---|
|  |  |  | * 如果5位顺序号已经达到最大值,提示用户联系系统管理员 | 
|---|
|  |  |  | * 如果5位顺序号未达到最大值,则加1 | 
|---|
|  |  |  | * cardNum为新的卡号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String vcNum = Optional.ofNullable(getVcCardNumOfMax(areaCode)).orElse(""); | 
|---|
|  |  |  | if (vcNum != null && vcNum.trim().length() > 0) { | 
|---|
|  |  |  | Integer number = Integer.parseInt(vcNum.substring(12)); | 
|---|
|  |  |  | number = number + 1; | 
|---|
|  |  |  | if (number > 65535) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", WechatResultCode.CARD_NUMBER_OVERRUN.getMessage()); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | vcNum = vcNum.substring(0, 12) + String.format("%05d", number); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | vcNum = areaCode + "00001"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成虚拟卡记录 | 
|---|
|  |  |  | SeVirtualCard seVirtualCard = new SeVirtualCard(); | 
|---|
|  |  |  | seVirtualCard.setVcNum(Long.parseLong(vcNum)); | 
|---|
|  |  |  | seVirtualCard.setClientId(clientId); | 
|---|
|  |  |  | seVirtualCard.setMoney(money); | 
|---|
|  |  |  | seVirtualCard.setState((byte) 1); | 
|---|
|  |  |  | seVirtualCard.setLastOperate(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
|---|
|  |  |  | seVirtualCard.setLastOperateTime(new Date()); | 
|---|
|  |  |  | seVirtualCard.setInUse((byte) 0); | 
|---|
|  |  |  | seVirtualCard.setCreateTime(new Date()); | 
|---|
|  |  |  | Long vcId = insertVirtualCard(seVirtualCard); | 
|---|
|  |  |  | if (vcId == null) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成虚拟卡操作记录,注册虚拟卡操作人为农户 | 
|---|
|  |  |  | SeVcOperate seVcOperate = new SeVcOperate(); | 
|---|
|  |  |  | seVcOperate.setVcId(vcId); | 
|---|
|  |  |  | seVcOperate.setClientId(clientId); | 
|---|
|  |  |  | seVcOperate.setOperateType(LastOperateENUM.OPEN_ACCOUNT.getCode()); | 
|---|
|  |  |  | seVcOperate.setOperator(clientId); | 
|---|
|  |  |  | seVcOperate.setOperateTime(new Date()); | 
|---|
|  |  |  | Long vcOperateId = insertVcOperate(seVcOperate); | 
|---|
|  |  |  | if (vcOperateId == null) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", WechatResultCode.VC_OPEN_ACCOUNT_FAIL.getMessage()); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", true); | 
|---|
|  |  |  | map.put("msg", "虚拟卡注册成功"); | 
|---|
|  |  |  | map.put("content", vcId); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取未绑定虚拟卡的取水口列表,给取水口绑虚拟卡使用 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map linkVcToIntake(Long clientId) { | 
|---|
|  |  |  | // 验证是否存在取水口未绑虚拟卡 | 
|---|
|  |  |  | List<VoIntakeSimple> list = prIntakeMapper.getNotLinkVcIntakes(); | 
|---|
|  |  |  | if (list == null || list.size() == 0) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", true); | 
|---|
|  |  |  | map.put("msg", "所有取水口都匹配了虚拟卡"); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 遍历所有未绑虚拟卡的取水口 | 
|---|
|  |  |  | for (VoIntakeSimple voIntakeSimple : list) { | 
|---|
|  |  |  | Long intakeId = voIntakeSimple.getIntakeId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 创建虚拟卡 | 
|---|
|  |  |  | Map map_result = addVC(clientId, 100000D); | 
|---|
|  |  |  | if (map_result.get("success").equals(false)) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", "灌虚拟卡注册失败"); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long vcId = (Long) map_result.get("content"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 取水口绑虚拟卡 | 
|---|
|  |  |  | PrIntakeVc intakeVc = new PrIntakeVc(); | 
|---|
|  |  |  | intakeVc.setIntakeId(intakeId); | 
|---|
|  |  |  | intakeVc.setVcId(vcId); | 
|---|
|  |  |  | Integer result = prIntakeVcMapper.insert(intakeVc); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (result == null) { | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", false); | 
|---|
|  |  |  | map.put("msg", "取水口绑虚拟卡失败"); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map map = new HashMap<>(); | 
|---|
|  |  |  | map.put("success", true); | 
|---|
|  |  |  | map.put("msg", "取水口绑虚拟卡成功"); | 
|---|
|  |  |  | map.put("content", null); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|