| | |
| | | import com.ruoyi.common.security.annotation.Logical; |
| | | import com.ruoyi.common.security.annotation.RequiresPermissions; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.api.model.TOrderInvoice; |
| | | import com.ruoyi.order.api.query.TOrderInvoiceQuery; |
| | | import com.ruoyi.order.api.vo.TOrderInvoiceVO; |
| | |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | TOrderInvoice orderInvoice = orderInvoiceService.getById(dto.getId()); |
| | | orderInvoice.setInvoiceUrl(dto.getInvoiceUrl()); |
| | | orderInvoice.setStatus(3); |
| | | orderInvoice.setBillingTime(LocalDateTime.now()); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | orderInvoice.setBillingUserId(userId == null ? null : userId.intValue()); |
| | | orderInvoiceService.updateById(orderInvoice); |
| | | dto.setMailBox(orderInvoice.getMailbox()); |
| | | appUserClient.uploadPdf(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/invoiceManagement/accept_hear_case"}, logical = Logical.OR) |
| | | @PostMapping("/cancel") |
| | | @ApiOperation(value = "取消开票申请", tags = {"管理后台-发票管理"}) |
| | | public AjaxResult<String> cancel(@RequestBody TOrderInvoice dto){ |
| | | TOrderInvoice orderInvoice = orderInvoiceService.getById(dto.getId()); |
| | | if (orderInvoice == null) { |
| | | return AjaxResult.error("开票申请不存在"); |
| | | } |
| | | if (Integer.valueOf(3).equals(orderInvoice.getStatus())) { |
| | | return AjaxResult.error("已完成开票不能取消"); |
| | | } |
| | | orderInvoice.setStatus(4); |
| | | orderInvoice.setCancelTime(LocalDateTime.now()); |
| | | orderInvoiceService.updateById(orderInvoice); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | for (TOrderInvoiceVO orderInvoiceVO : list) { |
| | | OrderInvoiceExport orderInvoiceExport = new OrderInvoiceExport(); |
| | | BeanUtils.copyProperties(orderInvoiceVO,orderInvoiceExport); |
| | | if (orderInvoiceVO.getCreateTime()!=null){ |
| | | orderInvoiceExport.setApplyTime(DateUtils.localDateTimeToString(orderInvoiceVO.getCreateTime())); |
| | | } |
| | | if (orderInvoiceVO.getBillingTime()!=null){ |
| | | orderInvoiceExport.setBillingTime(DateUtils.localDateTimeToString(orderInvoiceVO.getBillingTime())); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载开票申请,单个返回 Excel,多个返回 zip。 |
| | | */ |
| | | @RequiresPermissions(value = {"/invoiceManagement/export"}, logical = Logical.OR) |
| | | @ApiOperation(value = "下载开票申请", tags = {"管理后台-发票管理"}) |
| | | @Log(title = "下载开票申请", businessType = BusinessType.EXPORT) |
| | | @PutMapping("/downloadApplication") |
| | | public void downloadApplication(@RequestBody TOrderInvoiceQuery query) { |
| | | List<TOrderInvoiceVO> list = orderInvoiceService.export(query); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | try { |
| | | if (list.size() == 1) { |
| | | writeInvoiceWorkbook(response, list.get(0), buildInvoiceFileName(list.get(0))); |
| | | return; |
| | | } |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setContentType("application/zip"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("开票申请.zip", "utf-8")); |
| | | try (ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream())) { |
| | | for (TOrderInvoiceVO invoice : list) { |
| | | Workbook workbook = buildInvoiceWorkbook(invoice); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | workbook.write(outputStream); |
| | | workbook.close(); |
| | | zipOutputStream.putNextEntry(new ZipEntry(buildInvoiceFileName(invoice))); |
| | | zipOutputStream.write(outputStream.toByteArray()); |
| | | zipOutputStream.closeEntry(); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void writeInvoiceWorkbook(HttpServletResponse response, TOrderInvoiceVO invoice, String fileName) throws IOException { |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8")); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | Workbook workbook = buildInvoiceWorkbook(invoice); |
| | | try (ServletOutputStream outputStream = response.getOutputStream()) { |
| | | workbook.write(outputStream); |
| | | } |
| | | workbook.close(); |
| | | } |
| | | |
| | | private Workbook buildInvoiceWorkbook(TOrderInvoiceVO invoice) { |
| | | OrderInvoiceExport export = new OrderInvoiceExport(); |
| | | BeanUtils.copyProperties(invoice, export); |
| | | if (invoice.getCreateTime() != null) { |
| | | export.setApplyTime(DateUtils.localDateTimeToString(invoice.getCreateTime())); |
| | | } |
| | | if (invoice.getBillingTime() != null) { |
| | | export.setBillingTime(DateUtils.localDateTimeToString(invoice.getBillingTime())); |
| | | } |
| | | return ExcelExportUtil.exportExcel(new ExportParams(), OrderInvoiceExport.class, Collections.singletonList(export)); |
| | | } |
| | | |
| | | private String buildInvoiceFileName(TOrderInvoiceVO invoice) { |
| | | String title = invoice.getName() == null ? "开票申请" : invoice.getName(); |
| | | String phone = invoice.getUserPhone() == null ? "" : invoice.getUserPhone(); |
| | | return title + phone + ".xls"; |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/getMyOrderInvoiceList") |