package com.supermaket.manager.web;
import com.supermaket.manager.entity.Admin;
import com.supermaket.manager.entity.Menu;
import com.supermaket.manager.entity.Role;
import com.supermaket.manager.service.AdminService;
import com.supermaket.manager.util.EncryptUtil;
import com.supermaket.manager.util.GsonUtil;
import com.supermaket.manager.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.List;
@Controller
@RequestMapping("/admin")
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping("/login")
@ResponseBody
public ResultUtil login(String username, String password, HttpServletRequest request, HttpSession session)
throws ParseException {
Admin admin = adminService.login(username, EncryptUtil.encrypt(password));
if (admin != null) {
session.setAttribute("user", admin); //在拦截器中使用
session.setAttribute("admin", admin); //在main.jsp中药取出admin
return ResultUtil.ok(admin.getAdmin_id());
} else
return ResultUtil.error();
}
@RequestMapping("/getMenus")
@ResponseBody
public List<Menu> getMenus(HttpSession session) {
//System.out.println("getmenus进来了");
List<Menu> menus = null;
Admin admin = (Admin) session.getAttribute("admin");
Admin admin1 = adminService.getAdminById(admin.getAdmin_id());
if (admin1 != null) {
menus = adminService.getMenus(admin1); //getMenus函数里只是取出来 并没有实现排序
}
return menus;
}
/********页面跳转*******/
@RequestMapping("/logOut")
public ModelAndView loginout(ModelAndView modelAndView, HttpSession session)
throws ParseException {
session.invalidate();
modelAndView.setViewName("redirect:/index.jsp");
return modelAndView;
}
/*******管理员相关******/
//查看管理员的个人信息
@RequestMapping("/personalDate")
public String personalDate(HttpSession session) {
Admin admin = (Admin) session.getAttribute("admin");
Admin admin1 = adminService.getAdminById(admin.getAdmin_id());
session.setAttribute("admin1", admin1);
return "/jsp/admin/personalInfo";
}
//更新管理员
@RequestMapping("/updateAdmin")
@ResponseBody
public ResultUtil updateAdmin(Admin admin) {
try {
adminService.updAdmin(admin);
return ResultUtil.ok();
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error();
}
}
//更新管理员
@RequestMapping("/updAdmin")
@ResponseBody
public ResultUtil updAdmin(Admin admin)//这里 前端发送过来的 自动赋值给admin中的同名字段 和之前的一样
{
// System.out.println("updAdmin命令进来了");
if (admin != null && admin.getAdmin_id() == 1) {
return ResultUtil.error("不允许修改");
}
try {
adminService.updAdmin(admin);
return ResultUtil.ok();
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error();
}
}
//修改密码
@RequestMapping("/changeAdminPassword")
@ResponseBody
public ResultUtil changeAdminPassword(String oldPassword, String newPassword1, String username) {
//System.out.println("猜猜"+username);
Admin admin = adminService.getAdminByUsername(username);
if (admin != null) {
if (admin.getPassword().equals(EncryptUtil.encrypt(oldPassword))) {
admin.setPassword(EncryptUtil.encrypt(newPassword1));
adminService.updAdmin(admin);
return ResultUtil.ok();
} else {
return ResultUtil.error("旧密码错误,请重新填写");
}
}
return ResultUtil.error("请求出错!!");
}
@RequestMapping("/getAdminList")
@ResponseBody
//获取所有管理员列表 带分页
public ResultUtil getAdminList(Integer page, Integer limit) {
// Tomcat Localhost Log 会输出错误信息 如果下面的sql语句有问题
ResultUtil admins = adminService.getAdminList(page, limit);
//System.out.println(".."+page+"..."+limit);
return admins;
}
//检查是否已经存在此用户名
@RequestMapping("/checkAdminName/{username}")
@ResponseBody
public ResultUtil checkAdminName(@PathVariable("username") String username) {
Admin admin = adminService.getAdminByUsername(username);
if (admin != null) {
return new ResultUtil(500, "管理员已存在!");
}
return new ResultUtil(0);
}
//添加新管理员
@RequestMapping("/insAdmin")
@ResponseBody
public ResultUtil insAdmin(Admin admin) {
adminService.insAdmin(admin);
return ResultUtil.ok();
}
//编辑管理员
@RequestMapping("/editAdmin/{admin_id}")
public String editAdmin(HttpServletRequest request, @PathVariable("admin_id") int admin_id) {
Admin admin = adminService.getAdminById(admin_id);
List<Role> roles = adminService.getRoles();
request.setAttribute("admin", admin);
request.setAttribute("roles", roles);
return "/jsp/admin/editAdmin";
}
//删除一个管理员
@RequestMapping("/delAdminById/{admin_id}")
@ResponseBody
public ResultUtil delAdminById(@PathVariable("admin_id") Long admin_id) {
if (admin_id == 1) {
return ResultUtil.error();
}
try {
adminService.delAdminById(admin_id);
return ResultUtil.ok();
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error();
}
}
/********Role相关*******/
//获取角色列表 带分页
@RequestMapping("/getRoleList")
@ResponseBody
public ResultUtil getRoleList(Integer page, Integer limit) {
return adminService.getRoles(page, limit);
}
//删除一个角色
@RequestMapping("/delRole/{roleId}")
@ResponseBody
public ResultUtil delRole(@PathVariable("roleId") Long roleId) {
adminService.delRole(roleId);
return ResultUtil.ok();
}
@RequestMapping(value = "/xtreedata", produces = {"text/json;charset=UTF-8"})
@ResponseBody
public String xtreeData(@RequestParam(value = "roleId", defaultValue = "-1") Long roleId) {
//不用admin做中介一样可以
return GsonUtil.entityToJson(adminService.getXtreeData(roleId));
}
// 检查角色是否唯一 编辑角色的视乎用这个函数
@RequestMapping("/checkRoleName/{roleName}/{roleId}")
@ResponseBody
public ResultUtil checkRoleName(@PathVariable("roleName") String roleName,
@PathVariable("roleId") Long roleId) {
//System.out.println(roleName);
//System.out.println("曹操:"+roleId);
Role role = adminService.getRoleByRoleName(roleName);
if (role == null)//没有这个角色名 可以
{
return n
没有合适的资源?快使用搜索试试~ 我知道了~
基于ssm超市管理系统适合毕业设计
共2000个文件
gif:312个
js:284个
pak:232个
需积分: 0 0 下载量 182 浏览量
2022-11-26
21:31:27
上传
评论 1
收藏 373.98MB RAR 举报
温馨提示
系统设置:资料管理、权限管理、安全管理 用户管理 商品管理:商品列表、商品配送、商品类别 库存管理:进入库登记、库存信息 退换管理:添加退换信息、退换记录 门店管理:添加门店、门店信息 供应商管理:登记合作信息、供应商信息管理、解约申请、解决记录
资源推荐
资源详情
资源评论
收起资源包目录
基于ssm超市管理系统适合毕业设计 (2000个子文件)
entities.dat.values.at 18KB
v8_context_snapshot.bin 161KB
v8_context_snapshot.bin 161KB
v8_context_snapshot.bin 161KB
v8_context_snapshot.bin 161KB
snapshot_blob.bin 47KB
snapshot_blob.bin 47KB
snapshot_blob.bin 47KB
snapshot_blob.bin 47KB
AdminController.class 10KB
AdminController.class 10KB
WareController.class 9KB
WareController.class 9KB
AdminServiceImpl.class 8KB
AdminServiceImpl.class 8KB
StoreController.class 6KB
StoreController.class 6KB
Menu.class 4KB
Menu.class 4KB
TypeController.class 3KB
TypeController.class 3KB
Ware.class 3KB
Ware.class 3KB
PurchaseController.class 3KB
PurchaseController.class 3KB
AuthorizedInterceptor.class 3KB
AuthorizedInterceptor.class 3KB
Admin.class 3KB
Admin.class 3KB
SupplyController.class 3KB
SupplyController.class 3KB
WareServiceImpl.class 3KB
WareServiceImpl.class 3KB
Purchase.class 3KB
Purchase.class 3KB
TypeServiceImpl.class 3KB
TypeServiceImpl.class 3KB
OutController.class 3KB
OutController.class 3KB
ResController.class 3KB
ResController.class 3KB
ShopController.class 3KB
ShopController.class 3KB
ShopServiceImpl.class 3KB
ShopServiceImpl.class 3KB
PuechaseServiceImpl.class 3KB
PuechaseServiceImpl.class 3KB
SupplyServiceImpl.class 3KB
SupplyServiceImpl.class 3KB
StoreServiceImpl.class 3KB
StoreServiceImpl.class 3KB
OutServiceImpl.class 3KB
OutServiceImpl.class 3KB
ResServiceImpl.class 3KB
ResServiceImpl.class 3KB
DateUtil.class 2KB
DateUtil.class 2KB
Store.class 2KB
Store.class 2KB
ResultUtil.class 2KB
ResultUtil.class 2KB
Shop.class 2KB
Res.class 2KB
Shop.class 2KB
Res.class 2KB
Out.class 2KB
Out.class 2KB
Supply.class 2KB
Supply.class 2KB
Role.class 2KB
Role.class 2KB
PurchaseSearch.class 2KB
PurchaseSearch.class 2KB
Type.class 2KB
Type.class 2KB
WareSearch.class 2KB
SupplySearch.class 2KB
WareSearch.class 2KB
SupplySearch.class 2KB
OutSearch.class 2KB
ResSearch.class 2KB
OutSearch.class 2KB
ResSearch.class 2KB
EncryptUtil.class 1KB
EncryptUtil.class 1KB
RoleMenu.class 1KB
RoleMenu.class 1KB
AdminService.class 1KB
AdminService.class 1KB
StoreSearch.class 1KB
StoreSearch.class 1KB
AdminServiceImpl$1.class 1KB
AdminServiceImpl$1.class 1KB
GsonUtil.class 1016B
GsonUtil.class 1016B
AdminDao.class 896B
AdminDao.class 896B
WareDao.class 852B
WareDao.class 852B
TypeService.class 725B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
洛洛不觉
- 粉丝: 316
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功