This commit is contained in:
2024-03-07 09:14:21 +08:00
66 changed files with 1961 additions and 148 deletions

View File

@@ -0,0 +1,56 @@
package org.nl.wms.createmsg;
import com.alibaba.fastjson.JSONObject;
public class CreateMsg {
private static String excelPath = "D:/user3.xlsx";
private static String imgPath = "D:/Q4.PNG";
private static String sheetName = "0";
private static String multiple = "3";
public void createMsg(JSONObject whereJson) throws Exception {
excelPath = whereJson.getString("excelPath");
imgPath = whereJson.getString("imgPath");
System.out.println("");
System.out.println("**********************************");
System.out.println("***** " + "开始图片转换" + " *****");
System.out.println("**********************************");
System.out.println("");
System.out.println("***** " + "传入参数1" + excelPath + " *****");
System.out.println("***** " + "传入参数2" + imgPath + " *****");
System.out.println("***** " + "传入参数3" + sheetName + " *****");
System.out.println("***** " + "传入参数4" + multiple + " *****");
System.out.println("");
checkParam();
DrawFromExcel.excelToImage(excelPath, imgPath, sheetName, multiple);
System.out.println("");
System.out.println("**********************************");
System.out.println("***** " + "图片转换完成" + " *****");
System.out.println("**********************************");
}
/**
* 校验入参
*
* @throws Exception
*/
public static void checkParam() throws Exception {
if (null == excelPath || excelPath.isEmpty()) {
throw new Exception("操作异常未获取到【参数1】excel的绝对路径请核查后重试");
}
if (null == imgPath || imgPath.isEmpty()) {
throw new Exception("操作异常未获取到【参数2】生成图片的绝对路径请核查后重试");
}
if (null == sheetName || sheetName.isEmpty()) {
throw new Exception("操作异常未获取到【参数3】excel中Sheet页名称请核查后重试");
}
}
}

View File

