| | |
| | | |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.highdatas.mdm.entity.Maintain; |
| | | import com.highdatas.mdm.entity.MaintainField; |
| | | import com.highdatas.mdm.entity.TUser; |
| | | import com.highdatas.mdm.entity.TableSchemaResult; |
| | | import com.highdatas.mdm.pojo.Segment; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.security.MessageDigest; |
| | | import java.text.MessageFormat; |
| | | import java.util.Random; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @author kimi |
| | |
| | | |
| | | @Slf4j |
| | | public class DbUtils { |
| | | private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
| | | |
| | | public static String versionAddSub (String baseVersion) { |
| | | if (StringUtils.isEmpty(baseVersion)) { |
| | |
| | | return null; |
| | | } |
| | | return baseVersion.getOrderNo().compareTo(compareVersion.getOrderNo()); |
| | | } |
| | | public static Integer compareVersion(MaintainField baseVersion, MaintainField compareVersion) { |
| | | if ((baseVersion == null) || (compareVersion == null)) { |
| | | return null; |
| | | } |
| | | return baseVersion.getOrderNo().compareTo(compareVersion.getOrderNo()); |
| | | } |
| | | |
| | | public static String versionAddBig(String baseVersion) { |
| | |
| | | Segment segment = new Segment(name, value); |
| | | return segment.toString(); |
| | | } |
| | | |
| | | public static String getTableNameFromEntity(Object object) { |
| | | Field[] fields = object.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | |
| | | } |
| | | return builder.toString(); |
| | | } |
| | | |
| | | public static String assemblParam(String objects){ |
| | | if (StringUtils.isEmpty(objects)) { |
| | | return null; |
| | | }else { |
| | | return "@{" + objects + "}"; |
| | | } |
| | | |
| | | } |
| | | public static String getRandomString(int length) { |
| | | Random random = new Random(); |
| | | StringBuffer sb = new StringBuffer(); |
| | |
| | | } |
| | | return sbf.toString(); |
| | | } |
| | | |
| | | |
| | | public static Set<String> matcher(String testStr) { |
| | | return matcher(Constant.Default_Patter, testStr); |
| | | } |
| | | |
| | | public static String replaceEscape(String testStr) { |
| | | String new_str = Pattern.compile("\t|\r|\n| ").matcher(testStr).replaceAll(Constant.EMPTY); |
| | | return new_str; |
| | | } |
| | | |
| | | public static Set<String> matcher(String patter, String testStr) { |
| | | // String test = "@{databaseIp}:{databasePort}{instanceName};database"; |
| | | // String initCompile = "(?<=@\\{)(.+?)(?=\\})"; |
| | | |
| | | Set<String> ls=new HashSet<>(); |
| | | |
| | | Pattern pattern = Pattern.compile(patter); |
| | | Matcher matcher = pattern.matcher(testStr); |
| | | |
| | | while(matcher.find()){ |
| | | |
| | | ls.add(matcher.group()); |
| | | |
| | | } |
| | | return ls; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | private static String toHexString(byte[] b) { |
| | | StringBuilder sb = new StringBuilder(b.length * 2); |
| | | for (int i = 0; i < b.length; i++) { |
| | | sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]); |
| | | sb.append(HEX_DIGITS[b[i] & 0x0f]); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public static String Bit32(String SourceString) throws Exception { |
| | | MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); |
| | | digest.update(SourceString.getBytes()); |
| | | byte messageDigest[] = digest.digest(); |
| | | return toHexString(messageDigest); |
| | | } |
| | | |
| | | public static String Bit16(String SourceString) throws Exception { |
| | | return Bit32(SourceString).substring(8, 24); |
| | | } |
| | | |
| | | public static List<Segment> map2Segment(Map<String, String> masterModifiedMap) { |
| | | ArrayList<Segment> result = new ArrayList<>(); |
| | | Set<String> keys = masterModifiedMap.keySet(); |
| | | for (String key : keys) { |
| | | String value = masterModifiedMap.get(key); |
| | | Segment segment = new Segment(key, value); |
| | | result.add(segment); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static String getFieldRedisKey(String tableName, String field) { |
| | | if (StringUtils.isEmpty(tableName) && StringUtils.isEmpty(field)) { |
| | | return null; |
| | | }else if (StringUtils.isEmpty(field)){ |
| | | return tableName; |
| | | }else if (StringUtils.isEmpty(tableName)){ |
| | | return field; |
| | | }else { |
| | | return tableName + Constant.UnderLine + field; |
| | | } |
| | | } |
| | | |
| | | public static List<String> split(String redisVal) { |
| | | if (StringUtils.isEmpty(redisVal)) { |
| | | return null; |
| | | } |
| | | String[] split = redisVal.split(Constant.SEMICOLON); |
| | | List<String> strings = Arrays.asList(split); |
| | | return strings; |
| | | } |
| | | |
| | | public static TUser getUser(HttpServletRequest request) { |
| | | return (TUser) request.getSession().getAttribute(Constant.USER); |
| | | } |
| | | |
| | | public static Set<String> getRoleByUser(String userId) { |
| | | Set<String> roleIds = new HashSet<>(); |
| | | roleIds.add("R001"); |
| | | roleIds.add("R002"); |
| | | return roleIds; |
| | | } |
| | | } |