| | |
| | | package com.dy.pipIrrSell.cardOperate; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientCardMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeClientMapper; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; |
| | | 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.ClientCardSv; |
| | | import com.dy.pipIrrSell.clientCard.LastOperateENUM; |
| | | import com.dy.pipIrrSell.result.SellResultCode; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | Long operator = po.getOperator(); |
| | | Date rechargeTime = new Date(); |
| | | |
| | | |
| | | // 验证水卡状态是否支持当前操作 |
| | | String stateName = Optional.ofNullable(clientCardSv.getCardStateByCardNum(Long.parseLong(cardNum))).orElse(""); |
| | | if(stateName.length() == 0 || !stateName.equals("正常")) { |
| | | return BaseResponseUtils.buildFail(stateName + ", " + SellResultCode.THE_CARD_NOT_SUPPORT_THIS_OPERATION.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 依据水卡编号获取水卡表主键及农户编号 |
| | | */ |
| | |
| | | |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据指定条件获取充值记录 |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | | public QueryResultVo<List<VoRecharge>> getRecharges(QoRecharge queryVo) { |
| | | //完善查询充值记录的起止时间 |
| | | String rechargeTimeStart = queryVo.rechargeTimeStart; |
| | | String rechargeTimeStop = queryVo.rechargeTimeStop; |
| | | if(rechargeTimeStart != null) { |
| | | rechargeTimeStart = rechargeTimeStart + " 00:00:00"; |
| | | queryVo.setRechargeTimeStart(rechargeTimeStart); |
| | | } |
| | | if(rechargeTimeStop != null) { |
| | | rechargeTimeStop = rechargeTimeStop + " 23:59:59"; |
| | | queryVo.setRechargeTimeStop(rechargeTimeStop); |
| | | } |
| | | |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = seCardOperateMapper.getRecordCount(params); |
| | | |
| | | 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 ; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据指定条件获取交易记录 |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | public Map getTransactions(QoTransaction vo){ |
| | | // 补齐查询时间 |
| | | 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) ; |
| | | |
| | | // 获取汇总的购水金额、购卡金额 |
| | | Float waterCost = 0f; |
| | | Float cardCost = 0f; |
| | | Map map_sum = Optional.ofNullable(seCardOperateMapper.getTransactionSums(params)).orElse(new HashMap()); |
| | | if(map_sum.size() > 0) { |
| | | waterCost = Float.parseFloat(map_sum.get("waterCost").toString()); |
| | | cardCost = Float.parseFloat(map_sum.get("cardCost").toString()); |
| | | } |
| | | |
| | | // 获取符合条件的记录数 |
| | | Long itemTotal = seCardOperateMapper.getTransactionRecordCount(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<VoTransaction> lit = seCardOperateMapper.getTransactions(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", lit); |
| | | |
| | | Map map_result = new HashMap(); |
| | | map_result.put("waterCost", waterCost); |
| | | map_result.put("cardCost", cardCost); |
| | | map_result.put("records", map_record); |
| | | |
| | | return map_result; |
| | | } |
| | | |
| | | /** |
| | | * 获取交易统计记录 |
| | | * 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) { |
| | | //完善查询充值记录的起止时间 |
| | | String activeTimeStart = queryVo.activeTimeStart; |
| | | String activeTimeStop = queryVo.activeTimeStop; |
| | | if(activeTimeStart != null) { |
| | | activeTimeStart = activeTimeStart + " 00:00:00"; |
| | | queryVo.setActiveTimeStart(activeTimeStart); |
| | | } |
| | | if(activeTimeStop != null) { |
| | | activeTimeStop = activeTimeStop + " 23:59:59"; |
| | | queryVo.setActiveTimeStop(activeTimeStop); |
| | | } |
| | | |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = seCardOperateMapper.getActiveCardRecordCount(params); |
| | | |
| | | QueryResultVo<List<VoActiveCardNew>> rsVo = new QueryResultVo<>() ; |
| | | |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr ; |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = seCardOperateMapper.getActiveCards(params); |
| | | return rsVo ; |
| | | } |
| | | |
| | | /** |
| | | * 根据指定条件获取补卡记录 |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | | public QueryResultVo<List<VoReissueCard>> getReissueCards(QoReissueCard queryVo) { |
| | | //完善查询充值记录的起止时间 |
| | | String reissueCardTimeStart = queryVo.reissueCardTimeStart; |
| | | String reissueCardTimeStop = queryVo.reissueCardTimeStop; |
| | | if(reissueCardTimeStart != null) { |
| | | reissueCardTimeStart = reissueCardTimeStart + " 00:00:00"; |
| | | queryVo.setReissueCardTimeStart(reissueCardTimeStart); |
| | | } |
| | | if(reissueCardTimeStop != null) { |
| | | reissueCardTimeStop = reissueCardTimeStop + " 23:59:59"; |
| | | queryVo.setReissueCardTimeStop(reissueCardTimeStop); |
| | | } |
| | | |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = seCardOperateMapper.getReissueCardRecordCount(params); |
| | | |
| | | QueryResultVo<List<VoReissueCard>> rsVo = new QueryResultVo<>() ; |
| | | |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr ; |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = seCardOperateMapper.getReissueCards(params); |
| | | return rsVo ; |
| | | } |
| | | } |