源码获取:博客首页 "资源" 里下载!
垃圾分类查询管理系统。共分为两种角色,管理员、普通用户。
管理员角色具有功能:
系统设置-用户管理、页面管理、角色管理;
我的-首页、搜索记录、我的收益;
贡献管理-贡献管理、随机数据、每日垃圾、贡献记录;
垃圾管理-垃圾管理、分类管理、分类列表、垃圾列表、修改奖励;
数据分析-全国统计、分类统计、投放统计;
公告管理-公告管理、公告列表、必布公告;
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 8.0版本;
1. 后端:SpringBoot;
2. 前端:html+thymeleaf;
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中application.properties配置文件中的数据库配置改为自己的配置
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 运行项目,输入localhost:8083 登录
5. 管理员账户:admin 密码:123456
6. 普通用户账户:lcp 密码:123456
/**
* 用户管理控制器
*/
@RequestMapping("/admin/user")
@Component
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping("/list")
public String list(Model model, User user, PageBean pageBean){
model.addAttribute("usernmae",user.getUsername());
model.addAttribute("pageBean",userService.findList(user,pageBean));
model.addAttribute("title","用户列表");
return "admin/user/list";
}
/**
* 用户添加页面
* @param model
* @param
* @return
*/
@RequestMapping(value = "/add",method = RequestMethod.GET)
public String add(Model model){
List all = roleService.findAll();
model.addAttribute("roles",all);
return "admin/user/add";
}
@ResponseBody
@RequestMapping(value = "/add",method = RequestMethod.POST)
public Result add(Model model,User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断用户的角色是否选择
if(user.getRole()==null ||user.getRole().getId()==null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
//没有ID 传个0进去 0不是Long类型 所以加个0l L
if(userService.isExistUsername(user.getUsername(),0l)){
return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST);
}
//到这说明一切符合条件进行数据库新增
if(userService.save(user)==null){
return Result.error(CodeMsg.ADMIN_USER_ADD_ERROR);
}
operaterLogService.add("添加用户,用户名:"+user.getUsername());
return Result.success(true);
}
/**
* 用户编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit",method = RequestMethod.GET)
public String edit(Model model,@RequestParam(name = "id",required = true) Long id){
model.addAttribute("user",userService.find(id));
model.addAttribute("roles",roleService.findAll());
return "admin/user/edit";
}
/**
* 编辑用户信息表单提交处理
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit",method = RequestMethod.POST)
public Result edit(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断用户的角色是否选择
if(user.getRole()==null ||user.getRole().getId()==null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId()==null||user.getId().longValue()<=0){
return Result.error(CodeMsg.ADMIN_USER_NO_EXIST);
}
//判断数据库user表有没有这个用户名
if(userService.isExistUsername(user.getUsername(),user.getId().longValue())){
return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST);
}
//将提交的用户信息指定字段复制到已存在的user对象中
User findbyId = userService.find(user.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(user,findbyId,"id","createTime","updateTime");
//到这说明一切通过 开始进行数据库编辑
if(userService.save(findbyId)==null){
return Result.error(CodeMsg.ADMIN_USER_EDIT_ERROR);
}
operaterLogService.add("编辑用户,用户名:"+user.getUsername());
return Result.success(true);
}
@ResponseBody
@RequestMapping(value = "/delete",method = RequestMethod.POST)
public Result delete(@RequestParam(name = "id",required = true) Long id) {
try {
userService.delete(id);
} catch (Exception e){
return Result.error(CodeMsg.ADMIN_USER_DELETE_ERROR);
}
operaterLogService.add("删除用户,id为:"+id);
return Result.success(true);
}
}
@RequestMapping("/system")
@Controller
public class SystemController {
@Autowired
private SiteConfig siteConfig;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private UserService userService;
private Logger log= LoggerFactory.getLogger(SiteConfig.class);
@Autowired
private DatabaseBakService databaseBakService;
@Autowired
private SmsService smsService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private AssociationService associationService;
@Autowired
private ActivitiesService activitiesService;
@Autowired
private StyleService styleService;
@Autowired
private OrderAuthService orderAuthService;
@Autowired
private StudentService studentService;
/**
* 登录页面
* @param model
* @return
*/
@RequestMapping(value = "/login",method = RequestMethod.GET)
public String index(Model model){
model.addAttribute("siteName",siteConfig.getSiteName());
model.addAttribute("siteUrl",siteConfig.getSiteUrl());
return "admin/system/login";
}
//登录成功后主页
@RequestMapping(value = "/index")
public String indext(Model model){
model.addAttribute("operatorLogs",operaterLogService.findLastLog(10));
model.addAttribute("userTotal",userService.total());
model.addAttribute("logTotal",operaterLogService.total());
model.addAttribute("dataTotal",databaseBakService.total());
model.addAttribute("onlineUserTotal", HttpSessionS.onlineUserCount);
model.addAttribute("associationTotal",associationService.count(Association.TEAM_AUDIT_SUCCESS));
model.addAttribute("activitesTotal",activitiesService.count(Activities.ACTIVITIES_AUDIT_SUCCESS));
model.addAttribute("styleTotal",styleService.count(Style.STYLE_AUDIT_SUCCESS));
model.addAttribute("studentTotal",studentService.count());
return "admin/system/index";
}
@ResponseBody
@RequestMapping(value = "/login",method = RequestMethod.POST)
public Result login(HttpServletRequest request,User user, String cpacha){
Mapret=new HashMap();
if(user==null) {
return Result.error(CodeMsg.DATA_ERROR);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//表示实体信息合法,开始验证验证码是否为空、
if(StringUtils.isEmpty(cpacha)){
return Result.error(CodeMsg.CPACHA_EMPTY);
}
//说明验证码不为空,从session里获取验证码
Object attribute = request.getSession().getAttribute("admin_login");
if(attribute==null){
return Result.error(CodeMsg.SESSION_EXPIRED);
}
//表示session未失效,进一步判断用户填写的验证码是否正确
if(!cpacha.equalsIgnoreCase(attribute.toString())){
return Result.error(CodeMsg.CPACHA_ERROR);
}
//表示验证码正确,开始查询数据库,检验密码是否正确
User byUsername = userService.findByUsername(user.getUsername());
if(byUsername==null){
return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
}
//表示用户存在 进一步对比密码是否正确
if(!byUsername.getPassword().equals(user.getPassword())){
return Result.error(CodeMsg.ADMIN_PASSWORD_NO_ERROR);
}
//表示密码正确,将登录信息放入session中 并判断状态是否可用
if(byUsername.getStatus()!=byUsername.ADMIN_USER_STATUS_ENABLE){
return Result.error(CodeMsg.ADMIN_USER_STATUS_ERROR);
}
//检查用户是否有角色 状态是否被冻结
if(byUsername.getRole()==null||byUsername.getRole().getStatus()!= Role.ADMIN_ROLE_STATUS_ENABLE){
return Result.error(CodeMsg.ADMIN_USER_ROLE_STATUS_ERROR);
}
//检查用户有哪些权限
if(byUsername.getRole().getAuthorities()==null ||byUsername.getRole().getAuthorities().size()==0){
return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
}
//检查一切符合 可以登录
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY,byUsername);
//销毁session中的验证码
request.getSession().setAttribute("admin_login",null);
//将登录日志写入日志库
OperaterLog operaterLog=new OperaterLog();
operaterLog.setOperator(user.getUsername());
operaterLog.setContent("用户["+user.getUsername()+"]与["+ StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd HH:mm:ss")+"]登录系统");
operaterLogService.save(operaterLog);
log.info("用户成功登录,user="+byUsername);
return Result.success(true);
}
/**
* 注销登录
* @return
*/
@RequestMapping(value = "/logout")
public String logout(){
User loginedUser = SessionUtil.getLoginedUser();
if(loginedUser!=null){
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,"");
}
return "redirect:login";
}
/**
* 无权限提示页面
* @return
*/
@RequestMapping(value = "/no_right")
public String noRight(){
return "admin/system/no_right";
}
/**
* 修改用户个人信息
* @return
*/
@RequestMapping(value = "/update_userInfo",method = RequestMethod.GET)
public String updateUserInfo(){
return "admin/system/update_userinfo";
}
/**
* 修改信息保存
* @param user
* @return
*/
@RequestMapping(value = "/update_userInfo",method = RequestMethod.POST)
public String updateUserInfo(User user){
User loginedUser = SessionUtil.getLoginedUser();
loginedUser.setHeadPic(user.getHeadPic());
loginedUser.setEmail(user.getEmail());
loginedUser.setMobile(user.getMobile());
//首先保存到数据库
userService.save(loginedUser);
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);
return "redirect:update_userInfo";
}
@RequestMapping(value = "/update_pwd",method = RequestMethod.GET)
public String updatePwd(){
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
* @param oldPwd
* @param newPwd
* @return
*/
@ResponseBody
@RequestMapping(value = "/update_pwd",method = RequestMethod.POST)
public Result updatePwd(@RequestParam(name = "oldPwd",required = true) String oldPwd,
@RequestParam(name = "newPwd",required = true)String newPwd){
User loginedUser = SessionUtil.getLoginedUser();
if(!loginedUser.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_PASSWORD_OLD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_PASSWORD_NEW_ERROR);
}
//设置新密码
loginedUser.setPassword(newPwd);
//更新数据库
userService.save(loginedUser);
//更新session
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);
return Result.success(true);
}
/**
* 日志管理页面
* @param model
* @param operaterLog
* @param pageBean
* @return
*/
@RequestMapping(value = "/operator_log_list")
public String operatorLogList(Model model,OperaterLog operaterLog, PageBean pageBean){
model.addAttribute("pageBean",operaterLogService.findList(operaterLog,pageBean));
model.addAttribute("operator",operaterLog.getOperator());
model.addAttribute("title","日志列表");
return "admin/system/operator_log_list";
}
/**
* 删除操作日志,可删除多个
* @param ids
* @return
*/
@RequestMapping(value = "/delete_operator_log",method = RequestMethod.POST)
@ResponseBody
public Result delete(String ids){
if(!StringUtils.isEmpty(ids)){
String[] splitIds = ids.split(",");
for(String id:splitIds){
operaterLogService.delete(Long.valueOf(id));
}
}
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value ="/delete_all_log",method = RequestMethod.POST)
@ResponseBody
public Result deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
@ResponseBody
@RequestMapping(value = "/send",method = RequestMethod.POST)
public Result code(@RequestParam(name ="phoneName")String phone){
//调用方法
String code = redisTemplate.opsForValue().get(phone);
if(!StringUtils.isEmpty(code)){
return Result.error(CodeMsg.ADMIN_PHONE_SMS_EXIST);
}
//生成验证码并存储到redis中
code = UUID.randomUUID().toString().substring(0, 4);
HashMap param = new HashMap<>();
param.put("code",code);
boolean isSend = smsService.send(phone, "", param);
if(isSend){
redisTemplate.opsForValue().set(phone,code,5, TimeUnit.SECONDS);
return Result.success(true);
}else {
return Result.error(CodeMsg.ADMIN_PHONE_SMS_ERROR);
}
}
}
源码获取:博客首页 "资源" 里下载!