“mitao”
2025-12-23 ae7063f5e4a49e2ed55f240440246bdbae3fcc13
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
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.system.model.TBigGiftPackageOrder;
import com.ruoyi.system.model.TPhysicalGoods;
import com.ruoyi.system.model.TPhysicalGoodsOrder;
import com.ruoyi.system.query.BigGiftPackageQuery;
import com.ruoyi.system.service.TPhysicalGoodsOrderService;
import com.ruoyi.system.service.TPhysicalGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.List;
 
/**
 * <p>
 * 实物商品订单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-08
 */
@RestController
@RequestMapping("/t-physical-goods-order")
@Api(tags = "(嘉视达)实物商品订单")
public class TPhysicalGoodsOrderController {
    private final TPhysicalGoodsOrderService tPhysicalGoodsOrderService;
    private final TPhysicalGoodsService tPhysicalGoodsService;
 
    public TPhysicalGoodsOrderController(TPhysicalGoodsOrderService tPhysicalGoodsOrderService, TPhysicalGoodsService tPhysicalGoodsService) {
        this.tPhysicalGoodsOrderService = tPhysicalGoodsOrderService;
        this.tPhysicalGoodsService = tPhysicalGoodsService;
    }
 
 
    @ApiOperation(value = "实物商品订单列表")
    @PostMapping(value = "/pageList")
    public R<Page<TPhysicalGoodsOrder>> pageList(@RequestBody BigGiftPackageQuery query) {
        Page<TPhysicalGoodsOrder> page = tPhysicalGoodsOrderService.pageList(query);
        return R.ok(page);
    }
 
 
    @ApiOperation(value = "实物商品订单详情")
    @GetMapping(value = "/detail/{id}")
    public R<TPhysicalGoodsOrder> detail(@PathVariable("id") Long id) {
        TPhysicalGoodsOrder order = tPhysicalGoodsOrderService.getById(id);
        String physicalGoods = order.getPhysicalGoods();
        JSONObject jsonObject = JSONObject.parseObject(physicalGoods);
//        TPhysicalGoods goods = tPhysicalGoodsService.getById(order.getPhysicalGoodsId());
        order.setPhysicalGoodsName(jsonObject.getString("name"));
        order.setPhysicalGoodsCover(jsonObject.getString("coverImage"));
        order.setPhysicalGoodsPrice(new BigDecimal(jsonObject.getString("totalPrice")).setScale(2, BigDecimal.ROUND_HALF_UP));
        order.setPhysicalGoodsIntro(jsonObject.getString("introduction"));
        return R.ok(order);
    }
 
 
    @ApiOperation(value = "实物商品订单编辑")
    @PostMapping(value = "/edit")
    @Log(title = "实物商品订单-编辑", businessType = BusinessType.UPDATE)
    public R<String> edit(@RequestBody TPhysicalGoodsOrder order) {
        TPhysicalGoodsOrder goodsOrder = tPhysicalGoodsOrderService.getById(order.getId());
        if(goodsOrder.getStatus()!=1){
            return R.fail("待付款状态才可以编辑");
        }
        goodsOrder.setOrderPrice(order.getOrderPrice());
 
        boolean b = tPhysicalGoodsOrderService.updateById(goodsOrder);
        return R.ok("操作成功");
    }
 
 
    @ApiOperation(value = "实物商品订单删除")
    @DeleteMapping(value = "/delete/{id}")
    @Log(title = "实物商品订单-删除", businessType = BusinessType.DELETE)
    public R<String> delete(@PathVariable("id") Integer id) {
        TPhysicalGoodsOrder order = tPhysicalGoodsOrderService.getById(id);
        order.setDelFlag(1);
        boolean b = tPhysicalGoodsOrderService.updateById(order);
        return R.ok("操作成功");
    }
 
 
    @ApiOperation(value = "实物商品订单导出")
    @PostMapping(value = "/export")
    @Log(title = "实物商品订单导出-导出", businessType = BusinessType.EXPORT)
    public void export(@RequestBody BigGiftPackageQuery query){
 
        List<TPhysicalGoodsOrder> list = tPhysicalGoodsOrderService.export(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TPhysicalGoodsOrder.class, list);
        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();
            }
        }
    }
 
 
}