mpsScoreController.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. import { promises as fs } from 'fs';
  2. import moment from 'moment';
  3. import BufferMemoryClass from '../../model/BufferMemoryClass.js';
  4. import { stringUtils } from '../../util/stringClass.js';
  5. import commonModel from '../../model/commonModel.js';
  6. import mps, { ArrYear, getDistrict } from '../../model/mps.js';
  7. import _ from 'lodash';
  8. // 更新学校点赞数
  9. export async function UpdateMPSUserSchoolLikeNum(ctx) {
  10. const param = {
  11. UserID: ctx.request.body.UserID || 0,
  12. SchoolID: ctx.request.body.SchoolID || 0,
  13. SchoolType1: ctx.request.body.SchoolType1 || '高中',
  14. LikeNum: ctx.request.body.LikeNum || 0
  15. };
  16. var sql="select * from MPS_UserSchoolClickLike where UserID="+param.UserID+" and SchoolID="+param.SchoolID;
  17. var list = await commonModel.RunSql(null,sql);
  18. if (list && list.length>0){
  19. if (list[0].ClickLikeID!=param.ClickLikeID) {
  20. param.ID=list[0].ID;
  21. await mps.UpdateMPSUserSchoolClickLike(param);
  22. }
  23. }
  24. else{
  25. await mps.AddMPSUserSchoolClickLike(param);
  26. }
  27. result = await commonModel.RunSql({}, sql);
  28. ctx.body = { "errcode": 10000, result: result };
  29. }
  30. // 获取学校点赞数
  31. export async function GetMPSSchoolLikeNum(ctx) {
  32. const param = {
  33. SchoolID: ctx.query.SchoolID || 0,
  34. UserID: ctx.query.UserID || 0,
  35. };
  36. let sql="select ClickLikeID,count(*) as Count from MPS_UserSchoolClickLike where SchoolID="+param.SchoolID+" group by ClickLikeID order by Count desc,ClickLikeID;";
  37. let list = await commonModel.RunSql(null,sql);
  38. if (list && list.length>0){
  39. list[0].Show=1;
  40. let sql2="select * from MPS_UserSchoolClickLike where SchoolID="+param.SchoolID+" and UserID="+param.UserID+";";
  41. //console.log(sql2);
  42. let user=await commonModel.RunSql(null,sql2);
  43. if (user && user.length>0) {
  44. for (let i = 0; i < list.length; i++) {
  45. if (user[0].ClickLikeID == list[i].ClickLikeID) {
  46. list[i].Show = 1;
  47. }
  48. }
  49. }
  50. ctx.body = {errcode: 10000,result:list};
  51. }
  52. else{
  53. ctx.body = {errcode: 10000,result:[]};
  54. }
  55. }
  56. // 获取区县人数
  57. export async function GetMPSDistrictPersonNum(ctx) {
  58. let param = {
  59. DistrictID: ctx.query.DistrictID || '0', //所在区
  60. Year: ctx.query.Year || ArrYear[0].Name,
  61. };
  62. if (param.DistrictID==10 || param.DistrictID==12 || param.DistrictID==15 || param.DistrictID==16 )
  63. param.Year=ArrYear[0].Name;
  64. let info=null;
  65. if (param.DistrictID!="NaN"){
  66. const url = "GetMPSDistrictPersonNum?DistrictID=" + param.DistrictID;
  67. info = await BufferMemoryClass.get(url);
  68. if (process.env.NODE_ENV == 'development')
  69. info = [];
  70. if (!info || info.length == 0) {
  71. const year2 = Number(param.Year) - 1;
  72. let str = "";
  73. if (param.DistrictID && param.DistrictID != 0)
  74. str = " and s.DistrictID=" + param.DistrictID;
  75. const arr = [];
  76. const sql = "select c.SchoolType2Short,s.ScoreYear,sum(s.PlanNum) as PlanNum from MPS_Score s inner join MPS_School c on s.SchoolTarget=c.ID where s.ScoreYear in ('" + year2 + "','" + param.Year + "') and s.SchoolTargetRemark not in('4国际(本市)','5国际(非本市)') and s.PlanNum>0 " + str + " group by c.SchoolType2Short,s.ScoreYear order by c.SchoolType2Short desc,s.ScoreYear;";
  77. const list = await commonModel.RunSql({}, sql);
  78. if (list && list.length > 0) {
  79. for(let i=0;i<list.length;i++){
  80. list[i].PlanNum=Number(list[i].PlanNum);
  81. }
  82. arr.push({ "Name": "能上" + list[1].SchoolType2Short, "Year1": list[1].PlanNum, "Year2": list[1].PlanNum - list[0].PlanNum });
  83. arr.push({ "Name": "能上" + list[5].SchoolType2Short, "Year1": list[5].PlanNum + list[3].PlanNum, "Year2": list[5].PlanNum + list[3].PlanNum - list[4].PlanNum - list[2].PlanNum });
  84. arr.push({ "Name": "能上" + list[7].SchoolType2Short, "Year1": list[7].PlanNum, "Year2": list[7].PlanNum - list[6].PlanNum });
  85. arr.push({ "Name": "能上高中总计", "Year1": arr[0].Year1 + arr[1].Year1 + arr[2].Year1, "Year2": arr[0].Year2 + arr[1].Year2 + arr[2].Year2 });
  86. arr[0].Rate = Math.round(100 * arr[0].Year1 / arr[3].Year1);
  87. arr[1].Rate = Math.round(100 * arr[1].Year1 / arr[3].Year1);
  88. arr[2].Rate = Math.round(100 * arr[2].Year1 / arr[3].Year1);
  89. }
  90. info = {
  91. Year: param.Year,
  92. List: arr
  93. };
  94. const obj = {
  95. KeyName: url,
  96. ValueString: JSON.stringify(info)
  97. };
  98. await BufferMemoryClass.add(obj);
  99. console.log("缓存");
  100. }
  101. else {
  102. info = info[0].ValueString;
  103. info = JSON.parse(info);
  104. }
  105. }
  106. ctx.body = { "errcode": 10000, result: info };
  107. }
  108. // 获取城市招生人数
  109. export async function GetMPSCityPersonNum(ctx) {
  110. const param = {
  111. Year: ctx.query.Year || ArrYear[1].Name,
  112. };
  113. const url = "GetMPSCityPersonNum";
  114. let info = await BufferMemoryClass.get(url);
  115. // if (process.env.NODE_ENV == 'development')
  116. // info = [];
  117. if (!info || info.length == 0) {
  118. const year2 = Number(param.Year) - 1;
  119. const sql = "select c.SchoolType2Short,s.ScoreYear,sum(s.PlanNum) as PlanNum from MPS_Score s inner join MPS_School c on s.SchoolTarget=c.ID where s.ScoreYear in ('" + year2 + "','" + param.Year + "') and s.SchoolTargetRemark not in('4国际(本市)','5国际(非本市)') and s.PlanNum>0 group by c.SchoolType2Short,s.ScoreYear order by c.SchoolType2Short desc,s.ScoreYear;";
  120. const list = await commonModel.RunSql({}, sql);
  121. const sql2 = "select sum(PlanNum) as PlanNum from MPS_Score where ScoreYear='" + ArrYear[0].Name + "' and SchoolTarget in (1,2,3,4) and SchoolTargetRemark not in('4国际(本市)','5国际(非本市)');";
  122. const list2 = await commonModel.RunSql({}, sql2);
  123. for(let i=0;i<list.length;i++){
  124. list[i].PlanNum=Number(list[i].PlanNum);
  125. }
  126. list2[0].PlanNum=Number(list2[0].PlanNum);
  127. const arr = [];
  128. arr.push({ "Name": "能上" + list[1].SchoolType2Short, "Year1": list[1].PlanNum, "Year2": list[1].PlanNum - list[0].PlanNum, "Other": "「四校」招生计划数 " + list2[0].PlanNum + "人" });
  129. arr.push({ "Name": "能上" + list[5].SchoolType2Short, "Year1": list[5].PlanNum + list[3].PlanNum, "Year2": list[5].PlanNum + list[3].PlanNum - list[4].PlanNum - list[2].PlanNum, "Other": "特色高中招生计划数 " + list[3].PlanNum + "人" });
  130. arr.push({ "Name": "能上" + list[7].SchoolType2Short, "Year1": list[7].PlanNum, "Year2": list[7].PlanNum - list[6].PlanNum });
  131. arr.push({ "Name": "能上高中总计", "Year1": arr[0].Year1 + arr[1].Year1 + arr[2].Year1, "Year2": arr[0].Year2 + arr[1].Year2 + arr[2].Year2 });
  132. arr[0].Rate = Math.round(100 * arr[0].Year1 / arr[3].Year1);
  133. arr[1].Rate = Math.round(100 * arr[1].Year1 / arr[3].Year1);
  134. arr[2].Rate = Math.round(100 * arr[2].Year1 / arr[3].Year1);
  135. info = {
  136. Year: param.Year,
  137. List: arr
  138. };
  139. const obj = {
  140. KeyName: url,
  141. ValueString: JSON.stringify(info)
  142. };
  143. await BufferMemoryClass.add(obj);
  144. console.log("缓存");
  145. }
  146. else {
  147. info = info[0].ValueString;
  148. info = JSON.parse(info);
  149. }
  150. ctx.body = { "errcode": 10000, result: info };
  151. }
  152. // 得到分数线(小程序使用)
  153. export async function GetMPSScore(ctx) {
  154. var param = {
  155. ScoreYear: ctx.query.ScoreYear || ArrYear[0].Name,
  156. ScoreType: ctx.query.ScoreType || '1-15志愿',
  157. DistrictID: ctx.query.DistrictID || 0,
  158. };
  159. var url="GetMPSScore?ScoreYear="+param.ScoreYear+"&ScoreType="+param.ScoreType+"&DistrictID="+param.DistrictID;
  160. var list = await BufferMemoryClass.get(url);
  161. if (process.env.NODE_ENV == 'development')
  162. list=[];
  163. if (!list || list.length==0) {
  164. var sql0 = "SELECT f.ID,x.DistrictID as 'DistrictName',x.District as 'DistrictNameArea',f.DistrictID,f.ScoreType,f.SchoolOfGraduation,f.SchoolFullNameJunior,f.SchoolTarget,x.SchoolFullName,x.SchoolShortName,x.SchoolType2ShortID,x.SchoolType2Short,x.Accommodation,x.PublicOrPrivate,f.SchoolTargetRemark," +
  165. "f.PlanNum,f.ScoreTotal,f.Score1,f.Score2,f.Score3,f.Score4,f.SchoolTargetRemark2,f.PlanNumDifferenceValue,f.ScoreTotalDifferenceValue,x.PublicOrPrivate FROM MPS_Score f inner join MPS_School x on f.SchoolTarget=x.ID ";
  166. if (param.ScoreType == "名额到校") {
  167. sql0 += " inner join MPS_School c on f.SchoolOfGraduation = c.ID ";
  168. }
  169. sql0 += " where f.ScoreType='" + param.ScoreType + "'";
  170. var sql = sql0;
  171. var scoreYear = param.ScoreYear;
  172. sql += " and f.ScoreYear='" + scoreYear + "'";
  173. if (param.ScoreType != "自主招生") {
  174. sql += " and (f.PlanNum>0 || f.PlanNum=-999) and f.ScoreTotal>=0";
  175. }
  176. if (param.DistrictID != "全部" && param.DistrictID >= 0) {
  177. sql += " and f.DistrictID=" + param.DistrictID;
  178. }
  179. else if (param.DistrictID == -1) {
  180. sql += " and (f.SchoolTargetRemark='4国际(本市)' or f.SchoolTargetRemark='5国际(非本市)') ";
  181. }
  182. var sqlOrder = "";
  183. if (param.ScoreType == "名额到校")
  184. sqlOrder += " order by f.DistrictID,CAST(f.SchoolOfGraduation AS UNSIGNED),f.ScoreTotal desc;";
  185. else if (param.ScoreType == "名额到区")
  186. sqlOrder += " order by f.DistrictID,f.ScoreTotal desc;";
  187. else if (param.ScoreType == "1-15志愿")
  188. sqlOrder += " order by f.DistrictID,x.SchoolType2ShortID,f.ScoreTotal desc;";
  189. else if (param.ScoreType == "自主招生") {
  190. if (param.DistrictID == -1)
  191. sqlOrder += " order by f.DistrictID,x.DistrictID,x.OrderID,f.SchoolTarget,f.SchoolTargetRemark;";
  192. else
  193. sqlOrder += " order by f.DistrictID,x.DistrictID,x.OrderID2,f.SchoolTarget,f.SchoolTargetRemark;";
  194. }
  195. else
  196. sqlOrder += " order by f.DistrictID,x.DistrictID,x.SchoolNumber,f.SchoolTargetRemark;";
  197. sql += sqlOrder;
  198. //console.log(sql);
  199. var list = await commonModel.RunSql({}, sql);
  200. if (param.ScoreType == "自主招生") {
  201. var arrTemp = [], temp = 0, obj = {
  202. "学科": 0,
  203. "体育": 0,
  204. "艺术": 0,
  205. "国际(本市)": 0,
  206. "国际(非本市)": 0,
  207. "学科差": null,
  208. "体育差": null,
  209. "艺术差": null,
  210. "国际(本市)差": null,
  211. "国际(非本市)差": null
  212. };
  213. for (var i = 0; i < list.length; i++) {
  214. var item = list[i];
  215. if (i > 0 && temp != item.SchoolTarget) {
  216. arrTemp.push(obj);
  217. obj = {
  218. "学科": 0,
  219. "体育": 0,
  220. "艺术": 0,
  221. "国际(本市)": 0,
  222. "国际(非本市)": 0,
  223. "学科差": null,
  224. "体育差": null,
  225. "艺术差": null,
  226. "国际(本市)差": null,
  227. "国际(非本市)差": null
  228. };
  229. }
  230. item.DistrictName = getDistrict(item.DistrictName);
  231. if (item.DistrictName == "上海市")
  232. item.DistrictName = "委属";
  233. obj.ID = item.SchoolTarget;
  234. obj.SchoolFullName = item.SchoolFullName;
  235. obj.ScoreType = item.ScoreType;
  236. obj.DistrictName = item.DistrictName;
  237. obj.DistrictNameArea = item.DistrictNameArea;
  238. obj.SchoolType2Short = item.SchoolType2Short;
  239. obj.Accommodation = item.Accommodation;
  240. obj.PublicOrPrivate = item.PublicOrPrivate;
  241. obj[item.SchoolTargetRemark.substr(1)] = item.PlanNum;
  242. obj[item.SchoolTargetRemark.substr(1) + "差"] = item.PlanNumDifferenceValue;
  243. obj.Name = item.SchoolShortName;
  244. temp = item.SchoolTarget;
  245. }
  246. arrTemp.push(obj);
  247. for (var i = 0; i < arrTemp.length; i++) {
  248. arrTemp[i]["国际"] = arrTemp[i]["国际(本市)"] + arrTemp[i]["国际(非本市)"];
  249. if (arrTemp[i]["国际(本市)差"] && arrTemp[i]["国际(非本市)差"])
  250. arrTemp[i]["国际差"] = arrTemp[i]["国际(本市)差"] + arrTemp[i]["国际(非本市)差"];
  251. }
  252. list = arrTemp;
  253. }
  254. else {
  255. for (var i = 0; i < list.length; i++) {
  256. var item = list[i];
  257. item.DistrictName = getDistrict(item.DistrictName);
  258. item.ID = item.SchoolTarget;
  259. if (item.DistrictName == "上海市")
  260. item.DistrictName = "委属";
  261. if (param.ScoreType == "名额到区")
  262. item.Height = 121;
  263. else if (param.ScoreType == "1-15志愿") {
  264. if (item.SchoolTargetRemark && item.SchoolTargetRemark.indexOf("(") >= 0) {
  265. // item.SchoolShortName += "\n" + item.SchoolTargetRemark;
  266. // item.SchoolShortName = item.SchoolShortName.replace("(", "·");
  267. // item.SchoolShortName = item.SchoolShortName.replace(")", "");
  268. item.Height = 159;
  269. }
  270. else {
  271. item.Height = 121;
  272. if (item.SchoolTargetRemark || item.SchoolShortName.length > 5)
  273. item.Height = 159;
  274. }
  275. }
  276. else if (param.ScoreType == "名额到校")
  277. item.Height = 93;
  278. if (i > 0) {
  279. item.SchoolOfGraduationTemp = list[i - 1].SchoolOfGraduation;
  280. item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID;
  281. }
  282. item.Name = item.SchoolShortName;
  283. }
  284. }
  285. var today=moment().format("MM-DD");
  286. var year=moment().format("YYYY");
  287. if (ArrYear[0].IsNullScoreLine && param.ScoreYear==year){
  288. sql=sql.replace(ArrYear[0].Name,ArrYear[1].Name);
  289. var list2 = await commonModel.RunSql({}, sql);
  290. for(var i=0;i<list.length;i++){
  291. for(var j=0;j<list2.length;j++){
  292. if (list[i].DistrictID==list2[j].DistrictID
  293. && list[i].SchoolTarget==list2[j].SchoolTarget
  294. && (!list[i].SchoolOfGraduation || (list[i].SchoolOfGraduation && list[i].SchoolOfGraduation==list2[j].SchoolOfGraduation))){
  295. list[i].ScoreTotal=list2[j].ScoreTotal;
  296. list[i].Score1=list2[j].Score1;
  297. list[i].Score2=list2[j].Score2;
  298. list[i].Score3=list2[j].Score3;
  299. list[i].Score4=list2[j].Score4;
  300. list[i].ScoreTotalDifferenceValue=list2[j].ScoreTotalDifferenceValue;
  301. break;
  302. }
  303. }
  304. if (list[i].DistrictID=="12" && param.ScoreType=="名额到校") {
  305. if (list[i].SchoolTarget <= "5") {
  306. list[i].ID = "0";
  307. list[i].SchoolTarget = "0";
  308. list[i].Name = "委属市重点";
  309. list[i].SchoolShortName = "委属市重点";
  310. }
  311. }
  312. }
  313. if (param.ScoreType=="名额到区")
  314. list=_.orderBy(list, ['DistrictID','ScoreTotal'], ['asc','desc']);
  315. else if (param.ScoreType=="名额到校") {
  316. list = _.orderBy(list, ['DistrictID', 'SchoolOfGraduation', 'ScoreTotal'], ['asc', 'asc', 'desc']);
  317. for (var i = 0; i < list.length; i++) {
  318. var item = list[i];
  319. item.SchoolOfGraduationTemp = "";
  320. item.SchoolType2ShortIDTemp = "";
  321. }
  322. for (var i = 0; i < list.length; i++) {
  323. var item = list[i];
  324. if (i > 0) {
  325. item.SchoolOfGraduationTemp = list[i - 1].SchoolOfGraduation;
  326. item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID;
  327. }
  328. item.Name = item.SchoolShortName;
  329. }
  330. }
  331. else if (param.ScoreType=="1-15志愿") {
  332. list = _.orderBy(list, ['DistrictID', "SchoolType2ShortID", 'ScoreTotal'], ['asc', 'asc', 'desc']);
  333. for (var i = 0; i < list.length; i++) {
  334. var item = list[i];
  335. item.DistrictName = getDistrict(item.DistrictName);
  336. item.ID = item.SchoolTarget;
  337. if (i > 0) {
  338. item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID;
  339. }
  340. else{
  341. item.SchoolType2ShortIDTemp="";
  342. }
  343. item.Name = item.SchoolShortName;
  344. }
  345. }
  346. }
  347. for(let i=0;i<list.length;i++){
  348. let item=list[i];
  349. item.Score1=stringUtils.TrimEndZero(item.Score1);
  350. item.Score2=stringUtils.TrimEndZero(item.Score2);
  351. item.Score3=stringUtils.TrimEndZero(item.Score3);
  352. item.Score4=stringUtils.TrimEndZero(item.Score4);
  353. item.ScoreTotal=stringUtils.TrimEndZero(item.ScoreTotal);
  354. item.ScoreTotalDifferenceValue=stringUtils.TrimEndZero(item.ScoreTotalDifferenceValue);
  355. }
  356. let obj1={};
  357. obj1.KeyName=url;
  358. obj1.ValueString=JSON.stringify(list);
  359. await BufferMemoryClass.add(obj1);
  360. }
  361. else{
  362. list=list[0].ValueString;
  363. list=JSON.parse(list);
  364. }
  365. ctx.body = {"errcode": 10000,result:list};
  366. }
  367. //得到收藏学校分数线(小程序使用)
  368. export async function GetMPSScoreByCollect(ctx) {
  369. var param = {
  370. ScoreYear: ctx.query.ScoreYear || ArrYear[0].Name,
  371. UserID: ctx.query.UserID || 0,
  372. DistrictID: ctx.query.DistrictID || 0,
  373. SchoolType1: ctx.query.SchoolType1 || '高中',
  374. };
  375. var sql="";
  376. if (param.SchoolType1=='高中'){
  377. sql="select x.ID,f.ScoreType,f.PlanNum,f.ScoreTotal,f.Score1,f.Score2,f.Score3,f.Score4,f.PlanNumDifferenceValue,f.ScoreTotalDifferenceValue,f.DistrictID,f.SchoolTarget,f.SchoolOfGraduation " +
  378. "from MPS_Score f inner join MPS_School x on f.SchoolTarget=x.ID inner join MPS_UserCollect uc on x.ID=uc.SchoolID " +
  379. "where f.ScoreYear='"+param.ScoreYear+"' and uc.UserID="+param.UserID+" and (f.PlanNum>0 or f.PlanNum=-999) " +
  380. "and ((f.ScoreType in ('名额到区','1-15志愿') and f.DistrictID="+param.DistrictID+") or (f.ScoreType in ('自主招生') and f.SchoolTargetRemark='1学科')) " +
  381. "order by SchoolTarget,f.ScoreType desc,SchoolTargetRemark;";
  382. }
  383. else{
  384. sql="select f.SchoolOfGraduation as 'ID',f.SchoolFullNameJunior as 'SchoolFullName',f.DistrictID,x.SchoolShortName,f.PlanNum,f.ScoreTotal,f.Score1,f.Score2,f.Score3,f.Score4,f.PlanNumDifferenceValue,f.ScoreTotalDifferenceValue " +
  385. "from MPS_Score f inner join MPS_School x on f.SchoolTarget=x.ID " +
  386. "inner join MPS_UserCollect uc on f.SchoolOfGraduation=uc.SchoolID " +
  387. "where f.ScoreYear='"+param.ScoreYear+"' and uc.UserID="+param.UserID+" " +
  388. "and f.ScoreType in ('名额到校') and (f.PlanNum>0 or f.PlanNum=-999) " +
  389. "order by SchoolOfGraduation;";
  390. }
  391. var list=await commonModel.RunSql({},sql);
  392. for (var i = 0; i < list.length; i++) {
  393. var item = list[i];
  394. if (param.SchoolType1=='高中') {
  395. item.Name = item.ScoreType;
  396. delete item.ScoreType;
  397. }
  398. else {
  399. item.Name = item.SchoolShortName;
  400. item.District=getDistrict(item.DistrictID);
  401. }
  402. item.Height=93;
  403. if (!item.ScoreTotal)
  404. item.ScoreTotal="";
  405. if (!item.Score1)
  406. item.Score1="";
  407. if (!item.Score2)
  408. item.Score2="";
  409. if (!item.Score3)
  410. item.Score3="";
  411. if (!item.Score4)
  412. item.Score4="";
  413. if (i > 0) {
  414. item.TempID = list[i - 1].ID;
  415. }
  416. item.Score1=stringUtils.TrimEndZero(item.Score1);
  417. item.Score2=stringUtils.TrimEndZero(item.Score2);
  418. item.Score3=stringUtils.TrimEndZero(item.Score3);
  419. item.Score4=stringUtils.TrimEndZero(item.Score4);
  420. item.ScoreTotal=stringUtils.TrimEndZero(item.ScoreTotal);
  421. item.ScoreTotalDifferenceValue=stringUtils.TrimEndZero(item.ScoreTotalDifferenceValue);
  422. }
  423. var year=moment().format("YYYY");
  424. if (ArrYear[0].IsNullScoreLine && param.ScoreYear==year){
  425. sql=sql.replace(ArrYear[0].Name,ArrYear[1].Name);
  426. var list2 = await commonModel.RunSql({}, sql);
  427. for(var i=0;i<list.length;i++){
  428. if (list[i].Name!="自主招生") {
  429. for (var j = 0; j < list2.length; j++) {
  430. var item=list[i];
  431. if (param.SchoolType1=='高中') {
  432. if (item.DistrictID == list2[j].DistrictID
  433. && item.Name == list2[j].ScoreType
  434. && item.SchoolTarget == list2[j].SchoolTarget
  435. && list2[j].ScoreTotal>0
  436. && item.ID == list2[j].ID) {
  437. item.ScoreTotal = stringUtils.TrimEndZero(list2[j].ScoreTotal);
  438. item.Score1 = stringUtils.TrimEndZero(list2[j].Score1);
  439. item.Score2 = stringUtils.TrimEndZero(list2[j].Score2);
  440. item.Score3 = stringUtils.TrimEndZero(list2[j].Score3);
  441. item.Score4 = stringUtils.TrimEndZero(list2[j].Score4);
  442. item.ScoreTotalDifferenceValue = stringUtils.TrimEndZero(list2[j].ScoreTotalDifferenceValue);
  443. break;
  444. }
  445. }
  446. else {
  447. if (item.DistrictID == list2[j].DistrictID
  448. && item.Name == list2[j].SchoolShortName
  449. && list2[j].ScoreTotal>0
  450. && item.ID == list2[j].ID) {
  451. item.ScoreTotal = stringUtils.TrimEndZero(list2[j].ScoreTotal);
  452. item.Score1 = stringUtils.TrimEndZero(list2[j].Score1);
  453. item.Score2 = stringUtils.TrimEndZero(list2[j].Score2);
  454. item.Score3 = stringUtils.TrimEndZero(list2[j].Score3);
  455. item.Score4 = stringUtils.TrimEndZero(list2[j].Score4);
  456. item.ScoreTotalDifferenceValue = stringUtils.TrimEndZero(list2[j].ScoreTotalDifferenceValue);
  457. break;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. ctx.body = {"errcode": 10000,result:list};
  465. }
  466. //修改分数线
  467. export async function UpdateMPSScore(ctx) {
  468. let param = ctx.request.body;
  469. let sql="update MPS_Score set ? where ID="+param.ID+";";
  470. if (param.ID==0){
  471. let sql2 = "select * from MPS_Score where ScoreType='"+param.ScoreType+"' and ScoreYear='"+param.ScoreYear+"'";
  472. sql2+=" and DistrictID="+param.DistrictID+" ";
  473. if (!param.SchoolOfGraduation)
  474. param.SchoolOfGraduation=0;
  475. sql2+=" and SchoolOfGraduation='"+param.SchoolOfGraduation+"' ";
  476. sql2+=" and SchoolTarget='"+param.SchoolTarget+"'";
  477. if (param.SchoolTargetRemark && param.SchoolTargetRemark!="undefined") {
  478. sql2 += " and SchoolTargetRemark='" + param.SchoolTargetRemark + "';";
  479. }
  480. let hasID=await commonModel.RunSql({},sql2);
  481. if (hasID && hasID.length>0) {
  482. param.ID=hasID[0].ID;
  483. sql="update MPS_Score set ? where ID="+param.ID+";";
  484. }
  485. else{
  486. delete param.ID;
  487. sql = "insert into MPS_Score SET ?";
  488. }
  489. }
  490. let insertID = await commonModel.RunSql(param,sql);
  491. if (!param.ID || param.ID==0){
  492. sql="update MPS_Score f,MPS_School x set f.SchoolFullName=x.SchoolFullName where f.SchoolTarget=x.ID;";
  493. await commonModel.RunSql({},sql);
  494. sql="update MPS_Score f,MPS_School x set f.SchoolFullNameJunior=x.SchoolFullName where f.SchoolOfGraduation=x.ID;";
  495. await commonModel.RunSql({},sql);
  496. param.ID=insertID.insertId;
  497. }
  498. ctx.body = {"errcode": 10000,result:param.ID};
  499. }
  500. // 得到分数线(Web使用)
  501. export async function GetMPSScoreWeb(ctx) {
  502. const param = {
  503. ScoreYear: ctx.query.ScoreYear || ArrYear[0].Name,
  504. ScoreType: ctx.query.ScoreType || '1-15志愿',
  505. DistrictID: ctx.query.DistrictID || 0,
  506. };
  507. let sql0 = "SELECT f.ID,x.District as 'DistrictName',f.DistrictID,f.ScoreType,f.SchoolOfGraduation,f.SchoolFullNameJunior,f.SchoolTarget,x.SchoolFullName,x.SchoolShortName,x.SchoolType2Short,x.Accommodation,x.PublicOrPrivate,f.SchoolTargetRemark," +
  508. "f.PlanNum,f.ScoreTotal,f.Score1,f.Score2,f.Score3,f.Score4,f.SchoolTargetRemark2,f.PlanNumDifferenceValue,f.ScoreTotalDifferenceValue FROM MPS_Score f inner join MPS_School x on f.SchoolTarget=x.ID ";
  509. if (param.ScoreType === "名额到校") {
  510. sql0 += " inner join MPS_School c on f.SchoolOfGraduation = c.ID ";
  511. }
  512. sql0 += " where f.ScoreType='" + param.ScoreType + "'";
  513. let sql = sql0;
  514. let scoreYear = param.ScoreYear;
  515. sql += " and f.ScoreYear='" + scoreYear + "'";
  516. if (param.DistrictID !== "全部") {
  517. sql += " and f.DistrictID=" + param.DistrictID;
  518. }
  519. let sqlOrder = "";
  520. if (param.ScoreType === "名额到校") {
  521. if (param.DistrictID === 3 || param.DistrictID === 11 || param.DistrictID === 6 || param.DistrictID === 10 || param.DistrictID === 12)
  522. sqlOrder += " order by c.ID,x.SchoolNumber,f.ID;";
  523. else
  524. sqlOrder += " order by c.SchoolNumber,x.SchoolNumber,f.ID;";
  525. }
  526. else if (param.ScoreType === "1-15志愿")
  527. sqlOrder += " order by f.DistrictID,f.OrderID,x.ID;";
  528. else
  529. sqlOrder += " order by f.DistrictID,x.DistrictID,x.SchoolNumber,f.SchoolTargetRemark;";
  530. sql += sqlOrder;
  531. const list = await commonModel.RunSql({}, sql);
  532. if (param.ScoreYear === "2022") {
  533. for (let i = 0; i < list.length; i++) {
  534. const item = list[i];
  535. item.ID = 0;
  536. item.PlanNum = "";
  537. item.ScoreTotal = "";
  538. item.Score1 = "";
  539. item.Score2 = "";
  540. item.Score3 = "";
  541. item.Score4 = "";
  542. item.SchoolTargetRemark2 = "";
  543. }
  544. scoreYear = param.ScoreYear;
  545. sql = sql0;
  546. sql += " and f.ScoreYear='" + scoreYear + "'";
  547. if (param.DistrictID !== "全部") {
  548. sql += " and f.DistrictID='" + param.DistrictID + "'";
  549. }
  550. sql += sqlOrder;
  551. const list2 = await commonModel.RunSql({}, sql);
  552. for (let i = 0; i < list.length; i++) {
  553. const item = list[i];
  554. for (let j = 0; j < list2.length; j++) {
  555. if (
  556. item.SchoolOfGraduation === list2[j].SchoolOfGraduation
  557. && item.SchoolTarget === list2[j].SchoolTarget
  558. && item.DistrictID === list2[j].DistrictID
  559. && item.ScoreType === list2[j].ScoreType
  560. && (item.SchoolTargetRemark === list2[j].SchoolTargetRemark || (!item.SchoolTargetRemark && !list2[j].SchoolTargetRemark))
  561. ) {
  562. item.ID = list2[j].ID;
  563. item.SchoolTargetRemark = list2[j].SchoolTargetRemark;
  564. item.PlanNum = list2[j].PlanNum;
  565. item.ScoreTotal = list2[j].ScoreTotal;
  566. item.Score1 = list2[j].Score1;
  567. item.Score2 = list2[j].Score2;
  568. item.Score3 = list2[j].Score3;
  569. item.Score4 = list2[j].Score4;
  570. item.SchoolTargetRemark2 = list2[j].SchoolTargetRemark2;
  571. break;
  572. }
  573. }
  574. }
  575. }
  576. ctx.body = { "errcode": 10000, result: list };
  577. }