liding
9 天以前 f171534eb89eca16ef1834ef1daa73d95b1bf7cf
src/main/java/com/ruoyi/sales/controller/SalesLedgerProductController.java
@@ -1,48 +1,91 @@
package com.ruoyi.sales.controller;
import javax.servlet.http.HttpServletResponse;
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.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.service.ProcurementRecordService;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.dto.SalesLedgerProductDto;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
/**
 * 产品信息Controller
 *
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/sales/product")
public class SalesLedgerProductController extends BaseController
{
public class SalesLedgerProductController extends BaseController {
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    @Autowired
    private ProcurementRecordService procurementRecordService;
    @Autowired
    private StockUtils stockUtils;
    /**
     * 回款登记分页查询
     */
    @GetMapping("/listPageSalesLedger")
    public AjaxResult listPage(Page page, SalesLedgerProductDto salesLedgerProduct) {
        IPage<SalesLedgerProductDto> list = salesLedgerProductService.listPage(page, salesLedgerProduct);
        return AjaxResult.success(list);
    }
    /**
     * 付款登记分页查询
     */
    @GetMapping("/listPagePurchaseLedger")
    public AjaxResult listPagePurchaseLedger(Page page, SalesLedgerProductDto salesLedgerProduct) {
        IPage<SalesLedgerProductDto> list = salesLedgerProductService.listPagePurchaseLedger(page, salesLedgerProduct);
        return AjaxResult.success(list);
    }
    /**
     * 查询产品信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SalesLedgerProduct salesLedgerProduct)
    {
        startPage();
    public AjaxResult list(SalesLedgerProduct salesLedgerProduct) {
        List<SalesLedgerProduct> list = salesLedgerProductService.selectSalesLedgerProductList(salesLedgerProduct);
        return getDataTable(list);
        list.forEach(item -> {
            if (item.getFutureTickets().compareTo(BigDecimal.ZERO) == 0) {
                item.setFutureTickets(BigDecimal.ZERO);
            }
            if (item.getFutureTicketsAmount().compareTo(BigDecimal.ZERO) == 0) {
                item.setFutureTicketsAmount(BigDecimal.ZERO);
            }
//            ProcurementPageDto procurementDto = new ProcurementPageDto();
//            procurementDto.setSalesLedgerProductId(item.getId());
//            procurementDto.setProductCategory(item.getProductCategory());
//            IPage<ProcurementPageDtoCopy> result = procurementRecordService.listPageCopyByProduction(new Page<>(1,-1), procurementDto);
//            BigDecimal stockQuantity = stockUtils.getStockQuantity(item.getProductModelId()).get("stockQuantity");
//                ProcurementPageDtoCopy procurementDtoCopy = result.getRecords().get(0);
            if (item.getApproveStatus() != 2) {
                if (item.getHasSufficientStock() == 0) {
                    item.setApproveStatus(0);
                } else {
                    item.setApproveStatus(1);
                }
            }
        });
        return AjaxResult.success(list);
    }
    /**
@@ -50,8 +93,7 @@
     */
    @Log(title = "产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalesLedgerProduct salesLedgerProduct)
    {
    public void export(HttpServletResponse response, SalesLedgerProduct salesLedgerProduct) {
        List<SalesLedgerProduct> list = salesLedgerProductService.selectSalesLedgerProductList(salesLedgerProduct);
        ExcelUtil<SalesLedgerProduct> util = new ExcelUtil<SalesLedgerProduct>(SalesLedgerProduct.class);
        util.exportExcel(response, list, "产品信息数据");
@@ -61,8 +103,7 @@
     * 获取产品信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(salesLedgerProductService.selectSalesLedgerProductById(id));
    }
@@ -70,9 +111,8 @@
     * 新增修改产品信息
     */
    @Log(title = "产品信息", businessType = BusinessType.INSERT)
    @PostMapping  ("/addOrUpdateSalesLedgerProduct")
    public AjaxResult add(@RequestBody SalesLedgerProduct salesLedgerProduct)
    {
    @PostMapping("/addOrUpdateSalesLedgerProduct")
    public AjaxResult add(@RequestBody SalesLedgerProduct salesLedgerProduct) {
        return toAjax(salesLedgerProductService.addOrUpdateSalesLedgerProduct(salesLedgerProduct));
    }
@@ -80,12 +120,22 @@
     * 删除产品信息
     */
    @Log(title = "产品信息", businessType = BusinessType.DELETE)
   @DeleteMapping("/delProduct")
    public AjaxResult remove(@RequestBody Long[] ids)
    {
    @DeleteMapping("/delProduct")
    public AjaxResult remove(@RequestBody Long[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入要删除的ID");
        }
        return toAjax(salesLedgerProductService.deleteSalesLedgerProductByIds(ids));
    }
    //根据产品id获取bom判断库存是否充足
    @GetMapping("/judgmentInventory")
    public R judgmentInventory(SalesLedgerProduct salesLedgerProduct) {
        return salesLedgerProductService.judgmentInventory(salesLedgerProduct);
    }
    @GetMapping("/getById")
    public R getById(SalesLedgerProduct salesLedgerProduct) {
        return R.ok(salesLedgerProductService.getById(salesLedgerProduct));
    }
}