liurunyu
2024-06-28 6a6d287641a28ad19dfa1c319fe7a9191ef9ad52
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/cardOperate/CardOperateSv.java
@@ -6,6 +6,7 @@
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper;
import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper;
import com.dy.pipIrrGlobal.daoSe.SeClientMapper;
@@ -25,8 +26,6 @@
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -54,6 +53,9 @@
    @Autowired
    private SeGeneralMapper seGeneralMapper;
    @Autowired
    private BaSettingsMapper baSettingsMapper;
    /**
     * 添加开卡记录
@@ -70,8 +72,12 @@
     * @param clientNum 农户编号
     * @return 5级行政区划代码
     */
    public Long getAreaCodeByNum(String clientNum) {
        return seClientMapper.getAreaCodeByNum(clientNum);
    public String getAreaCodeByNum(String clientNum) {
        Long areaCode = seClientMapper.getAreaCodeByNum(clientNum);
        if (areaCode == null) {
            return "";
        }
        return String.valueOf(areaCode);
    }
    /**
@@ -133,7 +139,7 @@
         */
        Long cardId = 0L;
        Long clientId = 0L;
        String cardNum = po.getCardNum();
        Long cardNum = po.getCardNum();
        Float money = po.getMoney();
        Float amount = po.getAmount();
        Float gift = po.getGift();
@@ -146,7 +152,7 @@
        // 验证水卡状态是否支持当前操作
        String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(Long.parseLong(cardNum))).orElse("");
        String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(cardNum)).orElse("");
        if(stateName.length() == 0 || !stateName.equals("正常")) {
            return BaseResponseUtils.buildFail(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage());
        }
@@ -201,7 +207,6 @@
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 根据指定条件获取充值记录
     * @param queryVo
