Skip to content

Commit

Permalink
fetch: add other shipments export api wansenai#245
Browse files Browse the repository at this point in the history
  • Loading branch information
Jzow committed Dec 2, 2023
1 parent 5388ea5 commit 6ebf8fb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -64,4 +58,9 @@ public Response<String> deleteOtherShipmentsByIds(@RequestParam("ids") List<Long
public Response<String> updateOtherShipmentsStatusByIds(@RequestParam("ids") List<Long> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Response<String> updateOtherShipmentsStatus(List<Long> ids, Integer status);

void exportOtherShipments(QueryOtherShipmentDTO queryOtherShipmentDTO, HttpServletResponse response) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

private List<OtherShipmentVO> 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<OtherShipmentVO>(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<OtherShipmentDetailVO> getOtherShipmentsDetail(Long id) {
if (id == null) {
Expand Down Expand Up @@ -383,4 +426,13 @@ public Response<String> updateOtherShipmentsStatus(List<Long> 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);
}
}
}
11 changes: 11 additions & 0 deletions web/src/api/warehouse/shipments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -65,4 +66,14 @@ export function getOtherShipmentsDetailById(id: number) {
url: `${API.GetDetail}/${id}`
},
);
}

export function exportOtherShipments(params: QueryOtherShipmentsReq) {
return defHttp.get<BaseDataResp<Blob>>(
{
url: `${API.Export}`,
params,
responseType: "blob"
}
);
}
24 changes: 13 additions & 11 deletions web/src/views/warehouse/shipments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 6ebf8fb

Please sign in to comment.