|
@@ -0,0 +1,111 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const allNumReg = /^[0-9]+$/;
|
|
|
+const suffixNumReg = /[0-9]+$/;
|
|
|
+const mainReg = /^((GD*)|G)?(\d\d)*\d$/i;
|
|
|
+const subReg = /^((GD*)|G)?[A-Z]{2}(\d\d)+$/i;
|
|
|
+const gdXmjPartReg = /^((GD*)|G)/;
|
|
|
+// 路基、路面、涵洞、、桥梁、隧道、交通安全、隧道机电、绿化、其他、房建、专项评估
|
|
|
+const subXmjPrefixReplace = [
|
|
|
+ { str: 'LJ', num: '110', },
|
|
|
+ { str: 'LM', num: '120', },
|
|
|
+ { str: 'HD', num: '130', },
|
|
|
+ { str: 'TD', num: '140', },
|
|
|
+ { str: 'QL', num: '150', },
|
|
|
+ { str: 'SD', num: '160', },
|
|
|
+ { str: 'JA', num: '170', },
|
|
|
+ { str: 'SJ', num: '180', },
|
|
|
+ { str: 'LH', num: '190', },
|
|
|
+ { str: 'QT', num: '210', },
|
|
|
+ { str: 'FJ', num: '211', },
|
|
|
+ { str: 'ZP', num: '212', },
|
|
|
+];
|
|
|
+
|
|
|
+const findSubXmjPrefixNum = function (str) {
|
|
|
+ for (const p of subXmjPrefixReplace) {
|
|
|
+ if (str.indexOf(p.str) >= 0)
|
|
|
+ return p.num;
|
|
|
+ }
|
|
|
+ return '999';
|
|
|
+};
|
|
|
+
|
|
|
+const subXmjToNumStr = function (str) {
|
|
|
+ const num = str.match(suffixNumReg);
|
|
|
+ return findSubXmjPrefixNum(str) + (num ? num[0] : '') + (gdXmjPartReg.test(str) ? 1 : 0);
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ reg: {
|
|
|
+ mainXmj: mainReg,
|
|
|
+ subXmj: subReg,
|
|
|
+ gdXmjPartReg: gdXmjPartReg,
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 用于比较1-1类型项目节编号,或者202-1-a/202-2-3类型工程量清单
|
|
|
+ *
|
|
|
+ * @param str1
|
|
|
+ * @param str2
|
|
|
+ * @param symbol
|
|
|
+ */
|
|
|
+ defaultCompareCode: function (str1, str2, symbol = '-') {
|
|
|
+ if (!str1) {
|
|
|
+ return 1;
|
|
|
+ } else if (!str2) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ function compareSubCode(code1, code2) {
|
|
|
+ if (allNumReg.test(code1)) {
|
|
|
+ if (allNumReg.test(code2)) {
|
|
|
+ return parseInt(code1) - parseInt(code2);
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (allNumReg.test(code2)) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); // code1.localeCompare(code2);
|
|
|
+ }
|
|
|
+ const aCodes = str1.split(symbol),
|
|
|
+ bCodes = str2.split(symbol);
|
|
|
+ for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
|
|
|
+ const iCompare = compareSubCode(aCodes[i], bCodes[i]);
|
|
|
+ if (iCompare !== 0) {
|
|
|
+ return iCompare;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return aCodes.length - bCodes.length;
|
|
|
+ },
|
|
|
+ compare18MainXmj(str1, str2) {
|
|
|
+ if (str1.length < str2.length) {
|
|
|
+ return -1;
|
|
|
+ } else if (str1.length > str2.length) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ const num1 = str1.match(suffixNumReg)[0], num2 = str2.match(suffixNumReg)[0];
|
|
|
+ return num1.localeCompare(num2);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ compare18SubXmj(str1, str2) {
|
|
|
+ const numStr1 = subXmjToNumStr(str1), numStr2 = subXmjToNumStr(str2);
|
|
|
+ return numStr1.localeCompare(numStr2);
|
|
|
+ },
|
|
|
+ compareCode(str1, str2) {
|
|
|
+ if (mainReg.test(str1)) {
|
|
|
+ return this.compare18MainXmj(str1, str2);
|
|
|
+ }
|
|
|
+ if (subReg.test(str2)) {
|
|
|
+ return this.compare18SubXmj(str1, str2);
|
|
|
+ }
|
|
|
+ return this.defaultCompareCode(str1, str2);
|
|
|
+ }
|
|
|
+};
|