传统办法管理信息首先需要花费的时间比较多,其次数据出错率比较高,而且对错误的数据进行更改也比较困难,最后,检索数据费事费力。因此,在计算机上安装高校物品捐赠管理系统软件来发挥其高效地信息处理的作用,可以规范信息管理流程,让管理工作可以系统化和程序化,同时,高校物品捐赠管理系统的有效运用可以帮助管理人员准确快速地处理信息。
高校物品捐赠管理系统在对开发工具的选择上也很慎重,为了便于开发实现,选择的开发工具为Eclipse或idea,选择的数据库工具为Mysql。以此搭建开发环境实现高校物品捐赠管理系统的功能。其中管理员管理用户,新闻公告。
高校物品捐赠管理系统是一款运用软件开发技术设计实现的应用系统,在信息处理上可以达到快速的目的,不管是针对数据添加,数据维护和统计,以及数据查询等处理要求,高校物品捐赠管理系统都可以轻松应对。
关键词:高校物品捐赠管理系统;SpringBoot框架,系统分析,数据库设计
基于springboot高校物品捐赠管理系统源码和论文505
演示视频:
基于springboot高校物品捐赠管理系统源码和论文
Abstract
The traditional method of managing public transportation information first takes more time, and secondly, the data error rate is relatively high, and it is more difficult to modify the wrong data, and finally, it is laborious and laborious to retrieve the data. Therefore, installing the public transportation query website software on the computer to play its role in efficient information processing can standardize the public transportation information management process, so that the management work can be systematized and programmed. At the same time, the effective use of the public transportation query website can help managers accurately Process information quickly.
The public transportation query website is also very cautious in the selection of development tools. In order to facilitate the development and realization, the selected development tool is Eclipse, and the selected database tool is Mysql. In this way, the development environment is built to realize the functions of the public transport query website. Among them, the administrator manages users, drivers, news announcements, manages vehicles, stations, and trip information in the route management module, and responds to users' suggested messages in the message suggestion management module. Users inquire about the site, inquire about transfer information, post message suggestions, and check news announcements.
The bus query website is an application system designed and implemented using software development technology. It can achieve rapid information processing. Whether it is for data addition, data maintenance and statistics, and data query processing requirements, the bus query website can easily response.
Key Words:Public transport query website; bus number information; suggestion to leave a message; query site
数据库设计
一般来说,对用户进行调查,了解其需求,主要还是完成功能上的分析设计,殊不知,设计功能时,也要展示对数据库的设计。数据库服务于程序,它可以按照设定的规则对程序的数据进行保存,因此,也可以说数据库就是程序相关数据的集合。为了保证程序的高质量,数据库提供的数据存储服务也需要快速响应,同时数据信息也要安全合法可靠,所以设计一个数据库这样的任务也需要高度重视,并花时间和精力去努力完成。毕竟这影响到后期程序的开发和使用。试想而知,假设设计一个不好的数据库,遇到的问题将会有:第一,面对信息处理,会有着繁琐的业务逻辑,延长事务处理时间。第二:程序编码期间,将会产生更多的代码去完成数据处理的功能,产生大量的数据冗余,而且也不方便注释代码,还会占用更多的存储空间。综上所述,设计出合理的数据库是多么的重要。
表4.1字典表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | dic_code | String | 字段 | 是 |
3 | dic_name | String | 字段名 | 是 |
4 | code_index | Integer | 编码 | 是 |
5 | index_name | String | 编码名字 | 是 |
6 | super_id | Integer | 父字段id | 是 |
7 | beizhu | String | 备注 | 是 |
8 | create_time | Date | 创建时间 | 是 |
表4.2论坛表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | forum_name | String | 帖子标题 | 是 |
3 | yonghu_id | Integer | 用户 | 是 |
4 | users_id | Integer | 管理员 | 是 |
5 | forum_content | String | 发布内容 | 是 |
6 | super_ids | Integer | 父id | 是 |
7 | forum_state_types | Integer | 帖子状态 | 是 |
8 | insert_time | Date | 发帖时间 | 是 |
9 | update_time | Date | 修改时间 | 是 |
10 | create_time | Date | 创建时间 | 是 |
表4.3捐赠信息表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | qiuzhu_id | Integer | 求助 | 是 |
3 | yonghu_id | Integer | 用户 | 是 |
4 | juanzheng_num | Integer | 捐赠数量 | 是 |
5 | juanzheng_text | String | 备注 | 是 |
6 | insert_time | Date | 发布日期 | 是 |
7 | create_time | Date | 创建时间 | 是 |
表4.4公告求助表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | news_name | String | 公告标题 | 是 |
3 | news_types | Integer | 论坛信息 | 是 |
4 | news_photo | String | 公告图片 | 是 |
5 | insert_time | Date | 添加时间 | 是 |
6 | news_content | String | 公告详情 | 是 |
7 | create_time | Date | 创建时间 | 是 |
表4.5求助信息表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | yonghu_id | Integer | 用户 | 是 |
3 | qiuzhu_name | String | 求助标题 | 是 |
4 | qiuzhu_photo | String | 求助封面 | 是 |
5 | qiuzhu_types | Integer | 类别 | 是 |
6 | qiuzhu_wupin | String | 物品名称 | 是 |
7 | qiuzhu_num | Integer | 所需数量 | 是 |
8 | qiuzhu_address | String | 地址 | 是 |
9 | qiuzhu_tihuo | String | 提货方式 | 是 |
10 | qiuzhu_clicknum | Integer | 求助热度 | 是 |
11 | qiuzhu_content | String | 求助介绍 | 是 |
12 | qiuzhu_yesno_types | Integer | 求助审核 | 是 |
13 | qiuzhu_yesno_text | String | 审核回复 | 是 |
14 | qiuzhu_delete | Integer | 逻辑删除 | 是 |
15 | insert_time | Date | 录入时间 | 是 |
16 | create_time | Date | 创建时间 homeMain | 是 |
表4.6求助收藏表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | qiuzhu_id | Integer | 求助 | 是 |
3 | yonghu_id | Integer | 用户 | 是 |
4 | qiuzhu_collection_types | Integer | 类型 | 是 |
5 | insert_time | Date | 收藏时间 | 是 |
6 | create_time | Date | 创建时间 | 是 |
表4.7求助留言表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | qiuzhu_id | Integer | 求助 | 是 |
3 | yonghu_id | Integer | 用户 | 是 |
4 | qiuzhu_liuyan_text | String | 留言内容 | 是 |
5 | insert_time | Date | 留言时间 | 是 |
6 | reply_text | String | 回复内容 | 是 |
7 | update_time | Date | 回复时间 | 是 |
8 | create_time | Date | 创建时间 | 是 |
表4.8用户表
序号 | 列名 | 数据类型 | 说明 | 允许空 |
1 | Id | Int | id | 否 |
2 | yonghu_name | String | 用户名称 | 是 |
3 | yonghu_phone | String | 用户手机号 | 是 |
4 | yonghu_id_number | String | 用户身份证号 | 是 |
5 | yonghu_photo | String | 用户头像 | 是 |
6 | yonghu_email | String | 用户邮箱 | 是 |
7 | yonghu_jif | Integer | 积分数量 | 是 |
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
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.*;
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.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 求助信息
* 后端接口
* @author
* @email
*/
@RestController
@Controller
@RequestMapping("/qiuzhu")
public class QiuzhuController {
private static final Logger logger = LoggerFactory.getLogger(QiuzhuController.class);
private static final String TABLE_NAME = "qiuzhu";
@Autowired
private QiuzhuService qiuzhuService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;//字典
@Autowired
private ForumService forumService;//论坛
@Autowired
private JuanzhengService juanzhengService;//捐赠信息
@Autowired
private NewsService newsService;//公告资讯
@Autowired
private QiuzhuCollectionService qiuzhuCollectionService;//求助收藏
@Autowired
private QiuzhuLiuyanService qiuzhuLiuyanService;//求助留言
@Autowired
private YonghuService yonghuService;//用户
@Autowired
private UsersService usersService;//管理员
/**
* 后端列表
*/
@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(false)
return R.error(511,"永不会进入");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
params.put("qiuzhuDeleteStart",1);params.put("qiuzhuDeleteEnd",1);
CommonUtil.checkMap(params);
PageUtils page = qiuzhuService.queryPage(params);
//字典表数据转换
List<QiuzhuView> list =(List<QiuzhuView>)page.getList();
for(QiuzhuView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
QiuzhuEntity qiuzhu = qiuzhuService.selectById(id);
if(qiuzhu !=null){
//entity转view
QiuzhuView view = new QiuzhuView();
BeanUtils.copyProperties( qiuzhu , view );//把实体数据重构到view中
//级联表 用户
//级联表
YonghuEntity yonghu = yonghuService.selectById(qiuzhu.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段,当前表的级联注册表
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody QiuzhuEntity qiuzhu, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,qiuzhu:{}",this.getClass().getName(),qiuzhu.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永远不会进入");
else if("用户".equals(role))
qiuzhu.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
Wrapper<QiuzhuEntity> queryWrapper = new EntityWrapper<QiuzhuEntity>()
.eq("yonghu_id", qiuzhu.getYonghuId())
.eq("qiuzhu_name", qiuzhu.getQiuzhuName())
.eq("qiuzhu_types", qiuzhu.getQiuzhuTypes())
.eq("qiuzhu_wupin", qiuzhu.getQiuzhuWupin())
.eq("qiuzhu_num", qiuzhu.getQiuzhuNum())
.eq("qiuzhu_address", qiuzhu.getQiuzhuAddress())
.eq("qiuzhu_tihuo", qiuzhu.getQiuzhuTihuo())
.in("qiuzhu_yesno_types", new Integer[]{1,2})
.eq("qiuzhu_delete", 1)
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
QiuzhuEntity qiuzhuEntity = qiuzhuService.selectOne(queryWrapper);
if(qiuzhuEntity==null){
qiuzhu.setQiuzhuClicknum(1);
qiuzhu.setQiuzhuYesnoTypes(1);
qiuzhu.setQiuzhuDelete(1);
qiuzhu.setInsertTime(new Date());
qiuzhu.setCreateTime(new Date());
qiuzhuService.insert(qiuzhu);
return R.ok();
}else {
if(qiuzhuEntity.getQiuzhuYesnoTypes()==1)
return R.error(511,"有相同的待审核的数据");
else if(qiuzhuEntity.getQiuzhuYesnoTypes()==2)
return R.error(511,"有相同的审核通过的数据");
else
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody QiuzhuEntity qiuzhu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
logger.debug("update方法:,,Controller:{},,qiuzhu:{}",this.getClass().getName(),qiuzhu.toString());
QiuzhuEntity oldQiuzhuEntity = qiuzhuService.selectById(qiuzhu.getId());//查询原先数据
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永远不会进入");
// else if("用户".equals(role))
// qiuzhu.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
if("".equals(qiuzhu.getQiuzhuPhoto()) || "null".equals(qiuzhu.getQiuzhuPhoto())){
qiuzhu.setQiuzhuPhoto(null);
}
qiuzhuService.updateById(qiuzhu);//根据id更新
return R.ok();
}
/**
* 审核
*/
@RequestMapping("/shenhe")
public R shenhe(@RequestBody QiuzhuEntity qiuzhuEntity, HttpServletRequest request){
logger.debug("shenhe方法:,,Controller:{},,qiuzhuEntity:{}",this.getClass().getName(),qiuzhuEntity.toString());
QiuzhuEntity oldQiuzhu = qiuzhuService.selectById(qiuzhuEntity.getId());//查询原先数据
// if(qiuzhuEntity.getQiuzhuYesnoTypes() == 2){//通过
// qiuzhuEntity.setQiuzhuTypes();
// }else if(qiuzhuEntity.getQiuzhuYesnoTypes() == 3){//拒绝
// qiuzhuEntity.setQiuzhuTypes();
// }
qiuzhuService.updateById(qiuzhuEntity);//审核
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
List<QiuzhuEntity> oldQiuzhuList =qiuzhuService.selectBatchIds(Arrays.asList(ids));//要删除的数据
ArrayList<QiuzhuEntity> list = new ArrayList<>();
for(Integer id:ids){
QiuzhuEntity qiuzhuEntity = new QiuzhuEntity();
qiuzhuEntity.setId(id);
qiuzhuEntity.setQiuzhuDelete(2);
list.add(qiuzhuEntity);
}
if(list != null && list.size() >0){
qiuzhuService.updateBatchById(list);
}
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName, HttpServletRequest request){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
try {
List<QiuzhuEntity> qiuzhuList = new ArrayList<>();//上传的东西
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List<String> data:dataList){
//循环
QiuzhuEntity qiuzhuEntity = new QiuzhuEntity();
// qiuzhuEntity.setYonghuId(Integer.valueOf(data.get(0))); //用户 要改的
// qiuzhuEntity.setQiuzhuName(data.get(0)); //求助标题 要改的
// qiuzhuEntity.setQiuzhuPhoto("");//详情和图片
// qiuzhuEntity.setQiuzhuTypes(Integer.valueOf(data.get(0))); //类别 要改的
// qiuzhuEntity.setQiuzhuWupin(data.get(0)); //物品名称 要改的
// qiuzhuEntity.setQiuzhuNum(Integer.valueOf(data.get(0))); //所需数量 要改的
// qiuzhuEntity.setQiuzhuAddress(data.get(0)); //地址 要改的
// qiuzhuEntity.setQiuzhuTihuo(data.get(0)); //提货方式 要改的
// qiuzhuEntity.setQiuzhuClicknum(Integer.valueOf(data.get(0))); //求助热度 要改的
// qiuzhuEntity.setQiuzhuContent("");//详情和图片
// qiuzhuEntity.setQiuzhuYesnoTypes(Integer.valueOf(data.get(0))); //求助审核 要改的
// qiuzhuEntity.setQiuzhuYesnoText(data.get(0)); //审核回复 要改的
// qiuzhuEntity.setQiuzhuDelete(1);//逻辑删除字段
// qiuzhuEntity.setInsertTime(date);//时间
// qiuzhuEntity.setCreateTime(date);//时间
qiuzhuList.add(qiuzhuEntity);
//把要查询是否重复的字段放入map中
}
//查询是否重复
qiuzhuService.insertBatch(qiuzhuList);
return R.ok();
}
}
}
}catch (Exception e){
e.printStackTrace();
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 个性推荐
*/
@IgnoreAuth
@RequestMapping("/gexingtuijian")
public R gexingtuijian(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
List<QiuzhuView> returnQiuzhuViewList = new ArrayList<>();
//查看收藏
Map<String, Object> params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId"));
params1.put("shangxiaTypes",1);
params1.put("qiuzhuYesnoTypes",2);
params1.put("sort","yonghu_jif");
CommonUtil.checkMap(params1);
PageUtils pageUtils = qiuzhuCollectionService.queryPage(params1);
List<QiuzhuCollectionView> collectionViewsList =(List<QiuzhuCollectionView>)pageUtils.getList();
Map<Integer,Integer> typeMap=new HashMap<>();//购买的类型list
for(QiuzhuCollectionView collectionView:collectionViewsList){
Integer qiuzhuTypes = collectionView.getQiuzhuTypes();
if(typeMap.containsKey(qiuzhuTypes)){
typeMap.put(qiuzhuTypes,typeMap.get(qiuzhuTypes)+1);
}else{
typeMap.put(qiuzhuTypes,1);
}
}
List<Integer> typeList = new ArrayList<>();//排序后的有序的类型 按最多到最少
typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序
Integer limit = Integer.valueOf(String.valueOf(params.get("limit")));
for(Integer type:typeList){
Map<String, Object> params2 = new HashMap<>(params);params2.put("qiuzhuTypes",type);
params2.put("shangxiaTypes",1);
params2.put("qiuzhuYesnoTypes",2);
params2.put("sort","yonghu_jif");
CommonUtil.checkMap(params2);
PageUtils pageUtils1 = qiuzhuService.queryPage(params2);
List<QiuzhuView> qiuzhuViewList =(List<QiuzhuView>)pageUtils1.getList();
returnQiuzhuViewList.addAll(qiuzhuViewList);
if(returnQiuzhuViewList.size()>= limit) break;//返回的推荐数量大于要的数量 跳出循环
}
params.put("shangxiaTypes",1);
params.put("qiuzhuYesnoTypes",2);
params.put("sort","yonghu_jif");
//正常查询出来商品,用于补全推荐缺少的数据
PageUtils page = qiuzhuService.queryPage(params);
if(returnQiuzhuViewList.size()<limit){//返回数量还是小于要求数量
int toAddNum = limit - returnQiuzhuViewList.size();//要添加的数量
List<QiuzhuView> qiuzhuViewList =(List<QiuzhuView>)page.getList();
for(QiuzhuView qiuzhuView:qiuzhuViewList){
Boolean addFlag = true;
for(QiuzhuView returnQiuzhuView:returnQiuzhuViewList){
if(returnQiuzhuView.getId().intValue() ==qiuzhuView.getId().intValue()) addFlag=false;//返回的数据中已存在此商品
}
if(addFlag){
toAddNum=toAddNum-1;
returnQiuzhuViewList.add(qiuzhuView);
if(toAddNum==0) break;//够数量了
}
}
}else {
returnQiuzhuViewList = returnQiuzhuViewList.subList(0, limit);
}
for(QiuzhuView c:returnQiuzhuViewList)
dictionaryService.dictionaryConvert(c, request);
page.setList(returnQiuzhuViewList);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
CommonUtil.checkMap(params);
PageUtils page = qiuzhuService.queryPage(params);
//字典表数据转换
List<QiuzhuView> list =(List<QiuzhuView>)page.getList();
for(QiuzhuView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
QiuzhuEntity qiuzhu = qiuzhuService.selectById(id);
if(qiuzhu !=null){
//点击数量加1
qiuzhu.setQiuzhuClicknum(qiuzhu.getQiuzhuClicknum()+1);
qiuzhuService.updateById(qiuzhu);
//entity转view
QiuzhuView view = new QiuzhuView();
BeanUtils.copyProperties( qiuzhu , view );//把实体数据重构到view中
//级联表
YonghuEntity yonghu = yonghuService.selectById(qiuzhu.getYonghuId());
if(yonghu != null){
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
view.setYonghuId(yonghu.getId());
}
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody QiuzhuEntity qiuzhu, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,qiuzhu:{}",this.getClass().getName(),qiuzhu.toString());
Wrapper<QiuzhuEntity> queryWrapper = new EntityWrapper<QiuzhuEntity>()
.eq("yonghu_id", qiuzhu.getYonghuId())
.eq("qiuzhu_name", qiuzhu.getQiuzhuName())
.eq("qiuzhu_types", qiuzhu.getQiuzhuTypes())
.eq("qiuzhu_wupin", qiuzhu.getQiuzhuWupin())
.eq("qiuzhu_num", qiuzhu.getQiuzhuNum())
.eq("qiuzhu_address", qiuzhu.getQiuzhuAddress())
.eq("qiuzhu_tihuo", qiuzhu.getQiuzhuTihuo())
.eq("qiuzhu_clicknum", qiuzhu.getQiuzhuClicknum())
.in("qiuzhu_yesno_types", new Integer[]{1,2})
.eq("qiuzhu_yesno_text", qiuzhu.getQiuzhuYesnoText())
.eq("qiuzhu_delete", qiuzhu.getQiuzhuDelete())
// .notIn("qiuzhu_types", new Integer[]{102})
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
QiuzhuEntity qiuzhuEntity = qiuzhuService.selectOne(queryWrapper);
if(qiuzhuEntity==null){
qiuzhu.setQiuzhuClicknum(1);
qiuzhu.setQiuzhuYesnoTypes(1);
qiuzhu.setQiuzhuDelete(1);
qiuzhu.setInsertTime(new Date());
qiuzhu.setCreateTime(new Date());
qiuzhuService.insert(qiuzhu);
return R.ok();
}else {
if(qiuzhuEntity.getQiuzhuYesnoTypes()==1)
return R.error(511,"有相同的待审核的数据");
else if(qiuzhuEntity.getQiuzhuYesnoTypes()==2)
return R.error(511,"有相同的审核通过的数据");
else
return R.error(511,"表中有相同数据");
}
}
}
package com.controller;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.UsersEntity;
import com.service.TokenService;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
/**
* 登录相关
*/
@RequestMapping("users")
@RestController
public class UsersController {
@Autowired
private UsersService usersService;
@Autowired
private TokenService tokenService;
/**
* 登录
*/
@IgnoreAuth
@PostMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
UsersEntity user = usersService.selectOne(new EntityWrapper<UsersEntity>().eq("username", username));
if(user==null || !user.getPassword().equals(password)) {
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
R r = R.ok();
r.put("token", token);
r.put("role",user.getRole());
r.put("userId",user.getId());
return r;
}
/**
* 注册
*/
@IgnoreAuth
@PostMapping(value = "/register")
public R register(@RequestBody UsersEntity user){
// ValidatorUtils.validateEntity(user);
if(usersService.selectOne(new EntityWrapper<UsersEntity>().eq("username", user.getUsername())) !=null) {
return R.error("用户已存在");
}
usersService.insert(user);
return R.ok();
}
/**
* 退出
*/
@GetMapping(value = "logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
/**
* 修改密码
*/
@GetMapping(value = "/updatePassword")
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
UsersEntity users = usersService.selectById((Integer)request.getSession().getAttribute("userId"));
if(newPassword == null){
return R.error("新密码不能为空") ;
}
if(!oldPassword.equals(users.getPassword())){
return R.error("原密码输入错误");
}
if(newPassword.equals(users.getPassword())){
return R.error("新密码不能和原密码一致") ;
}
users.setPassword(newPassword);
usersService.updateById(users);
return R.ok();
}
/**
* 密码重置
*/
@IgnoreAuth
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
UsersEntity user = usersService.selectOne(new EntityWrapper<UsersEntity>().eq("username", username));
if(user==null) {
return R.error("账号不存在");
}
user.setPassword("123456");
usersService.update(user,null);
return R.ok("密码已重置为:123456");
}
/**
* 列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,UsersEntity user){
EntityWrapper<UsersEntity> ew = new EntityWrapper<UsersEntity>();
PageUtils page = usersService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/list")
public R list( UsersEntity user){
EntityWrapper<UsersEntity> ew = new EntityWrapper<UsersEntity>();
ew.allEq(MPUtil.allEQMapPre( user, "user"));
return R.ok().put("data", usersService.selectListView(ew));
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id){
UsersEntity user = usersService.selectById(id);
return R.ok().put("data", user);
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Integer id = (Integer)request.getSession().getAttribute("userId");
UsersEntity user = usersService.selectById(id);
return R.ok().put("data", user);
}
/**
* 保存
*/
@PostMapping("/save")
public R save(@RequestBody UsersEntity user){
// ValidatorUtils.validateEntity(user);
if(usersService.selectOne(new EntityWrapper<UsersEntity>().eq("username", user.getUsername())) !=null) {
return R.error("用户已存在");
}
usersService.insert(user);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody UsersEntity user){
// ValidatorUtils.validateEntity(user);
usersService.updateById(user);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
List<UsersEntity> user = usersService.selectList(null);
if(user.size() > 1){
usersService.deleteBatchIds(Arrays.asList(ids));
}else{
return R.error("管理员最少保留一个");
}
return R.ok();
}
}