liurunyu
2024-02-22 d919e26796ec5a6f78fc0b665840207f185f1274
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package com.dy.pipIrrSell.wallet;
 
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoSe.SeConsumeMapper;
import com.dy.pipIrrGlobal.daoSe.SeRefundMapper;
import com.dy.pipIrrGlobal.daoSe.SeWalletMapper;
import com.dy.pipIrrGlobal.daoSe.SeWalletRechargeMapper;
import com.dy.pipIrrGlobal.pojoSe.SeConsume;
import com.dy.pipIrrGlobal.pojoSe.SeRefund;
import com.dy.pipIrrGlobal.pojoSe.SeWallet;
import com.dy.pipIrrGlobal.pojoSe.SeWalletRecharge;
import com.dy.pipIrrGlobal.voSe.VoWallet;
import com.dy.pipIrrGlobal.voSe.VoWalletConsume;
import com.dy.pipIrrGlobal.voSe.VoWalletRecharge;
import com.dy.pipIrrGlobal.voSe.VoWalletRefund;
import com.dy.pipIrrSell.wallet.qo.QueryVo;
import com.dy.pipIrrSell.wallet.qo.QoWalletRecharge;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
 
/**
 * @author ZhuBaoMin
 * @date 2023/12/11 16:36
 * @LastEditTime 2023/12/11 16:36
 * @Description
 */
 
@Slf4j
@Service
public class WalletSv {
    @Autowired
    private SeWalletMapper seWalletMapper;
 
    @Autowired
    private SeWalletRechargeMapper seWalletRechargeMapper;
 
    @Autowired
    private SeConsumeMapper seConsumeMapper;
 
    @Autowired
    private SeRefundMapper seRefundMapper;
 
    /**
     * 根据农户ID获取电子钱包对象
     * @param clientId
     * @return
     */
    public SeWallet getWalletByClientId(Long clientId) {
        return seWalletMapper.getWalletByClientId(clientId);
    }
 
    /**
     * 注册电子钱包账号
     * @param po 电子钱包实体类
     * @return 电子钱包ID
     */
    public Long addWallet(SeWallet po) {
        seWalletMapper.insert(po);
        return po.getId();
    }
 
    /**
     * 电子钱包充值
     * @param po
     * @return
     */
    public Long addRecharge(SeWalletRecharge po) {
        seWalletRechargeMapper.insert(po);
        return po.getId();
    }
 
    /**
     * 电子钱包消费
     * @param po
     * @return
     */
    public Long addConsume(SeConsume po) {
        seConsumeMapper.insert(po);
        return po.getId();
    }
 
    /**
     * 添加退款申请
     * @param po
     * @return
     */
    public Long addRefund(SeRefund po) {
        seRefundMapper.insert(po);
        return po.getId();
    }
 
    /**
     * 根据钱包ID获取待审核的退款申请对象
     * @param walletId
     * @return
     */
    public SeRefund getRefundByWallerId(Long walletId) {
        return seRefundMapper.getRefundByWallerId(walletId);
    }
 
    /**
     * 审核退款申请
     * @param po
     * @return
     */
    public Integer auditRefund(SeRefund po) {
        return seRefundMapper.updateByPrimaryKeySelective(po);
    }
 
    /**
     * 修改电子钱包
     * 充值、消费、申请退款、审核退款时需要修改电子钱包的:余额、最后操作、最后操作时间
     * @param po
     * @return
     */
    public Integer updateWallet(SeWallet po) {
        return seWalletMapper.updateByPrimaryKeySelective(po);
    }
 
 
    /**
     * 根据农户姓名获取电子钱包账户记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoWallet>> getWallets(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        Long itemTotal = seWalletMapper.getRecordCount(params);
 
        QueryResultVo<List<VoWallet>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
 
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seWalletMapper.getWallets(params);
        return rsVo ;
    }
 
    /**
     * 根据指定条件获取电子钱包充值记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoWalletRecharge>> getWalletRecharges(QoWalletRecharge 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 = seWalletRechargeMapper.getRecordCount(params);
 
        QueryResultVo<List<VoWalletRecharge>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
 
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seWalletRechargeMapper.getWalletRecharges(params);
        return rsVo ;
    }
 
    /**
     * 根据农户ID获取电子钱包消费记录
     * @param queryVo
     * @return
     */
    public Map getWalletConsumes(QueryVo queryVo) {
        // 获取电子钱包消费汇总信息
        String clientName = "";
        String clientNum = "";
        Double money = 0.0;
        Double totalConsume = 0.0;
        Long clientId = Optional.ofNullable(queryVo.getClientId()).orElse(0L);
        Map map_consumeSum = Optional.ofNullable(seConsumeMapper.getWalletConsumeSum(clientId)).orElse(new HashMap());
        if(map_consumeSum.size() > 0) {
            clientName = map_consumeSum.get("clientName").toString();
            clientNum = map_consumeSum.get("clientNum").toString();
            money = Double.parseDouble(map_consumeSum.get("money").toString());
            totalConsume = Double.parseDouble(map_consumeSum.get("totalConsume").toString());
        }
 
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        Long itemTotal = seConsumeMapper.getRecordCount(params);
 
        QueryResultVo<List<VoWalletConsume>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
 
        rsVo.calculateAndSet(itemTotal, params);
        List<VoWalletConsume> list = seConsumeMapper.getWalletConsumes(params);
 
 
        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("clientName", clientName);
        map_result.put("clientNum", clientNum);
        map_result.put("money", money);
        map_result.put("totalConsume", totalConsume);
        map_result.put("records", map_record);
 
        return map_result;
    }
 
    /**
     * 根据指定条件获取电子钱包退款记录
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoWalletRefund>> getWalletRefunds(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        Long itemTotal = seRefundMapper.getRecordCount(params);
 
        QueryResultVo<List<VoWalletRefund>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = queryVo.pageSize ;
        rsVo.pageCurr = queryVo.pageCurr ;
 
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = seRefundMapper.getWalletRefunds(params);
        return rsVo ;
    }
}