@@ -0,0 +1,852 @@
package org.nl.wms.createmsg;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFSheet;
public class DrawFromExcel {
/**
* 默认图片格式
*/
private static final String IMAGE_FORMAT = "png";
/**
* 防止首行空行,的最大读取数值
*/
private static final int MAX_READ_NUM = 5;
/**
* excel结尾保留行数
*/
private static final int END_ROW_NUM = 0;
/**
* excel每行结果保留列数
*/
private static final int END_COL_NUM = 0;
/**
* 单元格边框宽度
*/
private static final int BORDER_WIDTH = 1;
/**
* 默认高度当获取row的行高空指针时使用此值
*/
private static final int DEFAULT_HEIGHT = 15;
/**
* 单元格字符高度修正值
*/
private static final int FONT_CORRECTED_Y = 2;
/**
* 单元格字符宽度修正值
*/
private static final int FONT_CORRECTED_X = 5;
/**
* 表格扩大倍数
*/
private static float grid_multiple = 0f;
/**
* 字体扩大倍数
*/
private static float font_multiple = 3f;
private static File excelFile = null;
private static Workbook workbook = null;
private static Sheet sheet = null;
private static DataFormatter dataFormatter = new DataFormatter();
private static BufferedImage image = null;
private static Graphics2D g2d = null;
private static FontMetrics fontMetrics = null;
public static void excelToImage(String excelPath, String imgPath, String sheetName, String multiple)
throws Exception {
excelFile = new File(excelPath);
if (!excelFile.exists()) {
throw new Exception("操作异常未获取到【参数1】的excel文件请核查后重试");
}
System.out.println("***** " + "创建对象并校验excel内容" + " *****");
workbook = WorkbookFactory.create(excelFile);
sheet = getSheet(workbook, sheetName);
if (null == sheet) {
throw new Exception("操作异常未获取到excel中的sheet页信息请核查后重试");
}
if (null != multiple && !multiple.isEmpty()) {
try {
grid_multiple = Float.parseFloat(multiple);
} catch (Exception e) {
grid_multiple = 1.5f;
}
}
int imageWidth = 0;// 图片宽度
int imageHeight = 0;// 图片高度
int lastRowNum = 0;// 表格最后一行
int lastCellNum = 0;// 表格最后一列
int rowSize = 0;// 表格行数
int colSize = 0;// 表格列数
List<Grid> grids = null;
List<CellRangeAddress> excelRangeAddress = new LinkedList<>();// 单元格合并集合
lastRowNum = sheet.getLastRowNum();
rowSize = sheet.getPhysicalNumberOfRows();
for (int i = 0; i < MAX_READ_NUM; i++) {
try {
lastCellNum = sheet.getRow(0).getLastCellNum();
colSize = sheet.getRow(0).getPhysicalNumberOfCells();
break;
} catch (Exception e) {
}
}
System.out.println("***** " + "获取到excel表格中【最后一行】为" + lastRowNum + " *****");
System.out.println("***** " + "获取到excel表格中【最后一列】为" + lastCellNum + " *****");
System.out.println("***** " + "获取到excel表格中存在的【物理行数】为" + rowSize + " *****");
System.out.println("***** " + "获取到excel表格中存在的【物理列数】为" + colSize + " *****");
rowSize = getRealRowSize(lastRowNum);
colSize = getMaxCellSize(lastRowNum, lastCellNum);
System.out.println("***** " + "处理后excel表格中存在的【最大行数】为" + rowSize + " *****");
System.out.println("***** " + "处理后excel表格中存在的【最大列数】为" + colSize + " *****");
if (rowSize == 0) {
throw new Exception("操作异常未获取到sheet页中的信息请核查后重试");
}
System.out.println();
imageWidth = getImageWidth(colSize);
System.out.println("***** " + "计算生成图片的【宽】为:" + imageWidth + " *****");
imageHeight = getImageHeight(rowSize);
System.out.println("***** " + "计算生成图片的【高】为:" + imageHeight + " *****");
grids = getGrid(rowSize, colSize);
System.out.println("***** " + "获取excel中存在【单元格的数量】为" + grids.size() + " *****");
excelRangeAddress = getMergedRegions();
System.out.println("***** " + "计算excel中存在【合并单元格的数量】为" + excelRangeAddress.size() + " *****");
countMergeGrid(grids, excelRangeAddress);
System.out.println("***** " + "与单元格合并计算处理后剩余【单元格的数量】为:" + grids.size() + " *****");
System.out.println();
System.out.println("***** " + "开始绘制图片" + " *****");
drawImage(imageWidth, imageHeight, grids);
System.out.println("***** " + "开始生成图片" + " *****");
ImageIO.write(image, IMAGE_FORMAT, new File(imgPath));
}
/**
* 获取指定的Sheet页没有指定则获取第一个sheet页
*
* @param workbook
* @param sheetName
* @return
*/
public static Sheet getSheet(Workbook workbook, String sheetName) {
Sheet sheet = workbook.getSheet(sheetName);
if (null == sheet) {
sheet = workbook.getSheetAt(0);
}
return sheet;
}
/**
* 获取最大行数
*
* @param lastRowNum
* @return
*/
public static int getRealRowSize(int lastRowNum) {
Row row = null;
String cellStr = "";
while (lastRowNum > 0) {
try {
row = sheet.getRow(lastRowNum);
for (Cell cell : row) {
cellStr = dataFormatter.formatCellValue(cell);
if (null != cellStr && !cellStr.isEmpty()) {
break;
}
}
} catch (Exception e) {
}
if (null != cellStr && !cellStr.isEmpty()) {
break;
}
lastRowNum--;
}
return lastRowNum + END_ROW_NUM + 1;
}
/**
* 获取最大的列数,兼容首列为空情况<br/>
*
* @param lastRowNum
* @param lastCellNum
* @return
*/
public static int getMaxCellSize(int lastRowNum, int lastCellNum) {
int cellSize = 0;
int maxRowNum = 0;
Row row = null;
while (lastRowNum > 0) {
try {
row = sheet.getRow(lastRowNum);
if (row.getPhysicalNumberOfCells() > cellSize) {
cellSize = row.getPhysicalNumberOfCells();
maxRowNum = lastRowNum;
}
} catch (Exception e) {
}
lastRowNum--;
}
return cellSize + countFrontNullColNum(maxRowNum, cellSize) + END_COL_NUM;
}
/**
* 计算前面空列<bar/> 当前面的列为空列时POI获取列最大值会去除空列按照从A0计算应该补充前面空列
*
* @return
*/
public static int countFrontNullColNum(int maxRowNum, int cellSize) {
int nullColNum = 0;
Row row = null;
Cell cell = null;
CellStyle cellStyle = null;
row = sheet.getRow(maxRowNum);
for (int i = 0; i < cellSize; i++) {
cell = null;
cellStyle = null;
try {
cell = row.getCell(i);
cellStyle = cell.getCellStyle();
if (null == cell || null == cellStyle) {
nullColNum++;
}
} catch (Exception e) {
nullColNum++;
}
}
return nullColNum;
}
/**
* 获取图片宽度
*
* @param cellSize
* @return
*/
public static int getImageWidth(int cellSize) {
int imageWidth = 0;
for (int i = 0; i < cellSize; i++) {
imageWidth += getColumnWidthInPixels(i) + BORDER_WIDTH * 2;
}
return (int) (imageWidth * grid_multiple)+ BORDER_WIDTH * 2;
}
/**
* 根据excel类型获取单元格宽度
*
* @param columnIndex
* @return
*/
public static int getColumnWidthInPixels(int columnIndex) {
float result = 0f;
if (sheet instanceof HSSFSheet) {
int cw = sheet.getColumnWidth(columnIndex);
int def = sheet.getDefaultColumnWidth() * 256;
float px = (cw == def) ? 32.0F : 36.56F;
result = cw / px;
} else if (sheet instanceof XSSFSheet) {
float widthIn256 = sheet.getColumnWidth(columnIndex);
result = (float) (widthIn256 / 256.0D * 7.001699924468994D);
} else if (sheet instanceof SXSSFSheet) {
float widthIn256 = sheet.getColumnWidth(columnIndex);
result = (float) (widthIn256 / 256.0D * 7.001699924468994D);
}
return (int) result;
}
/**
* 获取图片高度
*
* @param rowSize
* @return
*/
public static int getImageHeight(int rowSize) {
int imageHeight = 0;
Row row = null;
int nullSum = 0;
for (int i = 0; i < rowSize; i++) {
row = sheet.getRow(i);
try {
imageHeight += (int) row.getHeightInPoints() + BORDER_WIDTH * 2;
} catch (Exception e) {
imageHeight += DEFAULT_HEIGHT + BORDER_WIDTH * 2;
nullSum++;
}
}
System.out.println("***** " + "计算图片总高度时,发生【空指针】的次数为:" + nullSum + " *****");
return (int) (imageHeight * grid_multiple);
}
/**
* 获取excel的单元格合并的合集
*
* @return
*/
public static List<CellRangeAddress> getMergedRegions() {
List<CellRangeAddress> excelRangeAddress = new LinkedList<>();
int mergedRegionNum = sheet.getNumMergedRegions();
for (int i = 0; i < mergedRegionNum; i++) {
excelRangeAddress.add(sheet.getMergedRegion(i));
}
return excelRangeAddress;
}
/**
* 获取整体excel的单元格
*
* @param rowSize
* @param colSiz
* @return
*/
public static List<Grid> getGrid(int rowSize, int colSiz) {
List<Grid> grids = new ArrayList<>();
Grid grid = null;
Row row = null;
Cell cell = null;
int rowHeight = 0;
int colWidth = 0;
int x = 0;
int y = 0;
for (int i = 0; i < rowSize; i++) {
row = sheet.getRow(i);
/* 如果获取不到高度,则使用默认值 */
try {
rowHeight = (int) row.getHeightInPoints() + BORDER_WIDTH * 2;
} catch (Exception e) {
rowHeight = DEFAULT_HEIGHT + BORDER_WIDTH * 2;
}
rowHeight = (int) (rowHeight * grid_multiple);
x = 0;
/* poi会产生空行获取不到对象的情况在此主动创建一个对象 */
if (null == row) {
row = sheet.createRow(i);
for (int j = 0; j < colSiz; j++) {
cell = row.createCell(j);
cell.setCellValue("");
}
}
/* 遍历excel所有单元格并赋值给grid生成集合 */
for (int j = 0; j < colSiz; j++) {
cell = row.getCell(j);
colWidth = (int) getColumnWidthInPixels(j) + BORDER_WIDTH * 2;
colWidth = (int) (colWidth * grid_multiple);
grid = new Grid();
grid.setCell(cell);
grid.setRowNum(i);
grid.setColNum(j);
grid.setX(x);
grid.setY(y);
grid.setHeight(rowHeight);
grid.setWidth(colWidth);
grids.add(grid);
x += colWidth;
}
y += rowHeight;
}
return grids;
}
/**
* 计算合并的单元格
*
* @param grids
* @param excelRangeAddress
*/
@SuppressWarnings("rawtypes")
public static void countMergeGrid(List<Grid> grids, List<CellRangeAddress> excelRangeAddress) {
Map<String, Grid> gridMap = new HashMap<>();
for (Iterator iterator = grids.iterator(); iterator.hasNext();) {
Grid grid = (Grid) iterator.next();
gridMap.put(grid.getRowNum() + "_" + grid.getColNum(), grid);
}
int rowNum = 0;
int colNum = 0;
int firstRow = 0;
int firstColumn = 0;
int lastRow = 0;
int lastColumn = 0;
Grid endGrid = null;
for (Iterator iterator = grids.iterator(); iterator.hasNext();) {
Grid grid = (Grid) iterator.next();
rowNum = grid.getRowNum();
colNum = grid.getColNum();
for (CellRangeAddress cellRange : excelRangeAddress) {
firstRow = cellRange.getFirstRow();
firstColumn = cellRange.getFirstColumn();
lastRow = cellRange.getLastRow();
lastColumn = cellRange.getLastColumn();
/* 判断单元格是否在合并单元格区域,存在则重新计算第一个单元格的长宽、其他在合并区域的单元格删除 */
if (rowNum >= firstRow && rowNum <= lastRow && colNum >= firstColumn && colNum <= lastColumn) {
if (rowNum == firstRow && colNum == firstColumn) {
endGrid = gridMap.get(lastRow + "_" + lastColumn);
countMergeGridWidth(grid, endGrid);
} else {
iterator.remove();
}
}
}
}
}
/**
* 重新计算合并单元格,顶点的宽高
*
* @param startGrid
* @param endGrid
*/
public static void countMergeGridWidth(Grid startGrid, Grid endGrid) {
int startGridX = startGrid.getX();
int startGridY = startGrid.getY();
int endGridX = endGrid.getX();
int endGridY = endGrid.getY();
int endGridWidth = endGrid.getWidth();
int endGridHeight = endGrid.getHeight();
startGrid.setWidth(endGridX - startGridX + endGridWidth);
startGrid.setHeight(endGridY - startGridY + endGridHeight);
}
/**
* 根据grid绘制图片
*
* @param imageWidth
* @param imageHeight
* @param grids
*/
public static void drawImage(int imageWidth, int imageHeight, List<Grid> grids) {
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
g2d = image.createGraphics();
// 平滑字体
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST, 140);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
g2d.setColor(Color.white);
g2d.fillRect(0, 0, imageWidth, imageHeight);
fontMetrics = g2d.getFontMetrics();
Cell cell = null;
CellStyle cellStyle = null;
BorderStyle borderStyle = null;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
for (Grid grid : grids) {
x = grid.getX();
y = grid.getY();
width = grid.getWidth();
height = grid.getHeight();
/* 绘制整体表格边框 */
g2d.setColor(new Color(211, 211, 211));
g2d.setStroke(new BasicStroke(BORDER_WIDTH));
g2d.drawRect(x, y, width, height);
}
org.apache.poi.ss.usermodel.Font poiFont = null;
Font awtFont = null;
int strWidth = 0;
int strHeight = 0;
String cellValue = "";
for (Grid grid : grids) {
cellValue = "";
cellStyle = null;
strWidth = 0;
strHeight = 0;
cell = grid.getCell();
cellValue = dataFormatter.formatCellValue(cell);
try {
cellStyle = cell.getCellStyle();
} catch (Exception e) {
}
x = grid.getX();
y = grid.getY();
width = grid.getWidth();
height = grid.getHeight();
/* 绘制存在样式的表格边框 */
if (null != cellStyle) {
g2d.setColor(Color.black);
g2d.setStroke(new BasicStroke(BORDER_WIDTH));
borderStyle = cellStyle.getBorderTop();
if (borderStyle != BorderStyle.NONE) {
g2d.drawLine(x, y, x + width, y);
}
borderStyle = cellStyle.getBorderBottom();
if (borderStyle != BorderStyle.NONE) {
g2d.drawLine(x, y + height, x + width, y + height);
}
borderStyle = cellStyle.getBorderLeft();
if (borderStyle != BorderStyle.NONE) {
g2d.drawLine(x, y, x, y + height);
}
borderStyle = cellStyle.getBorderRight();
if (borderStyle != BorderStyle.NONE) {
g2d.drawLine(x + width, y, x + width, y + height);
}
}
/* 绘制单元格背景颜色 */
g2d.setColor(Color.white);
if (null != cellStyle) {
g2d.setColor(poiColorToAwtColor(cellStyle.getFillForegroundColorColor()));
}
g2d.fillRect(x + BORDER_WIDTH, y + BORDER_WIDTH, width - BORDER_WIDTH, height - BORDER_WIDTH);
/* 绘制文字 */
g2d.setColor(Color.black);
if (cellValue.contains("%")) {
cellValue = cellValue.substring(0, cellValue.indexOf("%")) + " " + "%";
}
if (null != cellStyle) {
// 设置字体
poiFont = workbook.getFontAt(cellStyle.getFontIndexAsInt());
awtFont = poiFontToAwtFont(poiFont);
g2d.setFont(awtFont);
// 设置字体颜色
g2d.setColor(getPoiFontColor(poiFont));
}
// 计算字符串宽度和高度
strWidth = fontMetrics.stringWidth(cellValue);
strHeight = fontMetrics.getHeight();
strWidth = (int) (strWidth * font_multiple);
strHeight = (int) (strHeight * ((font_multiple - 1) / 2 + 1));
if (width > strWidth) {
x = getDrawStrX(cellStyle, x, width, strWidth);
y = getDrawStrY(cellStyle, y, height, strHeight);
g2d.drawString(cellValue, x, y);
} else {
List<String> lines = SplitMultipleRows(cellValue, width, height, strHeight);
int sumLineHeight = strHeight * lines.size();
y = getDrawStrY(cellStyle, y, height, sumLineHeight);
for (int i = 0; i < lines.size(); i++) {
String str = lines.get(i);
strWidth = (int) (fontMetrics.stringWidth(str) * font_multiple);
g2d.drawString(str, getDrawStrX(cellStyle, x, width, strWidth),
y - sumLineHeight / lines.size() * (lines.size() - 1 - i) + BORDER_WIDTH * 2);
}
}
}
g2d.dispose();
}
/**
* 根据单元格宽高,及单元格内容,拆分多行
*
* @param cellValue
* @param width
* @param height
* @param strHeight
* @return
*/
@SuppressWarnings({ "rawtypes", "unused" })
public static List<String> SplitMultipleRows(String cellValue, int width, int height, int strHeight) {
List<String> lines = new ArrayList<>();
if (strHeight > height) {
lines = new ArrayList<>();
lines.add(cellValue);
return lines;
}
char[] valCharArray = cellValue.toCharArray();
int[] valCharWidthArray = new int[valCharArray.length];
StringBuffer strBuffer = new StringBuffer();
int sumCharWidth = 0;
int sumLineHeight = 0;
// 分别计算每个字符的宽度
for (int i = 0; i < valCharArray.length; i++) {
valCharWidthArray[i] = (int) (fontMetrics.stringWidth(String.valueOf(valCharArray[i])) * font_multiple);
}
// 相加字符,生成多行
for (int i = 0; i < valCharWidthArray.length; i++) {
sumCharWidth += valCharWidthArray[i];
if (sumCharWidth > width) {
lines.add(strBuffer.toString());
strBuffer = new StringBuffer();
sumCharWidth = valCharWidthArray[i];
}
strBuffer.append(valCharArray[i]);
if (i == valCharWidthArray.length - 1) {
lines.add(strBuffer.toString());
}
}
// 计算多行高度,如果大于表格高度,舍弃下面的行
for (Iterator iterator = lines.iterator(); iterator.hasNext();) {
String str = (String) iterator.next();
sumLineHeight = sumLineHeight + strHeight;
if (sumLineHeight > height) {
sumLineHeight = sumLineHeight - strHeight;
iterator.remove();
}
}
return lines;
}
/**
* 根据cellStyle的对齐方式获取绘制字符时X的位置
*
* @param cellStyle
* @param x
* @param width
* @param strWidth
* @return
*/
public static int getDrawStrX(CellStyle cellStyle, int x, int width, int strWidth) {
HorizontalAlignment alignment = null;
try {
alignment = cellStyle.getAlignment();
switch (alignment) {
case LEFT:
x = x + BORDER_WIDTH * 2 + FONT_CORRECTED_X;
break;
case CENTER:
x = x + (width - BORDER_WIDTH * 4 - strWidth) / 2 + FONT_CORRECTED_X;
break;
case RIGHT:
x = x + width - BORDER_WIDTH * 2 - strWidth + FONT_CORRECTED_X;
break;
default:
x = x + (width - BORDER_WIDTH * 4 - strWidth) / 2 + FONT_CORRECTED_X;
break;
}
} catch (Exception e) {
x = x + (width - BORDER_WIDTH * 4 - strWidth) / 2 + FONT_CORRECTED_X;
}
return x;
}
/**
* 根据cellStyle的对齐方式获取绘制字符时Y的位置
*
* @param cellStyle
* @param y
* @param height
* @param strHeight
* @return
*/
public static int getDrawStrY(CellStyle cellStyle, int y, int height, int strHeight) {
VerticalAlignment verticalAlignment = null;
try {
verticalAlignment = cellStyle.getVerticalAlignment();
switch (verticalAlignment) {
case TOP:
y = y + BORDER_WIDTH + strHeight - FONT_CORRECTED_Y;
break;
case CENTER:
y = y + BORDER_WIDTH + strHeight + (height - BORDER_WIDTH * 2 - strHeight) / 2 - FONT_CORRECTED_Y;
break;
case BOTTOM:
y = y + height - BORDER_WIDTH - FONT_CORRECTED_Y;
break;
default:
y = y + BORDER_WIDTH + strHeight + (height - BORDER_WIDTH * 2 - strHeight) / 2 - FONT_CORRECTED_Y;
break;
}
} catch (Exception e) {
y = y + BORDER_WIDTH + strHeight + (height - BORDER_WIDTH * 2 - strHeight) / 2 - FONT_CORRECTED_Y;
}
return y;
}
/**
* 通过POI字体获取AWT的字体颜色
*
* @param poiFont
* @return
*/
public static Color getPoiFontColor(org.apache.poi.ss.usermodel.Font poiFont) {
Color awtColor = null;
if (poiFont instanceof XSSFFont) {
XSSFColor color = ((XSSFFont) poiFont).getXSSFColor();
String rgbHex = "";
try {
rgbHex = color.getARGBHex();
} catch (Exception e) {
HSSFColor color1 = ((HSSFFont) poiFont).getHSSFColor((HSSFWorkbook) workbook);
short[] rgb = color1.getTriplet();
awtColor = new Color(rgb[255], rgb[0], rgb[0]);
return awtColor;
}
if (rgbHex != null) {
awtColor = new Color(Integer.parseInt(rgbHex.substring(2), 16));
}
} else if (poiFont instanceof HSSFFont) {
HSSFColor color = ((HSSFFont) poiFont).getHSSFColor((HSSFWorkbook) workbook);
short[] rgb = color.getTriplet();
awtColor = new Color(rgb[0], rgb[1], rgb[2]);
}
return awtColor;
}
/**
* POI颜色转AWT颜色
*
* @param color
* @return
*/
public static Color poiColorToAwtColor(org.apache.poi.ss.usermodel.Color color) {
Color awtColor = null;
if (color instanceof XSSFColor) {
String rgbHex = ((XSSFColor) color).getARGBHex();
if (rgbHex != null) {
awtColor = new Color(Integer.parseInt(rgbHex.substring(2), 16));
}
} else if (color instanceof HSSFColor) {
short[] s = ((HSSFColor) color).getTriplet();
if (s != null) {
awtColor = new Color(s[0], s[1], s[2]);
}
}
return awtColor;
}
/**
* POI字体转AWT字体
*
* @param poiFont
* @return
*/
public static Font poiFontToAwtFont(org.apache.poi.ss.usermodel.Font poiFont) {
int poiFontHeight = (int) poiFont.getFontHeightInPoints();
poiFontHeight = (int) (poiFontHeight * font_multiple);
return new Font(poiFont.getFontName(), Font.PLAIN, poiFontHeight);
}
}

