liurunyu
2024-10-12 708dce320caedf9973ff0282098fb70dafd6702e
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/cardOperate/CardOperateSv.java
@@ -9,12 +9,16 @@
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;
@@ -25,6 +29,7 @@
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.time.Duration;
import java.util.*;
/**
@@ -72,6 +77,7 @@
    /**
     * 添加开卡记录
     *
     * @param po 水卡操作对象
     * @return 开卡记录主键
     */
@@ -82,6 +88,7 @@
    /**
     * 根据农户编号获取5级行政区划代码,开卡使用
     *
     * @param clientNum 农户编号
     * @return 5级行政区划代码
     */
@@ -95,6 +102,7 @@
    /**
     * 根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用
     *
     * @param clientId
     * @return
     */
@@ -104,6 +112,7 @@
    /**
     * 根据行政区划串模块查询水卡编号,开卡使用
     *
     * @param areaCode
     * @return
     */
@@ -113,6 +122,7 @@
    /**
     * 根据行政区划串模糊查询管理卡编号,创建管理卡使用
     *
     * @param areaCode
     * @return
     */
@@ -122,6 +132,7 @@
    /**
     * 创建管理卡
     *
     * @param po
     * @return
     */
@@ -132,6 +143,7 @@
    /**
     * 根据农户编号获取农户ID,开卡使用
     *
     * @param clientNum
     * @return
     */
@@ -141,6 +153,7 @@
    /**
     * 添加水卡操作对象,各操作都使用
     *
     * @param po 水卡操作对象
     * @return 操作记录主键
     */
@@ -152,10 +165,11 @@
    /**
     * 添加充值记录
     * 修改农户信息、添加水卡操作记录、添加充值记录
     *
     * @param po
     * @return
     */
    public BaseResponse<Boolean> addRecharge(DtoRecharge po){
    public BaseResponse<Boolean> addRecharge(DtoRecharge po) {
        /**
         * cardId           水卡编号(依据水卡编号获取)
         * clientId         农户编号(依据水卡编号获取)
@@ -183,9 +197,16 @@
        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());
        }
@@ -193,36 +214,24 @@
         * 依据水卡编号获取水卡表主键及农户编号
         */
        Map map = Optional.ofNullable(clientCardSv.getCardIdAndClientNum(cardNum)).orElse(new HashMap());
        if(map == null || map.size() <= 0) {
        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());
         }
         */
        // 根据支付方式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());
        }
        /**
         * 添加水卡充值操作记录
@@ -233,21 +242,16 @@
        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) {
        if (rec == 0) {
            return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_ERROR.getMessage());
        }
@@ -266,9 +270,10 @@
        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) {
        if (rec_seRechargeHistory == 0) {
            return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_HISTORY_ERROR.getMessage());
        }
@@ -276,11 +281,12 @@
        map_response.put("projectNo", String.format("%02x", projectNo));
        map_response.put("orderNumber", rec);
        map_response.put("cardNum", cardNum);
        return BaseResponseUtils.buildSuccess(map_response) ;
        return BaseResponseUtils.buildSuccess(map_response);
    }
    /**
     * 根据指定条件获取充值记录
     *
     * @param queryVo
     * @return
     */
@@ -301,17 +307,18 @@
        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
     */
@@ -320,17 +327,18 @@
        Long itemTotal = seCardOperateMapper.getRechargesCountNew(params);
        QueryResultVo<List<VoRechargeNew>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
        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 ;
        return rsVo;
    }
    /**
     * 获取返还记录,管理平台充值列表使用
     *
     * @param queryVo
     * @return
     */
@@ -339,17 +347,18 @@
        Long itemTotal = seCardOperateMapper.getRefundsCount(params);
        QueryResultVo<List<VoRefund>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
        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 ;
        return rsVo;
    }
    /**
     * 获取水卡消费记录,管理平台使用
     *
     * @param queryVo
     * @return
     */
@@ -358,48 +367,49 @@
        Long itemTotal = rmOpenCloseValveHistoryMapper.getExpendsCount(params);
        QueryResultVo<List<VoExpend>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
        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 ;
        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);
        QueryResultVo<List<VoTradeDetails>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = vo.pageSize ;
        rsVo.pageCurr = vo.pageCurr ;
        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) {
        if (list.size() == 0) {
            return new HashMap();
        }
@@ -409,8 +419,8 @@
        Double totalGift = 0.0;
        Double totalRefund = 0.0;
        JSONArray array= JSONArray.parseArray(JSON.toJSONString(list));
        for(int i = 0; i < array.size(); i++) {
        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);
@@ -439,6 +449,7 @@
    /**
     * 根据指定条件获取开卡记录
     *
     * @param queryVo
     * @return
     */
@@ -446,11 +457,11 @@
        //完善查询充值记录的起止时间
        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);
        }
@@ -459,18 +470,19 @@
        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
     */
@@ -478,11 +490,11 @@
        //完善查询充值记录的起止时间
        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);
        }
@@ -491,18 +503,19 @@
        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;
    }
    /**
     * 根据指定条件获取通用操作记录
     *
     * @param queryVo
     * @return
     */
@@ -510,11 +523,11 @@
        //完善查询充值记录的起止时间
        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);
        }
@@ -523,26 +536,27 @@
        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() != ""){
        if (queryVo.getTimeStart() != null && queryVo.getTimeStart() != "") {
            queryVo.setTimeStart(queryVo.getTimeStart() + " 00:00:00");
        }
        if (queryVo.getTimeStop() != null && queryVo.getTimeStop() != ""){
        if (queryVo.getTimeStop() != null && queryVo.getTimeStop() != "") {
            queryVo.setTimeStop(queryVo.getTimeStop() + " 23:59:59");
        }
@@ -553,9 +567,9 @@
        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);
@@ -578,13 +592,14 @@
    /**
     * 判断指定水卡是否为挂失状态且无补卡记录
     *
     * @param cardNum 水卡编号
     * @return 是否已挂失未补卡
     */
    public Boolean isLostAndUnreplaced(Long cardNum) {
        Integer lostCount = seClientCardMapper.getLostCount(cardNum);
        Integer replacedCount = seClientCardMapper.getReplacedCount(cardNum);
        if(lostCount > 0 && replacedCount == 0) {
        if (lostCount > 0 && replacedCount == 0) {
            return true;
        }
        return false;
@@ -592,6 +607,7 @@
    /**
     * 修改农户水卡
     *
     * @param po
     * @return
     */
@@ -601,6 +617,7 @@
    /**
     * 获取项目编号
     *
     * @return
     */
    public String getProjectNo() {
@@ -609,6 +626,7 @@
    /**
     * 根据水卡编号获取其挂失时退款金额(补卡时判断使用)
     *
     * @param cardNum
     * @return
     */
@@ -618,23 +636,184 @@
    /**
     * 根据水卡地址判断该卡是否可以开卡
     *
     * @param cardAddr
     * @return
     */
    public Boolean canActiveCard(String cardAddr) {
        // 指定水卡地址的水卡数量
        // 指定水卡地址的水卡数量,无效卡片排除在外
        Long cardCount = Optional.ofNullable(seClientCardMapper.getCountByCardAddr(cardAddr)).orElse(0L);
        if(cardCount == 0) {
           return true;
        if (cardCount == 0) {
            return true;
        }
        // 指定水卡地址且正常状态或挂失状态的水卡数量
        cardCount = Optional.ofNullable(seClientCardMapper.getCountByCardAddrAndState(cardAddr)).orElse(0L);
        if(cardCount == 0) {
        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);
    }
}