Skip to content

Commit d2f9da3

Browse files
committed
fetch: add allot receipt export api eairps#245
1 parent be4add2 commit d2f9da3

File tree

6 files changed

+94
-21
lines changed

6 files changed

+94
-21
lines changed

core/api/src/main/java/com/wansenai/api/warehouse/AllotShipmentsController.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
import com.wansenai.utils.response.Response;
2020
import com.wansenai.vo.warehouse.AllotReceiptDetailVO;
2121
import com.wansenai.vo.warehouse.AllotReceiptVO;
22-
import org.springframework.web.bind.annotation.RestController;
23-
import org.springframework.web.bind.annotation.RequestMapping;
24-
import org.springframework.web.bind.annotation.RequestBody;
25-
import org.springframework.web.bind.annotation.GetMapping;
26-
import org.springframework.web.bind.annotation.PathVariable;
27-
import org.springframework.web.bind.annotation.PutMapping;
28-
import org.springframework.web.bind.annotation.RequestParam;
29-
import org.springframework.web.bind.annotation.PostMapping;
22+
import jakarta.servlet.http.HttpServletResponse;
23+
import org.springframework.web.bind.annotation.*;
3024

3125
import java.util.List;
3226

@@ -64,4 +58,10 @@ public Response<String> deleteAllotShipmentsByIds(@RequestParam("ids") List<Long
6458
public Response<String> updateAllotShipmentsStatusByIds(@RequestParam("ids") List<Long> ids, @RequestParam("status") Integer status) {
6559
return allotShipmentsService.updateAllotReceiptStatus(ids, status);
6660
}
61+
62+
@GetMapping("export")
63+
public void exportAllotShipments(@ModelAttribute QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception {
64+
allotShipmentsService.exportAllotReceipt(queryAllotReceiptDTO, response);
65+
}
66+
6767
}

core/domain/src/main/java/com/wansenai/vo/warehouse/AllotReceiptVO.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fasterxml.jackson.annotation.JsonFormat;
1616
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1717
import com.wansenai.bo.BigDecimalSerializerBO;
18+
import com.wansenai.utils.excel.ExcelExport;
1819
import lombok.Builder;
1920
import lombok.Data;
2021

@@ -28,19 +29,26 @@ public class AllotReceiptVO {
2829
@JsonFormat(shape = JsonFormat.Shape.STRING)
2930
private Long id;
3031

32+
@ExcelExport(value = "单据编号")
3133
private String receiptNumber;
3234

35+
@ExcelExport(value = "商品信息")
3336
private String productInfo;
3437

3538
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
39+
@ExcelExport(value = "单据日期")
3640
private LocalDateTime receiptDate;
3741

38-
private String operator;
39-
42+
@ExcelExport(value = "商品数量")
4043
private Integer productNumber;
4144

4245
@JsonSerialize(using = BigDecimalSerializerBO.class)
46+
@ExcelExport(value = "金额合计")
4347
private BigDecimal totalAmount;
4448

49+
@ExcelExport(value = "操作员")
50+
private String operator;
51+
52+
@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
4553
private Integer status;
4654
}

core/service/src/main/java/com/wansenai/service/warehouse/AllotShipmentsService.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.wansenai.utils.response.Response;
2121
import com.wansenai.vo.warehouse.AllotReceiptDetailVO;
2222
import com.wansenai.vo.warehouse.AllotReceiptVO;
23+
import jakarta.servlet.http.HttpServletResponse;
2324

2425
import java.util.List;
2526

@@ -34,4 +35,6 @@ public interface AllotShipmentsService extends IService<WarehouseReceiptMain> {
3435
Response<String> deleteBatchAllotReceipt(List<Long> ids);
3536

3637
Response<String> updateAllotReceiptStatus(List<Long> ids, Integer status);
38+
39+
void exportAllotReceipt(QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception;
3740
}

core/service/src/main/java/com/wansenai/service/warehouse/impl/AllotShipmentsServiceImpl.java

+49
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
import com.wansenai.utils.enums.AllotShipmentCodeEnum;
4040
import com.wansenai.utils.enums.BaseCodeEnum;
4141
import com.wansenai.utils.enums.OtherShipmentCodeEnum;
42+
import com.wansenai.utils.excel.ExcelUtils;
4243
import com.wansenai.utils.response.Response;
4344
import com.wansenai.vo.warehouse.AllotReceiptDetailVO;
4445
import com.wansenai.vo.warehouse.AllotReceiptVO;
46+
import jakarta.servlet.http.HttpServletResponse;
4547
import org.springframework.stereotype.Service;
4648
import org.springframework.transaction.annotation.Transactional;
4749
import org.springframework.util.StringUtils;
@@ -180,6 +182,44 @@ public Response<Page<AllotReceiptVO>> getAllotReceiptPageList(QueryAllotReceiptD
180182
return Response.responseData(result);
181183
}
182184

185+
private List<AllotReceiptVO> getAllotReceiptList(QueryAllotReceiptDTO queryAllotReceiptDTO) {
186+
var wrapperMainMapper = lambdaQuery()
187+
.eq(queryAllotReceiptDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryAllotReceiptDTO.getOperatorId())
188+
.eq(queryAllotReceiptDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryAllotReceiptDTO.getStatus())
189+
.eq(StringUtils.hasLength(queryAllotReceiptDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryAllotReceiptDTO.getReceiptNumber())
190+
.like(StringUtils.hasLength(queryAllotReceiptDTO.getRemark()), WarehouseReceiptMain::getRemark, queryAllotReceiptDTO.getRemark())
191+
.ge(StringUtils.hasLength(queryAllotReceiptDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryAllotReceiptDTO.getStartDate())
192+
.le(StringUtils.hasLength(queryAllotReceiptDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryAllotReceiptDTO.getEndDate())
193+
.eq(WarehouseReceiptMain::getType, "调拨出库")
194+
.eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED)
195+
.list();
196+
197+
var allotReceiptVOList = new ArrayList<AllotReceiptVO>(wrapperMainMapper.size() + 1);
198+
wrapperMainMapper.forEach(item -> {
199+
200+
var product = productService.getById(item.getProductId());
201+
var productInfo = "";
202+
if(product != null) {
203+
productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit();
204+
}
205+
206+
var operator = userService.getById(item.getCreateBy());
207+
var allotReceiptVO = AllotReceiptVO.builder()
208+
.id(item.getId())
209+
.receiptNumber(item.getReceiptNumber())
210+
.productInfo(productInfo)
211+
.receiptDate(item.getReceiptDate())
212+
.operator(Optional.ofNullable(operator).map(SysUser::getName).orElse(""))
213+
.productNumber(item.getTotalProductNumber())
214+
.totalAmount(item.getTotalAmount())
215+
.status(item.getStatus())
216+
.build();
217+
218+
allotReceiptVOList.add(allotReceiptVO);
219+
});
220+
return allotReceiptVOList;
221+
}
222+
183223
@Override
184224
public Response<AllotReceiptDetailVO> getAllotReceiptDetail(Long id) {
185225
if (id == null) {
@@ -433,4 +473,13 @@ public Response<String> updateAllotReceiptStatus(List<Long> ids, Integer status)
433473
}
434474
return Response.responseMsg(AllotShipmentCodeEnum.UPDATE_ALLOT_SHIPMENT_STOCK_RECEIPT_SUCCESS);
435475
}
476+
477+
@Override
478+
public void exportAllotReceipt(QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception {
479+
var data = getAllotReceiptList(queryAllotReceiptDTO);
480+
if (!data.isEmpty()) {
481+
var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "调拨出库", data);
482+
ExcelUtils.downloadExcel(file, "调拨出库", response);
483+
}
484+
}
436485
}

web/src/api/warehouse/allotShipments.ts

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum API {
1414
DeleteBatch = '/warehouse/allotShipments/deleteByIds',
1515
UpdateStatus = '/warehouse/allotShipments/updateStatusByIds',
1616
GetDetail = '/warehouse/allotShipments/getDetailById',
17+
Export = '/warehouse/allotShipments/export',
1718
}
1819

1920
export function getAllotShipmentsPageList(params: QueryAllotShipmentsReq) {
@@ -65,4 +66,14 @@ export function getAllotShipmentsDetailById(id: number) {
6566
url: `${API.GetDetail}/${id}`
6667
},
6768
);
69+
}
70+
71+
export function exportAllotShipments(params: QueryAllotShipmentsReq) {
72+
return defHttp.get<BaseDataResp<Blob>>(
73+
{
74+
url: `${API.Export}`,
75+
params,
76+
responseType: "blob"
77+
}
78+
);
6879
}

web/src/views/warehouse/allot/index.vue

+13-11
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ import {defineComponent, ref} from "vue";
5252
import {BasicTable, TableAction, useTable} from "@/components/Table";
5353
import {useMessage} from "@/hooks/web/useMessage";
5454
import {columns, searchFormSchema} from "@/views//warehouse/allot/allotShipments.data";
55-
import {exportXlsx} from "@/api/basic/common";
5655
import {useI18n} from "vue-i18n";
57-
import {getAllotShipmentsPageList, deleteBatchAllotShipments, updateAllotShipmentsStatus} from "@/api/warehouse/allotShipments";
56+
import {getAllotShipmentsPageList, deleteBatchAllotShipments, updateAllotShipmentsStatus, exportAllotShipments} from "@/api/warehouse/allotShipments";
5857
import AddEditAllotShipmentsModal from "@/views/warehouse/allot/components/AddEditAllotShipmentsModal.vue"
5958
import ViewAllotShipmentsModal from "@/views/warehouse/allot/components/ViewAllotShipmentsModal.vue";
6059
import {Tag} from "ant-design-vue";
@@ -67,7 +66,7 @@ export default defineComponent({
6766
const { createMessage } = useMessage();
6867
const addEditModalRef = ref(null);
6968
const [receiptViewModal, {openModal: openReceiptViewModal}] = useModal();
70-
const [registerTable, { reload, getSelectRows }] = useTable({
69+
const [registerTable, { reload, getSelectRows, getForm }] = useTable({
7170
title: '调拨出库列表',
7271
rowKey: 'id',
7372
api: getAllotShipmentsPageList,
@@ -170,14 +169,17 @@ export default defineComponent({
170169
}
171170
172171
async function handleExport() {
173-
const file = await exportXlsx("调拨出库列表")
174-
const blob = new Blob([file]);
175-
const link = document.createElement("a");
176-
link.href = URL.createObjectURL(blob);
177-
const timestamp = getTimestamp(new Date());
178-
link.download = "调拨出库数据" + timestamp + ".xlsx";
179-
link.target = "_blank";
180-
link.click();
172+
const data = getForm().getFieldsValue();
173+
const file: any = await exportAllotShipments(data)
174+
if (file.size > 0) {
175+
const blob = new Blob([file]);
176+
const link = document.createElement("a");
177+
link.href = URL.createObjectURL(blob);
178+
const timestamp = getTimestamp(new Date());
179+
link.download = "调拨出库数据" + timestamp + ".xlsx";
180+
link.target = "_blank";
181+
link.click();
182+
}
181183
}
182184
183185

0 commit comments

Comments
 (0)