package com.ruoyi.stock.controller; 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; import com.ruoyi.framework.web.domain.R; import com.ruoyi.stock.dto.StockCheckStartDto; import com.ruoyi.stock.pojo.StockCheckDetail; import com.ruoyi.stock.pojo.StockCheckMain; import com.ruoyi.stock.service.StockCheckService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/stockCheck") @RequiredArgsConstructor @Tag(name = "库存盘点") public class StockCheckController { private final StockCheckService stockCheckService; @PostMapping("/start") @Log(title = "Start stock check", businessType = BusinessType.INSERT) @Operation(summary = "发起盘点(生成账面快照明细)") public R start(@RequestBody StockCheckStartDto dto) { return stockCheckService.start(dto, dto.getProductModelIds()); } @GetMapping("/listPage") @Operation(summary = "盘点单分页") public R> listPage(Page page, StockCheckMain query) { return R.ok(stockCheckService.listPage(page, query)); } @GetMapping("/{id}") @Operation(summary = "盘点单详情(主表)") public R getInfo(@PathVariable Long id) { return R.ok(stockCheckService.getMain(id)); } @GetMapping("/detailPage") @Operation(summary = "盘点明细分页(onlyDiff=true只看已录入且有差异)") public R> detailPage(Page page, @RequestParam Long mainId, @RequestParam(required = false) Boolean onlyDiff) { return R.ok(stockCheckService.detailPage(page, mainId, onlyDiff)); } @PutMapping("/entry") @Log(title = "Stock check entry", businessType = BusinessType.UPDATE) @Operation(summary = "录入实盘数量 [{id,actualQty,remark}...]") public R entry(@RequestBody List details) { return stockCheckService.entry(details); } @PostMapping("/finish") @Log(title = "Finish stock check", businessType = BusinessType.UPDATE) @Operation(summary = "完成盘点(差异生成待审核调账单据)") public R finish(@RequestBody StockCheckMain main) { return stockCheckService.finish(main.getId()); } @PostMapping("/cancel") @Log(title = "Cancel stock check", businessType = BusinessType.UPDATE) @Operation(summary = "取消盘点(仅盘点中)") public R cancel(@RequestBody StockCheckMain main) { return stockCheckService.cancel(main.getId()); } @DeleteMapping("/delete") @Log(title = "Delete stock check", businessType = BusinessType.DELETE) @Operation(summary = "删除盘点单(连带删除明细)") public R delete(@RequestBody List ids) { return stockCheckService.delete(ids); } @GetMapping("/diffList") @Operation(summary = "差异分析列表") public R> diffList(@RequestParam Long mainId) { return R.ok(stockCheckService.diffList(mainId)); } @GetMapping("/diffList/export") @Log(title = "Export stock check diff", businessType = BusinessType.EXPORT) @Operation(summary = "差异分析导出") public void diffExport(HttpServletResponse response, @RequestParam Long mainId) { List list = stockCheckService.diffList(mainId); ExcelUtil util = new ExcelUtil<>(StockCheckDetail.class); util.exportExcel(response, list, "盘点差异分析"); } @GetMapping("/export") @Log(title = "Export stock check", businessType = BusinessType.EXPORT) @Operation(summary = "盘点单导出") public void export(HttpServletResponse response, StockCheckMain query) { List list = stockCheckService.listForExport(query); ExcelUtil util = new ExcelUtil<>(StockCheckMain.class); util.exportExcel(response, list, "库存盘点单"); } @GetMapping("/detailExport") @Log(title = "Export stock check detail", businessType = BusinessType.EXPORT) @Operation(summary = "盘点明细导出") public void detailExport(HttpServletResponse response, @RequestParam Long mainId) { List list = stockCheckService.detailPage(new Page<>(1, -1), mainId, null).getRecords(); ExcelUtil util = new ExcelUtil<>(StockCheckDetail.class); util.exportExcel(response, list, "盘点明细"); } }