供应商同步,多语言化检查,labelhtmlUtils编写

dev
IT-xiaoXiong 2021-12-13 12:00:39 +08:00
parent 7efbec9808
commit 062fc0466d
7 changed files with 3052 additions and 2708 deletions

View File

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

View File

@ -1044,6 +1044,7 @@ public class Util extends weaver.general.Util {
/** /**
* *
*
* @param fileName * @param fileName
* @param prefix * @param prefix
* @return * @return
@ -1088,6 +1089,7 @@ public class Util extends weaver.general.Util {
/** /**
* keyvalue * keyvalue
*
* @param prePrefix * @param prePrefix
* @param key key * @param key key
* @param value value * @param value value
@ -1329,10 +1331,12 @@ public class Util extends weaver.general.Util {
return result; return result;
} }
// 去重
public static <T> List<T> deWeight(List<T> list, Function<? super T, ?> keyExtractor) { public static <T> List<T> deWeight(List<T> list, Function<? super T, ?> keyExtractor) {
return list.stream().filter(distinctByKey(keyExtractor)).collect(Collectors.toList()); return list.stream().filter(distinctByKey(keyExtractor)).collect(Collectors.toList());
} }
//
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>(); Map<Object, Boolean> seen = new ConcurrentHashMap<>();
// putIfAbsent添加不存在的键返回null如果为null表示不重复 // putIfAbsent添加不存在的键返回null如果为null表示不重复
@ -1557,6 +1561,7 @@ public class Util extends weaver.general.Util {
/** /**
* *
*
* @param workflowId * @param workflowId
* @param docField * @param docField
* @return * @return
@ -1582,6 +1587,7 @@ public class Util extends weaver.general.Util {
/** /**
* *
*
* @param workflowId * @param workflowId
* @param docFieldId * @param docFieldId
* @return * @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 { 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) { if (map == null) {
return null; return null;
} }

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -1,10 +1,10 @@
package com.api.aiyh_pcn.copy_attachment.service; package com.api.aiyh_pcn.copy_attachment.service;
import aiyh.utils.ApiResult;
import aiyh.utils.zwl.common.ToolUtil; import aiyh.utils.zwl.common.ToolUtil;
import com.api.aiyh_pcn.copy_attachment.dao.DocTemplateDao;
import com.api.workflow.constant.RequestAuthenticationConstant; import com.api.workflow.constant.RequestAuthenticationConstant;
import com.engine.workflow.biz.requestForm.FileBiz; 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.general.Util;
import weaver.hrm.User; import weaver.hrm.User;
@ -39,7 +39,7 @@ public class CopyAttachmentService {
docIds = docTemplateDao.copyFile(user, tableName, fieldName, configId, workflowId, fileFieldId); docIds = docTemplateDao.copyFile(user, tableName, fieldName, configId, workflowId, fileFieldId);
} catch (Exception e) { } catch (Exception e) {
toolUtil.writeErrorLog("复制文件出错: " + e); toolUtil.writeErrorLog("复制文件出错: " + e);
return null; return ApiResult.error("复制文件出错!");
} }
if (docIds == null) { if (docIds == null) {
return ApiResult.error("未查询到附件模板!"); return ApiResult.error("未查询到附件模板!");
@ -69,6 +69,7 @@ public class CopyAttachmentService {
/** /**
* *
*
* @param user user * @param user user
* @param params * @param params
* @return * @return

View File

@ -355,7 +355,8 @@ public class FaDDContractService {
String.valueOf(ufContractInfoDTO.getWorkflowType()), 4); String.valueOf(ufContractInfoDTO.getWorkflowType()), 4);
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
String userInfo = ufContractInfoDTO.getUserInfo(); String userInfo = ufContractInfoDTO.getUserInfo();
User user = JSON.parseObject(userInfo, new TypeReference<User>() {}); User user = JSON.parseObject(userInfo, new TypeReference<User>() {
});
// 获取流程中的合同字段的文档目录id // 获取流程中的合同字段的文档目录id
rs.executeQuery( rs.executeQuery(
"select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType()); "select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType());
@ -418,7 +419,8 @@ public class FaDDContractService {
String.valueOf(ufContractInfoDTO.getWorkflowType()), 4); String.valueOf(ufContractInfoDTO.getWorkflowType()), 4);
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
String userInfo = ufContractInfoDTO.getUserInfo(); String userInfo = ufContractInfoDTO.getUserInfo();
User user = JSON.parseObject(userInfo, new TypeReference<User>() {}); User user = JSON.parseObject(userInfo, new TypeReference<User>() {
});
// 获取流程中的合同字段的文档目录id // 获取流程中的合同字段的文档目录id
rs.executeQuery( rs.executeQuery(
"select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType()); "select formid from workflow_base where id = ?", ufContractInfoDTO.getWorkflowType());

View File

@ -1,6 +1,8 @@
package customization.test; package customization.test;
import aiyh.utils.LabelHtmlUtils;
import aiyh.utils.Util; import aiyh.utils.Util;
import aiyh.utils.entity.LabelHtmlIndex;
import aiyh.utils.fileUtil.ProperUtil; import aiyh.utils.fileUtil.ProperUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.api.aiyh_pcn.patentWall.service.PatentWallService; import com.api.aiyh_pcn.patentWall.service.PatentWallService;
@ -404,4 +406,20 @@ public class NewUtilTest {
e.printStackTrace(); 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);
}
} }

View File

@ -117,13 +117,15 @@ public class AddCustomer_Action extends ToolUtil implements Action {
} }
} catch (LoginIdRepeatException e) { } catch (LoginIdRepeatException e) {
this.writeErrorLog(e + "\n"); this.writeErrorLog(e + "\n");
this.request.getRequestManager().setMessagecontent("登录名重复,请重新输入登录名"); this.request.getRequestManager().setMessagecontent(aiyh.utils.Util.getHtmlLabelName(-91703,
this.request.getRequestManager().setMessageid("登录名重复"); request.getRequestManager().getUser().getLanguage(), "登录名重复,请重新输入登录名"));
this.request.getRequestManager().setMessageid("1");
return Action.FAILURE_AND_CONTINUE; return Action.FAILURE_AND_CONTINUE;
} catch (Exception e) { } catch (Exception e) {
this.writeDebuggerLog("insert customer error!"); this.writeDebuggerLog("insert customer error!");
this.writeDebuggerLog(e + "\n"); 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"); this.request.getRequestManager().setMessageid("2");
} finally { } finally {
this.writeDebuggerLog(className, "------------" + className + " End -----------------"); this.writeDebuggerLog(className, "------------" + className + " End -----------------");