puzhibing
2023-06-12 d4f8078c2a062864dab885d6bd54fbe1195f85e2
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
245
246
247
248
249
250
251
252
253
254
255
256
package com.stylefeng.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.controller.resp.TDriverCommissionResp;
import com.stylefeng.guns.modular.system.controller.resp.TRechargeRecordAgentResp;
import com.stylefeng.guns.modular.system.controller.resp.TRechargeRecordUserResp;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
import com.stylefeng.guns.modular.system.model.TDriver;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TRechargeRecord;
import com.stylefeng.guns.modular.system.service.ITRechargeRecordService;
 
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-02-20 11:49:58
 */
@Controller
@RequestMapping("/tRechargeRecord")
public class TRechargeRecordController extends BaseController {
 
    private String PREFIX = "/system/tRechargeRecord/";
 
    @Autowired
    private ITRechargeRecordService tRechargeRecordService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tRechargeRecord.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tRechargeRecord_add")
    public String tRechargeRecordAdd() {
        return PREFIX + "tRechargeRecord_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tRechargeRecord_update/{tRechargeRecordId}")
    public String tRechargeRecordUpdate(@PathVariable Integer tRechargeRecordId, Model model) {
        TRechargeRecord tRechargeRecord = tRechargeRecordService.selectById(tRechargeRecordId);
        model.addAttribute("item",tRechargeRecord);
        LogObjectHolder.me().set(tRechargeRecord);
        return PREFIX + "tRechargeRecord_edit.html";
    }
 
    /**
     * 跳转到用户充值列表
     */
    @RequestMapping("/userRecharge")
    public String userRecharge() {
        return PREFIX + "tRechargeRecordUser.html";
    }
 
    /**
     * 跳转到代理商充值列表
     */
    @RequestMapping("/agentRecharge")
    public String agentRecharge() {
        return PREFIX + "tRechargeRecordAgent.html";
    }
 
    /**
     * 获取用户充值列表
     */
    @RequestMapping(value = "/userRechargeList")
    @ResponseBody
    public Object userRechargeList(String userName,String userPhone,String code,String createTime) {
        return tRechargeRecordService.userRecharge(userName,userPhone,code,createTime);
    }
 
    /**
     * 获取代理商充值列表
     */
    @RequestMapping(value = "/agentRechargeList")
    @ResponseBody
    public Object agentRechargeList(String driverName,String driverPhone,String createTime) {
        return tRechargeRecordService.agentRechargeList(driverName,driverPhone,createTime);
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return tRechargeRecordService.selectList(null);
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TRechargeRecord tRechargeRecord) {
        tRechargeRecordService.insert(tRechargeRecord);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tRechargeRecordId) {
        tRechargeRecordService.deleteById(tRechargeRecordId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TRechargeRecord tRechargeRecord) {
        tRechargeRecordService.updateById(tRechargeRecord);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tRechargeRecordId}")
    @ResponseBody
    public Object detail(@PathVariable("tRechargeRecordId") Integer tRechargeRecordId) {
        return tRechargeRecordService.selectById(tRechargeRecordId);
    }
 
    @ApiOperation(value = "导出用户充值列表",notes="导出用户充值列表")
    @RequestMapping(value = "/exportUserRecharge")
    @ResponseBody
    public void exportUserRecharge(String userName,String userPhone,String code,String createTime, HttpServletResponse response) {
        try {
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyyMMdd");
            String time1 = format.format(date);
            String fileName = "UserRechargeRecord"+time1+".xls";
            String[] title = new String[] {"充值时间","流水ID","用户姓名","用户手机号","充值金额",
                    "充值方式","状态"};
            List<TRechargeRecordUserResp> userRechargeList = tRechargeRecordService.userRecharge(userName,userPhone,code,createTime);
 
            String[][] values = new String[userRechargeList.size()][];
            for (int i = 0; i < userRechargeList.size(); i++) {
                TRechargeRecordUserResp d = userRechargeList.get(i);
                values[i] = new String[title.length];
                values[i][0] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d.getCreateTime());
                values[i][1] = d.getCode();
                values[i][2] = d.getUserName();
                values[i][3] = d.getUserPhone();
                values[i][4] = String.valueOf(Objects.nonNull(d.getAmount())?d.getAmount(): BigDecimal.ZERO);
                Integer payType = d.getPayType();
                if(1 == payType){
                    values[i][5] = "微信";
                }else if(2 == payType){
                    values[i][5] = "系统充值";
                }else{
                    values[i][5] = "其他";
                }
                Integer status1 = d.getPayStatus();
                if(1 == status1){
                    values[i][6] = "失败";
                }else if(2 == status1){
                    values[i][6] = "成功";
                }
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
            ExcelUtil.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @ApiOperation(value = "导出代理商充值列表",notes="导出代理商充值列表")
    @RequestMapping(value = "/exportAgentRecharge")
    @ResponseBody
    public void exportAgentRecharge(String driverName,String driverPhone,String createTime, HttpServletResponse response) {
        try {
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyyMMdd");
            String time1 = format.format(date);
            String fileName = "AgentRechargeRecord"+time1+".xls";
            String[] title = new String[] {"充值时间","代理商姓名","联系电话","代理区域","司机姓名","司机手机号","充值金额",
                    "充值方式","状态"};
            List<TRechargeRecordAgentResp> agentRechargeList = tRechargeRecordService.agentRechargeList(driverName,driverPhone,createTime);
 
            String[][] values = new String[agentRechargeList.size()][];
            for (int i = 0; i < agentRechargeList.size(); i++) {
                TRechargeRecordAgentResp d = agentRechargeList.get(i);
                values[i] = new String[title.length];
                values[i][0] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d.getCreateTime());
                values[i][1] = d.getPrincipal();
                values[i][2] = d.getPrincipalPhone();
                values[i][3] = d.getProvinceName()+d.getCityName();
                values[i][4] = d.getDriverName();
                values[i][5] = d.getDriverPhone();
                values[i][6] = String.valueOf(Objects.nonNull(d.getAmount())?d.getAmount(): BigDecimal.ZERO);
                Integer payType = d.getPayType();
                if(1 == payType){
                    values[i][7] = "微信";
                }else if(2 == payType){
                    values[i][7] = "系统充值";
                }else{
                    values[i][7] = "其他";
                }
                Integer status1 = d.getPayStatus();
                if(1 == status1){
                    values[i][8] = "失败";
                }else if(2 == status1){
                    values[i][8] = "成功";
                }
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
            ExcelUtil.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}