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 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.ChengjiEntity;
import com.service.ChengjiService;
import com.entity.view.ChengjiView;
import com.service.YonghuService;
import com.entity.YonghuEntity;
import com.utils.PageUtils;
import com.utils.R;
/**
* 成绩
* 后端接口
* @author
* @email
* @date 2021-03-03
*/
@RestController
@Controller
@RequestMapping("/chengji")
public class ChengjiController {
private static final Logger logger = LoggerFactory.getLogger(ChengjiController.class);
@Autowired
private ChengjiService chengjiService;
@Autowired
private TokenService tokenService;
//级联表service
@Autowired
private YonghuService yonghuService;
//字典表map
Map<String, Map<Integer, String>> dictionaryMap;
/**
* 后端列表
*/
@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 = chengjiService.queryPage(params);
//字典表数据转换
List<ChengjiView> list =(List<ChengjiView>)page.getList();
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
for(ChengjiView c:list){
this.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);
ChengjiEntity chengji = chengjiService.selectById(id);
if(chengji !=null){
//entity转view
ChengjiView view = new ChengjiView();
BeanUtils.copyProperties( chengji , view );//把实体数据重构到view中
//级联表
YonghuEntity yonghu = yonghuService.selectById(chengji.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//字典表字典转换
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
this.dictionaryConvert(view);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody ChengjiEntity chengji, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,chengji:{}",this.getClass().getName(),chengji.toString());
Wrapper<ChengjiEntity> queryWrapper = new EntityWrapper<ChengjiEntity>()
.eq("yonghu_id", chengji.getYonghuId())
.eq("exam_name", chengji.getExamName())
.eq("kemu_types", chengji.getKemuTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
ChengjiEntity chengjiEntity = chengjiService.selectOne(queryWrapper);
if(chengjiEntity==null){
chengji.setCreateTime(new Date());
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// chengji.set
// }
chengjiService.insert(chengji);
return R.ok();
}else {
return R.error(511,"该学生此次考试本门成绩已经录入过");
}
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody ChengjiEntity chengji, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,chengji:{}",this.getClass().getName(),chengji.toString());
//根据字段查询是否有相同数据
Wrapper<ChengjiEntity> queryWrapper = new EntityWrapper<ChengjiEntity>()
.notIn("id",chengji.getId())
.eq("yonghu_id", chengji.getYonghuId())
.eq("exam_name", chengji.getExamName())
.eq("kemu_types", chengji.getKemuTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
ChengjiEntity chengjiEntity = chengjiService.selectOne(queryWrapper);
if(chengjiEntity==null){
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// chengji.set
// }
chengjiService.updateById(chengji);//根据id更新
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());
chengjiService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*字典表数据转换
*/
public void dictionaryConvert(ChengjiView chengjiView){
//当前表的字典字段
if(StringUtil.isNotEmpty(String.valueOf(chengjiView.getKemuTypes()))){
chengjiView.setKemuValue(dictionaryMap.get("kemu_types").get(chengjiView.getKemuTypes()));
}
//级联表的字典字段
if(StringUtil.isNotEmpty(String.valueOf(chengjiView.getSexTypes()))){
chengjiView.setSexValue(dictionaryMap.get("sex_types").get(chengjiView.getSexTypes()));
}
}
/**
* 柱状图统计统计
*/
@RequestMapping("/group/bar")
@ResponseBody
public R groupBar() {
logger.debug("group:,,Controller:{}",this.getClass().getName());
List<HashMap<String, Object>> map1 = chengjiService.groupBar();
if(map1!= null && map1.size()>0){
//以考试名字分组 如 第一次考试 科目1 第二次考试 科目2 把科目1和科目2合并
Map<String, HashMap<Integer, Double>> map2 = new HashMap<>();//map2 就是可以考试名字作为key 以科目作为vale的值 科目是科目类型为key,平均分数为value
for(HashMap<String, Object> m:map1){
Double avg = Double.parseDouble(m.get("avg").toString());//平均分数
Integer kemu_types = Integer.parseInt(m.get("kemu_types").toString());//科目id
String exam_name = String.valueOf(m.get("exam_name"));//考试名字
HashMap<Integer, Double> oldKemu = map2.get(exam_name);
if( oldKemu==null){
//map2中没有这个对象就�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
JSP+SSM项目-班主任助理系统的Java毕业设计(源码+说明+演示视频+数据库).zip 【项目技术】 开发语言:Java 框架:ssm 架构:B/S 数据库:mysql 【实现功能】 学生信息管理,请假管理,成绩管理,家长信息管理,学业预警管理,实习管理等
资源推荐
资源详情
资源评论
收起资源包目录
JSP+SSM项目-班主任助理系统的Java毕业设计(源码+说明+演示视频+数据库).zip (915个子文件)
pink-violet.css 171KB
yellow-green.css 149KB
bootstrap.min.css 141KB
bootstrap.css 120KB
bootstrap.min.css 98KB
style.css 66KB
animate.css 55KB
ueditor.css 44KB
ueditor.min.css 34KB
font-awesome.min.css 30KB
jquery-ui-1.10.4.custom.min.css 27KB
jquery.treetable.theme.default.css 25KB
animate.css 23KB
styles.css 23KB
entypo-icon.css 23KB
all.css 21KB
font-awesome.css 21KB
video-js.css 21KB
font-awesome.min.css 20KB
all.css 19KB
image.css 19KB
jquery.idealforms.css 17KB
themify-icons.css 16KB
video.css 15KB
attachment.css 15KB
square.min.css 14KB
all.css 14KB
all.css 13KB
all.css 13KB
bootstrap-select.css 13KB
all.css 12KB
dropzone.css 11KB
video-js.min.css 11KB
bootstrap-switch.css 11KB
bootstrap-datetimepicker.min.css 11KB
extra-pages.css 11KB
ladda.min.css 10KB
tooltipster.css 9KB
calendar.css 9KB
responsive.css 8KB
shCoreDefault.css 7KB
social.css 7KB
jquery-jvectormap.css 6KB
clockface.css 6KB
jquery.steps.css 6KB
dripicon.css 5KB
weather-icons.min.css 5KB
footable.core.css 5KB
dataTables.bootstrap4.min.css 5KB
datepicker.css 5KB
style-responsive.css 5KB
tabelizer.min.css 5KB
datepicker.css 5KB
datepicker.css 5KB
footable.standalone.css 5KB
signin.css 5KB
media.css 5KB
family.css 5KB
slidebars.css 4KB
skin-select.css 4KB
datepicker.css 4KB
scrawl.css 4KB
DT_bootstrap.css 4KB
datepicker.css 4KB
lightbox.css 4KB
bootstrap-timepicker.css 3KB
jquery.news-ticker.css 3KB
green.css 3KB
yellow.css 3KB
red.css 3KB
blue.css 3KB
violet.css 3KB
codemirror.css 3KB
bootstrap-colorpicker.css 3KB
maki-icons.css 3KB
jquery.treeview.css 3KB
profile.css 3KB
charts.css 3KB
jquery.searchableSelect.css 2KB
background.css 2KB
bootstrap-wysihtml5.css 2KB
awwwards.css 2KB
jquery.stepy.css 2KB
responsive-table.css 2KB
emotion.css 2KB
dialogbase.css 2KB
jquery.pnotify.default.css 2KB
music.css 2KB
demo.css 1KB
all.css 1KB
polaris.css 1KB
polaris.css 1KB
acc-wizard.min.css 1KB
jquery.easy-pie-chart.css 1KB
futurico.css 1KB
futurico.css 1KB
pace-theme-center-simple.css 1KB
uploader.css 1KB
edittable.css 1KB
editor.css 1KB
共 915 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
岛上程序猿
- 粉丝: 2697
- 资源: 4154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功