Browse Source

Merge branch 'master' of http://47.100.3.209:3000/gdc/yiliangyiyun

ccj 2 years ago
parent
commit
cbbb8afeee

+ 17 - 3
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/controller/HistoricalInventoryInfoController.java

@@ -1,9 +1,12 @@
 package com.yh.saas.plugin.yiliangyiyun.controller;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo;
+import com.yh.saas.plugin.yiliangyiyun.service.IHistoricalInventoryInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
-import org.springframework.web.bind.annotation.RestController;
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * <p>
@@ -16,6 +19,17 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/historicalInventoryInfo")
 public class HistoricalInventoryInfoController {
-
+    @Autowired
+    private IHistoricalInventoryInfoService historicalInventoryInfoService;
+    /**
+     * 导出历史库存记录
+     *
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/exportHistoricalInventory")
+    public void exportHistoricalInventory(@RequestBody HistoricalInventoryInfo example, HttpServletResponse response) throws Exception {
+        historicalInventoryInfoService.exportHistoricalInventory(example,response);
+    }
 }
 

+ 22 - 5
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/entity/HistoricalInventoryInfo.java

@@ -1,15 +1,19 @@
 package com.yh.saas.plugin.yiliangyiyun.entity;
 
 import java.io.Serializable;
+import java.util.Date;
 
 
+import com.baomidou.mybatisplus.annotations.TableField;
 import com.baomidou.mybatisplus.annotations.TableId;
 import com.baomidou.mybatisplus.annotations.TableName;
 import com.baomidou.mybatisplus.enums.IdType;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.yh.saas.common.support.entity.BaseModel;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
 
 /**
  * <p>
@@ -32,6 +36,10 @@ public class HistoricalInventoryInfo extends BaseModel<HistoricalInventoryInfo>
      */
     @TableId(type = IdType.UUID)
     private String id;
+    /**
+     * 公司id
+     */
+    private String compId;
     /**
      * 仓库id
      */
@@ -40,15 +48,24 @@ public class HistoricalInventoryInfo extends BaseModel<HistoricalInventoryInfo>
      * 仓库名称
      */
     private String warehouseName;
-    /**
-     * 仓位编号id
-     */
-    private String positionId;
     /**
      * 累计储存量(吨)
      */
     private Double accumulatedStorage;
-
+    /**
+     * 开始时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @TableField(exist = false)
+    private Date startDate;
+    /**
+     * 结束时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @TableField(exist = false)
+    private Date endDate;
 
     @Override
     protected Serializable pkVal() {

+ 19 - 1
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/mapper/HistoricalInventoryInfoMapper.java

@@ -2,6 +2,11 @@ package com.yh.saas.plugin.yiliangyiyun.mapper;
 
 import com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo;
 import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo;
+import com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -12,5 +17,18 @@ import com.baomidou.mybatisplus.mapper.BaseMapper;
  * @since 2022-09-13
  */
 public interface HistoricalInventoryInfoMapper extends BaseMapper<HistoricalInventoryInfo> {
-
+    /**
+     * 历史库存
+     *
+     * @param pageView
+     * @return
+     */
+    List<HistoricalInventoryInfo> getHistoricalInventoryByCondition(Map<String, Object> pageView);
+    /**
+     * 根据条件查询历史库存记录
+     *
+     * @param pageView
+     * @return
+     */
+    List<HistoricalInventoryInfo> getHistoricalInventoryListByCondition(Map<String, Object> pageView);
 }

+ 10 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/IHistoricalInventoryInfoService.java

@@ -3,6 +3,8 @@ package com.yh.saas.plugin.yiliangyiyun.service;
 import com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo;
 import com.baomidou.mybatisplus.service.IService;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * <p>
  * 记录历史库存信息 服务类
@@ -12,5 +14,13 @@ import com.baomidou.mybatisplus.service.IService;
  * @since 2022-09-13
  */
 public interface IHistoricalInventoryInfoService extends IService<HistoricalInventoryInfo> {
+    /**
+     * 导出历史库存记录
+     * @param historicalInventoryInfo
+     * @param response
+     * @throws Exception
+     */
+    void exportHistoricalInventory(HistoricalInventoryInfo historicalInventoryInfo, HttpServletResponse response) throws Exception;
+
 
 }

+ 401 - 2
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/HistoricalInventoryInfoServiceImpl.java

@@ -1,10 +1,30 @@
 package com.yh.saas.plugin.yiliangyiyun.service.impl;
 
-import com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.winsea.svc.base.base.util.DateUtils;
+import com.winsea.svc.base.security.util.AuthSecurityUtils;
+import com.yh.saas.common.support.util.IdGenerator;
+import com.yh.saas.plugin.yiliangyiyun.entity.*;
 import com.yh.saas.plugin.yiliangyiyun.mapper.HistoricalInventoryInfoMapper;
-import com.yh.saas.plugin.yiliangyiyun.service.IHistoricalInventoryInfoService;
+import com.yh.saas.plugin.yiliangyiyun.service.*;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.httpclient.util.DateUtil;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLDecoder;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * <p>
@@ -15,6 +35,385 @@ import org.springframework.stereotype.Service;
  * @since 2022-09-13
  */
 @Service
+@Slf4j
 public class HistoricalInventoryInfoServiceImpl extends ServiceImpl<HistoricalInventoryInfoMapper, HistoricalInventoryInfo> implements IHistoricalInventoryInfoService {
+    @Autowired
+    private IWarehouseBaseInfoService warehouseBaseInfoService;
+    @Value("${file-root-path}")
+    private String localPath;
+
+    /**
+     * 生成历史库存记录,每天01:00点更新
+     *
+     * @return
+     */
+    @Transactional
+//    @Scheduled(cron = "0 0 01 * * ?")
+    public String makeHistoricalInventory() {
+        Map<String, Object> pageView = new HashMap<>();
+        String compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
+        pageView.put("compId", compId);
+        List<HistoricalInventoryInfo> dataList = baseMapper.getHistoricalInventoryByCondition(pageView);
+        if (!CollectionUtils.isEmpty(dataList)) {
+            for (HistoricalInventoryInfo historicalInventoryInfo1 : dataList) {
+                List<WarehouseBaseInfo> warehouseBaseInfoList = warehouseBaseInfoService.selectList(new EntityWrapper<WarehouseBaseInfo>()
+                        .eq("id", historicalInventoryInfo1.getBaseId())
+                        .eq("delete_flag", "0"));
+                HistoricalInventoryInfo historicalInventoryInfo = new HistoricalInventoryInfo();
+                historicalInventoryInfo.setId(IdGenerator.generateUUID());
+                historicalInventoryInfo.setCompId(warehouseBaseInfoList.get(0).getCompId());
+                historicalInventoryInfo.setBaseId(historicalInventoryInfo1.getBaseId());
+                historicalInventoryInfo.setWarehouseName(historicalInventoryInfo1.getWarehouseName());
+                historicalInventoryInfo.setAccumulatedStorage(historicalInventoryInfo1.getAccumulatedStorage());
+                this.insert(historicalInventoryInfo);
+            }
+        }
+        return "OK";
+    }
+
+    /**
+     * 判断浮点数
+     *
+     * @param example
+     * @return
+     */
+    private Double editDouble(Double example) {
+        Double exampleOne = example != null ? example : 0d;
+        return exampleOne;
+    }
+
+    /**
+     * 导出历史库存记录
+     *
+     * @param historicalInventoryInfo
+     * @param response
+     * @throws Exception
+     */
+    @Override
+    public void exportHistoricalInventory(HistoricalInventoryInfo historicalInventoryInfo, HttpServletResponse response) throws Exception {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        // 1.Excel的头部信息
+        String headerTitle = "";
+
+        // 2.创建一个webbook 对应一个Excel文件
+        HSSFWorkbook wb = new HSSFWorkbook();
+
+        // 3.在webbook中添加一个sheet,对应Excel文件中的sheet
+        HSSFSheet sheet;
+
+        sheet = wb.createSheet("历史库存记录信息");
+        headerTitle = "历史库存记录信息";
+
+        // 4.设置打印参数
+        sheet.setMargin(HSSFSheet.TopMargin, (short) 1);// 页边距(上)
+        sheet.setMargin(HSSFSheet.BottomMargin, (short) 1);// 页边距(下)
+        sheet.setMargin(HSSFSheet.LeftMargin, (short) 1);// 页边距(左)
+        sheet.setMargin(HSSFSheet.RightMargin, (short) 1);// 页边距(右)
+
+        // 不显示网格
+        sheet.setDisplayGridlines(false);
+        // 设置水平居中
+        sheet.setHorizontallyCenter(true);
+
+        /**************** 数据行样式 start ****************/
+        HSSFFont fontTitle = wb.createFont();
+        fontTitle.setFontName("宋体");
+        fontTitle.setFontHeightInPoints((short) 14);
+        // 设置字体加粗
+        fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+        HSSFFont fontComp = wb.createFont();
+        fontComp.setFontName("宋体");
+        fontComp.setFontHeightInPoints((short) 16);
+        // 设置字体加粗
+        fontComp.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+        HSSFFont fontDetail = wb.createFont();
+        fontDetail.setFontName("宋体");
+        fontDetail.setFontHeightInPoints((short) 12);
+
+        // title
+        HSSFCellStyle styleTitle = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 指定单元格垂直居中对齐
+        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleTitle.setWrapText(true);
+        // 设置单元格字体
+        styleTitle.setFont(fontTitle);
+        // 右边框
+        styleTitle.setBorderRight(HSSFCellStyle.BORDER_NONE);
+        // 左边框
+        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
+        // 上边框
+        styleTitle.setBorderTop(HSSFCellStyle.BORDER_NONE);
+        // 下边框
+        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
+
+        HSSFCellStyle contextstyle = wb.createCellStyle();
+        // 指定单元格居中对齐
+        contextstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 指定单元格垂直居中对齐
+        contextstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        contextstyle.setWrapText(true);
+        // 设置单元格字体
+        contextstyle.setFont(fontDetail);
+        // 右边框
+        contextstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        // 左边框
+        contextstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        // 上边框
+        contextstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        // 下styleDetailTitle
+        contextstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+
+        // title
+        HSSFCellStyle styleComp = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleComp.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 指定单元格垂直居中对齐
+        styleComp.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleComp.setWrapText(true);
+        // 设置单元格字体
+        styleComp.setFont(fontComp);
+        // 右边框
+        styleComp.setBorderRight(HSSFCellStyle.BORDER_NONE);
+        // 左边框
+        styleComp.setBorderLeft(HSSFCellStyle.BORDER_NONE);
+        // 上边框
+        styleComp.setBorderTop(HSSFCellStyle.BORDER_NONE);
+        // 下边框
+        styleComp.setBorderBottom(HSSFCellStyle.BORDER_NONE);
+
+        HSSFCellStyle styleInfo = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleInfo.setAlignment(HSSFCellStyle.ALIGN_LEFT);
+        // 指定单元格垂直居中对齐
+        styleInfo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleInfo.setWrapText(true);
+        // 设置单元格字体
+        styleInfo.setFont(fontDetail);
+        // 右边框
+        styleInfo.setBorderRight(HSSFCellStyle.BORDER_NONE);
+        // 左边框
+        styleInfo.setBorderLeft(HSSFCellStyle.BORDER_NONE);
+        // 上边框
+        styleInfo.setBorderTop(HSSFCellStyle.BORDER_NONE);
+        // 下边框
+        styleInfo.setBorderBottom(HSSFCellStyle.BORDER_NONE);
+
+        HSSFCellStyle styleDetail = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleDetail.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 指定单元格垂直居中对齐
+        styleDetail.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleDetail.setWrapText(true);
+        // 设置单元格字体
+        styleDetail.setFont(fontDetail);
+        // 右边框
+        styleDetail.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        // 左边框
+        styleDetail.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        // 上边框
+        styleDetail.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        // 下styleDetailTitle
+        styleDetail.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+
+        HSSFCellStyle styleDetailYellow = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleDetailYellow.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 指定单元格垂直居中对齐
+        styleDetailYellow.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleDetailYellow.setWrapText(true);
+        // 设置单元格字体
+        styleDetailYellow.setFont(fontDetail);
+        // 右边框
+        styleDetailYellow.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        // 左边框
+        styleDetailYellow.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        // 上边框
+        styleDetailYellow.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        // 下styleDetailTitle
+        styleDetailYellow.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        styleDetailYellow.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
+        styleDetailYellow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+
+
+        HSSFCellStyle styleDetailLeft = wb.createCellStyle();
+        // 指定单元格居中对齐
+        styleDetailLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
+        // 指定单元格垂直居中对齐
+        styleDetailLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 指定单元格自动换行
+        styleDetailLeft.setWrapText(true);
+        // 设置单元格字体
+        styleDetailLeft.setFont(fontDetail);
+        // 右边框
+        styleDetailLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        // 左边框
+        styleDetailLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        // 上边框
+        styleDetailLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        // 下styleDetailTitle
+        styleDetailLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        /**************** 数据行样式 end ****************/
+
+        // 设置列宽
+        sheet.setColumnWidth(0, 1 * 256 + 184);
+        sheet.setColumnWidth(1, 60 * 256 + 184);
+        sheet.setColumnWidth(2, 60 * 256 + 184);
+        sheet.setColumnWidth(3, 60 * 256 + 184);
+        sheet.setColumnWidth(4, 1 * 256 + 184);
+
+        // 创建单元格对象
+        HSSFCell cell = null;
+
+        // 创建打印设置对象
+        HSSFPrintSetup ps = sheet.getPrintSetup();
+        // 打印方向,true:横向,false:纵向(默认)
+        ps.setLandscape(false);
+        // // 打印质量
+        // ps.setVResolution((short) 700)
+        // 设置缩放比例
+        ps.setScale((short) 80);
+        // 纸张类型
+        ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
+
+
+        int rownum = 1;
+        HSSFRow row0 = sheet.createRow((int) rownum);
+        row0.setHeightInPoints(25);
+        cell = row0.createCell(1);
+        cell.setCellStyle(styleTitle);
+        cell.setCellValue("历史库存记录信息");
+        sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, (short) 1, (short) 3));
+        cell = row0.createCell(2);
+        cell.setCellStyle(styleTitle);
+        cell = row0.createCell(3);
+        cell.setCellStyle(styleTitle);
+        rownum++;
+
+        Map<String, Object> pageView = new HashMap<>();
+        //  公司ID
+        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
+        pageView.put("startDate", historicalInventoryInfo.getStartDate());
+        pageView.put("endDate", historicalInventoryInfo.getEndDate());
+        pageView.put("warehouseName", historicalInventoryInfo.getWarehouseName());
+        // 查询历史库存记录
+        List<HistoricalInventoryInfo> dataList = baseMapper.getHistoricalInventoryListByCondition(pageView);
+
+        HSSFRow row1 = sheet.createRow((int) rownum);
+        row1.setHeightInPoints(30);
+        cell = row1.createCell(1);
+        cell.setCellValue("仓库名称");
+        cell.setCellStyle(styleDetail);
+        cell = row1.createCell(2);
+        cell.setCellValue("当日库存量(吨)");
+        cell.setCellStyle(styleDetail);
+        cell = row1.createCell(3);
+        cell.setCellValue("日期");
+        cell.setCellStyle(styleDetail);
+        rownum++;
+
+        // 详情信息
+        if (!CollectionUtils.isEmpty(dataList)) {
+            for (int i = 0; i < dataList.size(); i++) {
+                HistoricalInventoryInfo historicalInventoryInfo1 = dataList.get(i);
+                HSSFRow rowx = sheet.createRow((int) rownum);
+                rowx.setHeightInPoints(20);
+                cell = rowx.createCell(1);
+                cell.setCellValue(historicalInventoryInfo1.getWarehouseName());
+                cell.setCellStyle(styleDetail);
+                cell = rowx.createCell(2);
+                cell.setCellValue(editDouble(historicalInventoryInfo1.getAccumulatedStorage()));
+                cell.setCellStyle(contextstyle);
+                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
+                contextstyle.setDataFormat(df.getBuiltinFormat("#,##0.00"));//保留两位小数点
+                cell = rowx.createCell(3);
+                String date = addDateOneDay(historicalInventoryInfo1.getCreateDate());
+                cell.setCellValue(date);
+                cell.setCellStyle(styleDetail);
+                rownum++;
+            }
+        }
+
+        String path = null;
+        String tempPath = null;
+        String excelPath = null;
+
+            try {
+                // 取得绝对路径
+                tempPath = URLDecoder.decode((localPath), "utf-8");
+
+                // EXCEL路径
+                excelPath = "/web/temp/pay/" + DateUtil.formatDate(new Date(), DateUtils.DATE_FMT_YYYYMMDD_NS) + '/'
+                        + UUID.randomUUID().toString().replaceAll("-", "");
+
+                path = tempPath + excelPath + '/' + "历史库存记录信息"
+                        + ".xlsx";
+
+            } catch (Exception e) {
+                log.debug(e.getMessage());
+            }
+        // 下载
+        download(path, response, wb);
+    }
+    private String addDateOneDay(Date date) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+        return sdf.format(date);
+    }
+    /**
+     * 下载
+     *
+     * @param path
+     * @param response
+     */
+    private void download(String path, HttpServletResponse response, Workbook wb) {
+
+        try {
+
+            // path是指欲下载的文件的路径。
+            File file = new File(path);
+            // 取得文件名。
+            String fileName = file.getName();
+            // 给文件名编码
+            fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");
+
+            response.setContentType("application/vnd.ms-excel");
+            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
+
+            // 定义byte输出流
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+            // 写导出文件
+            wb.write(out);
+
+            // 取得模板文件中的数据
+            byte[] result = out.toByteArray();
+
+            // 设置输出数据类型
+            response.setContentType("application/vnd.ms-excel");
+            // 设置输出数据长度
+            response.setContentLength(result.length);
+
+            // 设置文件名称
+            response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
+            // 将文件流输出到画面
+            response.getOutputStream().write(result);
+
+            out.flush();
+            out.close();
 
+        } catch (IOException ex) {
+            log.debug(ex.getMessage());
+        }
+    }
 }

