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;
}
}
......@@ -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