| New file | 
 |  |  | 
 |  |  | package com.dy.pipIrrTerminal.general; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONArray; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SeGeneralMapper; | 
 |  |  | import com.dy.pipIrrGlobal.daoSe.SePaymentMethodMapper; | 
 |  |  | import com.dy.pipIrrGlobal.pojoSe.SePaymentMethod; | 
 |  |  | import com.dy.pipIrrGlobal.voSe.VoTransactionStatistics; | 
 |  |  | import com.dy.pipIrrTerminal.general.qo.QoSummary; | 
 |  |  | 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.*; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @author ZhuBaoMin | 
 |  |  |  * @date 2025-06-25 11:22 | 
 |  |  |  * @LastEditTime 2025-06-25 11:22 | 
 |  |  |  * @Description | 
 |  |  |  */ | 
 |  |  |  | 
 |  |  | @Slf4j | 
 |  |  | @Service | 
 |  |  | public class GeneralSv { | 
 |  |  |     @Autowired | 
 |  |  |     private SeGeneralMapper seGeneralMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SePaymentMethodMapper sePaymentMethodMapper; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 充值机用获取交易统计记录 | 
 |  |  |      * @param vo | 
 |  |  |      * @return | 
 |  |  |      * @throws ParseException | 
 |  |  |      */ | 
 |  |  |     public Map getSummaries(QoSummary vo) throws ParseException { | 
 |  |  |         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |  | 
 |  |  |         Integer pageSize = vo.getPageSize(); | 
 |  |  |         Integer pageCurr = vo.getPageCurr(); | 
 |  |  |         // 起始索引位置 | 
 |  |  |         Integer startIndex = (pageCurr - 1) * pageSize; | 
 |  |  |  | 
 |  |  |         // 获取各支付方式ID | 
 |  |  |         Long paymentId_cash = 0L; | 
 |  |  |         Long paymentId_pos = 0L; | 
 |  |  |         Long paymentId_transfer = 0L; | 
 |  |  |         List<SePaymentMethod> list_payment = sePaymentMethodMapper.getPaymentMethods(); | 
 |  |  |         for (int i = 0; i < list_payment.size(); i++) { | 
 |  |  |             SePaymentMethod paymentMethod = list_payment.get(i); | 
 |  |  |             if(paymentMethod.getName().equals("现金")) { | 
 |  |  |                 paymentId_cash = paymentMethod.getId(); | 
 |  |  |             } | 
 |  |  |             if(paymentMethod.getName().equals("POS机")) { | 
 |  |  |                 paymentId_pos = paymentMethod.getId(); | 
 |  |  |             } | 
 |  |  |             if(paymentMethod.getName().equals("银行转账")) { | 
 |  |  |                 paymentId_transfer = paymentMethod.getId(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 接收传入参数:交易起止日期、收银员ID | 
 |  |  |         JSONArray array_paymentSums = new JSONArray(); | 
 |  |  |         Date timeStart = dateFormat.parse(vo.getTimeStart()); | 
 |  |  |         Date timeStop = dateFormat.parse(vo.getTimeStop()); | 
 |  |  |         Long cashierId = vo.cashierId; | 
 |  |  |  | 
 |  |  |         Calendar calendar = Calendar.getInstance(); | 
 |  |  |         calendar.setTime(timeStart); | 
 |  |  |         while (calendar.getTime().before(timeStop) || calendar.getTime().equals(timeStop)) { | 
 |  |  |             String tradeDate = dateFormat.format(calendar.getTime()) ; | 
 |  |  |             Float receivedCash = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, paymentId_cash)).orElse(0f); | 
 |  |  |             Float receivedPos = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,paymentId_pos)).orElse(0f); | 
 |  |  |             Float receivedTransfer = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, paymentId_transfer)).orElse(0f); | 
 |  |  |  | 
 |  |  |             JSONObject job = new JSONObject(); | 
 |  |  |             job.put("tradeDate", tradeDate); | 
 |  |  |             job.put("receivedCash", receivedCash); | 
 |  |  |             job.put("receivedPos", receivedPos); | 
 |  |  |             job.put("receivedTransfer", receivedTransfer); | 
 |  |  |             array_paymentSums.add(job); | 
 |  |  |             calendar.add(Calendar.DAY_OF_MONTH, 1); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 生成查询参数 | 
 |  |  |         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; | 
 |  |  |  | 
 |  |  |         /** | 
 |  |  |          * 根据收银员编号、交易日期查询汇总记录 | 
 |  |  |          * 遍历汇总记录查询结果,计算笔数合计、实收金额合计、赠送金额合计、返还金额合计 | 
 |  |  |          */ | 
 |  |  |         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; | 
 |  |  |         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); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         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 map_record = new HashMap(); | 
 |  |  |         map_record.put("itemTotal", list.size()); | 
 |  |  |         map_record.put("pageCurr", pageCurr); | 
 |  |  |         map_record.put("pageSize", pageSize); | 
 |  |  |         map_record.put("pageTotal", (int)Math.ceil((double)list.size() / pageSize)); | 
 |  |  |         JSONArray array_record = (JSONArray) JSON.toJSON(list); | 
 |  |  |         JSONArray array_record_page = (JSONArray)JSON.toJSON(array_record.subList(startIndex, Math.min(startIndex + pageSize, array_record.size()))); | 
 |  |  |         map_record.put("list", array_record_page); | 
 |  |  |  | 
 |  |  |         // 分页格式组装支付方式列表 | 
 |  |  |         Map map_paymentSums = new HashMap(); | 
 |  |  |         map_paymentSums.put("itemTotal", array_paymentSums.size()); | 
 |  |  |         map_paymentSums.put("pageCurr", pageCurr); | 
 |  |  |         map_paymentSums.put("pageSize", pageSize); | 
 |  |  |         map_paymentSums.put("pageTotal", (int)Math.ceil((double)array_paymentSums.size() / pageSize)); | 
 |  |  |         JSONArray array_paymentSums_page = (JSONArray) JSON.toJSON(array_paymentSums.subList(startIndex, Math.min(startIndex + pageSize, array_paymentSums.size()))); | 
 |  |  |         map_paymentSums.put("list", array_paymentSums_page); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         map_result.put("records", map_record); | 
 |  |  |         map_result.put("paymentSums", map_paymentSums); | 
 |  |  |  | 
 |  |  |         return map_result; | 
 |  |  |     } | 
 |  |  | } |