Browse Source

请求头、库存入库数据添加并生成Excel,监管数据表、sql脚本

master
fkf 2 years ago
parent
commit
7445261883
  1. 81
      docs/databases/table_create_gf.sql
  2. 42
      yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/pushinventorydata/PushInventoryData.java
  3. 314
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/instock/InStockService.java
  4. 80
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/inventory/InventoryService.java
  5. 13
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataMapper.java
  6. 16
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataRest.java
  7. 17
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataService.java
  8. 3
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShHttp.java
  9. 7
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShRequester.java
  10. 15
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/timedtask/ShanHaiTimedTask.java
  11. 4
      yxt-supervise-gf-biz/src/test/java/demo/tool/SecurTest.java

81
docs/databases/table_create_gf.sql

@ -11,7 +11,7 @@
Target Server Version : 50741
File Encoding : 65001
Date: 13/07/2023 17:49:30
Date: 20/07/2023 17:33:16
*/
SET NAMES utf8mb4;
@ -43,8 +43,9 @@ CREATE TABLE `in_stock` (
`create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建时间',
`source_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源名称',
`source_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源类型',
`time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '查询数据时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物入库明细表' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物入库明细表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for inventory
@ -66,7 +67,7 @@ CREATE TABLE `inventory` (
`storehouse_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称',
`time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '库存记录表' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 164 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '库存记录表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for out_stock
@ -74,8 +75,80 @@ CREATE TABLE `inventory` (
DROP TABLE IF EXISTS `out_stock`;
CREATE TABLE `out_stock` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`materiel_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料名称',
`brand_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '品牌',
`materiel_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料编号',
`batch_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
`materiel_group_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料组',
`num` int(64) NULL DEFAULT NULL COMMENT '本次操作数量',
`price` double(10, 2) NULL DEFAULT NULL COMMENT '单价',
`actual_price` double(10, 2) NULL DEFAULT NULL COMMENT '批次总金额',
`unit` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料单位',
`admin_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '经办人',
`storehouse_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称',
`happen_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '申请时间',
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型',
`type_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型明文',
`status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '审核状态',
`orig_num` int(255) NULL DEFAULT NULL COMMENT '原数量',
`new_num` int(255) NULL DEFAULT NULL COMMENT '更新后的数量',
`create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建时间',
`source_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源名称',
`source_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源类型',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物出库明细表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for push_in_stock_data
-- ----------------------------
DROP TABLE IF EXISTS `push_in_stock_data`;
CREATE TABLE `push_in_stock_data` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`materiel_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料名称',
`brand_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '品牌',
`materiel_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料编号',
`batch_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
`materiel_group_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料组',
`num` int(64) NULL DEFAULT NULL COMMENT '本次操作数量',
`price` double(10, 2) NULL DEFAULT NULL COMMENT '单价',
`actual_price` double(10, 2) NULL DEFAULT NULL COMMENT '批次总金额',
`unit` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料单位',
`admin_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '经办人',
`storehouse_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称',
`happen_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '申请时间',
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型',
`type_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型明文',
`status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '审核状态',
`orig_num` int(255) NULL DEFAULT NULL COMMENT '原数量',
`new_num` int(255) NULL DEFAULT NULL COMMENT '更新后的数量',
`create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建时间',
`source_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源名称',
`source_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '来源类型',
`time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '查询数据时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管入库数据表(推送入库数据表)' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for push_inventory_data
-- ----------------------------
DROP TABLE IF EXISTS `push_inventory_data`;
CREATE TABLE `push_inventory_data` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`num` int(255) NULL DEFAULT NULL COMMENT '库存数量',
`storehouse_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库编码',
`materiel_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料id',
`materiel_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料编码',
`materiel_group` int(64) NULL DEFAULT NULL COMMENT '物料组id',
`brand_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料品牌',
`materiel_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料名称',
`price` double(255, 0) NULL DEFAULT NULL COMMENT '物料单价(成本价)',
`update_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '最后更新时间',
`materiel_group_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料组明文',
`update_time_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '最后更新时间明文',
`storehouse_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称',
`time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物出库明细表' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 53 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管库存数据表(推送库存)' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for warehouse information

42
yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/pushinventorydata/PushInventoryData.java

@ -0,0 +1,42 @@
package com.yxt.supervise.gf.api.pushinventorydata;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author feikefei
* @create 2023-07-20-9:23
*/
@Data
@ApiModel(value = "库存监管列表")
@TableName("push_inventory_data")
public class PushInventoryData {
private Integer id;
@ApiModelProperty("库存数量")
private Integer num;//268
@ApiModelProperty("仓库名称")
private String storehouse_name;//"藁城荣名库"
@ApiModelProperty("仓库编号")
private String storehouse_code;//"031102"
@ApiModelProperty("物料id")
private String materiel_id;//19428
@ApiModelProperty("物料编号")
private String materiel_no;//"9001000037"
@ApiModelProperty("物料组id")
private Integer materiel_group;//7
@ApiModelProperty("物料品牌")
private String brand_name;//"山海新能"
@ApiModelProperty("物料名称")
private String materiel_name;//"铝线3*95+1-50mm"
@ApiModelProperty("物料单价(成本价)")
private Double price;//"0.00"
@ApiModelProperty("最后更新时间")
private String update_time;//1684723525
@ApiModelProperty("物料组明文")
private String materiel_group_text;//"线缆"
@ApiModelProperty("最后更新时间明文")
private String update_time_text;//"2023-05-22 10:45:25"
private String time;
}

314
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/instock/InStockService.java

@ -1,8 +1,7 @@
package com.yxt.supervise.gf.biz.instock;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -13,14 +12,26 @@ import com.yxt.common.core.vo.PagerVo;
import com.yxt.supervise.gf.api.instock.InStock;
import com.yxt.supervise.gf.api.instock.InStockQuery;
import com.yxt.supervise.gf.api.instock.InStockVo;
import com.yxt.supervise.gf.api.pushinventorydata.PushInventoryData;
import com.yxt.supervise.gf.shanhai.ShRequester;
import com.yxt.supervise.gf.shanhai.req.In_stockGetRecordMaterielList;
import com.yxt.supervise.gf.shanhai.resp.BaseResponse;
import com.yxt.supervise.gf.shanhai.resp.BaseResponseListObj;
import com.yxt.supervise.gf.shanhai.resp.InStockGetRecordMaterielList;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author feikefei
@ -29,8 +40,14 @@ import java.util.List;
@Service
public class InStockService extends ServiceImpl<InStockMapper, InStock> {
@Value("${import.filePath}")
private String filePath;
public ResultBean save(In_stockGetRecordMaterielList reqParams){
ResultBean rb = ResultBean.fireFail();
String currDay = DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd");
reqParams.setStart_happen_time(currDay);
reqParams.setEnd_happen_time(currDay);
BaseResponse<BaseResponseListObj<InStockGetRecordMaterielList>> api$system$in_stock$get_record_materiel_list = ShRequester.getApi$system$in_stock$get_record_materiel_list(reqParams);
List<InStockGetRecordMaterielList> list = api$system$in_stock$get_record_materiel_list.getData().getList();
for (InStockGetRecordMaterielList inStockGetRecordMaterielList : list) {
@ -38,9 +55,300 @@ public class InStockService extends ServiceImpl<InStockMapper, InStock> {
BeanUtil.copyProperties(inStockGetRecordMaterielList,inStock);
baseMapper.insert(inStock);
}
Map<String, List<InStockGetRecordMaterielList>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name()));
Map<String, List<InStockGetRecordMaterielList>> map = new HashMap<>();
for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : listMap.entrySet()) {
String key = stringListEntry.getKey();
if (key.equals("江西余干库") || key.equals("庄河荣名库") || key.equals("安阳荣名库") || key.equals("藁城荣名库") || key.equals("曲阜荣名库")) {
List<InStockGetRecordMaterielList> value = stringListEntry.getValue();
List<InStockGetRecordMaterielList> filterValue = null;
filterValue = value.stream().filter(t -> t.getMateriel_group_text().equals("组件") || t.getMateriel_group_text().equals("逆变器")).collect(Collectors.toList());
if (filterValue.size() != 0){
map.put(stringListEntry.getKey(),filterValue);
}
}
}
try {
exportExcel(map);
}catch (Exception e){
e.printStackTrace();
}
return rb.success().setMsg("新增成功");
}
public void exportExcel(Map<String, List<InStockGetRecordMaterielList>> map1) throws Exception{
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
XSSFWorkbook wb = new XSSFWorkbook();
List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据
for (Map.Entry<String, List<InStockGetRecordMaterielList>> stringListEntry : map1.entrySet()) {
Map<String, Object> map = new HashMap<>();
//标题行抽出字段
String[] head = {"质物名称","规格(型号)","生产厂家(产地)","数量","重量","质权人确认的单价","核算的价值","货位号","备注"};
//设置sheet名称,并创建新的sheet对象
Sheet stuSheet = wb.createSheet(stringListEntry.getKey());
//合并单元格 设置表头信息
Row headRow = stuSheet.createRow(0); //第一行为头
Font head1 = wb.createFont();
head1.setFontHeightInPoints((short) 25);
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(head1);
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,head.length-1);
Cell cell1 = headRow.createCell(0);
cell1.setCellStyle(cellStyle);
cell1.setCellValue("货物入库质押表");
stuSheet.addMergedRegion(callRangeAddress);
Row headRowOne = stuSheet.createRow(1);
Cell headCell = headRowOne.createCell(0);
headCell.setCellValue("编号:");
Cell headCell1 = headRowOne.createCell(8);
headCell1.setCellValue("仓库名称:" + stringListEntry.getKey());
CellRangeAddress callRangeAddress1 = new CellRangeAddress(2,2,0,head.length-1);
Row headRowTwo = stuSheet.createRow(2);
Cell headCellTwo = headRowTwo.createCell(0);
headCellTwo.setCellValue("上报日期:" + sdf1.format(date));
stuSheet.addMergedRegion(callRangeAddress1);
//设置表头字体大小
Font font1 = wb.createFont();
font1.setFontHeightInPoints((short) 16);
//获取表头行
Row titleRow = stuSheet.createRow(3);
//创建单元格,设置style居中,字体,单元格大小等
CellStyle style = wb.createCellStyle();
style.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style.setAlignment(HorizontalAlignment.CENTER);
style.setBorderBottom(BorderStyle.THIN); //下边框
style.setBorderLeft(BorderStyle.THIN);//左边框
style.setBorderTop(BorderStyle.THIN);//上边框
style.setBorderRight(BorderStyle.THIN);//右边框
style.setShrinkToFit(true); //自动伸缩
style.setFont(font1);
//把已经写好的标题行写入excel文件中
for (int i = 0; i < head.length; i++) {
Cell cell = titleRow.createCell(i);
cell.setCellValue(head[i]);
cell.setCellStyle(style);
}
//把从数据库中取得的数据一一写入excel文件中
Row row = null;
Cell cell2 = null;
Double count = 0.0;
Integer numCount = 0;
CellStyle dataStyle = wb.createCellStyle();
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
dataStyle.setBorderBottom(BorderStyle.THIN); //下边框
dataStyle.setBorderLeft(BorderStyle.THIN);//左边框
dataStyle.setBorderTop(BorderStyle.THIN);//上边框
dataStyle.setBorderRight(BorderStyle.THIN);//右边框
for (int i = 0; i < stringListEntry.getValue().size(); i++) {
//创建list.size()行数据
row = stuSheet.createRow(i + 4);
//把值一一写进单元格里
//设置第一列为自动递增的序号
cell2 = row.createCell(0);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(1);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name());
numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(2);
cell2.setCellValue(stringListEntry.getValue().get(i).getSource_name());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(3);
cell2.setCellValue(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(4);
cell2.setCellValue("");
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(5);
cell2.setCellValue(stringListEntry.getValue().get(i).getPrice());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(6);
Double price = Double.parseDouble(stringListEntry.getValue().get(i).getPrice()) * Integer.parseInt(stringListEntry.getValue().get(i).getNum());
if (price == null){
price = 0.0;
}
cell2.setCellValue(price);
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(7);
cell2.setCellValue("");
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(8);
cell2.setCellValue("");
cell2.setCellStyle(dataStyle);
count+=price;
}
Font font = wb.createFont();
font.setFontHeightInPoints((short) 14);
Row row1 = stuSheet.createRow(stringListEntry.getValue().size()+4);
CellStyle style11 = wb.createCellStyle();
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style11.setAlignment(HorizontalAlignment.CENTER);
style11.setBorderBottom(BorderStyle.THIN); //下边框
style11.setBorderLeft(BorderStyle.THIN);//左边框
style11.setBorderTop(BorderStyle.THIN);//上边框
style11.setBorderRight(BorderStyle.THIN);//右边框
style11.setFont(font);
Cell cell11 = row1.createCell(0);
cell11.setCellStyle(style11);
cell11.setCellValue("合计");
cell11 = row1.createCell(3);
cell11.setCellStyle(style11);
cell11.setCellValue(numCount);
cell11 = row1.createCell(6);
cell11.setCellStyle(style11);
cell11.setCellValue(count);
cell11 = row1.createCell(1);
cell11.setCellStyle(style11);
cell11 = row1.createCell(2);
cell11.setCellStyle(style11);
cell11 = row1.createCell(4);
cell11.setCellStyle(style11);
cell11 = row1.createCell(5);
cell11.setCellStyle(style11);
cell11 = row1.createCell(7);
cell11.setCellStyle(style11);
cell11 = row1.createCell(8);
cell11.setCellStyle(style11);
map.put("name",stringListEntry.getKey());
map.put("numCount",numCount);
map.put("count",count);
listMap1.add(map);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < head.length; i++) {
stuSheet.autoSizeColumn(i, true);
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10);
}
}
//汇总工作簿
String[] collectHead = {"序号","仓库名称","物料数量","核算的价值"};
Sheet stuSheet = wb.createSheet("货物入库质押汇总表");
Row headRow = stuSheet.createRow(0); //第一行为头
Font head1 = wb.createFont();
head1.setFontHeightInPoints((short) 25);
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(head1);
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,collectHead.length-1);
CellRangeAddress callRangeAddress1 = new CellRangeAddress(1,1,0,collectHead.length-1);
CellRangeAddress callRangeAddress2 = new CellRangeAddress(2,2,0,collectHead.length-1);
Cell cell1 = headRow.createCell(0);
cell1.setCellStyle(cellStyle);
cell1.setCellValue("货物入库质押汇总表");
stuSheet.addMergedRegion(callRangeAddress);
Row headRowOne = stuSheet.createRow(1);
Cell headCell = headRowOne.createCell(0);
headCell.setCellValue("编号:");
stuSheet.addMergedRegion(callRangeAddress1);
Row headRowTwo = stuSheet.createRow(2);
Cell headCellTwo = headRowTwo.createCell(0);
headCellTwo.setCellValue("上报日期:" + sdf1.format(date));
stuSheet.addMergedRegion(callRangeAddress2);
//设置表头字体大小
Font font1 = wb.createFont();
font1.setFontHeightInPoints((short) 16);
//获取表头行
Row titleRow = stuSheet.createRow(3);
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setFontHeightInPoints((short) 16);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setBorderBottom(BorderStyle.THIN); //下边框
style.setBorderLeft(BorderStyle.THIN);//左边框
style.setBorderTop(BorderStyle.THIN);//上边框
style.setBorderRight(BorderStyle.THIN);//右边框
style.setShrinkToFit(true); //自动伸缩
style.setFont(font);
Cell cell = null;
//把已经写好的标题行写入excel文件中
for (int i = 0; i < collectHead.length; i++) {
cell = titleRow.createCell(i);
cell.setCellValue(collectHead[i]);
cell.setCellStyle(style);
}
//把从数据库中取得的数据一一写入excel文件中
Row row = null;
Cell cell2 = null;
Double count = 0.0;
CellStyle dataStyle = wb.createCellStyle();
dataStyle.setBorderBottom(BorderStyle.THIN); //下边框
dataStyle.setBorderLeft(BorderStyle.THIN);//左边框
dataStyle.setBorderTop(BorderStyle.THIN);//上边框
dataStyle.setBorderRight(BorderStyle.THIN);//右边框
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
Integer numSum = 0;
Double countSum = 0.0;
for (int i = 0; i < listMap1.size(); i++) {
//创建list.size()行数据
row = stuSheet.createRow(i + 4);
//把值一一写进单元格里
//设置第一列为自动递增的序号
cell2 = row.createCell(0);
cell2.setCellValue(i + 1);
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(1);
cell2.setCellValue(listMap1.get(i).get("name").toString());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(2);
cell2.setCellValue(listMap1.get(i).get("numCount").toString());
numSum+=Integer.parseInt(listMap1.get(i).get("numCount").toString());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(3);
DecimalFormat df = new DecimalFormat("#0.00");
cell2.setCellValue(df.format(listMap1.get(i).get("count")));
countSum+=Double.parseDouble(df.format(listMap1.get(i).get("count")));
cell2.setCellStyle(dataStyle);
}
font.setFontHeightInPoints((short) 14);
Row row1 = stuSheet.createRow(listMap1.size()+4);
CellStyle style11 = wb.createCellStyle();
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style11.setAlignment(HorizontalAlignment.CENTER);
style11.setBorderBottom(BorderStyle.THIN); //下边框
style11.setBorderLeft(BorderStyle.THIN);//左边框
style11.setBorderTop(BorderStyle.THIN);//上边框
style11.setBorderRight(BorderStyle.THIN);//右边框
style11.setFont(font);
Cell cell11 = row1.createCell(0);
cell11.setCellStyle(style11);
cell11.setCellValue("合计");
cell11 = row1.createCell(1);
cell11.setCellStyle(style11);
cell11 = row1.createCell(2);
cell11.setCellStyle(style11);
cell11.setCellValue(numSum);
cell11 = row1.createCell(3);
cell11.setCellStyle(style11);
cell11.setCellValue(countSum);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < collectHead.length; i++) {
stuSheet.autoSizeColumn(i, true);
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10);
}
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
//设置文件名
String fileName = "货物入库质押表" + sdf.format(new Date()) + ".xlsx";
String savePath = filePath + File.separator + fileName;
//下载
OutputStream fileOut = new FileOutputStream(savePath);
wb.write(fileOut);
fileOut.close();
}
public PagerVo<InStockVo> listPage(PagerQuery<InStockQuery> pq){
InStockQuery params = pq.getParams();
QueryWrapper<InStock> wq = new QueryWrapper<>();

80
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/inventory/InventoryService.java

@ -11,6 +11,8 @@ import com.yxt.common.core.vo.PagerVo;
import com.yxt.supervise.gf.api.inventory.Inventory;
import com.yxt.supervise.gf.api.inventory.InventoryQuery;
import com.yxt.supervise.gf.api.inventory.InventoryVo;
import com.yxt.supervise.gf.api.pushinventorydata.PushInventoryData;
import com.yxt.supervise.gf.biz.pushinventorydata.PushInventoryDataService;
import com.yxt.supervise.gf.shanhai.ShRequester;
import com.yxt.supervise.gf.shanhai.req.InventoryIndex;
import com.yxt.supervise.gf.shanhai.resp.BaseResponse;
@ -18,6 +20,7 @@ import com.yxt.supervise.gf.shanhai.resp.BaseResponseListObj;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -40,6 +43,8 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
@Value("${import.filePath}")
private String filePath;
@Autowired
private PushInventoryDataService pushInventoryDataService;
public ResultBean save(InventoryIndex inventoryIndex){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@ -53,8 +58,28 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
inventory1.setTime(sdf.format(date));
baseMapper.insert(inventory1);
}
//进行过滤并保存到本地推送库(监管数据)中
Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name()));
Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> map = new HashMap<>();
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : listMap.entrySet()) {
String key = stringListEntry.getKey();
if (key.equals("江西余干库") || key.equals("庄河荣名库") || key.equals("安阳荣名库") || key.equals("藁城荣名库") || key.equals("曲阜荣名库")) {
List<com.yxt.supervise.gf.shanhai.resp.Inventory> value = stringListEntry.getValue();
List<com.yxt.supervise.gf.shanhai.resp.Inventory> filterValue = null;
filterValue = value.stream().filter(t -> t.getMateriel_group_text().equals("组件") || t.getMateriel_group_text().equals("逆变器")).collect(Collectors.toList());
if (filterValue.size() != 0){
map.put(stringListEntry.getKey(),filterValue);
for (com.yxt.supervise.gf.shanhai.resp.Inventory inventory : filterValue) {
PushInventoryData pushInventoryData = new PushInventoryData();
BeanUtil.copyProperties(inventory,pushInventoryData,"id");
pushInventoryData.setTime(sdf.format(date));
pushInventoryDataService.save(pushInventoryData);
}
}
}
}
try {
exportExcel(list);
exportExcel(map);
}catch (Exception e){
e.printStackTrace();
}
@ -63,28 +88,18 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
/**
* 添加到数据库数据时生成的表格
* @param list 导出数据
* @param mapList 导出数据
* @throws Exception
*/
public void exportExcel(List<com.yxt.supervise.gf.shanhai.resp.Inventory> list) throws Exception {
public void exportExcel(Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> mapList) throws Exception {
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
XSSFWorkbook wb = new XSSFWorkbook();
Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> listMap = list.stream().collect(Collectors.groupingBy(it -> it.getStorehouse_name()));
List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据
Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> map1 = new HashMap<>();
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : listMap.entrySet()) {
List<com.yxt.supervise.gf.shanhai.resp.Inventory> value = stringListEntry.getValue();
List<com.yxt.supervise.gf.shanhai.resp.Inventory> filterValue = null;
filterValue = value.stream().filter(t -> t.getMateriel_group_text().equals("组件") || t.getMateriel_group_text().equals("逆变器")).collect(Collectors.toList());
if (filterValue.size() != 0){
map1.put(stringListEntry.getKey(),filterValue);
}
}
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : map1.entrySet()) {
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : mapList.entrySet()) {
Map<String, Object> map = new HashMap<>();
//标题行抽出字段
String[] head = {"序号","库存数量","仓库编码", "物料id", "物料编码", "物料组id", "物料品牌", "物料名称", "物料单价(成本价)", "最后更新时间", "物料组明文", "最后更新时间明文", "仓库名称","货值"};
String[] head = {"序号","仓库名称","物料组","物料编码","物料名称","物料品牌","物料单价","库存数量","货值"};
//设置sheet名称,并创建新的sheet对象
Sheet stuSheet = wb.createSheet(stringListEntry.getKey());
//合并单元格
@ -135,48 +150,33 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
cell2.setCellValue(i + 1);
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(1);
cell2.setCellValue(stringListEntry.getValue().get(i).getNum());
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_name());
numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(2);
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_code());
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(3);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_id());
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_no());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(4);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_no());
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(5);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(6);
cell2.setCellValue(stringListEntry.getValue().get(i).getBrand_name());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(7);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name());
cell2.setCellStyle(dataStyle);
Double price = stringListEntry.getValue().get(i).getPrice();
if (price == null){
price = 0.0;
}
cell2 = row.createCell(8);
cell2 = row.createCell(6);
cell2.setCellValue(price);
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(9);
cell2.setCellValue(stringListEntry.getValue().get(i).getUpdate_time());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(10);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(11);
cell2.setCellValue(stringListEntry.getValue().get(i).getUpdate_time_text());
cell2.setCellStyle(dataStyle);
cell2 = row.createCell(12);
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_name());
cell2 = row.createCell(7);
cell2.setCellValue(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle);
Double i1 = Integer.parseInt(stringListEntry.getValue().get(i).getNum()) * price;
cell2 = row.createCell(13);
cell2 = row.createCell(8);
cell2.setCellValue(i1);
cell2.setCellStyle(dataStyle);
count+=i1;
@ -191,7 +191,7 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
Cell cell11 = row1.createCell(0);
cell11.setCellStyle(style11);
cell11.setCellValue("合计");
cell11 = row1.createCell(13);
cell11 = row1.createCell(8);
cell11.setCellStyle(style11);
cell11.setCellValue(count);
map.put("name",stringListEntry.getKey());
@ -293,7 +293,7 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
file.mkdirs();
}
//设置文件名
String fileName = sdf1.format(new Date()) + "库存记录" + ".xlsx";
String fileName = "山海仓库库存" + sdf1.format(new Date()) + ".xlsx";
String savePath = filePath + File.separator + fileName;
//下载
OutputStream fileOut = new FileOutputStream(savePath);

13
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataMapper.java

@ -0,0 +1,13 @@
package com.yxt.supervise.gf.biz.pushinventorydata;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yxt.supervise.gf.api.pushinventorydata.PushInventoryData;
import org.apache.ibatis.annotations.Mapper;
/**
* @author feikefei
* @create 2023-07-20-9:26
*/
@Mapper
public interface PushInventoryDataMapper extends BaseMapper<PushInventoryData> {
}

16
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataRest.java

@ -0,0 +1,16 @@
package com.yxt.supervise.gf.biz.pushinventorydata;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author feikefei
* @create 2023-07-20-9:24
*/
@Api(value = "货物库存推送表(监管数据)")
@RestController
@RequestMapping("gf/pushInventoryData")
public class PushInventoryDataRest {
}

17
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/pushinventorydata/PushInventoryDataService.java

@ -0,0 +1,17 @@
package com.yxt.supervise.gf.biz.pushinventorydata;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxt.supervise.gf.api.pushinventorydata.PushInventoryData;
import org.springframework.stereotype.Service;
/**
* @author feikefei
* @create 2023-07-20-9:26
*/
@Service
public class PushInventoryDataService extends ServiceImpl<PushInventoryDataMapper, PushInventoryData> {
public void saveInventory(PushInventoryData data){
baseMapper.insert(data);
}
}

3
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShHttp.java

@ -68,7 +68,8 @@ public class ShHttp {
String data = headerData(date);
return httpRequest
.header("date", date)
.header("data", data);
.header("data", data)
.header("identity","system");
}
private static String headerData(String date) {

7
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/ShRequester.java

@ -374,9 +374,12 @@ public class ShRequester {
public static BaseResponse<BaseResponseListObj<InStockGetRecordMaterielList>> getApi$system$in_stock$get_record_materiel_list(In_stockGetRecordMaterielList reqParams){
BaseResponse<BaseResponseListObj<InStockGetRecordMaterielList>> req = new BaseResponse<>();
BaseResponseListObj<InStockGetRecordMaterielList> reqObj = new BaseResponseListObj<>();
Map<String, Object> param = null;
if (reqParams != null)
Map<String, Object> param = new HashMap<>();
if (reqParams != null){
param = BeanUtil.beanToMap(reqParams);
}
param.put("page",1);
param.put("limit",2000);
String s = ShHttp.doGet(in_stock$get_record_materiel_list, param);
BaseResponse<BaseResponseListObj<JSONObject>> baseResponse = toBean(s, req, reqObj);
BeanUtil.copyProperties(baseResponse,req);

15
yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/timedtask/ShanHaiTimedTask.java

@ -3,8 +3,10 @@ package com.yxt.supervise.gf.shanhai.timedtask;
import com.yxt.common.core.result.ResultBean;
import com.yxt.supervise.gf.biz.instock.InStockService;
import com.yxt.supervise.gf.biz.inventory.InventoryService;
import com.yxt.supervise.gf.biz.outstock.OutStockService;
import com.yxt.supervise.gf.shanhai.req.In_stockGetRecordMaterielList;
import com.yxt.supervise.gf.shanhai.req.InventoryIndex;
import com.yxt.supervise.gf.shanhai.req.Out_stockGetRecordMaterielList;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@ -22,6 +24,8 @@ public class ShanHaiTimedTask {
private InventoryService inventoryService;
@Autowired
private InStockService inStockService;
@Autowired
private OutStockService outStockService;
/**
* @Description //描述: 定时抓取并添加到本地库存管理信息并生成Excel文件到指定位置
@ -44,4 +48,15 @@ public class ShanHaiTimedTask {
In_stockGetRecordMaterielList list = new In_stockGetRecordMaterielList();
inStockService.save(list);
}
/**
* @Description //描述: 定时抓取并添加到本地出库记录信息
* @Param []
* @return void
**/
// @Scheduled(cron = "0 2 3 * * ?")
public void outStockTimedTask(){
Out_stockGetRecordMaterielList list = new Out_stockGetRecordMaterielList();
outStockService.save(list);
}
}

4
yxt-supervise-gf-biz/src/test/java/demo/tool/SecurTest.java

@ -146,8 +146,8 @@ public class SecurTest {
BaseResponse<BaseResponseListObj<StorehouseIndex>> api$system$storehouse$index = ShRequester.getApi$system$storehouse$index(null, null);
System.out.println(api$system$storehouse$index);
// BaseResponse<BaseResponseListObj<StorehouseIndex>> api$system$storehouse$index = ShRequester.getApi$system$storehouse$index(null, null);
// System.out.println(api$system$storehouse$index);
// BaseResponse<BaseResponseListObj<SupplierIndex>> api$system$supplier$index = ShRequester.getApi$system$supplier$index();
// System.out.println(api$system$supplier$index);

Loading…
Cancel
Save