+ 47 - 1
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/HistoricalInventoryInfoMapper.xml

@@ -1,5 +1,51 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.yh.saas.plugin.yiliangyiyun.mapper.HistoricalInventoryInfoMapper">
-
+    <!-- 历史库存记录查询 -->
+    <select id="getHistoricalInventoryByCondition" parameterType="Map"
+            resultType="com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo">
+        SELECT
+            wbi.warehouse_name as warehouseName,
+            wbi.id as baseId,
+            wbi.comp_id as compId,
+            sum( wpsi.storage ) as accumulatedStorage
+        FROM warehouse_base_info wbi
+        LEFT JOIN warehouse_position_info wpi on wbi.id = wpi.base_id
+        AND wpi.delete_flag = '0'
+        LEFT JOIN warehouse_position_storage_info wpsi on wpsi.position_id = wpi.id
+        AND wpsi.delete_flag = '0'
+        WHERE
+            wpsi.id IS NOT NULL
+            AND wbi.comp_id = #{compId}
+        GROUP BY wbi.id
+        ORDER BY wbi.warehouse_name
+    </select>
+    <!-- 历史库存记录查询 -->
+    <select id="getHistoricalInventoryListByCondition" parameterType="Map"
+            resultType="com.yh.saas.plugin.yiliangyiyun.entity.HistoricalInventoryInfo">
+        SELECT
+        id,
+        warehouse_name as warehouseName,
+        create_date as createDate,
+        base_id as baseId,
+        accumulated_storage as accumulatedStorage
+        FROM historical_inventory_info
+        WHERE
+        id IS NOT NULL
+        AND delete_flag = '0'
+        AND comp_id = #{compId}
+        <if test="warehouseName != null and warehouseName != ''">
+            AND warehouse_name = #{warehouseName}
+        </if>
+        <if test="startDate != null">
+            AND (DATE_FORMAT(create_date,"%Y%m%d") &gt;=
+            DATE_FORMAT(#{startDate},"%Y%m%d"))
+        </if>
+        <if test="endDate != null">
+            AND (DATE_FORMAT(create_date,"%Y%m%d") &lt;=
+            DATE_FORMAT(#{endDate},"%Y%m%d"))
+        </if>
+        GROUP BY id
+        ORDER BY warehouse_name
+    </select>
 </mapper>