Commit 6d401a87 by wancheng

物料清单导入

parent c04d3f93
package com.baosight.hpjx.aspect.annotation;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hpjx.util.DocExcelUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.soa.XLocalManager;
import com.baosight.iplat4j.core.web.controller.WebDispatchController;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.Args;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.baosight.hpjx.common.DocRouteEnum;
/**
* DOC 接口类
*
* @author:songx
* @date:2022/5/5,10:04
*/
@CrossOrigin
@RestController
@RequestMapping("/doc")
public class DocController extends WebDispatchController {
private final static Logger logger = LoggerFactory.getLogger(DocController.class);
/**
* 批量导入
*
* @param file
* @return
*/
@RequestMapping(value = "/import/api", method = RequestMethod.POST)
public EiInfo importExcel(MultipartFile file, HttpServletRequest request) {
Map<String, String[]> paramMaps = request.getParameterMap();
EiInfo outInfo = new EiInfo();
outInfo.setStatus(EiConstant.STATUS_FAILURE);
try {
if (file == null) {
outInfo.setMsg("导入文件不能为空");
return outInfo;
}
String id = request.getParameter("id");
DocRouteEnum docRouteEnum = DocRouteEnum.getById(id);
if (docRouteEnum == null) {
outInfo.setMsg("导入标识ID不存在");
return outInfo;
}
String startRow = request.getParameter("startRow");
List dataList = DocExcelUtils.readExcel(file, NumberUtils.createInteger(startRow), docRouteEnum.getClazz());
if (CollectionUtils.isEmpty(dataList)) {
outInfo.setMsg("未读取到数据");
return outInfo;
}
outInfo.set(EiConstant.serviceName, docRouteEnum.getServiceNme());
outInfo.set(EiConstant.methodName, docRouteEnum.getMethodName());
outInfo.set("params", this.convertParam(paramMaps));
outInfo.set("dataList", dataList);
outInfo = XLocalManager.call(outInfo);
} catch (Exception e) {
LogUtils.setDetailMsg(outInfo, e, "导入excel失败");
}
return outInfo;
}
/**
* 参数转换
*
* @param paramMaps
* @return
*/
private Map<String, String> convertParam(Map<String, String[]> paramMaps) {
if (MapUtils.isEmpty(paramMaps)) {
return new HashMap<>();
}
Map<String, String> paramMap = new HashMap<>();
for (Map.Entry<String, String[]> entry : paramMaps.entrySet()) {
paramMap.put(entry.getKey(), entry.getValue()[0]);
}
return paramMap;
}
}
package com.baosight.hpjx.common;
import com.baosight.hpjx.hp.sc.domain.HPSC002;
/**
* @author:songx
* @date:2022/9/23,14:51
*/
public enum DocRouteEnum {
HT("route_001", "HPSC002", "importData", HPSC002.class);
private String id;
private String serviceNme;
private String methodName;
private Class clazz;
<T> DocRouteEnum(String id, String serviceNme, String methodName, Class<T> clazz) {
this.id = id;
this.serviceNme = serviceNme;
this.methodName = methodName;
this.clazz = clazz;
}
/**
* 根据ID获取枚举
*
* @param id
* @return
*/
public static DocRouteEnum getById(String id) {
for (DocRouteEnum docRouteEnum : DocRouteEnum.values()) {
if (docRouteEnum.id.equals(id)) {
return docRouteEnum;
}
}
return null;
}
public String getId() {
return id;
}
public String getServiceNme() {
return serviceNme;
}
public String getMethodName() {
return methodName;
}
public Class getClazz() {
return clazz;
}
}
package com.baosight.hpjx.common;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @author:songx
* @date:2021/3/20,21:38
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelAnno {
/**
* 列索引
*
* @return
*/
int index() default 0;
/**
* 列名
*
* @return
*/
String name() default "";
}
package com.baosight.hpjx.common;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @author:songx
* @date:2021/3/20,21:38
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelHeadAnon {
/**
* 列索引
*
* @return
*/
int index() default 0;
/**
* 必须与属性名保持一致,否则会获取不到数据
*
* @return
*/
String field() default "";
/**
* 列的中文名
*
* @return
*/
String name() default "";
}
package com.baosight.hpjx.hp.sc.domain;
import com.baosight.hpjx.common.ExcelAnno;
import com.baosight.iplat4j.core.util.NumberUtils;
import java.math.BigDecimal;
import com.baosight.iplat4j.core.ei.EiColumn;
......@@ -119,15 +120,22 @@ public class HPSC002 extends DaoEPBase {
private String leaf = "1"; /* 是否有叶子节点*/
private String sort = " "; /* 排序字段*/
private String icon = " "; /* 图片地址*/
@ExcelAnno(index = 0)
private Integer prdtType; /* 产品类型*/
private String prdtCode = " "; /* 产品编码*/
@ExcelAnno(index = 1)
private String prdtName = " "; /* 产品名称*/
@ExcelAnno(index = 2)
private BigDecimal length = new BigDecimal("0"); /* 长*/
@ExcelAnno(index = 3)
private BigDecimal width = new BigDecimal("0"); /* 宽*/
@ExcelAnno(index = 4)
private BigDecimal thick = new BigDecimal("0"); /* 厚*/
private Long inventRecordId; /* 项目档案ID*/
private String spec = " "; /* 规格*/
@ExcelAnno(index = 6)
private BigDecimal num = new BigDecimal(0.000); /* 数量*/
@ExcelAnno(index = 7)
private BigDecimal unitWt = new BigDecimal(0.000); /* 单重*/
private BigDecimal totalWt = new BigDecimal(0.000); /* 总重*/
private String filePath1 = " "; /* 文件地址1*/
......@@ -143,6 +151,7 @@ public class HPSC002 extends DaoEPBase {
private String updatedBy = " "; /* 更新人*/
private String updatedName = " "; /* 修改人名称*/
private String updatedTime = " "; /* 更新时间*/
@ExcelAnno(index = 5)
private String remark = " "; /* 备注*/
private String pgStatus = " "; /* 派工状态*/
......
......@@ -743,6 +743,38 @@ public class ServiceHPSC002 extends ServiceBase {
}
public EiInfo importData(EiInfo inInfo) {
try {
List<HPSC002> dataList = (List) inInfo.get("dataList");
HashMap params = (HashMap) inInfo.get("params");
String parentId = (String) params.get("parentId");
String projCode = (String) params.get("projCode");
String projName = (String) params.get("projName");
String parentPrdtName = (String) params.get("parentPrdtName");
// 写入数据
for (HPSC002 hpsc002:dataList) {
/*BigDecimal num = hpsc002.getNum();
BigDecimal unitWt = hpsc002.getUnitWt();
DecimalFormat decimalFormat = new DecimalFormat("#.000");
BigDecimal totalWt = new BigDecimal(decimalFormat.format(num.multiply(unitWt).floatValue()));
hpsc002.setDelStatus(CommonConstant.YesNo.NO_0.intValue());
hpsc002.setTotalWt(totalWt);*/
hpsc002.setParentId(parentId);
hpsc002.setProjCode(projCode);
hpsc002.setProjName(projName);
hpsc002.setParentPrdtName(parentPrdtName);
hpsc002.setStatus(CommonConstant.YesNo.NO_0.intValue());
add(hpsc002);
}
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + dataList.size() + "]条数据保存成功!");
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "保存失败");
}
return inInfo;
}
/**
* 部件类型下拉框
* @param inInfo 形参
......
package com.baosight.hpjx.hp.sc.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceBase;
/**
*
*/
public class ServiceHPSC097 extends ServiceBase {
/**
* 画面初始化.
*/
@OperationLogAnnotation(operModul = "附件上传",operType = "查询",operDesc = "初始化")
public EiInfo initLoad(EiInfo inInfo) {
return inInfo;
}
/**
* 附件上传.
*/
@OperationLogAnnotation(operModul = "附件上传",operType = "上传",operDesc = "附件上传")
public EiInfo form(EiInfo inInfo) {
return inInfo;
}
}
package com.baosight.hpjx.util;
import com.baosight.hpjx.common.ExcelAnno;
import com.baosight.hpjx.common.ExcelHeadAnon;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
/**
* @author:songx
* @date:2021/3/20,21:22
*/
@Slf4j
public class DocExcelUtils {
/**
* 读取excel反射实体
*
* @param file MultipartFile
* @param startRow 起始行
* @param clazz entity
* @return
* @throws RuntimeException
*/
public static <T extends Object> List<T> readExcel(MultipartFile file, Integer startRow, Class<T> clazz)
throws Exception {
// 得到一个工作表
Sheet sheet = getSheet(file);
return getRowData(sheet, startRow, clazz);
}
/**
* 读取excel内容
*
* @param sheet
* @param startRow 起始行
* @param clazz
* @param <T>
* @return
*/
private static <T> List<T> getRowData(Sheet sheet, Integer startRow, Class<T> clazz) throws Exception {
List<T> results = new ArrayList();
// 获取类所有属性
Field[] fields = clazz.getDeclaredFields();
// 获取行总数
int rows = sheet.getLastRowNum() + 1;
for (int i = (startRow == null ? 1 : startRow); i < rows; i++) {
// 获取excel行
Row row = sheet.getRow(i);
if (row == null || row.getCell(0) == null || row.getCell(1) == null) {
continue;
}
// 创建实体
T obj = clazz.newInstance();
for (Field f : fields) {
// 设置属性可访问
f.setAccessible(true);
// 判断是否是注解
if (f.isAnnotationPresent(ExcelAnno.class)) {
// 获取注解
ExcelAnno excelAnno = f.getAnnotation(ExcelAnno.class);
// 获取列索引
int columnIndex = excelAnno.index();
// 获取单元格
Cell cell = row.getCell(columnIndex);
// 设置属性
setFieldValue(obj, f, cell);
}
}
// 添加到集合中
results.add(obj);
}
return results;
}
/**
* 绑定实体值
*
* @param obj Object
* @param f Field
* @param cell Cell
* @return
* @throws RuntimeException
*/
private static void setFieldValue(Object obj, Field f, Cell cell) throws IOException {
if (cell == null) {
return;
}
cell.setCellType(Cell.CELL_TYPE_STRING);
String cellValue = cell.getStringCellValue();
if (cellValue.equals("3-零件")) {
cellValue = "3";
}
if (cellValue.equals("4-部件")) {
cellValue = "4";
}
if (cellValue.equals("2-耗材")) {
cellValue = "2";
}
try {
if (StringUtils.isBlank(cellValue)) {
f.set(obj, f.getType() == String.class ? cellValue : null);
return;
}
if (f.getType() == byte.class || f.getType() == Byte.class) {
f.set(obj, Byte.parseByte(cellValue));
} else if (f.getType() == int.class || f.getType() == Integer.class) {
f.set(obj, Integer.parseInt(cellValue));
} else if (f.getType() == Double.class || f.getType() == double.class) {
f.set(obj, Double.parseDouble(cellValue));
} else if (f.getType() == BigDecimal.class) {
f.set(obj, new BigDecimal(cellValue));
} else {
f.set(obj, cellValue);
}
} catch (Exception e) {
String msg = String.format("读取数据值失败,名称[%s],数值[%s],%s", f.getName(), cellValue, e.getMessage());
log.error(msg, e);
throw new IOException(msg);
}
}
/**
* 工作簿处理
*
* @param file
*/
private static Sheet getSheet(MultipartFile file) throws IOException {
Workbook workbook;
try (InputStream is = file.getInputStream()) {
// 根据excel文件版本获取工作簿
if (file.getOriginalFilename().endsWith(".xls")) {
workbook = new HSSFWorkbook(is);
} else if (file.getOriginalFilename().endsWith(".xlsx")) {
workbook = new XSSFWorkbook(is);
} else {
throw new RuntimeException("非excel文件");
}
// 得到一个工作表
return workbook.getSheetAt(0);
} catch (IOException e) {
throw e;
}
}
/**
* 导出Excel
*
* @param sheetName 要导出的excel名称
* @param dataList 要导出的数据集合
* @param clazz if dataList is Map, clazz must be null
* @param <T>
*/
public static <T> HSSFWorkbook export(String sheetName, List<T> dataList, Class<T> clazz) throws Exception {
// 设置默认文件名为当前时间:年月日时分秒
if (StringUtils.isBlank(sheetName)) {
sheetName = "sheet1";
}
//创建一个WorkBook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
//在Workbook中,创建一个sheet,对应Excel中的工作薄(sheet)
HSSFSheet sheet = wb.createSheet(sheetName);
//创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
//创建一个居中格式
style.setAlignment(HorizontalAlignment.CENTER);
//style.setAlignment(CellStyle.ALIGN_CENTER);
// 获取excel标题
LinkedHashMap<String, String> fieldMap = clazz == null ? getFieldMap(dataList) : getFieldMap(clazz);
// 填充工作表
fillSheet(sheet, dataList, fieldMap, style);
return wb;
}
/**
* 获取field头
*
* @param dataList
* @param <T>
* @return
*/
private static <T> LinkedHashMap<String, String> getFieldMap(List<T> dataList) {
LinkedHashMap<String, String> resultMap = new LinkedHashMap();
if (CollectionUtils.isEmpty(dataList)) {
return resultMap;
}
Map<String, Object> dataMap = (Map<String, Object>) dataList.get(0);
for (String key : dataMap.keySet()) {
resultMap.put(key, key);
}
return resultMap;
}
/**
* 获取field头
*
* @param clazz
* @return
*/
private static <T> LinkedHashMap<String, String> getFieldMap(Class<T> clazz) {
LinkedHashMap<String, String> resultMap = new LinkedHashMap();
if (clazz == null) {
return resultMap;
}
Field[] fields = clazz.getDeclaredFields();
List<ExcelHeadAnon> excelHeadAnons = new ArrayList<>();
for (Field f : fields) {
// 设置属性可访问
f.setAccessible(true);
// 判断是否是注解
if (f.isAnnotationPresent(ExcelHeadAnon.class)) {
excelHeadAnons.add(f.getAnnotation(ExcelHeadAnon.class));
}
}
// 从小到大正序排
excelHeadAnons.sort(Comparator.comparing(ExcelHeadAnon::index));
for (ExcelHeadAnon excelHeadAnon : excelHeadAnons) {
resultMap.put(excelHeadAnon.field(), excelHeadAnon.name());
}
return resultMap;
}
/**
* 根据字段名获取字段对象
*
* @param fieldName 字段名
* @param clazz 包含该字段的类
* @return 字段
*/
public static Field getFieldByName(String fieldName, Class<?> clazz) {
// 拿到本类的所有字段
Field[] selfFields = clazz.getDeclaredFields();
// 如果本类中存在该字段,则返回
for (Field field : selfFields) {
//如果本类中存在该字段,则返回
if (field.getName().equals(fieldName)) {
return field;
}
}
// 否则,查看父类中是否存在此字段,如果有则返回
Class<?> superClazz = clazz.getSuperclass();
if (superClazz != null && superClazz != Object.class) {
// 递归
return getFieldByName(fieldName, superClazz);
}
// 如果本类和父类都没有,则返回空
return null;
}
/**
* 根据字段名获取字段值
*
* @param fieldName 字段名
* @param o 对象
* @return 字段值
* @throws Exception 异常
*/
public static Object getFieldValueByName(String fieldName, Object o) throws Exception {
Object value = null;
//根据字段名得到字段对象
Field field = getFieldByName(fieldName, o.getClass());
//如果该字段存在,则取出该字段的值
if (field != null) {
field.setAccessible(true);//类中的成员变量为private,在类外边使用属性值,故必须进行此操作
value = field.get(o);//获取当前对象中当前Field的value
} else {
throw new IllegalArgumentException(o.getClass().getSimpleName() + "类不存在字段名 "
+ fieldName);
}
return value;
}
/**
* 根据带路径或不带路径的属性名获取属性值,即接受简单属性名,
* 如userName等,又接受带路径的属性名,如student.department.name等
*
* @param fieldNameSequence 带路径的属性名或简单属性名
* @param o 对象
* @return 属性值
*/
public static Object getFieldValueByNameSequence(String fieldNameSequence, Object o) throws Exception {
Object value = null;
// 将fieldNameSequence进行拆分
String[] attributes = fieldNameSequence.split("\\.");
if (o instanceof Map) {
value = ((Map) o).get(fieldNameSequence);
} else if (attributes.length == 1) {
value = getFieldValueByName(fieldNameSequence, o);
} else {
// 根据数组中第一个连接属性名获取连接属性对象,如student.department.name
Object fieldObj = getFieldValueByName(attributes[0], o);
//截取除第一个属性名之后的路径
String subFieldNameSequence = fieldNameSequence
.substring(fieldNameSequence.indexOf(".") + 1);
//递归得到最终的属性对象的值
value = getFieldValueByNameSequence(subFieldNameSequence, fieldObj);
}
return value;
}
/**
* 向工作表中填充数据
*
* @param sheet excel的工作表名称
* @param dataList 数据源
* @param fieldMap 中英文字段对应关系的Map
* @param style 表格中的格式
* @throws Exception 异常
*/
public static <T> void fillSheet(HSSFSheet sheet, List<T> dataList, LinkedHashMap<String, String> fieldMap,
HSSFCellStyle style) throws Exception {
// 定义存放英文字段名和中文字段名的数组
String[] enFields = new String[fieldMap.size()];
String[] cnFields = new String[fieldMap.size()];
// 填充数组
int count = 0;
for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
enFields[count] = entry.getKey();
cnFields[count] = entry.getValue();
count++;
}
//在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 填充表头
for (int i = 0; i < cnFields.length; i++) {
HSSFCell cell = row.createCell(i);
cell.setCellValue(cnFields[i]);
cell.setCellStyle(style);
sheet.autoSizeColumn(i);
}
// 填充内容
for (int index = 0; index < dataList.size(); index++) {
row = sheet.createRow(index + 1);
// 获取单个对象
T item = dataList.get(index);
for (int i = 0; i < enFields.length; i++) {
Object objValue = getFieldValueByNameSequence(enFields[i], item);
String fieldValue = convertValue(objValue);
row.createCell(i).setCellValue(fieldValue);
}
}
}
/**
* 转换值
*
* @param objValue
* @return
*/
private static String convertValue(Object objValue) {
if (objValue == null) {
return "";
}
if (objValue instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(objValue);
}
return objValue.toString();
}
//
// /**
// * 创建独立下拉框
// *
// * @param workbook 工作簿
// * @param targetSheet 目标sheet
// * @param options 下拉框值(key-value)
// * @param column 下拉框所在的列索引(0开始)
// * @param sheetIndex sheet也索引(0开始)
// * @author lanheng
// * 2019-05-27 15:32:35
// */
// public static void addValidationToSheet(Workbook workbook, Sheet targetSheet, List<String> options, int column,
// int sheetIndex) {
// String sheetName = "hidden" + sheetIndex;
// Sheet optionsSheet = workbook.createSheet(sheetName);
// String nameName = sheetName + "_parent";
//
// int rowIndex = 0;
// for (String option : options) {
// Row row = optionsSheet.createRow(rowIndex);
// Cell cell = row.createCell(0);
// cell.setCellValue(option);
// rowIndex++;
// }
//
// // 将码值sheet页做成excel公式
// Name namedCell = workbook.createName();
// namedCell.setNameName(nameName);
// namedCell.setRefersToFormula(sheetName + "!$A$1:$A$" + (options.size() > 0 ? options.size() : 1));
//
// if (optionsSheet instanceof HSSFSheet) {
// DVConstraint constraint = DVConstraint.createFormulaListConstraint(nameName);
// CellRangeAddressList regions = new CellRangeAddressList(0, 65535, column, column);
// targetSheet.addValidationData(new HSSFDataValidation(regions, constraint));
// } else if (optionsSheet instanceof XSSFSheet) {
// XSSFDataValidationConstraint constraint = new XSSFDataValidationConstraint(
// DataValidationConstraint.ValidationType.LIST, nameName);
// // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
// CellRangeAddressList regions = new CellRangeAddressList(0, 100, column, column);
// // 数据有效性对象
// DataValidationHelper help = new XSSFDataValidationHelper((XSSFSheet) optionsSheet);
// DataValidation validation = help.createValidation(constraint, regions);
// targetSheet.addValidationData(validation);
// } else if (optionsSheet instanceof SXSSFSheet) {
// DataValidationHelper help = optionsSheet.getDataValidationHelper();
// DataValidationConstraint constraint = help.createFormulaListConstraint(nameName);
// CellRangeAddressList regions = new CellRangeAddressList(0, 65535, column, column);
// DataValidation validation = help.createValidation(constraint, regions);
// targetSheet.addValidationData(validation);
// }
// workbook.setSheetHidden(sheetIndex, true);
// }
//
}
......@@ -383,11 +383,30 @@ $(function () {
});
e.preventDefault();
} else {
openFileWindow.open();
//uploadFileWindow.open();
var parentId = IPLATUI.EFTree.materialTree.selectTreeNode.nodeId;
var parentPrdtName = IPLATUI.EFTree.materialTree.selectTreeNode.prdtName;
var projCode = IPLATUI.EFTree.materialTree.selectTreeNode.projCode;
var projName = IPLATUI.EFTree.materialTree.selectTreeNode.projName;
var lv = IPLATUI.EFTree.materialTree.selectTreeNode.lv;
JSColorbox.open({
href: "HPSC097?methodName=initLoad&inqu_status-0-parentId=" + parentId+"&inqu_status-0-projCode="+projCode+"&inqu_status-0-projName="+projName+"&inqu_status-0-parentPrdtName="+parentPrdtName,
title: "<div style='text-align: center;'>导入</div>",
width: "70%",
height: "70%",
callbackName: function () {
// 刷新列表
resultGrid.dataSource.page(1);
// 刷新树
updateTree();
// 关闭弹窗
JSColorbox.close();
}
});
}
}
});
IPLATUI.EFUpload = {
/* IPLATUI.EFUpload = {
fileUpload: {
showFileList: false,
upload: function (e) {
......@@ -399,10 +418,12 @@ $(function () {
var src;
var className;
if ("run" == projectEnv) {
src = e.response.docUrl + e.response.docType
//src = e.response.docUrl + e.response.docType
src = downloadHref(e.response.docId) + e.response.docType
className = e.response.groupId;
} else {
src = e.response.docUrl
//src = downloadHref(e.response.docId) + '.' + e.response.docUrl.split(".")[1];
className = e.response.docTag;
}
var parentId = IPLATUI.EFTree.materialTree.selectTreeNode.nodeId;
......@@ -442,13 +463,14 @@ $(function () {
IPLAT.NotificationUtil('导入失败!', "error");// 失败提示信息
}
}
}
}*/
$("#DOWNLOAD").on("click", function (e) {
var href = ctx + "\\HP\\template\\SC\\HPSC002_物料清单.xls";
window.location.href = href;
});
/**
* 生成模板
*/
......
......@@ -88,7 +88,7 @@
</div>
</div>
<%-- EEDM8010页面加载时,不会加载EEDM6000 (lazyload="true") --%>
<EF:EFWindow id="uploadFile" url="${ctx}/web/HPSC099" lazyload="true" refresh="true">
<%-- <EF:EFWindow id="uploadFile" url="${ctx}/web/HPSC099" lazyload="true" refresh="true">
</EF:EFWindow>
<EF:EFWindow id="openFile">
<EF:EFRegion id="upload" title="文件导入区">
......@@ -96,7 +96,15 @@
<EF:EFUpload ename="fileUpload" cname="导入" docTag="HPSC002" path="upload"/>
</EF:EFRegion>
</EF:EFWindow>
<EF:EFWindow id="openFile">
<EF:EFRegion id="upload" title="文件导入区">
<div id="button"></div>
<EF:EFInput cname="上传文件" blockId="inqu_status" ename="file" row="0" type="file" colWidth="3"/>
</EF:EFRegion>
</EF:EFWindow>--%>
<EF:EFWindow id="uploadFile" url="${ctx}/web/HPSC097" lazyload="true" refresh="true"/>
</EF:EFPage>
<script>
let ctx="${ctx}";
</script>
......
$(function () {
/* IPLATUI.EFUpload = {
uploadFile: {
success: function(e) {
let docId = e.response.docId;
if (isBlank(docId)) {
return;
}
$("#fileDocId").val(docId);
NotificationUtil("附件上传成功");
console.log($("#fileDocId").val())
saveTemp(e);
try {
parent.JSColorbox.setValueCallback(docId);
} catch (e){
}
},
}
};*/
// 提交
$("#upload").on("click", upload);
function saveTemp(e) {
let docId = e.response.docId;
let docName = e.response.docName;
let docSize = e.response.docSize;
let docTag = e.response.docTag;
let docUrl = e.response.docUrl;
let result = new EiInfo();
result.set("result-0-docId",docId);
result.set("result-0-docName",docName);
result.set("result-0-docSize",docSize);
result.set("result-0-docTag",docTag);
result.set("result-0-realPath",docUrl);
result.set("result-0-bizType",$("#inqu_status-0-bizType").val());
result.set("result-0-matId",$("#inqu_status-0-matId").val());
EiCommunicator.send("HPDS002", "insert", result, {
onSuccess: function (ei) {
if (ei.getStatus() >= 0) {
if (ei.getStatus() == 0) {
NotificationUtil(ei, 'warning');
} else {
NotificationUtil(ei);
}
} else {
NotificationUtil(ei, "error");
}
},
onFail: function (ei) {
// 发生异常
NotificationUtil("操作失败,原因[" + ei + "]", "error");
}
});
}
});
/**
* 上传文件
*/
let upload = function () {
let file = $("#inqu_status-0-file").val();
if(isBlank(file)){
message("请选择文件");
return;
}
/* let orderTypeCode = $("#inqu_status-0-orderTypeCode").val();
if(isBlank(orderTypeCode)){
message("请选择类别");
return;
}*/
let parentId = $("#inqu_status-0-parentId").val();
let projCode = $("#inqu_status-0-projCode").val();
let projName = $("#inqu_status-0-projName").val();
let parentPrdtName = $("#inqu_status-0-parentPrdtName").val();
let _IPLAT = IPLAT;
_IPLAT.progress($("body"), true);
let formData = new FormData();
formData.append("id", "route_001");
formData.append("startRow", "1"); // 第几行开始读取
formData.append("parentId", parentId);
formData.append("projCode", projCode);
formData.append("projName", projName);
formData.append("parentPrdtName", parentPrdtName);
/* formData.append("orderTypeCode", orderTypeCode);*/
formData.append("file", $("#inqu_status-0-file")[0].files[0]);
$.ajax({
url: IPLATUI.CONTEXT_PATH + '/doc/import/api',
type: 'POST',
// dataType: 'json',
data: formData,
async: true,
cache: false,
contentType: false,
processData: false,
success: function (res) {
_IPLAT.progress($("body"), false);
parent.JSColorbox.setValueCallback();
},
error: function (res) {
message(res.msg);
_IPLAT.progress($("body"), false);
}
});
}
<!DOCTYPE html>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="EF" tagdir="/WEB-INF/tags/EF" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<EF:EFPage title="附件上传">
<EF:EFInput ename="inqu_status-0-parentId" cname="父Id" type="hidden"/>
<EF:EFInput ename="inqu_status-0-projCode" cname="项目代码" type="hidden"/>
<EF:EFInput ename="inqu_status-0-projName" cname="项目名称" type="hidden"/>
<EF:EFInput ename="inqu_status-0-parentPrdtName" cname="项目部件名称" type="hidden"/>
<EF:EFInput cname="上传文件" blockId="inqu_status" ename="file" row="0" type="file" colWidth="4"/>
<button id="upload" type="submit">提交</button>
</EF:EFPage>
<script src="${ctx}/HP/SC/HPSC097.js"></script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment