xuhy
2024-12-11 5be07b1a021f596b003eac001f4cb77416ae6c7b
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
257
258
259
260
261
262
263
264
265
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.query.AppUserQuery;
import com.ruoyi.system.query.OrderQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.query.CourseQuery;
import com.ruoyi.web.controller.query.InformationQuery;
import com.ruoyi.web.controller.tool.PayMoneyUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/t-order")
public class TOrderController {
    @Resource
    private TOrderService orderService;
 
    @Resource
    private TCourseService courseService;
    @Resource
    private TRegionService regionService;
    @Resource
    private TTechnicalTitleService tTechnicalTitleService;
    @Resource
    private TTitleMajorService majorService;
    @Resource
    private TGeneratedRecordsService generatedRecordsService;
    @Resource
    private TInformationService informationService;
    @Resource
    private PayMoneyUtil payMoneyUtil;
    @Resource
    private TokenService tokenService;
    @Resource
    private TAppUserService appUserService;
 
 
    //查询
    @ApiOperation(value = "查询",tags = "后台-订单管理")
    @PostMapping("/pageList")
    public R<PageInfo<TOrder>> pageList(@RequestBody OrderQuery orderQuery){
        return R.ok(orderService.pageList(orderQuery));
    }
 
    @ApiOperation(value = "删除",tags = "web-订单管理")
    @PostMapping("/delete")
    public R delete(@RequestParam Long orderId){
        orderService.removeById(orderId);
        return R.ok();
    }
 
    @ApiOperation(value = "订单查询",tags = "web-个人中心")
    @PostMapping("/web/pageList")
    public R<PageInfo<TOrder>> webpageList(@RequestBody OrderQuery orderQuery){
        Long userId = tokenService.getLoginUser().getUserId();
        orderQuery.setUserId(userId);
        return R.ok(orderService.pageList(orderQuery));
    }
 
 
    @ApiOperation(value = "计数",tags = "后台-订单管理")
    @PostMapping("/count")
    public R<List<Map<String,Object>>> count(@RequestBody OrderQuery orderQuery){
        return R.ok(orderService.totalCount(orderQuery));
    }
 
 
    @ApiOperation(value = "取消订单",tags = {"后台-订单管理","web-个人中心"})
    @PostMapping("/cancel")
    public R cancel(Long orderId){
         TOrder byId = orderService.getById(orderId);
         if (byId.getPaymentStatus()!=1){
             return R.fail("订单状态异常");
         }
         byId.setPaymentStatus(3);
        byId.setCancelTime(LocalDateTime.now());
         orderService.updateById(byId);
        return R.ok();
    }
 
 
    @ApiOperation(value = "课程详情",tags = "后台-订单管理")
    @PostMapping(value = "/course/detail")
    public R<TCourse> list(Long id,Long goodId) {
        TCourse course = courseService.getById(goodId);
 
 
            TRegion byId = regionService.getById(course.getRegionId());
        course.setRegionName(byId.getProvinceName()+"-"+byId.getName());
            TTechnicalTitle byId1 = tTechnicalTitleService.getById(course.getTechnicalId() );
            TTitleMajor byId2 = majorService.getById(course.getMajorId());
        course.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName());
 
