package com.ruoyi.web.controller.api; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.framework.web.service.TokenService; import com.ruoyi.system.dto.RefundAuditDto; import com.ruoyi.system.export.TPhysicalGoodsImport; import com.ruoyi.system.model.*; import com.ruoyi.system.query.BigGiftPackageQuery; import com.ruoyi.system.query.RefundApplicationQuery; import com.ruoyi.system.service.TAppUserService; import com.ruoyi.system.service.TBigGiftPackageOrderService; import com.ruoyi.system.service.TBigGiftPackageService; import com.ruoyi.system.service.TRefundApplicationService; import com.ruoyi.system.vo.TRefundApplicationVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; 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.net.URLEncoder; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** *

* 退款申请 前端控制器 *

* * @author xiaochen * @since 2025-12-08 */ @RestController @RequestMapping("/t-refund-application") @Api(tags = "(嘉视达)退款申请") public class TRefundApplicationController { private final TRefundApplicationService tRefundApplicationService; private final TokenService tokenService; private final TBigGiftPackageOrderService tBigGiftPackageOrderService; public TRefundApplicationController(TRefundApplicationService tRefundApplicationService, TokenService tokenService, TBigGiftPackageOrderService tBigGiftPackageOrderService) { this.tRefundApplicationService = tRefundApplicationService; this.tokenService = tokenService; this.tBigGiftPackageOrderService = tBigGiftPackageOrderService; } @ApiOperation(value = "退款申请列表") @PostMapping(value = "/pageRefundList") public R> pageRefundList(@RequestBody RefundApplicationQuery query) { Page page = tRefundApplicationService.pageRefundList(query); return R.ok(page); } @ApiOperation(value = "退款申请详情") @GetMapping(value = "/refundDetail/{id}") public R refundDetail(@PathVariable Integer id) { return R.ok(tRefundApplicationService.refundDetail(id)); } @ApiOperation(value = "退款申请删除") @DeleteMapping(value = "/delete/{id}") @Log(title = "退款申请-删除", businessType = BusinessType.DELETE) public R delete(@PathVariable Integer id) { TRefundApplication refundApplication = tRefundApplicationService.getById(id); refundApplication.setDelFlag(1); tRefundApplicationService.updateById(refundApplication); return R.ok(); } @ApiOperation(value = "退款申请审核") @PostMapping(value = "/refundAudit") @Log(title = "退款申请-审核", businessType = BusinessType.UPDATE) public R refundAudit(@RequestBody RefundAuditDto dto) { TRefundApplication refundApplication = tRefundApplicationService.getById(dto.getId()); refundApplication.setStatus(dto.getAuditStatus()); refundApplication.setAuditTime(LocalDateTime.now()); refundApplication.setAuditRemark(dto.getAuditRemark()); Long userId = tokenService.getLoginUser().getUserId(); refundApplication.setAuditUserId(userId); boolean b = tRefundApplicationService.updateById(refundApplication); if (b && dto.getAuditStatus()==2) { Integer bigGiftPackageOrderId = refundApplication.getBigGiftPackageOrderId(); TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(bigGiftPackageOrderId); tBigGiftPackageOrder.setStatus(5); tBigGiftPackageOrderService.updateById(tBigGiftPackageOrder); } return R.ok("操作成功"); } @ApiOperation(value = "退款申请导出") @PostMapping(value = "/export") @Log(title = "退款申请-导出", businessType = BusinessType.EXPORT) public void exportRegistration(@RequestBody BigGiftPackageQuery query){ List list = tRefundApplicationService.pageRefundExportList(query); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TBigGiftPackageOrder.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(); } } } }