|
|
@@ -31,130 +31,137 @@ export async function GetMPSSchool(ctx) {
|
|
31
|
31
|
RowCount: ctx.query.RowCount || 4,
|
|
32
|
32
|
};
|
|
33
|
33
|
|
|
34
|
|
- // 生成缓存键
|
|
35
|
|
- const cacheKey = `GetMPSSchool?SchoolType1=${param.SchoolType1}&DistrictID=${param.DistrictID}&SelectType=${param.SelectType}&Key=${param.Key}&RowCount=${param.RowCount}&Usage=${param.Usage}`;
|
|
|
34
|
+ if (param.Key && !stringUtils.IsValidChineseNumberParentheses(param.Key)){
|
|
|
35
|
+ ctx.body = { errcode: 500, message: "获取学校列表失败" };
|
|
|
36
|
+ }
|
|
|
37
|
+ else{
|
|
36
|
38
|
|
|
37
|
|
- // 尝试从缓存获取
|
|
38
|
|
- let cachedData = await BufferMemoryClass.get(cacheKey);
|
|
39
|
|
- let result;
|
|
|
39
|
+ // 生成缓存键
|
|
|
40
|
+ const cacheKey = `GetMPSSchool?SchoolType1=${param.SchoolType1}&DistrictID=${param.DistrictID}&SelectType=${param.SelectType}&Key=${param.Key}&RowCount=${param.RowCount}&Usage=${param.Usage}`;
|
|
40
|
41
|
|
|
41
|
|
- if (!cachedData || cachedData.length === 0) {
|
|
42
|
|
- param.District = getDistrict(Number(param.DistrictID));
|
|
43
|
|
-
|
|
44
|
|
- let sql="SELECT ID,SchoolFullName,SchoolShortName,SchoolOtherName,SchoolNumber,SchoolType1,SchoolType2," +
|
|
45
|
|
- "SchoolType2Short,PublicOrPrivate,District,Address,Accommodation,Fees,ImageLogo,Pinyin,Coordinates " +
|
|
46
|
|
- "FROM kylx365_db.MPS_School where Flag=0";
|
|
47
|
|
- if (param.SchoolType1)
|
|
48
|
|
- sql+=" and SchoolType1='"+param.SchoolType1+"' ";
|
|
49
|
|
-
|
|
50
|
|
- if (param.Key) {
|
|
51
|
|
- if (stringUtils.IsNumber(param.Key)){
|
|
52
|
|
- sql+=" and ID="+param.Key+";";
|
|
|
42
|
+ // 尝试从缓存获取
|
|
|
43
|
+ let cachedData = await BufferMemoryClass.get(cacheKey);
|
|
|
44
|
+ let result;
|
|
|
45
|
+
|
|
|
46
|
+ if (!cachedData || cachedData.length === 0) {
|
|
|
47
|
+ param.District = getDistrict(Number(param.DistrictID));
|
|
|
48
|
+
|
|
|
49
|
+ let sql="SELECT ID,SchoolFullName,SchoolShortName,SchoolOtherName,SchoolNumber,SchoolType1,SchoolType2," +
|
|
|
50
|
+ "SchoolType2Short,PublicOrPrivate,District,Address,Accommodation,Fees,ImageLogo,Pinyin,Coordinates " +
|
|
|
51
|
+ "FROM kylx365_db.MPS_School where Flag=0";
|
|
|
52
|
+ if (param.SchoolType1)
|
|
|
53
|
+ sql+=" and SchoolType1='"+param.SchoolType1+"' ";
|
|
|
54
|
+
|
|
|
55
|
+ if (param.Key) {
|
|
|
56
|
+ if (stringUtils.IsNumber(param.Key)){
|
|
|
57
|
+ sql+=" and ID="+param.Key+";";
|
|
|
58
|
+ }
|
|
|
59
|
+ else{
|
|
|
60
|
+ sql += " and (SchoolFullName like '%" + param.Key + "%' or SchoolShortName like '%" + param.Key + "%' or SchoolOtherName like '%" + param.Key + "%' or SchoolNumber = '" + param.Key + "')"
|
|
|
61
|
+ if (Number(param.RowCount)>0)
|
|
|
62
|
+ sql+=" order by SchoolType1 desc,OrderID limit "+param.RowCount+";";
|
|
|
63
|
+ else
|
|
|
64
|
+ sql+=" order by SchoolType1 desc,OrderID;";
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
53
|
67
|
}
|
|
54
|
68
|
else{
|
|
55
|
|
- sql += " and (SchoolFullName like '%" + param.Key + "%' or SchoolShortName like '%" + param.Key + "%' or SchoolOtherName like '%" + param.Key + "%' or SchoolNumber = '" + param.Key + "')"
|
|
56
|
|
- if (Number(param.RowCount)>0)
|
|
57
|
|
- sql+=" order by SchoolType1 desc,OrderID limit "+param.RowCount+";";
|
|
58
|
|
- else
|
|
59
|
|
- sql+=" order by SchoolType1 desc,OrderID;";
|
|
60
|
|
- }
|
|
61
|
|
-
|
|
62
|
|
- }
|
|
63
|
|
- else{
|
|
64
|
|
- if (param.District)
|
|
65
|
|
- sql+=" and (District='"+param.District+"' or District='上海市')";
|
|
|
69
|
+ if (param.District)
|
|
|
70
|
+ sql+=" and (District='"+param.District+"' or District='上海市')";
|
|
66
|
71
|
|
|
67
|
|
- if (param.SchoolType1=="高中")
|
|
68
|
|
- if (param.SchoolType2Short=="市重点")
|
|
69
|
|
- sql+=" order by ID;";
|
|
|
72
|
+ if (param.SchoolType1=="高中")
|
|
|
73
|
+ if (param.SchoolType2Short=="市重点")
|
|
|
74
|
+ sql+=" order by ID;";
|
|
|
75
|
+ else
|
|
|
76
|
+ sql+=" order by CONVERT(SchoolFullName USING gbk);";
|
|
|
77
|
+ else if (param.Usage=="web")
|
|
|
78
|
+ sql+=" order by DistrictID,SchoolType2ShortID,ID;";
|
|
70
|
79
|
else
|
|
71
|
80
|
sql+=" order by CONVERT(SchoolFullName USING gbk);";
|
|
72
|
|
- else if (param.Usage=="web")
|
|
73
|
|
- sql+=" order by DistrictID,SchoolType2ShortID,ID;";
|
|
74
|
|
- else
|
|
75
|
|
- sql+=" order by CONVERT(SchoolFullName USING gbk);";
|
|
76
|
|
- }
|
|
|
81
|
+ }
|
|
77
|
82
|
|
|
78
|
|
- //console.log(sql);
|
|
79
|
|
-
|
|
80
|
|
- let list = await commonModel.RunSql({}, sql);
|
|
81
|
|
-
|
|
82
|
|
- if (param.SelectType === "structure") {
|
|
83
|
|
- let item=[];
|
|
84
|
|
- item.push({Name:"市重点",List:[]});
|
|
85
|
|
- item.push({Name:"区重点",List:[]});
|
|
86
|
|
- item.push({Name:"一般高中",List:[]});
|
|
87
|
|
- item.push({Name:"初中",List:[]});
|
|
88
|
|
-
|
|
89
|
|
- for(let i=0;i<list.length;i++){
|
|
90
|
|
- if (list[i].SchoolType1=="初中"){
|
|
91
|
|
- item[3].List.push(list[i]);
|
|
92
|
|
- }
|
|
93
|
|
- else if (list[i].SchoolType2Short=="市重点"){
|
|
94
|
|
- if (list[i].District=="上海市") {
|
|
95
|
|
- if (list[i].SchoolShortName=="上海中学" && param.DistrictID=="2")
|
|
96
|
|
- item[0].List.push(list[i]);
|
|
97
|
|
- else if (list[i].SchoolShortName=="交大附中" && param.DistrictID=="7")
|
|
98
|
|
- item[0].List.push(list[i]);
|
|
99
|
|
- else if (list[i].SchoolShortName=="复旦附中" && param.DistrictID=="7")
|
|
100
|
|
- item[0].List.push(list[i]);
|
|
101
|
|
- else if (list[i].SchoolShortName=="华师二附" && param.DistrictID=="11")
|
|
102
|
|
- item[0].List.push(list[i]);
|
|
103
|
|
- else if (list[i].SchoolShortName=="上师附中" && param.DistrictID=="11")
|
|
104
|
|
- item[0].List.push(list[i]);
|
|
105
|
|
- else if (list[i].SchoolShortName=="上海实验" && param.DistrictID=="11")
|
|
106
|
|
- item[0].List.push(list[i]);
|
|
107
|
|
- else if (list[i].SchoolShortName=="上外附中" && param.DistrictID=="11")
|
|
108
|
|
- item[0].List.push(list[i]);
|
|
|
83
|
+ //console.log(sql);
|
|
|
84
|
+
|
|
|
85
|
+ let list = await commonModel.RunSql({}, sql);
|
|
|
86
|
+
|
|
|
87
|
+ if (param.SelectType === "structure") {
|
|
|
88
|
+ let item=[];
|
|
|
89
|
+ item.push({Name:"市重点",List:[]});
|
|
|
90
|
+ item.push({Name:"区重点",List:[]});
|
|
|
91
|
+ item.push({Name:"一般高中",List:[]});
|
|
|
92
|
+ item.push({Name:"初中",List:[]});
|
|
|
93
|
+
|
|
|
94
|
+ for(let i=0;i<list.length;i++){
|
|
|
95
|
+ if (list[i].SchoolType1=="初中"){
|
|
|
96
|
+ item[3].List.push(list[i]);
|
|
|
97
|
+ }
|
|
|
98
|
+ else if (list[i].SchoolType2Short=="市重点"){
|
|
|
99
|
+ if (list[i].District=="上海市") {
|
|
|
100
|
+ if (list[i].SchoolShortName=="上海中学" && param.DistrictID=="2")
|
|
|
101
|
+ item[0].List.push(list[i]);
|
|
|
102
|
+ else if (list[i].SchoolShortName=="交大附中" && param.DistrictID=="7")
|
|
|
103
|
+ item[0].List.push(list[i]);
|
|
|
104
|
+ else if (list[i].SchoolShortName=="复旦附中" && param.DistrictID=="7")
|
|
|
105
|
+ item[0].List.push(list[i]);
|
|
|
106
|
+ else if (list[i].SchoolShortName=="华师二附" && param.DistrictID=="11")
|
|
|
107
|
+ item[0].List.push(list[i]);
|
|
|
108
|
+ else if (list[i].SchoolShortName=="上师附中" && param.DistrictID=="11")
|
|
|
109
|
+ item[0].List.push(list[i]);
|
|
|
110
|
+ else if (list[i].SchoolShortName=="上海实验" && param.DistrictID=="11")
|
|
|
111
|
+ item[0].List.push(list[i]);
|
|
|
112
|
+ else if (list[i].SchoolShortName=="上外附中" && param.DistrictID=="11")
|
|
|
113
|
+ item[0].List.push(list[i]);
|
|
109
|
114
|
|
|
|
115
|
+ }
|
|
|
116
|
+ else
|
|
|
117
|
+ item[0].List.push(list[i]);
|
|
110
|
118
|
}
|
|
111
|
|
- else
|
|
112
|
|
- item[0].List.push(list[i]);
|
|
113
|
|
- }
|
|
114
|
|
- else if (list[i].SchoolType2Short=="一般高中"){
|
|
115
|
|
- if (list[i].District=="上海市") {
|
|
116
|
|
- if (list[i].SchoolShortName=="上科大附校" && param.DistrictID=="11")
|
|
|
119
|
+ else if (list[i].SchoolType2Short=="一般高中"){
|
|
|
120
|
+ if (list[i].District=="上海市") {
|
|
|
121
|
+ if (list[i].SchoolShortName=="上科大附校" && param.DistrictID=="11")
|
|
|
122
|
+ item[2].List.push(list[i]);
|
|
|
123
|
+ }
|
|
|
124
|
+ else
|
|
117
|
125
|
item[2].List.push(list[i]);
|
|
118
|
126
|
}
|
|
119
|
|
- else
|
|
120
|
|
- item[2].List.push(list[i]);
|
|
121
|
|
- }
|
|
122
|
|
- else {
|
|
123
|
|
- item[1].List.push(list[i]);
|
|
|
127
|
+ else {
|
|
|
128
|
+ item[1].List.push(list[i]);
|
|
|
129
|
+ }
|
|
124
|
130
|
}
|
|
125
|
|
- }
|
|
126
|
|
- for (let j=0;j<4;j++) {
|
|
|
131
|
+ for (let j=0;j<4;j++) {
|
|
127
|
132
|
|
|
128
|
|
- item[j].List=_.orderBy(item[j].List, ['Pinyin','SchoolFullName'], ['asc','asc']);
|
|
|
133
|
+ item[j].List=_.orderBy(item[j].List, ['Pinyin','SchoolFullName'], ['asc','asc']);
|
|
129
|
134
|
|
|
130
|
|
- for (let i = 0; i < item[j].List.length; i++) {
|
|
131
|
|
- if (i > 0)
|
|
132
|
|
- item[j].List[i].Pinyin2 = item[j].List[i - 1].Pinyin;
|
|
133
|
|
- else
|
|
134
|
|
- item[j].List[i].Pinyin2 = "";
|
|
|
135
|
+ for (let i = 0; i < item[j].List.length; i++) {
|
|
|
136
|
+ if (i > 0)
|
|
|
137
|
+ item[j].List[i].Pinyin2 = item[j].List[i - 1].Pinyin;
|
|
|
138
|
+ else
|
|
|
139
|
+ item[j].List[i].Pinyin2 = "";
|
|
|
140
|
+ }
|
|
135
|
141
|
}
|
|
|
142
|
+ result=item;
|
|
|
143
|
+
|
|
|
144
|
+ } else {
|
|
|
145
|
+ result = list;
|
|
136
|
146
|
}
|
|
137
|
|
- result=item;
|
|
138
|
147
|
|
|
|
148
|
+ // 缓存结果
|
|
|
149
|
+ await BufferMemoryClass.add({
|
|
|
150
|
+ KeyName: cacheKey,
|
|
|
151
|
+ ValueString: JSON.stringify(result)
|
|
|
152
|
+ });
|
|
|
153
|
+ //console.log("数据已缓存");
|
|
139
|
154
|
} else {
|
|
140
|
|
- result = list;
|
|
|
155
|
+ result = JSON.parse(cachedData[0].ValueString);
|
|
141
|
156
|
}
|
|
142
|
157
|
|
|
143
|
|
- // 缓存结果
|
|
144
|
|
- await BufferMemoryClass.add({
|
|
145
|
|
- KeyName: cacheKey,
|
|
146
|
|
- ValueString: JSON.stringify(result)
|
|
147
|
|
- });
|
|
148
|
|
- //console.log("数据已缓存");
|
|
149
|
|
- } else {
|
|
150
|
|
- result = JSON.parse(cachedData[0].ValueString);
|
|
|
158
|
+ ctx.body = { errcode: 10000, result };
|
|
151
|
159
|
}
|
|
152
|
|
-
|
|
153
|
|
- ctx.body = { errcode: 10000, result };
|
|
154
|
160
|
} catch (error) {
|
|
155
|
161
|
console.error("获取学校列表失败:", error);
|
|
156
|
162
|
ctx.body = { errcode: 500, message: "获取学校列表失败" };
|
|
157
|
163
|
}
|
|
|
164
|
+
|
|
158
|
165
|
}
|
|
159
|
166
|
|
|
160
|
167
|
|