package com.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Article;
import com.entity.Bbs;
import com.entity.Cart;
import com.entity.Cate;
import com.entity.Complains;
import com.entity.Goods;
import com.entity.Orders;
import com.entity.Rebbs;
import com.entity.Seller;
import com.entity.Topic;
import com.entity.Users;
import com.service.ArticleService;
import com.service.BbsService;
import com.service.CartService;
import com.service.CateService;
import com.service.ComplainsService;
import com.service.GoodsService;
import com.service.OrdersService;
import com.service.RebbsService;
import com.service.SellerService;
import com.service.TopicService;
import com.service.UsersService;
import com.util.PageHelper;
import com.util.VeDate;
//定义为控制器
@Controller
// 设置路径
@RequestMapping("/index")
public class IndexController extends BaseController {
@Autowired
private UsersService usersService;
@Autowired
private SellerService sellerService;
@Autowired
private ArticleService articleService;
@Autowired
private CateService cateService;
@Autowired
private GoodsService goodsService;
@Autowired
private CartService cartService;
@Autowired
private OrdersService ordersService;
@Autowired
private TopicService topicService;
@Autowired
private ComplainsService complainsService;
@Autowired
private BbsService bbsService;
@Autowired
private RebbsService rebbsService;
// 公共方法 提供公共查询数据
private void front() {
this.getRequest().setAttribute("title", "学校食堂管理系统");
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Goods> hotList = this.goodsService.getGoodsByHot();
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Goods> goodsList = this.goodsService.getGoodsByCate(cate.getCateid());
cate.setGoodsList(goodsList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}
// 公告
@RequestMapping("article.action")
public String article(String number) {
this.front();
List<Article> tempList = this.articleService.getAllArticle();
PageHelper.getIndexPage(tempList, "article", "article", null, 10, number, this.getRequest());
return "users/article";
}
// 阅读公告
@RequestMapping("read.action")
public String read(String id) {
this.front();
Article article = this.articleService.getArticleById(id);
article.setHits("" + (Integer.parseInt(article.getHits()) + 1));
this.articleService.updateArticle(article);
this.getRequest().setAttribute("article", article);
return "users/read";
}
// 准备登录
@RequestMapping("preLogin.action")
public String prelogin() {
this.front();
return "users/login";
}
// 用户登录
@RequestMapping("login.action")
public String login() {
this.front();
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Users u = new Users();
u.setUsername(username);
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
this.getSession().setAttribute("message", "用户名不存在");
return "redirect:/index/preLogin.action";
} else {
Users users = usersList.get(0);
if ("锁定".equals(users.getStatus())) {
this.getSession().setAttribute("message", "账户被锁定");
return "redirect:/index/preLogin.action";
}
if (password.equals(users.getPassword())) {
this.getSession().setAttribute("userid", users.getUsersid());
this.getSession().setAttribute("username", users.getUsername());
this.getSession().setAttribute("users", users);
return "redirect:/index/index.action";
} else {
this.getSession().setAttribute("message", "密码错误");
return "redirect:/index/preLogin.action";
}
}
}
// 商家准备注册
@RequestMapping("preRegSeller.action")
public String preRegSeller() {
this.front();
return "users/sellerregister";
}
@RequestMapping("sellerregister.action")
public String sellerregister(Seller seller) {
this.front();
Seller u = new Seller();
u.setUsername(seller.getUsername());
List<Seller> usersList = this.sellerService.getSellerByCond(u);
if (usersList.size() == 0) {
seller.setStatus("锁定");
seller.setRegdate(VeDate.getStringDateShort());
this.sellerService.insertSeller(seller);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preRegSeller.action";
}
return "redirect:/seller/index.action";
}
// 准备注册
@RequestMapping("preReg.action")
public String preReg() {
this.front();
return "users/register";
}
// 用户注册
@RequestMapping("register.action")
public String register(Users users) {
this.front();
Users u = new Users();
u.setUsername(users.getUsername());
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
users.setStatus("锁定");
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preReg.action";
}
return "redirect:/index/preLogin.action";
}
// 退出登录
@RequestMapping("exit.action")
public String exit() {
this.front();
this.getSession().removeAttribute("userid");
this.getSession().removeAttribute("username");
this.getSession().removeAttribute("users");
return "redirect:/index/index.action";
}
// 准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Users users = this.usersService.getUsersById(userid);
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
return "redirect:/index/prePwd.action";
}
return "redirect:/index/prePwd.action";
}
@RequestMapping("usercenter.action")
public String usercenter() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/usercenter";
}
@RequestMapping("userinfo.action")
public String userinfo() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
this.getSession().setAttribute("users", this.usersService.getUsersById(userid));
return "users/userinfo";
}
@RequestMapping("personal.action")
public String personal(Users users) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.usersService.updateUsers(users);
return "redirect:/index/userinfo.action";
}
// 留言板
@RequestMapping("bbs.action")
public String bbs() {
this.front();
List<Bbs> bbsList = this.bbsService.getAllBbs();
this.getReques
土豆片片
- 粉丝: 1857
- 资源: 5869
最新资源
- Python_免费开源加密交易机器人.zip
- Python_免费是指《帝国时代2》引擎的自由开源克隆版.zip
- Python_面向科学家和工程师的深度学习和强化学习库.zip
- Python_免费在线教科书的Jupyter笔记本为快速计算线性代数课程.zip
- 移动机器人路径规划(人工势场法),本次路径规划的代码是基于matlab语言的,该方法的基本思想是机器人受到来自目的地的引力以及受到来自障碍物的斥力 这 些力形成合力后驱使机器人避开障碍物后移向目的地
- 机械设计堆垛机sw18可编辑全套设计资料100%好用.zip.zip
- 多编组列车仿真,车体加载fluent里导出的气动力进行仿真 利用脚本建立fluent里的导出的气动力数据和simpack力元的接口进行快速的数据更新
- 编译原理词法分析的实现
- 电压电流双闭环NPC三电平逆变器的仿真,采用载波层叠调制
- Wincc报表模板 1、数据库存储全局脚本 存储时间自由设置 2、报表查询VBS脚本,带下拉框,组合框,查询内容自由选择,时间自由选择 3、导出到本地EXECL 并打印 4、各类控件,语音报警
- 数据快速拷贝软件,拷贝速度为WINDOWS的2-7倍 具有不间断、挑选拷贝、快速删除、剪切等功能
- MATLAB基础应用精讲-【智能优化算法】黏菌算法(SMA)(附MATLAB和python代码实现)
- CS1.5★ALAN装逼脚本Ver.2025.03.弹道版【ALT开压枪】
- 有源电力滤波器APF MATLAB仿真 选阶补偿,matlab版本V2014,基于LCL滤波器的I型三电平拓扑仿真模型,三相四线制,软件锁相环,C语言编程提取谐波指令,直流电压和中点电位控制稳定
- 修复版早起打卡+完美细教程+修复支付接口问题已完美运营
- 光储一体机仿真模型,光伏与储能在直流侧耦合,采用boost电路加NPC电路,基于MATLAB Simulink建模仿真 闭环控制仿真模型,可以进行功率调度和充放电控制 仿真模型使用MATLAB 2
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