供应商同步,多语言化检查,labelhtmlUtils编写
parent
7efbec9808
commit
062fc0466d
|
@ -0,0 +1,170 @@
|
|||
package aiyh.utils;
|
||||
|
||||
import aiyh.utils.entity.LabelHtmlIndex;
|
||||
import aiyh.utils.service.UtilService;
|
||||
import weaver.systeminfo.SystemEnv;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author EBU7-dev1-ayh
|
||||
* create 2021/12/13 0013 10:29
|
||||
* 多语言工具类
|
||||
*/
|
||||
|
||||
|
||||
public class LabelHtmlUtils {
|
||||
|
||||
private final UtilService utilService = new UtilService();
|
||||
private Map<String, Object> htmlLabel = null;
|
||||
|
||||
public LabelHtmlUtils(String prefix) {
|
||||
if (!this.init(prefix)) {
|
||||
throw new RuntimeException("配置文件异常,请检查配置文件结构是否符合要求!");
|
||||
}
|
||||
}
|
||||
|
||||
public LabelHtmlUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化配置信息
|
||||
*
|
||||
* @param prefix 前缀
|
||||
* @return 是否初始化成功
|
||||
*/
|
||||
public synchronized boolean init(String prefix) {
|
||||
if (this.htmlLabel != null) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
this.htmlLabel = Util.readProperties2Map("htmlLabelIndex", prefix);
|
||||
return this.htmlLabel != null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定语言id的自定义标签
|
||||
*
|
||||
* @param id 自定义标签id
|
||||
* @param languageId 语言id
|
||||
* @param defaultStr 默认字符串
|
||||
* @return 自定义标签对应的语言字符串,或者默认字符串
|
||||
*/
|
||||
public String getHtmlLabelName(int id, int languageId, String defaultStr) {
|
||||
String htmlLabelName = SystemEnv.getHtmlLabelName(id, languageId);
|
||||
return htmlLabelName == null ? defaultStr : htmlLabelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定语言id的自定义标签
|
||||
*
|
||||
* @param id 标签id
|
||||
* @param languageId 语言id
|
||||
* @return 自定义标签的语言字符串
|
||||
*/
|
||||
public String getHtmlLabelName(int id, int languageId) {
|
||||
return SystemEnv.getHtmlLabelName(id, languageId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过语言id截取多语言字符串
|
||||
*
|
||||
* @param languageId 语言id
|
||||
* @param languageStr 多语言字符串
|
||||
* @return 截取后的字符串
|
||||
*/
|
||||
public String getHtmlLabelNameByStr(int languageId, String languageStr) {
|
||||
String pattern = "(`~`" + languageId + " )(?<label>(\\w*|\\W*|[\\u4e00-\\u9fa5]*))(`~`)";
|
||||
Pattern compile = Pattern.compile(pattern);
|
||||
Matcher matcher = compile.matcher(languageStr);
|
||||
if (matcher.find()) {
|
||||
return matcher.group("label");
|
||||
}
|
||||
return languageStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置多余元文件详细
|
||||
*
|
||||
* @param key 键
|
||||
*/
|
||||
public Map<String, Object> getHtmlLabelMap(String key) {
|
||||
if (this.htmlLabel == null) {
|
||||
throw new RuntimeException("请初始化以读取配置信息,调用方法init(String prefix)");
|
||||
}
|
||||
Map<String, Object> map;
|
||||
try {
|
||||
map = (Map<String, Object>) this.htmlLabel.get(key);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("配置文件异常,请检查配置文件结构是否符合要求!");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置文件中的多语言配置
|
||||
*
|
||||
* @param key 多语言配置中的前缀
|
||||
* @return 多语言配置Map
|
||||
*/
|
||||
public Map<String, String> getHtmlLabel(String key) {
|
||||
if (this.htmlLabel == null) {
|
||||
throw new RuntimeException("请初始化以读取配置信息,调用方法init(String prefix)");
|
||||
}
|
||||
Map<String, String> map;
|
||||
try {
|
||||
map = (Map<String, String>) this.htmlLabel.get(key);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("配置文件异常,请检查配置文件结构是否符合要求!");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置文件中的多语言配置
|
||||
*
|
||||
* @param key 多语言配置中的前缀
|
||||
* @return 多语言配置对象
|
||||
*/
|
||||
public LabelHtmlIndex getLabelHtmlIndex(String key) {
|
||||
if (this.htmlLabel == null) {
|
||||
throw new RuntimeException("请初始化以读取配置信息,调用方法init(String prefix)");
|
||||
}
|
||||
Map<String, Object> map;
|
||||
LabelHtmlIndex labelHtmlIndex;
|
||||
try {
|
||||
map = (Map<String, Object>) this.htmlLabel.get(key);
|
||||
labelHtmlIndex = Util.mapToObject(map, LabelHtmlIndex.class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("配置文件异常,请检查配置文件结构是否符合要求!");
|
||||
}
|
||||
return labelHtmlIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取配置文件中的多语言配置
|
||||
*
|
||||
* @param map 多语言配置中的对象
|
||||
* @return 多语言配置对象
|
||||
*/
|
||||
public LabelHtmlIndex getLabelHtmlIndex(Map<String, Object> map, String key) {
|
||||
LabelHtmlIndex labelHtmlIndex;
|
||||
Map<String, Object> resultMap;
|
||||
try {
|
||||
resultMap = (Map<String, Object>) map.get(key);
|
||||
labelHtmlIndex = Util.mapToObject(resultMap, LabelHtmlIndex.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("map转换异常!");
|
||||
}
|
||||
return labelHtmlIndex;
|
||||
}
|
||||
}
|
|
@ -1044,6 +1044,7 @@ public class Util extends weaver.general.Util {
|
|||
|
||||
/**
|
||||
* 根据配置文件文件名以及前缀获取对应的配置文件信息
|
||||
*
|
||||
* @param fileName
|
||||
* @param prefix
|
||||
* @return
|
||||
|
@ -1088,6 +1089,7 @@ public class Util extends weaver.general.Util {
|
|||
|
||||
/**
|
||||
* 处理配置文件的key和value映射关系
|
||||
*
|
||||
* @param prePrefix 前缀
|
||||
* @param key key
|
||||
* @param value value
|
||||
|
@ -1329,10 +1331,12 @@ public class Util extends weaver.general.Util {
|
|||
return result;
|
||||
}
|
||||
|
||||
// 去重
|
||||
public static <T> List<T> deWeight(List<T> list, Function<? super T, ?> keyExtractor) {
|
||||
return list.stream().filter(distinctByKey(keyExtractor)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//
|
||||
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
// putIfAbsent添加不存在的键,返回null,如果为null表示不重复
|
||||
|
@ -1557,6 +1561,7 @@ public class Util extends weaver.general.Util {
|
|||
|
||||
/**
|
||||
* 根据流程和流程字段查询文档目录
|
||||
*
|
||||
* @param workflowId
|
||||
* @param docField
|
||||
* @return
|
||||
|
@ -1582,6 +1587,7 @@ public class Util extends weaver.general.Util {
|
|||
|
||||
/**
|
||||
* 根据流程和流程字段查询文档目录
|
||||
*
|
||||
* @param workflowId
|
||||
* @param docFieldId
|
||||
* @return
|
||||
|
@ -1618,6 +1624,112 @@ public class Util extends weaver.general.Util {
|
|||
|
||||
|
||||
public static <T> T mapToObject(Map<String, Object> map, Class<T> t) throws Exception {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
T obj = t.newInstance();
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
int mod = field.getModifiers();
|
||||
if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) {
|
||||
continue;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
if (field.getType().equals(String.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, String.valueOf(map.get(field.getName())));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(Integer.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Integer.valueOf(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(Boolean.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Boolean.valueOf(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(Float.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Float.valueOf(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(Double.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Double.valueOf(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(int.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Integer.parseInt(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(float.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Float.parseFloat(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(double.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Double.parseDouble(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (field.getType().equals(boolean.class)) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
if (map.get(field.getName()) == null || "".equals(map.get(field.getName()))) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Boolean.parseBoolean(String.valueOf(map.get(field.getName()))));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static <T> T strMapToObject(Map<String, String> map, Class<T> t) throws Exception {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package aiyh.utils.entity;
|
||||
|
||||
/**
|
||||
* @author EBU7-dev1-ayh
|
||||
* create 2021/12/13 0013 11:19
|
||||
*/
|
||||
|
||||
|
||||
public class LabelHtmlIndex {
|
||||
private Integer labelIndex;
|
||||
private String defaultStr;
|
||||
|
||||
public LabelHtmlIndex() {
|
||||
|
||||
}
|
||||
|
||||
public LabelHtmlIndex(Integer labelIndex, String defaultStr) {
|
||||
this.labelIndex = labelIndex;
|
||||
this.defaultStr = defaultStr;
|
||||
}
|
||||
|
||||
public Integer getLabelIndex() {
|
||||
return labelIndex;
|
||||
}
|
||||
|
||||
|
||||
public String getDefaultStr() {
|
||||
return defaultStr;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LabelHtmlIndex{" +
|
||||
"labelIndex='" + labelIndex + '\'' +
|
||||
", defaultStr='" + defaultStr + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.api.aiyh_pcn.copy_attachment.service;
|
||||
|
||||
import aiyh.utils.ApiResult;
|
||||
import aiyh.utils.zwl.common.ToolUtil;
|
||||
import com.api.aiyh_pcn.copy_attachment.dao.DocTemplateDao;
|
||||
import com.api.workflow.constant.RequestAuthenticationConstant;
|
||||
import com.engine.workflow.biz.requestForm.FileBiz;
|
||||
import aiyh.utils.ApiResult;
|
||||
import com.api.aiyh_pcn.copy_attachment.dao.DocTemplateDao;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class CopyAttachmentService {
|
|||
docIds = docTemplateDao.copyFile(user, tableName, fieldName, configId, workflowId, fileFieldId);
|
||||
} catch (Exception e) {
|
||||
toolUtil.writeErrorLog("复制文件出错: " + e);
|
||||
return null;
|
||||
return ApiResult.error("复制文件出错!");
|
||||
}
|
||||
if (docIds == null) {
|
||||
return ApiResult.error("未查询到附件模板!");
|
||||
|
@ -69,6 +69,7 @@ public class CopyAttachmentService {
|
|||
|
||||
/**
|
||||
* 查询文档信息
|
||||
*
|
||||
* @param user user对象
|
||||
* @param params 前端参数
|
||||
* @return 文档信息
|
||||
|
|
|
@ -355,7 +355,8 @@ public class FaDDContractService {
|
|||
String.valueOf(ufContractInfoDTO.getWorkflowType()), 4);
|
||||
RecordSet rs = new RecordSet();
|
||||
String userInfo = ufContractInfoDTO.getUserInfo();
|
||||
User user = JSON.parseObject(userInfo, new TypeReference<User>() {});
|
||||
User user = JSON.parseObject(userInfo, new TypeReference<User>() {
|
||||
});
|
||||
// 获取流程中的合同字段的文档目录id
|
||||
rs.executeQuery(
|
||||
"select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType());
|
||||
|
@ -418,7 +419,8 @@ public class FaDDContractService {
|
|||
String.valueOf(ufContractInfoDTO.getWorkflowType()), 4);
|
||||
RecordSet rs = new RecordSet();
|
||||
String userInfo = ufContractInfoDTO.getUserInfo();
|
||||
User user = JSON.parseObject(userInfo, new TypeReference<User>() {});
|
||||
User user = JSON.parseObject(userInfo, new TypeReference<User>() {
|
||||
});
|
||||
// 获取流程中的合同字段的文档目录id
|
||||
rs.executeQuery(
|
||||
"select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType());
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package customization.test;
|
||||
|
||||
import aiyh.utils.LabelHtmlUtils;
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.entity.LabelHtmlIndex;
|
||||
import aiyh.utils.fileUtil.ProperUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.api.aiyh_pcn.patentWall.service.PatentWallService;
|
||||
|
@ -404,4 +406,20 @@ public class NewUtilTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTime() {
|
||||
System.out.println(System.currentTimeMillis());
|
||||
System.out.println(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPro() {
|
||||
LabelHtmlUtils labelHtmlUtils = new LabelHtmlUtils("aiyh.htmlLabel.porsche");
|
||||
Map<String, Object> faDDContractController = labelHtmlUtils.getHtmlLabelMap("FaDDContractController");
|
||||
System.out.println(faDDContractController);
|
||||
LabelHtmlIndex labelHtmlIndex = labelHtmlUtils.getLabelHtmlIndex(faDDContractController, "singedErr");
|
||||
System.out.println(labelHtmlIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,13 +117,15 @@ public class AddCustomer_Action extends ToolUtil implements Action {
|
|||
}
|
||||
} catch (LoginIdRepeatException e) {
|
||||
this.writeErrorLog(e + "\n");
|
||||
this.request.getRequestManager().setMessagecontent("登录名重复,请重新输入登录名");
|
||||
this.request.getRequestManager().setMessageid("登录名重复");
|
||||
this.request.getRequestManager().setMessagecontent(aiyh.utils.Util.getHtmlLabelName(-91703,
|
||||
request.getRequestManager().getUser().getLanguage(), "登录名重复,请重新输入登录名"));
|
||||
this.request.getRequestManager().setMessageid("1");
|
||||
return Action.FAILURE_AND_CONTINUE;
|
||||
} catch (Exception e) {
|
||||
this.writeDebuggerLog("insert customer error!");
|
||||
this.writeDebuggerLog(e + "\n");
|
||||
this.request.getRequestManager().setMessagecontent("生成外部用户错误,请联系管理员!");
|
||||
this.request.getRequestManager().setMessagecontent(aiyh.utils.Util.getHtmlLabelName(-91704,
|
||||
request.getRequestManager().getUser().getLanguage(), "生成外部用户错误,请联系管理员!"));
|
||||
this.request.getRequestManager().setMessageid("2");
|
||||
} finally {
|
||||
this.writeDebuggerLog(className, "------------" + className + " End -----------------");
|
||||
|
|
Loading…
Reference in New Issue