基于spring boot+vue實現的平行志愿錄取系統
1.項目簡介
這兩天干上高考出成績,有不少親戚家的孩子今年高考,和我詢問關于報志愿的問題。老家河北今年是采用所謂的平行志愿。我看了很多的資料才明白什么叫所謂的“平行志愿”。
整個流程好像很是復雜。我突發奇想,心想何不自己編寫一個程序來模擬一下這個所謂的錄取過程呢。
考生成績和志愿是機密類的數據,向我們這樣的平頭百姓向那倒是不太可能的事情,那么就只能自己寫個程序生成一份模擬的成績和志愿數據。
成績比較好辦,因為有個參考,那就是省教育考試院放出的“一分一段成績統計表”。這個東西提供了我們模擬成績數據的很多信息:一是考生的人數,每個分數下的人數都寫得很清楚;二是成績的分布情況,即在不同成績段的考生人數都十分詳細的列出。
2.思路分析
高考填報志愿非常重要,關于志愿填報及院校錄取規則,我們看完院校投檔原理就明白了。
假如甲同學610分乙同學609分。甲報考的志愿,第一個是北郵,第二個是北林;乙同學,第一個報北林,第二個報了北京工業大學。那么問題來了,如果考生甲沒有被他的第一志愿北京郵電大學提檔,那么對于北京林業大學來說,會優先檢索誰的志愿呢?當然是甲同學的,因為平行志愿的錄取規則是分數優先,遵循志愿。那什么叫分數優先,甲乙高考分數,誰的分數高,甲同學高。那么,甲同學的就會優先被他所在省份的教育考試院的電腦檢索系統檢索。那在檢索的時候,考生乙的檔案是屬于停滯狀態的。先看甲同學報的所有志愿,然后再看乙同學報的志愿。所以通過這個案例,我們就知道分數優先,遵循志愿。按照每個考生他所報的志愿從第一個到第二個都是按照這種平行的順序依次進行提檔。那么被提檔之后,這名考生等同于他的提檔機會就沒有了。
那再看第二個問題,如果說考生甲被第一志愿提檔了,但是報專業的時候因為一些因素被退檔了。那么考生甲被退檔之后,它還能再向北京林業大學繼續投檔嗎?答案是否定的。因為一輪投檔就一次機會,如果北京郵電大學被退了,那么我們就會去一批征集志愿,或者是二批次。如果是整個本科批次合并的,就會一退到底,直接到專科或者復讀。很多省份在2019年是最后一屆文理分科。那么對于2020年之后,我們都是新高考選科,那么您想復讀的話可能不符合復讀,或者再報考的要求。所以今年對于2019年高三的家長來說,今年壓力比往年都要大,我們必須要保證我們孩子報考的志愿一次性成功,不能復讀。
3.項目開發
3.1技術棧
- JDK8
- MySQL5.7
- springboot2.3
- maven3.6.3(需要安裝,否則沒有依賴)
- vue2.0(前端開發環境,并不必需)
- vue-cli3(前端開發環境,并不必需)
3.2環境配置
- 打開Mysql,創建數據庫
CREATE DATABASE `<你的數據庫名>` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
-- 例如:CREATE DATABASE `db_enroll` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
- 進入數據庫,運行sql文件,在sql文件夾下,可以把sql放在一個沒有中文路徑的地方,否則有可能出錯
-- 進入剛剛創建的數據庫
use db_enroll;
-- 運行路徑下的sql文件
source /path/to/sql/db_enroll.sql
- 修改springboot配置文件application.yml,找到下面配置
enroll:login:# 登錄用戶名adminName: admin# 登錄密碼adminPass: 123456# 改為自己的數據庫名database: DATABASE_NAME# 改為自己的數據庫密碼(賬號默認root)dbpass: MYSQL_PASSWORD
3.3項目配置
spring:datasource:username: rootpassword: ${enroll.dbpass}url: jdbc:mysql://localhost:3306/${enroll.database}?serverTimezone=GMT%2B8&allowMultiQueries=truedriver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourcedruid:# 連接池的配置信息# 初始化大小,最小,最大initial-size: 5min-idle: 5maxActive: 20# 配置獲取連接等待超時的時間maxWait: 60000# 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒timeBetweenEvictionRunsMillis: 60000# 配置一個連接在池中最小生存的時間,單位是毫秒minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1testWhileIdle: truetestOnBorrow: falsetestOnReturn: false# 打開PSCache,并且指定每個連接上PSCache的大小poolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20# 配置監控統計攔截的filters,去掉后監控界面sql無法統計,'wall'用于防火墻filters: stat,slf4j# 通過connectProperties屬性來打開mergeSql功能;慢SQL記錄connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000# 配置DruidStatFilterweb-stat-filter:enabled: trueurl-pattern: "/*"exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"# 配置DruidStatViewServletstat-view-servlet:url-pattern: "/druid/*"# IP白名單(沒有配置或者為空,則允許所有訪問)allow: 127.0.0.1,192.168.163.1# IP黑名單 (存在共同時,deny優先于allow)reset-enable: false# 登錄名login-username: admin# 登錄密碼login-password: 123456filter:wall:config:multi-statement-allow: trueinitialization-mode: ALWAYSschema:- classpath:sql/schema.sqlinitialize: truedevtools:restart:enabled: truejackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:ss
mybatis:configuration:map-underscore-to-camel-case: truemapper-locations:- classpath:mybatis/mapper/*.xmltype-aliases-package: org.enroll.pojoenroll:login:adminName: adminadminPass: 123456database: db_enrolldbpass: 15975867048
3.4配置類
全局異常捕捉
package org.enroll.configuration;import org.enroll.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import javax.sql.DataSource;
import java.util.HashMap;@Configuration
public class EnrollConfig implements WebMvcConfigurer {@AutowiredLoginInterceptor interceptor;@Value("classpath:sql/schema.sql")private Resource dataScript;@Overridepublic void addInterceptors(InterceptorRegistry registry) {InterceptorRegistration registration = registry.addInterceptor(interceptor);registration.addPathPatterns("/**");registration.excludePathPatterns("/login/doLogin");}@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("http://localhost:8000").allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS").allowedHeaders("*").allowCredentials(true).maxAge(3600).allowedHeaders("*");}@Beanpublic HashMap<String, Object> globalStorage(){return new HashMap<>();}@Beanpublic DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {final DataSourceInitializer initializer = new DataSourceInitializer();initializer.setDataSource(dataSource);initializer.setDatabasePopulator(databasePopulator());initializer.afterPropertiesSet();return initializer;}private DatabasePopulator databasePopulator() {final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();populator.addScript(dataScript);return populator;}
}
登陸信息類
package org.enroll.configuration;import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Data
@Component
@ConfigurationProperties(prefix = "enroll.login")
public class LoginProperties {private String adminName;private String adminPass;
}
攔截器
@Component
public class LoginInterceptor implements HandlerInterceptor {@Resource(name = "globalStorage")Map<String, Object> storage;public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// if(request.getSession().equals(storage.get("authSession")))
// return true;
// response.setCharacterEncoding("UTF-8");
// response.setContentType("application/json");
// response.getWriter().println("{\"code\":\"010\",\"data\":null,\"message\":\"未登錄\"}");
// return false;return true;}
}
3.5常用工具類
查詢結果集
@Data
public class QueryResultOption {private Integer rank;private Integer departmentId;private String majorId;}
json常量
@Getter
@Setter
@AllArgsConstructor
public class JsonResponse {public static final String OK = "000";public static final String SYSTEM_ERROR = "100";public static final String INVALID_REQUEST = "001";public static final String AUTH_ERR = "010";private String code;private Object data;private String message;}
3.6業務代碼
@RestController
@RequestMapping("/student")
public class StudentController {@AutowiredIStudentService studentService;@RequestMapping("/getStudentRaw")public JsonResponse getStudentRaw(@RequestParam(required = false, defaultValue = "1") Integer currentPage){if(currentPage == null || currentPage<=0)return new JsonResponse(JsonResponse.INVALID_REQUEST,null, null);return new JsonResponse(JsonResponse.OK, studentService.getStudentRaw(currentPage), null);}@RequestMapping("/getAdjustStudentRaw")public JsonResponse getAdjustStudentRaw(@RequestParam(required = false, defaultValue = "1") int currentPage){return new JsonResponse(JsonResponse.OK, studentService.getAdjustStudentRaw(currentPage), null);}@RequestMapping("/getExitStudentRaw")public JsonResponse getExitStudentRaw(@RequestParam(required = false, defaultValue = "1") int currentPage){return new JsonResponse(JsonResponse.OK, studentService.getExitStudentRaw(currentPage), null);}@RequestMapping("/doEnroll")public JsonResponse doEnroll(){studentService.doEnroll();return new JsonResponse(JsonResponse.OK, null, null);}@RequestMapping("/doAdjust")public JsonResponse doAdjust(){studentService.doAdjust();return new JsonResponse(JsonResponse.OK, null, null);}// StatisticsResult getResult(int currentPage, boolean desc);@RequestMapping("/getResult")public JsonResponse getResult(@RequestParam(required = false, defaultValue = "1") int currentPage,@RequestParam(required = false, defaultValue = "false") boolean desc,QueryResultOption option){return new JsonResponse(JsonResponse.OK, studentService.getResult(currentPage, desc, option), null);}
// StatisticsResult getResultByDepartment( int departmentId, int currentPage, boolean desc);/*** @description t通過學院、專業、排名查詢已棄用,請使用上面的getResult* @author 李宏鑫* @param null* @return* @updateTime 2021/1/7 20:53* @throws*/@RequestMapping("/getResultByDepartment")@Deprecatedpublic JsonResponse getResultByDepartment(int departmentId, @RequestParam(required = false, defaultValue = "1") int currentPage, @RequestParam(required = false, defaultValue = "false") boolean desc){return new JsonResponse(JsonResponse.OK, studentService.getResultByDepartment(departmentId, currentPage, desc), null);}
// StatisticsResult getResultByMajor( String majorId, int currentPage, boolean desc);@RequestMapping("/getResultByMajor")@Deprecatedpublic JsonResponse getResultByMajor(String majorId, @RequestParam(required = false, defaultValue = "1") int currentPage, @RequestParam(required = false, defaultValue = "false") boolean desc){return new JsonResponse(JsonResponse.OK, studentService.getResultByMajor(majorId, currentPage, desc), null);}@RequestMapping("/searchStudent")@Deprecatedpublic JsonResponse searchStudent(@RequestParam(required = false, defaultValue = "1") int currentPage,String keyword){return new JsonResponse(JsonResponse.OK, studentService.searchStudent(currentPage,keyword), null);}@RequestMapping("/searchStudentByCandidate")public JsonResponse searchStudentByCandidate(@RequestParam(required = false, defaultValue = "1") int currentPage,String keyword){return new JsonResponse(JsonResponse.OK, studentService.searchStudentByCandidate(currentPage,keyword), null);}@RequestMapping("/getStudentBeforeRank")public JsonResponse getStudentBeforeRank(@RequestParam(required = false, defaultValue = "1") int currentPage, int rank){return new JsonResponse(JsonResponse.OK, studentService.getStudentBeforeRank(currentPage, rank), null);}@RequestMapping("/getStatisticsResult")public JsonResponse getStatisticsResult(){return new JsonResponse(JsonResponse.OK, studentService.getStatisticsResult(), null);}
// List<Map<String, Object>> getResultInDepartment(int departmentId);@RequestMapping("/getStatisticsResultInDepartment")public JsonResponse getStatisticsResultInDepartment(){return new JsonResponse(JsonResponse.OK, studentService.getStatisticsResultInDepartment(), null);}
// List<Map<String, Object>> getResultInMajor(String majorId);@RequestMapping("/getStatisticsResultInMajor")public JsonResponse getStatisticsResultInMajor(){return new JsonResponse(JsonResponse.OK, studentService.getStatisticsResultInMajor(), null);}// Map<String, Integer> getDistribute();@RequestMapping("/getDistribute")public JsonResponse getDistribute(){return new JsonResponse(JsonResponse.OK, studentService.getDistribute(), null);}// Map<String, Integer> getDistributeInProvince(String province);@RequestMapping("/getDistributeInProvince")public JsonResponse getDistributeInProvince(String province){return new JsonResponse(JsonResponse.OK, studentService.getDistributeInProvince(province), null);}// Map<String, Integer> getGradeDistribute();@RequestMapping("/getGradeDistribute")public JsonResponse getGradeDistribute(){return new JsonResponse(JsonResponse.OK, studentService.getGradeDistribute(), null);}// Map<String, Integer> getGradeDistributeByDepartment( int departmentId);@RequestMapping("/getGradeDistributeByDepartment")public JsonResponse getGradeDistributeByDepartment(int departmentId){return new JsonResponse(JsonResponse.OK, studentService.getGradeDistributeByDepartment(departmentId), null);}// Map<String, Integer> getGradeDistributeByMajor(String majorId);@RequestMapping("/getGradeDistributeByMajor")public JsonResponse getGradeDistributeByMajor(String majorId){return new JsonResponse(JsonResponse.OK, studentService.getGradeDistributeByMajor(majorId), null);}// Map<String, Integer> getCountDistributeInDepartment();@RequestMapping("/getCountDistributeInDepartment")public JsonResponse getCountDistributeInDepartment(){return new JsonResponse(JsonResponse.OK, studentService.getCountDistributeInDepartment(), null);}// Map<String, Integer> getCountDistributeInMajor();@RequestMapping("/getCountDistributeInMajor")public JsonResponse getCountDistributeInMajor(){return new JsonResponse(JsonResponse.OK, studentService.getCountDistributeInMajor(), null);}// Map<String, Integer> getCountDistributeInMajorByDepartment(int departmentId);@RequestMapping("/getCountDistributeInMajorByDepartment")public JsonResponse getCountDistributeInMajorByDepartment(int departmentId){return new JsonResponse(JsonResponse.OK, studentService.getCountDistributeInMajorByDepartment(departmentId), null);}@RequestMapping("/reset")@Deprecatedpublic JsonResponse reset(){studentService.reset();return new JsonResponse(JsonResponse.OK, null, null);}@RequestMapping("/formalReady")@Deprecatedpublic JsonResponse formalReady(){studentService.formallyReady();return new JsonResponse(JsonResponse.OK, null, null);}
}
3.7前端代碼
<template><div id="back-stage-student-info"><empty-data v-if="studentInfo == null || studentInfo.length === 0"/><div id="student-plan-info" v-else><table-row-count :count="total"></table-row-count><el-table:data="studentInfo"stripestyle="width: 100%"><el-table-columnprop="candidate"label="準考證號"width="110"></el-table-column><el-table-columnprop="studentName"label="姓名"></el-table-column><el-table-columnprop="totalGrade"label="總分"></el-table-column><el-table-columnprop="rank"label="排名"></el-table-column><el-table-columnprop="will1"label="志愿1"></el-table-column><el-table-columnprop="will2"label="志愿2"></el-table-column><el-table-columnprop="will3"label="志愿3"></el-table-column><el-table-columnprop="will4"label="志愿4"></el-table-column><el-table-columnprop="will5"label="志愿5"></el-table-column><el-table-columnprop="will6"label="志愿6"></el-table-column><el-table-columnprop="province"label="省份"></el-table-column><el-table-columnprop="city"label="城市"></el-table-column><el-table-columnprop="subjectType"label="科類"></el-table-column></el-table><div class="page-bar" ><el-paginationlayout="prev, pager, next, jumper"@current-change="changePage":page-size="50":current-page.sync="currentPage"hide-on-single-page:total="total"></el-pagination></div></div></div>
</template><script>import {request} from "../../network/request";import EmptyData from "./EmptyData"import TableRowCount from './TableRowCount'export default {name: "StudentInfo",data() {return {studentInfo: null,currentPage: 1,total: 0,loading: null}},methods: {changePage(){this.loadStudentInfo();},loadStudentInfo(){this.setLoading();request({url: 'student/getStudentRaw',params: {currentPage: this.currentPage}}) .then( res => {if (res.code === '000'){this.studentInfo = res.data.list;this.total = res.data.total;} else {this.$message.error(res.message)}}).catch( err => {this.$message.error('系統錯誤')}).finally( () => {this.setUnloading();})},setLoading(){this.loading = this.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.7)'});},setUnloading(){this.loading.close();}},created(){this.loadStudentInfo();},components: {EmptyData,TableRowCount}}
</script><style scoped lang="less">.page-bar{width: 500px;margin: 30px auto;}
</style>
4.項目演示
4.1登錄
4.2導入(測試文件在excel文件夾下,數據為隨機模擬)
表格信息
4.3統計信息
4.4生源地分布
4.5導出結果
5.總結
廣東工業大學課程設計 數據庫課程設計 平行志愿錄取系統(后端代碼,廣東工業大學數據庫大作業) 基于java、spring、MySQL數據庫、vue.js的課程設計