Skip to content

Commit 6ebf8fb

Browse files
committed
fetch: add other shipments export api eairps#245
1 parent 5388ea5 commit 6ebf8fb

File tree

6 files changed

+97
-21
lines changed

6 files changed

+97
-21
lines changed

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

+7-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.OtherShipmentDetailVO;
2121
import com.wansenai.vo.warehouse.OtherShipmentVO;
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,9 @@ public Response<String> deleteOtherShipmentsByIds(@RequestParam("ids") List<Long
6458
public Response<String> updateOtherShipmentsStatusByIds(@RequestParam("ids") List<Long> ids, @RequestParam("status") Integer status) {
6559
return otherShipmentsService.updateOtherShipmentsStatus(ids, status);
6660
}
61+
62+
@GetMapping("export")
63+
public void exportOtherShipments(@ModelAttribute QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception {
64+
otherShipmentsService.exportOtherShipments(queryOtherShipmentDTO, response);
65+
}
6766
}

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

+11-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,21 +29,29 @@ public class OtherShipmentVO {
2829
@JsonFormat(shape = JsonFormat.Shape.STRING)
2930
private Long id;
3031

32+
@ExcelExport(value = "客户")
3133
private String customerName;
3234

35+
@ExcelExport(value = "单据编号")
3336
private String receiptNumber;
3437

38+
@ExcelExport(value = "商品信息")
3539
private String productInfo;
3640

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

40-
private String operator;
41-
45+
@ExcelExport(value = "商品数量")
4246
private Integer productNumber;
4347

4448
@JsonSerialize(using = BigDecimalSerializerBO.class)
49+
@ExcelExport(value = "金额合计")
4550
private BigDecimal totalAmount;
4651

52+
@ExcelExport(value = "操作员")
53+
private String operator;
54+
55+
@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
4756
private Integer status;
4857
}

core/service/src/main/java/com/wansenai/service/warehouse/OtherShipmentsService.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.OtherShipmentDetailVO;
2222
import com.wansenai.vo.warehouse.OtherShipmentVO;
23+
import jakarta.servlet.http.HttpServletResponse;
2324

2425
import java.util.List;
2526

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

3637
Response<String> updateOtherShipmentsStatus(List<Long> ids, Integer status);
38+
39+
void exportOtherShipments(QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception;
3740
}

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

+52
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
import com.wansenai.utils.constants.CommonConstants;
3838
import com.wansenai.utils.enums.BaseCodeEnum;
3939
import com.wansenai.utils.enums.OtherShipmentCodeEnum;
40+
import com.wansenai.utils.excel.ExcelUtils;
4041
import com.wansenai.utils.response.Response;
4142
import com.wansenai.vo.warehouse.OtherShipmentDetailVO;
4243
import com.wansenai.vo.warehouse.OtherShipmentVO;
44+
import jakarta.servlet.http.HttpServletResponse;
4345
import org.springframework.stereotype.Service;
4446
import org.springframework.util.StringUtils;
4547

@@ -179,6 +181,47 @@ public Response<Page<OtherShipmentVO>> getOtherShipmentsPageList(QueryOtherShipm
179181
return Response.responseData(result);
180182
}
181183

184+
private List<OtherShipmentVO> getOtherShipmentsList(QueryOtherShipmentDTO queryOtherShipmentDTO) {
185+
var wrapperMainMapper = lambdaQuery()
186+
.eq(queryOtherShipmentDTO.getCustomerId() != null, WarehouseReceiptMain::getRelatedPersonId, queryOtherShipmentDTO.getCustomerId())
187+
.eq(queryOtherShipmentDTO.getOperatorId() != null, WarehouseReceiptMain::getCreateBy, queryOtherShipmentDTO.getOperatorId())
188+
.eq(queryOtherShipmentDTO.getStatus() != null, WarehouseReceiptMain::getStatus, queryOtherShipmentDTO.getStatus())
189+
.eq(StringUtils.hasLength(queryOtherShipmentDTO.getReceiptNumber()), WarehouseReceiptMain::getReceiptNumber, queryOtherShipmentDTO.getReceiptNumber())
190+
.eq(StringUtils.hasLength(queryOtherShipmentDTO.getOtherReceipt()), WarehouseReceiptMain::getReceiptNumber, queryOtherShipmentDTO.getOtherReceipt())
191+
.like(StringUtils.hasLength(queryOtherShipmentDTO.getRemark()), WarehouseReceiptMain::getRemark, queryOtherShipmentDTO.getRemark())
192+
.ge(StringUtils.hasLength(queryOtherShipmentDTO.getStartDate()), WarehouseReceiptMain::getCreateTime, queryOtherShipmentDTO.getStartDate())
193+
.le(StringUtils.hasLength(queryOtherShipmentDTO.getEndDate()), WarehouseReceiptMain::getCreateTime, queryOtherShipmentDTO.getEndDate())
194+
.eq(WarehouseReceiptMain::getType, "其他出库")
195+
.eq(WarehouseReceiptMain::getDeleteFlag, CommonConstants.NOT_DELETED)
196+
.list();
197+
198+
var otherShipmentVOList = new ArrayList<OtherShipmentVO>(wrapperMainMapper.size() + 1);
199+
wrapperMainMapper.forEach(item -> {
200+
201+
var product = productService.getById(item.getProductId());
202+
var productInfo = "";
203+
if(product != null) {
204+
productInfo = product.getProductName() + "|" + product.getProductStandard() + "|" + product.getProductModel() + "|" + product.getProductUnit();
205+
}
206+
207+
var operator = userService.getById(item.getCreateBy());
208+
var otherShipmentVO = OtherShipmentVO.builder()
209+
.id(item.getId())
210+
.receiptNumber(item.getReceiptNumber())
211+
.productInfo(productInfo)
212+
.customerName(commonService.getCustomerName(item.getRelatedPersonId()))
213+
.receiptDate(item.getReceiptDate())
214+
.operator(Optional.ofNullable(operator).map(SysUser::getName).orElse(""))
215+
.productNumber(item.getTotalProductNumber())
216+
.totalAmount(item.getTotalAmount())
217+
.status(item.getStatus())
218+
.build();
219+
220+
otherShipmentVOList.add(otherShipmentVO);
221+
});
222+
return otherShipmentVOList;
223+
}
224+
182225
@Override
183226
public Response<OtherShipmentDetailVO> getOtherShipmentsDetail(Long id) {
184227
if (id == null) {
@@ -383,4 +426,13 @@ public Response<String> updateOtherShipmentsStatus(List<Long> ids, Integer statu
383426
}
384427
return Response.responseMsg(OtherShipmentCodeEnum.UPDATE_OTHER_SHIPMENT_STOCK_SUCCESS);
385428
}
429+
430+
@Override
431+
public void exportOtherShipments(QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception {
432+
var data = getOtherShipmentsList(queryOtherShipmentDTO);
433+
if (!data.isEmpty()) {
434+
var file = ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "其他出库", data);
435+
ExcelUtils.downloadExcel(file, "其他出库", response);
436+
}
437+
}
386438
}

web/src/api/warehouse/shipments.ts

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

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

web/src/views/warehouse/shipments/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/shipments/otherShipments.data";
55-
import {exportXlsx} from "@/api/basic/common";
5655
import {useI18n} from "vue-i18n";
57-
import {getOtherShipmentsPageList, deleteBatchOtherShipments, updateOtherShipmentsStatus} from "@/api/warehouse/shipments";
56+
import {getOtherShipmentsPageList, deleteBatchOtherShipments, updateOtherShipmentsStatus, exportOtherShipments} from "@/api/warehouse/shipments";
5857
import AddEditOtherShipmentsModal from "@/views/warehouse/shipments/components/AddEditOtherShipmentsModal.vue"
5958
import ViewOtherShipmentsModal from "@/views/warehouse/shipments/components/ViewOtherShipmentsModal.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: getOtherShipmentsPageList,
@@ -169,14 +168,17 @@ export default defineComponent({
169168
}
170169
171170
async function handleExport() {
172-
const file = await exportXlsx("其他出库列表")
173-
const blob = new Blob([file]);
174-
const link = document.createElement("a");
175-
link.href = URL.createObjectURL(blob);
176-
const timestamp = getTimestamp(new Date());
177-
link.download = "其他出库数据" + timestamp + ".xlsx";
178-
link.target = "_blank";
179-
link.click();
171+
const data = getForm().getFieldsValue();
172+
const file: any = await exportOtherShipments(data)
173+
if (file.size > 0) {
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();
181+
}
180182
}
181183
182184

0 commit comments

Comments
 (0)