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.TAppUser;
|
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.TAppUserService;
|
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;
|
private final TAppUserService tAppUserService;
|
|
public TPhysicalGoodsOrderController(TPhysicalGoodsOrderService tPhysicalGoodsOrderService, TPhysicalGoodsService tPhysicalGoodsService, TAppUserService tAppUserService) {
|
this.tPhysicalGoodsOrderService = tPhysicalGoodsOrderService;
|
this.tPhysicalGoodsService = tPhysicalGoodsService;
|
this.tAppUserService = tAppUserService;
|
}
|
|
|
@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"));
|
|
Integer appUserId = order.getAppUserId();
|
TAppUser appUser = tAppUserService.getById(appUserId);
|
order.setUserName(appUser.getName());
|
order.setPhone(appUser.getPhone());
|
|
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();
|
}
|
}
|
}
|
|
|
}
|