Commit 762c272d by 宋祥

1.增加公共的导入模块

parent 774ca0af
package com.baosight.hggp.aspect.annotation;
import com.baosight.hggp.aspect.domain.TCPReceive;
import com.baosight.hggp.controller.DocController;
import com.baosight.iplat4j.core.web.controller.WebDispatchController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
package com.baosight.hggp.aspect.annotation;
package com.baosight.hggp.controller;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.core.enums.DocRouteEnum;
import com.baosight.hggp.util.DocExcelUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.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.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
......@@ -20,10 +21,11 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baosight.hggp.common.DocRouteEnum;
/**
* DOC 接口类
*
......@@ -35,7 +37,7 @@ import com.baosight.hggp.common.DocRouteEnum;
@RequestMapping("/doc")
public class DocController extends WebDispatchController {
private final static Logger logger = LoggerFactory.getLogger(DocController.class);
private final static Logger log = LoggerFactory.getLogger(DocController.class);
/**
* 批量导入
......@@ -53,29 +55,28 @@ public class DocController extends WebDispatchController {
outInfo.setMsg("导入文件不能为空");
return outInfo;
}
Map<String, String> params = this.convertParam(paramMaps);
Map<String, Object> params = this.convertParam(paramMaps);
String id = request.getParameter("id");
DocRouteEnum docRouteEnum = DocRouteEnum.getById(id);
if (params.get("fileName").contains("HGSC004A")){
if (MapUtils.getString(params, "fileName").contains("HGSC004A")) {
docRouteEnum = DocRouteEnum.getById("route_001");
}else if (params.get("fileName").contains("HGSC009A")){
} else if (params.get("fileName").toString().contains("HGSC009A")) {
docRouteEnum = DocRouteEnum.getById("route_002");
}else if (params.get("fileName").contains("HGPZ005")){
} else if (params.get("fileName").toString().contains("HGPZ005")) {
docRouteEnum = DocRouteEnum.getById("route_003");
}
if (docRouteEnum == null) {
outInfo.setMsg("导入标识ID不存在");
return outInfo;
}
String startRow = request.getParameter("startRow");
List dataList = DocExcelUtils.readExcel(file, NumberUtils.createInteger(startRow), docRouteEnum.getClazz());
List dataList = DocExcelUtils.readExcel(file, docRouteEnum.getStartRow(), 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("params", params);
outInfo.set("dataList", dataList);
outInfo = XLocalManager.call(outInfo);
} catch (Exception e) {
......@@ -90,15 +91,42 @@ public class DocController extends WebDispatchController {
* @param paramMaps
* @return
*/
private Map<String, String> convertParam(Map<String, String[]> paramMaps) {
private Map<String, Object> convertParam(Map<String, String[]> paramMaps) {
if (MapUtils.isEmpty(paramMaps)) {
return new HashMap<>();
}
Map<String, String> paramMap = new HashMap<>();
Map<String, Object> paramMap = new HashMap<>();
for (Map.Entry<String, String[]> entry : paramMaps.entrySet()) {
paramMap.put(entry.getKey(), entry.getValue()[0]);
String key = entry.getKey();
String value = entry.getValue()[0];
if ("parameter".equals(key)) {
paramMap.put(key, encodeParam(value));
} else {
paramMap.put(key, value);
}
}
return paramMap;
}
/**
* 解码参数
*
* @param parameter
* @return
*/
private Map<String, Object> encodeParam(String parameter) {
try {
if (StringUtils.isBlank(parameter)) {
return null;
}
// 帆软传递进来的参数进行了两次编码,因此需要进行两次解码
String paramsText = URLDecoder.decode(parameter, "UTF-8");
paramsText = URLDecoder.decode(paramsText, "UTF-8");
return JSONObject.parseObject(paramsText).getInnerMap();
} catch (Exception e) {
log.error("字符串解码:{}", e.getMessage(), e);
throw new PlatException("参数格式错误,解码失败");
}
}
}
package com.baosight.hggp.common;
package com.baosight.hggp.core.enums;
import com.baosight.hggp.hg.cw.domain.HGCW003;
import com.baosight.hggp.hg.pz.domain.HGPZ005;
import com.baosight.hggp.hg.sc.domain.HGSC004A;
import com.baosight.hggp.hg.sc.domain.HGSC009;
import com.baosight.hggp.hg.sc.domain.HGSC009A;
import com.baosight.hggp.hg.sj.domain.HGSJ003;
......@@ -13,20 +11,50 @@ import com.baosight.hggp.hg.sj.domain.HGSJ003;
* @date:2022/9/23,14:51
*/
public enum DocRouteEnum {
HGSC004A("route_001", "HGSC004A", "importData", HGSC004A.class),
HGSC009A("route_002", "HGSC009", "importData", HGSC009A.class),
HGPZ005("route_003", "HGPZ005", "importData", HGPZ005.class),
HGCW003("route_004", "HGCW003", "importData", HGCW003.class),
HGSJ003("route_005", "HGSJ003", "importData", HGSJ003.class),
HGSC004A("route_001", "", 1, "HGSC004A", "importData", HGSC004A.class),
HGSC009A("route_002", "", 1, "HGSC009", "importData", HGSC009A.class),
HGPZ005("route_003", "", 1, "HGPZ005", "importData", HGPZ005.class),
HGCW003("route_004", "", 1, "HGCW003", "importData", HGCW003.class),
HGSJ003("route_005", "", 1, "HGSJ003", "importData", HGSJ003.class),
;
/**
* 唯一标识
*/
private String id;
/**
* 模版文件的地址,模版文件路径必须在META-INF.resources下面
*/
private String templateUrl;
/**
* 数据从excel的第几行开始,起始0
*/
private int startRow;
/**
* 业务处理类
*/
private String serviceNme;
/**
* 业务处理方法
*/
private String methodName;
/**
* 数据转换后的实体类
*/
private Class clazz;
<T> DocRouteEnum(String id, String serviceNme, String methodName, Class<T> clazz) {
<T> DocRouteEnum(String id, String templateUrl, int startRow, String serviceNme, String methodName,
Class<T> clazz) {
this.id = id;
this.templateUrl = templateUrl;
this.startRow = startRow;
this.serviceNme = serviceNme;
this.methodName = methodName;
this.clazz = clazz;
......@@ -51,6 +79,14 @@ public enum DocRouteEnum {
return id;
}
public String getTemplateUrl() {
return templateUrl;
}
public int getStartRow() {
return startRow;
}
public String getServiceNme() {
return serviceNme;
}
......
package com.baosight.hggp.hg.dm.service;
import com.baosight.hggp.core.enums.DocRouteEnum;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import java.util.Map;
/**
* 文件导入
*
* @author:songx
* @date:2024/4/7,17:02
*/
public class ServiceHGDM91 extends ServiceEPBase {
/**
* 初始化
*
* @param inInfo
* @return
*/
@Override
public EiInfo initLoad(EiInfo inInfo) {
try {
Map queryRow = EiInfoUtils.getFirstRow(inInfo);
setTemplateUrl(queryRow);
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "初始化失败");
}
return inInfo;
}
/**
* 根据路由获取模版地址
*
* @param queryRow
* @return
*/
private void setTemplateUrl(Map queryRow) {
String templateUrl = "";
String id = MapUtils.getString(queryRow, "id");
if (StringUtils.isNotBlank(id)) {
DocRouteEnum docRouteEnum = DocRouteEnum.getById(id);
templateUrl = docRouteEnum == null ? "" : docRouteEnum.getTemplateUrl();
}
queryRow.put("templateUrl", templateUrl);
}
}
$(function () {
// 提交
$("#SUBMIT").on("click", submit);
});
/**
* 页面加载时执行
*/
$(window).load(function () {
// 显示下载模版按钮
let templateUrl = $("#inqu_status-0-templateUrl").val();
if (!isBlank(templateUrl)) {
$("#templateUrl").attr('href', IPLATUI.CONTEXT_PATH + templateUrl);
$("#templateDiv").show();
}
});
/**
* 提交
*/
let submit = function () {
let file = $("#inqu_status-0-file")[0].files[0];
if (isBlank(file)) {
message("请选择文件");
return;
}
var suffix = file.name.substr(file.name.lastIndexOf("."));
if (".xls" != suffix && ".xlsx" != suffix) {
message("请选择Excel格式的文件导入");
return false;
}
let _IPLAT = IPLAT;
_IPLAT.progress($("body"), true);
let formData = new FormData();
formData.append("id", $("#inqu_status-0-id").val());
formData.append("parameter", $("#inqu_status-0-parameter").val());
formData.append("file", file);
$.ajax({
url: IPLATUI.CONTEXT_PATH + '/doc/import/api',
type: 'POST',
data: formData,
async: true,
cache: false,
contentType: false,
processData: false,
success: function (res) {
_IPLAT.progress($("body"), false);
message(res.msg);
if (res.status != -1) {
parent.JSColorbox.setValueCallback(res);
}
},
error: function (res) {
_IPLAT.progress($("body"), false);
message(res.msg);
}
});
}
/**
* 判断是否为null
*
* @param value
* @returns {boolean}
*/
function isBlank(data) {
return data == null || data === undefined || data === 'null' || $.trim(data) === '' ||
data === 'undefined' || data === 'unknown';
}
/**
* 消息提示
*
* @param msg
*/
function message(msg) {
WindowUtil({
title: "提示:",
content: "<div class='kendo-del-message'>" + msg + "</div>"
});
};
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="EF" tagdir="/WEB-INF/tags/EF" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<EF:EFPage title="导入">
<EF:EFRegion id="inqu" title="文件区域">
<div class="row">
<EF:EFInput cname="参数" blockId="inqu_status" ename="parameter" row="0" colWidth="12" type="hidden"/>
<EF:EFInput cname="路由ID" blockId="inqu_status" ename="id" row="0" colWidth="12" type="hidden"/>
<EF:EFInput cname="模版地址" blockId="inqu_status" ename="templateUrl" row="0" colWidth="12" type="hidden"/>
<EF:EFInput cname="导入文件" blockId="inqu_status" ename="file" row="0" colWidth="12" ratio="2:10" type="file"/>
</div>
<div id="templateDiv" class="row" style="display: none;text-align: right;padding-right: 25px;">
<a id="templateUrl" href="">下载模版</a>
</div>
</EF:EFRegion>
<EF:EFRegion title="提示">
<span style='color: red;font-size: 12px;'>
1.请选择xls或xlsx格式的excel文件
</span>
</EF:EFRegion>
</EF:EFPage>
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