diff --git a/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java b/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java index 1f987b7f..f0f70a53 100644 --- a/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java +++ b/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java @@ -16,8 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package com.jeesite.test.diff; +package com.jeesite.common.text; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -45,7 +44,7 @@ import java.util.regex.Pattern; * Class containing the diff, match and patch methods. * Also contains the behaviour settings. */ -public class diff_match_patch { +public class DiffMatchPatch { // Defaults. // Set these on your diff_match_patch instance to override the defaults. @@ -1340,8 +1339,9 @@ public class diff_match_patch { public String diff_prettyHtml(LinkedList diffs) { StringBuilder html = new StringBuilder(); for (Diff aDiff : diffs) { - String text = aDiff.text.replace("&", "&").replace("<", "<") - .replace(">", ">").replace("\n", "¶
"); + String text = aDiff.text; +// text = text.replace("&", "&").replace("<", "<") +// .replace(">", ">").replace("\n", "
"); switch (aDiff.operation) { case INSERT: html.append("").append(text) diff --git a/common/src/test/java/com/jeesite/test/diff/DiffMatchPatchTest.java b/common/src/test/java/com/jeesite/test/diff/DiffMatchPatchTest.java deleted file mode 100644 index 03ca99ce..00000000 --- a/common/src/test/java/com/jeesite/test/diff/DiffMatchPatchTest.java +++ /dev/null @@ -1,932 +0,0 @@ -/* - * Test harness for diff_match_patch.java - * - * Copyright 2006 Google Inc. - * http://code.google.com/p/google-diff-match-patch/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.jeesite.test.diff; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import com.jeesite.test.diff.diff_match_patch.Diff; -import com.jeesite.test.diff.diff_match_patch.LinesToCharsResult; -import com.jeesite.test.diff.diff_match_patch.Patch; - -@SuppressWarnings("deprecation") -public class diff_match_patch_test extends TestCase { - - private diff_match_patch dmp; - private diff_match_patch.Operation DELETE = diff_match_patch.Operation.DELETE; - private diff_match_patch.Operation EQUAL = diff_match_patch.Operation.EQUAL; - private diff_match_patch.Operation INSERT = diff_match_patch.Operation.INSERT; - - @Override -protected void setUp() { - // Create an instance of the diff_match_patch object. - dmp = new diff_match_patch(); - } - - - // DIFF TEST FUNCTIONS - - - public void testDiffCommonPrefix() { - // Detect any common prefix. - assertEquals("diff_commonPrefix: Null case.", 0, dmp.diff_commonPrefix("abc", "xyz")); - - assertEquals("diff_commonPrefix: Non-null case.", 4, dmp.diff_commonPrefix("1234abcdef", "1234xyz")); - - assertEquals("diff_commonPrefix: Whole case.", 4, dmp.diff_commonPrefix("1234", "1234xyz")); - } - - public void testDiffCommonSuffix() { - // Detect any common suffix. - assertEquals("diff_commonSuffix: Null case.", 0, dmp.diff_commonSuffix("abc", "xyz")); - - assertEquals("diff_commonSuffix: Non-null case.", 4, dmp.diff_commonSuffix("abcdef1234", "xyz1234")); - - assertEquals("diff_commonSuffix: Whole case.", 4, dmp.diff_commonSuffix("1234", "xyz1234")); - } - - public void testDiffCommonOverlap() { - // Detect any suffix/prefix overlap. - assertEquals("diff_commonOverlap: Null case.", 0, dmp.diff_commonOverlap("", "abcd")); - - assertEquals("diff_commonOverlap: Whole case.", 3, dmp.diff_commonOverlap("abc", "abcd")); - - assertEquals("diff_commonOverlap: No overlap.", 0, dmp.diff_commonOverlap("123456", "abcd")); - - assertEquals("diff_commonOverlap: Overlap.", 3, dmp.diff_commonOverlap("123456xxx", "xxxabcd")); - - // Some overly clever languages (C#) may treat ligatures as equal to their - // component letters. E.g. U+FB01 == 'fi' - assertEquals("diff_commonOverlap: Unicode.", 0, dmp.diff_commonOverlap("fi", "\ufb01i")); - } - - public void testDiffHalfmatch() { - // Detect a halfmatch. - dmp.Diff_Timeout = 1; - assertNull("diff_halfMatch: No match #1.", dmp.diff_halfMatch("1234567890", "abcdef")); - - assertNull("diff_halfMatch: No match #2.", dmp.diff_halfMatch("12345", "23")); - - assertArrayEquals("diff_halfMatch: Single Match #1.", new String[]{"12", "90", "a", "z", "345678"}, dmp.diff_halfMatch("1234567890", "a345678z")); - - assertArrayEquals("diff_halfMatch: Single Match #2.", new String[]{"a", "z", "12", "90", "345678"}, dmp.diff_halfMatch("a345678z", "1234567890")); - - assertArrayEquals("diff_halfMatch: Single Match #3.", new String[]{"abc", "z", "1234", "0", "56789"}, dmp.diff_halfMatch("abc56789z", "1234567890")); - - assertArrayEquals("diff_halfMatch: Single Match #4.", new String[]{"a", "xyz", "1", "7890", "23456"}, dmp.diff_halfMatch("a23456xyz", "1234567890")); - - assertArrayEquals("diff_halfMatch: Multiple Matches #1.", new String[]{"12123", "123121", "a", "z", "1234123451234"}, dmp.diff_halfMatch("121231234123451234123121", "a1234123451234z")); - - assertArrayEquals("diff_halfMatch: Multiple Matches #2.", new String[]{"", "-=-=-=-=-=", "x", "", "x-=-=-=-=-=-=-="}, dmp.diff_halfMatch("x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-=")); - - assertArrayEquals("diff_halfMatch: Multiple Matches #3.", new String[]{"-=-=-=-=-=", "", "", "y", "-=-=-=-=-=-=-=y"}, dmp.diff_halfMatch("-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy")); - - // Optimal diff would be -q+x=H-i+e=lloHe+Hu=llo-Hew+y not -qHillo+x=HelloHe-w+Hulloy - assertArrayEquals("diff_halfMatch: Non-optimal halfmatch.", new String[]{"qHillo", "w", "x", "Hulloy", "HelloHe"}, dmp.diff_halfMatch("qHilloHelloHew", "xHelloHeHulloy")); - - dmp.Diff_Timeout = 0; - assertNull("diff_halfMatch: Optimal no halfmatch.", dmp.diff_halfMatch("qHilloHelloHew", "xHelloHeHulloy")); - } - - public void testDiffLinesToChars() { - // Convert lines down to characters. - ArrayList tmpVector = new ArrayList(); - tmpVector.add(""); - tmpVector.add("alpha\n"); - tmpVector.add("beta\n"); - assertLinesToCharsResultEquals("diff_linesToChars: Shared lines.", new LinesToCharsResult("\u0001\u0002\u0001", "\u0002\u0001\u0002", tmpVector), dmp.diff_linesToChars("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n")); - - tmpVector.clear(); - tmpVector.add(""); - tmpVector.add("alpha\r\n"); - tmpVector.add("beta\r\n"); - tmpVector.add("\r\n"); - assertLinesToCharsResultEquals("diff_linesToChars: Empty string and blank lines.", new LinesToCharsResult("", "\u0001\u0002\u0003\u0003", tmpVector), dmp.diff_linesToChars("", "alpha\r\nbeta\r\n\r\n\r\n")); - - tmpVector.clear(); - tmpVector.add(""); - tmpVector.add("a"); - tmpVector.add("b"); - assertLinesToCharsResultEquals("diff_linesToChars: No linebreaks.", new LinesToCharsResult("\u0001", "\u0002", tmpVector), dmp.diff_linesToChars("a", "b")); - - // More than 256 to reveal any 8-bit limitations. - int n = 300; - tmpVector.clear(); - StringBuilder lineList = new StringBuilder(); - StringBuilder charList = new StringBuilder(); - for (int x = 1; x < n + 1; x++) { - tmpVector.add(x + "\n"); - lineList.append(x + "\n"); - charList.append(String.valueOf((char) x)); - } - assertEquals(n, tmpVector.size()); - String lines = lineList.toString(); - String chars = charList.toString(); - assertEquals(n, chars.length()); - tmpVector.add(0, ""); - assertLinesToCharsResultEquals("diff_linesToChars: More than 256.", new LinesToCharsResult(chars, "", tmpVector), dmp.diff_linesToChars(lines, "")); - } - - public void testDiffCharsToLines() { - // First check that Diff equality works. - assertTrue("diff_charsToLines: Equality #1.", new Diff(EQUAL, "a").equals(new Diff(EQUAL, "a"))); - - assertEquals("diff_charsToLines: Equality #2.", new Diff(EQUAL, "a"), new Diff(EQUAL, "a")); - - // Convert chars up to lines. - LinkedList diffs = diffList(new Diff(EQUAL, "\u0001\u0002\u0001"), new Diff(INSERT, "\u0002\u0001\u0002")); - ArrayList tmpVector = new ArrayList(); - tmpVector.add(""); - tmpVector.add("alpha\n"); - tmpVector.add("beta\n"); - dmp.diff_charsToLines(diffs, tmpVector); - assertEquals("diff_charsToLines: Shared lines.", diffList(new Diff(EQUAL, "alpha\nbeta\nalpha\n"), new Diff(INSERT, "beta\nalpha\nbeta\n")), diffs); - - // More than 256 to reveal any 8-bit limitations. - int n = 300; - tmpVector.clear(); - StringBuilder lineList = new StringBuilder(); - StringBuilder charList = new StringBuilder(); - for (int x = 1; x < n + 1; x++) { - tmpVector.add(x + "\n"); - lineList.append(x + "\n"); - charList.append(String.valueOf((char) x)); - } - assertEquals(n, tmpVector.size()); - String lines = lineList.toString(); - String chars = charList.toString(); - assertEquals(n, chars.length()); - tmpVector.add(0, ""); - diffs = diffList(new Diff(DELETE, chars)); - dmp.diff_charsToLines(diffs, tmpVector); - assertEquals("diff_charsToLines: More than 256.", diffList(new Diff(DELETE, lines)), diffs); - } - - public void testDiffCleanupMerge() { - // Cleanup a messy diff. - LinkedList diffs = diffList(); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Null case.", diffList(), diffs); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "b"), new Diff(INSERT, "c")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: No change case.", diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "b"), new Diff(INSERT, "c")), diffs); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(EQUAL, "b"), new Diff(EQUAL, "c")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Merge equalities.", diffList(new Diff(EQUAL, "abc")), diffs); - - diffs = diffList(new Diff(DELETE, "a"), new Diff(DELETE, "b"), new Diff(DELETE, "c")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Merge deletions.", diffList(new Diff(DELETE, "abc")), diffs); - - diffs = diffList(new Diff(INSERT, "a"), new Diff(INSERT, "b"), new Diff(INSERT, "c")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Merge insertions.", diffList(new Diff(INSERT, "abc")), diffs); - - diffs = diffList(new Diff(DELETE, "a"), new Diff(INSERT, "b"), new Diff(DELETE, "c"), new Diff(INSERT, "d"), new Diff(EQUAL, "e"), new Diff(EQUAL, "f")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Merge interweave.", diffList(new Diff(DELETE, "ac"), new Diff(INSERT, "bd"), new Diff(EQUAL, "ef")), diffs); - - diffs = diffList(new Diff(DELETE, "a"), new Diff(INSERT, "abc"), new Diff(DELETE, "dc")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Prefix and suffix detection.", diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "d"), new Diff(INSERT, "b"), new Diff(EQUAL, "c")), diffs); - - diffs = diffList(new Diff(EQUAL, "x"), new Diff(DELETE, "a"), new Diff(INSERT, "abc"), new Diff(DELETE, "dc"), new Diff(EQUAL, "y")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Prefix and suffix detection with equalities.", diffList(new Diff(EQUAL, "xa"), new Diff(DELETE, "d"), new Diff(INSERT, "b"), new Diff(EQUAL, "cy")), diffs); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(INSERT, "ba"), new Diff(EQUAL, "c")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Slide edit left.", diffList(new Diff(INSERT, "ab"), new Diff(EQUAL, "ac")), diffs); - - diffs = diffList(new Diff(EQUAL, "c"), new Diff(INSERT, "ab"), new Diff(EQUAL, "a")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Slide edit right.", diffList(new Diff(EQUAL, "ca"), new Diff(INSERT, "ba")), diffs); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "b"), new Diff(EQUAL, "c"), new Diff(DELETE, "ac"), new Diff(EQUAL, "x")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Slide edit left recursive.", diffList(new Diff(DELETE, "abc"), new Diff(EQUAL, "acx")), diffs); - - diffs = diffList(new Diff(EQUAL, "x"), new Diff(DELETE, "ca"), new Diff(EQUAL, "c"), new Diff(DELETE, "b"), new Diff(EQUAL, "a")); - dmp.diff_cleanupMerge(diffs); - assertEquals("diff_cleanupMerge: Slide edit right recursive.", diffList(new Diff(EQUAL, "xca"), new Diff(DELETE, "cba")), diffs); - } - - public void testDiffCleanupSemanticLossless() { - // Slide diffs to match logical boundaries. - LinkedList diffs = diffList(); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Null case.", diffList(), diffs); - - diffs = diffList(new Diff(EQUAL, "AAA\r\n\r\nBBB"), new Diff(INSERT, "\r\nDDD\r\n\r\nBBB"), new Diff(EQUAL, "\r\nEEE")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Blank lines.", diffList(new Diff(EQUAL, "AAA\r\n\r\n"), new Diff(INSERT, "BBB\r\nDDD\r\n\r\n"), new Diff(EQUAL, "BBB\r\nEEE")), diffs); - - diffs = diffList(new Diff(EQUAL, "AAA\r\nBBB"), new Diff(INSERT, " DDD\r\nBBB"), new Diff(EQUAL, " EEE")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Line boundaries.", diffList(new Diff(EQUAL, "AAA\r\n"), new Diff(INSERT, "BBB DDD\r\n"), new Diff(EQUAL, "BBB EEE")), diffs); - - diffs = diffList(new Diff(EQUAL, "The c"), new Diff(INSERT, "ow and the c"), new Diff(EQUAL, "at.")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Word boundaries.", diffList(new Diff(EQUAL, "The "), new Diff(INSERT, "cow and the "), new Diff(EQUAL, "cat.")), diffs); - - diffs = diffList(new Diff(EQUAL, "The-c"), new Diff(INSERT, "ow-and-the-c"), new Diff(EQUAL, "at.")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Alphanumeric boundaries.", diffList(new Diff(EQUAL, "The-"), new Diff(INSERT, "cow-and-the-"), new Diff(EQUAL, "cat.")), diffs); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "a"), new Diff(EQUAL, "ax")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Hitting the start.", diffList(new Diff(DELETE, "a"), new Diff(EQUAL, "aax")), diffs); - - diffs = diffList(new Diff(EQUAL, "xa"), new Diff(DELETE, "a"), new Diff(EQUAL, "a")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Hitting the end.", diffList(new Diff(EQUAL, "xaa"), new Diff(DELETE, "a")), diffs); - - diffs = diffList(new Diff(EQUAL, "The xxx. The "), new Diff(INSERT, "zzz. The "), new Diff(EQUAL, "yyy.")); - dmp.diff_cleanupSemanticLossless(diffs); - assertEquals("diff_cleanupSemanticLossless: Sentence boundaries.", diffList(new Diff(EQUAL, "The xxx."), new Diff(INSERT, " The zzz."), new Diff(EQUAL, " The yyy.")), diffs); - } - - public void testDiffCleanupSemantic() { - // Cleanup semantically trivial equalities. - LinkedList diffs = diffList(); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Null case.", diffList(), diffs); - - diffs = diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "cd"), new Diff(EQUAL, "12"), new Diff(DELETE, "e")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: No elimination #1.", diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "cd"), new Diff(EQUAL, "12"), new Diff(DELETE, "e")), diffs); - - diffs = diffList(new Diff(DELETE, "abc"), new Diff(INSERT, "ABC"), new Diff(EQUAL, "1234"), new Diff(DELETE, "wxyz")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: No elimination #2.", diffList(new Diff(DELETE, "abc"), new Diff(INSERT, "ABC"), new Diff(EQUAL, "1234"), new Diff(DELETE, "wxyz")), diffs); - - diffs = diffList(new Diff(DELETE, "a"), new Diff(EQUAL, "b"), new Diff(DELETE, "c")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Simple elimination.", diffList(new Diff(DELETE, "abc"), new Diff(INSERT, "b")), diffs); - - diffs = diffList(new Diff(DELETE, "ab"), new Diff(EQUAL, "cd"), new Diff(DELETE, "e"), new Diff(EQUAL, "f"), new Diff(INSERT, "g")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Backpass elimination.", diffList(new Diff(DELETE, "abcdef"), new Diff(INSERT, "cdfg")), diffs); - - diffs = diffList(new Diff(INSERT, "1"), new Diff(EQUAL, "A"), new Diff(DELETE, "B"), new Diff(INSERT, "2"), new Diff(EQUAL, "_"), new Diff(INSERT, "1"), new Diff(EQUAL, "A"), new Diff(DELETE, "B"), new Diff(INSERT, "2")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Multiple elimination.", diffList(new Diff(DELETE, "AB_AB"), new Diff(INSERT, "1A2_1A2")), diffs); - - diffs = diffList(new Diff(EQUAL, "The c"), new Diff(DELETE, "ow and the c"), new Diff(EQUAL, "at.")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Word boundaries.", diffList(new Diff(EQUAL, "The "), new Diff(DELETE, "cow and the "), new Diff(EQUAL, "cat.")), diffs); - - diffs = diffList(new Diff(DELETE, "abcxx"), new Diff(INSERT, "xxdef")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: No overlap elimination.", diffList(new Diff(DELETE, "abcxx"), new Diff(INSERT, "xxdef")), diffs); - - diffs = diffList(new Diff(DELETE, "abcxxx"), new Diff(INSERT, "xxxdef")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Overlap elimination.", diffList(new Diff(DELETE, "abc"), new Diff(EQUAL, "xxx"), new Diff(INSERT, "def")), diffs); - - diffs = diffList(new Diff(DELETE, "xxxabc"), new Diff(INSERT, "defxxx")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Reverse overlap elimination.", diffList(new Diff(INSERT, "def"), new Diff(EQUAL, "xxx"), new Diff(DELETE, "abc")), diffs); - - diffs = diffList(new Diff(DELETE, "abcd1212"), new Diff(INSERT, "1212efghi"), new Diff(EQUAL, "----"), new Diff(DELETE, "A3"), new Diff(INSERT, "3BC")); - dmp.diff_cleanupSemantic(diffs); - assertEquals("diff_cleanupSemantic: Two overlap eliminations.", diffList(new Diff(DELETE, "abcd"), new Diff(EQUAL, "1212"), new Diff(INSERT, "efghi"), new Diff(EQUAL, "----"), new Diff(DELETE, "A"), new Diff(EQUAL, "3"), new Diff(INSERT, "BC")), diffs); - } - - public void testDiffCleanupEfficiency() { - // Cleanup operationally trivial equalities. - dmp.Diff_EditCost = 4; - LinkedList diffs = diffList(); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: Null case.", diffList(), diffs); - System.out.println(dmp.diff_prettyHtml(diffs)); - - diffs = diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "12"), new Diff(EQUAL, "wxyz"), new Diff(DELETE, "cd"), new Diff(INSERT, "34")); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: No elimination.", diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "12"), new Diff(EQUAL, "wxyz"), new Diff(DELETE, "cd"), new Diff(INSERT, "34")), diffs); - System.out.println(dmp.diff_prettyHtml(diffs)); - - diffs = diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "12"), new Diff(EQUAL, "xyz"), new Diff(DELETE, "cd"), new Diff(INSERT, "34")); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: Four-edit elimination.", diffList(new Diff(DELETE, "abxyzcd"), new Diff(INSERT, "12xyz34")), diffs); - System.out.println(dmp.diff_prettyHtml(diffs)); - - diffs = diffList(new Diff(INSERT, "12"), new Diff(EQUAL, "x"), new Diff(DELETE, "cd"), new Diff(INSERT, "34")); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: Three-edit elimination.", diffList(new Diff(DELETE, "xcd"), new Diff(INSERT, "12x34")), diffs); - System.out.println(dmp.diff_prettyHtml(diffs)); - - diffs = diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "12"), new Diff(EQUAL, "xy"), new Diff(INSERT, "34"), new Diff(EQUAL, "z"), new Diff(DELETE, "cd"), new Diff(INSERT, "56")); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: Backpass elimination.", diffList(new Diff(DELETE, "abxyzcd"), new Diff(INSERT, "12xy34z56")), diffs); - System.out.println(dmp.diff_prettyHtml(diffs)); - - dmp.Diff_EditCost = 5; - diffs = diffList(new Diff(DELETE, "ab"), new Diff(INSERT, "12"), new Diff(EQUAL, "wxyz"), new Diff(DELETE, "cd"), new Diff(INSERT, "34")); - dmp.diff_cleanupEfficiency(diffs); - assertEquals("diff_cleanupEfficiency: High cost elimination.", diffList(new Diff(DELETE, "abwxyzcd"), new Diff(INSERT, "12wxyz34")), diffs); - dmp.Diff_EditCost = 4; - System.out.println(dmp.diff_prettyHtml(diffs)); - } - - public void testDiffPrettyHtml() { - // Pretty print. - LinkedList diffs = diffList(new Diff(EQUAL, "a\n"), new Diff(DELETE, "b"), new Diff(INSERT, "c&d")); - assertEquals("diff_prettyHtml:", "
<B>b</B>c&d", dmp.diff_prettyHtml(diffs)); - } - - public void testDiffText() { - // Compute the source and destination texts. - LinkedList diffs = diffList(new Diff(EQUAL, "jump"), new Diff(DELETE, "s"), new Diff(INSERT, "ed"), new Diff(EQUAL, " over "), new Diff(DELETE, "the"), new Diff(INSERT, "a"), new Diff(EQUAL, " lazy")); - assertEquals("diff_text1:", "jumps over the lazy", dmp.diff_text1(diffs)); - assertEquals("diff_text2:", "jumped over a lazy", dmp.diff_text2(diffs)); - } - - public void testDiffDelta() { - // Convert a diff into delta string. - LinkedList diffs = diffList(new Diff(EQUAL, "jump"), new Diff(DELETE, "s"), new Diff(INSERT, "ed"), new Diff(EQUAL, " over "), new Diff(DELETE, "the"), new Diff(INSERT, "a"), new Diff(EQUAL, " lazy"), new Diff(INSERT, "old dog")); - String text1 = dmp.diff_text1(diffs); - assertEquals("diff_text1: Base text.", "jumps over the lazy", text1); - - String delta = dmp.diff_toDelta(diffs); - assertEquals("diff_toDelta:", "=4\t-1\t+ed\t=6\t-3\t+a\t=5\t+old dog", delta); - - // Convert delta string into a diff. - assertEquals("diff_fromDelta: Normal.", diffs, dmp.diff_fromDelta(text1, delta)); - - // Generates error (19 < 20). - try { - dmp.diff_fromDelta(text1 + "x", delta); - fail("diff_fromDelta: Too long."); - } catch (IllegalArgumentException ex) { - // Exception expected. - } - - // Generates error (19 > 18). - try { - dmp.diff_fromDelta(text1.substring(1), delta); - fail("diff_fromDelta: Too short."); - } catch (IllegalArgumentException ex) { - // Exception expected. - } - - // Generates error (%c3%xy invalid Unicode). - try { - dmp.diff_fromDelta("", "+%c3%xy"); - fail("diff_fromDelta: Invalid character."); - } catch (IllegalArgumentException ex) { - // Exception expected. - } - - // Test deltas with special characters. - diffs = diffList(new Diff(EQUAL, "\u0680 \000 \t %"), new Diff(DELETE, "\u0681 \001 \n ^"), new Diff(INSERT, "\u0682 \002 \\ |")); - text1 = dmp.diff_text1(diffs); - assertEquals("diff_text1: Unicode text.", "\u0680 \000 \t %\u0681 \001 \n ^", text1); - - delta = dmp.diff_toDelta(diffs); - assertEquals("diff_toDelta: Unicode.", "=7\t-7\t+%DA%82 %02 %5C %7C", delta); - - assertEquals("diff_fromDelta: Unicode.", diffs, dmp.diff_fromDelta(text1, delta)); - - // Verify pool of unchanged characters. - diffs = diffList(new Diff(INSERT, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ")); - String text2 = dmp.diff_text2(diffs); - assertEquals("diff_text2: Unchanged characters.", "A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", text2); - - delta = dmp.diff_toDelta(diffs); - assertEquals("diff_toDelta: Unchanged characters.", "+A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", delta); - - // Convert delta string into a diff. - assertEquals("diff_fromDelta: Unchanged characters.", diffs, dmp.diff_fromDelta("", delta)); - } - - public void testDiffXIndex() { - // Translate a location in text1 to text2. - LinkedList diffs = diffList(new Diff(DELETE, "a"), new Diff(INSERT, "1234"), new Diff(EQUAL, "xyz")); - assertEquals("diff_xIndex: Translation on equality.", 5, dmp.diff_xIndex(diffs, 2)); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "1234"), new Diff(EQUAL, "xyz")); - assertEquals("diff_xIndex: Translation on deletion.", 1, dmp.diff_xIndex(diffs, 3)); - } - - public void testDiffLevenshtein() { - LinkedList diffs = diffList(new Diff(DELETE, "abc"), new Diff(INSERT, "1234"), new Diff(EQUAL, "xyz")); - assertEquals("Levenshtein with trailing equality.", 4, dmp.diff_levenshtein(diffs)); - - diffs = diffList(new Diff(EQUAL, "xyz"), new Diff(DELETE, "abc"), new Diff(INSERT, "1234")); - assertEquals("Levenshtein with leading equality.", 4, dmp.diff_levenshtein(diffs)); - - diffs = diffList(new Diff(DELETE, "abc"), new Diff(EQUAL, "xyz"), new Diff(INSERT, "1234")); - assertEquals("Levenshtein with middle equality.", 7, dmp.diff_levenshtein(diffs)); - } - - public void testDiffBisect() { - // Normal. - String a = "cat"; - String b = "map"; - // Since the resulting diff hasn't been normalized, it would be ok if - // the insertion and deletion pairs are swapped. - // If the order changes, tweak this test as required. - LinkedList diffs = diffList(new Diff(DELETE, "c"), new Diff(INSERT, "m"), new Diff(EQUAL, "a"), new Diff(DELETE, "t"), new Diff(INSERT, "p")); - assertEquals("diff_bisect: Normal.", diffs, dmp.diff_bisect(a, b, Long.MAX_VALUE)); - - // Timeout. - diffs = diffList(new Diff(DELETE, "cat"), new Diff(INSERT, "map")); - assertEquals("diff_bisect: Timeout.", diffs, dmp.diff_bisect(a, b, 0)); - } - - public void testDiffMain() { - // Perform a trivial diff. - LinkedList diffs = diffList(); - assertEquals("diff_main: Null case.", diffs, dmp.diff_main("", "", false)); - - diffs = diffList(new Diff(EQUAL, "abc")); - assertEquals("diff_main: Equality.", diffs, dmp.diff_main("abc", "abc", false)); - - diffs = diffList(new Diff(EQUAL, "ab"), new Diff(INSERT, "123"), new Diff(EQUAL, "c")); - assertEquals("diff_main: Simple insertion.", diffs, dmp.diff_main("abc", "ab123c", false)); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "123"), new Diff(EQUAL, "bc")); - assertEquals("diff_main: Simple deletion.", diffs, dmp.diff_main("a123bc", "abc", false)); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(INSERT, "123"), new Diff(EQUAL, "b"), new Diff(INSERT, "456"), new Diff(EQUAL, "c")); - assertEquals("diff_main: Two insertions.", diffs, dmp.diff_main("abc", "a123b456c", false)); - - diffs = diffList(new Diff(EQUAL, "a"), new Diff(DELETE, "123"), new Diff(EQUAL, "b"), new Diff(DELETE, "456"), new Diff(EQUAL, "c")); - assertEquals("diff_main: Two deletions.", diffs, dmp.diff_main("a123b456c", "abc", false)); - - // Perform a real diff. - // Switch off the timeout. - dmp.Diff_Timeout = 0; - diffs = diffList(new Diff(DELETE, "a"), new Diff(INSERT, "b")); - assertEquals("diff_main: Simple case #1.", diffs, dmp.diff_main("a", "b", false)); - - diffs = diffList(new Diff(DELETE, "Apple"), new Diff(INSERT, "Banana"), new Diff(EQUAL, "s are a"), new Diff(INSERT, "lso"), new Diff(EQUAL, " fruit.")); - assertEquals("diff_main: Simple case #2.", diffs, dmp.diff_main("Apples are a fruit.", "Bananas are also fruit.", false)); - - diffs = diffList(new Diff(DELETE, "a"), new Diff(INSERT, "\u0680"), new Diff(EQUAL, "x"), new Diff(DELETE, "\t"), new Diff(INSERT, "\000")); - assertEquals("diff_main: Simple case #3.", diffs, dmp.diff_main("ax\t", "\u0680x\000", false)); - - diffs = diffList(new Diff(DELETE, "1"), new Diff(EQUAL, "a"), new Diff(DELETE, "y"), new Diff(EQUAL, "b"), new Diff(DELETE, "2"), new Diff(INSERT, "xab")); - assertEquals("diff_main: Overlap #1.", diffs, dmp.diff_main("1ayb2", "abxab", false)); - - diffs = diffList(new Diff(INSERT, "xaxcx"), new Diff(EQUAL, "abc"), new Diff(DELETE, "y")); - assertEquals("diff_main: Overlap #2.", diffs, dmp.diff_main("abcy", "xaxcxabc", false)); - - diffs = diffList(new Diff(DELETE, "ABCD"), new Diff(EQUAL, "a"), new Diff(DELETE, "="), new Diff(INSERT, "-"), new Diff(EQUAL, "bcd"), new Diff(DELETE, "="), new Diff(INSERT, "-"), new Diff(EQUAL, "efghijklmnopqrs"), new Diff(DELETE, "EFGHIJKLMNOefg")); - assertEquals("diff_main: Overlap #3.", diffs, dmp.diff_main("ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg", "a-bcd-efghijklmnopqrs", false)); - - diffs = diffList(new Diff(INSERT, " "), new Diff(EQUAL, "a"), new Diff(INSERT, "nd"), new Diff(EQUAL, " [[Pennsylvania]]"), new Diff(DELETE, " and [[New")); - assertEquals("diff_main: Large equality.", diffs, dmp.diff_main("a [[Pennsylvania]] and [[New", " and [[Pennsylvania]]", false)); - - dmp.Diff_Timeout = 0.1f; // 100ms - String a = "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"; - String b = "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"; - // Increase the text lengths by 1024 times to ensure a timeout. - for (int x = 0; x < 10; x++) { - a = a + a; - b = b + b; - } - long startTime = System.currentTimeMillis(); - dmp.diff_main(a, b); - long endTime = System.currentTimeMillis(); - // Test that we took at least the timeout period. - assertTrue("diff_main: Timeout min.", dmp.Diff_Timeout * 1000 <= endTime - startTime); - // Test that we didn't take forever (be forgiving). - // Theoretically this test could fail very occasionally if the - // OS task swaps or locks up for a second at the wrong moment. - assertTrue("diff_main: Timeout max.", dmp.Diff_Timeout * 1000 * 2 > endTime - startTime); - dmp.Diff_Timeout = 0; - - // Test the linemode speedup. - // Must be long to pass the 100 char cutoff. - a = "1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n"; - b = "abcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\nabcdefghij\n"; - assertEquals("diff_main: Simple line-mode.", dmp.diff_main(a, b, true), dmp.diff_main(a, b, false)); - - a = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; - b = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"; - assertEquals("diff_main: Single line-mode.", dmp.diff_main(a, b, true), dmp.diff_main(a, b, false)); - - a = "1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n1234567890\n"; - b = "abcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n1234567890\n1234567890\n1234567890\nabcdefghij\n"; - String[] texts_linemode = diff_rebuildtexts(dmp.diff_main(a, b, true)); - String[] texts_textmode = diff_rebuildtexts(dmp.diff_main(a, b, false)); - assertArrayEquals("diff_main: Overlap line-mode.", texts_textmode, texts_linemode); - - // Test null inputs. - try { - dmp.diff_main(null, null); - fail("diff_main: Null inputs."); - } catch (IllegalArgumentException ex) { - // Error expected. - } - } - - - // MATCH TEST FUNCTIONS - - - public void testMatchAlphabet() { - // Initialise the bitmasks for Bitap. - Map bitmask; - bitmask = new HashMap(); - bitmask.put('a', 4); bitmask.put('b', 2); bitmask.put('c', 1); - assertEquals("match_alphabet: Unique.", bitmask, dmp.match_alphabet("abc")); - - bitmask = new HashMap(); - bitmask.put('a', 37); bitmask.put('b', 18); bitmask.put('c', 8); - assertEquals("match_alphabet: Duplicates.", bitmask, dmp.match_alphabet("abcaba")); - } - - public void testMatchBitap() { - // Bitap algorithm. - dmp.Match_Distance = 100; - dmp.Match_Threshold = 0.5f; - assertEquals("match_bitap: Exact match #1.", 5, dmp.match_bitap("abcdefghijk", "fgh", 5)); - - assertEquals("match_bitap: Exact match #2.", 5, dmp.match_bitap("abcdefghijk", "fgh", 0)); - - assertEquals("match_bitap: Fuzzy match #1.", 4, dmp.match_bitap("abcdefghijk", "efxhi", 0)); - - assertEquals("match_bitap: Fuzzy match #2.", 2, dmp.match_bitap("abcdefghijk", "cdefxyhijk", 5)); - - assertEquals("match_bitap: Fuzzy match #3.", -1, dmp.match_bitap("abcdefghijk", "bxy", 1)); - - assertEquals("match_bitap: Overflow.", 2, dmp.match_bitap("123456789xx0", "3456789x0", 2)); - - assertEquals("match_bitap: Before start match.", 0, dmp.match_bitap("abcdef", "xxabc", 4)); - - assertEquals("match_bitap: Beyond end match.", 3, dmp.match_bitap("abcdef", "defyy", 4)); - - assertEquals("match_bitap: Oversized pattern.", 0, dmp.match_bitap("abcdef", "xabcdefy", 0)); - - dmp.Match_Threshold = 0.4f; - assertEquals("match_bitap: Threshold #1.", 4, dmp.match_bitap("abcdefghijk", "efxyhi", 1)); - - dmp.Match_Threshold = 0.3f; - assertEquals("match_bitap: Threshold #2.", -1, dmp.match_bitap("abcdefghijk", "efxyhi", 1)); - - dmp.Match_Threshold = 0.0f; - assertEquals("match_bitap: Threshold #3.", 1, dmp.match_bitap("abcdefghijk", "bcdef", 1)); - - dmp.Match_Threshold = 0.5f; - assertEquals("match_bitap: Multiple select #1.", 0, dmp.match_bitap("abcdexyzabcde", "abccde", 3)); - - assertEquals("match_bitap: Multiple select #2.", 8, dmp.match_bitap("abcdexyzabcde", "abccde", 5)); - - dmp.Match_Distance = 10; // Strict location. - assertEquals("match_bitap: Distance test #1.", -1, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); - - assertEquals("match_bitap: Distance test #2.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdxxefg", 1)); - - dmp.Match_Distance = 1000; // Loose location. - assertEquals("match_bitap: Distance test #3.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); - } - - public void testMatchMain() { - // Full match. - assertEquals("match_main: Equality.", 0, dmp.match_main("abcdef", "abcdef", 1000)); - - assertEquals("match_main: Null text.", -1, dmp.match_main("", "abcdef", 1)); - - assertEquals("match_main: Null pattern.", 3, dmp.match_main("abcdef", "", 3)); - - assertEquals("match_main: Exact match.", 3, dmp.match_main("abcdef", "de", 3)); - - assertEquals("match_main: Beyond end match.", 3, dmp.match_main("abcdef", "defy", 4)); - - assertEquals("match_main: Oversized pattern.", 0, dmp.match_main("abcdef", "abcdefy", 0)); - - dmp.Match_Threshold = 0.7f; - assertEquals("match_main: Complex match.", 4, dmp.match_main("I am the very model of a modern major general.", " that berry ", 5)); - dmp.Match_Threshold = 0.5f; - - // Test null inputs. - try { - dmp.match_main(null, null, 0); - fail("match_main: Null inputs."); - } catch (IllegalArgumentException ex) { - // Error expected. - } - } - - - // PATCH TEST FUNCTIONS - - - public void testPatchObj() { - // Patch Object. - Patch p = new Patch(); - p.start1 = 20; - p.start2 = 21; - p.length1 = 18; - p.length2 = 17; - p.diffs = diffList(new Diff(EQUAL, "jump"), new Diff(DELETE, "s"), new Diff(INSERT, "ed"), new Diff(EQUAL, " over "), new Diff(DELETE, "the"), new Diff(INSERT, "a"), new Diff(EQUAL, "\nlaz")); - String strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n"; - assertEquals("Patch: toString.", strp, p.toString()); - } - - public void testPatchFromText() { - assertTrue("patch_fromText: #0.", dmp.patch_fromText("").isEmpty()); - - String strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n"; - assertEquals("patch_fromText: #1.", strp, dmp.patch_fromText(strp).get(0).toString()); - - assertEquals("patch_fromText: #2.", "@@ -1 +1 @@\n-a\n+b\n", dmp.patch_fromText("@@ -1 +1 @@\n-a\n+b\n").get(0).toString()); - - assertEquals("patch_fromText: #3.", "@@ -1,3 +0,0 @@\n-abc\n", dmp.patch_fromText("@@ -1,3 +0,0 @@\n-abc\n").get(0).toString()); - - assertEquals("patch_fromText: #4.", "@@ -0,0 +1,3 @@\n+abc\n", dmp.patch_fromText("@@ -0,0 +1,3 @@\n+abc\n").get(0).toString()); - - // Generates error. - try { - dmp.patch_fromText("Bad\nPatch\n"); - fail("patch_fromText: #5."); - } catch (IllegalArgumentException ex) { - // Exception expected. - } - } - - public void testPatchToText() { - String strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"; - List patches; - patches = dmp.patch_fromText(strp); - assertEquals("patch_toText: Single.", strp, dmp.patch_toText(patches)); - - strp = "@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n tes\n"; - patches = dmp.patch_fromText(strp); - assertEquals("patch_toText: Dual.", strp, dmp.patch_toText(patches)); - } - - public void testPatchAddContext() { - dmp.Patch_Margin = 4; - Patch p; - p = dmp.patch_fromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n").get(0); - dmp.patch_addContext(p, "The quick brown fox jumps over the lazy dog."); - assertEquals("patch_addContext: Simple case.", "@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n", p.toString()); - - p = dmp.patch_fromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n").get(0); - dmp.patch_addContext(p, "The quick brown fox jumps."); - assertEquals("patch_addContext: Not enough trailing context.", "@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.toString()); - - p = dmp.patch_fromText("@@ -3 +3,2 @@\n-e\n+at\n").get(0); - dmp.patch_addContext(p, "The quick brown fox jumps."); - assertEquals("patch_addContext: Not enough leading context.", "@@ -1,7 +1,8 @@\n Th\n-e\n+at\n qui\n", p.toString()); - - p = dmp.patch_fromText("@@ -3 +3,2 @@\n-e\n+at\n").get(0); - dmp.patch_addContext(p, "The quick brown fox jumps. The quick brown fox crashes."); - assertEquals("patch_addContext: Ambiguity.", "@@ -1,27 +1,28 @@\n Th\n-e\n+at\n quick brown fox jumps. \n", p.toString()); - } - - public void testPatchMake() { - LinkedList patches; - patches = dmp.patch_make("", ""); - assertEquals("patch_make: Null case.", "", dmp.patch_toText(patches)); - - String text1 = "The quick brown fox jumps over the lazy dog."; - String text2 = "That quick brown fox jumped over a lazy dog."; - String expectedPatch = "@@ -1,8 +1,7 @@\n Th\n-at\n+e\n qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n over \n-a\n+the\n laz\n"; - // The second patch must be "-21,17 +21,18", not "-22,17 +21,18" due to rolling context. - patches = dmp.patch_make(text2, text1); - assertEquals("patch_make: Text2+Text1 inputs.", expectedPatch, dmp.patch_toText(patches)); - - expectedPatch = "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"; - patches = dmp.patch_make(text1, text2); - assertEquals("patch_make: Text1+Text2 inputs.", expectedPatch, dmp.patch_toText(patches)); - - LinkedList diffs = dmp.diff_main(text1, text2, false); - patches = dmp.patch_make(diffs); - assertEquals("patch_make: Diff input.", expectedPatch, dmp.patch_toText(patches)); - - patches = dmp.patch_make(text1, diffs); - assertEquals("patch_make: Text1+Diff inputs.", expectedPatch, dmp.patch_toText(patches)); - - patches = dmp.patch_make("`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?"); - assertEquals("patch_toText: Character encoding.", "@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n", dmp.patch_toText(patches)); - - diffs = diffList(new Diff(DELETE, "`1234567890-=[]\\;',./"), new Diff(INSERT, "~!@#$%^&*()_+{}|:\"<>?")); - assertEquals("patch_fromText: Character decoding.", diffs, dmp.patch_fromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n").get(0).diffs); - - text1 = ""; - for (int x = 0; x < 100; x++) { - text1 += "abcdef"; - } - text2 = text1 + "123"; - expectedPatch = "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"; - patches = dmp.patch_make(text1, text2); - assertEquals("patch_make: Long string with repeats.", expectedPatch, dmp.patch_toText(patches)); - - // Test null inputs. - try { - dmp.patch_make(null); - fail("patch_make: Null inputs."); - } catch (IllegalArgumentException ex) { - // Error expected. - } - } - - public void testPatchSplitMax() { - // Assumes that Match_MaxBits is 32. - LinkedList patches; - patches = dmp.patch_make("abcdefghijklmnopqrstuvwxyz01234567890", "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0"); - dmp.patch_splitMax(patches); - assertEquals("patch_splitMax: #1.", "@@ -1,32 +1,46 @@\n+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\n uv\n+X\n wx\n+X\n yz\n+X\n 012345\n@@ -25,13 +39,18 @@\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n", dmp.patch_toText(patches)); - - patches = dmp.patch_make("abcdef1234567890123456789012345678901234567890123456789012345678901234567890uvwxyz", "abcdefuvwxyz"); - String oldToText = dmp.patch_toText(patches); - dmp.patch_splitMax(patches); - assertEquals("patch_splitMax: #2.", oldToText, dmp.patch_toText(patches)); - - patches = dmp.patch_make("1234567890123456789012345678901234567890123456789012345678901234567890", "abc"); - dmp.patch_splitMax(patches); - assertEquals("patch_splitMax: #3.", "@@ -1,32 +1,4 @@\n-1234567890123456789012345678\n 9012\n@@ -29,32 +1,4 @@\n-9012345678901234567890123456\n 7890\n@@ -57,14 +1,3 @@\n-78901234567890\n+abc\n", dmp.patch_toText(patches)); - - patches = dmp.patch_make("abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1", "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1"); - dmp.patch_splitMax(patches); - assertEquals("patch_splitMax: #4.", "@@ -2,32 +2,32 @@\n bcdefghij , h : \n-0\n+1\n , t : 1 abcdef\n@@ -29,32 +29,32 @@\n bcdefghij , h : \n-0\n+1\n , t : 1 abcdef\n", dmp.patch_toText(patches)); - } - - public void testPatchAddPadding() { - LinkedList patches; - patches = dmp.patch_make("", "test"); - assertEquals("patch_addPadding: Both edges full.", "@@ -0,0 +1,4 @@\n+test\n", dmp.patch_toText(patches)); - dmp.patch_addPadding(patches); - assertEquals("patch_addPadding: Both edges full.", "@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n", dmp.patch_toText(patches)); - - patches = dmp.patch_make("XY", "XtestY"); - assertEquals("patch_addPadding: Both edges partial.", "@@ -1,2 +1,6 @@\n X\n+test\n Y\n", dmp.patch_toText(patches)); - dmp.patch_addPadding(patches); - assertEquals("patch_addPadding: Both edges partial.", "@@ -2,8 +2,12 @@\n %02%03%04X\n+test\n Y%01%02%03\n", dmp.patch_toText(patches)); - - patches = dmp.patch_make("XXXXYYYY", "XXXXtestYYYY"); - assertEquals("patch_addPadding: Both edges none.", "@@ -1,8 +1,12 @@\n XXXX\n+test\n YYYY\n", dmp.patch_toText(patches)); - dmp.patch_addPadding(patches); - assertEquals("patch_addPadding: Both edges none.", "@@ -5,8 +5,12 @@\n XXXX\n+test\n YYYY\n", dmp.patch_toText(patches)); - } - - public void testPatchApply() { - dmp.Match_Distance = 1000; - dmp.Match_Threshold = 0.5f; - dmp.Patch_DeleteThreshold = 0.5f; - LinkedList patches; - patches = dmp.patch_make("", ""); - Object[] results = dmp.patch_apply(patches, "Hello world."); - boolean[] boolArray = (boolean[]) results[1]; - String resultStr = results[0] + "\t" + boolArray.length; - assertEquals("patch_apply: Null case.", "Hello world.\t0", resultStr); - - patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog."); - results = dmp.patch_apply(patches, "The quick brown fox jumps over the lazy dog."); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Exact match.", "That quick brown fox jumped over a lazy dog.\ttrue\ttrue", resultStr); - - results = dmp.patch_apply(patches, "The quick red rabbit jumps over the tired tiger."); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Partial match.", "That quick red rabbit jumped over a tired tiger.\ttrue\ttrue", resultStr); - - results = dmp.patch_apply(patches, "I am the very model of a modern major general."); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Failed match.", "I am the very model of a modern major general.\tfalse\tfalse", resultStr); - - patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); - results = dmp.patch_apply(patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Big delete, small change.", "xabcy\ttrue\ttrue", resultStr); - - patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); - results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Big delete, big change 1.", "xabc12345678901234567890---------------++++++++++---------------12345678901234567890y\tfalse\ttrue", resultStr); - - dmp.Patch_DeleteThreshold = 0.6f; - patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); - results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Big delete, big change 2.", "xabcy\ttrue\ttrue", resultStr); - dmp.Patch_DeleteThreshold = 0.5f; - - // Compensate for failed patch. - dmp.Match_Threshold = 0.0f; - dmp.Match_Distance = 0; - patches = dmp.patch_make("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890"); - results = dmp.patch_apply(patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; - assertEquals("patch_apply: Compensate for failed patch.", "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tfalse\ttrue", resultStr); - dmp.Match_Threshold = 0.5f; - dmp.Match_Distance = 1000; - - patches = dmp.patch_make("", "test"); - String patchStr = dmp.patch_toText(patches); - dmp.patch_apply(patches, ""); - assertEquals("patch_apply: No side effects.", patchStr, dmp.patch_toText(patches)); - - patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "Woof"); - patchStr = dmp.patch_toText(patches); - dmp.patch_apply(patches, "The quick brown fox jumps over the lazy dog."); - assertEquals("patch_apply: No side effects with major delete.", patchStr, dmp.patch_toText(patches)); - - patches = dmp.patch_make("", "test"); - results = dmp.patch_apply(patches, ""); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0]; - assertEquals("patch_apply: Edge exact match.", "test\ttrue", resultStr); - - patches = dmp.patch_make("XY", "XtestY"); - results = dmp.patch_apply(patches, "XY"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0]; - assertEquals("patch_apply: Near edge exact match.", "XtestY\ttrue", resultStr); - - patches = dmp.patch_make("y", "y123"); - results = dmp.patch_apply(patches, "x"); - boolArray = (boolean[]) results[1]; - resultStr = results[0] + "\t" + boolArray[0]; - assertEquals("patch_apply: Edge partial match.", "x123\ttrue", resultStr); - } - - private void assertArrayEquals(String error_msg, Object[] a, Object[] b) { - List list_a = Arrays.asList(a); - List list_b = Arrays.asList(b); - assertEquals(error_msg, list_a, list_b); - } - - private void assertLinesToCharsResultEquals(String error_msg, - LinesToCharsResult a, LinesToCharsResult b) { - assertEquals(error_msg, a.chars1, b.chars1); - assertEquals(error_msg, a.chars2, b.chars2); - assertEquals(error_msg, a.lineArray, b.lineArray); - } - - // Construct the two texts which made up the diff originally. - private static String[] diff_rebuildtexts(LinkedList diffs) { - String[] text = {"", ""}; - for (Diff myDiff : diffs) { - if (myDiff.operation != diff_match_patch.Operation.INSERT) { - text[0] += myDiff.text; - } - if (myDiff.operation != diff_match_patch.Operation.DELETE) { - text[1] += myDiff.text; - } - } - return text; - } - - // Private function for quickly building lists of diffs. - private static LinkedList diffList(Diff... diffs) { - LinkedList myDiffList = new LinkedList(); - for (Diff myDiff : diffs) { - myDiffList.add(myDiff); - } - return myDiffList; - } - - public static void assertEquals(String message, Object expected, Object actual) { -// System.out.println(message + " " + expected + " " + actual); - Assert.assertEquals(message, expected, actual); - } - public static void assertEquals(String message, String expected, String actual) { -// System.out.println(message + " " + expected + " " + actual); - Assert.assertEquals(message, expected, actual); - } - - public static void main(String[] args) { - diff_match_patch_test d = new diff_match_patch_test(); - d.setUp(); - d.testDiffCleanupEfficiency(); - } - -} diff --git a/modules/core/db/core.erm b/modules/core/db/core.erm index f5c8af9f..3e152639 100644 --- a/modules/core/db/core.erm +++ b/modules/core/db/core.erm @@ -11,8 +11,8 @@ 0 1.0 - 531 - 1945 + 109 + 1843 128 128 @@ -791,6 +791,22 @@ dict_value varchar(n) + + ed5ac38bb6330b7ce8daaa76475ac87c6e1f7e4c + null + null + false + null + false + false + false + + false + + 新旧数据比较结果 + diff_modify_data + clob + 329bbb76f0884117ace79bb686695f4e9cb120b6 300 @@ -1431,6 +1447,22 @@ is_attac character(n) + + e889df5da9a251b18e384fc428bb2654cdda9310 + 1 + null + false + null + false + false + false + + false + + 是否异常 + is_exception + character(n) + 5224ef38946585af8ba22f294756ffaecb434ddc 1 @@ -1720,8 +1752,8 @@ nvarchar(n) - 1656c73df4466012ab837df13e760b030caa7ce8 - 1 + e05fe9078021fb5b026eefac77069bc0b2d13c56 + 50 null false null @@ -1733,7 +1765,7 @@ 日志类型 日志类型 log_type - character(n) + varchar(n) a349e3aeee90969e1e0c7f6ad8481b209eb691f3 @@ -13240,6 +13272,423 @@ + + d666c509d068f3dabf0fba21897bba87ecd883c4 + 170 + 269 + Segoe UI + 9 + 1112 + 2034 + + 128 + 128 + 192 + + + + dcb09f95b0ac0ddaef78794ac3fa636075cc7152 + e991c3c26f1883475a23693afa7c3cd6a4cef394 + d666c509d068f3dabf0fba21897bba87ecd883c4 + -1 + -1 + -1 + -1 + + 0 + 0 + 0 + + 1..n + 1 + true + + RESTRICT + RESTRICT + null + null + + + js_sys_job_log + 作业调度日志表 + + + + + + + 869fc70cf3a4e92e8056b40814df8e03f9f9efde + 9382e4d59004f8f437199ae02d75645c714ed23f + + + + + varchar(n) + + + false + false + true + true + false + + + + + + + + + + + false + false + false + + + 0 + + + + 6d5f3e5ef4d28e57966c33c4b4ef424f1dc42b7b + 55c7d0a9ab8650c264a75bb1bf958cac2fe68152 + dcb09f95b0ac0ddaef78794ac3fa636075cc7152 + + + + + varchar(n) + + + false + true + true + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + 91110163a8a31ee61a4153360707026b5498dd65 + 443772d4627c23aef484c324c8e431121b921a44 + dcb09f95b0ac0ddaef78794ac3fa636075cc7152 + + + + + varchar(n) + + + false + true + true + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + 8afadc1ddabcb75c4b83d8bef5401cd464ddb03b + 3e80df782a38bab9e765399dfd0343f568b4d9b7 + + + + + varchar(n) + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + 728962f9a8c15fa620380b1e8bbb54a9b386ce72 + 81bc4d9e8dad3d9348f2c71eb3c600e4594f1316 + + + + + varchar(n) + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + 78a5e7f85b6c82e0032ba56579b661b0971a46c8 + 6ed5757124ebbe8c4839b820b2418e840d14bb89 + + + + + varchar(n) + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + e889df5da9a251b18e384fc428bb2654cdda9310 + 0b9a8fee0730362310d5c0e58a67ea01e2d5d722 + + + + + character(n) + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + d903f31236ff7a6701ff92a19986146ace84c236 + 81d875aad67d3c4ada7aa5d5972a120957d18221 + + + + + clob + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + da64f182d5dd75b3fc0eaaf8ee1aed8e3d57aa41 + 2aa75821064814ccb859d75d5c59616e9949cae2 + + + + + timestamp + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + + + + + false + true + idx_sys_job_log_jn + + + + + 6d5f3e5ef4d28e57966c33c4b4ef424f1dc42b7b + false + + + + + false + true + idx_sys_job_log_jg + + + + + 91110163a8a31ee61a4153360707026b5498dd65 + false + + + + + false + true + idx_sys_job_log_t + + + + + 3e80df782a38bab9e765399dfd0343f568b4d9b7 + false + + + + + false + true + idx_sys_job_log_e + + + + + 81bc4d9e8dad3d9348f2c71eb3c600e4594f1316 + false + + + + + false + true + idx_sys_job_log_ie + + + + + 0b9a8fee0730362310d5c0e58a67ea01e2d5d722 + false + + + + + + + + + +
2074919cbcf9f3c311ec3d7e27d331e2a3cfa883443 @@ -13296,13 +13745,13 @@ - 1656c73df4466012ab837df13e760b030caa7ce8 + e05fe9078021fb5b026eefac77069bc0b2d13c56 a03e633748bfae8eae5aa92ae432469d3130afb4 - character(n) + varchar(n) false @@ -13559,6 +14008,39 @@ 0 + + ed5ac38bb6330b7ce8daaa76475ac87c6e1f7e4c + adcd4f96b525c65bc0d1f9ab2f20d70498760da8 + + + + + clob + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + 667704664e4b88b145cebda0d6a1fbafb53525f0 8f891169da270ac3ad6f57020764868821524aa8 @@ -13691,6 +14173,39 @@ 0 + + e889df5da9a251b18e384fc428bb2654cdda9310 + 186bf2bddf5b4fb9ce835106138d47adb1bebc9e + + + + + character(n) + + + false + false + false + false + false + + + + + + + + + + + false + false + false + + + 0 + + d903f31236ff7a6701ff92a19986146ace84c236 cce47a5de15237ce22ef226c5d652d9d0eeab8ce @@ -13891,325 +14406,19 @@ - - - - - - -
- - d666c509d068f3dabf0fba21897bba87ecd883c4 - 170 - 269 - Segoe UI - 9 - 1112 - 2034 - - 128 - 128 - 192 - - - - e1a2f005527fd14e5cff72541625da54bf76faf6 - e991c3c26f1883475a23693afa7c3cd6a4cef394 - d666c509d068f3dabf0fba21897bba87ecd883c4 - -1 - -1 - -1 - -1 - - 0 - 0 - 0 - - 1..n - 1 - true - - RESTRICT - RESTRICT - null - null - - - js_sys_job_log - 作业调度日志表 - - - - - - - 869fc70cf3a4e92e8056b40814df8e03f9f9efde - 9382e4d59004f8f437199ae02d75645c714ed23f + + false + true + idx_sys_log_ie + - - - - varchar(n) - - - false - false - true - true - false - - - - - - - - - - - false - false - false - - - 0 - - - - 6d5f3e5ef4d28e57966c33c4b4ef424f1dc42b7b - 55c7d0a9ab8650c264a75bb1bf958cac2fe68152 - e1a2f005527fd14e5cff72541625da54bf76faf6 - - - - - varchar(n) - - - false - true - true - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - 91110163a8a31ee61a4153360707026b5498dd65 - 443772d4627c23aef484c324c8e431121b921a44 - e1a2f005527fd14e5cff72541625da54bf76faf6 - - - - - varchar(n) - - - false - true - true - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - 8afadc1ddabcb75c4b83d8bef5401cd464ddb03b - 3e80df782a38bab9e765399dfd0343f568b4d9b7 - - - - - varchar(n) - - - false - false - false - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - 728962f9a8c15fa620380b1e8bbb54a9b386ce72 - 81bc4d9e8dad3d9348f2c71eb3c600e4594f1316 - - - - - varchar(n) - - - false - false - false - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - 78a5e7f85b6c82e0032ba56579b661b0971a46c8 - 6ed5757124ebbe8c4839b820b2418e840d14bb89 - - - - - varchar(n) - - - false - false - false - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - d903f31236ff7a6701ff92a19986146ace84c236 - 81d875aad67d3c4ada7aa5d5972a120957d18221 - - - - - clob - - - false - false - false - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - da64f182d5dd75b3fc0eaaf8ee1aed8e3d57aa41 - 2aa75821064814ccb859d75d5c59616e9949cae2 - - - - - timestamp - - - false - false - false - false - false - - - - - - - - - - - false - false - false - - - 0 - - - - + + + 186bf2bddf5b4fb9ce835106138d47adb1bebc9e + false + + + diff --git a/modules/core/db/oracle/core.sql b/modules/core/db/oracle/core.sql index eb32e488..2770f7cf 100644 --- a/modules/core/db/oracle/core.sql +++ b/modules/core/db/oracle/core.sql @@ -39,6 +39,11 @@ DROP INDEX idx_sys_file_biz_ud; DROP INDEX idx_sys_file_biz_bt; DROP INDEX idx_sys_file_biz_bk; DROP INDEX idx_sys_job_status; +DROP INDEX idx_sys_job_log_jn; +DROP INDEX idx_sys_job_log_jg; +DROP INDEX idx_sys_job_log_t; +DROP INDEX idx_sys_job_log_e; +DROP INDEX idx_sys_job_log_ie; DROP INDEX idx_sys_lang_code; DROP INDEX idx_sys_lang_type; DROP INDEX idx_sys_log_cd; @@ -46,6 +51,7 @@ DROP INDEX idx_sys_log_cc; DROP INDEX idx_sys_log_lt; DROP INDEX idx_sys_log_bk; DROP INDEX idx_sys_log_bt; +DROP INDEX idx_sys_log_ie; DROP INDEX idx_sys_menu_pc; DROP INDEX idx_sys_menu_ts; DROP INDEX idx_sys_menu_status; @@ -411,6 +417,7 @@ CREATE TABLE js_sys_job_log job_type varchar2(50), job_event varchar2(200), job_message varchar2(500), + is_exception char(1), exception_info clob, create_date timestamp, PRIMARY KEY (id) @@ -438,7 +445,7 @@ CREATE TABLE js_sys_lang CREATE TABLE js_sys_log ( id varchar2(64) NOT NULL, - log_type char(1) NOT NULL, + log_type varchar2(50) NOT NULL, log_title nvarchar2(500) NOT NULL, create_by varchar2(64) NOT NULL, create_by_name nvarchar2(100) NOT NULL, @@ -446,10 +453,12 @@ CREATE TABLE js_sys_log request_uri nvarchar2(255), request_method varchar2(10), request_params clob, + diff_modify_data clob, biz_key varchar2(64), biz_type varchar2(64), remote_addr varchar2(255) NOT NULL, server_addr varchar2(255) NOT NULL, + is_exception char(1), exception_info clob, user_agent nvarchar2(500), device_name varchar2(100), @@ -888,6 +897,11 @@ CREATE INDEX idx_sys_file_biz_ud ON js_sys_file_upload (update_date); CREATE INDEX idx_sys_file_biz_bt ON js_sys_file_upload (biz_type); CREATE INDEX idx_sys_file_biz_bk ON js_sys_file_upload (biz_key); CREATE INDEX idx_sys_job_status ON js_sys_job (status); +CREATE INDEX idx_sys_job_log_jn ON js_sys_job_log (job_name); +CREATE INDEX idx_sys_job_log_jg ON js_sys_job_log (job_group); +CREATE INDEX idx_sys_job_log_t ON js_sys_job_log (job_type); +CREATE INDEX idx_sys_job_log_e ON js_sys_job_log (job_event); +CREATE INDEX idx_sys_job_log_ie ON js_sys_job_log (is_exception); CREATE INDEX idx_sys_lang_code ON js_sys_lang (lang_code); CREATE INDEX idx_sys_lang_type ON js_sys_lang (lang_type); CREATE INDEX idx_sys_log_cd ON js_sys_log (create_by); @@ -895,6 +909,7 @@ CREATE INDEX idx_sys_log_cc ON js_sys_log (corp_code); CREATE INDEX idx_sys_log_lt ON js_sys_log (log_type); CREATE INDEX idx_sys_log_bk ON js_sys_log (biz_key); CREATE INDEX idx_sys_log_bt ON js_sys_log (biz_type); +CREATE INDEX idx_sys_log_ie ON js_sys_log (is_exception); CREATE INDEX idx_sys_menu_pc ON js_sys_menu (parent_code); CREATE INDEX idx_sys_menu_ts ON js_sys_menu (tree_sort); CREATE INDEX idx_sys_menu_status ON js_sys_menu (status); @@ -1157,6 +1172,7 @@ COMMENT ON COLUMN js_sys_job_log.job_group IS '任务组名'; COMMENT ON COLUMN js_sys_job_log.job_type IS '日志类型'; COMMENT ON COLUMN js_sys_job_log.job_event IS '日志事件'; COMMENT ON COLUMN js_sys_job_log.job_message IS '日志信息'; +COMMENT ON COLUMN js_sys_job_log.is_exception IS '是否异常'; COMMENT ON COLUMN js_sys_job_log.exception_info IS '异常信息'; COMMENT ON COLUMN js_sys_job_log.create_date IS '创建时间'; COMMENT ON TABLE js_sys_lang IS '国际化语言'; @@ -1180,10 +1196,12 @@ COMMENT ON COLUMN js_sys_log.create_date IS '创建时间'; COMMENT ON COLUMN js_sys_log.request_uri IS '请求URI'; COMMENT ON COLUMN js_sys_log.request_method IS '操作方式'; COMMENT ON COLUMN js_sys_log.request_params IS '操作提交的数据'; +COMMENT ON COLUMN js_sys_log.diff_modify_data IS '新旧数据比较结果'; COMMENT ON COLUMN js_sys_log.biz_key IS '业务主键'; COMMENT ON COLUMN js_sys_log.biz_type IS '业务类型'; COMMENT ON COLUMN js_sys_log.remote_addr IS '操作IP地址'; COMMENT ON COLUMN js_sys_log.server_addr IS '请求服务器地址'; +COMMENT ON COLUMN js_sys_log.is_exception IS '是否异常'; COMMENT ON COLUMN js_sys_log.exception_info IS '异常信息'; COMMENT ON COLUMN js_sys_log.user_agent IS '用户代理'; COMMENT ON COLUMN js_sys_log.device_name IS '设备名称/操作系统'; diff --git a/modules/core/src/main/java/com/jeesite/common/shiro/filter/LogoutFilter.java b/modules/core/src/main/java/com/jeesite/common/shiro/filter/LogoutFilter.java index 9e5804bf..e17c567d 100644 --- a/modules/core/src/main/java/com/jeesite/common/shiro/filter/LogoutFilter.java +++ b/modules/core/src/main/java/com/jeesite/common/shiro/filter/LogoutFilter.java @@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory; import com.jeesite.common.config.Global; import com.jeesite.common.web.http.ServletUtils; +import com.jeesite.modules.sys.entity.Log; import com.jeesite.modules.sys.utils.LogUtils; /** @@ -35,7 +36,7 @@ public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter //try/catch added for SHIRO-298: try { // 记录用户退出日志 - LogUtils.saveLog(ServletUtils.getRequest(), "系统退出"); + LogUtils.saveLog(ServletUtils.getRequest(), "系统退出", Log.TYPE_LOGIN_LOGOUT); // 退出登录 subject.logout(); } catch (SessionException ise) { diff --git a/modules/core/src/main/java/com/jeesite/common/shiro/realm/AuthorizingRealm.java b/modules/core/src/main/java/com/jeesite/common/shiro/realm/AuthorizingRealm.java index 53dcd3e3..ddf756b3 100644 --- a/modules/core/src/main/java/com/jeesite/common/shiro/realm/AuthorizingRealm.java +++ b/modules/core/src/main/java/com/jeesite/common/shiro/realm/AuthorizingRealm.java @@ -5,12 +5,15 @@ package com.jeesite.common.shiro.realm; import java.util.Map; +import javax.servlet.http.HttpServletRequest; + import org.apache.shiro.subject.PrincipalCollection; import com.jeesite.common.codec.EncodeUtils; import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.web.http.ServletUtils; import com.jeesite.modules.sys.entity.EmpUser; +import com.jeesite.modules.sys.entity.Log; import com.jeesite.modules.sys.entity.User; import com.jeesite.modules.sys.service.EmpUserService; import com.jeesite.modules.sys.service.UserService; @@ -55,13 +58,13 @@ public class AuthorizingRealm extends com.jeesite.common.shiro.realm.BaseAuthori userService.updateUserLoginInfo(user); // 记录用户登录日志 - LogUtils.saveLog(ServletUtils.getRequest(), "系统登录"); + LogUtils.saveLog(ServletUtils.getRequest(), "系统登录", Log.TYPE_LOGIN_LOGOUT); } @Override - public void onLogoutSuccess(User logoutUser) { + public void onLogoutSuccess(User logoutUser, HttpServletRequest request) { // 记录用户退出日志 - LogUtils.saveLog(logoutUser, null, null, null, "系统退出"); + LogUtils.saveLog(logoutUser, request, null, null, "系统退出", Log.TYPE_LOGIN_LOGOUT); } public void setUserService(UserService userService) { diff --git a/web/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java b/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java similarity index 85% rename from web/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java rename to modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java index 5ef2d134..aba834dd 100644 --- a/web/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java +++ b/modules/core/src/main/java/com/jeesite/modules/config/web/DruidStatConfig.java @@ -3,6 +3,7 @@ */ package com.jeesite.modules.config.web; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; @@ -17,6 +18,7 @@ import com.alibaba.druid.support.http.WebStatFilter; * @version 2017年11月30日 */ @Configuration +@ConditionalOnProperty(name="druid.stat.enabled", havingValue="true", matchIfMissing=true) public class DruidStatConfig { /** diff --git a/web/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java b/modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java similarity index 57% rename from web/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java rename to modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java index 5f7e6701..b83324b8 100644 --- a/web/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java +++ b/modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/LogInterceptorConfig.java @@ -6,10 +6,12 @@ package com.jeesite.modules.config.web.interceptor; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import com.jeesite.common.config.Global; +import com.jeesite.common.lang.StringUtils; import com.jeesite.modules.sys.interceptor.LogInterceptor; /** @@ -24,17 +26,19 @@ public class LogInterceptorConfig extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new LogInterceptor()) - .addPathPatterns(Global.getAdminPath() + "/**") - .excludePathPatterns(Global.getAdminPath() + "/index") - .excludePathPatterns(Global.getAdminPath() + "/login") - .excludePathPatterns(Global.getAdminPath() + "/**/listData") - .excludePathPatterns(Global.getAdminPath() + "/**/treeData") - .excludePathPatterns(Global.getAdminPath() + "/file/**") - .excludePathPatterns(Global.getAdminPath() + "/tags/**") - .excludePathPatterns(Global.getAdminPath() + "/sys/log/**") - .excludePathPatterns(Global.getAdminPath() + "/sys/online/count") - ; + InterceptorRegistration registration = registry.addInterceptor(new LogInterceptor()); + String apps = Global.getProperty("web.interceptor.log.addPathPatterns"); + String epps = Global.getProperty("web.interceptor.log.excludePathPatterns"); + for (String uri : StringUtils.split(apps, ",")){ + if (StringUtils.isNotBlank(uri)){ + registration.addPathPatterns(StringUtils.trim(uri)); + } + } + for (String uri : StringUtils.split(epps, ",")){ + if (StringUtils.isNotBlank(uri)){ + registration.excludePathPatterns(StringUtils.trim(epps)); + } + } } } \ No newline at end of file diff --git a/web/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java b/modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java similarity index 51% rename from web/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java rename to modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java index f731f755..c16b02cc 100644 --- a/web/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java +++ b/modules/core/src/main/java/com/jeesite/modules/config/web/interceptor/MobileViewInterceptorConfig.java @@ -6,11 +6,13 @@ package com.jeesite.modules.config.web.interceptor; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import com.jeesite.common.config.Global; -import com.jeesite.modules.sys.interceptor.LogInterceptor; +import com.jeesite.common.lang.StringUtils; +import com.jeesite.modules.sys.interceptor.MobileInterceptor; /** * 前台自动切换到手机视图拦截器 @@ -19,14 +21,24 @@ import com.jeesite.modules.sys.interceptor.LogInterceptor; */ @Configuration @EnableWebMvc -@ConditionalOnProperty(name="web.interceptor.mobile.enabled", havingValue="true") +@ConditionalOnProperty(name="web.interceptor.mobile.enabled", havingValue="true", matchIfMissing=false) public class MobileViewInterceptorConfig extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new LogInterceptor()) - .addPathPatterns(Global.getFrontPath() + "/**") - ; + InterceptorRegistration registration = registry.addInterceptor(new MobileInterceptor()); + String apps = Global.getProperty("web.interceptor.mobile.addPathPatterns"); + String epps = Global.getProperty("web.interceptor.mobile.excludePathPatterns"); + for (String uri : StringUtils.split(apps, ",")){ + if (StringUtils.isNotBlank(uri)){ + registration.addPathPatterns(StringUtils.trim(uri)); + } + } + for (String uri : StringUtils.split(epps, ",")){ + if (StringUtils.isNotBlank(uri)){ + registration.excludePathPatterns(StringUtils.trim(epps)); + } + } } } \ No newline at end of file diff --git a/modules/core/src/main/java/com/jeesite/modules/db/InitCoreData.xlsx b/modules/core/src/main/java/com/jeesite/modules/db/InitCoreData.xlsx index b8c608ae..89932279 100644 Binary files a/modules/core/src/main/java/com/jeesite/modules/db/InitCoreData.xlsx and b/modules/core/src/main/java/com/jeesite/modules/db/InitCoreData.xlsx differ diff --git a/modules/core/src/main/java/com/jeesite/modules/sys/entity/Log.java b/modules/core/src/main/java/com/jeesite/modules/sys/entity/Log.java index 4cb769c8..6faf2ba8 100644 --- a/modules/core/src/main/java/com/jeesite/modules/sys/entity/Log.java +++ b/modules/core/src/main/java/com/jeesite/modules/sys/entity/Log.java @@ -1,243 +1,255 @@ -/** - * Copyright (c) 2013-Now http://jeesite.com All rights reserved. - */ -package com.jeesite.modules.sys.entity; - -import java.util.Map; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.hibernate.validator.constraints.Length; -import org.hibernate.validator.constraints.NotBlank; - -import com.jeesite.common.collect.MapUtils; -import com.jeesite.common.entity.BaseEntity; -import com.jeesite.common.entity.DataEntity; -import com.jeesite.common.lang.StringUtils; -import com.jeesite.common.mybatis.annotation.Column; -import com.jeesite.common.mybatis.annotation.Table; -import com.jeesite.common.mybatis.mapper.query.QueryType; -import com.jeesite.common.shiro.realm.LoginInfo; -import com.jeesite.modules.sys.utils.UserUtils; - -/** - * 操作日志Entity - * @author ThinkGem - * @version 2017-03-19 - */ -@Table(name="${_prefix}sys_log", alias="a", columns={ - @Column(includeEntity=BaseEntity.class), - @Column(name="id", attrName="id", label="编码", isPK=true), - @Column(name="log_type", attrName="logType", label="日志类型"), - @Column(name="log_title", attrName="logTitle", label="日志标题", queryType=QueryType.LIKE), - @Column(name="create_by", attrName="createBy.userCode", label="创建者", isUpdate=false), - @Column(name="create_by_name", attrName="createBy.userName", label="创建者名称", queryType=QueryType.LIKE), - @Column(name="create_date", attrName="createDate", label="创建时间", isUpdate=false, isQuery=false), - @Column(name="request_uri", attrName="requestUri", label="请求URI", queryType=QueryType.LIKE), - @Column(name="request_method", attrName="requestMethod", label="操作方式"), - @Column(name="request_params", attrName="requestParams", label="操作提交的数据", queryType=QueryType.LIKE), - @Column(name="biz_key", attrName="bizKey", label="业务主键"), - @Column(name="biz_type", attrName="bizType", label="业务类型"), - @Column(name="remote_addr", attrName="remoteAddr", label="操作IP地址"), - @Column(name="server_addr", attrName="serverAddr", label="请求服务器地址"), - @Column(name="exception_info", attrName="exceptionInfo", label="异常信息"), - @Column(name="user_agent", attrName="userAgent", label="用户代理"), - @Column(name="device_name", attrName="deviceName", label="设备名称/操作系统", queryType=QueryType.LIKE), - @Column(name="browser_name", attrName="browserName", label="浏览器名称", queryType=QueryType.LIKE), - }, orderBy="a.create_date DESC" -) -public class Log extends DataEntity { - - // 日志类型(1:接入日志;2:错误日志) - public static final String TYPE_ACCESS = "1"; - public static final String TYPE_EXCEPTION = "2"; - - private static final long serialVersionUID = 1L; - - private String logType; // 日志类型 - private String logTitle; // 日志标题 - private String requestUri; // 请求URI - private String requestMethod; // 操作方式 - private String requestParams; // 操作提交的数据 - private String bizKey; // 业务主键 - private String bizType; // 业务类型 - private String remoteAddr; // 操作IP地址 - private String serverAddr; // 请求服务器地址 - private String exceptionInfo; // 异常信息 - private String userAgent; // 用户代理 - private String deviceName; // 设备名称/操作系统 - private String browserName; // 浏览器名称 - - private Map paramsMap; // 操作提交的数据,临时存储用 - - public Log() { - this(null); - } - - public Log(String id){ - super(id); - } - - @NotBlank(message="日志类型不能为空") - @Length(min=0, max=1, message="日志类型长度不能超过 1 个字符") - public String getLogType() { - return logType; - } - - public void setLogType(String logType) { - this.logType = logType; - } - - @NotBlank(message="日志标题不能为空") - @Length(min=0, max=500, message="日志标题长度不能超过 500 个字符") - public String getLogTitle() { - return logTitle; - } - - public void setLogTitle(String logTitle) { - this.logTitle = logTitle; - } - - @Length(min=0, max=255, message="请求URI长度不能超过 255 个字符") - public String getRequestUri() { - LoginInfo p = UserUtils.getLoginInfo(); - if (p != null && "1".equals(p.getParam("l"))){ - return null; - } - return requestUri; - } - - public void setRequestUri(String requestUri) { - this.requestUri = requestUri; - } - - @Length(min=0, max=10, message="操作方式长度不能超过 10 个字符") - public String getRequestMethod() { - return requestMethod; - } - - public void setRequestMethod(String requestMethod) { - this.requestMethod = requestMethod; - } - - public String getRequestParams() { - return requestParams; - } - - public void setRequestParams(String requestParams) { - this.requestParams = requestParams; - } - - @Length(min=0, max=64, message="业务主键长度不能超过 64 个字符") - public String getBizKey() { - return bizKey; - } - - public void setBizKey(String bizKey) { - this.bizKey = bizKey; - } - - @Length(min=0, max=64, message="业务类型长度不能超过 64 个字符") - public String getBizType() { - return bizType; - } - - public void setBizType(String bizType) { - this.bizType = bizType; - } - - @NotBlank(message="操作IP地址不能为空") - @Length(min=0, max=255, message="操作IP地址长度不能超过 255 个字符") - public String getRemoteAddr() { - return remoteAddr; - } - - public void setRemoteAddr(String remoteAddr) { - this.remoteAddr = remoteAddr; - } - - @NotBlank(message="请求服务器地址不能为空") - @Length(min=0, max=255, message="请求服务器地址长度不能超过 255 个字符") - public String getServerAddr() { - return serverAddr; - } - - public void setServerAddr(String serverAddr) { - this.serverAddr = serverAddr; - } - - public String getExceptionInfo() { - return exceptionInfo; - } - - public void setExceptionInfo(String exceptionInfo) { - this.exceptionInfo = exceptionInfo; - } - - @Length(min=0, max=500, message="用户代理长度不能超过 500 个字符") - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } - - @Length(min=0, max=100, message="设备名称/操作系统长度不能超过 100 个字符") - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - @Length(min=0, max=100, message="浏览器名称长度不能超过 100 个字符") - public String getBrowserName() { - return browserName; - } - - public void setBrowserName(String browserName) { - this.browserName = browserName; - } - - /** - * 设置请求参数 - * @param paramMap - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public void setRequestParams(Map paramsMap){ - if (paramsMap == null){ - return; - } - if (this.paramsMap == null){ - this.paramsMap = MapUtils.newHashMap(); - } - StringBuilder params = new StringBuilder(); - for (Map.Entry param : ((Map)paramsMap).entrySet()){ - params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "="); - String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : ""); - params.append(StringUtils.abbr(StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "*" : paramValue, 1000)); - this.paramsMap.put(param.getKey(), param.getValue()); - } - this.requestParams = params.toString(); - } - - /** - * 根据名称获取参数(只有先执行setParams(Map)后才有效) - * @param name - * @return - */ - public String getRequestParam(String name) { - if (paramsMap == null){ - return null; - } - String[] values = (String[])paramsMap.get(name); - return values != null && values.length > 0 ? values[0] : null; - } - - @Override - public String toString() { - return ReflectionToStringBuilder.toString(this); - } - +/** + * Copyright (c) 2013-Now http://jeesite.com All rights reserved. + */ +package com.jeesite.modules.sys.entity; + +import java.util.Map; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.NotBlank; + +import com.jeesite.common.collect.MapUtils; +import com.jeesite.common.entity.BaseEntity; +import com.jeesite.common.entity.DataEntity; +import com.jeesite.common.lang.StringUtils; +import com.jeesite.common.mybatis.annotation.Column; +import com.jeesite.common.mybatis.annotation.Table; +import com.jeesite.common.mybatis.mapper.query.QueryType; +import com.jeesite.common.shiro.realm.LoginInfo; +import com.jeesite.modules.sys.utils.UserUtils; + +/** + * 操作日志Entity + * @author ThinkGem + * @version 2017-03-19 + */ +@Table(name="${_prefix}sys_log", alias="a", columns={ + @Column(includeEntity=BaseEntity.class), + @Column(name="id", attrName="id", label="编码", isPK=true), + @Column(name="log_type", attrName="logType", label="日志类型"), + @Column(name="log_title", attrName="logTitle", label="日志标题", queryType=QueryType.LIKE), + @Column(name="create_by", attrName="createBy.userCode", label="创建者", isUpdate=false), + @Column(name="create_by_name", attrName="createBy.userName", label="创建者名称", queryType=QueryType.LIKE), + @Column(name="create_date", attrName="createDate", label="创建时间", isUpdate=false, isQuery=false), + @Column(name="request_uri", attrName="requestUri", label="请求URI", queryType=QueryType.LIKE), + @Column(name="request_method", attrName="requestMethod", label="操作方式"), + @Column(name="request_params", attrName="requestParams", label="操作提交的数据", queryType=QueryType.LIKE), + @Column(name="biz_key", attrName="bizKey", label="业务主键"), + @Column(name="biz_type", attrName="bizType", label="业务类型"), + @Column(name="remote_addr", attrName="remoteAddr", label="操作IP地址"), + @Column(name="server_addr", attrName="serverAddr", label="请求服务器地址"), + @Column(name="is_exception", attrName="isException", label="是否异常"), + @Column(name="exception_info", attrName="exceptionInfo", label="异常信息"), + @Column(name="user_agent", attrName="userAgent", label="用户代理"), + @Column(name="device_name", attrName="deviceName", label="设备名称/操作系统", queryType=QueryType.LIKE), + @Column(name="browser_name", attrName="browserName", label="浏览器名称", queryType=QueryType.LIKE), + }, orderBy="a.create_date DESC" +) +public class Log extends DataEntity { + + // 日志类型(access:接入日志;update:修改日志;select:查询日志;loginLogout:登录登出;) + public static final String TYPE_ACCESS = "access"; + public static final String TYPE_UPDATE = "update"; + public static final String TYPE_SELECT = "select"; + public static final String TYPE_LOGIN_LOGOUT = "loginLogout"; + + private static final long serialVersionUID = 1L; + + private String logType; // 日志类型 + private String logTitle; // 日志标题 + private String requestUri; // 请求URI + private String requestMethod; // 操作方式 + private String requestParams; // 操作提交的数据 + private String bizKey; // 业务主键 + private String bizType; // 业务类型 + private String remoteAddr; // 操作IP地址 + private String serverAddr; // 请求服务器地址 + private String isException; // 是否有异常 + private String exceptionInfo; // 异常信息 + private String userAgent; // 用户代理 + private String deviceName; // 设备名称/操作系统 + private String browserName; // 浏览器名称 + + private Map paramsMap; // 操作提交的数据,临时存储用 + + public Log() { + this(null); + } + + public Log(String id){ + super(id); + } + + @NotBlank(message="日志类型不能为空") + @Length(min=0, max=1, message="日志类型长度不能超过 1 个字符") + public String getLogType() { + return logType; + } + + public void setLogType(String logType) { + this.logType = logType; + } + + @NotBlank(message="日志标题不能为空") + @Length(min=0, max=500, message="日志标题长度不能超过 500 个字符") + public String getLogTitle() { + return logTitle; + } + + public void setLogTitle(String logTitle) { + this.logTitle = logTitle; + } + + @Length(min=0, max=255, message="请求URI长度不能超过 255 个字符") + public String getRequestUri() { + LoginInfo p = UserUtils.getLoginInfo(); + if (p != null && "1".equals(p.getParam("l"))){ + return null; + } + return requestUri; + } + + public void setRequestUri(String requestUri) { + this.requestUri = requestUri; + } + + @Length(min=0, max=10, message="操作方式长度不能超过 10 个字符") + public String getRequestMethod() { + return requestMethod; + } + + public void setRequestMethod(String requestMethod) { + this.requestMethod = requestMethod; + } + + public String getRequestParams() { + return requestParams; + } + + public void setRequestParams(String requestParams) { + this.requestParams = requestParams; + } + + @Length(min=0, max=64, message="业务主键长度不能超过 64 个字符") + public String getBizKey() { + return bizKey; + } + + public void setBizKey(String bizKey) { + this.bizKey = bizKey; + } + + @Length(min=0, max=64, message="业务类型长度不能超过 64 个字符") + public String getBizType() { + return bizType; + } + + public void setBizType(String bizType) { + this.bizType = bizType; + } + + @NotBlank(message="操作IP地址不能为空") + @Length(min=0, max=255, message="操作IP地址长度不能超过 255 个字符") + public String getRemoteAddr() { + return remoteAddr; + } + + public void setRemoteAddr(String remoteAddr) { + this.remoteAddr = remoteAddr; + } + + @NotBlank(message="请求服务器地址不能为空") + @Length(min=0, max=255, message="请求服务器地址长度不能超过 255 个字符") + public String getServerAddr() { + return serverAddr; + } + + public void setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + } + + public String getIsException() { + return isException; + } + + public void setIsException(String isException) { + this.isException = isException; + } + + public String getExceptionInfo() { + return exceptionInfo; + } + + public void setExceptionInfo(String exceptionInfo) { + this.exceptionInfo = exceptionInfo; + } + + @Length(min=0, max=500, message="用户代理长度不能超过 500 个字符") + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + @Length(min=0, max=100, message="设备名称/操作系统长度不能超过 100 个字符") + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + @Length(min=0, max=100, message="浏览器名称长度不能超过 100 个字符") + public String getBrowserName() { + return browserName; + } + + public void setBrowserName(String browserName) { + this.browserName = browserName; + } + + /** + * 设置请求参数 + * @param paramMap + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void setRequestParams(Map paramsMap){ + if (paramsMap == null){ + return; + } + if (this.paramsMap == null){ + this.paramsMap = MapUtils.newHashMap(); + } + StringBuilder params = new StringBuilder(); + for (Map.Entry param : ((Map)paramsMap).entrySet()){ + params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "="); + String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : ""); + params.append(StringUtils.abbr(StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "*" : paramValue, 1000)); + this.paramsMap.put(param.getKey(), param.getValue()); + } + this.requestParams = params.toString(); + } + + /** + * 根据名称获取参数(只有先执行setParams(Map)后才有效) + * @param name + * @return + */ + public String getRequestParam(String name) { + if (paramsMap == null){ + return null; + } + String[] values = (String[])paramsMap.get(name); + return values != null && values.length > 0 ? values[0] : null; + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } + } \ No newline at end of file diff --git a/modules/core/src/main/java/com/jeesite/modules/sys/interceptor/LogInterceptor.java b/modules/core/src/main/java/com/jeesite/modules/sys/interceptor/LogInterceptor.java index e82b5b15..e66c8cd1 100644 --- a/modules/core/src/main/java/com/jeesite/modules/sys/interceptor/LogInterceptor.java +++ b/modules/core/src/main/java/com/jeesite/modules/sys/interceptor/LogInterceptor.java @@ -1,70 +1,71 @@ -/** - * Copyright (c) 2013-Now http://jeesite.com All rights reserved. - */ -package com.jeesite.modules.sys.interceptor; - -import java.text.SimpleDateFormat; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.core.NamedThreadLocal; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -import com.jeesite.common.lang.DateUtils; -import com.jeesite.common.lang.TimeUtils; -import com.jeesite.common.service.BaseService; -import com.jeesite.modules.sys.utils.LogUtils; - -/** - * 日志拦截器 - * @author ThinkGem - * @version 2014-8-19 - */ -public class LogInterceptor extends BaseService implements HandlerInterceptor { - - private static final ThreadLocal startTimeThreadLocal = - new NamedThreadLocal("ThreadLocal StartTime"); - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, - Object handler) throws Exception { - if (logger.isDebugEnabled()){ - long beginTime = System.currentTimeMillis();//1、开始时间 - startTimeThreadLocal.set(beginTime); //线程绑定变量(该数据只有当前请求的线程可见) - logger.debug("开始计时: {} URI: {}", new SimpleDateFormat("hh:mm:ss.SSS") - .format(beginTime), request.getRequestURI()); - } - return true; - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, - ModelAndView modelAndView) throws Exception { - if (modelAndView != null){ - logger.info("ViewName: " + modelAndView.getViewName() + " <<<<<<<<< " + request.getRequestURI() + " >>>>>>>>> " + handler); - } - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) throws Exception { - - // 保存日志 - LogUtils.saveLog(request, handler, ex, null); - - // 打印JVM信息。 - if (logger.isDebugEnabled()){ - long beginTime = startTimeThreadLocal.get();//得到线程绑定的局部变量(开始时间) - long endTime = System.currentTimeMillis(); //2、结束时间 - logger.debug("计时结束: {} 用时: {} URI: {} 最大内存: {}m 已分配内存: {}m 已分配内存中的剩余空间: {}m 最大可用内存: {}m", - DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(endTime - beginTime), - request.getRequestURI(), Runtime.getRuntime().maxMemory()/1024/1024, Runtime.getRuntime().totalMemory()/1024/1024, Runtime.getRuntime().freeMemory()/1024/1024, - (Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory())/1024/1024); - startTimeThreadLocal.remove(); //用完之后销毁线程变量数据 - } - - } - -} +/** + * Copyright (c) 2013-Now http://jeesite.com All rights reserved. + */ +package com.jeesite.modules.sys.interceptor; + +import java.text.SimpleDateFormat; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.core.NamedThreadLocal; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import com.jeesite.common.lang.DateUtils; +import com.jeesite.common.lang.TimeUtils; +import com.jeesite.common.service.BaseService; +import com.jeesite.modules.sys.utils.LogUtils; +import com.jeesite.modules.sys.utils.UserUtils; + +/** + * 日志拦截器 + * @author ThinkGem + * @version 2014-8-19 + */ +public class LogInterceptor extends BaseService implements HandlerInterceptor { + + private static final ThreadLocal startTimeThreadLocal = + new NamedThreadLocal("ThreadLocal StartTime"); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + if (logger.isDebugEnabled()){ + long beginTime = System.currentTimeMillis();//1、开始时间 + startTimeThreadLocal.set(beginTime); //线程绑定变量(该数据只有当前请求的线程可见) + logger.debug("开始计时: {} URI: {}", new SimpleDateFormat("hh:mm:ss.SSS") + .format(beginTime), request.getRequestURI()); + } + return true; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) throws Exception { + if (modelAndView != null){ + logger.info("ViewName: " + modelAndView.getViewName() + " <<<<<<<<< " + request.getRequestURI() + " >>>>>>>>> " + handler); + } + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception ex) throws Exception { + + // 保存日志 + LogUtils.saveLog(UserUtils.getUser(), request, handler, ex, null, null); + + // 打印JVM信息。 + if (logger.isDebugEnabled()){ + long beginTime = startTimeThreadLocal.get();//得到线程绑定的局部变量(开始时间) + long endTime = System.currentTimeMillis(); //2、结束时间 + logger.debug("计时结束: {} 用时: {} URI: {} 最大内存: {}m 已分配内存: {}m 已分配内存中的剩余空间: {}m 最大可用内存: {}m", + DateUtils.formatDate(endTime, "hh:mm:ss.SSS"), TimeUtils.formatDateAgo(endTime - beginTime), + request.getRequestURI(), Runtime.getRuntime().maxMemory()/1024/1024, Runtime.getRuntime().totalMemory()/1024/1024, Runtime.getRuntime().freeMemory()/1024/1024, + (Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory())/1024/1024); + startTimeThreadLocal.remove(); //用完之后销毁线程变量数据 + } + + } + +} diff --git a/modules/core/src/main/java/com/jeesite/modules/sys/utils/LogUtils.java b/modules/core/src/main/java/com/jeesite/modules/sys/utils/LogUtils.java index 8babdfeb..5478d285 100644 --- a/modules/core/src/main/java/com/jeesite/modules/sys/utils/LogUtils.java +++ b/modules/core/src/main/java/com/jeesite/modules/sys/utils/LogUtils.java @@ -1,210 +1,197 @@ -/** - * Copyright (c) 2013-Now http://jeesite.com All rights reserved. - */ -package com.jeesite.modules.sys.utils; - -import java.lang.reflect.Method; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.core.DefaultParameterNameDiscoverer; -import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.method.HandlerMethod; - -import com.jeesite.common.config.Global; -import com.jeesite.common.entity.BaseEntity; -import com.jeesite.common.lang.ExceptionUtils; -import com.jeesite.common.lang.StringUtils; -import com.jeesite.common.mybatis.annotation.Column; -import com.jeesite.common.mybatis.annotation.Table; -import com.jeesite.common.mybatis.mapper.MapperHelper; -import com.jeesite.common.network.IpUtils; -import com.jeesite.common.utils.SpringUtils; -import com.jeesite.common.web.http.ServletUtils; -import com.jeesite.common.web.http.UserAgentUtils; -import com.jeesite.modules.sys.entity.Log; -import com.jeesite.modules.sys.entity.User; -import com.jeesite.modules.sys.service.LogService; -import com.jeesite.modules.sys.service.MenuService; -import com.jeesite.modules.sys.utils.UserUtils; - -import eu.bitwalker.useragentutils.UserAgent; - -/** - * 字典工具类 - * @author ThinkGem - * @version 2014-11-7 - */ -public class LogUtils { - - /** - * 静态内部类,延迟加载,懒汉式,线程安全的单例模式 - */ - private static final class Static { - private static LogService logService = SpringUtils.getBean(LogService.class); - private static MenuService menuService = SpringUtils.getBean(MenuService.class); - } - - // 参数名获取工具(尝试获取标注为@ModelAttribute注解的方法,第一个参数名一般为主键名) - private static ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer(); - - /** - * 保存日志 - */ - public static void saveLog(String title){ - saveLog(null, null, null, title); - } - - /** - * 保存日志 - */ - public static void saveLog(HttpServletRequest request, String title){ - saveLog(request, null, null, title); - } - - /** - * 保存日志 - */ - public static void saveLog(HttpServletRequest request, Object handler, Exception ex, String title){ - saveLog(null, request, handler, ex, title); - } - - /** - * 保存日志 - */ - public static void saveLog(User user, HttpServletRequest request, Object handler, Exception ex, String title){ - if (user == null){ - user = UserUtils.getUser(); - } - if (request == null){ - request = ServletUtils.getRequest(); - } - if (request != null && user != null && StringUtils.isNotBlank(user.getUserCode())){ - Log log = new Log(); - log.setLogTitle(title); - Throwable throwable = ex != null ? ex : ExceptionUtils.getThrowable(request); - log.setLogType(throwable == null ? Log.TYPE_ACCESS : Log.TYPE_EXCEPTION); - log.setServerAddr(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); - log.setRemoteAddr(IpUtils.getRemoteAddr(request)); - UserAgent userAgent = UserAgentUtils.getUserAgent(request); - log.setDeviceName(userAgent.getOperatingSystem().getName()); - log.setBrowserName(userAgent.getBrowser().getName()); - log.setUserAgent(request.getHeader("User-Agent")); - log.setRequestUri(StringUtils.abbr(request.getRequestURI(), 255)); - log.setRequestParams(request.getParameterMap()); - log.setRequestMethod(request.getMethod()); - if (Global.isUseCorpModel()){ - log.setCorpCode(user.getCorpCode()); - log.setCorpName(user.getCorpName()); - } - log.setCurrentUser(user); - log.preInsert(); - - // 异步保存日志 - new SaveLogThread(log, handler, throwable).start(); - - } - } - /** - * 保存日志线程 - */ - public static class SaveLogThread extends Thread{ - - private Log log; - private Object handler; - private Throwable throwable; - - public SaveLogThread(Log log, Object handler, Throwable throwable){ - super(SaveLogThread.class.getSimpleName()); - this.log = log; - this.handler = handler; - this.throwable = throwable; - } - - @Override - public void run() { - // 获取日志标题 - if (StringUtils.isBlank(log.getLogTitle())){ - String permission = ""; - if (handler instanceof HandlerMethod){ - HandlerMethod hm = ((HandlerMethod)handler); - Method m = hm.getMethod(); - // 获取权限字符串 - RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class); - permission = (rp != null ? StringUtils.join(rp.value(), ",") : ""); - - // 尝试获取BaseEntity的设置的主键值 - for (Class type : m.getParameterTypes()){ - try { - // 判断是否是BaseEntity的子类 - Class superClass = type.getSuperclass(); - while(superClass != null && superClass != BaseEntity.class){ - superClass = superClass.getSuperclass(); - }; - // 如果是BaseEntity的子类,则获取主键名 - if (superClass != null){ - Table t = type.getAnnotation(Table.class); - for (Column c : t.columns()){ - if (c.isPK()){ - try { - String attrName = MapperHelper.getAttrName(c); - if (attrName != null){ - log.setBizKey(log.getRequestParam(attrName)); - } - } catch (Exception e) { - break; - } - } - } - } - } catch (Exception e) { - break; - } - } - - // 尝试获取标注为@ModelAttribute注解的方法,第一个参数名一般为主键名 - if (StringUtils.isBlank(log.getBizKey())){ - for (Method me : hm.getBeanType().getMethods()){ - ModelAttribute ma = AnnotationUtils.findAnnotation(me, ModelAttribute.class); - if(ma != null){ - String[] ps = pnd.getParameterNames(me); - if(ps != null && ps.length > 0){ - log.setBizKey(StringUtils.abbr(log.getRequestParam(ps[0]), 64)); - break; - } - } - } - } - - // 最后尝试获取参数为id的值 - if (StringUtils.isBlank(log.getBizKey())){ - log.setBizKey(log.getRequestParam("id")); - } - - } - log.setLogTitle(Static.menuService.getMenuNamePath(log.getRequestUri(), permission)); - } - if (StringUtils.isBlank(log.getLogTitle())){ - if (StringUtils.contains(log.getRequestParams(), "taskCommandInfo=")){ - log.setLogTitle("我的任务-任务办理"); - }else{ - log.setLogTitle("未知操作"); - } - } - // 如果有异常,设置异常信息(将异常对象转换为字符串) - log.setExceptionInfo(ExceptionUtils.getStackTraceAsString(throwable)); - // 如果无地址并无异常日志,则不保存信息 - if (StringUtils.isBlank(log.getRequestUri()) && StringUtils.isBlank(log.getExceptionInfo())){ - return; - } - // 保存日志信息 - log.setIsNewRecord(true); - Static.logService.insertLog(log); - - } - } - -} +/** + * Copyright (c) 2013-Now http://jeesite.com All rights reserved. + */ +package com.jeesite.modules.sys.utils; + +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.ibatis.mapping.SqlCommandType; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.core.DefaultParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.method.HandlerMethod; + +import com.jeesite.common.config.Global; +import com.jeesite.common.entity.BaseEntity; +import com.jeesite.common.lang.ExceptionUtils; +import com.jeesite.common.lang.ObjectUtils; +import com.jeesite.common.lang.StringUtils; +import com.jeesite.common.mybatis.annotation.Column; +import com.jeesite.common.mybatis.annotation.Table; +import com.jeesite.common.mybatis.mapper.MapperHelper; +import com.jeesite.common.network.IpUtils; +import com.jeesite.common.utils.SpringUtils; +import com.jeesite.common.web.http.UserAgentUtils; +import com.jeesite.modules.sys.entity.Log; +import com.jeesite.modules.sys.entity.User; +import com.jeesite.modules.sys.service.LogService; +import com.jeesite.modules.sys.service.MenuService; + +import eu.bitwalker.useragentutils.UserAgent; + +/** + * 字典工具类 + * @author ThinkGem + * @version 2014-11-7 + */ +public class LogUtils { + + /** + * 静态内部类,延迟加载,懒汉式,线程安全的单例模式 + */ + private static final class Static { + private static LogService logService = SpringUtils.getBean(LogService.class); + private static MenuService menuService = SpringUtils.getBean(MenuService.class); + } + + // 参数名获取工具(尝试获取标注为@ModelAttribute注解的方法,第一个参数名一般为主键名) + private static ParameterNameDiscoverer pnd = new DefaultParameterNameDiscoverer(); + + /** + * 保存日志 + */ + public static void saveLog(HttpServletRequest request, String logTitle, String logType){ + saveLog(UserUtils.getUser(), request, null, null, logTitle, logType); + } + + /** + * 保存日志 + */ + public static void saveLog(User user, HttpServletRequest request, Object handler, Exception ex, String logTitle, String logType){ + if (user == null || StringUtils.isBlank(user.getUserCode()) || request == null){ + return; + } + Log log = new Log(); + log.setLogTitle(logTitle); + log.setLogType(logType); + if (StringUtils.isBlank(log.getLogType())){ + String sqlCommandTypes = ObjectUtils.toString(request.getAttribute(SqlCommandType.class.getName())); + if (StringUtils.inString(","+sqlCommandTypes+",", ",INSERT,", ",UPDATE,", ",DELETE,")){ + log.setLogType(Log.TYPE_UPDATE); + }else if (StringUtils.inString(","+sqlCommandTypes+",", ",SELECT,")){ + log.setLogType(Log.TYPE_SELECT); + }else{ + log.setLogType(Log.TYPE_ACCESS); + } + } + log.setServerAddr(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); + log.setRemoteAddr(IpUtils.getRemoteAddr(request)); + UserAgent userAgent = UserAgentUtils.getUserAgent(request); + log.setDeviceName(userAgent.getOperatingSystem().getName()); + log.setBrowserName(userAgent.getBrowser().getName()); + log.setUserAgent(request.getHeader("User-Agent")); + log.setRequestUri(StringUtils.abbr(request.getRequestURI(), 255)); + log.setRequestParams(request.getParameterMap()); + log.setRequestMethod(request.getMethod()); + if (Global.isUseCorpModel()){ + log.setCorpCode(user.getCorpCode()); + log.setCorpName(user.getCorpName()); + } + log.setCurrentUser(user); + log.preInsert(); + + // 获取异常对象 + Throwable throwable = null; + if (ex != null){ + throwable = ExceptionUtils.getThrowable(request); + } + + // 异步保存日志 + new SaveLogThread(log, handler, throwable).start(); + } + /** + * 保存日志线程 + */ + public static class SaveLogThread extends Thread{ + + private Log log; + private Object handler; + private Throwable throwable; + + public SaveLogThread(Log log, Object handler, Throwable throwable){ + super(SaveLogThread.class.getSimpleName()); + this.log = log; + this.handler = handler; + this.throwable = throwable; + } + + @Override + public void run() { + // 获取日志标题 + if (StringUtils.isBlank(log.getLogTitle())){ + String permission = ""; + if (handler instanceof HandlerMethod){ + HandlerMethod hm = ((HandlerMethod)handler); + Method m = hm.getMethod(); + // 获取权限字符串 + RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class); + permission = (rp != null ? StringUtils.join(rp.value(), ",") : ""); + + // 尝试获取BaseEntity的设置的主键值 + for (Class type : m.getParameterTypes()){ + try { + // 判断是否是BaseEntity的子类 + Class superClass = type.getSuperclass(); + while(superClass != null && superClass != BaseEntity.class){ + superClass = superClass.getSuperclass(); + }; + // 如果是BaseEntity的子类,则获取主键名 + if (superClass != null){ + Table t = type.getAnnotation(Table.class); + for (Column c : t.columns()){ + if (c.isPK()){ + try { + String attrName = MapperHelper.getAttrName(c); + if (attrName != null){ + log.setBizKey(log.getRequestParam(attrName)); + } + } catch (Exception e) { + break; + } + } + } + } + } catch (Exception e) { + break; + } + } + + // 尝试获取标注为@ModelAttribute注解的方法,第一个参数名一般为主键名 + if (StringUtils.isBlank(log.getBizKey())){ + for (Method me : hm.getBeanType().getMethods()){ + ModelAttribute ma = AnnotationUtils.findAnnotation(me, ModelAttribute.class); + if(ma != null){ + String[] ps = pnd.getParameterNames(me); + if(ps != null && ps.length > 0){ + log.setBizKey(StringUtils.abbr(log.getRequestParam(ps[0]), 64)); + log.setBizType(me.getReturnType().getSimpleName()); + break; + } + } + } + } + } + log.setLogTitle(Static.menuService.getMenuNamePath(log.getRequestUri(), permission)); + } + if (StringUtils.isBlank(log.getLogTitle())){ + log.setLogTitle("未知操作"); + } + // 如果有异常,设置异常信息(将异常对象转换为字符串) + log.setExceptionInfo(throwable != null ? Global.YES : Global.NO); + log.setExceptionInfo(ExceptionUtils.getStackTraceAsString(throwable)); + // 如果无地址并无异常日志,则不保存信息 + if (StringUtils.isBlank(log.getRequestUri()) && StringUtils.isBlank(log.getExceptionInfo())){ + return; + } + // 保存日志信息 + log.setIsNewRecord(true); + Static.logService.insertLog(log); + + } + } + +} diff --git a/modules/core/src/main/resources/jeesite-core.yml b/modules/core/src/main/resources/jeesite-core.yml index 8eac8bf0..7270746a 100644 --- a/modules/core/src/main/resources/jeesite-core.yml +++ b/modules/core/src/main/resources/jeesite-core.yml @@ -56,9 +56,6 @@ jdbc: # 最大连接数 maxActive: 20 - # 表名前缀 - tablePrefix: js_ - # # 多数数据源名称列表,调用方式:DataSourceHolder.setDataSourceName("ds2") # dataSourceNames: ds2 # @@ -69,13 +66,23 @@ jdbc: # url: jdbc:oracle:thin:@127.0.0.1:1521/orcl # username: jeesite # password: jeesite -# encryptUsername: false -# encryptPassword: true +# testSql: ~ +# encrypt: +# username: false +# password: true # pool: # init: 1 # minIdle: 3 # maxActive: 20 + # 表名前缀 + tablePrefix: js_ + + # Druid连接池监控 + druid: + stat: + enabled: true + # Redis 配置 redis: @@ -353,11 +360,25 @@ web: # 后台管理日志记录拦截器 log: enabled: true + addPathPatterns: > + ${adminPath}/** + excludePathPatterns: > + ${adminPath}/index, + ${adminPath}/login, + ${adminPath}/**/listData, + ${adminPath}/**/treeData, + ${adminPath}/file/**, + ${adminPath}/tags/*, + ${adminPath}/sys/log/**, + ${adminPath}/sys/online/count # 前台自动切换到手机视图拦截器 mobile: enabled: false - + addPathPatterns: > + ${frontPath}/** + excludePathPatterns: ~ + # 静态文件后缀,过滤静态文件,以提高访问性能。 staticFile: .css,.js,.map,.png,.jpg,.gif,.jpeg,.bmp,.ico,.swf,.psd,.htc,.crx,.xpi,.exe,.ipa,.apk,.otf,.eot,.svg,.ttf,.woff,.woff2 diff --git a/modules/core/src/main/resources/logger-core.xml b/modules/core/src/main/resources/logger-core.xml index ee73705b..35cfa3a2 100644 --- a/modules/core/src/main/resources/logger-core.xml +++ b/modules/core/src/main/resources/logger-core.xml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/web/.settings/org.eclipse.jdt.core.prefs b/web/.settings/org.eclipse.jdt.core.prefs index 443e0859..6e80039d 100644 --- a/web/.settings/org.eclipse.jdt.core.prefs +++ b/web/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/web/.settings/org.eclipse.wst.common.project.facet.core.xml b/web/.settings/org.eclipse.wst.common.project.facet.core.xml index af7ced35..05642433 100644 --- a/web/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/web/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -2,6 +2,6 @@ - + diff --git a/web/pom.xml b/web/pom.xml index 03eb8ac1..d2632f6e 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -20,6 +20,9 @@ com.jeesite.modules.config.Application + + + 1.8 false false diff --git a/web/src/test/java/com/jeesite/test/InitCoreData.java b/web/src/test/java/com/jeesite/test/InitCoreData.java index 9ebcd9bd..d04a6b62 100644 --- a/web/src/test/java/com/jeesite/test/InitCoreData.java +++ b/web/src/test/java/com/jeesite/test/InitCoreData.java @@ -24,14 +24,14 @@ public class InitCoreData extends com.jeesite.modules.db.InitCoreData { initConfig(); initModule(); initDict(); - initRole(); - initMenu(); - initUser(); +// initRole(); +// initMenu(); +// initUser(); // initArea(); - initOffice(); - initCompany(); - initPost(); - initEmpUser(); +// initOffice(); +// initCompany(); +// initPost(); +// initEmpUser(); } }