源码获取:俺的博客首页 "资源" 里下载!
项目介绍
该项目主要分为管理员与普通员工两种角色;
管理员角色包含以下功能:
管理员登录,进货管理,图书信息管理,库存管理,销售管理,客户信息管理,供应商信息管理,员工信息管理等功能。
普通员工角色包含以下功能:
用户登录,进货管理,图书信息管理,库存管理,销售管理,客户信息管理,供应商管理,修改个人资料等功能。
环境需要
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.数据库:MySql 5.7版本;
6.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+bootstrap+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties与spring-mybatis.xml配置文件中的数据库配置改为自己的配置;
注:在spring-mybatis.xml没有将db.properties的数据同步过去的情况下修改;
4. 运行项目,输入localhost:8080/chaoshi 登录 注:tomcat中配置项目路径必须为/chaoshi,前端代码中已写死,否则会报错;
操作员账号/密码: 001/123456
管理员账号/密码:999/admin
用户管理控制层:
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 登录
*
* @param username 用户名
* @param password 密码
* @param request
* @return
*/
@SysLog("登陆操作")
@PostMapping("/login")
public Result login(String username, String password, HttpServletRequest request) {
try {
//获取当前登录主体对象
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
subject.login(token);
LoginUserVO userDTO = (LoginUserVO) subject.getPrincipal();
request.getSession().setAttribute("username", userDTO.getUser());
return Result.success(true, "200", "登录成功");
} catch (UnknownAccountException e) {
e.printStackTrace();
return Result.error(false, "400", "登录失败,用户名不存在");
}catch (IncorrectCredentialsException e) {
e.printStackTrace();
return Result.error(false, "400", "登录失败,密码错误");
}catch (AuthenticationException e) {
e.printStackTrace();
return Result.error(false, "400", "登录失败,账户禁用");
}
}
/**
* 得到登陆验证码
* @param response
* @param session
* @throws IOException
*/
@RequestMapping("/getCode")
public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
//定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36,4,5);
session.setAttribute("code",lineCaptcha.getCode());
try {
ServletOutputStream outputStream = response.getOutputStream();
lineCaptcha.write(outputStream);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 查询所有用户信息
*
* @param userVO
* @return
*/
@SysLog("用户查询操作")
@RequestMapping("/userList")
public DataGridViewResult userList(UserVO userVO) {
//分页构造函数
IPage<User> page = new Page<>(userVO.getPage(), userVO.getLimit());
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.like(!StringUtils.isEmpty(userVO.getUsername()), "username", userVO.getUsername());
queryWrapper.like(!StringUtils.isEmpty(userVO.getUname()), "uname", userVO.getUname());
/**
* 翻页查询
* @param page 翻页对象
* @param queryWrapper 实体对象封装操作类
*/
IPage<User> userIPage = userService.page(page, queryWrapper);
return new DataGridViewResult(userIPage.getTotal(), userIPage.getRecords());
}
/**
* 添加用户信息
*
* @param user
* @return
*/
@SysLog("用户添加操作")
@PostMapping("/adduser")
public Result addRole(User user) {
user.setUcreatetime(new Date());
String salt = UUIDUtil.randomUUID();
user.setPassword(PasswordUtil.md5("000000", salt, 2));
user.setSalt(salt);
user.setType(1);
boolean bool = userService.save(user);
try {
if (bool) {
return Result.success(true, "200", "添加成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "添加失败!");
}
/**
* 校验用户名是否存在
*
* @param username
* @return
*/
@RequestMapping("/checkUserName")
public String checkUserName(String username) {
Map<String, Object> map = new HashMap<>();
try {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username", username);
User user = userService.getOne(queryWrapper);
if (user != null) {
map.put("exist", true);
map.put("message", "用户名已存在");
} else {
map.put("exist", false);
map.put("message", "用户名可以使用");
}
} catch (Exception e) {
e.printStackTrace();
}
return JSON.toJSONString(map);
}
/**
* 修改用户信息
*
* @param user
* @return
*/
@SysLog("用户修改操作")
@PostMapping("/updateuser")
public Result updateUser(User user) {
boolean bool = userService.updateById(user);
try {
if (bool) {
return Result.success(true, "200", "修改成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "修改失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("用户删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {
boolean bool = userService.removeById(id);
try {
if (bool) {
return Result.success(true, "200", "删除成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "删除失败!");
}
/**
* 重置密码
*
* @param id
* @return
*/
@SysLog("用户修改操作")
@PostMapping("/resetPwd")
public Result resetPwd(int id) {
User user = new User();
String salt = UUIDUtil.randomUUID();
user.setUid(id);
user.setPassword(PasswordUtil.md5("000000", salt, 2));
user.setSalt(salt);
boolean bool = userService.updateById(user);
try {
if (bool) {
return Result.success(true, "200", "重置成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "重置失败!");
}
/**
* 根据id查询当前用户拥有的角色
*
* @param id
* @return
*/
@RequestMapping("/initRoleByUserId")
public DataGridViewResult initRoleByUserId(int id) {
List<Map<String, Object>> mapList = null;
try {
//查询所有角色列表
mapList = roleService.listMaps();
//根据用户id查询用户拥有的角色
Set<Integer> roleIdList = userService.findRoleByUserId(id);
for (Map<String, Object> map : mapList) {
//定义标记 默认不选中
boolean flag = false;
int roleId = (int) map.get("roleid");
for (Integer rid : roleIdList) {
if (rid == roleId) {
flag = true;
break;
}
}
map.put("LAY_CHECKED", flag);
}
} catch (Exception e) {
e.printStackTrace();
}
return new DataGridViewResult(Long.valueOf(mapList.size()), mapList);
}
/**
* 为用户分配角色
*
* @param roleids
* @param userid
* @return
*/
@SysLog("用户添加操作")
@RequestMapping("/saveUserRole")
public Result saveUserRole(String roleids, int userid) {
try {
if (userService.saveUserRole(userid, roleids)) {
return Result.success(true, null, "分配成功");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "分配失败");
}
/**
* 修改密码
*
* @param newPassWord1
* @param newPassWord2
* @return
*/
@RequestMapping("/updateUserPassWord")
public Result updateUserPassWord(String newPassWord1, String newPassWord2,HttpSession session) {
User sessionUser = (User) session.getAttribute("username");
if (newPassWord1.equals(newPassWord2)){
User user = new User();
String salt = UUIDUtil.randomUUID();
user.setUid(sessionUser.getUid());
user.setPassword(PasswordUtil.md5(newPassWord1, salt, 2));
user.setSalt(salt);
boolean bool = userService.updateById(user);
if (bool){
return Result.success(true,null,"修改成功");
}else {
return Result.error(false,null,"修改失败!");
}
}else {
return Result.error(false,null,"修改失败,两次密码不一致!");
}
}
}
角色管理控制层:
@RestController
@RequestMapping("/role")
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private PermissionService permissionService;
/**
* 查询所有角色信息
* @param roleVO
* @return
*/
@SysLog("角色查询操作")
@RequestMapping("/roleList")
public DataGridViewResult roleList(RoleVO roleVO) {
//分页构造函数
IPage<Role> page = new Page<>(roleVO.getPage(), roleVO.getLimit());
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
queryWrapper.like(!StringUtils.isEmpty(roleVO.getRolename()), "rolename", roleVO.getRolename());
/**
* 翻页查询
*
* @param page 翻页对象
* @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
*/
IPage<Role> roleIPage = roleService.page(page, queryWrapper);
return new DataGridViewResult(roleIPage.getTotal(), roleIPage.getRecords());
}
/**
* 添加角色信息
*
* @param role
* @return
*/
@SysLog("角色添加操作")
@PostMapping("/addrole")
public Result addRole(Role role) {
boolean bool = roleService.save(role);
try {
if (bool) {
return Result.success(true, "200", "添加成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "添加失败!");
}
/**
* 修改角色信息
*
* @param role
* @return
*/
@SysLog("角色修改操作")
@PostMapping("/updaterole")
public Result updateRole(Role role) {
boolean bool = roleService.updateById(role);
try {
if (bool) {
return Result.success(true, "200", "修改成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "修改失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("角色删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {
boolean bool = roleService.removeById(id);
try {
if (bool) {
return Result.success(true, "200", "删除成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "删除失败!");
}
/**
* 初始化权限菜单树
*
* @param roleId
* @return
*/
@RequestMapping("/initPermissionByRoleId")
public DataGridViewResult initPermissionByRoleId(int roleId) {
//创建条件构造器对象
QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
List<Permission> permissionList = permissionService.list();
List<Integer> currentPermissionIds = permissionService.findRolePermissionIdByRoleId(roleId);
//保存角色拥有的菜单
List<Permission> currentPermissions = new ArrayList<>();
if (currentPermissionIds != null && currentPermissionIds.size() > 0) {
queryWrapper.in("id", currentPermissionIds);
currentPermissions = permissionService.list(queryWrapper);
}
List<TreeNode> treeNodes = new ArrayList<>();
for (Permission p1 : permissionList) {
//定义变量标记是否选中
String checkArr = "0";
for (Permission p2 : currentPermissions) {
if (p1.getId().equals(p2.getId())) {
checkArr = "1";
break;
}
}
Boolean spread = p1.getSpread() == 1 ? true : false;
treeNodes.add(new TreeNode(p1.getId(), p1.getPid(), p1.getTitle(), spread, checkArr));
}
return new DataGridViewResult(treeNodes);
}
/**
* 保存分配权限关系方法
*
* @param roleid
* @param ids
* @return
*/
@SysLog("角色添加操作")
@RequestMapping("/saveRolePermission")
public Result saveRolePermission(int roleid, String ids) {
try {
if (roleService.saveRolePermission(roleid, ids)) {
return Result.success(true, null, "分配成功");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error(false, null, "分配失败");
}
}
进货管理控制层:
@RestController
@RequestMapping("/inport")
public class InportController {
@Autowired
private InportService inportService;
@Autowired
private GoodsService goodsService;
@Autowired
private ProviderService providerService;
/**
* 进货查询
*
* @param
* @return
*/
@SysLog("进货查询操作")
@RequestMapping("/inportList")
public DataGridViewResult inportList(InportVO inportVO) {
//创建分页信息 参数1 当前页 参数2 每页显示条数
IPage<Inport> page = new Page<>(inportVO.getPage(), inportVO.getLimit());
QueryWrapper<Inport> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(inportVO.getProviderid() != null && inportVO.getProviderid() != 0, "providerid", inportVO.getProviderid());
queryWrapper.eq(inportVO.getGoodsid() != null && inportVO.getGoodsid() != 0, "goodsid", inportVO.getGoodsid());
queryWrapper.ge(inportVO.getStartTime() != null, "inptime", inportVO.getStartTime());
queryWrapper.le(inportVO.getEndTime() != null, "inptime", inportVO.getEndTime());
queryWrapper.orderByDesc("inptime");
IPage<Inport> inportIPage = inportService.page(page, queryWrapper);
List<Inport> records = inportIPage.getRecords();
for (Inport inport : records) {
inport.setAllinpprice(inport.getInpprice()*inport.getNumber());
Provider provider = providerService.getById(inport.getProviderid());
if (null != provider) {
inport.setProvidername(provider.getProvidername());
}
Goods goods = goodsService.getById(inport.getGoodsid());
if (null != goods) {
inport.setGoodsname(goods.getGname());
}
}
return new DataGridViewResult(inportIPage.getTotal(), records);
}
/**
* 添加进货信息
*
* @param inport
* @return
*/
@SysLog("进货添加操作")
@PostMapping("/addinport")
public Result addInport(Inport inport, HttpSession session) {
if (inport.getGoodsid()==0||inport.getProviderid()==0){
return Result.error(false, null, "添加失败!未选供应商或商品");
}
User user = (User) session.getAttribute("username");
inport.setOperateperson(user.getUname());
inport.setInptime(new Date());
boolean bool = inportService.save(inport);
if (bool) {
return Result.success(true, "200", "添加成功!");
}
return Result.error(false, null, "添加失败!");
}
/**
* 删除单条数据
*
* @param id
* @return
*/
@SysLog("进货删除操作")
@RequestMapping("/deleteOne")
public Result deleteOne(int id) {
boolean bool = inportService.removeById(id);
if (bool) {
return Result.success(true, "200", "删除成功!");
}
return Result.error(false, null, "删除失败!");
}
/**
* 修改进货信息
*
* @param inport
* @return
*/
@SysLog("进货修改操作")
@PostMapping("/updateinport")
public Result updateGoods(Inport inport, HttpSession session) {
User user = (User) session.getAttribute("username");
inport.setOperateperson(user.getUname());
inport.setInptime(new Date());
boolean bool = inportService.updateById(inport);
if (bool) {
return Result.success(true, "200", "修改成功!");
}
return Result.error(false, null, "修改失败!");
}
}
源码获取:俺的博客首页 "资源" 里下载!