Skip to content

Commit

Permalink
fetch: add allot receipt export api eairps#245
Browse files Browse the repository at this point in the history
  • Loading branch information
Jzow committed Dec 2, 2023
1 parent be4add2 commit d2f9da3
Show file tree
Hide file tree
Showing 6 changed files with 94 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.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;

Expand Down Expand Up @@ -64,4 +58,10 @@ public Response<String> deleteAllotShipmentsByIds(@RequestParam("ids") List<Long
public Response<String> updateAllotShipmentsStatusByIds(@RequestParam("ids") List<Long> 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);
}

}
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,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;
}
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.AllotReceiptDetailVO;
import com.wansenai.vo.warehouse.AllotReceiptVO;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

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

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

void exportAllotReceipt(QueryAllotReceiptDTO queryAllotReceiptDTO, HttpServletResponse response) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +182,44 @@ public Response<Page<AllotReceiptVO>> getAllotReceiptPageList(QueryAllotReceiptD
return Response.responseData(result);
}

private List<AllotReceiptVO> 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<AllotReceiptVO>(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<AllotReceiptDetailVO> getAllotReceiptDetail(Long id) {
if (id == null) {
Expand Down Expand Up @@ -433,4 +473,13 @@ public Response<String> updateAllotReceiptStatus(List<Long> 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);
}
}
}
11 changes: 11 additions & 0 deletions web/src/api/warehouse/allotShipments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -65,4 +66,14 @@ export function getAllotShipmentsDetailById(id: number) {
url: `${API.GetDetail}/${id}`
},
);
}

export function exportAllotShipments(params: QueryAllotShipmentsReq) {
return defHttp.get<BaseDataResp<Blob>>(
{
url: `${API.Export}`,
params,
responseType: "blob"
}
);
}
24 changes: 13 additions & 11 deletions web/src/views/warehouse/allot/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/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";
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: getAllotShipmentsPageList,
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit d2f9da3

Please sign in to comment.