Commit 15b5c1d5 by 宋祥

Merge branch 'dev-sx' of ssh://10.70.33.7:32359/smart/hp-smart into dev

parents 01b19ca4 9b3bfac7
package com.baosight.hpjx.controller;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.hpjx.util.StringUtils;
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.XServiceManager;
import com.baosight.iplat4j.eu.dm.document.bos.s3.api.signed.SignedBosHelp;
import com.baosight.iplat4j.eu.dm.document.bos.s3.param.BosParamHelp;
import com.baosight.hpjx.util.FileUtils;
import com.google.common.base.Joiner;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
/**
* @author:songx
* @date:2024/3/14,14:26
*/
@Slf4j
@Controller
@CrossOrigin
@RequestMapping({"/file/download"})
public class FileDownloadController {
/**
* 更具docId下载文件
*
* @param docId
* @param request
* @param response
* @throws IOException
*/
@RequestMapping({"/{docId}"})
public void downloadUrl(@PathVariable String docId, HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/plain; charset=UTF-8");
try {
EiInfo queryDocMapInfo = new EiInfo();
queryDocMapInfo.set("docId", docId);
queryDocMapInfo.set(EiConstant.serviceId, "S_EU_0102");
EiInfo returnInfo = XServiceManager.call(queryDocMapInfo);
Map docMap = returnInfo.getMap("docMap");
String s3UrlPrefix = MapUtils.getString(docMap, "url");
String fileName = MapUtils.getString(docMap, "resCname");
String returnUrlPrefix = BosParamHelp.disposeUrl(s3UrlPrefix);
Map<String, String[]> parameterMap = request.getParameterMap();
String returnUrl = this.getReturnUrlByParam(parameterMap, returnUrlPrefix);
if (StringUtils.isBlank(returnUrl)) {
String seconds = request.getHeader("seconds");
if (StringUtils.isBlank(seconds)) {
seconds = request.getParameter("seconds");
}
returnUrl = this.buildReturnUrl(seconds, fileName, returnUrlPrefix, s3UrlPrefix);
}
// 下载文件
if (StringUtils.isNotBlank(returnUrl)) {
FileUtils.downloadUrlFile(returnUrl, fileName, response);
} else {
throw new PlatException("文件地址异常");
}
} catch (Exception e) {
String msg = String.format("下载文件【%s】失败!原因:%s", docId, LogUtils.getMsg(e));
response.getWriter().write(msg);
}
}
private String getReturnUrlByParam(Map<String, String[]> parameterMap, String returnUrl)
throws UnsupportedEncodingException {
String returnUrl2 = "";
Map<String, String> paramMap = this.getParamMap(parameterMap);
paramMap.remove("code");
paramMap.remove("access_token");
paramMap.remove("seconds");
if (!paramMap.isEmpty() && paramMap.containsKey("X-Amz-Signature")) {
String queryString = this.buildQueryString(paramMap);
returnUrl2 = returnUrl + "?" + queryString;
}
return returnUrl2;
}
private String buildReturnUrl(String seconds, String fileName, String returnUrlPrefix, String s3UrlPrefix)
throws Exception {
URL s3Url = SignedBosHelp.getDownloadTempUrl(s3UrlPrefix, fileName, seconds);
String s3UrlParam = StringUtils.defaultIfEmpty(s3Url.getQuery(), "");
String returnUrl = returnUrlPrefix + "?" + s3UrlParam;
return com.baosight.iplat4j.eu.dm.util.FileUtils.returnDocUrlByEncodeFileName(returnUrl);
}
private Map<String, String> getParamMap(Map<String, String[]> parameterMap) {
Map paramMap = new HashMap();
Set<String> parameterSet = parameterMap.keySet();
Iterator parameterIterator = parameterSet.iterator();
while (parameterIterator.hasNext()) {
String next = (String) parameterIterator.next();
String[] valueArray = (String[]) parameterMap.get(next);
if (valueArray != null && valueArray.length != 0) {
String value = Joiner.on(",").join(valueArray);
paramMap.put(next, value);
}
}
return paramMap;
}
private String buildQueryString(Map<String, String> parameterMap) throws UnsupportedEncodingException {
StringBuilder strBuilder = new StringBuilder();
String rcd = MapUtils.getString(parameterMap, "response-content-disposition");
parameterMap.remove("response-content-disposition");
String next;
for (Iterator iterator = parameterMap.keySet().iterator(); iterator.hasNext();
strBuilder.append(next).append("=").append((String) parameterMap.get(next))) {
next = (String) iterator.next();
if (strBuilder.length() > 0) {
strBuilder.append("&");
}
}
if (StringUtils.isNotBlank(rcd)) {
strBuilder.append("&").append("response-content-disposition").append("=").append(
URLEncoder.encode(rcd, "UTF-8"));
}
return strBuilder.toString();
}
}
......@@ -7,6 +7,20 @@ package com.baosight.hpjx.core.constant;
public class CommonConstant {
/**
* 环境变量
*
* @author:songx
* @date:2024/1/20,15:04
*/
public static class projectEnv {
// 开发环境
public static final String DEV = "dev";
// 正式环境
public static final String RUN = "run";
}
/**
* 是否
*
* @author:songx
......
......@@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class MyGenericFilterFilter extends GenericFilterBean {
public class MyGenericFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
......
package com.baosight.hpjx.core.oss;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.baosight.hpjx.util.StringUtils;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import lombok.extern.slf4j.Slf4j;
/**
* OSS凭证
*
* @author:songx
* @date:2023/8/28,11:26
*/
@Slf4j
public class OssClientUtils {
private OssClientUtils() {
}
/**
* 初始化配置信息(纯粹就打印日志而已,因为会加载该类的全局变量)
*/
public static void init() {
AmazonS3 s3Client = Instance.s3Client;
log.info("初始化OSS客户端完成:isReady -> {}", s3Client != null);
}
/**
* 获取S3客户端
*
* @return
*/
public static AmazonS3 getS3Client() {
return Instance.s3Client;
}
/**
* 刷新客户端
*/
public static void refresh() {
Instance.refresh();
}
/**
* 初始化Instance
*
* @author:songx
* @date:2022/4/2,9:58
*/
private static class Instance {
/**
* 客户端实例
*/
private static AmazonS3 s3Client = buildAmazonS3();
/**
* 刷新S3客户端
*/
private static void refresh() {
s3Client = buildAmazonS3();
log.info("刷新OSS客户端完成:isReady->{}", s3Client != null);
}
/**
* 获取AmazonS3Client实例
*
* @return
*/
private static synchronized AmazonS3 buildAmazonS3() {
String accessKey = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.accessKey");
String secretKey = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.secretKey");
String endpoint = PlatApplicationContext.getProperty("iplat4j.admin.objectStorage.s3.endpoint");
if (StringUtils.isBlank(accessKey) || StringUtils.isBlank(secretKey) || StringUtils.isBlank(endpoint)) {
return null;
}
AmazonS3ClientBuilder client = AmazonS3ClientBuilder.standard();
ClientConfiguration config = new ClientConfiguration();
config.setProtocol(com.amazonaws.Protocol.HTTPS);
config.setConnectionTimeout(10001);
config.setSignerOverride("S3SignerType");
client.setClientConfiguration(config);
client.setCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(accessKey, secretKey)));
String url = endpoint + ":" + 80;
client.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));
return client.build();
}
}
}
package com.baosight.hpjx.core.oss;
import com.amazonaws.services.s3.AmazonS3;
import com.baosight.hpjx.util.AssertUtils;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import java.io.File;
/**
* OSS工具类
*
* @author:songx
* @date:2023/8/28,11:25
*/
public class OssUtils {
// 桶名称
private static final String bucketName = PlatApplicationContext.getProperty(
"iplat4j.admin.objectStorage.s3.bucket");
/**
* 前端上传文件
*
* @param pageContext
* @return
* @throws Exception
*/
public static String uploadFile(PageContext pageContext) throws Exception {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
return null;
}
/**
* 上传文件
*
* @param key 默认不指定key的情况下,以文件内容的hash值作为文件名
* @param file
*/
public static void uploadFile(String key, File file) {
AmazonS3 client = OssClientUtils.getS3Client();
AssertUtils.isNull(client, "上传失败,OSS客户端未初始化,请检查");
client.putObject(bucketName, key, file);
}
}
package com.baosight.hpjx.hp.sc.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.hp.ds.domain.HPDS002;
import com.baosight.hpjx.hp.sc.domain.HPSC002;
import com.baosight.hpjx.hp.sc.domain.HPSC002A;
import com.baosight.hpjx.hp.sc.domain.HPSC006;
import com.baosight.hpjx.hp.zl.domain.HPZL001A;
import com.baosight.hpjx.util.EiInfoUtils;
import com.baosight.hpjx.util.FileUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.iplat4j.core.ProjectInfo;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
......@@ -68,7 +71,13 @@ public class ServiceHPSC002A extends ServiceEPBase {
@Override
public EiInfo query(EiInfo inInfo) {
try {
inInfo = super.query(inInfo, HPSC002A.QUERY, new HPSC002A());
// 项目环境
String projectEnv = ProjectInfo.getProjectEnv();
if (CommonConstant.projectEnv.RUN.equalsIgnoreCase(projectEnv)) {
inInfo = super.query(inInfo, "HPSC002A.queryRun", new HPSC002A());
} else {
inInfo = super.query(inInfo, "HPSC002A.queryDev", new HPSC002A());
}
} catch (Throwable e) {
LogUtils.setDetailMsg(inInfo, e, "查询失败");
}
......
package com.baosight.hpjx.hp.sc.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.hp.sc.domain.HPSC002;
import com.baosight.hpjx.hp.sc.domain.HPSC002A;
import com.baosight.hpjx.hp.sc.domain.HPSC002B;
import com.baosight.hpjx.hp.zl.domain.HPZL001A;
import com.baosight.hpjx.util.EiInfoUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.iplat4j.core.ProjectInfo;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
......@@ -57,7 +60,13 @@ public class ServiceHPSC002B extends ServiceEPBase {
@Override
public EiInfo query(EiInfo inInfo) {
try {
inInfo = super.query(inInfo, HPSC002B.QUERY, new HPSC002B());
// 项目环境
String projectEnv = ProjectInfo.getProjectEnv();
if (CommonConstant.projectEnv.RUN.equalsIgnoreCase(projectEnv)) {
inInfo = super.query(inInfo, "HPSC002B.queryRun", new HPSC002B());
} else {
inInfo = super.query(inInfo, "HPSC002B.queryDev", new HPSC002B());
}
} catch (Throwable e) {
LogUtils.setDetailMsg(inInfo, e, "查询失败");
}
......
......@@ -9,7 +9,6 @@
A.BIZ_TYPE as "bizType", <!-- 物料ID -->
A.MAT_ID as "matId", <!-- 物料ID -->
A.DOC_ID as "docId", <!-- 文件ID -->
B.DOC_NAME as "docName", <!-- 文件名称 -->
A.CREATED_BY as "createdBy", <!-- 创建人 -->
A.CREATED_NAME as "createdName", <!-- 创建人名称 -->
A.CREATED_TIME as "createdTime", <!-- 创建时间 -->
......@@ -18,6 +17,16 @@
A.UPDATED_TIME as "updatedTime" <!-- 修改时间 -->
</sql>
<sql id="columnDev">
<include refid="column"/>,
B.DOC_NAME as "docName" <!-- 文件名称 -->
</sql>
<sql id="columnRun">
<include refid="column"/>,
B.RES_CNAME as "docName" <!-- 文件名称 -->
</sql>
<sql id="condition">
<isNotEmpty prepend=" AND " property="id">
A.ID = #id#
......@@ -37,10 +46,25 @@
<isNotEmpty prepend=" AND " property="docId">
A.DOC_ID = #docId#
</isNotEmpty>
</sql>
<!-- 开发环境 -->
<sql id="conditionDev">
AND A.DOC_ID = B.DOC_ID
<include refid="condition"/>
<isNotEmpty prepend=" AND " property="docName">
B.DOC_NAME LIKE CONCAT('%', #docName#, '%')
</isNotEmpty>
</sql>
</sql>
<!-- 正式环境 -->
<sql id="conditionRun">
AND A.DOC_ID = B.RES_ID
<include refid="condition"/>
<isNotEmpty prepend=" AND " property="docName">
B.RES_CNAME LIKE CONCAT('%', #docName#, '%')
</isNotEmpty>
</sql>
<sql id="customCondition">
<isNotEmpty prepend=" AND " property="createdDateFrom">
......@@ -62,21 +86,37 @@
</dynamic>
</sql>
<select id="query" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002A">
<select id="queryDev" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002A">
SELECT
<include refid="column"/>
FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM02 B
WHERE 1=1
AND A.DOC_ID = B.DOC_ID
<include refid="condition"/>
<include refid="conditionDev"/>
<include refid="customCondition"/>
<include refid="order"/>
</select>
<select id="count" resultClass="int">
<select id="countDev" resultClass="int">
SELECT COUNT(*) FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM02 B
WHERE 1=1
<include refid="condition"/>
<include refid="conditionDev"/>
<include refid="customCondition"/>
</select>
<select id="queryRun" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002A">
SELECT
<include refid="column"/>
FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM05 B
WHERE 1=1
<include refid="conditionRun"/>
<include refid="customCondition"/>
<include refid="order"/>
</select>
<select id="countRun" resultClass="int">
SELECT COUNT(*) FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM05 B
WHERE 1=1
<include refid="conditionRun"/>
<include refid="customCondition"/>
</select>
......
......@@ -9,7 +9,6 @@
A.BIZ_TYPE as "bizType", <!-- 物料ID -->
A.MAT_ID as "matId", <!-- 物料ID -->
A.DOC_ID as "docId", <!-- 文件ID -->
B.DOC_NAME as "docName", <!-- 文件名称 -->
A.CREATED_BY as "createdBy", <!-- 创建人 -->
A.CREATED_NAME as "createdName", <!-- 创建人名称 -->
A.CREATED_TIME as "createdTime", <!-- 创建时间 -->
......@@ -18,6 +17,16 @@
A.UPDATED_TIME as "updatedTime" <!-- 修改时间 -->
</sql>
<sql id="columnDev">
<include refid="column"/>,
B.DOC_NAME as "docName" <!-- 文件名称 -->
</sql>
<sql id="columnRun">
<include refid="column"/>,
B.RES_CNAME as "docName" <!-- 文件名称 -->
</sql>
<sql id="condition">
<isNotEmpty prepend=" AND " property="id">
A.ID = #id#
......@@ -55,11 +64,26 @@
<isNotEmpty prepend=" AND " property="updatedTime">
A.UPDATED_TIME = #updatedTime#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedTime">
B.DOC_NAME LIKE ('%$updatedTime$%')
</isNotEmpty>
</sql>
<!-- 开发环境 -->
<sql id="conditionDev">
AND A.DOC_ID = B.DOC_ID
<include refid="condition"/>
<isNotEmpty prepend=" AND " property="docName">
B.DOC_NAME LIKE CONCAT('%', #docName#, '%')
</isNotEmpty>
</sql>
<!-- 正式环境 -->
<sql id="conditionRun">
AND A.DOC_ID = B.RES_ID
<include refid="condition"/>
<isNotEmpty prepend=" AND " property="docName">
B.RES_CNAME LIKE CONCAT('%', #docName#, '%')
</isNotEmpty>
</sql>
<sql id="customCondition">
<isNotEmpty prepend=" AND " property="createdDateFrom">
A.CREATED_TIME &gt;= CONCAT(REPLACE(#depositDateFrom#, '-', ''), '000000')
......@@ -80,21 +104,37 @@
</dynamic>
</sql>
<select id="query" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002B">
<select id="queryDev" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002B">
SELECT
<include refid="column"/>
FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM02 B
WHERE 1=1
AND A.DOC_ID = B.DOC_ID
<include refid="condition"/>
<include refid="conditionDev"/>
<include refid="customCondition"/>
<include refid="order"/>
</select>
<select id="count" resultClass="int">
<select id="countDev" resultClass="int">
SELECT COUNT(*) FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM02 B
WHERE 1=1
<include refid="condition"/>
<include refid="conditionDev"/>
<include refid="customCondition"/>
</select>
<select id="queryRun" resultClass="com.baosight.hpjx.hp.sc.domain.HPSC002B">
SELECT
<include refid="column"/>
FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM05 B
WHERE 1=1
<include refid="conditionRun"/>
<include refid="customCondition"/>
<include refid="order"/>
</select>
<select id="countRun" resultClass="int">
SELECT COUNT(*) FROM ${hpjxSchema}.T_HPSC002A A, ${platSchema}.TEUDM05 B
WHERE 1=1
<include refid="conditionRun"/>
<include refid="customCondition"/>
</select>
......
......@@ -64,7 +64,7 @@ public class ServiceHPZL001A extends ServiceEPBase {
try {
// 项目环境
String projectEnv = ProjectInfo.getProjectEnv();
if ("run".equalsIgnoreCase(projectEnv)) {
if (CommonConstant.projectEnv.RUN.equalsIgnoreCase(projectEnv)) {
inInfo = super.query(inInfo, "HPZL001A.queryRun", new HPZL001A());
} else {
inInfo = super.query(inInfo, "HPZL001A.queryDev", new HPZL001A());
......
......@@ -2,7 +2,9 @@ package com.baosight.hpjx.util;
import com.baosight.hpjx.core.constant.OSConstant;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
......@@ -14,6 +16,9 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DecimalFormat;
......@@ -25,12 +30,15 @@ import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
/**
* 文件工具类
*
* @author:songx
* @date:2016/3/26,11:54
*/
@Slf4j
public class FileUtils extends org.apache.commons.io.FileUtils {
/**
......@@ -454,4 +462,48 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
}
}
/**
* InputStream
*
* @param url
*/
public static InputStream downloadStreamFromUrl(String url) throws IOException {
URL httpUrl = new URL(url);
return httpUrl.openStream();
}
/**
* 下载文件到前端
*
* @param url
* @param fileName
* @param response
*/
public static void downloadUrlFile(String url, String fileName, HttpServletResponse response) throws IOException {
// 设置响应类型,图片和PDF直接预览
if ("jpg/jpeg/png/bmp/gif/tif/icon/ico".contains(
fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase())) {
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/jpeg");
} else {
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(fileName, "UTF-8"));
}
try (InputStream is = downloadStreamFromUrl(url);
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
byte[] buffer = new byte[1024];
while (true) {
int len = is.read(buffer);
if (len == -1) {
break;
}
outputStream.write(buffer, 0, len);
}
outputStream.flush();
} catch (IOException e) {
throw e;
}
}
}
......@@ -72,7 +72,21 @@ public class LogUtils {
}
inInfo.setMsg(msg.concat(e.getMessage()));
}
/**
* 转换系统异常,业务异常
*
* @param e
* @return
*/
public static String getMsg(Throwable e) {
if (e instanceof PlatException) {
return e.getMessage();
} else {
return "服务异常,请稍后重试!";
}
}
/**
* 打印日志
*
......
......@@ -13,6 +13,7 @@ import com.baosight.hpjx.util.DateUtils;
import com.baosight.hpjx.util.EiInfoUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.hpjx.util.StringUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
......@@ -22,6 +23,10 @@ import com.baosight.iplat4j.ed.util.SequenceGenerator;
import com.baosight.xservices.xs.og.domain.XSOG01;
import com.baosight.xservices.xs.util.LoginUserDetails;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -97,8 +102,14 @@ public class ServiceXSOG0801A extends ServiceEPBase {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
// 非管理员组织机构编码前缀增加企业编码 added by songx at 2024-01-15
String companyCode = UserSessionUtils.getCompanyCode();
resultRows.forEach((row) -> {
String orgId = SequenceGenerator.getNextSequence(HPConstant.SequenceId.ORG_CODE);
List<Map> newRows = new ArrayList<>();
for (Map row : resultRows) {
// 已存在的数据跳过
String orgId = MapUtils.getString(row, "orgId");
if (StringUtils.isNotBlank(orgId)) {
continue;
}
orgId = SequenceGenerator.getNextSequence(HPConstant.SequenceId.ORG_CODE);
row.put("orgId", orgId);
row.put("orgEname", orgId);
row.put("companyCode", companyCode);
......@@ -115,9 +126,15 @@ public class ServiceXSOG0801A extends ServiceEPBase {
row.put("factoryCode", factoryOrg.getOrgId());
row.put("factoryName", factoryOrg.getOrgCname());
}
});
newRows.add(row);
}
if (CollectionUtils.isEmpty(newRows)) {
inInfo.setStatus(EiConstant.STATUS_FAILURE);
inInfo.setMsg("请新增一行输入需要新增的数据");
return inInfo;
}
EiInfo call = new EiInfo();
call.set("list", resultRows);
call.set("list", newRows);
call.set(EiConstant.serviceId, "S_XS_87");
XServiceManager.call(call);
inInfo = this.query(inInfo);
......
package com.baosight.xservices.xs.og.service;
import com.baosight.hpjx.core.constant.CodesetConstant;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.enums.OrgTypeEnum;
import com.baosight.hpjx.core.security.UserSessionUtils;
import com.baosight.hpjx.core.tools.CodeValueTools;
import com.baosight.hpjx.hp.constant.HPConstant;
import com.baosight.hpjx.hp.kc.domain.HPKC010;
import com.baosight.hpjx.hp.xs.domain.Org;
import com.baosight.hpjx.hp.xs.tools.HPXSTools;
import com.baosight.hpjx.util.DateUtils;
import com.baosight.hpjx.util.EiInfoUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.hpjx.util.StringUtils;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import com.baosight.iplat4j.core.web.threadlocal.UserSession;
import com.baosight.iplat4j.ed.util.SequenceGenerator;
import com.baosight.xservices.xs.og.domain.XSOG01;
import com.baosight.xservices.xs.util.LoginUserDetails;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 新增组织机构
*
* @author:songx
* @date:2022/7/11,11:08
*/
public class ServiceXSOG0801B extends ServiceEPBase {
/**
* 初始化
*
* @param inInfo
* @return
*/
@Override
public EiInfo initLoad(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
Org org = HPXSTools.XsOrg.get(MapUtils.getString(queryMap, "orgId"));
// 回填父级ID
queryMap.put("parentOrgId", org.getParentOrgId());
String condition;
if (OrgTypeEnum.FACTORY.getCode().equals(org.getOrgType())) {
condition = String.format(" ITEM_CODE = '%s'", OrgTypeEnum.FACTORY.getCode());
} else {
condition = String.format(" ITEM_CODE IN ('%s', '%s', '%s')", OrgTypeEnum.DEPT.getCode(),
OrgTypeEnum.PROD_GROUP.getCode(), OrgTypeEnum.CUT_GROUP.getCode());
}
List<Map> orgTypes = CodeValueTools.getCodeValues(CodesetConstant.XsOg.ORG_TYPE, condition);
inInfo.addBlock("orgTypeBlock").addRows(orgTypes);
inInfo.addBlock(EiConstant.resultBlock).addBlockMeta(new HPKC010().eiMetadata);
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "初始化失败");
}
return inInfo;
}
/**
* 查询数据列表
*
* @param inInfo
* @return
*/
@Override
public EiInfo query(EiInfo inInfo) {
try {
Map queryRow = EiInfoUtils.getFirstRow(inInfo);
String orgId = MapUtils.getString(queryRow, "orgId");
if ("".equals(orgId)) {
return inInfo;
}
queryRow.put("companyCode", UserSessionUtils.getCompanyCode());
inInfo = super.query(inInfo, "XSOG01.query", new XSOG01());
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "查询失败");
}
return inInfo;
}
/**
* 保存
*
* @param inInfo
* @return
*/
public EiInfo save(EiInfo inInfo) {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
resultRows.forEach((row) -> {
row.put("establishDate", DateUtils.formatShort(row.get("establishDate")));
row.put("recRevisor", UserSession.getLoginName());
});
EiInfo call = new EiInfo();
call.set("list", resultRows);
call.set(EiConstant.serviceId, "S_XS_89");
XServiceManager.call(call);
inInfo = this.query(inInfo);
inInfo.setMsg("修改成功");
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "修改组织机构失败");
}
return inInfo;
}
}
......@@ -152,6 +152,9 @@
<isNotEmpty prepend=" AND " property="parentOrgId">
PARENT_ORG_ID = #parentOrgId#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="orgId">
ORG_ID = #orgId#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="orgCname">
ORG_CNAME like ('%$orgCname$%')
</isNotEmpty>
......
......@@ -359,6 +359,7 @@ public class ServiceXSOrgManage extends ServiceEPBase {
block.setCell(i, "orgBriefName", inInfoRowMap.get("orgBriefName").toString());
}
block.setCell(i, "establishDate", inInfoRowMap.get("establishDate"));
block.setCell(i, "recRevisor", recRevisor);
block.setCell(i, "recReviseTime", DateUtils.curDateTimeStr14());
}
......
......@@ -20,7 +20,6 @@
</script>
<script type="text/javascript">
let projectEnv = "${projectEnv}";
console.warn("projectEnv", projectEnv);
</script>
<script src="${ctx}/common/js/common.js"></script>
<script src="${ctx}/common/js/jsUtils.js"></script>
......@@ -5,8 +5,7 @@ $(function () {
field: "operator",
template: function (item) {
let template = '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'href="' + IPLATUI.CONTEXT_PATH + '/EU/DM/EUDM06.jsp?docId=' + item.docId
+ '" >附件下载</a>';
+ 'href="' + downloadHref(item.docId) + '" target="_blank">附件下载</a>';
return template;
}
}],
......
......@@ -5,8 +5,7 @@ $(function () {
field: "operator",
template: function (item) {
let template = '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'href="' + IPLATUI.CONTEXT_PATH + '/EU/DM/EUDM06.jsp?docId=' + item.docId
+ '" >附件下载</a>';
+ 'href="' + downloadHref(item.docId) + '" target="_blank">附件下载</a>';
return template;
}
}],
......
......@@ -6,7 +6,7 @@ $(function () {
template: function (item) {
let docId = item.docId;
let template = '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'href="' + downloadHref(docId) + '" >附件下载</a>';
+ 'href="' + downloadHref(docId) + '" target="_blank">附件下载</a>';
return template;
}
}],
......
......@@ -568,9 +568,17 @@ $(function () {
IPLAT.alert("请在组织机构树选择任意节点后编辑组织机构")
return
}
$("#inqu_status3-0-orgId").val(orgId)
result3Grid.dataSource.page(1)
$("#editOrgWindow").data("kendoWindow").open();
// $("#inqu_status3-0-orgId").val(orgId)
// result3Grid.dataSource.page(1)
// $("#editOrgWindow").data("kendoWindow").open();
let params = "&inqu_status-0-orgId=" + orgId;
JSColorbox.open({
href: "XSOG0801B?methodName=initLoad" + params,
title: "<div style='text-align: center;'>编辑组织机构</div>",
width: "70%",
height: "70%",
callbackName: editCallback
});
})
$("#categoryTree").mousedown(function (e) {
......@@ -913,6 +921,15 @@ let addCallback = function (parentOrgId) {
}
/**
* 编辑组织机构回调
*/
let editCallback = function (parentOrgId) {
// 回填父级ID
$("#inqu_status2-0-parentOrgId").val(parentOrgId);
refreshTree();
}
/**
* 刷新树
*/
let refreshTree = function () {
......
......@@ -308,7 +308,7 @@
<EF:EFColumn ename="orgEname" cname="组织编码" readonly="true" locked="true" hidden="true"/>
<EF:EFColumn ename="orgCname" cname="组织名称" locked="true" required="true" />
<EF:EFColumn ename="orgBriefName" cname="组织别名" hidden="true"/>
<EF:EFComboColumn ename="orgType" cname="组织类型" align="center" readonly="true">
<EF:EFComboColumn ename="orgType" cname="组织类型" align="center">
<EF:EFCodeOption codeName="xs.og.orgType" textField="label" valueField="value"/>
</EF:EFComboColumn>
<EF:EFColumn ename="orgNodeType" cname="节点类型" hidden="true" defaultValue="2"/> <%--隐藏 默认值为2--%>
......
$(function () {
IPLATUI.EFGrid = {
"result": {
columns: [],
columns: [{
field: "orgId",
template: function (e) {
// 新增时,组织机构编码需要置空
if (e.isNew()) {
e["orgId"] = "";
}
return e['orgId'];
}
}],
onSave: function (e) {
// 阻止后台保存请求,使用自定义保存
e.preventDefault();
......
......@@ -23,7 +23,7 @@
<EF:EFColumn ename="orgEname" cname="组织编码" readonly="true" hidden="true"/>
<EF:EFColumn ename="orgCname" cname="组织名称" required="true" locked="true"/>
<EF:EFColumn ename="orgBriefName" cname="组织别名" hidden="true"/>
<EF:EFComboColumn ename="orgType" cname="组织类型" required="true" textField="label" valueField="value">
<EF:EFComboColumn ename="orgType" cname="组织类型" align="center" required="true" >
<EF:EFOptions blockId="orgTypeBlock" textField="label" valueField="value"/>
</EF:EFComboColumn>
<EF:EFColumn ename="orgNodeType" cname="节点类型" hidden="true" defaultValue="2"/> <%--隐藏 默认值为2--%>
......
$(function () {
IPLATUI.EFGrid = {
"result": {
columns: [],
onSave: function (e) {
// 阻止后台保存请求,使用自定义保存
e.preventDefault();
save();
}
}
};
$("#ef_form_head").hide();
});
/**
* 页面加载时执行
*/
$(window).load(function () {
// 初始化查询
query();
});
/**
* 查询
*/
var query = function (e) {
resultGrid.dataSource.page(1);
};
/**
* 选择库存
*/
let save = function () {
let rows = resultGrid.getCheckedRows();
if (rows.length < 1) {
message("请选择数据")
return;
}
for (let i = 0; i < rows.length; i++) {
let orgCname = rows[i]['orgCname'];
if (isBlank(orgCname)) {
message("组织机构名称不能为空");
return;
}
let orgType = rows[i]['orgType'];
if (isBlank(orgType)) {
message("组织类型不能为空");
return;
}
let establishDate = rows[i]['establishDate'];
if (isBlank(establishDate)) {
message("成立时间不能为空");
return;
}
}
JSUtils.confirm("确定对勾选中的[" + rows.length + "]条数据做\"保存\"操作? ", {
ok: function () {
JSUtils.submitGridsData("result", "XSOG0801B", "save", true, function (e) {
var status = e.getStatus();
if (status !== -1) {
let parentOrgId = $("#inqu_status-0-parentOrgId").val();
parent.JSColorbox.setValueCallback(parentOrgId);
}
});
}
});
}
<!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:EFRegion id="result" title="组织机构">
<EF:EFInput cname="上级组织编码" blockId="inqu_status" ename="parentOrgId" row="0" type="hidden"/>
<EF:EFInput cname="组织编码" blockId="inqu_status" ename="orgId" row="0" type="hidden"/>
<EF:EFGrid blockId="result" autoBind="false" autoDraw="false" checkMode="multiple,row">
<EF:EFColumn ename="orgId" cname="组织ID" hidden="true"/>
<EF:EFColumn ename="orgEname" cname="组织编码" readonly="true" hidden="true"/>
<EF:EFColumn ename="orgCname" cname="组织名称" required="true" locked="true"/>
<EF:EFColumn ename="orgBriefName" cname="组织别名" hidden="true"/>
<EF:EFComboColumn ename="orgType" cname="组织类型" align="center" required="true" >
<EF:EFOptions blockId="orgTypeBlock" textField="label" valueField="value"/>
</EF:EFComboColumn>
<EF:EFColumn ename="orgNodeType" cname="节点类型" hidden="true" defaultValue="2"/> <%--隐藏 默认值为2--%>
<EF:EFColumn ename="parentOrgId" cname="上级组织编码" readonly="true" hidden="true"/> <%--隐藏--%>
<EF:EFColumn ename="establishDate" cname="成立时间" required="true" width="170" parseFormats="['yyyyMMdd']"
editType="date" dateFormat="yyyy-MM-dd" align="center"/>
<EF:EFColumn ename="orgLevel" cname="组织级别" align="center" hidden="true"/>
<EF:EFColumn ename="sortIndex" cname="排序" align="center"/>
</EF:EFGrid>
</EF:EFRegion>
</EF:EFPage>
......@@ -73,7 +73,11 @@ function message(msg) {
* @returns {string}
*/
function downloadHref(docId) {
return IPLATUI.CONTEXT_PATH + ("run" == projectEnv ? ('/docFileDownload/' + docId)
// S3地址有外网
// return IPLATUI.CONTEXT_PATH + ("run" == projectEnv ? ('/docFileDownload/' + docId)
// : ('/EU/DM/EUDM06.jsp?docId=' + docId));
// S3地址无外网
return IPLATUI.CONTEXT_PATH + ("run" == projectEnv ? ('/file/download/' + docId)
: ('/EU/DM/EUDM06.jsp?docId=' + docId));
}
......
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