基于JSP+Mybatis实现的CRM客户关系管理系统
Posted 编程指南针
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于JSP+Mybatis实现的CRM客户关系管理系统相关的知识,希望对你有一定的参考价值。
项目编号:BS-XX-111
该项目主要基于JAVAWEB技术,开发了一套CRM客户关系管理系统,实现了用户登录,权限控制,数据统计,以及市场活动、线索、客户、联系人、合同的CRUD,使用Proxy实现Service层的动态代理,实现DAO层事务控制。
运行环境
jdk8+tomcat8+mysql5.7+IntelliJ IDEA
项目技术(必填)
java servlet+mybatis+layui+jquery+echarts
下面展示一下具体的功能界面:
系统主页面
市场活动管理:查询的相关数据可以导出到EXCEL表里
销售线索管理
客户管理
联系人管理
交易管理
个人信息管理
系统设置—用户管理
系统设置—角色管理
系统设置—权限管理
部分核心代码:
package com.crsbg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import com.crsbg.entity.PageVO;
import com.crsbg.entity.User;
import com.crsbg.service.UserService;
import com.crsbg.service.impl.UserServiceImpl;
import com.crsbg.utils.JSONUtil;
import com.crsbg.utils.ServiceFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*用户管理控制器
*/
public class UserController extends HttpServlet
private UserService userService = null;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String path = request.getServletPath();
if("/controller/login".equals(path))
login(request,response);
else if("/controller/getUsers".equals(path))
getUsers(request,response);
else if("/controller/updateUser".equals(path))
updateUser(request,response);
else if("/controller/changePwd".equals(path))
changePwd(request,response);
else if("/controller/addUser".equals(path))
addUser(request,response);
else if("/controller/getUserList".equals(path))
getUserList(request,response);
else if("/controller/deleteUsers".equals(path))
deleteUsers(request,response);
else if("/controller/getUserById".equals(path))
getUserById(request,response);
else if("/controller/updateUser2".equals(path))
updateUser2(request,response);
else if("/controller/resetPwd".equals(path))
resetPwd(request,response);
else if("/controller/welcome".equals(path))
getDatas(request,response);
private void getDatas(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
System.out.println("进入首页获取数据getDatas...");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
Map<String,Object> map = userService.getDatas();
request.setAttribute("activities",map.get("activities"));
request.setAttribute("clues",map.get("clues"));
request.setAttribute("trans",map.get("trans"));
request.setAttribute("owners",map.get("owners"));
request.setAttribute("volumes",map.get("volumes"));
request.getRequestDispatcher("/pages/welcome.jsp").forward(request,response);
private void resetPwd(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入重置密码resetPwd...");
String id = request.getParameter("id");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
boolean flag = userService.resetPwd(id);
response.getWriter().print(flag);
private void updateUser2(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入修改用户详情updateUser2...");
String id = request.getParameter("id");
String name = request.getParameter("name");
String username = request.getParameter("username");
String isEnable =request.getParameter("isEnable");
String isAdmin =request.getParameter("isAdmin");
String[] roleIds = request.getParameterValues("roleIds");
String email =request.getParameter("email");
String remark =request.getParameter("remark");
User user = new User();
user.setId(id);
user.setName(name);
user.setUsername(username);
user.setIsEnable(isEnable);
user.setIsAdmin(isAdmin);
user.setEmail(email);
user.setRemark(remark);
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
Map<String,Object> map = userService.updateUser2(user,roleIds);
JSONUtil.getJSON(response,map);
private void getUserById(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入查询用户详情getUserById...");
String id = request.getParameter("id");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
User user = userService.getUserById(id);
JSONUtil.getJSON(response,user);
private void deleteUsers(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入批量删除用户deleteUsers...");
String[] ids = request.getParameterValues("id");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
boolean flag = userService.deleteUsers(ids);
response.getWriter().print(flag);
private void getUserList(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入获取用户列表getUserList...");
String name = request.getParameter("name");
int page = Integer.parseInt(request.getParameter("page"));
int limit = Integer.parseInt(request.getParameter("limit"));
int pageNumber = (page-1)*limit;
int pageSize = limit;
Map<String,Object> param = new HashMap<>();
param.put("name",name);
param.put("pageNumber",pageNumber);
param.put("pageSize",pageSize);
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
PageVO<User> vo = userService.getUserList(param);
Map<String,Object> map = new HashMap<>();
map.put("code",0);
map.put("message","请求成功");
map.put("count",vo.getTotal());
map.put("data",vo.getDatas());
JSONUtil.getJSON(response,map);
private void addUser(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入添加用户addUser...");
String name = request.getParameter("name");
String username = request.getParameter("username");
String isEnable =request.getParameter("isEnable");
String isAdmin =request.getParameter("isAdmin");
String[] roleIds = request.getParameterValues("roleIds");
String email =request.getParameter("email");
String remark =request.getParameter("remark");
User user = new User();
user.setId(IdUtil.simpleUUID());
user.setName(name);
user.setUsername(username);
user.setPassword(SecureUtil.md5("123")); //123
user.setIsEnable(isEnable);
user.setIsAdmin(isAdmin);
user.setEmail(email);
user.setRemark(remark);
user.setRegistTime(DateUtil.now());
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
Map<String,Object> map = userService.addUser(user,roleIds);
JSONUtil.getJSON(response,map);
private void changePwd(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入重置密码changePwd...");
String oldPwd = SecureUtil.md5(request.getParameter("oldPwd"));
String password = SecureUtil.md5(request.getParameter("password"));
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
Map<String,Object> map = new HashMap<>();
if(!user.getPassword().equals(oldPwd))
map.put("success",false);
map.put("msg","修改失败,旧密码错误");
JSONUtil.getJSON(response,map);
//response.getWriter().print("\\"success\\":false,\\"msg\\":\\"重置失败,旧密码错误\\"");
else
user.setPassword(password);
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
boolean flag = userService.changePwd(user);
if(flag)
session.setAttribute("user",user);
map.put("success",true);
map.put("msg","修改成功");
JSONUtil.getJSON(response,map);
//response.getWriter().print("\\"success\\":true,\\"msg\\":\\"重置成功\\"");
else
map.put("success",false);
map.put("msg","修改失败");
JSONUtil.getJSON(response,map);
//response.getWriter().print("\\"success\\":false,\\"msg\\":\\"重置失败\\"");
private void updateUser(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入修改个人信息adminInfo...");
String name = request.getParameter("name");
String email = request.getParameter("email");
String remark = request.getParameter("remark");
User user = (User) request.getSession().getAttribute("user");
user.setName(name);
user.setEmail(email);
user.setRemark(remark);
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
boolean flag = userService.updateUser(user);
if(flag)
request.getSession().setAttribute("user",user);
response.getWriter().print(flag);
private void getUsers(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入getUsers方法");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
List<User> userList = userService.getUsers();
JSONUtil.getJSON(response,userList);
private void login(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入login方法");
userService = (UserService) ServiceFactory.getService(new UserServiceImpl());
String username = request.getParameter("username");
String password = SecureUtil.md5(request.getParameter("password"));
Map<String,Object> map = new HashMap<>();
try
User user = userService.login(username,password);
request.getSession().setAttribute("user",user);
map.put("success",true);
JSONUtil.getJSON(response,map);
catch (Exception e)
String msg = e.getMessage();
map.put("success",false);
map.put("msg",msg);
JSONUtil.getJSON(response,map);
package com.crsbg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.crsbg.entity.PageVO;
import com.crsbg.entity.Permission;
import com.crsbg.entity.Role;
import com.crsbg.service.PermissionService;
import com.crsbg.service.RoleService;
import com.crsbg.service.impl.PermissionServiceImpl;
import com.crsbg.service.impl.RoleServiceImpl;
import com.crsbg.utils.JSONUtil;
import com.crsbg.utils.ServiceFactory;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 角色管理控制器
*/
public class RoleController extends HttpServlet
private RoleService roleService = null;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String path = request.getServletPath();
if("/controller/getRoleList".equals(path))
getRoleList(request,response);
else if("/controller/addRole".equals(path))
addRole(request,response);
else if("/controller/deleteRoles".equals(path))
deleteRoles(request,response);
else if("/controller/getPermissionIds".equals(path))
getPermissionIds(request,response);
else if("/controller/updateRole".equals(path))
updateRole(request,response);
private void updateRole(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入修改角色信息updateRole...");
String id = request.getParameter("id");
String name = request.getParameter("name");
String orderNo = request.getParameter("orderNo");
String[] permissionIds = request.getParameterValues("permissionIds");
Role role = new Role();
role.setId(id);
role.setName(name);
role.setOrderNo(orderNo);
roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
Map<String,Object> map = roleService.updateRole(role,permissionIds);
JSONUtil.getJSON(response,map);
private void getPermissionIds(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入查询当前角色权限getPermissionIds...");
String roleId = request.getParameter("roleId");
roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
List<String> permissionIds = roleService.getPermissionIds(roleId);
Map<String,List<String>> map = new HashMap<>();
map.put("pids",permissionIds);
JSONUtil.getJSON(response,map);
private void deleteRoles(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入批量删除角色deleteRoles...");
String[] ids = request.getParameterValues("id");
roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
boolean flag = roleService.deleteRoles(ids);
response.getWriter().print(flag);
private void addRole(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入添加角色addRole...");
String name = request.getParameter("name");
String orderNo = request.getParameter("orderNo");
String[] permissionIds = request.getParameterValues("permissionIds");
Role role = new Role();
role.setId(IdUtil.simpleUUID());
role.setName(name);
role.setOrderNo(orderNo);
role.setCreateTime(DateUtil.now());
roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
Map<String,Object> map = roleService.addRole(role,permissionIds);
if((boolean)map.get("success"))
updateApplication(request,response);
JSONUtil.getJSON(response,map);
private void getRoleList(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入获取角色列表getPermissionList...");
String name = request.getParameter("name");
int page = Integer.parseInt(request.getParameter("page"));
int limit = Integer.parseInt(request.getParameter("limit"));
int pageNumber = (page-1)*limit;
int pageSize = limit;
Map<String,Object> param = new HashMap<>();
param.put("name",name);
param.put("pageNumber",pageNumber);
param.put("pageSize",pageSize);
roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
PageVO<Role> vo = roleService.getRoleList(param);
Map<String,Object> map = new HashMap<>();
map.put("code",0);
map.put("message","请求成功");
map.put("count",vo.getTotal());
map.put("data",vo.getDatas());
JSONUtil.getJSON(response,map);
//更新application中的缓存
private void updateApplication(HttpServletRequest request, HttpServletResponse response)
ServletContext application = request.getServletContext();
RoleService roleService = (RoleService) ServiceFactory.getService(new RoleServiceImpl());
List<Role> roleList = roleService.getRole();
application.setAttribute("roles",roleList);
package com.crsbg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.crsbg.entity.PageVO;
import com.crsbg.entity.Permission;
import com.crsbg.entity.User;
import com.crsbg.service.PermissionService;
import com.crsbg.service.UserService;
import com.crsbg.service.impl.PermissionServiceImpl;
import com.crsbg.service.impl.UserServiceImpl;
import com.crsbg.utils.JSONUtil;
import com.crsbg.utils.ServiceFactory;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 权限管理控制器
*/
public class PermissionController extends HttpServlet
private PermissionService permissionService = null;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String path = request.getServletPath();
if("/controller/getPermissionList".equals(path))
getPermissionList(request,response);
else if("/controller/addPermission".equals(path))
addPermission(request,response);
else if("/controller/updatePermission".equals(path))
updatePermission(request,response);
else if("/controller/deletePermissions".equals(path))
deletePermissions(request,response);
private void deletePermissions(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入批量删除权限deletePermissions...");
String[] ids = request.getParameterValues("id");
permissionService = (PermissionService) ServiceFactory.getService(new PermissionServiceImpl());
boolean flag = permissionService.deletePermissions(ids);
response.getWriter().print(flag);
private void updatePermission(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入修改权限updatePermission...");
String id = request.getParameter("id");
String title = request.getParameter("title");
String url = request.getParameter("url");
String orderNo = request.getParameter("orderNo");
Permission permission = new Permission();
permission.setId(id);
permission.setTitle(title);
permission.setUrl(url);
permission.setOrderNo(orderNo);
permissionService = (PermissionService) ServiceFactory.getService(new PermissionServiceImpl());
boolean flag = permissionService.updatePermission(permission);
response.getWriter().print(flag);
private void addPermission(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入添加权限addPermission...");
String title = request.getParameter("title");
String url = request.getParameter("url");
String orderNo = request.getParameter("orderNo");
Permission permission = new Permission();
permission.setId(IdUtil.simpleUUID());
permission.setTitle(title);
permission.setUrl(url);
permission.setOrderNo(orderNo);
permission.setCreateTime(DateUtil.now());
permissionService = (PermissionService) ServiceFactory.getService(new PermissionServiceImpl());
Map<String,Object> map = permissionService.addPermission(permission);
if((boolean)map.get("success"))
updateApplication(request,response);
JSONUtil.getJSON(response,map);
private void getPermissionList(HttpServletRequest request, HttpServletResponse response) throws IOException
System.out.println("进入获取权限列表getPermissionList...");
String title = request.getParameter("title");
int page = Integer.parseInt(request.getParameter("page"));
int limit = Integer.parseInt(request.getParameter("limit"));
int pageNumber = (page-1)*limit;
int pageSize = limit;
Map<String,Object> param = new HashMap<>();
param.put("title",title);
param.put("pageNumber",pageNumber);
param.put("pageSize",pageSize);
permissionService = (PermissionService) ServiceFactory.getService(new PermissionServiceImpl());
PageVO<Permission> vo = permissionService.getPermissionList(param);
Map<String,Object> map = new HashMap<>();
map.put("code",0);
map.put("message","请求成功");
map.put("count",vo.getTotal());
map.put("data",vo.getDatas());
JSONUtil.getJSON(response,map);
//更新application中的缓存
private void updateApplication(HttpServletRequest request, HttpServletResponse response)
ServletContext application = request.getServletContext();
PermissionService permissionService = (PermissionService) ServiceFactory.getService(new PermissionServiceImpl());
List<Permission> permissionList = permissionService.getPermission();
application.setAttribute("permissions",permissionList);
以上是关于基于JSP+Mybatis实现的CRM客户关系管理系统的主要内容,如果未能解决你的问题,请参考以下文章