        TOrder byId3 = orderService.getById(id);
        TAppUser byId4 = appUserService.getById(byId3.getUserId());
        byId3.setName(byId4.getName());
        byId3.setPhone(byId4.getPhone());
        byId3.setAvatar(byId4.getAvatar());
        course.setOrder(byId3);
 
 
        return R.ok(course);
    }
 
    @ApiOperation(value = "工作总结详情",tags = "后台-订单管理")
    @PostMapping("/generate/detail")
    public R<TGeneratedRecords> detail(Long id){
        TOrder byId = orderService.getById(id);
        TGeneratedRecords one = generatedRecordsService.lambdaQuery().eq(TGeneratedRecords::getUserId, byId.getUserId()).orderByDesc(TGeneratedRecords::getCreateTime).last("limit 1").one();
        if (one == null) {
            TGeneratedRecords generatedRecords = new TGeneratedRecords();
            generatedRecords.setOrder(byId);
            return R.ok(generatedRecords);
        }
 
        TOrder byId3 = orderService.getById(id);
        TAppUser byId4 = appUserService.getById(byId3.getUserId());
        byId3.setName(byId4.getName());
        byId3.setPhone(byId4.getPhone());
        byId3.setAvatar(byId4.getAvatar());
        one.setOrder(byId3);
 
        return R.ok(one);
    }
 
 
    @ApiOperation(value = "资料详情",tags = "后台-订单管理")
    @PostMapping(value = "/order/information/detail")
    public R<TInformation> informationR1(Long goodId,Long id) {
      TInformation record = informationService.getById(goodId);
            TRegion byId = regionService.getById(record.getRegionId());
            record.setRegionName(byId.getProvinceName()+"-"+byId.getName());
            TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId());
            TTitleMajor byId2 = majorService.getById(record.getMajorId());
            record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName());
 
 
        TOrder byId3 = orderService.getById(id);
        TAppUser byId4 = appUserService.getById(byId3.getUserId());
        byId3.setName(byId4.getName());
        byId3.setPhone(byId4.getPhone());
        byId3.setAvatar(byId4.getAvatar());
        record.setOrder(byId3);
 
 
        return R.ok(record);
    }
 
 
    @ApiOperation(value = "资料详情",tags = "后台-资料管理")
    @PostMapping(value = "/information/detail")
    public R<TInformation> informationR(Long goodId) {
        TInformation record = informationService.getById(goodId);
        TRegion byId = regionService.getById(record.getRegionId());
        record.setRegionName(byId.getProvinceName()+"-"+byId.getName());
        TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId());
        TTitleMajor byId2 = majorService.getById(record.getMajorId());
        record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName());
 
 
 
        return R.ok(record);
    }
 
    @ApiOperation(value = "退款",tags = "后台-资料管理")
    @PostMapping(value = "/refund")
    public R<TInformation> refund(Long orderId) throws AlipayApiException {
        TOrder byId = orderService.getById(orderId);
        if (byId.getPaymentStatus()!=2){
            return R.fail("订单状态异常");
        }
 
        if (byId.getPaymentType()==1){
            payMoneyUtil.wxRefund(byId.getSerialNumber(), byId.getCode(),byId.getPaymentAmount().toString(), byId.getPaymentAmount().toString(),"/");
        }
        if (byId.getPaymentType()==2){
            Map<String, String> stringStringMap = payMoneyUtil.aliRefund(byId.getCode(), byId.getPaymentAmount().toString());
            if ("10000".equals(stringStringMap.get("code"))){
                byId.setPaymentStatus(4);
                orderService.updateById(byId);
            }
        }
 
        return R.ok();
    }
 
 
    @ApiOperation(value = "导出",tags = "后台-订单管理")
    @PostMapping(value = "/export")
    public void mealGeneratorExport(@RequestBody OrderQuery orderQuery) {
        orderQuery.setPageNum(1);
        orderQuery.setPageSize(9999);
        PageInfo<TOrder> tOrderPageInfo = orderService.pageList(orderQuery);
        for (TOrder record : tOrderPageInfo.getRecords()) {
            record.getFormattedCreateTime();
            if (record.getGoodType()==1){
                TCourse byId = courseService.getById(record.getGoodId());
                record.setGoodName(byId.getCourseName());
            }else if (record.getGoodType()==2){
                TInformation byId = informationService.getById(record.getGoodId());
                record.setGoodName(byId.getInformationName());
            }else {
                record.setGoodName("工作总结订单");
            }
        }
 
 
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TOrder.class,tOrderPageInfo.getRecords() );
        HttpServletResponse response = WebUtils.response();
        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();
            }
        }
    }
 
 
}