@@ -232,7 +237,6 @@
        rsVo.obj = seCardOperateMapper.getRecharges(params);
        return rsVo ;
    }
    /**
     * 根据指定条件获取交易记录
@@ -289,104 +293,11 @@
    }
    /**
     * 获取交易统计记录
     * 1.交易统计记录
     * 2.笔数合计、实收金额合计、赠送金额合计
     * 3.每一天、各种支付方式实收金额合计
     * @param vo
     * @return
     */
    public Map getTransactionStatistics(QoTransactionStatistics vo) throws ParseException {
        /**
         * 遍历查询日期,取出每天三种支付方式(现金、扫码、转账)实收金额
         * 每天一个对象
         * 对象组成JSONArray添加到返回对象中
         */
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = dateFormat.parse(vo.getOperateTimeStart());
        Date stopDate = dateFormat.parse(vo.getOperateTimeStop());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        JSONArray array_paymentSums = new JSONArray();
        while (calendar.getTime().before(stopDate) || calendar.getTime().equals(stopDate)) {
            String tradeDate = dateFormat.format(calendar.getTime()) ;
            Float receivedCash = Optional.ofNullable(seCardOperateMapper.getPaymentSums(tradeDate ,1L)).orElse(0f);
            Float receivedQRCode = Optional.ofNullable(seCardOperateMapper.getPaymentSums(tradeDate,2L)).orElse(0f);
            Float receivedTransfer = Optional.ofNullable(seCardOperateMapper.getPaymentSums(tradeDate, 3L)).orElse(0f);
            JSONObject job = new JSONObject();
            job.put("tradeDate", tradeDate);
            job.put("receivedCash", receivedCash);
            job.put("receivedQRCode", receivedQRCode);
            job.put("receivedTransfer", receivedTransfer);
            array_paymentSums.add(job);
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }
        // 补齐查询时间
        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) ;
        //获取笔数合计、实收金额合计、赠送金额合计
        Integer totalCount = 0;
        Float totalReceived = 0f;
        Float totalGift = 0f;
        Map map_sum = Optional.ofNullable(seCardOperateMapper.getTransactionStatisticsSums(params)).orElse(new HashMap());
        if(map_sum.size() > 0) {
            totalCount = Integer.parseInt(map_sum.get("totalCount").toString());
            totalReceived = Float.parseFloat(map_sum.get("totalReceived").toString());
            totalGift = Float.parseFloat(map_sum.get("totalGift").toString());
        }
        // 获取符合条件的记录数
        Long itemTotal = seCardOperateMapper.getTransactionStatisticsRecordCount(params);
        Integer pageSize = vo.getPageSize();
        // 计算总页数
        Integer pageTotal ;
        pageTotal = (int)Math.ceil((itemTotal==null?0.0D:itemTotal.doubleValue())/pageSize);
        // 根据当前页码及每页数量计算偏移量
        Integer pageCurr = (Integer.parseInt(params.get("pageCurr").toString()) - 1) * Integer.parseInt(params.get("pageSize").toString());
        params.put("pageCurr", pageCurr);
        List<VoTransactionStatistics> list = seCardOperateMapper.getTransactionStatistics(params);
        Map map_record = new HashMap();
        map_record.put("itemTotal", itemTotal);
        map_record.put("pageCurr", vo.pageCurr);
        map_record.put("pageSize", pageSize);
        map_record.put("pageTotal", pageTotal);
        map_record.put("list", list);
        Map map_result = new HashMap();
        map_result.put("totalCount", totalCount);
        map_result.put("totalReceived", totalReceived);
        map_result.put("totalGift", totalGift);
        map_result.put("records", map_record);
        map_result.put("paymentSums", array_paymentSums);
        return map_result;
    }
    /**
     * 根据指定条件获取开卡记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoActiveCardNew>> getActiveCards(QoActiveCard queryVo) {
    public QueryResultVo<List<VoActiveCard>> getActiveCards(QoActiveCard queryVo) {
        //完善查询充值记录的起止时间
        String activeTimeStart = queryVo.activeTimeStart;
        String activeTimeStop = queryVo.activeTimeStop;
@@ -403,7 +314,7 @@
        Long itemTotal = seCardOperateMapper.getActiveCardRecordCount(params);
        QueryResultVo<List<VoActiveCardNew>> rsVo = new QueryResultVo<>() ;
        QueryResultVo<List<VoActiveCard>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
@@ -446,6 +357,38 @@
    }
    /**
     * 根据指定条件获取IC卡注销记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoOperate>> getCommonOperations(QoCommonOperate queryVo) {
        //完善查询充值记录的起止时间
        String timeStart = queryVo.getTimeStart();
        String timeStop = queryVo.getTimeStop();
        if(timeStart != null) {
            timeStart = timeStart + " 00:00:00";
            queryVo.setTimeStart(timeStart);
        }
        if(timeStop != null) {
            timeStop = timeStop + " 23:59:59";
            queryVo.setTimeStop(timeStop);
        }
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        Long itemTotal = Optional.ofNullable(seCardOperateMapper.getCommonOperationRecordCount(params)).orElse(0L);
        QueryResultVo<List<VoOperate>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seCardOperateMapper.getCommonOperations(params);
        return rsVo ;
    }
    /**
     * 根据指定条件获取收据列表
     * @param queryVo
     * @return
@@ -480,4 +423,34 @@
        return map_result;
    }
    /**
     * 判断指定水卡是否为挂失状态且无补卡记录
     * @param cardNum 水卡编号
     * @return 是否已挂失未补卡
     */
    public Boolean isLostAndUnreplaced(Long cardNum) {
        Integer rec = seClientCardMapper.isLostAndUnreplaced(cardNum);
        if(rec != null && rec > 0) {
            return false;
        }
        return true;
    }
    /**
     * 修改农户水卡
     * @param po
     * @return
     */
    public Integer updateClientCard(SeClientCard po) {
        return seClientCardMapper.updateByPrimaryKeySelective(po);
    }
    /**
     * 获取项目编号
     * @return
     */
    public String getProjectNo() {
        return baSettingsMapper.getItemValue("projectNo");
    }
}