liujie
2025-12-29 e76b3d267706c06bd1f80e77f9d90890ac2fd546
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
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.system.dto.AuditInsuranceOrderOfflineDTO;
import com.ruoyi.system.dto.AuditInsuranceOrderRefundDTO;
import com.ruoyi.system.export.TInsuranceOrderExport;
import com.ruoyi.system.export.TInsuranceOrderRefundExport;
import com.ruoyi.system.export.TRefundOrderExport;
import com.ruoyi.system.model.TCourse;
import com.ruoyi.system.model.TInsurance;
import com.ruoyi.system.model.TInsuranceOrder;
import com.ruoyi.system.query.TInsuranceOrderQuery;
import com.ruoyi.system.service.TInsuranceOrderService;
import com.ruoyi.system.service.TInsuranceService;
import com.ruoyi.system.vo.TInsuranceOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 用户保险费 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-29
 */
@Api(tags = "保险订单")
@RestController
@RequestMapping("/t-insurance-order")
public class TInsuranceOrderController {
 
    private final TInsuranceOrderService insuranceOrderService;
    private final TInsuranceService insuranceService;
 
    @Autowired
    public TInsuranceOrderController(TInsuranceOrderService insuranceOrderService, TInsuranceService insuranceService) {
        this.insuranceOrderService = insuranceOrderService;
        this.insuranceService = insuranceService;
    }
 
    /**
     * 获取保险订单管理管理列表
     */
    @ApiOperation(value = "获取保险订单记录分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TInsuranceOrderVO>> pageList(@RequestBody TInsuranceOrderQuery query) {
        return R.ok(insuranceOrderService.pageList(query));
    }
    /**
     * 获取保险申请退款记录分页列表
     */
    @ApiOperation(value = "获取保险申请退款记录分页列表")
    @PostMapping(value = "/refundPageList")
    public R<PageInfo<TInsuranceOrderVO>> refundPageList(@RequestBody TInsuranceOrderQuery query) {
        return R.ok(insuranceOrderService.refundPageList(query));
    }
 
    /**
     * 查看保险订单管理详情
     */
    @ApiOperation(value = "查看保险订单管理详情")
    @GetMapping(value = "/getDetailById")
    public R<TInsuranceOrderVO> getDetailById(@RequestParam String id) {
        TInsuranceOrder insuranceOrder = insuranceOrderService.getById(id);
        TInsuranceOrderVO insuranceOrderVO = new TInsuranceOrderVO();
        BeanUtils.copyProperties(insuranceOrder, insuranceOrderVO);
        // 查询保险信息
        TInsurance insurance = insuranceService.getById(insuranceOrder.getInsuranceId());
        insuranceOrderVO.setInsurance(insurance);
        return R.ok(insuranceOrderVO);
    }
 
    /**
     * 审核保险订单管理退款申请
     */
    @Log(title = "保险订单管理信息-审核保险订单管理线下支付", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "审核保险订单管理线下支付")
    @PostMapping(value = "/auditInsuranceOrderOffline")
    public R<String> auditInsuranceOrderOffline(@Validated @RequestBody AuditInsuranceOrderOfflineDTO dto) {
        TInsuranceOrder insuranceOrder = insuranceOrderService.getById(dto.getId());
        if(dto.getOfflineStatus() == 1){
            // 通过
            insuranceOrder.setOfflineVoucher(dto.getOfflineVoucher());
            // 修改支付状态为已退款
            insuranceOrder.setStatus(2);
        }
        if(dto.getOfflineStatus() == 2){
            // 驳回
            insuranceOrder.setOfflineReason(dto.getOfflineReason());
            insuranceOrder.setStatus(4);
        }
        insuranceOrderService.updateById(insuranceOrder);
        return R.ok();
    }
 
    /**
     * 审核保险订单管理退款申请
     */
    @Log(title = "保险订单管理信息-审核保险订单管理退款申请", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "审核保险订单管理退款申请")
    @PostMapping(value = "/auditInsuranceOrderRefund")
    public R<String> auditInsuranceOrderRefund(@Validated @RequestBody AuditInsuranceOrderRefundDTO dto) {
        TInsuranceOrder insuranceOrder = insuranceOrderService.getById(dto.getId());
        insuranceOrder.setRefundStatus(dto.getRefundStatus());
        if(dto.getRefundStatus() == 2){
            // 通过
            insuranceOrder.setRefundVoucher(dto.getRefundVoucher());
            // 修改支付状态为已退款
            insuranceOrder.setStatus(1);
        }
        if(dto.getRefundStatus() == 3){
            // 驳回
            insuranceOrder.setRejectReason(dto.getRejectReason());
            insuranceOrder.setStatus(2);
        }
        insuranceOrderService.updateById(insuranceOrder);
        return R.ok();
    }
 
    /**
     * 删除保险订单管理
     */
    @Log(title = "保险订单管理信息-删除保险订单管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除保险订单管理")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        return R.ok(insuranceOrderService.removeById(id));
    }
 
    /**
     * 批量删除保险订单管理
     */
    @Log(title = "保险订单管理信息-删除保险订单管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除保险订单管理")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        return R.ok(insuranceOrderService.removeByIds(ids));
    }
 
    @Log(title = "保险订单管理信息-保险订单记录导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "保险订单记录导出")
    @PostMapping("/exportInsuranceOrder")
    public void exportInsuranceOrder(@RequestBody TInsuranceOrderQuery query){
        List<TInsuranceOrderExport> insuranceOrderExports = insuranceOrderService.exportInsuranceOrder(query);
        for (TInsuranceOrderExport insuranceOrderExport : insuranceOrderExports) {
            if(Objects.nonNull(insuranceOrderExport.getPayTime())){
                insuranceOrderExport.setPayTimeStr(DateUtils.localDateTimeToString(insuranceOrderExport.getPayTime()));
            }
            if(Objects.nonNull(insuranceOrderExport.getEndTime())){
                insuranceOrderExport.setEndTimeStr(DateUtils.localDateToString(insuranceOrderExport.getEndTime()));
            }
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TInsuranceOrderExport.class, insuranceOrderExports);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("保险订单记录.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @Log(title = "保险订单管理信息-退款记录导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "退款记录导出")
    @PostMapping("/exportRefundOrder")
    public void exportRefundOrder(@RequestBody TInsuranceOrderQuery query){
        List<TInsuranceOrderRefundExport> insuranceOrderRefundExports = insuranceOrderService.exportRefundOrder(query);
        for (TInsuranceOrderRefundExport insuranceOrderRefundExport : insuranceOrderRefundExports) {
            if(Objects.nonNull(insuranceOrderRefundExport.getPayTime())){
                insuranceOrderRefundExport.setPayTimeStr(DateUtils.localDateTimeToString(insuranceOrderRefundExport.getPayTime()));
            }
            if(Objects.nonNull(insuranceOrderRefundExport.getEndTime())){
                insuranceOrderRefundExport.setEndTimeStr(DateUtils.localDateToString(insuranceOrderRefundExport.getEndTime()));
            }
            if(Objects.nonNull(insuranceOrderRefundExport.getRequestRefundTime())){
                insuranceOrderRefundExport.setRequestRefundTimeStr(DateUtils.localDateTimeToString(insuranceOrderRefundExport.getRequestRefundTime()));
            }
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TInsuranceOrderRefundExport.class, insuranceOrderRefundExports);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("保险退款记录.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
}