From 5388ea5e4164d47818357a6eaa18503d266387e9 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 2 Dec 2023 15:27:29 +0800 Subject: [PATCH 1/5] fetch: add other storage export api #245 --- .../api/warehouse/OtherStorageController.java | 16 +++--- .../wansenai/vo/warehouse/OtherStorageVO.java | 13 ++++- .../warehouse/OtherStorageService.java | 3 ++ .../impl/OtherStorageServiceImpl.java | 54 +++++++++++++++++++ web/src/api/warehouse/storage.ts | 11 ++++ web/src/views/warehouse/storage/index.vue | 24 +++++---- 6 files changed, 100 insertions(+), 21 deletions(-) diff --git a/core/api/src/main/java/com/wansenai/api/warehouse/OtherStorageController.java b/core/api/src/main/java/com/wansenai/api/warehouse/OtherStorageController.java index 222e06f9..23f61aea 100644 --- a/core/api/src/main/java/com/wansenai/api/warehouse/OtherStorageController.java +++ b/core/api/src/main/java/com/wansenai/api/warehouse/OtherStorageController.java @@ -19,14 +19,8 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherStorageDetailVO; import com.wansenai.vo.warehouse.OtherStorageVO; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.PostMapping; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -64,4 +58,10 @@ public Response deleteOtherStorageByIds(@RequestParam("ids") List public Response updateOtherStorageStatusByIds(@RequestParam("ids") List ids, @RequestParam("status") Integer status) { return otherStorageService.updateOtherStorageStatus(ids, status); } + + @GetMapping("export") + public void exportOtherStorage(@ModelAttribute QueryOtherStorageDTO queryOtherStorageDTO, HttpServletResponse response) throws Exception { + otherStorageService.exportOtherStorage(queryOtherStorageDTO, response); + } + } diff --git a/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherStorageVO.java b/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherStorageVO.java index 168d14fc..86828450 100644 --- a/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherStorageVO.java +++ b/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherStorageVO.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.wansenai.bo.BigDecimalSerializerBO; +import com.wansenai.utils.excel.ExcelExport; import lombok.Builder; import lombok.Data; @@ -28,21 +29,29 @@ public class OtherStorageVO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Long id; + @ExcelExport(value = "供应商") private String supplierName; + @ExcelExport(value = "单据编号") private String receiptNumber; + @ExcelExport(value = "商品信息") private String productInfo; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelExport(value = "单据日期") private LocalDateTime receiptDate; - private String operator; - + @ExcelExport(value = "商品数量") private Integer productNumber; @JsonSerialize(using = BigDecimalSerializerBO.class) + @ExcelExport(value = "金额合计") private BigDecimal totalAmount; + @ExcelExport(value = "操作员") + private String operator; + + @ExcelExport(value = "状态", kv = "0-未审核;1-已审核") private Integer status; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/OtherStorageService.java b/core/service/src/main/java/com/wansenai/service/warehouse/OtherStorageService.java index 91ad7f28..a130220e 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/OtherStorageService.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/OtherStorageService.java @@ -20,6 +20,7 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherStorageDetailVO; import com.wansenai.vo.warehouse.OtherStorageVO; +import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -34,4 +35,6 @@ public interface OtherStorageService extends IService { Response deleteBatchOtherStorage(List ids); Response updateOtherStorageStatus(List ids, Integer status); + + void exportOtherStorage(QueryOtherStorageDTO queryOtherStorageDTO, HttpServletResponse response) throws Exception; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherStorageServiceImpl.java b/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherStorageServiceImpl.java index 490134eb..83468c7f 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherStorageServiceImpl.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherStorageServiceImpl.java @@ -38,9 +38,11 @@ import com.wansenai.utils.constants.CommonConstants; import com.wansenai.utils.enums.BaseCodeEnum; import com.wansenai.utils.enums.OtherStorageCodeEnum; +import com.wansenai.utils.excel.ExcelUtils; import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherStorageDetailVO; import com.wansenai.vo.warehouse.OtherStorageVO; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -179,6 +181,49 @@ public Response> getOtherStoragePageList(QueryOtherStorageD result.setTotal(wrapperMainMapper.getTotal()); return Response.responseData(result); } + + private List getOtherStorageList(QueryOtherStorageDTO queryOtherStorageDTO) { + var wrapperMainMapper = lambdaQuery() + .eq(queryOtherStorageDTO.getSupplierId() != null, WarehouseReceiptMain::getRelatedPersonId, queryOtherStorageDTO.getSupplierId()) + .eq(queryOtherStorageDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryOtherStorageDTO.getOperatorId()) + .eq(queryOtherStorageDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryOtherStorageDTO.getStatus()) + .eq(StringUtils.hasLength(queryOtherStorageDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryOtherStorageDTO.getReceiptNumber()) + .eq(StringUtils.hasLength(queryOtherStorageDTO.getOtherReceipt()), WarehouseReceiptMain::getReceiptNumber, queryOtherStorageDTO.getOtherReceipt()) + .like(StringUtils.hasLength(queryOtherStorageDTO.getRemark()), WarehouseReceiptMain::getRemark, queryOtherStorageDTO.getRemark()) + .ge(StringUtils.hasLength(queryOtherStorageDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryOtherStorageDTO.getStartDate()) + .le(StringUtils.hasLength(queryOtherStorageDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryOtherStorageDTO.getEndDate()) + .eq(WarehouseReceiptMain::getType, "其他入库") + .eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED) + .list(); + + var otherStorageVOList = new ArrayList(wrapperMainMapper.size() + 1); + wrapperMainMapper.forEach(item -> { + + var product = productService.getById(item.getProductId()); + var productInfo = ""; + if(product != null) { + productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit(); + } + + var operator = userService.getById(item.getCreateBy()); + var otherStorageVO = OtherStorageVO.builder() + .id(item.getId()) + .receiptNumber(item.getReceiptNumber()) + .productInfo(productInfo) + .supplierName(commonService.getSupplierName(item.getRelatedPersonId())) + .receiptDate(item.getReceiptDate()) + .operator(Optional.ofNullable(operator).map(SysUser::getName).orElse("")) + .productNumber(item.getTotalProductNumber()) + .totalAmount(item.getTotalAmount()) + .status(item.getStatus()) + .build(); + + otherStorageVOList.add(otherStorageVO); + }); + return otherStorageVOList; + } + + @Override public Response getOtherStorageDetail(Long id) { if (id == null) { @@ -383,4 +428,13 @@ public Response updateOtherStorageStatus(List ids, Integer status) } return Response.responseMsg(OtherStorageCodeEnum.UPDATE_OTHER_STORAGE_STOCK_SUCCESS); } + + @Override + public void exportOtherStorage(QueryOtherStorageDTO queryOtherStorageDTO, HttpServletResponse response) throws Exception { + var data = getOtherStorageList(queryOtherStorageDTO); + if (!data.isEmpty()) { + var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "其他入库", data); + ExcelUtils.downloadExcel(file, "其他入库", response); + } + } } diff --git a/web/src/api/warehouse/storage.ts b/web/src/api/warehouse/storage.ts index 5b30d197..5261088a 100644 --- a/web/src/api/warehouse/storage.ts +++ b/web/src/api/warehouse/storage.ts @@ -14,6 +14,7 @@ enum API { DeleteBatch = '/warehouse/otherStorage/deleteByIds', UpdateStatus = '/warehouse/otherStorage/updateStatusByIds', GetDetail = '/warehouse/otherStorage/getDetailById', + Export = '/warehouse/otherStorage/export', } export function getOtherStoragePageList(params: QueryOtherStorageReq) { @@ -65,4 +66,14 @@ export function getOtherStorageDetailById(id: number) { url: `${API.GetDetail}/${id}` }, ); +} + +export function exportOtherStorage(params: QueryOtherStorageReq) { + return defHttp.get>( + { + url: `${API.Export}`, + params, + responseType: "blob" + } + ); } \ No newline at end of file diff --git a/web/src/views/warehouse/storage/index.vue b/web/src/views/warehouse/storage/index.vue index ffabdccb..7cd4b089 100644 --- a/web/src/views/warehouse/storage/index.vue +++ b/web/src/views/warehouse/storage/index.vue @@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue"; import {BasicTable, TableAction, useTable} from "@/components/Table"; import {useMessage} from "@/hooks/web/useMessage"; import {columns, searchFormSchema} from "@/views//warehouse/storage/otherStorage.data"; -import {exportXlsx} from "@/api/basic/common"; import {useI18n} from "vue-i18n"; -import {getOtherStoragePageList, deleteBatchOtherStorage, updateOtherStorageStatus} from "@/api/warehouse/storage"; +import {getOtherStoragePageList, deleteBatchOtherStorage, updateOtherStorageStatus, exportOtherStorage} from "@/api/warehouse/storage"; import AddEditOtherStorageModal from "@/views/warehouse/storage/components/AddEditOtherStorageModal.vue" import ViewOtherStorageModal from "@/views/warehouse/storage/components/ViewOtherStorageModal.vue"; import {Tag} from "ant-design-vue"; @@ -67,7 +66,7 @@ export default defineComponent({ const { createMessage } = useMessage(); const addEditModalRef = ref(null); const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal(); - const [registerTable, { reload, getSelectRows }] = useTable({ + const [registerTable, { reload, getSelectRows, getForm }] = useTable({ title: '其他入库列表', rowKey: 'id', api: getOtherStoragePageList, @@ -169,14 +168,17 @@ export default defineComponent({ } async function handleExport() { - const file = await exportXlsx("其他入库列表") - const blob = new Blob([file]); - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - const timestamp = getTimestamp(new Date()); - link.download = "其他入库数据" + timestamp + ".xlsx"; - link.target = "_blank"; - link.click(); + const data = getForm().getFieldsValue(); + const file: any = await exportOtherStorage(data) + if (file.size > 0) { + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "其他入库数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } } From 6ebf8fb17c81c6f9e9ff4dcdf5472e82c3b31859 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 2 Dec 2023 15:27:49 +0800 Subject: [PATCH 2/5] fetch: add other shipments export api #245 --- .../warehouse/OtherShipmentsController.java | 15 +++--- .../vo/warehouse/OtherShipmentVO.java | 13 ++++- .../warehouse/OtherShipmentsService.java | 3 ++ .../impl/OtherShipmentsServiceImpl.java | 52 +++++++++++++++++++ web/src/api/warehouse/shipments.ts | 11 ++++ web/src/views/warehouse/shipments/index.vue | 24 +++++---- 6 files changed, 97 insertions(+), 21 deletions(-) diff --git a/core/api/src/main/java/com/wansenai/api/warehouse/OtherShipmentsController.java b/core/api/src/main/java/com/wansenai/api/warehouse/OtherShipmentsController.java index 270d6062..5fe77806 100644 --- a/core/api/src/main/java/com/wansenai/api/warehouse/OtherShipmentsController.java +++ b/core/api/src/main/java/com/wansenai/api/warehouse/OtherShipmentsController.java @@ -19,14 +19,8 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherShipmentDetailVO; import com.wansenai.vo.warehouse.OtherShipmentVO; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.PostMapping; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -64,4 +58,9 @@ public Response deleteOtherShipmentsByIds(@RequestParam("ids") List updateOtherShipmentsStatusByIds(@RequestParam("ids") List ids, @RequestParam("status") Integer status) { return otherShipmentsService.updateOtherShipmentsStatus(ids, status); } + + @GetMapping("export") + public void exportOtherShipments(@ModelAttribute QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception { + otherShipmentsService.exportOtherShipments(queryOtherShipmentDTO, response); + } } diff --git a/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherShipmentVO.java b/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherShipmentVO.java index 8302c541..226bbc90 100644 --- a/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherShipmentVO.java +++ b/core/domain/src/main/java/com/wansenai/vo/warehouse/OtherShipmentVO.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.wansenai.bo.BigDecimalSerializerBO; +import com.wansenai.utils.excel.ExcelExport; import lombok.Builder; import lombok.Data; @@ -28,21 +29,29 @@ public class OtherShipmentVO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Long id; + @ExcelExport(value = "客户") private String customerName; + @ExcelExport(value = "单据编号") private String receiptNumber; + @ExcelExport(value = "商品信息") private String productInfo; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelExport(value = "单据日期") private LocalDateTime receiptDate; - private String operator; - + @ExcelExport(value = "商品数量") private Integer productNumber; @JsonSerialize(using = BigDecimalSerializerBO.class) + @ExcelExport(value = "金额合计") private BigDecimal totalAmount; + @ExcelExport(value = "操作员") + private String operator; + + @ExcelExport(value = "状态", kv = "0-未审核;1-已审核") private Integer status; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/OtherShipmentsService.java b/core/service/src/main/java/com/wansenai/service/warehouse/OtherShipmentsService.java index 7e4c0222..64f2d083 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/OtherShipmentsService.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/OtherShipmentsService.java @@ -20,6 +20,7 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherShipmentDetailVO; import com.wansenai.vo.warehouse.OtherShipmentVO; +import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -34,4 +35,6 @@ public interface OtherShipmentsService extends IService { Response deleteBatchOtherShipments(List ids); Response updateOtherShipmentsStatus(List ids, Integer status); + + void exportOtherShipments(QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherShipmentsServiceImpl.java b/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherShipmentsServiceImpl.java index aaee3db8..f5eb1159 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherShipmentsServiceImpl.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/impl/OtherShipmentsServiceImpl.java @@ -37,9 +37,11 @@ import com.wansenai.utils.constants.CommonConstants; import com.wansenai.utils.enums.BaseCodeEnum; import com.wansenai.utils.enums.OtherShipmentCodeEnum; +import com.wansenai.utils.excel.ExcelUtils; import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.OtherShipmentDetailVO; import com.wansenai.vo.warehouse.OtherShipmentVO; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -179,6 +181,47 @@ public Response> getOtherShipmentsPageList(QueryOtherShipm return Response.responseData(result); } + private List getOtherShipmentsList(QueryOtherShipmentDTO queryOtherShipmentDTO) { + var wrapperMainMapper = lambdaQuery() + .eq(queryOtherShipmentDTO.getCustomerId() != null, WarehouseReceiptMain::getRelatedPersonId, queryOtherShipmentDTO.getCustomerId()) + .eq(queryOtherShipmentDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryOtherShipmentDTO.getOperatorId()) + .eq(queryOtherShipmentDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryOtherShipmentDTO.getStatus()) + .eq(StringUtils.hasLength(queryOtherShipmentDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryOtherShipmentDTO.getReceiptNumber()) + .eq(StringUtils.hasLength(queryOtherShipmentDTO.getOtherReceipt()), WarehouseReceiptMain::getReceiptNumber, queryOtherShipmentDTO.getOtherReceipt()) + .like(StringUtils.hasLength(queryOtherShipmentDTO.getRemark()), WarehouseReceiptMain::getRemark, queryOtherShipmentDTO.getRemark()) + .ge(StringUtils.hasLength(queryOtherShipmentDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryOtherShipmentDTO.getStartDate()) + .le(StringUtils.hasLength(queryOtherShipmentDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryOtherShipmentDTO.getEndDate()) + .eq(WarehouseReceiptMain::getType, "其他出库") + .eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED) + .list(); + + var otherShipmentVOList = new ArrayList(wrapperMainMapper.size() + 1); + wrapperMainMapper.forEach(item -> { + + var product = productService.getById(item.getProductId()); + var productInfo = ""; + if(product != null) { + productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit(); + } + + var operator = userService.getById(item.getCreateBy()); + var otherShipmentVO = OtherShipmentVO.builder() + .id(item.getId()) + .receiptNumber(item.getReceiptNumber()) + .productInfo(productInfo) + .customerName(commonService.getCustomerName(item.getRelatedPersonId())) + .receiptDate(item.getReceiptDate()) + .operator(Optional.ofNullable(operator).map(SysUser::getName).orElse("")) + .productNumber(item.getTotalProductNumber()) + .totalAmount(item.getTotalAmount()) + .status(item.getStatus()) + .build(); + + otherShipmentVOList.add(otherShipmentVO); + }); + return otherShipmentVOList; + } + @Override public Response getOtherShipmentsDetail(Long id) { if (id == null) { @@ -383,4 +426,13 @@ public Response updateOtherShipmentsStatus(List ids, Integer statu } return Response.responseMsg(OtherShipmentCodeEnum.UPDATE_OTHER_SHIPMENT_STOCK_SUCCESS); } + + @Override + public void exportOtherShipments(QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception { + var data = getOtherShipmentsList(queryOtherShipmentDTO); + if (!data.isEmpty()) { + var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "其他出库", data); + ExcelUtils.downloadExcel(file, "其他出库", response); + } + } } diff --git a/web/src/api/warehouse/shipments.ts b/web/src/api/warehouse/shipments.ts index 1fc203d4..2908e886 100644 --- a/web/src/api/warehouse/shipments.ts +++ b/web/src/api/warehouse/shipments.ts @@ -14,6 +14,7 @@ enum API { DeleteBatch = '/warehouse/otherShipments/deleteByIds', UpdateStatus = '/warehouse/otherShipments/updateStatusByIds', GetDetail = '/warehouse/otherShipments/getDetailById', + Export = '/warehouse/otherShipments/export', } export function getOtherShipmentsPageList(params: QueryOtherShipmentsReq) { @@ -65,4 +66,14 @@ export function getOtherShipmentsDetailById(id: number) { url: `${API.GetDetail}/${id}` }, ); +} + +export function exportOtherShipments(params: QueryOtherShipmentsReq) { + return defHttp.get>( + { + url: `${API.Export}`, + params, + responseType: "blob" + } + ); } \ No newline at end of file diff --git a/web/src/views/warehouse/shipments/index.vue b/web/src/views/warehouse/shipments/index.vue index 21d18a4c..f81f61ae 100644 --- a/web/src/views/warehouse/shipments/index.vue +++ b/web/src/views/warehouse/shipments/index.vue @@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue"; import {BasicTable, TableAction, useTable} from "@/components/Table"; import {useMessage} from "@/hooks/web/useMessage"; import {columns, searchFormSchema} from "@/views//warehouse/shipments/otherShipments.data"; -import {exportXlsx} from "@/api/basic/common"; import {useI18n} from "vue-i18n"; -import {getOtherShipmentsPageList, deleteBatchOtherShipments, updateOtherShipmentsStatus} from "@/api/warehouse/shipments"; +import {getOtherShipmentsPageList, deleteBatchOtherShipments, updateOtherShipmentsStatus, exportOtherShipments} from "@/api/warehouse/shipments"; import AddEditOtherShipmentsModal from "@/views/warehouse/shipments/components/AddEditOtherShipmentsModal.vue" import ViewOtherShipmentsModal from "@/views/warehouse/shipments/components/ViewOtherShipmentsModal.vue"; import {Tag} from "ant-design-vue"; @@ -67,7 +66,7 @@ export default defineComponent({ const { createMessage } = useMessage(); const addEditModalRef = ref(null); const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal(); - const [registerTable, { reload, getSelectRows }] = useTable({ + const [registerTable, { reload, getSelectRows, getForm }] = useTable({ title: '其他出库列表', rowKey: 'id', api: getOtherShipmentsPageList, @@ -169,14 +168,17 @@ export default defineComponent({ } async function handleExport() { - const file = await exportXlsx("其他出库列表") - const blob = new Blob([file]); - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - const timestamp = getTimestamp(new Date()); - link.download = "其他出库数据" + timestamp + ".xlsx"; - link.target = "_blank"; - link.click(); + const data = getForm().getFieldsValue(); + const file: any = await exportOtherShipments(data) + if (file.size > 0) { + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "其他出库数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } } From 693d5a586a31daceef0b72b642352fce49c03a0d Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 2 Dec 2023 15:28:08 +0800 Subject: [PATCH 3/5] fetch: add disassemble receipt export api #245 --- .../api/warehouse/DisAssembleController.java | 15 +++--- .../vo/warehouse/DisassembleReceiptVO.java | 12 ++++- .../warehouse/DisassembleReceiptService.java | 3 ++ .../impl/DisassembleReceiptServiceImpl.java | 49 +++++++++++++++++++ web/src/api/warehouse/disassemble.ts | 11 +++++ web/src/views/warehouse/disassemble/index.vue | 24 ++++----- 6 files changed, 93 insertions(+), 21 deletions(-) diff --git a/core/api/src/main/java/com/wansenai/api/warehouse/DisAssembleController.java b/core/api/src/main/java/com/wansenai/api/warehouse/DisAssembleController.java index bbd71970..8f737fc4 100644 --- a/core/api/src/main/java/com/wansenai/api/warehouse/DisAssembleController.java +++ b/core/api/src/main/java/com/wansenai/api/warehouse/DisAssembleController.java @@ -19,14 +19,8 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.DisassembleReceiptDetailVO; import com.wansenai.vo.warehouse.DisassembleReceiptVO; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.PostMapping; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -64,4 +58,9 @@ public Response deleteDisAssembleReceiptByIds(@RequestParam("ids") List< public Response updateDisAssembleReceiptStatusByIds(@RequestParam("ids") List ids, @RequestParam("status") Integer status) { return disassembleService.updateDisassembleReceiptStatus(ids, status); } + + @GetMapping("export") + public void exportDisAssembleReceipt(@ModelAttribute QueryDisassembleReceiptDTO queryDisassembleReceiptDTO, HttpServletResponse response) throws Exception { + disassembleService.exportDisAssembleReceipt(queryDisassembleReceiptDTO, response); + } } diff --git a/core/domain/src/main/java/com/wansenai/vo/warehouse/DisassembleReceiptVO.java b/core/domain/src/main/java/com/wansenai/vo/warehouse/DisassembleReceiptVO.java index adcc0aaa..34b4cf36 100644 --- a/core/domain/src/main/java/com/wansenai/vo/warehouse/DisassembleReceiptVO.java +++ b/core/domain/src/main/java/com/wansenai/vo/warehouse/DisassembleReceiptVO.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.wansenai.bo.BigDecimalSerializerBO; +import com.wansenai.utils.excel.ExcelExport; import lombok.Builder; import lombok.Data; @@ -28,19 +29,26 @@ public class DisassembleReceiptVO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Long id; + @ExcelExport(value = "单据编号") private String receiptNumber; + @ExcelExport(value = "商品信息") private String productInfo; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelExport(value = "单据日期") private LocalDateTime receiptDate; - private String operator; - + @ExcelExport(value = "商品数量") private Integer productNumber; @JsonSerialize(using = BigDecimalSerializerBO.class) + @ExcelExport(value = "金额合计") private BigDecimal totalAmount; + @ExcelExport(value = "操作员") + private String operator; + + @ExcelExport(value = "状态", kv = "0-未审核;1-已审核") private Integer status; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/DisassembleReceiptService.java b/core/service/src/main/java/com/wansenai/service/warehouse/DisassembleReceiptService.java index b1124ccd..f8b9d20b 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/DisassembleReceiptService.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/DisassembleReceiptService.java @@ -20,6 +20,7 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.DisassembleReceiptDetailVO; import com.wansenai.vo.warehouse.DisassembleReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -34,4 +35,6 @@ public interface DisassembleReceiptService extends IService deleteBatchDisassembleReceipt(List ids); Response updateDisassembleReceiptStatus(List ids, Integer status); + + void exportDisAssembleReceipt(QueryDisassembleReceiptDTO queryDisassembleReceiptDTO, HttpServletResponse response) throws Exception; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/impl/DisassembleReceiptServiceImpl.java b/core/service/src/main/java/com/wansenai/service/warehouse/impl/DisassembleReceiptServiceImpl.java index 31760f76..ffe64986 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/impl/DisassembleReceiptServiceImpl.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/impl/DisassembleReceiptServiceImpl.java @@ -38,11 +38,13 @@ import com.wansenai.utils.enums.AssembleReceiptCodeEnum; import com.wansenai.utils.enums.BaseCodeEnum; import com.wansenai.utils.enums.DisassembleReceiptCodeEnum; +import com.wansenai.utils.excel.ExcelUtils; import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AssembleReceiptDetailVO; import com.wansenai.vo.warehouse.AssembleReceiptVO; import com.wansenai.vo.warehouse.DisassembleReceiptDetailVO; import com.wansenai.vo.warehouse.DisassembleReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -181,6 +183,44 @@ public Response> getDisassembleReceiptPageList(QueryD return Response.responseData(result); } + public List getDisassembleReceiptList(QueryDisassembleReceiptDTO queryDisassembleReceiptDTO) { + var wrapperMainMapper = lambdaQuery() + .eq(queryDisassembleReceiptDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryDisassembleReceiptDTO.getOperatorId()) + .eq(queryDisassembleReceiptDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryDisassembleReceiptDTO.getStatus()) + .eq(StringUtils.hasLength(queryDisassembleReceiptDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryDisassembleReceiptDTO.getReceiptNumber()) + .like(StringUtils.hasLength(queryDisassembleReceiptDTO.getRemark()), WarehouseReceiptMain::getRemark, queryDisassembleReceiptDTO.getRemark()) + .ge(StringUtils.hasLength(queryDisassembleReceiptDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryDisassembleReceiptDTO.getStartDate()) + .le(StringUtils.hasLength(queryDisassembleReceiptDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryDisassembleReceiptDTO.getEndDate()) + .eq(WarehouseReceiptMain::getType, "拆卸单") + .eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED) + .list(); + + var disAssembleReceiptVOList = new ArrayList(wrapperMainMapper.size() + 1); + wrapperMainMapper.forEach(item -> { + + var product = productService.getById(item.getProductId()); + var productInfo = ""; + if(product != null) { + productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit(); + } + + var operator = userService.getById(item.getCreateBy()); + var disAssembleReceiptVO = DisassembleReceiptVO.builder() + .id(item.getId()) + .receiptNumber(item.getReceiptNumber()) + .productInfo(productInfo) + .receiptDate(item.getReceiptDate()) + .operator(Optional.ofNullable(operator).map(SysUser::getName).orElse("")) + .productNumber(item.getTotalProductNumber()) + .totalAmount(item.getTotalAmount()) + .status(item.getStatus()) + .build(); + + disAssembleReceiptVOList.add(disAssembleReceiptVO); + }); + return disAssembleReceiptVOList; + } + @Override public Response getDisassembleReceiptDetail(Long id) { if (id == null) { @@ -432,4 +472,13 @@ public Response updateDisassembleReceiptStatus(List ids, Integer s } return Response.responseMsg(DisassembleReceiptCodeEnum.UPDATE_DISASSEMBLE_RECEIPT_SUCCESS); } + + @Override + public void exportDisAssembleReceipt(QueryDisassembleReceiptDTO queryDisassembleReceiptDTO, HttpServletResponse response) throws Exception { + var data = getDisassembleReceiptList(queryDisassembleReceiptDTO); + if (!data.isEmpty()) { + var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "拆卸单", data); + ExcelUtils.downloadExcel(file, "拆卸单", response); + } + } } diff --git a/web/src/api/warehouse/disassemble.ts b/web/src/api/warehouse/disassemble.ts index c52ece2f..345b4529 100644 --- a/web/src/api/warehouse/disassemble.ts +++ b/web/src/api/warehouse/disassemble.ts @@ -14,6 +14,7 @@ enum API { DeleteBatch = '/warehouse/disassemble/deleteByIds', UpdateStatus = '/warehouse/disassemble/updateStatusByIds', GetDetail = '/warehouse/disassemble/getDetailById', + Export = '/warehouse/disassemble/export', } export function getDisAssemblePageList(params: QueryDisAssembleReq) { @@ -65,4 +66,14 @@ export function getDisAssembleDetailById(id: number) { url: `${API.GetDetail}/${id}` }, ); +} + +export function exportDisAssemble(params: QueryDisAssembleReq) { + return defHttp.get>( + { + url: `${API.Export}`, + params, + responseType: "blob" + } + ); } \ No newline at end of file diff --git a/web/src/views/warehouse/disassemble/index.vue b/web/src/views/warehouse/disassemble/index.vue index 924243ee..551b36d1 100644 --- a/web/src/views/warehouse/disassemble/index.vue +++ b/web/src/views/warehouse/disassemble/index.vue @@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue"; import {BasicTable, TableAction, useTable} from "@/components/Table"; import {useMessage} from "@/hooks/web/useMessage"; import {columns, searchFormSchema} from "@/views//warehouse/disassemble/disassemble.data"; -import {exportXlsx} from "@/api/basic/common"; import {useI18n} from "vue-i18n"; -import {getDisAssemblePageList, deleteBatchDisAssemble, updateDisAssembleStatus} from "@/api/warehouse/disassemble"; +import {getDisAssemblePageList, deleteBatchDisAssemble, updateDisAssembleStatus, exportDisAssemble} from "@/api/warehouse/disassemble"; import AddEditDisassembleModal from "@/views/warehouse/disassemble/components/AddEditDisassembleModal.vue" import ViewDisassembleModal from "@/views/warehouse/disassemble/components/ViewDisassembleModal.vue"; import {Tag} from "ant-design-vue"; @@ -67,7 +66,7 @@ export default defineComponent({ const { createMessage } = useMessage(); const addEditModalRef = ref(null); const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal(); - const [registerTable, { reload, getSelectRows }] = useTable({ + const [registerTable, { reload, getSelectRows, getForm }] = useTable({ title: '拆卸单列表', rowKey: 'id', api: getDisAssemblePageList, @@ -170,14 +169,17 @@ export default defineComponent({ } async function handleExport() { - const file = await exportXlsx("拆卸单列表") - const blob = new Blob([file]); - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - const timestamp = getTimestamp(new Date()); - link.download = "拆卸单数据" + timestamp + ".xlsx"; - link.target = "_blank"; - link.click(); + const data = getForm().getFieldsValue(); + const file: any = await exportDisAssemble(data) + if (file.size > 0) { + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "拆卸单数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } } From be4add2fa6320ed07bc55f64400e465c4392f07e Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 2 Dec 2023 15:28:17 +0800 Subject: [PATCH 4/5] fetch: add assemble receipt export api #245 --- .../api/warehouse/AssembleController.java | 15 +++--- .../vo/warehouse/AssembleReceiptVO.java | 12 ++++- .../warehouse/AssembleReceiptService.java | 3 ++ .../impl/AssembleReceiptServiceImpl.java | 52 ++++++++++++++++++- web/src/api/warehouse/assemble.ts | 11 ++++ web/src/views/warehouse/assemble/index.vue | 24 +++++---- 6 files changed, 95 insertions(+), 22 deletions(-) diff --git a/core/api/src/main/java/com/wansenai/api/warehouse/AssembleController.java b/core/api/src/main/java/com/wansenai/api/warehouse/AssembleController.java index 895906ab..3f40cc47 100644 --- a/core/api/src/main/java/com/wansenai/api/warehouse/AssembleController.java +++ b/core/api/src/main/java/com/wansenai/api/warehouse/AssembleController.java @@ -19,14 +19,8 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AssembleReceiptDetailVO; import com.wansenai.vo.warehouse.AssembleReceiptVO; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.PostMapping; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -64,4 +58,9 @@ public Response deleteAssembleReceiptByIds(@RequestParam("ids") List updateAssembleReceiptStatusByIds(@RequestParam("ids") List ids, @RequestParam("status") Integer status) { return assembleService.updateAssembleReceiptStatus(ids, status); } + + @GetMapping("export") + public void exportAssembleReceipt(@ModelAttribute QueryAssembleReceiptDTO queryAssembleReceiptDTO, HttpServletResponse response) throws Exception { + assembleService.exportAssembleReceipt(queryAssembleReceiptDTO, response); + } } diff --git a/core/domain/src/main/java/com/wansenai/vo/warehouse/AssembleReceiptVO.java b/core/domain/src/main/java/com/wansenai/vo/warehouse/AssembleReceiptVO.java index 5d6c9470..768e07b5 100644 --- a/core/domain/src/main/java/com/wansenai/vo/warehouse/AssembleReceiptVO.java +++ b/core/domain/src/main/java/com/wansenai/vo/warehouse/AssembleReceiptVO.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.wansenai.bo.BigDecimalSerializerBO; +import com.wansenai.utils.excel.ExcelExport; import lombok.Builder; import lombok.Data; @@ -28,19 +29,26 @@ public class AssembleReceiptVO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Long id; + @ExcelExport(value = "单据编号") private String receiptNumber; + @ExcelExport(value = "商品信息") private String productInfo; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelExport(value = "单据日期") private LocalDateTime receiptDate; - private String operator; - + @ExcelExport(value = "商品数量") private Integer productNumber; @JsonSerialize(using = BigDecimalSerializerBO.class) + @ExcelExport(value = "金额合计") private BigDecimal totalAmount; + @ExcelExport(value = "操作员") + private String operator; + + @ExcelExport(value = "状态", kv = "0-未审核;1-已审核") private Integer status; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/AssembleReceiptService.java b/core/service/src/main/java/com/wansenai/service/warehouse/AssembleReceiptService.java index 8d7dae0e..eb016304 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/AssembleReceiptService.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/AssembleReceiptService.java @@ -20,6 +20,7 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AssembleReceiptDetailVO; import com.wansenai.vo.warehouse.AssembleReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -34,4 +35,6 @@ public interface AssembleReceiptService extends IService { Response deleteBatchAssembleReceipt(List ids); Response updateAssembleReceiptStatus(List ids, Integer status); + + void exportAssembleReceipt(QueryAssembleReceiptDTO queryAssembleReceiptDTO, HttpServletResponse response) throws Exception; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/impl/AssembleReceiptServiceImpl.java b/core/service/src/main/java/com/wansenai/service/warehouse/impl/AssembleReceiptServiceImpl.java index f6117bde..3e8b2a0b 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/impl/AssembleReceiptServiceImpl.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/impl/AssembleReceiptServiceImpl.java @@ -37,9 +37,11 @@ import com.wansenai.utils.constants.CommonConstants; import com.wansenai.utils.enums.AssembleReceiptCodeEnum; import com.wansenai.utils.enums.BaseCodeEnum; +import com.wansenai.utils.excel.ExcelUtils; import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AssembleReceiptDetailVO; import com.wansenai.vo.warehouse.AssembleReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -178,7 +180,46 @@ public Response> getAssembleReceiptPageList(QueryAssembl return Response.responseData(result); } - @Override + private List getAssembleReceiptList(QueryAssembleReceiptDTO queryAssembleReceiptDTO) { + var wrapperMainMapper = lambdaQuery() + .eq(queryAssembleReceiptDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryAssembleReceiptDTO.getOperatorId()) + .eq(queryAssembleReceiptDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryAssembleReceiptDTO.getStatus()) + .eq(StringUtils.hasLength(queryAssembleReceiptDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryAssembleReceiptDTO.getReceiptNumber()) + .like(StringUtils.hasLength(queryAssembleReceiptDTO.getRemark()), WarehouseReceiptMain::getRemark, queryAssembleReceiptDTO.getRemark()) + .ge(StringUtils.hasLength(queryAssembleReceiptDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryAssembleReceiptDTO.getStartDate()) + .le(StringUtils.hasLength(queryAssembleReceiptDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryAssembleReceiptDTO.getEndDate()) + .eq(WarehouseReceiptMain::getType, "组装单") + .eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED) + .list(); + + var assembleReceiptVOList = new ArrayList(wrapperMainMapper.size() + 1); + wrapperMainMapper.forEach(item -> { + + var product = productService.getById(item.getProductId()); + var productInfo = ""; + if(product != null) { + productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit(); + } + + var operator = userService.getById(item.getCreateBy()); + var assembleReceiptVO = AssembleReceiptVO.builder() + .id(item.getId()) + .receiptNumber(item.getReceiptNumber()) + .productInfo(productInfo) + .receiptDate(item.getReceiptDate()) + .operator(Optional.ofNullable(operator).map(SysUser::getName).orElse("")) + .productNumber(item.getTotalProductNumber()) + .totalAmount(item.getTotalAmount()) + .status(item.getStatus()) + .build(); + + assembleReceiptVOList.add(assembleReceiptVO); + }); + return assembleReceiptVOList; + } + + + @Override public Response getAssembleReceiptDetail(Long id) { if (id == null) { return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL); @@ -428,4 +469,13 @@ public Response updateAssembleReceiptStatus(List ids, Integer stat } return Response.responseMsg(AssembleReceiptCodeEnum.UPDATE_ASSEMBLE_RECEIPT_SUCCESS); } + + @Override + public void exportAssembleReceipt(QueryAssembleReceiptDTO queryAssembleReceiptDTO, HttpServletResponse response) throws Exception { + var data = getAssembleReceiptList(queryAssembleReceiptDTO); + if (!data.isEmpty()) { + var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "组装单", data); + ExcelUtils.downloadExcel(file, "组装单", response); + } + } } diff --git a/web/src/api/warehouse/assemble.ts b/web/src/api/warehouse/assemble.ts index 62420a58..3796c3a8 100644 --- a/web/src/api/warehouse/assemble.ts +++ b/web/src/api/warehouse/assemble.ts @@ -14,6 +14,7 @@ enum API { DeleteBatch = '/warehouse/assemble/deleteByIds', UpdateStatus = '/warehouse/assemble/updateStatusByIds', GetDetail = '/warehouse/assemble/getDetailById', + Export = '/warehouse/assemble/export', } export function getAssemblePageList(params: QueryAssembleReq) { @@ -65,4 +66,14 @@ export function getAssembleDetailById(id: number) { url: `${API.GetDetail}/${id}` }, ); +} + +export function exportAssemble(params: QueryAssembleReq) { + return defHttp.get>( + { + url: `${API.Export}`, + params, + responseType: "blob" + } + ); } \ No newline at end of file diff --git a/web/src/views/warehouse/assemble/index.vue b/web/src/views/warehouse/assemble/index.vue index c6720c6c..e5c2645f 100644 --- a/web/src/views/warehouse/assemble/index.vue +++ b/web/src/views/warehouse/assemble/index.vue @@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue"; import {BasicTable, TableAction, useTable} from "@/components/Table"; import {useMessage} from "@/hooks/web/useMessage"; import {columns, searchFormSchema} from "@/views//warehouse/assemble/assemble.data"; -import {exportXlsx} from "@/api/basic/common"; import {useI18n} from "vue-i18n"; -import {getAssemblePageList, deleteBatchAssemble, updateAssembleStatus} from "@/api/warehouse/assemble"; +import {getAssemblePageList, deleteBatchAssemble, updateAssembleStatus, exportAssemble} from "@/api/warehouse/assemble"; import AddEditAssembleModal from "@/views/warehouse/assemble/components/AddEditAssembleModal.vue" import ViewAssembleModal from "@/views/warehouse/assemble/components/ViewAssembleModal.vue"; import {Tag} from "ant-design-vue"; @@ -67,7 +66,7 @@ export default defineComponent({ const { createMessage } = useMessage(); const addEditModalRef = ref(null); const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal(); - const [registerTable, { reload, getSelectRows }] = useTable({ + const [registerTable, { reload, getSelectRows, getForm }] = useTable({ title: '组装单列表', rowKey: 'id', api: getAssemblePageList, @@ -170,14 +169,17 @@ export default defineComponent({ } async function handleExport() { - const file = await exportXlsx("组装单列表") - const blob = new Blob([file]); - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - const timestamp = getTimestamp(new Date()); - link.download = "组装单数据" + timestamp + ".xlsx"; - link.target = "_blank"; - link.click(); + const data = getForm().getFieldsValue(); + const file: any = await exportAssemble(data) + if (file.size > 0) { + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "组装单数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } } From d2f9da33285c67cd8ffc09489e974a8896708e21 Mon Sep 17 00:00:00 2001 From: jameszow Date: Sat, 2 Dec 2023 15:28:30 +0800 Subject: [PATCH 5/5] fetch: add allot receipt export api #245 --- .../warehouse/AllotShipmentsController.java | 16 +++--- .../wansenai/vo/warehouse/AllotReceiptVO.java | 12 ++++- .../warehouse/AllotShipmentsService.java | 3 ++ .../impl/AllotShipmentsServiceImpl.java | 49 +++++++++++++++++++ web/src/api/warehouse/allotShipments.ts | 11 +++++ web/src/views/warehouse/allot/index.vue | 24 ++++----- 6 files changed, 94 insertions(+), 21 deletions(-) diff --git a/core/api/src/main/java/com/wansenai/api/warehouse/AllotShipmentsController.java b/core/api/src/main/java/com/wansenai/api/warehouse/AllotShipmentsController.java index 6ebaa06e..febb2e14 100644 --- a/core/api/src/main/java/com/wansenai/api/warehouse/AllotShipmentsController.java +++ b/core/api/src/main/java/com/wansenai/api/warehouse/AllotShipmentsController.java @@ -19,14 +19,8 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AllotReceiptDetailVO; import com.wansenai.vo.warehouse.AllotReceiptVO; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.PostMapping; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -64,4 +58,10 @@ public Response deleteAllotShipmentsByIds(@RequestParam("ids") List updateAllotShipmentsStatusByIds(@RequestParam("ids") List ids, @RequestParam("status") Integer status) { return allotShipmentsService.updateAllotReceiptStatus(ids, status); } + + @GetMapping("export") + public void exportAllotShipments(@ModelAttribute QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception { + allotShipmentsService.exportAllotReceipt(queryAllotReceiptDTO, response); + } + } diff --git a/core/domain/src/main/java/com/wansenai/vo/warehouse/AllotReceiptVO.java b/core/domain/src/main/java/com/wansenai/vo/warehouse/AllotReceiptVO.java index 9d619605..bbdc49d5 100644 --- a/core/domain/src/main/java/com/wansenai/vo/warehouse/AllotReceiptVO.java +++ b/core/domain/src/main/java/com/wansenai/vo/warehouse/AllotReceiptVO.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.wansenai.bo.BigDecimalSerializerBO; +import com.wansenai.utils.excel.ExcelExport; import lombok.Builder; import lombok.Data; @@ -28,19 +29,26 @@ public class AllotReceiptVO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Long id; + @ExcelExport(value = "单据编号") private String receiptNumber; + @ExcelExport(value = "商品信息") private String productInfo; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ExcelExport(value = "单据日期") private LocalDateTime receiptDate; - private String operator; - + @ExcelExport(value = "商品数量") private Integer productNumber; @JsonSerialize(using = BigDecimalSerializerBO.class) + @ExcelExport(value = "金额合计") private BigDecimal totalAmount; + @ExcelExport(value = "操作员") + private String operator; + + @ExcelExport(value = "状态", kv = "0-未审核;1-已审核") private Integer status; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/AllotShipmentsService.java b/core/service/src/main/java/com/wansenai/service/warehouse/AllotShipmentsService.java index 732b9291..f5e9d89c 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/AllotShipmentsService.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/AllotShipmentsService.java @@ -20,6 +20,7 @@ import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AllotReceiptDetailVO; import com.wansenai.vo.warehouse.AllotReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import java.util.List; @@ -34,4 +35,6 @@ public interface AllotShipmentsService extends IService { Response deleteBatchAllotReceipt(List ids); Response updateAllotReceiptStatus(List ids, Integer status); + + void exportAllotReceipt(QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception; } diff --git a/core/service/src/main/java/com/wansenai/service/warehouse/impl/AllotShipmentsServiceImpl.java b/core/service/src/main/java/com/wansenai/service/warehouse/impl/AllotShipmentsServiceImpl.java index 14615099..9437679b 100644 --- a/core/service/src/main/java/com/wansenai/service/warehouse/impl/AllotShipmentsServiceImpl.java +++ b/core/service/src/main/java/com/wansenai/service/warehouse/impl/AllotShipmentsServiceImpl.java @@ -39,9 +39,11 @@ import com.wansenai.utils.enums.AllotShipmentCodeEnum; import com.wansenai.utils.enums.BaseCodeEnum; import com.wansenai.utils.enums.OtherShipmentCodeEnum; +import com.wansenai.utils.excel.ExcelUtils; import com.wansenai.utils.response.Response; import com.wansenai.vo.warehouse.AllotReceiptDetailVO; import com.wansenai.vo.warehouse.AllotReceiptVO; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -180,6 +182,44 @@ public Response> getAllotReceiptPageList(QueryAllotReceiptD return Response.responseData(result); } + private List getAllotReceiptList(QueryAllotReceiptDTO queryAllotReceiptDTO) { + var wrapperMainMapper = lambdaQuery() + .eq(queryAllotReceiptDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryAllotReceiptDTO.getOperatorId()) + .eq(queryAllotReceiptDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryAllotReceiptDTO.getStatus()) + .eq(StringUtils.hasLength(queryAllotReceiptDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryAllotReceiptDTO.getReceiptNumber()) + .like(StringUtils.hasLength(queryAllotReceiptDTO.getRemark()), WarehouseReceiptMain::getRemark, queryAllotReceiptDTO.getRemark()) + .ge(StringUtils.hasLength(queryAllotReceiptDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryAllotReceiptDTO.getStartDate()) + .le(StringUtils.hasLength(queryAllotReceiptDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryAllotReceiptDTO.getEndDate()) + .eq(WarehouseReceiptMain::getType, "调拨出库") + .eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED) + .list(); + + var allotReceiptVOList = new ArrayList(wrapperMainMapper.size() + 1); + wrapperMainMapper.forEach(item -> { + + var product = productService.getById(item.getProductId()); + var productInfo = ""; + if(product != null) { + productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit(); + } + + var operator = userService.getById(item.getCreateBy()); + var allotReceiptVO = AllotReceiptVO.builder() + .id(item.getId()) + .receiptNumber(item.getReceiptNumber()) + .productInfo(productInfo) + .receiptDate(item.getReceiptDate()) + .operator(Optional.ofNullable(operator).map(SysUser::getName).orElse("")) + .productNumber(item.getTotalProductNumber()) + .totalAmount(item.getTotalAmount()) + .status(item.getStatus()) + .build(); + + allotReceiptVOList.add(allotReceiptVO); + }); + return allotReceiptVOList; + } + @Override public Response getAllotReceiptDetail(Long id) { if (id == null) { @@ -433,4 +473,13 @@ public Response updateAllotReceiptStatus(List ids, Integer status) } return Response.responseMsg(AllotShipmentCodeEnum.UPDATE_ALLOT_SHIPMENT_STOCK_RECEIPT_SUCCESS); } + + @Override + public void exportAllotReceipt(QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception { + var data = getAllotReceiptList(queryAllotReceiptDTO); + if (!data.isEmpty()) { + var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "调拨出库", data); + ExcelUtils.downloadExcel(file, "调拨出库", response); + } + } } diff --git a/web/src/api/warehouse/allotShipments.ts b/web/src/api/warehouse/allotShipments.ts index 9812a3d7..7652c898 100644 --- a/web/src/api/warehouse/allotShipments.ts +++ b/web/src/api/warehouse/allotShipments.ts @@ -14,6 +14,7 @@ enum API { DeleteBatch = '/warehouse/allotShipments/deleteByIds', UpdateStatus = '/warehouse/allotShipments/updateStatusByIds', GetDetail = '/warehouse/allotShipments/getDetailById', + Export = '/warehouse/allotShipments/export', } export function getAllotShipmentsPageList(params: QueryAllotShipmentsReq) { @@ -65,4 +66,14 @@ export function getAllotShipmentsDetailById(id: number) { url: `${API.GetDetail}/${id}` }, ); +} + +export function exportAllotShipments(params: QueryAllotShipmentsReq) { + return defHttp.get>( + { + url: `${API.Export}`, + params, + responseType: "blob" + } + ); } \ No newline at end of file diff --git a/web/src/views/warehouse/allot/index.vue b/web/src/views/warehouse/allot/index.vue index d3f8f7e1..a667c5d1 100644 --- a/web/src/views/warehouse/allot/index.vue +++ b/web/src/views/warehouse/allot/index.vue @@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue"; import {BasicTable, TableAction, useTable} from "@/components/Table"; import {useMessage} from "@/hooks/web/useMessage"; import {columns, searchFormSchema} from "@/views//warehouse/allot/allotShipments.data"; -import {exportXlsx} from "@/api/basic/common"; import {useI18n} from "vue-i18n"; -import {getAllotShipmentsPageList, deleteBatchAllotShipments, updateAllotShipmentsStatus} from "@/api/warehouse/allotShipments"; +import {getAllotShipmentsPageList, deleteBatchAllotShipments, updateAllotShipmentsStatus, exportAllotShipments} from "@/api/warehouse/allotShipments"; import AddEditAllotShipmentsModal from "@/views/warehouse/allot/components/AddEditAllotShipmentsModal.vue" import ViewAllotShipmentsModal from "@/views/warehouse/allot/components/ViewAllotShipmentsModal.vue"; import {Tag} from "ant-design-vue"; @@ -67,7 +66,7 @@ export default defineComponent({ const { createMessage } = useMessage(); const addEditModalRef = ref(null); const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal(); - const [registerTable, { reload, getSelectRows }] = useTable({ + const [registerTable, { reload, getSelectRows, getForm }] = useTable({ title: '调拨出库列表', rowKey: 'id', api: getAllotShipmentsPageList, @@ -170,14 +169,17 @@ export default defineComponent({ } async function handleExport() { - const file = await exportXlsx("调拨出库列表") - const blob = new Blob([file]); - const link = document.createElement("a"); - link.href = URL.createObjectURL(blob); - const timestamp = getTimestamp(new Date()); - link.download = "调拨出库数据" + timestamp + ".xlsx"; - link.target = "_blank"; - link.click(); + const data = getForm().getFieldsValue(); + const file: any = await exportAllotShipments(data) + if (file.size > 0) { + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "调拨出库数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } }