liding
3 天以前 e1609fe42f1582453879d6b4bf316f4217834d6b
src/main/java/com/ruoyi/purchase/controller/PurchaseLedgerController.java
@@ -1,5 +1,8 @@
package com.ruoyi.purchase.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -9,13 +12,18 @@
import com.ruoyi.purchase.dto.PurchaseLedgerDto;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.purchase.service.IPurchaseLedgerService;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 采购台账Controller
@@ -26,10 +34,12 @@
@RestController
@RequestMapping("/purchase/ledger")
@AllArgsConstructor
@Api(tags = "111")
public class PurchaseLedgerController extends BaseController {
    private IPurchaseLedgerService purchaseLedgerService;
    private ISalesLedgerService salesLedgerService;
    private ISalesLedgerProductService salesLedgerProductService;
    /**
     * 查询采购台账列表
@@ -53,6 +63,20 @@
    }
    /**
     * 导出来票登记列表
     */
    @Log(title = "导出来票登记列表", businessType = BusinessType.EXPORT)
    @PostMapping("/exportOne")
    public void exportOne(HttpServletResponse response, PurchaseLedger purchaseLedger) {
        Page page = new Page();
        page.setCurrent(-1);
        page.setSize(-1);
        IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerService.selectPurchaseLedgerListPage(page, new PurchaseLedgerDto());
        ExcelUtil<PurchaseLedgerDto> util = new ExcelUtil<PurchaseLedgerDto>(PurchaseLedgerDto.class);
        util.exportExcel(response, purchaseLedgerDtoIPage.getRecords(), "导出来票登记列表");
    }
    /**
     * 新增修改采购台账
     */
    @Log(title = "采购台账", businessType = BusinessType.INSERT)
@@ -60,7 +84,42 @@
    public AjaxResult addOrEditPurchase(@RequestBody PurchaseLedgerDto purchaseLedgerDto) throws IOException {
        return toAjax(purchaseLedgerService.addOrEditPurchase(purchaseLedgerDto));
    }
    /**
     * 新增采购模板
     */
    @PostMapping("/addPurchaseTemplate")
    public AjaxResult addPurchaseTemplate(@RequestBody PurchaseLedgerDto purchaseLedgerDto) throws IOException {
        return toAjax(purchaseLedgerService.addPurchaseTemplate(purchaseLedgerDto));
    }
    /**
     * 查询采购模板
     */
    @ApiOperation("/2222")
    @GetMapping("/getPurchaseTemplateList")
    public AjaxResult getPurchaseTemplateList() {
        PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto();
        purchaseLedgerDto.setApprovalStatus(3);
        IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerService.selectPurchaseLedgerListPage(new Page(1, -1), purchaseLedgerDto);
        List<PurchaseLedgerDto> purchaseLedgers = purchaseLedgerDtoIPage.getRecords();
        purchaseLedgers.forEach(purchaseLedgerDto1 -> {
            LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerDto1.getId())
                    .eq(SalesLedgerProduct::getType, 2);
            List<SalesLedgerProduct> list = salesLedgerProductService.list(queryWrapper);
            if (!list.isEmpty()) {
                purchaseLedgerDto1.setProductData(list);
            }
        });
        return AjaxResult.success(purchaseLedgers);
    }
    /**
     * 修改采购台账审批状态
     */
    @PostMapping("/updateApprovalStatus")
    public AjaxResult addOrEditPurchase(@RequestBody PurchaseLedger purchaseLedger){
        return toAjax(purchaseLedgerService.updateById(purchaseLedger));
    }
    /**
     * 查询采购台账和产品父子列表
     */
@@ -86,6 +145,15 @@
        return salesLedgerService.getSalesNo();
    }
    /**
     * 根据销售合同查询产品信息
     */
    @GetMapping("/getProductBySalesNo")
    public AjaxResult getProductBySalesNo(Long id) {
        return AjaxResult.success(purchaseLedgerService.getProductBySalesNo(id));
    }
    /**
     * 查询采购合同号
     */
@@ -98,8 +166,8 @@
     * 根据id查询采购合同号
     */
    @GetMapping("/getPurchaseNoById")
    public PurchaseLedgerDto getPurchaseNoById(Long id) {
        return purchaseLedgerService.getPurchaseNoById(id);
    public AjaxResult getPurchaseNoById(Long id) {
        return AjaxResult.success(purchaseLedgerService.getPurchaseNoById(id));
    }
    /**
@@ -114,7 +182,25 @@
     * 根据采购合同号查询产品
     */
    @GetMapping("/getInfo")
    public PurchaseLedgerDto getInfo(PurchaseLedgerDto purchaseLedgerDto) {
        return purchaseLedgerService.getInfo(purchaseLedgerDto);
    public AjaxResult getInfo(PurchaseLedgerDto purchaseLedgerDto) {
        return AjaxResult.success(purchaseLedgerService.getInfo(purchaseLedgerDto));
    }
    /**
     * 查询采购台账列表
     */
    @GetMapping("/listPage")
    public AjaxResult listPage(Page page, PurchaseLedgerDto purchaseLedger) {
        IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerService.selectPurchaseLedgerListPage(page ,purchaseLedger);
        //过滤掉approvalStatus=3的记录
        purchaseLedgerDtoIPage.getRecords().removeIf(purchaseLedgerDto -> purchaseLedgerDto.getApprovalStatus() == 3);
         return AjaxResult.success(purchaseLedgerDtoIPage);
    }
    @ApiOperation("生成采购序列号")
    @GetMapping("/createPurchaseNo")
    @Log(title = "生成采购序列号", businessType = BusinessType.OTHER)
    public AjaxResult createPurchaseNo() {
        return AjaxResult.success("生成成功",purchaseLedgerService.getPurchaseNo());
    }
}