Browse Source

定时添加数据到云仓中

master
fkf 2 years ago
parent
commit
9849ee68e1
  1. 45
      docs/databases/table_create_gf.sql
  2. 1
      yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/prodstock/ProdStock.java
  3. 459
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/biz/inventory/InventoryService.java
  4. 4
      yxt-supervise-gf-biz/src/main/java/com/yxt/supervise/gf/shanhai/timedtask/ShanHaiTimedTask.java

45
docs/databases/table_create_gf.sql

@ -11,7 +11,7 @@
Target Server Version : 50741 Target Server Version : 50741
File Encoding : 65001 File Encoding : 65001
Date: 20/07/2023 17:33:16 Date: 15/08/2023 16:38:06
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
@ -45,7 +45,7 @@ CREATE TABLE `in_stock` (
`source_type` 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 '查询数据时间', `time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '查询数据时间',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物入库明细表' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 20 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物入库明细表' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for inventory -- Table structure for inventory
@ -67,7 +67,7 @@ CREATE TABLE `inventory` (
`storehouse_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 '仓库名称',
`time` 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 PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 164 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '库存记录表' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 6049 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '库存记录表' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for out_stock -- Table structure for out_stock
@ -95,8 +95,9 @@ CREATE TABLE `out_stock` (
`create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci 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_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 '来源类型', `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 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 = 56 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '货物出库明细表' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for push_in_stock_data -- Table structure for push_in_stock_data
@ -126,7 +127,7 @@ CREATE TABLE `push_in_stock_data` (
`source_type` 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 '查询数据时间', `time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '查询数据时间',
PRIMARY KEY (`id`) USING BTREE 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 = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管入库数据表(推送入库数据表)' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for push_inventory_data -- Table structure for push_inventory_data
@ -148,7 +149,37 @@ CREATE TABLE `push_inventory_data` (
`storehouse_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 '仓库名称',
`time` 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 PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 53 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管库存数据表(推送库存)' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 991 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管库存数据表(推送库存)' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for push_out_stock_data
-- ----------------------------
DROP TABLE IF EXISTS `push_out_stock_data`;
CREATE TABLE `push_out_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 = 42 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '监管出库数据表(推送出库数据表)' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for warehouse information -- Table structure for warehouse information
@ -160,6 +191,6 @@ CREATE TABLE `warehouse information` (
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称', `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库名称',
`address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库地址', `address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '仓库地址',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 34 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '仓库信息表' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '仓库信息表' ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

1
yxt-supervise-gf-api/src/main/java/com/yxt/supervise/gf/api/prodstock/ProdStock.java

@ -16,6 +16,7 @@ public class ProdStock {
private String weight; private String weight;
private String confirmedPrice; private String confirmedPrice;
private String calculatedValue; private String calculatedValue;
private String locationId;
private String locationNumber; private String locationNumber;
private String custerName; private String custerName;
private String proUnit; private String proUnit;

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

@ -128,243 +128,246 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
prodStock.setProSid(inventory.getMateriel_id()); prodStock.setProSid(inventory.getMateriel_id());
prodStock.setCusterName(data.get(0).get("custerName").toString()); prodStock.setCusterName(data.get(0).get("custerName").toString());
prodStock.setCusterSid(records1.get(0).getSid()); prodStock.setCusterSid(records1.get(0).getSid());
prodStock.setLocationId("0");
prodStock.setLocationNumber("0");
prodStockList.add(prodStock); prodStockList.add(prodStock);
} }
} }
} }
prodStockMap.put("list", prodStockList); prodStockMap.put("list", prodStockList);
String s = JSON.toJSONString(prodStockMap); String s = JSON.toJSONString(prodStockMap);
HttpRequest.post("http://jianguan.yyundong.com/warehouseapi/stock/importStock").body(s).execute(); HttpResponse execute = HttpRequest.post("http://jianguan.yyundong.com/warehouseapi/stock/importStock").body(s).execute();
//导出报表 System.out.println(execute);
ThreadUtil.execute(() -> { //导出报表 暂时在此项目中不需要导出Excel报表
try { // ThreadUtil.execute(() -> {
exportExcel(map); // try {
}catch (Exception e){ // exportExcel(map);
e.printStackTrace(); // }catch (Exception e){
} // e.printStackTrace();
}); // }
// });
return rb.success().setMsg("添加成功"); return rb.success().setMsg("添加成功");
} }
/** // /**
* 添加到数据库数据时生成的表格 // * 添加到数据库数据时生成的表格
* @param mapList 导出数据 // * @param mapList 导出数据
* @throws Exception // * @throws Exception
*/ // */
public void exportExcel(Map<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> mapList) 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"); // SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date(); // Date date = new Date();
XSSFWorkbook wb = new XSSFWorkbook(); // XSSFWorkbook wb = new XSSFWorkbook();
List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据 // List<Map<String, Object>> listMap1 = new ArrayList<>();//存储汇总数据
mapList.forEach((k,v) -> { // mapList.forEach((k,v) -> {
HashMap<String, Object> mapCount = new HashMap<>(); // HashMap<String, Object> mapCount = new HashMap<>();
Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum(); // Integer sumCount = v.stream().mapToInt(it -> Integer.parseInt(it.getNum())).sum();
Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * it.getPrice()).sum(); // Double priceCount = v.stream().mapToDouble(it -> Integer.parseInt(it.getNum()) * it.getPrice()).sum();
mapCount.put("name",k); // mapCount.put("name",k);
mapCount.put("sumCount",sumCount); // mapCount.put("sumCount",sumCount);
mapCount.put("priceCount",priceCount); // mapCount.put("priceCount",priceCount);
listMap1.add(mapCount); // listMap1.add(mapCount);
}); // });
//汇总工作簿 // //汇总工作簿
String[] collectHead = {"序号","仓库名称","物料数量","货值"}; // String[] collectHead = {"序号","仓库名称","物料数量","货值"};
Sheet stuSheeth = wb.createSheet("汇总"); // Sheet stuSheeth = wb.createSheet("汇总");
Row headRowh = stuSheeth.createRow(0); //第一行为头 // Row headRowh = stuSheeth.createRow(0); //第一行为头
Font head1h = wb.createFont(); // Font head1h = wb.createFont();
head1h.setFontHeightInPoints((short) 25); // head1h.setFontHeightInPoints((short) 25);
CellStyle cellStyleh = wb.createCellStyle(); // CellStyle cellStyleh = wb.createCellStyle();
cellStyleh.setFont(head1h); // cellStyleh.setFont(head1h);
cellStyleh.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式 // cellStyleh.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStyleh.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // cellStyleh.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddressh = new CellRangeAddress(0,0,0,collectHead.length-1); // CellRangeAddress callRangeAddressh = new CellRangeAddress(0,0,0,collectHead.length-1);
Cell cell1h = headRowh.createCell(0); // Cell cell1h = headRowh.createCell(0);
cell1h.setCellStyle(cellStyleh); // cell1h.setCellStyle(cellStyleh);
cell1h.setCellValue("库存汇总"); // cell1h.setCellValue("库存汇总");
stuSheeth.addMergedRegion(callRangeAddressh); // stuSheeth.addMergedRegion(callRangeAddressh);
//设置表头字体大小 // //设置表头字体大小
Font font1h = wb.createFont(); // Font font1h = wb.createFont();
font1h.setFontHeightInPoints((short) 16); // font1h.setFontHeightInPoints((short) 16);
//获取表头行 // //获取表头行
Row titleRowh = stuSheeth.createRow(1); // Row titleRowh = stuSheeth.createRow(1);
CellStyle styleh = wb.createCellStyle(); // CellStyle styleh = wb.createCellStyle();
Font fonth = wb.createFont(); // Font fonth = wb.createFont();
fonth.setFontHeightInPoints((short) 16); // fonth.setFontHeightInPoints((short) 16);
styleh.setVerticalAlignment(VerticalAlignment.CENTER); // styleh.setVerticalAlignment(VerticalAlignment.CENTER);
styleh.setAlignment(HorizontalAlignment.CENTER); // styleh.setAlignment(HorizontalAlignment.CENTER);
styleh.setShrinkToFit(true); //自动伸缩 // styleh.setShrinkToFit(true); //自动伸缩
styleh.setFont(fonth); // styleh.setFont(fonth);
Cell cell = null; // Cell cell = null;
//把已经写好的标题行写入excel文件中 // //把已经写好的标题行写入excel文件中
for (int i = 0; i < collectHead.length; i++) { // for (int i = 0; i < collectHead.length; i++) {
cell = titleRowh.createCell(i); // cell = titleRowh.createCell(i);
cell.setCellValue(collectHead[i]); // cell.setCellValue(collectHead[i]);
cell.setCellStyle(styleh); // cell.setCellStyle(styleh);
} // }
//把从数据库中取得的数据一一写入excel文件中 // //把从数据库中取得的数据一一写入excel文件中
Row rowh = null; // Row rowh = null;
Cell cell2h = null; // Cell cell2h = null;
CellStyle dataStyleh = wb.createCellStyle(); // CellStyle dataStyleh = wb.createCellStyle();
dataStyleh.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // dataStyleh.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyleh.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式 // dataStyleh.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
Integer numSum = 0; // Integer numSum = 0;
Double countSum = 0.0; // Double countSum = 0.0;
for (int i = 0; i < listMap1.size(); i++) { // for (int i = 0; i < listMap1.size(); i++) {
//创建list.size()行数据 // //创建list.size()行数据
rowh = stuSheeth.createRow(i + 2); // rowh = stuSheeth.createRow(i + 2);
//把值一一写进单元格里 // //把值一一写进单元格里
//设置第一列为自动递增的序号 // //设置第一列为自动递增的序号
cell2h = rowh.createCell(0); // cell2h = rowh.createCell(0);
cell2h.setCellValue(i + 1); // cell2h.setCellValue(i + 1);
cell2h.setCellStyle(dataStyleh); // cell2h.setCellStyle(dataStyleh);
cell2h = rowh.createCell(1); // cell2h = rowh.createCell(1);
cell2h.setCellValue(listMap1.get(i).get("name").toString()); // cell2h.setCellValue(listMap1.get(i).get("name").toString());
cell2h.setCellStyle(dataStyleh); // cell2h.setCellStyle(dataStyleh);
cell2h = rowh.createCell(2); // cell2h = rowh.createCell(2);
cell2h.setCellValue(listMap1.get(i).get("sumCount").toString()); // cell2h.setCellValue(listMap1.get(i).get("sumCount").toString());
numSum+=Integer.parseInt(listMap1.get(i).get("sumCount").toString()); // numSum+=Integer.parseInt(listMap1.get(i).get("sumCount").toString());
cell2h.setCellStyle(dataStyleh); // cell2h.setCellStyle(dataStyleh);
cell2h = rowh.createCell(3); // cell2h = rowh.createCell(3);
DecimalFormat df = new DecimalFormat("#0.00"); // DecimalFormat df = new DecimalFormat("#0.00");
cell2h.setCellValue(df.format(listMap1.get(i).get("priceCount"))); // cell2h.setCellValue(df.format(listMap1.get(i).get("priceCount")));
countSum+=Double.parseDouble(df.format(listMap1.get(i).get("priceCount"))); // countSum+=Double.parseDouble(df.format(listMap1.get(i).get("priceCount")));
cell2h.setCellStyle(dataStyleh); // cell2h.setCellStyle(dataStyleh);
} // }
fonth.setFontHeightInPoints((short) 14); // fonth.setFontHeightInPoints((short) 14);
Row row1h = stuSheeth.createRow(listMap1.size()+2); // Row row1h = stuSheeth.createRow(listMap1.size()+2);
CellStyle style11h = wb.createCellStyle(); // CellStyle style11h = wb.createCellStyle();
style11h.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // style11h.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style11h.setAlignment(HorizontalAlignment.CENTER); // style11h.setAlignment(HorizontalAlignment.CENTER);
style11h.setFont(fonth); // style11h.setFont(fonth);
Cell cell11h = row1h.createCell(0); // Cell cell11h = row1h.createCell(0);
cell11h.setCellStyle(style11h); // cell11h.setCellStyle(style11h);
cell11h.setCellValue("合计"); // cell11h.setCellValue("合计");
cell11h = row1h.createCell(2); // cell11h = row1h.createCell(2);
cell11h.setCellStyle(style11h); // cell11h.setCellStyle(style11h);
cell11h.setCellValue(numSum); // cell11h.setCellValue(numSum);
cell11h = row1h.createCell(3); // cell11h = row1h.createCell(3);
cell11h.setCellStyle(style11h); // cell11h.setCellStyle(style11h);
cell11h.setCellValue(countSum); // cell11h.setCellValue(countSum);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍 // //设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < collectHead.length; i++) { // for (int i = 0; i < collectHead.length; i++) {
stuSheeth.autoSizeColumn(i, true); // stuSheeth.autoSizeColumn(i, true);
stuSheeth.setColumnWidth(i, stuSheeth.getColumnWidth(i) * 15 / 10); // stuSheeth.setColumnWidth(i, stuSheeth.getColumnWidth(i) * 15 / 10);
} // }
//
//
for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : mapList.entrySet()) { // for (Map.Entry<String, List<com.yxt.supervise.gf.shanhai.resp.Inventory>> stringListEntry : mapList.entrySet()) {
//标题行抽出字段 // //标题行抽出字段
String[] head = {"序号","仓库名称","物料组","物料编码","物料名称","物料品牌","物料单价","库存数量","货值"}; // String[] head = {"序号","仓库名称","物料组","物料编码","物料名称","物料品牌","物料单价","库存数量","货值"};
//设置sheet名称,并创建新的sheet对象 // //设置sheet名称,并创建新的sheet对象
Sheet stuSheet = wb.createSheet(stringListEntry.getKey()); // Sheet stuSheet = wb.createSheet(stringListEntry.getKey());
//合并单元格 // //合并单元格
Row headRow = stuSheet.createRow(0); //第一行为头 // Row headRow = stuSheet.createRow(0); //第一行为头
Font head1 = wb.createFont(); // Font head1 = wb.createFont();
head1.setFontHeightInPoints((short) 25); // head1.setFontHeightInPoints((short) 25);
CellStyle cellStyle = wb.createCellStyle(); // CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(head1); // cellStyle.setFont(head1);
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式 // cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,head.length-1); // CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,head.length-1);
Cell cell1 = headRow.createCell(0); // Cell cell1 = headRow.createCell(0);
cell1.setCellStyle(cellStyle); // cell1.setCellStyle(cellStyle);
cell1.setCellValue(stringListEntry.getKey() + "("+ sdf1.format(date) +")"); // cell1.setCellValue(stringListEntry.getKey() + "("+ sdf1.format(date) +")");
stuSheet.addMergedRegion(callRangeAddress); // stuSheet.addMergedRegion(callRangeAddress);
//设置表头字体大小 // //设置表头字体大小
Font font1 = wb.createFont(); // Font font1 = wb.createFont();
font1.setFontHeightInPoints((short) 16); // font1.setFontHeightInPoints((short) 16);
//获取表头行 // //获取表头行
Row titleRow = stuSheet.createRow(1); // Row titleRow = stuSheet.createRow(1);
//创建单元格,设置style居中,字体,单元格大小等 // //创建单元格,设置style居中,字体,单元格大小等
CellStyle style = wb.createCellStyle(); // CellStyle style = wb.createCellStyle();
style.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // style.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(HorizontalAlignment.CENTER);
style.setShrinkToFit(true); //自动伸缩 // style.setShrinkToFit(true); //自动伸缩
style.setFont(font1); // style.setFont(font1);
Cell cellh = null; // Cell cellh = null;
//把已经写好的标题行写入excel文件中 // //把已经写好的标题行写入excel文件中
for (int i = 0; i < head.length; i++) { // for (int i = 0; i < head.length; i++) {
cellh = titleRow.createCell(i); // cellh = titleRow.createCell(i);
cellh.setCellValue(head[i]); // cellh.setCellValue(head[i]);
cellh.setCellStyle(style); // cellh.setCellStyle(style);
} // }
//把从数据库中取得的数据一一写入excel文件中 // //把从数据库中取得的数据一一写入excel文件中
Row row = null; // Row row = null;
Cell cell2 = null; // Cell cell2 = null;
Double count = 0.0; // Double count = 0.0;
Integer numCount = 0; // Integer numCount = 0;
CellStyle dataStyle = wb.createCellStyle(); // CellStyle dataStyle = wb.createCellStyle();
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式 // dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
for (int i = 0; i < stringListEntry.getValue().size(); i++) { // for (int i = 0; i < stringListEntry.getValue().size(); i++) {
//创建list.size()行数据 // //创建list.size()行数据
row = stuSheet.createRow(i + 2); // row = stuSheet.createRow(i + 2);
//把值一一写进单元格里 // //把值一一写进单元格里
//设置第一列为自动递增的序号 // //设置第一列为自动递增的序号
cell2 = row.createCell(0); // cell2 = row.createCell(0);
cell2.setCellValue(i + 1); // cell2.setCellValue(i + 1);
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(1); // cell2 = row.createCell(1);
cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_name()); // cell2.setCellValue(stringListEntry.getValue().get(i).getStorehouse_name());
numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum()); // numCount+=Integer.parseInt(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(2); // cell2 = row.createCell(2);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text()); // cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_group_text());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(3); // cell2 = row.createCell(3);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_no()); // cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_no());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(4); // cell2 = row.createCell(4);
cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name()); // cell2.setCellValue(stringListEntry.getValue().get(i).getMateriel_name());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(5); // cell2 = row.createCell(5);
cell2.setCellValue(stringListEntry.getValue().get(i).getBrand_name()); // cell2.setCellValue(stringListEntry.getValue().get(i).getBrand_name());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
Double price = stringListEntry.getValue().get(i).getPrice(); // Double price = stringListEntry.getValue().get(i).getPrice();
if (price == null){ // if (price == null){
price = 0.0; // price = 0.0;
} // }
cell2 = row.createCell(6); // cell2 = row.createCell(6);
cell2.setCellValue(price); // cell2.setCellValue(price);
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
cell2 = row.createCell(7); // cell2 = row.createCell(7);
cell2.setCellValue(stringListEntry.getValue().get(i).getNum()); // cell2.setCellValue(stringListEntry.getValue().get(i).getNum());
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
Double i1 = Integer.parseInt(stringListEntry.getValue().get(i).getNum()) * price; // Double i1 = Integer.parseInt(stringListEntry.getValue().get(i).getNum()) * price;
cell2 = row.createCell(8); // cell2 = row.createCell(8);
cell2.setCellValue(i1); // cell2.setCellValue(i1);
cell2.setCellStyle(dataStyle); // cell2.setCellStyle(dataStyle);
count+=i1; // count+=i1;
} // }
Font font = wb.createFont(); // Font font = wb.createFont();
font.setFontHeightInPoints((short) 14); // font.setFontHeightInPoints((short) 14);
Row row1 = stuSheet.createRow(stringListEntry.getValue().size()+2); // Row row1 = stuSheet.createRow(stringListEntry.getValue().size()+2);
CellStyle style11 = wb.createCellStyle(); // CellStyle style11 = wb.createCellStyle();
style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式 // style11.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
style11.setAlignment(HorizontalAlignment.CENTER); // style11.setAlignment(HorizontalAlignment.CENTER);
style11.setFont(font); // style11.setFont(font);
Cell cell11 = row1.createCell(0); // Cell cell11 = row1.createCell(0);
cell11.setCellStyle(style11); // cell11.setCellStyle(style11);
cell11.setCellValue("合计"); // cell11.setCellValue("合计");
cell11 = row1.createCell(8); // cell11 = row1.createCell(8);
cell11.setCellStyle(style11); // cell11.setCellStyle(style11);
cell11.setCellValue(count); // cell11.setCellValue(count);
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍 // //设置单元格宽度自适应,在此基础上把宽度调至1.5倍
for (int i = 0; i < head.length; i++) { // for (int i = 0; i < head.length; i++) {
stuSheet.autoSizeColumn(i, true); // stuSheet.autoSizeColumn(i, true);
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10); // stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10);
} // }
} // }
File file = new File(filePath); // File file = new File(filePath);
if (!file.exists()) { // if (!file.exists()) {
file.mkdirs(); // file.mkdirs();
} // }
//设置文件名 // //设置文件名
String fileName = "山海仓库库存" + sdf1.format(new Date()) + ".xlsx"; // String fileName = "山海仓库库存" + sdf1.format(new Date()) + ".xlsx";
String savePath = filePath + File.separator + fileName; // String savePath = filePath + File.separator + fileName;
//下载 // //下载
OutputStream fileOut = new FileOutputStream(savePath); // OutputStream fileOut = new FileOutputStream(savePath);
wb.write(fileOut); // wb.write(fileOut);
fileOut.close(); // fileOut.close();
} // }
public PagerVo<InventoryVo> listPage(PagerQuery<InventoryQuery> pq){ public PagerVo<InventoryVo> listPage(PagerQuery<InventoryQuery> pq){
InventoryQuery params = pq.getParams(); InventoryQuery params = pq.getParams();

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

@ -29,11 +29,11 @@ public class ShanHaiTimedTask {
private OutStockService outStockService; private OutStockService outStockService;
/** /**
* @Description //描述: 定时抓取并添加到本地库存管理信息并生成Excel文件到指定位置 * @Description //描述: 定时抓取并添加数据到本地库存管理信息
* @Param [] * @Param []
* @return void * @return void
**/ **/
// @Scheduled(cron = "0 0 3 * * ?") @Scheduled(cron = "0 0 2 * * ?")
public void inventoryTimedTask(){ public void inventoryTimedTask(){
ThreadUtil.execute(() -> inventoryService.save(new InventoryIndex())); ThreadUtil.execute(() -> inventoryService.save(new InventoryIndex()));
} }

Loading…
Cancel
Save