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.YonghuEntity;
import com.service.YonghuService;
import com.entity.view.YonghuView;
import com.utils.PageUtils;
import com.utils.R;
/**
* 学生
* 后端接口
* @author
* @email
* @date 2021-03-02
*/
@RestController
@Controller
@RequestMapping("/yonghu")
public class YonghuController {
private static final Logger logger = LoggerFactory.getLogger(YonghuController.class);
@Autowired
private YonghuService yonghuService;
@Autowired
private TokenService tokenService;
//级联表service
//字典表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));
PageUtils page = yonghuService.queryPage(params);
//字典表数据转换
List<YonghuView> list =(List<YonghuView>)page.getList();
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
for(YonghuView 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);
YonghuEntity yonghu = yonghuService.selectById(id);
if(yonghu !=null){
//entity转view
YonghuView view = new YonghuView();
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
//字典表字典转换
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 YonghuEntity yonghu, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
.eq("username", yonghu.getUsername())
.eq("password", yonghu.getPassword())
.eq("name", yonghu.getName())
.eq("phone", yonghu.getPhone())
.eq("id_number", yonghu.getIdNumber())
.eq("sex_types", yonghu.getSexTypes())
.eq("nation", yonghu.getNation())
.eq("politics_types", yonghu.getPoliticsTypes())
.eq("birthplace", yonghu.getBirthplace())
.eq("yonghu_types", yonghu.getYonghuTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
if(yonghuEntity==null){
yonghu.setCreateTime(new Date());
yonghu.setPassword("123456");
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// yonghu.set
// }
yonghuService.insert(yonghu);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
//根据字段查询是否有相同数据
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
.notIn("id",yonghu.getId())
.eq("username", yonghu.getUsername())
.eq("password", yonghu.getPassword())
.eq("name", yonghu.getName())
.eq("phone", yonghu.getPhone())
.eq("id_number", yonghu.getIdNumber())
.eq("sex_types", yonghu.getSexTypes())
.eq("nation", yonghu.getNation())
.eq("politics_types", yonghu.getPoliticsTypes())
.eq("birthplace", yonghu.getBirthplace())
.eq("yonghu_types", yonghu.getYonghuTypes())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
if("".equals(yonghu.getMyPhoto()) || "null".equals(yonghu.getMyPhoto())){
yonghu.setMyPhoto(null);
}
if(yonghuEntity==null){
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// yonghu.set
// }
yonghuService.updateById(yonghu);//根据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());
yonghuService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*字典表数据转换
*/
public void dictionaryConvert(YonghuView yonghuView){
//当前表的字典字段
if(StringUtil.isNotEmpty(String.valueOf(yonghuView.getSexTypes()))){
yonghuView.setSexValue(dictionaryMap.get("sex_types").get(yonghuView.getSexTypes()));
}
if(StringUtil.isNotEmpty(String.valueOf(yonghuView.getPoliticsTypes()))){
yonghuView.setPoliticsValue(dictionaryMap.get("politics_types").get(yonghuView.getPoliticsTypes()));
}
if(StringUtil.isNotEmpty(String.valueOf(yonghuView.getYonghuTypes()))){
yonghuView.setYonghuValue(dictionaryMap.get("yonghu_types").get(yonghuView.getYonghuTypes()));
}
//级联表的字典字段
}
/**
* 登录
*/
@IgnoreAuth
@PostMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
if(yonghu==null || !yonghu.getPassword().equals(password)) {
return R.error("账号或密码不正确");
}
ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
dictionaryMap = (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
String role = dictionaryMap.get("yonghu_types").get(yonghu.getYonghuTypes());
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu",role );
R r = R.ok();
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
学生管理系统提供的功能有: 学生管理:学生管理增删改查 成绩管理:成绩增删改查 请假信息管理:请假信息增删改查 任务管理:任务增删改查 系统公告管理:系统公告增删改查 留言管理:留言增删改查
资源推荐
资源详情
资源评论
收起资源包目录
多角色学生管理系统-java-基于SSMl的多角色学生管理系统设计与实现(毕业论文) (986个子文件)
CommonController.class 10KB
YonghuController.class 9KB
QingjiaController.class 9KB
ChengjiController.class 8KB
DictionaryController.class 7KB
XitonggonggaoController.class 7KB
MPUtil.class 7KB
RenwuController.class 6KB
UserController.class 6KB
YonghuEntity.class 6KB
QingjiaEntity.class 5KB
TokenServiceImpl.class 4KB
FileController.class 4KB
DictionaryEntity.class 4KB
LiuyanxinxiController.class 4KB
BaiduUtil.class 4KB
QingjiaView.class 4KB
ChengjiView.class 4KB
LiuyanxinxiEntity.class 4KB
RenwuEntity.class 4KB
ChengjiEntity.class 4KB
AuthorizationInterceptor.class 4KB
XitonggonggaoEntity.class 4KB
YonghuVO.class 4KB
ConfigController.class 4KB
YonghuModel.class 3KB
DictionaryServletContextListener.class 3KB
Query.class 3KB
QingjiaVO.class 3KB
UserServiceImpl.class 3KB
PageUtils.class 3KB
TokenEntity.class 3KB
QingjiaModel.class 3KB
DictionaryVO.class 2KB
LiuyanxinxiVO.class 2KB
CommonServiceImpl.class 2KB
ChengjiVO.class 2KB
RenwuVO.class 2KB
DictionaryModel.class 2KB
XitonggonggaoVO.class 2KB
LiuyanxinxiModel.class 2KB
XitonggonggaoServiceImpl.class 2KB
LiuyanxinxiServiceImpl.class 2KB
DictionaryServiceImpl.class 2KB
ChengjiModel.class 2KB
QingjiaServiceImpl.class 2KB
ChengjiServiceImpl.class 2KB
RenwuModel.class 2KB
YonghuServiceImpl.class 2KB
RenwuServiceImpl.class 2KB
XitonggonggaoModel.class 2KB
R.class 2KB
UserEntity.class 2KB
YonghuView.class 2KB
ValidatorUtils.class 2KB
SpringContextUtils.class 2KB
HttpClientUtils.class 2KB
ConfigServiceImpl.class 2KB
TypeEnum.class 1KB
RenwuView.class 1KB
JQPageInfo.class 1KB
EIException.class 1KB
ConfigEntity.class 1KB
SQLFilter.class 1KB
XitonggonggaoView.class 1KB
LiuyanxinxiView.class 1KB
DictionaryView.class 1KB
TokenService.class 1KB
CommonUtil.class 1KB
CommonDao.class 979B
CommonService.class 954B
FileUtil.class 932B
TokenDao.class 907B
UserDao.class 900B
MyMetaObjectHandler.class 900B
UserService.class 871B
XitonggonggaoDao.class 696B
LiuyanxinxiDao.class 688B
DictionaryDao.class 684B
ChengjiDao.class 672B
QingjiaDao.class 672B
YonghuDao.class 668B
RenwuDao.class 664B
StringUtil.class 634B
XitonggonggaoService.class 448B
LiuyanxinxiService.class 442B
DictionaryService.class 439B
QingjiaService.class 430B
ChengjiService.class 430B
IgnoreAuth.class 428B
ConfigService.class 427B
YonghuService.class 427B
RenwuService.class 424B
APPLoginUser.class 395B
LoginUser.class 389B
ConfigDao.class 269B
.classpath 1KB
org.eclipse.wst.common.component 659B
org.eclipse.wst.jsdt.ui.superType.container 49B
pink-violet.css 171KB
共 986 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
code.song
- 粉丝: 389
- 资源: 915
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功