互联网发展至今,无论是其理论还是技术都已经成熟,而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播,搭配信息管理工具可以很好地为人们提供服务。针对四六级报名信息管理混乱,出错率高,信息安全性差,劳动强度大,费时费力等问题,采用四六级报名与成绩查询系统可以有效管理,使信息管理能够更加科学和规范。
四六级报名与成绩查询系统在Eclipse环境中,使用Java语言进行编码,使用Mysql创建数据表保存本系统产生的数据。系统可以提供信息显示和相应服务,其管理员管理考试和考场信息,管理学生,成绩以及老师信息。老师查询考试以及考场信息,管理学生成绩,查看公告。学生对四六级考试进行报名,查询考场以及考试成绩。
2.1 Java语言
Java语言最早是由Sun公司在1995年推出的一门新型的计算机编程语言,经过多年的发展,能够具有大部分计算机编程语言的一些特点。Java语言又是一门基于面向对象思想的计算机编程语言,不仅可以吸收接纳C++语言的优势,也在一定程度上放弃了它的一些不足之处。Java计算机语言具有分布式等特点。Java语言可以开发的应用主要有安卓应用、网站开发等应用。
2.2 Vue框架
Vue框架是可以构建项目用户操作界面的应用框架,所有的系统页面效果设计通过采取自底向上的增量开发设计思想,在项目数据传输上提供了MVVM的业务数据双向绑定思想。Vue框架的主要特点是:1.Vue框架提供了数据的双向绑定进行传输的效果;2.Vue框架项目的数据是通过路由进行管理;3.Vue框架的轻量级,使得开发人员更加容易上手进行项目开发。
2.3 MySQL数据库
MySQL数据库在项目中运行速度快,对于平时开发使用到的平台是没用任何的限制,能够被广泛的应用在企业级开发中。MySQL数据库是指一个基于开源的和多线程的用户关系和管理的数据库系统,MySQL是基于开放源代码的数据库管理系统,能够跨一定的平台且可以正常的进行使用。
MySQL数据库管理并不是让所有的数据表都统一放在一个空间足够大的数据存储容器的里面,而是要把同一个数据库里面存储的全部数据信息都可以分别的存放在各个不同格式的存储表当中,MySQL作为一种关联性数据库的管理系统,能够有效快速地去提升数据处理存储的速度安全性与效率。并且这样也可以让数据库的灵活程度得到很大幅度的提高。
2.4 IDEA开发工具
IDEA开发工具的全称是叫IntelliJ IDEA,是可以进行Java语言功能编码实现的工具之一。IDEA编译工具目前在Java程序编程中是最理想的一种开发工具,它本身既拥有智能的且便捷实用的代码助手、丰富而灵活强大的编码模板库支持、超强且高效简洁的快捷键体系,并且它能自动提示代码、代码分析、全栈开发等方面的功能都极为优秀。提倡智能编码,能够最大限度的减少系统设计上的工作量。
2.5 SSM框架
SSM框架是JAVA语言里面三大基本的应用框架的组合体,是一个标准的MVC的应用框架之一。一个完整的使用SSM框架开发的系统,其代码结构,主要是由四个部分进行组成,能够对业务进行结构化的拆分。在项目中,使用Spring框架可以实现对项目中的所有业务对象信息进行管理,使用SpringMVC框架能够对项目中的用户操作功能的请求信息进行转发并进行其他的操作,使用Mybatis框架可以对项目中的数据信息进行持久化的操作处理。
package com.controller;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.DictionaryEntity;
import com.service.DictionaryService;
import com.entity.view.DictionaryView;
import com.utils.PageUtils;
import com.utils.R;
/**
* 字典表
* 后端接口
* @author
* @email
* @date 2021-03-23
*/
@RestController
@Controller
@RequestMapping("/dictionary")
public class DictionaryController {
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class);
@Autowired
private DictionaryService dictionaryService;
@Autowired
private TokenService tokenService;
//级联表service
/**
* 后端列表
*/
@RequestMapping("/page")
@IgnoreAuth
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isNotEmpty(role) && "用户".equals(role)){
params.put("yonghuId",request.getSession().getAttribute("userId"));
}
PageUtils page = dictionaryService.queryPage(params);
//字典表数据转换
List<DictionaryView> list =(List<DictionaryView>)page.getList();
for(DictionaryView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
DictionaryEntity dictionary = dictionaryService.selectById(id);
if(dictionary !=null){
//entity转view
DictionaryView view = new DictionaryView();
BeanUtils.copyProperties( dictionary , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
.eq("dic_code", dictionary.getDicCode())
.eq("code_index", dictionary.getCodeIndex())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
if(dictionaryEntity==null){
dictionary.setCreateTime(new Date());
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// dictionary.set
// }
dictionaryService.insert(dictionary);
//如果字典表新增数据的话,把数据再重新查出,放入监听器中
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
Map<String, Map<Integer,String>> map = new HashMap<>();
for(DictionaryEntity d :dictionaryEntities){
Map<Integer, String> m = map.get(d.getDicCode());
if(m ==null || m.isEmpty()){
m = new HashMap<>();
}
m.put(d.getCodeIndex(),d.getIndexName());
map.put(d.getDicCode(),m);
}
servletContext.setAttribute("dictionaryMap",map);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString());
//根据字段查询是否有相同数据
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
.notIn("id",dictionary.getId())
.eq("dic_code", dictionary.getDicCode())
.eq("code_index", dictionary.getCodeIndex())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper);
if(dictionaryEntity==null){
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// dictionary.set
// }
dictionaryService.updateById(dictionary);//根据id更新
//如果字典表修改数据的话,把数据再重新查出,放入监听器中
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>());
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
Map<String, Map<Integer,String>> map = new HashMap<>();
for(DictionaryEntity d :dictionaryEntities){
Map<Integer, String> m = map.get(d.getDicCode());
if(m ==null || m.isEmpty()){
m = new HashMap<>();
}
m.put(d.getCodeIndex(),d.getIndexName());
map.put(d.getDicCode(),m);
}
servletContext.setAttribute("dictionaryMap",map);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
dictionaryService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
}
package com.controller;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import com.entity.ChengjiEntity;
import com.entity.KaochangEntity;
import com.entity.LaoshiEntity;
import com.service.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.KaoshiEntity;
import com.entity.view.KaoshiView;
import com.utils.PageUtils;
import com.utils.R;
/**
* 考试
* 后端接口
* @author
* @email
* @date 2021-03-23
*/
@RestController
@Controller
@RequestMapping("/kaoshi")
public class KaoshiController {
private static final Logger logger = LoggerFactory.getLogger(KaoshiController.class);
@Autowired
private KaoshiService kaoshiService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;
@Autowired
private LaoshiService laoshiService;
@Autowired
private KaochangService kaochangService;
@Autowired
private ChengjiService chengjiService;
//级联表service
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isNotEmpty(role) && "用户".equals(role)){
params.put("yonghuId",request.getSession().getAttribute("userId"));
}
PageUtils page = kaoshiService.queryPage(params);
//字典表数据转换
List<KaoshiView> list =(List<KaoshiView>)page.getList();
for(KaoshiView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
KaoshiEntity kaoshi = kaoshiService.selectById(id);
if(kaoshi !=null){
//entity转view
KaoshiView view = new KaoshiView();
BeanUtils.copyProperties( kaoshi , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 保存考试并且默认添加两个考场
*/
@RequestMapping("/save")
public R save(@RequestBody KaoshiEntity kaoshi, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,kaoshi:{}",this.getClass().getName(),kaoshi.toString());
Wrapper<KaoshiEntity> queryWrapper = new EntityWrapper<KaoshiEntity>()
.eq("kaoshi_name", kaoshi.getKaoshiName())
.eq("kaoshi_types", kaoshi.getKaoshiTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
KaoshiEntity kaoshiEntity = kaoshiService.selectOne(queryWrapper);
if(kaoshiEntity==null){
if((kaoshi.getEndTime().getTime()-kaoshi.getStartTime().getTime())<=0){
return R.error("考试结束时间不能小于开始时间");
}
Date date = new Date();
kaoshi.setCreateTime(date);
kaoshiService.insert(kaoshi);
List<LaoshiEntity> laoshiEntities = laoshiService.selectList(new EntityWrapper<LaoshiEntity>());
if(laoshiEntities.size()>1){
Integer laoshiIndex1;
Integer laoshiIndex2;
if(laoshiEntities.size()==2){
laoshiIndex1=1;
laoshiIndex2=2;
}else{
Random random = new Random();
laoshiIndex1 = random.nextInt(laoshiEntities.size()-1);
laoshiIndex2 = random.nextInt(laoshiEntities.size()-1);
boolean flag=true;
while (flag){
if(laoshiIndex1.intValue() == laoshiIndex2.intValue()){
laoshiIndex2 = random.nextInt(laoshiEntities.size()-1);
}else{
flag =false;
}
}
}
//默认添加考场
List<KaochangEntity> kaochangEntityList = new ArrayList<>();
KaochangEntity kaochang1 = new KaochangEntity();
kaochang1.setCreateTime(date);
kaochang1.setKaochangAddress("长椿路第一考场");
kaochang1.setKaochangName(kaoshi.getKaoshiName()+"的第一考场");
kaochang1.setKaoshiId(kaoshi.getId());
kaochang1.setKaoshiNumber(0);
kaochang1.setLaoshiId(laoshiEntities.get(laoshiIndex1).getId());
kaochangEntityList.add(kaochang1);
KaochangEntity kaochang2 = new KaochangEntity();
kaochang2.setCreateTime(date);
kaochang2.setKaochangAddress("长椿路第二考场");
kaochang2.setKaochangName(kaoshi.getKaoshiName()+"的第二考场");
kaochang2.setKaoshiId(kaoshi.getId());
kaochang2.setKaoshiNumber(0);
kaochang2.setLaoshiId(laoshiEntities.get(laoshiIndex2).getId());
kaochangEntityList.add(kaochang2);
kaochangService.insertBatch(kaochangEntityList);
return R.ok();
}else{
return R.error("老师数量过少,生成不出两个考场");
}
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody KaoshiEntity kaoshi, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,kaoshi:{}",this.getClass().getName(),kaoshi.toString());
//根据字段查询是否有相同数据
Wrapper<KaoshiEntity> queryWrapper = new EntityWrapper<KaoshiEntity>()
.notIn("id",kaoshi.getId())
.andNew()
.eq("kaoshi_name", kaoshi.getKaoshiName())
.eq("kaoshi_types", kaoshi.getKaoshiTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
KaoshiEntity kaoshiEntity = kaoshiService.selectOne(queryWrapper);
kaoshi.setStartTime(new Date());
kaoshi.setEndTime(new Date());
if(kaoshiEntity==null){
if((kaoshi.getEndTime().getTime()-kaoshi.getStartTime().getTime())<0){
return R.error("考试结束时间不能小于开始时间");
}
kaoshiService.updateById(kaoshi);//根据id更新
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 报名
*/
@RequestMapping("/baoming")
public R baoming(@RequestParam Integer kaoshiId, HttpServletRequest request){
logger.debug("baoming方法:,,Controller:{},,kaoshiId:{}",this.getClass().getName(),kaoshiId);
String role = String.valueOf(request.getSession().getAttribute("role"));
Integer userId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
if("用户".equals(role)){
KaoshiEntity kaoshiEntity = kaoshiService.selectById(kaoshiId);
if(kaoshiEntity != null){
Integer kaoshiTypes = kaoshiEntity.getKaoshiTypes();
if(kaoshiTypes.intValue() ==1){
ChengjiEntity one = chengjiService.selectOne(new EntityWrapper<ChengjiEntity>().eq("yonghu_id", userId).eq("chengji_types", 3).eq("kaoshi_types",1));
if(one!=null){
return R.error("您已经考过四级考试了");
}
List<KaochangEntity> kaoChangs = kaochangService.selectList(new EntityWrapper<KaochangEntity>().eq("kaoshi_id", kaoshiEntity.getId()));
List<Integer> ids = new ArrayList<>();
for(KaochangEntity k:kaoChangs){
ids.add(k.getId());
}
if(ids != null && ids.size()>0){
List<ChengjiEntity> chengjiEntities = chengjiService.selectList(new EntityWrapper<ChengjiEntity>().eq("yonghu_id", userId).in("kaochang_id", ids));
if(chengjiEntities.size()>0){
return R.error("您已经参加过本次考试了");
}
}
//查询出当前考试的考场人数小于20的考场
List<KaochangEntity> kaochangEntityList = kaochangService.selectList(new EntityWrapper<KaochangEntity>().eq("kaoshi_id", kaoshiEntity.getId()).between("kaoshi_number", 0, 19));
if( kaochangEntityList == null || kaochangEntityList.size()==0 ){
return R.error("可用考场为空");
}else{
//随机获取一个可用考场
KaochangEntity kaochangEntity = kaochangEntityList.get(new Random().nextInt(kaochangEntityList.size() - 1));
kaochangEntity.setKaoshiNumber(kaochangEntity.getKaoshiNumber()+1);
kaochangService.updateById(kaochangEntity);
// 新增成绩 成绩类型为报名
ChengjiEntity chengjiEntity = new ChengjiEntity();
chengjiEntity.setCreateTime(new Date());
chengjiEntity.setChengjiTypes(1);
chengjiEntity.setFraction(null);
chengjiEntity.setKaochangId(kaochangEntity.getId());
chengjiEntity.setYonghuId(userId);
chengjiEntity.setKaoshiTypes(1);
chengjiService.insert(chengjiEntity);
}
}else if(kaoshiTypes.intValue() ==2){
//查出该用户是否存在四级考试合格
ChengjiEntity one = chengjiService.selectOne(new EntityWrapper<ChengjiEntity>().eq("yonghu_id", userId).eq("chengji_types", 3).eq("kaoshi_types",1));
if(one ==null){
return R.error("您先参加四级考试才能参与六级考试");
}
one = chengjiService.selectOne(new EntityWrapper<ChengjiEntity>().eq("yonghu_id", userId).eq("chengji_types", 3).eq("kaoshi_types",2));
if(one!=null){
return R.error("您已经考过六级考试了");
}
List<KaochangEntity> kaoChangs = kaochangService.selectList(new EntityWrapper<KaochangEntity>().eq("kaoshi_id", kaoshiEntity.getId()));
List<Integer> ids = new ArrayList<>();
for(KaochangEntity k:kaoChangs){
ids.add(k.getId());
}
if(ids != null && ids.size()>0){
List<ChengjiEntity> chengjiEntities = chengjiService.selectList(new EntityWrapper<ChengjiEntity>().eq("yonghu_id", userId).in("kaochang_id", ids));
if(chengjiEntities.size()>0){
return R.error("您已经参加过本次考试了");
}
}
//查询出当前考试的考场人数小于20的考场
List<KaochangEntity> kaochangEntityList = kaochangService.selectList(new EntityWrapper<KaochangEntity>().eq("kaoshi_id", kaoshiEntity.getId()).between("kaoshi_number", 0, 19));
if( kaochangEntityList == null || kaochangEntityList.size()==0 ){
return R.error("可用考场为空");
}else{
//随机获取一个可用考场
KaochangEntity kaochangEntity = kaochangEntityList.get(new Random().nextInt(kaochangEntityList.size() - 1));
kaochangEntity.setKaoshiNumber(kaochangEntity.getKaoshiNumber()+1);
kaochangService.updateById(kaochangEntity);
// 新增成绩 成绩类型为报名
ChengjiEntity chengjiEntity = new ChengjiEntity();
chengjiEntity.setCreateTime(new Date());
chengjiEntity.setChengjiTypes(1);
chengjiEntity.setFraction(null);
chengjiEntity.setKaochangId(kaochangEntity.getId());
chengjiEntity.setYonghuId(userId);
chengjiEntity.setKaoshiTypes(2);
chengjiService.insert(chengjiEntity);
}
}else{
return R.error("考试类型不正确");
}
return R.ok();
}else{
return R.error("查不到考试");
}
}else{
return R.error("您没有权限报名考试");
}
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
kaoshiService.deleteBatchIds(Arrays.asList(ids));
kaochangService.delete(new EntityWrapper<KaochangEntity>().in("kaoshi_id",ids));
return R.ok();
}
}