| src/main/java/com/ruoyi/stock/controller/StockInventoryController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/dto/StockInRecordDto.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/dto/StockInventoryDto.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/execl/StockInventoryExportData.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/service/StockInventoryService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/resources/mapper/sales/SalesLedgerProductMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/resources/mapper/stock/StockInventoryMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/ruoyi/stock/controller/StockInventoryController.java
@@ -62,9 +62,9 @@ } @GetMapping("importStockInventory") @PostMapping("importStockInventory") @ApiOperation("导入库存") public R importStockInventory(MultipartFile file) { public R importStockInventory(MultipartFile file) { return stockInventoryService.importStockInventory(file); } @@ -78,7 +78,19 @@ @PostMapping("/exportStockInventory") @ApiOperation("导出库存") public void exportStockInventory(HttpServletResponse response,StockInventoryDto stockInventoryDto) { stockInventoryService.exportStockInventory(response,stockInventoryDto); public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) { stockInventoryService.exportStockInventory(response, stockInventoryDto); } @GetMapping("stockInventoryPage") @ApiOperation("库存报表查询") public R stockInventoryPage(Page page, StockInventoryDto stockInventoryDto) { return R.ok(stockInventoryService.stockInventoryPage(stockInventoryDto,page)); } @GetMapping("stockInAndOutRecord") @ApiOperation("统计各个产品的入库和出库记录") public R stockInAndOutRecord(StockInventoryDto stockInventoryDto,Page page) { return R.ok(stockInventoryService.stockInAndOutRecord(stockInventoryDto,page)); } } src/main/java/com/ruoyi/stock/dto/StockInRecordDto.java
@@ -23,4 +23,7 @@ private String timeStr; private String createBy; //现存量 private String currentStock; } src/main/java/com/ruoyi/stock/dto/StockInventoryDto.java
@@ -1,7 +1,12 @@ package com.ruoyi.stock.dto; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.stock.pojo.StockInventory; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; import java.time.LocalDate; @Data public class StockInventoryDto extends StockInventory { @@ -16,4 +21,20 @@ //入库类型对应的id private Long recordId; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd") private LocalDate reportDate; //库存月报查询字段 @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd") private LocalDate startMonth; @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd") private LocalDate endMonth; private BigDecimal totalStockIn; private BigDecimal totalStockOut; private BigDecimal currentStock; } src/main/java/com/ruoyi/stock/execl/StockInventoryExportData.java
@@ -29,10 +29,10 @@ @Excel(name = "备注") private String remark; @Excel(name = "最新更新时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime updateTime; // // @Excel(name = "最新更新时间") // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") // private LocalDateTime updateTime; } src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.stock.dto.StockInRecordDto; import com.ruoyi.stock.dto.StockInventoryDto; import com.ruoyi.stock.execl.StockInventoryExportData; import com.ruoyi.stock.pojo.StockInventory; @@ -31,4 +32,7 @@ List<StockInventoryExportData> listStockInventoryExportData(@Param("ew") StockInventoryDto stockInventoryDto); IPage<StockInRecordDto> stockInventoryPage(@Param("ew") StockInventoryDto stockInventoryDto, Page page); IPage<StockInventoryDto> stockInAndOutRecord(@Param("ew") StockInventoryDto stockInventoryDto, Page page); } src/main/java/com/ruoyi/stock/service/StockInventoryService.java
@@ -3,12 +3,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.framework.web.domain.R; import com.ruoyi.stock.dto.StockInRecordDto; import com.ruoyi.stock.dto.StockInventoryDto; import com.ruoyi.stock.pojo.StockInventory; import com.baomidou.mybatisplus.extension.service.IService; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.List; /** * <p> @@ -29,4 +31,9 @@ R importStockInventory(MultipartFile file); void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto); IPage<StockInRecordDto> stockInventoryPage(StockInventoryDto stockInventoryDto,Page page); IPage<StockInventoryDto> stockInAndOutRecord(StockInventoryDto stockInventoryDto,Page page); } src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.account.pojo.BorrowInfo; import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.domain.R; @@ -26,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** @@ -101,32 +101,54 @@ @Override public R importStockInventory(MultipartFile file) { try { final StringBuffer[] errorMsg = {new StringBuffer()}; //查询所有的产品 List<SalesLedgerProduct> salesLedgerProducts =salesLedgerProductMapper.selectProduct(); // 查询所有的产品 List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct(); ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class); List<StockInventoryExportData> list = util.importExcel(file.getInputStream()); list.stream().forEach(dto -> { salesLedgerProducts.stream().forEach(item->{ if (item.getProductCategory().equals(dto.getProductName())&&item.getSpecificationModel().equals(dto.getModel())) { //更新库存 // 记录未找到匹配项的数据 List<String> unmatchedRecords = new ArrayList<>(); list.forEach(dto -> { boolean matched = false; for (SalesLedgerProduct item : salesLedgerProducts) { if (item.getProductCategory().equals(dto.getProductName()) && item.getSpecificationModel().equals(dto.getModel())) { StockInventoryDto stockInventoryDto = new StockInventoryDto(); stockInventoryDto.setRecordId(0L); stockInventoryDto.setRecordType(StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode()); stockInventoryDto.setQualitity(dto.getQualitity()); stockInventoryDto.setRemark(dto.getRemark()); stockInventoryDto.setProductModelId(item.getProductModelId()); this.addstockInventory(stockInventoryDto); }else { errorMsg[0] = errorMsg[0].append("产品名称:"+dto.getProductName()+"规格:"+dto.getModel()+"不存在").append("\n"); this.addstockInventory(stockInventoryDto); matched = true; break; // 找到匹配项后跳出循环 } }); } if (!matched) { // 记录未匹配的数据 String unmatchedInfo = String.format("产品名称:%s,规格型号:%s", dto.getProductName(), dto.getModel()); unmatchedRecords.add(unmatchedInfo); } }); return R.ok(errorMsg[0]); }catch (Exception e){ // 构建返回信息 StringBuilder message = new StringBuilder(); if (!unmatchedRecords.isEmpty()) { message.append("以下产品未找到匹配项:\n"); for (String record : unmatchedRecords) { message.append(record).append("\n"); } throw new RuntimeException(message.toString()); } } catch (Exception e) { e.printStackTrace(); return R.fail("导入失败:" + e.getMessage()); } return R.fail(); return R.ok("导入成功"); } @Override public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) { @@ -135,4 +157,14 @@ ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class); util.exportExcel(response,list, "库存信息"); } @Override public IPage<StockInRecordDto> stockInventoryPage(StockInventoryDto stockInventoryDto, Page page) { return stockInventoryMapper.stockInventoryPage(stockInventoryDto,page); } @Override public IPage<StockInventoryDto> stockInAndOutRecord(StockInventoryDto stockInventoryDto, Page page) { return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto,page); } } src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -154,7 +154,7 @@ select p.product_name as product_category, pm.model as specification_model, pm.id pm.id as product_model_id from product_model pm left join product p on pm.product_id = p.id </select> src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -73,5 +73,99 @@ and p.product_name like concat('%',#{ew.productName},'%') </if> </select> <select id="stockInventoryPage" resultType="com.ruoyi.stock.dto.StockInRecordDto"> select sir.*,si.qualitity, pm.model, pm.unit, p.product_name from stock_in_record sir left join stock_inventory si on sir.product_model_id = si.product_model_id left join product_model pm on sir.product_model_id = pm.id left join product p on pm.product_id = p.id <where> <if test="ew.reportDate != null"> and sir.create_time >= #{ew.reportDate} and sir.create_time < DATE_ADD(#{ew.reportDate}, INTERVAL 1 DAY) </if> <if test="ew.startMonth != null"> and sir.create_time >= #{ew.startMonth} </if> <if test="ew.endMonth != null"> and sir.create_time <= #{ew.endMonth} </if> </where> </select> <select id="stockInAndOutRecord" resultType="com.ruoyi.stock.dto.StockInventoryDto"> SELECT pm.model, pm.unit, p.product_name, MAX(current_inventory) as current_stock, SUM(CASE WHEN record_type = 'in' THEN amount ELSE 0 END) as total_stock_in, SUM(CASE WHEN record_type = 'out' THEN amount ELSE 0 END) as total_stock_out FROM ( SELECT product_model_id, SUM(qualitity) as current_inventory, 0 as amount, '' as record_type FROM stock_inventory GROUP BY product_model_id UNION ALL SELECT product_model_id, 0 as current_inventory, SUM(stock_in_num) as amount, 'in' as record_type FROM stock_in_record <where> type = 0 <if test="ew.startMonth != null"> and stock_in_record.create_time >= #{ew.startMonth} </if> <if test="ew.endMonth != null"> and stock_in_record.create_time <= #{ew.endMonth} </if> </where> GROUP BY product_model_id UNION ALL SELECT product_model_id, 0 as current_inventory, SUM(stock_out_num) as amount, 'out' as record_type FROM stock_out_record <where> type = 0 <if test="ew.startMonth != null"> and stock_out_record.create_time >= #{ew.startMonth} </if> <if test="ew.endMonth != null"> and stock_out_record.create_time <= #{ew.endMonth} </if> </where> GROUP BY product_model_id ) combined_data LEFT JOIN product_model pm ON pm.id = combined_data.product_model_id LEFT JOIN product p ON p.id = pm.product_id <where> <if test="ew.productName != null and ew.productName !=''"> and p.product_name like concat('%',#{ew.productName},'%') </if> <if test="ew.model != null and ew.model !=''"> and pm.model like concat('%',#{ew.model},'%') </if> </where> GROUP BY pm.model, pm.unit, p.product_name </select> </mapper>