diff --git a/models/problem.js b/models/problem.js index 6916ddd..2b8a1f8 100644 --- a/models/problem.js +++ b/models/problem.js @@ -21,7 +21,7 @@ let statisticsStatements = { fastest: -'\ + '\ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -46,7 +46,7 @@ WHERE \ ORDER BY `total_time` ASC \ ', slowest: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -71,7 +71,7 @@ WHERE \ ORDER BY `total_time` DESC \ ', shortest: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -96,7 +96,7 @@ WHERE \ ORDER BY `code_length` ASC \ ', longest: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -121,7 +121,7 @@ WHERE \ ORDER BY `code_length` DESC \ ', earliest: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -146,7 +146,7 @@ WHERE \ ORDER BY `submit_time` ASC \ ', min: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -171,7 +171,7 @@ WHERE \ ORDER BY `max_memory` ASC \ ', max: -' \ + ' \ SELECT \ DISTINCT(`user_id`) AS `user_id`, \ ( \ @@ -201,6 +201,7 @@ let Sequelize = require('sequelize'); let db = syzoj.db; let User = syzoj.model('user'); +let JudgeState = syzoj.model('judge_state'); let File = syzoj.model('file'); const fs = require('fs-extra'); const path = require('path'); @@ -249,17 +250,17 @@ let model = db.define('problem', { values: ['traditional', 'submit-answer', 'interaction'] } }, { - timestamps: false, - tableName: 'problem', - indexes: [ - { - fields: ['title'], - }, - { - fields: ['user_id'], - } - ] -}); + timestamps: false, + tableName: 'problem', + indexes: [ + { + fields: ['title'], + }, + { + fields: ['user_id'], + } + ] + }); let Model = require('./common'); class Problem extends Model { @@ -472,8 +473,6 @@ class Problem extends Model { async getJudgeState(user, acFirst) { if (!user) return null; - let JudgeState = syzoj.model('judge_state'); - let where = { user_id: user.id, problem_id: this.id @@ -498,6 +497,12 @@ class Problem extends Model { }); } + async resetSubmissionCount() { + this.submit_num = await JudgeState.count({ score: { $not: null }, problem_id: this.id }); + this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id }); + await this.save(); + } + // type: fastest / slowest / shortest / longest / earliest async countStatistics(type) { let statement = statisticsStatements[type]; @@ -585,10 +590,12 @@ class Problem extends Model { let addTagIDs = newTagIDs.filter(x => !oldTagIDs.includes(x)); for (let tagID of delTagIDs) { - let map = await ProblemTagMap.findOne({ where: { - problem_id: this.id, - tag_id: tagID - } }); + let map = await ProblemTagMap.findOne({ + where: { + problem_id: this.id, + tag_id: tagID + } + }); await map.destroy(); } @@ -605,10 +612,10 @@ class Problem extends Model { async changeID(id) { id = parseInt(id); - await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id); - await db.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); - await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); - await db.query('UPDATE `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); + await db.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id); + await db.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); + await db.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); + await db.query('UPDATE `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id); let Contest = syzoj.model('contest'); let contests = await Contest.all(); diff --git a/modules/admin.js b/modules/admin.js index 2de0d5d..e448c32 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -198,6 +198,19 @@ app.post('/admin/privilege', async (req, res) => { } }); +app.get('/admin/other', async (req, res) => { + try { + if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); + + res.render('admin_other'); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }) + } +}); + app.get('/admin/rejudge', async (req, res) => { try { if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); @@ -214,6 +227,28 @@ app.get('/admin/rejudge', async (req, res) => { } }); +app.post('/admin/other', async (req, res) => { + try { + if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); + + if (req.body.type === 'reset_count') { + const problems = await Problem.query(); + for(const p of problems) { + await p.resetSubmissionCount(); + } + } else { + throw new ErrorMessage("操作类型不正确"); + } + + res.redirect(syzoj.utils.makeUrl(['admin', 'other'])); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }) + } +}); + app.post('/admin/rejudge', async (req, res) => { try { if (!res.locals.user || !res.locals.user.is_admin) throw new ErrorMessage('您没有权限进行此操作。'); diff --git a/modules/problem.js b/modules/problem.js index 7386e2f..7fa2509 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -533,30 +533,30 @@ app.post('/problem/:id/manage', app.multer.fields([{ name: 'testdata', maxCount: // Set problem public async function setPublic(req, res, is_public) { - try { - let id = parseInt(req.params.id); - let problem = await Problem.fromID(id); - if (!problem) throw new ErrorMessage('无此题目。'); + try { + let id = parseInt(req.params.id); + let problem = await Problem.fromID(id); + if (!problem) throw new ErrorMessage('无此题目。'); - let allowedManage = await problem.isAllowedManageBy(res.locals.user); - if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。'); + let allowedManage = await problem.isAllowedManageBy(res.locals.user); + if (!allowedManage) throw new ErrorMessage('您没有权限进行此操作。'); - problem.is_public = is_public; - problem.publicizer_id = res.locals.user.id; - await problem.save(); + problem.is_public = is_public; + problem.publicizer_id = res.locals.user.id; + await problem.save(); - res.redirect(syzoj.utils.makeUrl(['problem', id])); - } catch (e) { - syzoj.log(e); - res.render('error', { - err: e - }); + res.redirect(syzoj.utils.makeUrl(['problem', id])); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }); + } } -} app.post('/problem/:id/public', async (req, res) => { - await setPublic(req, res, true); -}); + await setPublic(req, res, true); + }); app.post('/problem/:id/dis_public', async (req, res) => { await setPublic(req, res, false); diff --git a/views/admin_header.ejs b/views/admin_header.ejs index ccdd354..23bcad1 100644 --- a/views/admin_header.ejs +++ b/views/admin_header.ejs @@ -5,7 +5,8 @@ let items = { privilege: '权限管理', rejudge: '一键重测', links: '友链管理', - raw: '配置文件' + raw: '配置文件', + other: '其他操作' }; %> <% this.title = items[this.adminPage] + ' - 后台管理'; %> diff --git a/views/admin_other.ejs b/views/admin_other.ejs new file mode 100644 index 0000000..01d1b59 --- /dev/null +++ b/views/admin_other.ejs @@ -0,0 +1,7 @@ +<% this.adminPage = 'rejudge'; %> +<% include admin_header %> +
+ + +
+<% include admin_footer %> diff --git a/views/admin_rejudge.ejs b/views/admin_rejudge.ejs index 2bceb43..10acd21 100644 --- a/views/admin_rejudge.ejs +++ b/views/admin_rejudge.ejs @@ -1,7 +1,6 @@ <% this.adminPage = 'rejudge'; %> <% include admin_header %>
-
diff --git a/views/problem_manage.ejs b/views/problem_manage.ejs index b553cf8..2330e83 100644 --- a/views/problem_manage.ejs +++ b/views/problem_manage.ejs @@ -4,6 +4,7 @@
+ <% include problem_testcases %>