View File

@@ -0,0 +1,70 @@
package org.nl.wms.createmsg;
import org.apache.poi.ss.usermodel.Cell;
public class Grid {
private Cell cell;
private int rowNum;
private int colNum;
private int x;
private int y;
private int width;
private int height;
public Cell getCell() {
return cell;
}
public int getRowNum() {
return rowNum;
}
public int getColNum() {
return colNum;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void setCell(Cell cell) {
this.cell = cell;
}
public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
public void setColNum(int colNum) {
this.colNum = colNum;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
}

View File

@@ -135,4 +135,45 @@ public interface LmsToMesService {
* }
*/
JSONObject ChildScrapUpdate(JSONObject jo);
/**
* 向飞书推送图片
* @param file_name : 图片名称
* @return {
* "RTYPE": "S",
* "RTMSG": "图片上传成功",
* "RTOAL": 0,
* "RSYS": null,
* "RTDAT": "img_v3_028m_594c5c05-e1d6-4b2c-8298-445f3df23d4g",
* "RTDAT2": null
* }
*/
JSONObject sendSalesIvtMsg(String file_name);
/**
* 向飞书推送业务员对应的图片参数
* @param param {
* "UserList": [
* {
* "User": "********" //用户工号列表
* }
* ],
* "Code": "*********", //卡片ID
* "card": { //卡片参数
* "**": {},
* "**": {}
* }
* }
* @return {
* "RTYPE": "S",
* "RTMSG": "消息发送成功",
* "RTOAL": 0,
* "RSYS": null,
* "RTDAT": null,
* "RTDAT2": null
* }
*/
JSONObject sendSalesIvtMsgParam(JSONObject param);
}

View File

@@ -702,4 +702,75 @@ public class LmsToMesServiceImpl implements LmsToMesService {
}
return result;
}
@Override
public JSONObject sendSalesIvtMsg(String file_name) {
log.info("sendSalesIvtMsg接口输入参数为-------------------" + file_name.toString());
JSONObject result = new JSONObject();
if (StrUtil.equals("0", is_connect_mes)) {
result.put("status", HttpStatus.OK.value());
result.put("message", "下发成功,但未连接飞书!");
result.put("data", new JSONObject());
return result;
}
String url = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("FEISHU_URL").getValue();
String api = "/FeiShuNoticesWebApi/UploadImage";
url = url + api;
try {
String resultMsg = HttpRequest.get(url)
.body("fileName",file_name)
.execute().body();
result = JSONObject.parseObject(resultMsg);
log.info("sendSalesIvtMsg接口输出参数为-------------------" + result.toString());
String RTYPE = result.getString("RTYPE");
if ("E".equals(RTYPE)) {
throw new BadRequestException(result.getString("RTMSG"));
}
} catch (Exception e) {
throw new BadRequestException("飞书提示错误:" + e.getMessage());
}
return result;
}
@Override
public JSONObject sendSalesIvtMsgParam(JSONObject param) {
log.info("sendSalesIvtMsgParam接口输入参数为-------------------" + param.toString());
JSONObject result = new JSONObject();
if (StrUtil.equals("0", is_connect_mes)) {
result.put("status", HttpStatus.OK.value());
result.put("message", "下发成功,但未连接飞书!");
result.put("data", new JSONObject());
return result;
}
String url = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("FEISHU_URL").getValue();
String api = "/FeiShuNoticesWebApi/SendCard";
url = url + api;
try {
String resultMsg = HttpRequest.post(url)
.body(String.valueOf(param))
.execute().body();
result = JSONObject.parseObject(resultMsg);
log.info("sendSalesIvtMsgParam接口输出参数为-------------------" + result.toString());
String RTYPE = result.getString("RTYPE");
if ("E".equals(RTYPE)) {
throw new BadRequestException(result.getString("RTMSG"));
}
} catch (Exception e) {
throw new BadRequestException("飞书提示错误:" + e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,443 @@
package org.nl.wms.sch.manage;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.nl.common.utils.IdUtil;
import org.nl.modules.common.config.FileProperties;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.tools.domain.LocalStorage;
import org.nl.modules.tools.repository.LocalStorageRepository;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.nl.system.service.param.impl.SysParamServiceImpl;
import org.nl.wms.createmsg.CreateMsg;
import org.nl.wms.ext.mes.service.LmsToMesService;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 查询区域对应业务员库存
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class AutoSendSalesIvt {
private final FileProperties properties;
private final LocalStorageRepository localStorageRepository;
private final LmsToMesService lmsToMesService;
/*
* 填充前路径
*/
private static String fileName = "";
/*
* 填充后路径
*/
private static String fileNameLast = "";
/*
* 模板
*/
private static String template = "";
/*
* 远程地址
*/
private static String baseApi = "http://60.165.35.2:8011";
public void run() {
fileName = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("REGION_PERSON_FRIST").getValue();
fileNameLast = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("REGION_PERSON_LAST").getValue();
template = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("REGION_PERSON_TEMP").getValue();
// 查询数据
queryData();
}
/**
* 查询数据
*/
private void queryData() {
// 查询所有客户
List<JSONObject> custList = WQL.getWO("TEST0002").addParam("flag", "1")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询区域
List<JSONObject> regionList = WQL.getWO("TEST0002").addParam("flag", "2")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询区域对应负责人
List<JSONObject> regionPersonList = WQL.getWO("TEST0002").addParam("flag", "3")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
for (int i = 0; i < regionList.size(); i++) {
String region_code = regionList.get(i).getString("value");
// 匹配对应的客户
List<JSONObject> areaCustList = custList.stream()
.filter(row -> row.getString("area").equals(region_code))
.collect(Collectors.toList());
String cust_name_in = areaCustList.stream()
.map(row -> row.getString("cust_name"))
.collect(Collectors.joining("','"));
// 根据业务员分组
Map<String, List<JSONObject>> salesMapList = areaCustList.stream()
.collect(Collectors.groupingBy(row -> row.getString("sales_owner")));
// 处理数据
JSONObject json = regionPersonList.stream()
.filter(row -> row.getString("label").equals(region_code))
.collect(Collectors.toList()).get(0);
JSONObject result = dataMang(salesMapList, cust_name_in, json.getString("value"));
result.put("name", regionList.get(i).getString("label"));
result.put("value", regionList.get(i).getString("value"));
if (result.getJSONArray("data").size() == 1) {
continue;
}
// 生成excel
createExcel(result);
}
}
/**
* 数据处理
* @param salesMapList :同一区域所有业务员客户分组
* @param cust_name_in :客户名称查询条件
* @param region_head :区域负责人
*/
private JSONObject dataMang(Map<String, List<JSONObject>> salesMapList, String cust_name_in ,String region_head) {
// 查询此区域15天以内所有库存
List<JSONObject> ivtList_15 = WQL.getWO("AUTO01").addParam("flag", "2").addParam("cust_name_in", "('" + cust_name_in + "')")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询此区域15-30天以内所有库存
List<JSONObject> ivtList15_30 = WQL.getWO("AUTO01").addParam("flag", "3").addParam("cust_name_in", "('" + cust_name_in + "')")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询此区域31-60天以内所有库存
List<JSONObject> ivtList31_60 = WQL.getWO("AUTO01").addParam("flag", "4").addParam("cust_name_in", "('" + cust_name_in + "')")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询此区域61-90天以内所有库存
List<JSONObject> ivtList61_90 = WQL.getWO("AUTO01").addParam("flag", "5").addParam("cust_name_in", "('" + cust_name_in + "')")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 查询此区域大于90天所有库存
List<JSONObject> ivtList90 = WQL.getWO("AUTO01").addParam("flag", "6").addParam("cust_name_in", "('" + cust_name_in + "')")
.process().getResultJSONArray(0).toJavaList(JSONObject.class);
// 返回的集合
List<JSONObject> resultListAll = new ArrayList<>();
// 记录每个业务员对应的数据条数
List<Integer> resultSize = new ArrayList<>();
double max_day1 = 0.00;
double max_day2 = 0.00;
double max_day3 = 0.00;
double max_day4 = 0.00;
double max_day5 = 0.00;
for (String sales : salesMapList.keySet()) {
// 业务员客户集合
List<JSONObject> salesList = salesMapList.get(sales);
List<JSONObject> resultList = new ArrayList<>();
for (int i = 0; i < salesList.size(); i++) {
JSONObject json = salesList.get(i);
JSONObject resultJson = new JSONObject();
resultJson.put("region_head",region_head);
resultJson.put("sales_man",sales);
resultJson.put("cust_name",json.getString("cust_name"));
// 匹配15以内库存
double qty15 = ivtList_15.stream()
.filter(row -> row.getString("cust_name").equals(json.getString("cust_name")))
.map(row -> row.getDoubleValue("canuse_qty"))
.reduce(Double::sum).orElse(0.000);
resultJson.put("day1", NumberUtil.round(qty15, 3));
// 匹配15-30以内库存
double qty15_30 = ivtList15_30.stream()
.filter(row -> row.getString("cust_name").equals(json.getString("cust_name")))
.map(row -> row.getDoubleValue("canuse_qty"))
.reduce(Double::sum).orElse(0.000);
resultJson.put("day2", NumberUtil.round(qty15_30, 3));
// 匹配31-60以内库存
double qty31_60 = ivtList31_60.stream()
.filter(row -> row.getString("cust_name").equals(json.getString("cust_name")))
.map(row -> row.getDoubleValue("canuse_qty"))
.reduce(Double::sum).orElse(0.000);
resultJson.put("day3", NumberUtil.round(qty31_60, 3));
// 匹配61-90以内库存
double qty61_90 = ivtList61_90.stream()
.filter(row -> row.getString("cust_name").equals(json.getString("cust_name")))
.map(row -> row.getDoubleValue("canuse_qty"))
.reduce(Double::sum).orElse(0.000);
resultJson.put("day4", NumberUtil.round(qty61_90, 3));
// 匹配大于90的库存
double qty90 = ivtList90.stream()
.filter(row -> row.getString("cust_name").equals(json.getString("cust_name")))
.map(row -> row.getDoubleValue("canuse_qty"))
.reduce(Double::sum).orElse(0.000);
resultJson.put("day5", NumberUtil.round(qty90, 3));
// 合计
double day_sum = NumberUtil.add(qty15, qty15_30, qty31_60, qty61_90, qty90).doubleValue();
resultJson.put("day_sum", NumberUtil.round(day_sum, 3));
resultList.add(resultJson);
}
// 插入小计
JSONObject jsonMin = new JSONObject();
jsonMin.put("sales_man", "小计");
// 15天以内
double day1_sum = resultList.stream()
.map(row -> row.getDoubleValue("day1"))
.reduce(Double::sum).orElse(0.00);
jsonMin.put("day1", NumberUtil.round(day1_sum, 3));
max_day1 = NumberUtil.add(max_day1,day1_sum);
// 15-30天以内
double day2_sum = resultList.stream()
.map(row -> row.getDoubleValue("day2"))
.reduce(Double::sum).orElse(0.00);
jsonMin.put("day2", NumberUtil.round(day2_sum, 3));
max_day2 = NumberUtil.add(max_day2,day2_sum);
// 31-60天以内
double day3_sum = resultList.stream()
.map(row -> row.getDoubleValue("day3"))
.reduce(Double::sum).orElse(0.00);
jsonMin.put("day3", NumberUtil.round(day3_sum, 3));
max_day3 = NumberUtil.add(max_day3,day3_sum);
// 61-90天以内
double day4_sum = resultList.stream()
.map(row -> row.getDoubleValue("day4"))
.reduce(Double::sum).orElse(0.00);
jsonMin.put("day4", NumberUtil.round(day4_sum, 3));
max_day4 = NumberUtil.add(max_day4,day4_sum);
// 大于90天
double day5_sum = resultList.stream()
.map(row -> row.getDoubleValue("day5"))
.reduce(Double::sum).orElse(0.00);
jsonMin.put("day5", NumberUtil.round(day5_sum, 3));
max_day5 = NumberUtil.add(max_day5,day5_sum);
// 合计
double day_sum = NumberUtil.add(day1_sum, day2_sum, day3_sum, day4_sum, day5_sum).doubleValue();
jsonMin.put("day_sum",day_sum);
resultList.add(jsonMin);
resultSize.add(resultListAll.size() + resultList.size()+1);
resultListAll.addAll(resultList);
}
// 计算最终合计
JSONObject jsonSum = new JSONObject();
jsonSum.put("sales_man", "合计");
jsonSum.put("day1",NumberUtil.round(max_day1, 3));
jsonSum.put("day2",NumberUtil.round(max_day2, 3));
jsonSum.put("day3",NumberUtil.round(max_day3, 3));
jsonSum.put("day4",NumberUtil.round(max_day4, 3));
jsonSum.put("day5",NumberUtil.round(max_day5, 3));
double day_sum = NumberUtil.add(max_day1, max_day2, max_day3, max_day4, max_day5).doubleValue();
jsonSum.put("day_sum",day_sum);
resultListAll.add(jsonSum);
JSONObject result = new JSONObject();
result.put("data", resultListAll);
resultSize.add(resultListAll.size()+1);
result.put("size", resultSize);
return result;
}
/**
* 生成excel
* @param result {
* data库存数据
* size需要填充颜色的第几行
* }
*/
@SneakyThrows
private void createExcel(JSONObject result) {
ExcelWriter workBook = EasyExcel.write(fileName).withTemplate(template).build();
WriteSheet sheet1 = EasyExcel.writerSheet(0).build();
// 数据
List<JSONObject> data = result.getJSONArray("data").toJavaList(JSONObject.class);
// 单组填充
JSONObject oneJson = new JSONObject();
oneJson.put("name", result.getString("name"));
workBook.fill(oneJson,sheet1);
// 多组填充
workBook.fill(new FillWrapper("data", data), sheet1);
workBook.finish();
// 添加样式
// 打开刚生成的excel文件
Workbook workbook = new XSSFWorkbook(fileName);
Sheet sheet = workbook.getSheetAt(0);
List<Integer> sizeList = result.getJSONArray("size").toJavaList(Integer.class);
for (int j = 0; j <sizeList.size(); j++) {
int size = sizeList.get(j);
Row row = sheet.getRow(size);
for (int i = 0; i < 9; i++) {
// 获取单元格
Cell cell = row.getCell(i);
// 创建单元格样式对象
CellStyle cellStyle = workbook.createCellStyle();
// 设置单元格的背景色为黄色 LIGHT_GREEN 、PALE_BLUE
cellStyle.setFillForegroundColor(IndexedColors.YELLOW1.getIndex());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
/*
* 设置字体
*/
Font font = workbook.createFont();
// 加粗字体
font.setBold(true);
// 设置字体颜色
font.setColor(IndexedColors.RED1.getIndex());
// 设置字体
if (i == 1) {
font.setFontName("宋体");
} else {
font.setFontName("Arial");
}
cellStyle.setFont(font);
// 居中对其
cellStyle.setAlignment(HorizontalAlignment.CENTER);
// 设置边框
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
// 设置单元格的样式
cell.setCellStyle(cellStyle);
}
}
// 创建输出流
FileOutputStream outputStream = new FileOutputStream(fileNameLast);
// 写入Excel文件
workbook.write(outputStream);
// 关闭输出流
outputStream.close();
System.out.println("写入成功");
/*
* 生成图片
*/
String type = FileUtil.getFileType("png");
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String fileName = format.format(date) + "-" + result.getString("value") + IdUtil.getStringId() + ".png";
String path = properties.getPath().getPath() + type + File.separator + fileName;
// 海亮共享文件夹
String filePath = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("HAILANG_FILEPATH").getValue() + fileName;
JSONObject param = new JSONObject();
param.put("excelPath", fileNameLast);
param.put("imgPath", filePath);
// 生成图片
CreateMsg createMsg = new CreateMsg();
createMsg.createMsg(param);
/* // 上传图片
LocalStorage localStorage = new LocalStorage(
nowStr + "区域库存.png",
nowStr + "区域库存",
"png",
path,
type,
"");
localStorageRepository.save(localStorage);*/
// 调用接口传送图片名称
JSONObject resultParam = lmsToMesService.sendSalesIvtMsg(fileName);
// 查询此区域的所有业务员
String area = result.getString("value");
List<JSONObject> areaList = WQLObject.getWQLObject("md_cs_areasalesinfo")
.query("area = '" + area + "' and is_active = '1'")
.getResultJSONArray(0).toJavaList(JSONObject.class);
List<JSONObject> userList = areaList.stream()
.map(row -> {
JSONObject jsonObject = new JSONObject();
jsonObject.put("User", row.getString("sales_code"));
return jsonObject;
})
.collect(Collectors.toList());
// 调用接口返回飞书
JSONObject paramFeiShu = new JSONObject();
paramFeiShu.put("UserList", userList);
paramFeiShu.put("Code", "");
paramFeiShu.put("card", resultParam.getString("RTDAT"));
lmsToMesService.sendSalesIvtMsgParam(paramFeiShu);
}
}

View File

@@ -0,0 +1,152 @@
[交易说明]
交易名: 业务员区域库存
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.cust_name_in TYPEAS f_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "2"
QUERY
SELECT
ivt.canuse_qty / 1000 AS canuse_qty,
cust.cust_code,
cust.cust_name
FROM
st_ivt_structivt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = attr.storagevehicle_code
AND ivt.pcsn = sub.container_name
INNER JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
WHERE
ivt.canuse_qty > '0'
AND cust.cust_name in 输入.cust_name_in
AND DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) < "15"
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "3"
QUERY
SELECT
ivt.canuse_qty / 1000 AS canuse_qty,
cust.cust_code,
cust.cust_name
FROM
st_ivt_structivt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = attr.storagevehicle_code
AND ivt.pcsn = sub.container_name
INNER JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
WHERE
ivt.canuse_qty > '0'
AND cust.cust_name in 输入.cust_name_in
AND (
DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) >= "15"
AND DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) <= "30"
)
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "4"
QUERY
SELECT
ivt.canuse_qty / 1000 AS canuse_qty,
cust.cust_code,
cust.cust_name
FROM
st_ivt_structivt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = attr.storagevehicle_code
AND ivt.pcsn = sub.container_name
INNER JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
WHERE
ivt.canuse_qty > '0'
AND cust.cust_name in 输入.cust_name_in
AND (
DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) >= "31"
AND DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) <= "60"
)
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "5"
QUERY
SELECT
ivt.canuse_qty / 1000 AS canuse_qty,
cust.cust_code,
cust.cust_name
FROM
st_ivt_structivt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = attr.storagevehicle_code
AND ivt.pcsn = sub.container_name
INNER JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
WHERE
ivt.canuse_qty > '0'
AND cust.cust_name in 输入.cust_name_in
AND (
DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) >= "61"
AND DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) <= "90"
)
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "6"
QUERY
SELECT
ivt.canuse_qty / 1000 AS canuse_qty,
cust.cust_code,
cust.cust_name
FROM
st_ivt_structivt ivt
LEFT JOIN st_ivt_structattr attr ON ivt.struct_id = attr.struct_id
LEFT JOIN pdm_bi_subpackagerelation sub ON sub.package_box_sn = attr.storagevehicle_code
AND ivt.pcsn = sub.container_name
INNER JOIN md_cs_customerbase cust ON cust.cust_code = sub.customer_name
WHERE
ivt.canuse_qty > '0'
AND cust.cust_name in 输入.cust_name_in
AND DATEDIFF( NOW(), LEFT(ivt.instorage_time,10) ) > "90"
ENDSELECT
ENDQUERY
ENDIF

View File

@@ -0,0 +1,80 @@
[交易说明]
交易名: 成品日报
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
QUERY
SELECT
cust.*,
info1.area
FROM
md_cs_customerbase cust
INNER JOIN md_cs_areasalesinfo info1 ON info1.sales_name = cust.sales_owner
WHERE
cust.is_delete = '0'
AND cust.is_used = '1'
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "2"
QUERY
SELECT
*
FROM
sys_dict
WHERE
code = 'IVT_REIGION'
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "3"
QUERY
SELECT
*
FROM
sys_dict
WHERE
code = 'IVT_REIGION_PERSON'
ENDSELECT
ENDQUERY
ENDIF