| | |
| | | package com.dy.pipIrrSell.general; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoSe.SeAuditsMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeCardOperateMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.SeGeneralMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.*; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeAudits; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeGeneral; |
| | | import com.dy.pipIrrGlobal.voSe.VoGeneral; |
| | | import com.dy.pipIrrGlobal.voSe.VoTradeDetails; |
| | | import com.dy.pipIrrGlobal.voSe.VoTransactionStatistics; |
| | | import com.dy.pipIrrSell.general.qo.QoGeneral; |
| | | import com.dy.pipIrrSell.general.qo.QoSummary; |
| | | import com.dy.pipIrrSell.general.qo.QoToAudit; |
| | | 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.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private SeCardOperateMapper seCardOperateMapper; |
| | | |
| | | @Autowired |
| | | private SeWalletRechargeMapper seWalletRechargeMapper; |
| | | |
| | | @Autowired |
| | | private SeRefundMapper seRefundMapper; |
| | | |
| | | /** |
| | | * 获取未生成总账的交易日期列表(当天的交易记录不生成总账) |
| | |
| | | Long itemTotal = seGeneralMapper.getRecordCount(params); |
| | | |
| | | QueryResultVo<List<VoGeneral>> rsVo = new QueryResultVo<>() ; |
| | | Integer pageCurr = 0; |
| | | Integer pageSize = 10000; |
| | | rsVo.pageCurr = 1; |
| | | rsVo.pageSize = 10000; |
| | | if(queryVo.pageSize != null && queryVo.pageCurr != null) { |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr; |
| | | pageSize = queryVo.pageSize ; |
| | | pageCurr = (Integer.parseInt(params.get("pageCurr").toString()) - 1) * Integer.parseInt(params.get("pageSize").toString()); |
| | | } |
| | | params.put("pageCurr", pageCurr); |
| | | params.put("pageSize", pageSize); |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr ; |
| | | |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = seGeneralMapper.getGenerals(params); |
| | |
| | | } |
| | | |
| | | /** |
| | | * t添加总账审核记录 |
| | | * 添加总账审核记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | return seAuditsMapper.insert(po); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 财务对账审核页,收银员+日期分组,排除交易类型分组 |
| | | * 开卡系统交易汇总查询与对账系统交易汇总查询共用服务实现类 |
| | | * @param vo |
| | | * @return |
| | | * @throws ParseException |
| | | */ |
| | | public Map getToAudit(QoToAudit vo) { |
| | | /** |
| | | * 取出指定日期三种支付方式(现金、扫码、转账)实收金额 |
| | | */ |
| | | public Map getSummaries(QoSummary vo) throws ParseException { |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | |
| | | // 接收传入参数:交易起止日期、收银员ID |
| | | JSONArray array_paymentSums = new JSONArray(); |
| | | String tradeDate = vo.getTradeDate(); |
| | | Date timeStart = dateFormat.parse(vo.getTimeStart()); |
| | | Date timeStop = dateFormat.parse(vo.getTimeStop()); |
| | | Long cashierId = vo.cashierId; |
| | | |
| | | Float receivedCash = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 1L)).orElse(0f); |
| | | Float receivedQRCode = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,2L)).orElse(0f); |
| | | Float receivedTransfer = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 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 calendar = Calendar.getInstance(); |
| | | calendar.setTime(timeStart); |
| | | while (calendar.getTime().before(timeStop) || calendar.getTime().equals(timeStop)) { |
| | | String tradeDate = dateFormat.format(calendar.getTime()) ; |
| | | if(cashierId != 1000000L) { |
| | | Float receivedCash = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 1L)).orElse(0f); |
| | | Float receivedQRCode = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,2L)).orElse(0f); |
| | | Float receivedTransfer = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 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); |
| | | |
| | | }else { |
| | | // 分级计算指定日期微信收退款合计,再计算实收金额 |
| | | Double rechargeWeChat = Optional.ofNullable(seWalletRechargeMapper.getRechargeSum(tradeDate)).orElse(0.0); |
| | | Double refundWeChat = Optional.ofNullable(seRefundMapper.getRefundSum(tradeDate)).orElse(0.0); |
| | | Double receiveWeChat = rechargeWeChat - refundWeChat; |
| | | |
| | | // 微信实收金额写入返回对象(写入前格式化) |
| | | JSONObject job = new JSONObject(); |
| | | job.put("receiveWeChat", df.format(receiveWeChat)); |
| | | array_paymentSums.add(job); |
| | | } |
| | | calendar.add(Calendar.DAY_OF_MONTH, 1); |
| | | } |
| | | |
| | | // 生成查询参数 |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; |
| | | |
| | | //获取笔数合计、实收金额合计、赠送金额合计 |
| | | // 获取符合条件的记录数(代码全部注释掉了,没删) |
| | | //Long itemTotal = seGeneralMapper.getToAuditRecordCount(params); |
| | | |
| | | /** |
| | | * 根据收银员编号、交易日期查询汇总记录 |
| | | * 遍历汇总记录查询结果,计算笔数合计、实收金额合计、赠送金额合计、返还金额合计 |
| | | */ |
| | | List<VoTransactionStatistics> list = Optional.ofNullable(seGeneralMapper.getSummaries(params)).orElse(new ArrayList<>()); |
| | | if(list.size() == 0) { |
| | | return new HashMap(); |
| | | } |
| | | |
| | | Integer totalCount = 0; |
| | | Float totalReceived = 0f; |
| | | Float totalGift = 0f; |
| | | Map map_sum = Optional.ofNullable(seGeneralMapper.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()); |
| | | Float totalRefund = 0f; |
| | | JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); |
| | | for(int i = 0; i < array.size(); i++) { |
| | | JSONObject job_summary = array.getJSONObject(i); |
| | | totalCount = totalCount + Optional.ofNullable(job_summary.getInteger("count")).orElse(0); |
| | | totalReceived = totalReceived + Optional.ofNullable(job_summary.getFloat("received")).orElse(0f); |
| | | totalGift = totalGift + Optional.ofNullable(job_summary.getFloat("gift")).orElse(0f); |
| | | totalRefund = totalRefund + Optional.ofNullable(job_summary.getFloat("refundAmount")).orElse(0f); |
| | | } |
| | | |
| | | // 获取符合条件的记录数 |
| | | Long itemTotal = seGeneralMapper.getToAuditRecordCount(params); |
| | | |
| | | List<VoTransactionStatistics> list = seGeneralMapper.getToAudit(params); |
| | | Map map_record = new HashMap(); |
| | | map_record.put("itemTotal", itemTotal); |
| | | map_record.put("pageCurr", vo.pageCurr); |
| | | //map_record.put("itemTotal", itemTotal); |
| | | 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("totalRefund", totalRefund); |
| | | |
| | | map_result.put("records", map_record); |
| | | map_result.put("paymentSums", array_paymentSums); |
| | | |
| | | return map_result; |
| | | } |
| | | |
| | | /** |
| | | * 根据收银员ID及日期获取财务对账_交易明细记录 |
| | | * @param queryVo |
| | | * @return |
| | | */ |
| | | public Map getTradeDetails(QoToAudit queryVo) { |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); |
| | | |
| | | Long itemTotal = seGeneralMapper.getTradeDetailsRecordCount(params); |
| | | |
| | | QueryResultVo<List<VoTradeDetails>> rsVo = new QueryResultVo<>() ; |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr ; |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | List<VoTradeDetails> list = Optional.ofNullable(seGeneralMapper.getTradeDetails(params)).orElse(new ArrayList<>()); |
| | | if(list.size() == 0) { |
| | | return new HashMap(); |
| | | } |
| | | |
| | | // 遍历交易明细记录,汇总交易金额 |
| | | Double totalTradeAmount = 0.0; |
| | | JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); |
| | | for(int i = 0; i < array.size(); i++) { |
| | | JSONObject job = array.getJSONObject(i); |
| | | Double tradeAmount = Optional.ofNullable(job.getDouble("tradeAmount")).orElse(0.0); |
| | | totalTradeAmount = totalTradeAmount + tradeAmount; |
| | | } |
| | | |
| | | Map map_record = new HashMap(); |
| | | map_record.put("itemTotal", rsVo.itemTotal); |
| | | map_record.put("pageCurr", rsVo.pageCurr); |
| | | map_record.put("pageSize", rsVo.pageSize); |
| | | map_record.put("pageTotal", rsVo.pageTotal); |
| | | map_record.put("list", list); |
| | | |
| | | Map map_result = new HashMap(); |
| | | |
| | | map_result.put("totalTradeAmount", df.format(totalTradeAmount)); |
| | | map_result.put("records", map_record); |
| | | |
| | | return map_result; |
| | | |
| | | } |
| | | } |