Administrator
2024-01-30 bc45a4a5a9b40e934317644c691ec5117e802859
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.dy.pipIrrSell.general;
 
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.pojoSe.SeAudits;
import com.dy.pipIrrGlobal.pojoSe.SeGeneral;
import com.dy.pipIrrGlobal.voSe.VoGeneral;
import com.dy.pipIrrGlobal.voSe.VoTransactionStatistics;
import com.dy.pipIrrSell.general.qo.QoGeneral;
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.util.*;
 
/**
 * @author ZhuBaoMin
 * @date 2024-01-24 19:02
 * @LastEditTime 2024-01-24 19:02
 * @Description
 */
 
@Slf4j
@Service
public class GeneralSv {
    @Autowired
    private SeGeneralMapper seGeneralMapper;
 
    @Autowired
    private SeAuditsMapper seAuditsMapper;
 
    @Autowired
    private SeCardOperateMapper seCardOperateMapper;
 
    /**
     * 获取未生成总账的交易日期列表(当天的交易记录不生成总账)
     * @return
     */
    public List<Map<String, Object>> getDatesOfNotInGenerals() {
        return seGeneralMapper.getDatesOfNotInGenerals();
    }
 
    /**
     * 添加总账
     * @param po 总账对象
     * @return
     */
    public Integer addGeneral(SeGeneral po) {
        return seGeneralMapper.insert(po);
    }
 
    /**
     * 根据交易日期获取总账记录列表(待生成的)
     * @param operateDate 交易日期
     * @return 取总账记录列表
     */
    public List<SeGeneral> getGeneralByOperateDate(String operateDate) {
        return seGeneralMapper.getGeneralByOperateDate(operateDate);
    }
 
    /**
     * 根据指定条件获取总账记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoGeneral>> getGenerals(QoGeneral queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        Long itemTotal = seGeneralMapper.getRecordCount(params);
 
        QueryResultVo<List<VoGeneral>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
 
 
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seGeneralMapper.getGenerals(params);
        return rsVo ;
    }
 
    /**
     * 修改总账审核意见
     * @param po
     * @return
     */
    public Integer updateGeneral(SeGeneral po) {
        return seGeneralMapper.updateByPrimaryKeySelective(po);
    }
 
    /**
     * 根据编号查询总账
     * @param id
     * @return
     */
    public SeGeneral getGeneralById(Long id) {
        return seGeneralMapper.selectByPrimaryKey(id);
    }
 
    /**
     * t添加总账审核记录
     * @param po
     * @return
     */
    public Integer addAudits(SeAudits po) {
        return seAuditsMapper.insert(po);
    }
 
    /**
     * 财务对账审核页,收银员+日期分组,排除交易类型分组
     * @param vo
     * @return
     */
    public Map getToAudit(QoToAudit vo) {
        /**
         * 取出指定日期三种支付方式(现金、扫码、转账)实收金额
         */
        JSONArray array_paymentSums = new JSONArray();
        String tradeDate = vo.getTradeDate();
        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);
 
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ;
 
        //获取笔数合计、实收金额合计、赠送金额合计
        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());
        }
 
        // 获取符合条件的记录数
        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("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;
    }
}