供应商同步,多语言化检查,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 prefix
* @return
@ -1088,6 +1089,7 @@ public class Util extends weaver.general.Util {
/**
* keyvalue
*
* @param prePrefix
* @param key key
* @param value value
@ -1219,7 +1221,7 @@ public class Util extends weaver.general.Util {
}
public static Object prop2MapPutValue(Object value) {
if(value == null){
if (value == null) {
return null;
}
String valueStr = String.valueOf(value).trim();
@ -1227,10 +1229,10 @@ public class Util extends weaver.general.Util {
return valueStr.substring(1, valueStr.length() - 1);
}
if (valueStr.contains(",")) {
if(valueStr.contains("\\,")){
if (valueStr.contains("\\,")) {
String[] split = valueStr.split("(?<!\\\\),");
for (int i = 0; i < split.length; i ++){
split[i] = split[i].replaceAll("\\\\,",",");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].replaceAll("\\\\,", ",");
}
return split;
}
@ -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表示不重复
@ -1528,12 +1532,12 @@ public class Util extends weaver.general.Util {
}
public static String getHtmlLabelName(int id, int languageId, String defaultStr){
public static String getHtmlLabelName(int id, int languageId, String defaultStr) {
String htmlLabelName = SystemEnv.getHtmlLabelName(id, languageId);
return htmlLabelName == null ? defaultStr : htmlLabelName;
}
public static String getHtmlLabelName(int id, int languageId){
public static String getHtmlLabelName(int id, int languageId) {
return SystemEnv.getHtmlLabelName(id, languageId);
}
@ -1557,24 +1561,25 @@ public class Util extends weaver.general.Util {
/**
*
*
* @param workflowId
* @param docField
* @return
*/
public static String getDocCategorys(String workflowId,String docField){
public static String getDocCategorys(String workflowId, String docField) {
RecordSet rs = new RecordSet();
rs.executeQuery("select formid from workflow_base where id = ?",workflowId);
rs.executeQuery("select formid from workflow_base where id = ?", workflowId);
String formId = Util.recordeSet2Entity(rs, String.class);
String query = "select doccategory from workflow_fileupload where fieldid = (select id from workflow_billfield where fieldname = ? and billid = ?)";
rs.executeQuery(query,docField,formId);
String docCategorys =Util.null2String(Util.recordeSet2Entity(rs, String.class));
if(StringUtils.isNullOrEmpty(docCategorys)){
rs.executeQuery(query, docField, formId);
String docCategorys = Util.null2String(Util.recordeSet2Entity(rs, String.class));
if (StringUtils.isNullOrEmpty(docCategorys)) {
query = "select doccategory from workflow_base where id = ?";
rs.executeQuery(query,workflowId);
rs.executeQuery(query, workflowId);
rs.next();
docCategorys = Util.null2String(rs.getString(1));
}
if(StringUtils.isNullOrEmpty(docCategorys)){
if (StringUtils.isNullOrEmpty(docCategorys)) {
docCategorys = ",,1";
}
return docCategorys;
@ -1582,35 +1587,36 @@ public class Util extends weaver.general.Util {
/**
*
*
* @param workflowId
* @param docFieldId
* @return
*/
public static String getDocCategorysById(String workflowId,String docFieldId){
public static String getDocCategorysById(String workflowId, String docFieldId) {
RecordSet rs = new RecordSet();
// rs.executeQuery("select formid from workflow_base where id = ?",workflowId);
// String formId = Util.recordeSet2Entity(rs, String.class);
String query = "select doccategory from workflow_fileupload where workflowid = ? and fieldid = ?";
rs.executeQuery(query,workflowId,docFieldId);
String docCategorys =Util.null2String(Util.recordeSet2Entity(rs, String.class));
if(StringUtils.isNullOrEmpty(docCategorys)){
rs.executeQuery(query, workflowId, docFieldId);
String docCategorys = Util.null2String(Util.recordeSet2Entity(rs, String.class));
if (StringUtils.isNullOrEmpty(docCategorys)) {
query = "select doccategory from workflow_base where id = ?";
rs.executeQuery(query,workflowId);
rs.executeQuery(query, workflowId);
rs.next();
docCategorys = Util.null2String(rs.getString(1));
}
if(StringUtils.isNullOrEmpty(docCategorys)){
if (StringUtils.isNullOrEmpty(docCategorys)) {
docCategorys = ",,1";
}
return docCategorys;
}
public static String null2DefaultStr(Object obj, String defaultStr){
public static String null2DefaultStr(Object obj, String defaultStr) {
String objStr = Util.null2String(obj);
if(StringUtils.isNullOrEmpty(objStr) && StringUtils.isNullOrEmpty(defaultStr)){
if (StringUtils.isNullOrEmpty(objStr) && StringUtils.isNullOrEmpty(defaultStr)) {
return "";
}
if(StringUtils.isNullOrEmpty(objStr) && !StringUtils.isNullOrEmpty(defaultStr)){
if (StringUtils.isNullOrEmpty(objStr) && !StringUtils.isNullOrEmpty(defaultStr)) {
return defaultStr;
}
return objStr;
@ -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;
}

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;
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;
@ -20,7 +20,7 @@ import java.util.Map;
public class CopyAttachmentService {
public static String copyFile(User user, Map<String, Object> params){
public static String copyFile(User user, Map<String, Object> params) {
ToolUtil toolUtil = new ToolUtil();
// 建模表名称
String tableName = String.valueOf(params.get("tableName"));
@ -34,14 +34,14 @@ public class CopyAttachmentService {
String workflowId = String.valueOf(params.get("workflowId"));
DocTemplateDao docTemplateDao = new DocTemplateDao();
int[] docIds = null;
try{
try {
// docIds = docTemplateDao.copyFile(user.getUID(), tableName, fieldName, configId);
docIds = docTemplateDao.copyFile(user, tableName, fieldName, configId,workflowId,fileFieldId);
}catch(Exception e){
docIds = docTemplateDao.copyFile(user, tableName, fieldName, configId, workflowId, fileFieldId);
} catch (Exception e) {
toolUtil.writeErrorLog("复制文件出错: " + e);
return null;
return ApiResult.error("复制文件出错!");
}
if(docIds == null){
if (docIds == null) {
return ApiResult.error("未查询到附件模板!");
}
/*try{
@ -64,17 +64,18 @@ public class CopyAttachmentService {
e.printStackTrace();
return ApiResult.error("删除失败!");
}
return ApiResult.success(array,"删除成功!");
return ApiResult.success(array, "删除成功!");
}
/**
*
*
* @param user user
* @param params
* @return
*/
public static String queryFilesData(User user, Map<String, Object> params){
String listType = Util.null2String(String.valueOf(params.get("listType")),"list");
public static String queryFilesData(User user, Map<String, Object> params) {
String listType = Util.null2String(String.valueOf(params.get("listType")), "list");
int requestid = Util.getIntValue(Util.null2String(String.valueOf(params.get("requestid"))), -1);
int desrequestid = Util.getIntValue(Util.null2String(String.valueOf(params.get("desrequestid"))), -1);
int isprint = Util.getIntValue(Util.null2String(String.valueOf(params.get("isprint"))), 0);
@ -83,12 +84,12 @@ public class CopyAttachmentService {
String f_weaver_belongto_usertype = Util.null2String(String.valueOf(params.get("f_weaver_belongto_usertype")));
String authStr = Util.null2String(String.valueOf(params.get(RequestAuthenticationConstant.AUTHORITY_STRING)));
String authSignatureStr = Util.null2String(String.valueOf(params.get(RequestAuthenticationConstant.AUTHORITY_SIGNATURESTRING)));
Map<String,Object> paramsMap = new HashMap<>();
paramsMap.put("user",user);
Map<String,Object> retobj;
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("user", user);
Map<String, Object> retobj;
try {
retobj = FileBiz.getFileDatas(Util.null2String(params.get("docIds")),listType,requestid,desrequestid,
isprint,f_weaver_belongto_userid,f_weaver_belongto_usertype,true,false,authStr,authSignatureStr,paramsMap);
retobj = FileBiz.getFileDatas(Util.null2String(params.get("docIds")), listType, requestid, desrequestid,
isprint, f_weaver_belongto_userid, f_weaver_belongto_usertype, true, false, authStr, authSignatureStr, paramsMap);
} catch (Exception e) {
e.printStackTrace();
return ApiResult.error("查询附件信息失败:" + e);

View File

@ -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());

View File

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

View File

@ -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 -----------------");