import { promises as fs } from 'fs'; import moment from 'moment'; import BufferMemoryClass from '../../model/BufferMemoryClass.js'; import { stringUtils } from '../../util/stringClass.js'; import commonModel from '../../model/commonModel.js'; import mps, { ArrYear, getDistrict } from '../../model/mps.js'; import _ from 'lodash'; // 更新学校点赞数 export async function UpdateMPSUserSchoolLikeNum(ctx) { const param = { UserID: ctx.request.body.UserID || 0, SchoolID: ctx.request.body.SchoolID || 0, SchoolType1: ctx.request.body.SchoolType1 || '高中', LikeNum: ctx.request.body.LikeNum || 0 }; var sql="select * from MPS_UserSchoolClickLike where UserID="+param.UserID+" and SchoolID="+param.SchoolID; var list = await commonModel.RunSql(null,sql); if (list && list.length>0){ if (list[0].ClickLikeID!=param.ClickLikeID) { param.ID=list[0].ID; await mps.UpdateMPSUserSchoolClickLike(param); } } else{ await mps.AddMPSUserSchoolClickLike(param); } result = await commonModel.RunSql({}, sql); ctx.body = { "errcode": 10000, result: result }; } // 获取学校点赞数 export async function GetMPSSchoolLikeNum(ctx) { const param = { SchoolID: ctx.query.SchoolID || 0, UserID: ctx.query.UserID || 0, }; let sql="select ClickLikeID,count(*) as Count from MPS_UserSchoolClickLike where SchoolID="+param.SchoolID+" group by ClickLikeID order by Count desc,ClickLikeID;"; let list = await commonModel.RunSql(null,sql); if (list && list.length>0){ list[0].Show=1; let sql2="select * from MPS_UserSchoolClickLike where SchoolID="+param.SchoolID+" and UserID="+param.UserID+";"; //console.log(sql2); let user=await commonModel.RunSql(null,sql2); if (user && user.length>0) { for (let i = 0; i < list.length; i++) { if (user[0].ClickLikeID == list[i].ClickLikeID) { list[i].Show = 1; } } } ctx.body = {errcode: 10000,result:list}; } else{ ctx.body = {errcode: 10000,result:[]}; } } // 获取区县人数 export async function GetMPSDistrictPersonNum(ctx) { let param = { DistrictID: ctx.query.DistrictID || '0', //所在区 Year: ctx.query.Year || ArrYear[0].Name, }; if (param.DistrictID==10 || param.DistrictID==12 || param.DistrictID==15 || param.DistrictID==16 ) param.Year=ArrYear[0].Name; let info=null; if (param.DistrictID!="NaN"){ const url = "GetMPSDistrictPersonNum?DistrictID=" + param.DistrictID; info = await BufferMemoryClass.get(url); if (process.env.NODE_ENV == 'development') info = []; if (!info || info.length == 0) { const year2 = Number(param.Year) - 1; let str = ""; if (param.DistrictID && param.DistrictID != 0) str = " and s.DistrictID=" + param.DistrictID; const arr = []; 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;"; const list = await commonModel.RunSql({}, sql); if (list && list.length > 0) { for(let i=0;i0 group by c.SchoolType2Short,s.ScoreYear order by c.SchoolType2Short desc,s.ScoreYear;"; const list = await commonModel.RunSql({}, sql); 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国际(非本市)');"; const list2 = await commonModel.RunSql({}, sql2); for(let i=0;i= 0) { sql += " and f.DistrictID=" + param.DistrictID; } else if (param.DistrictID == -1) { sql += " and (f.SchoolTargetRemark='4国际(本市)' or f.SchoolTargetRemark='5国际(非本市)') "; } var sqlOrder = ""; if (param.ScoreType == "名额到校") sqlOrder += " order by f.DistrictID,CAST(f.SchoolOfGraduation AS UNSIGNED),f.ScoreTotal desc;"; else if (param.ScoreType == "名额到区") sqlOrder += " order by f.DistrictID,f.ScoreTotal desc;"; else if (param.ScoreType == "1-15志愿") sqlOrder += " order by f.DistrictID,x.SchoolType2ShortID,f.ScoreTotal desc;"; else if (param.ScoreType == "自主招生") { if (param.DistrictID == -1) sqlOrder += " order by f.DistrictID,x.DistrictID,x.OrderID,f.SchoolTarget,f.SchoolTargetRemark;"; else sqlOrder += " order by f.DistrictID,x.DistrictID,x.OrderID2,f.SchoolTarget,f.SchoolTargetRemark;"; } else sqlOrder += " order by f.DistrictID,x.DistrictID,x.SchoolNumber,f.SchoolTargetRemark;"; sql += sqlOrder; //console.log(sql); var list = await commonModel.RunSql({}, sql); if (param.ScoreType == "自主招生") { var arrTemp = [], temp = 0, obj = { "学科": 0, "体育": 0, "艺术": 0, "国际(本市)": 0, "国际(非本市)": 0, "学科差": null, "体育差": null, "艺术差": null, "国际(本市)差": null, "国际(非本市)差": null }; for (var i = 0; i < list.length; i++) { var item = list[i]; if (i > 0 && temp != item.SchoolTarget) { arrTemp.push(obj); obj = { "学科": 0, "体育": 0, "艺术": 0, "国际(本市)": 0, "国际(非本市)": 0, "学科差": null, "体育差": null, "艺术差": null, "国际(本市)差": null, "国际(非本市)差": null }; } item.DistrictName = getDistrict(item.DistrictName); if (item.DistrictName == "上海市") item.DistrictName = "委属"; obj.ID = item.SchoolTarget; obj.SchoolFullName = item.SchoolFullName; obj.ScoreType = item.ScoreType; obj.DistrictName = item.DistrictName; obj.DistrictNameArea = item.DistrictNameArea; obj.SchoolType2Short = item.SchoolType2Short; obj.Accommodation = item.Accommodation; obj.PublicOrPrivate = item.PublicOrPrivate; obj[item.SchoolTargetRemark.substr(1)] = item.PlanNum; obj[item.SchoolTargetRemark.substr(1) + "差"] = item.PlanNumDifferenceValue; obj.Name = item.SchoolShortName; temp = item.SchoolTarget; } arrTemp.push(obj); for (var i = 0; i < arrTemp.length; i++) { arrTemp[i]["国际"] = arrTemp[i]["国际(本市)"] + arrTemp[i]["国际(非本市)"]; if (arrTemp[i]["国际(本市)差"] && arrTemp[i]["国际(非本市)差"]) arrTemp[i]["国际差"] = arrTemp[i]["国际(本市)差"] + arrTemp[i]["国际(非本市)差"]; } list = arrTemp; } else { for (var i = 0; i < list.length; i++) { var item = list[i]; item.DistrictName = getDistrict(item.DistrictName); item.ID = item.SchoolTarget; if (item.DistrictName == "上海市") item.DistrictName = "委属"; if (param.ScoreType == "名额到区") item.Height = 121; else if (param.ScoreType == "1-15志愿") { if (item.SchoolTargetRemark && item.SchoolTargetRemark.indexOf("(") >= 0) { // item.SchoolShortName += "\n" + item.SchoolTargetRemark; // item.SchoolShortName = item.SchoolShortName.replace("(", "·"); // item.SchoolShortName = item.SchoolShortName.replace(")", ""); item.Height = 159; } else { item.Height = 121; if (item.SchoolTargetRemark || item.SchoolShortName.length > 5) item.Height = 159; } } else if (param.ScoreType == "名额到校") item.Height = 93; if (i > 0) { item.SchoolOfGraduationTemp = list[i - 1].SchoolOfGraduation; item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID; } item.Name = item.SchoolShortName; } } var today=moment().format("MM-DD"); var year=moment().format("YYYY"); if (ArrYear[0].IsNullScoreLine && param.ScoreYear==year){ sql=sql.replace(ArrYear[0].Name,ArrYear[1].Name); var list2 = await commonModel.RunSql({}, sql); for(var i=0;i 0) { item.SchoolOfGraduationTemp = list[i - 1].SchoolOfGraduation; item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID; } item.Name = item.SchoolShortName; } } else if (param.ScoreType=="1-15志愿") { list = _.orderBy(list, ['DistrictID', "SchoolType2ShortID", 'ScoreTotal'], ['asc', 'asc', 'desc']); for (var i = 0; i < list.length; i++) { var item = list[i]; item.DistrictName = getDistrict(item.DistrictName); item.ID = item.SchoolTarget; if (i > 0) { item.SchoolType2ShortIDTemp = list[i - 1].SchoolType2ShortID; } else{ item.SchoolType2ShortIDTemp=""; } item.Name = item.SchoolShortName; } } } for(let i=0;i0 or f.PlanNum=-999) " + "and ((f.ScoreType in ('名额到区','1-15志愿') and f.DistrictID="+param.DistrictID+") or (f.ScoreType in ('自主招生') and f.SchoolTargetRemark='1学科')) " + "order by SchoolTarget,f.ScoreType desc,SchoolTargetRemark;"; } else{ 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 " + "from MPS_Score f inner join MPS_School x on f.SchoolTarget=x.ID " + "inner join MPS_UserCollect uc on f.SchoolOfGraduation=uc.SchoolID " + "where f.ScoreYear='"+param.ScoreYear+"' and uc.UserID="+param.UserID+" " + "and f.ScoreType in ('名额到校') and (f.PlanNum>0 or f.PlanNum=-999) " + "order by SchoolOfGraduation;"; } var list=await commonModel.RunSql({},sql); for (var i = 0; i < list.length; i++) { var item = list[i]; if (param.SchoolType1=='高中') { item.Name = item.ScoreType; delete item.ScoreType; } else { item.Name = item.SchoolShortName; item.District=getDistrict(item.DistrictID); } item.Height=93; if (!item.ScoreTotal) item.ScoreTotal=""; if (!item.Score1) item.Score1=""; if (!item.Score2) item.Score2=""; if (!item.Score3) item.Score3=""; if (!item.Score4) item.Score4=""; if (i > 0) { item.TempID = list[i - 1].ID; } item.Score1=stringUtils.TrimEndZero(item.Score1); item.Score2=stringUtils.TrimEndZero(item.Score2); item.Score3=stringUtils.TrimEndZero(item.Score3); item.Score4=stringUtils.TrimEndZero(item.Score4); item.ScoreTotal=stringUtils.TrimEndZero(item.ScoreTotal); item.ScoreTotalDifferenceValue=stringUtils.TrimEndZero(item.ScoreTotalDifferenceValue); } var year=moment().format("YYYY"); if (ArrYear[0].IsNullScoreLine && param.ScoreYear==year){ sql=sql.replace(ArrYear[0].Name,ArrYear[1].Name); var list2 = await commonModel.RunSql({}, sql); for(var i=0;i0 && item.ID == list2[j].ID) { item.ScoreTotal = stringUtils.TrimEndZero(list2[j].ScoreTotal); item.Score1 = stringUtils.TrimEndZero(list2[j].Score1); item.Score2 = stringUtils.TrimEndZero(list2[j].Score2); item.Score3 = stringUtils.TrimEndZero(list2[j].Score3); item.Score4 = stringUtils.TrimEndZero(list2[j].Score4); item.ScoreTotalDifferenceValue = stringUtils.TrimEndZero(list2[j].ScoreTotalDifferenceValue); break; } } else { if (item.DistrictID == list2[j].DistrictID && item.Name == list2[j].SchoolShortName && list2[j].ScoreTotal>0 && item.ID == list2[j].ID) { item.ScoreTotal = stringUtils.TrimEndZero(list2[j].ScoreTotal); item.Score1 = stringUtils.TrimEndZero(list2[j].Score1); item.Score2 = stringUtils.TrimEndZero(list2[j].Score2); item.Score3 = stringUtils.TrimEndZero(list2[j].Score3); item.Score4 = stringUtils.TrimEndZero(list2[j].Score4); item.ScoreTotalDifferenceValue = stringUtils.TrimEndZero(list2[j].ScoreTotalDifferenceValue); break; } } } } } } ctx.body = {"errcode": 10000,result:list}; } //修改分数线 export async function UpdateMPSScore(ctx) { let param = ctx.request.body; let sql="update MPS_Score set ? where ID="+param.ID+";"; if (param.ID==0){ let sql2 = "select * from MPS_Score where ScoreType='"+param.ScoreType+"' and ScoreYear='"+param.ScoreYear+"'"; sql2+=" and DistrictID="+param.DistrictID+" "; if (!param.SchoolOfGraduation) param.SchoolOfGraduation=0; sql2+=" and SchoolOfGraduation='"+param.SchoolOfGraduation+"' "; sql2+=" and SchoolTarget='"+param.SchoolTarget+"'"; if (param.SchoolTargetRemark && param.SchoolTargetRemark!="undefined") { sql2 += " and SchoolTargetRemark='" + param.SchoolTargetRemark + "';"; } let hasID=await commonModel.RunSql({},sql2); if (hasID && hasID.length>0) { param.ID=hasID[0].ID; sql="update MPS_Score set ? where ID="+param.ID+";"; } else{ delete param.ID; sql = "insert into MPS_Score SET ?"; } } let insertID = await commonModel.RunSql(param,sql); if (!param.ID || param.ID==0){ sql="update MPS_Score f,MPS_School x set f.SchoolFullName=x.SchoolFullName where f.SchoolTarget=x.ID;"; await commonModel.RunSql({},sql); sql="update MPS_Score f,MPS_School x set f.SchoolFullNameJunior=x.SchoolFullName where f.SchoolOfGraduation=x.ID;"; await commonModel.RunSql({},sql); param.ID=insertID.insertId; } ctx.body = {"errcode": 10000,result:param.ID}; } // 得到分数线(Web使用) export async function GetMPSScoreWeb(ctx) { const param = { ScoreYear: ctx.query.ScoreYear || ArrYear[0].Name, ScoreType: ctx.query.ScoreType || '1-15志愿', DistrictID: ctx.query.DistrictID || 0, }; 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," + "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 "; if (param.ScoreType === "名额到校") { sql0 += " inner join MPS_School c on f.SchoolOfGraduation = c.ID "; } sql0 += " where f.ScoreType='" + param.ScoreType + "'"; let sql = sql0; let scoreYear = param.ScoreYear; sql += " and f.ScoreYear='" + scoreYear + "'"; if (param.DistrictID !== "全部") { sql += " and f.DistrictID=" + param.DistrictID; } let sqlOrder = ""; if (param.ScoreType === "名额到校") { if (param.DistrictID === 3 || param.DistrictID === 11 || param.DistrictID === 6 || param.DistrictID === 10 || param.DistrictID === 12) sqlOrder += " order by c.ID,x.SchoolNumber,f.ID;"; else sqlOrder += " order by c.SchoolNumber,x.SchoolNumber,f.ID;"; } else if (param.ScoreType === "1-15志愿") sqlOrder += " order by f.DistrictID,f.OrderID,x.ID;"; else sqlOrder += " order by f.DistrictID,x.DistrictID,x.SchoolNumber,f.SchoolTargetRemark;"; sql += sqlOrder; const list = await commonModel.RunSql({}, sql); if (param.ScoreYear === "2022") { for (let i = 0; i < list.length; i++) { const item = list[i]; item.ID = 0; item.PlanNum = ""; item.ScoreTotal = ""; item.Score1 = ""; item.Score2 = ""; item.Score3 = ""; item.Score4 = ""; item.SchoolTargetRemark2 = ""; } scoreYear = param.ScoreYear; sql = sql0; sql += " and f.ScoreYear='" + scoreYear + "'"; if (param.DistrictID !== "全部") { sql += " and f.DistrictID='" + param.DistrictID + "'"; } sql += sqlOrder; const list2 = await commonModel.RunSql({}, sql); for (let i = 0; i < list.length; i++) { const item = list[i]; for (let j = 0; j < list2.length; j++) { if ( item.SchoolOfGraduation === list2[j].SchoolOfGraduation && item.SchoolTarget === list2[j].SchoolTarget && item.DistrictID === list2[j].DistrictID && item.ScoreType === list2[j].ScoreType && (item.SchoolTargetRemark === list2[j].SchoolTargetRemark || (!item.SchoolTargetRemark && !list2[j].SchoolTargetRemark)) ) { item.ID = list2[j].ID; item.SchoolTargetRemark = list2[j].SchoolTargetRemark; item.PlanNum = list2[j].PlanNum; item.ScoreTotal = list2[j].ScoreTotal; item.Score1 = list2[j].Score1; item.Score2 = list2[j].Score2; item.Score3 = list2[j].Score3; item.Score4 = list2[j].Score4; item.SchoolTargetRemark2 = list2[j].SchoolTargetRemark2; break; } } } } ctx.body = { "errcode": 10000, result: list }; }