基于javaweb+mysql的jsp+servletcrm客户关系管理系统(java+layui+echarts+jsp+mysql)

基于javaweb+mysql的jsp+servletcrm客户关系管理系统(java+layui+echarts+jsp+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的JSP+Servletcrm客户关系管理系统(java+layui+echarts+jsp+mysql)

功能介绍

该项目未使用spring框架,实现了用户登录,权限控制,数据统计,以及市场活动、线索、客户、联系人、交易管理的CRUD, 使用Proxy实现Service层的动态代理,实现DAO层事务控制,有助于深入理解web项目。管理员还包含系统设置:用户管理、角色管理、 权限管理;其中角色管理可以设置总经理、副总经理、销售经理、综合事务等角色的权限菜单。

环境需要

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 5.7版本;

技术栈

  1. 后端:Servlet+Mybatis 2. 前端:Layui+jquery+echarts+JSP

使用说明

  1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包; 2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置 4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录 5. 管理员账户: admin 密码:123456 普通员工账户:zs 密码:123

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 {
            getActivityByName(request,response);
        }else if("/controller/getActivityByName2".equals(path)){
            getActivityByName2(request,response);
        }else if("/controller/getActivityByConid".equals(path)){
            getActivityByConid(request,response);
        }else if("/controller/getActivityByName3".equals(path)){
            getActivityByName3(request,response);
        }
    }

    private void getActivityByName3(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName3...");
        String sname = request.getParameter("sname");
        String contactsId = request.getParameter("contactsId");
        Map<String,String> param = new HashMap<>();
        param.put("name",sname);
        param.put("contactsId",contactsId);
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List<Activity> activityList = activityService.getActivityByName3(param);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByConid(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入获取市场列表getActivityByConid...");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String contactsId = request.getParameter("contactsId");
        List<Activity> activityList = activityService.getActivityByConid(contactsId);
        JSONUtil.getJSON(response,activityList);
    }

    private void getActivityByName2(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName2...");
        String sname = request.getParameter("sname");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List<Activity> activityList = activityService.getActivityByName2(sname);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName...");
        String sname = request.getParameter("sname");
        String contactSummary = request.getParameter("contactSummary");
        String description = request.getParameter("description");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        Customer customer = new Customer();
        customer.setId(id);
        customer.setOwner(owner);
        customer.setName(name);
        customer.setWebsite(website);
        customer.setTel(tel);
        customer.setNextContactDate(nextContactDate);
        customer.setAddress(address);
        customer.setDescription(description);
        customer.setContactSummary(contactSummary);
        customer.setCreateBy(createBy);
        customer.setCreateTime(createTime);
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        boolean flag = customerService.addCustomer(customer);
        response.getWriter().print(flag);
    }

    private void getCustomer(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入查询客户getCustomer...");
        String name = request.getParameter("name");
        String owner = request.getParameter("owner");
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        int pageNumber = (page-1)*limit;
        int pageSize = limit;
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        Map<String,Object> param = new HashMap<>();
        param.put("name",name);
        param.put("owner",owner);
        param.put("pageNumber",pageNumber);
        param.put("pageSize",pageSize);
        PageVO<Customer> vo = customerService.getCustomer(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);
    }
}
package com.crsbg.controller;

        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;

        //String password = SecureUtil.md5(request.getParameter("password"));
        String password = (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;

public class ActivityController extends HttpServlet {
    private ActivityService activityService = null;
    @Override
        System.out.println("进入添加联系人addContacts...");
        String id = IdUtil.simpleUUID();
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String customerId = request.getParameter("customerId");
        String job = request.getParameter("job");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String birth = request.getParameter("birth");
        String source = request.getParameter("source");
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        Contacts contacts = new Contacts();
        contacts.setId(id);
        contacts.setFullname(fullname);
        contacts.setAppellation(appellation);
        contacts.setCustomerId(customerId);
        contacts.setJob(job);
        contacts.setPhone(phone);
        contacts.setEmail(email);
        contacts.setBirth(birth);
        contacts.setSource(source);
        contacts.setDescription(description);
        contacts.setContactSummary(contactSummary);
        contacts.setNextContactDate(nextContactDate);
        contacts.setAddress(address);
        contacts.setCreateBy(createBy);
        contacts.setCreateTime(createTime);
        contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl());
        boolean flag = contactsService.addContacts(contacts);
        response.getWriter().print(flag);
    }

    private void getContacts(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入查询联系人getContacts...");
        String fullname = request.getParameter("fullname");
        String company = request.getParameter("company");
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
    }

}
package com.crsbg.controller;

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");
        contacts.setCustomerId(customerId);
        contacts.setJob(job);
        contacts.setPhone(phone);
        contacts.setEmail(email);
        contacts.setBirth(birth);
        contacts.setSource(source);
        contacts.setDescription(description);
        contacts.setContactSummary(contactSummary);
        contacts.setNextContactDate(nextContactDate);
        contacts.setAddress(address);
        contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl());
        boolean flag = contactsService.updateContacts(contacts);
        response.getWriter().print(flag);
    }

    private void detailContacts(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入联系人详情detailContacts...");
        String id = request.getParameter("id");
        contactsService = (ContactsService) ServiceFactory.getService(new ContactsServiceImpl());
        Contacts contacts = contactsService.getContactsById(id);
        request.setAttribute("contacts",contacts);
        request.getRequestDispatcher("/pages/contacts-detail.jsp").forward(request,response);
    }

    private void addContacts(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入添加联系人addContacts...");
        String id = IdUtil.simpleUUID();
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String customerId = request.getParameter("customerId");
        String job = request.getParameter("job");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String birth = request.getParameter("birth");
        String source = request.getParameter("source");
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        Contacts contacts = new Contacts();
        contacts.setId(id);
        contacts.setFullname(fullname);
        contacts.setAppellation(appellation);
        contacts.setCustomerId(customerId);
        contacts.setJob(job);
        contacts.setPhone(phone);
        contacts.setEmail(email);
        contacts.setBirth(birth);
        contacts.setSource(source);
        contacts.setDescription(description);
        contacts.setContactSummary(contactSummary);
        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;

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)){

    private void addContacts(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入添加联系人addContacts...");
        String id = IdUtil.simpleUUID();
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String customerId = request.getParameter("customerId");
        String job = request.getParameter("job");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String birth = request.getParameter("birth");
        String source = request.getParameter("source");
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        Contacts contacts = new Contacts();
        contacts.setId(id);
        contacts.setFullname(fullname);
        contacts.setAppellation(appellation);
        contacts.setCustomerId(customerId);
        contacts.setJob(job);
        contacts.setPhone(phone);
        contacts.setEmail(email);
        contacts.setBirth(birth);
        contacts.setSource(source);
        contacts.setDescription(description);
        contacts.setContactSummary(contactSummary);
        contacts.setNextContactDate(nextContactDate);
        contacts.setAddress(address);
        contacts.setCreateBy(createBy);
        contacts.setCreateTime(createTime);
        contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl());
        boolean flag = contactsService.addContacts(contacts);
        response.getWriter().print(flag);
    }

    private void getContacts(HttpServletRequest request, HttpServletResponse response) throws IOException {
    }

    private void getCustomerName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入获取客户名称getCustomerName");
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        List<Customer> customerList = customerService.getCustomerName();
        JSONUtil.getJSON(response,customerList);
    }

    private void deleteCustomers(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入批量删除客户deleteCustomers...");
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        String[] ids = request.getParameterValues("id");
        Map<String,Object> map = customerService.deleteCustomers(ids);
        JSONUtil.getJSON(response,map);
    }

    private void deleteCustomer(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入删除客户deleteCustomer...");
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        String id = request.getParameter("id");
        Map<String,Object> map = customerService.deleteCustomer(id);
        JSONUtil.getJSON(response,map);
    }

    private void updateCustomer(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入修改客户updateCustomer...");
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        String id = request.getParameter("id");
        String owner = request.getParameter("owner");
        String name = request.getParameter("name");
        String website = request.getParameter("website");
        String tel = request.getParameter("tel");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate =  request.getParameter("nextContactDate");
        String description = request.getParameter("description");
        String address = request.getParameter("address");
        String editBy = ((User)request.getSession().getAttribute("user")).getName();
        String editTime = DateUtil.now();
        Customer customer = new Customer();
        customer.setId(id);
        customer.setOwner(owner);
        customer.setName(name);
        customer.setWebsite(website);
        customer.setTel(tel);

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);
    public void init(ServletConfig config) throws ServletException {

        System.out.println("正在初始化 log4j日志设置信息");
        String log4jLocation = config.getInitParameter("log4j-properties-location");
        ServletContext sc = config.getServletContext();

        if (log4jLocation == null) {
            System.err.println("没有找到log4j-properties-location, 所以使用 BasicConfigurator初始化");
            BasicConfigurator.configure();
        } else {
            String webAppPath = sc.getRealPath("/");
            String log4jProp = webAppPath + log4jLocation;
            File yoMamaYesThisSaysYoMama = new File(log4jProp);
            if (yoMamaYesThisSaysYoMama.exists()) {
                System.out.println(log4jProp + "初始化日志设置信息");
                PropertyConfigurator.configure(log4jProp);
            } else {
                System.err.println(log4jProp+ " 文件没有找到, 所以使用 BasicConfigurator初始化");
                BasicConfigurator.configure();
            }
        }
        super.init(config);
    }

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException, IOException {
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
    }

}
package com.crsbg.filter;

public class PermissionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
        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;

        HttpServletResponse response = (HttpServletResponse) resp;
        User user = (User) request.getSession().getAttribute("user");
        String path = request.getServletPath();
        List<String> permissionList = new ArrayList<>();
        permissionList.add("/pages/activity.jsp");
        permissionList.add("/pages/clue.jsp");
        permissionList.add("/pages/customer.jsp");
        permissionList.add("/pages/contacts.jsp");
        permissionList.add("/pages/tran.jsp");
        permissionList.add("/pages/user.jsp");
        permissionList.add("/pages/role.jsp");
        permissionList.add("/pages/permission.jsp");
        if(user!=null&&permissionList.contains(path)){
            Set<String> permissions = user.getPermissions();
            if(!"1".equals(user.getIsAdmin())&&!permissions.contains(path)){
                response.sendRedirect(request.getContextPath()+"/pages/error.jsp");
                return;
            }
        }
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
package com.crsbg.filter;

public class LoginFilter implements Filter{
        String owner = request.getParameter("owner");
        String company = request.getParameter("company");
        String job = request.getParameter("job");
        String email = request.getParameter("email");
        String tel = request.getParameter("tel");
        String website = request.getParameter("website");
        String phone = request.getParameter("phone");
        String state = request.getParameter("state");
        String source = request.getParameter("source");
        String editBy = ((User)request.getSession().getAttribute("user")).getName();
        String editTime = DateUtil.now();
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        Clue clue = new Clue();
        clue.setId(id);
        clue.setFullname(fullname);
        clue.setAppellation(appellation);
        clue.setOwner(owner);
        clue.setCompany(company);
        clue.setJob(job);
        clue.setEmail(email);
        clue.setTel(tel);
        clue.setWebsite(website);
        clue.setPhone(phone);
        clue.setState(state);
        clue.setSource(source);
        clue.setEditBy(editBy);
        clue.setEditTime(editTime);
        clue.setDescription(description);
        clue.setContactSummary(contactSummary);
        clue.setNextContactDate(nextContactDate);
        clue.setAddress(address);
        boolean flag = clueService.updateClue(clue);
        response.getWriter().print(flag);
    }

    private void getClueByIdAndUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入查询线索和用户getClueByIdAndUser...");
        String id = request.getParameter("id");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        Map map = clueService.getClueByIdAndUser(id);
        JSONUtil.getJSON(response, map);
    }

        Map<String,Object> map = new HashMap<>();
        map.put("success",flag);
        map.put("editBy",editBy);
        map.put("editTime",editTime);
        JSONUtil.getJSON(response,map);
    }

    private void detailCustomer(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入客户详情detailCustomer...");
        String id = request.getParameter("id");
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        Customer customer = customerService.getCustomerById(id);
        request.setAttribute("customer",customer);
        request.getRequestDispatcher("/pages/customer-detail.jsp").forward(request,response);
    }

    private void addCustomer(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入添加客户addCustomer...");
        String id = IdUtil.simpleUUID();
        String owner = request.getParameter("owner");
        String name = request.getParameter("name");
        String website = request.getParameter("website");
        String tel = request.getParameter("tel");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        String contactSummary = request.getParameter("contactSummary");
        String description = request.getParameter("description");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        Customer customer = new Customer();
        customer.setId(id);
        customer.setOwner(owner);
        customer.setName(name);
        customer.setWebsite(website);
        customer.setTel(tel);
        customer.setNextContactDate(nextContactDate);
        customer.setAddress(address);
        customer.setDescription(description);
        customer.setContactSummary(contactSummary);
        customer.setCreateBy(createBy);
        customer.setCreateTime(createTime);
        customerService = (CustomerService) ServiceFactory.getService(new CustomerServiceImpl());
        boolean flag = customerService.addCustomer(customer);
        response.getWriter().print(flag);
        Map map = clueService.getClueByIdAndUser(id);
        JSONUtil.getJSON(response, map);
    }

    private void removeClueActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入解除线索和市场活动关系removeClueActivity...");
        String id = request.getParameter("id");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        boolean flag = clueService.removeClueActivity(id);
        response.getWriter().print(flag);
    }

    private void addClueActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入添加线索和市场活动关系addClueActivity...");
        String clueId = request.getParameter("cid");
        String[] activityIds = request.getParameterValues("aid");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        boolean flag = clueService.addClueActivity(clueId,activityIds);
        response.getWriter().print(flag);
    }

    private void clueDetail(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        System.out.println("进入查询线索详细信息detailClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = request.getParameter("id");
        Clue clue = clueService.detailClue(id);
        request.setAttribute("clue",clue);
        request.getRequestDispatcher("/pages/clue-detail.jsp").forward(request,response);
    }

    private void addClue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入addClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = IdUtil.simpleUUID();
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String owner = request.getParameter("owner");
        String company = request.getParameter("company");
        String job = request.getParameter("job");
        String email = request.getParameter("email");
        String tel = request.getParameter("tel");
        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"));
        String password = (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;

        tran.setCreateTime(createTime);
        tran.setDescription(description);
        tran.setContactSummary(contactSummary);
        tranService = (TranService) ServiceFactory.getService(new TranServiceImpl());
        boolean flag = tranService.addTran(tran,customer);
        response.getWriter().print(flag);
    }

    private void getTran(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入获取交易列表getTran...");
        String owner = request.getParameter("owner");
        String name = request.getParameter("name");
        String expectedDate = request.getParameter("expectedDate");
        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("owner",owner);
        param.put("name",name);
        param.put("expectedDate",expectedDate);
        param.put("pageNumber",pageNumber);
        param.put("pageSize",pageSize);
        tranService = (TranService) ServiceFactory.getService(new TranServiceImpl());
        PageVO<Tran> vo = tranService.getTran(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);
    }
}
package com.crsbg.controller;

        String sname = request.getParameter("sname");
        String contactsId = request.getParameter("contactsId");
        Map<String,String> param = new HashMap<>();
        param.put("name",sname);
        param.put("contactsId",contactsId);
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List<Activity> activityList = activityService.getActivityByName3(param);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByConid(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入获取市场列表getActivityByConid...");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String contactsId = request.getParameter("contactsId");
        List<Activity> activityList = activityService.getActivityByConid(contactsId);
        JSONUtil.getJSON(response,activityList);
    }

    private void getActivityByName2(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName2...");
        String sname = request.getParameter("sname");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List<Activity> activityList = activityService.getActivityByName2(sname);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName...");
        String sname = request.getParameter("sname");
        String clueId = request.getParameter("clueId");
        Map<String,String> param = new HashMap<>();
        param.put("name",sname);
        param.put("clueId",clueId);
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List<Activity> activityList = activityService.getActivityByName(param);
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
    @Override
    public void destroy() {

    }
}
package com.crsbg.filter;

public class LoginFilter implements Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) resp;
		Object user = request.getSession().getAttribute("user");
		String path = request.getServletPath();
		
		if(user!=null||"/pages/login.jsp".equals(path)||"/controller/login".equals(path)) {
			chain.doFilter(request, response);
		}else {
			response.sendRedirect(request.getContextPath()+"/pages/login.jsp");
		}
	}

        JSONUtil.getJSON(response,map);
    }
}
package com.crsbg.controller;

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 {
            //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"));

public class PermissionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        User user = (User) request.getSession().getAttribute("user");
        String path = request.getServletPath();
        List<String> permissionList = new ArrayList<>();
        permissionList.add("/pages/activity.jsp");
        permissionList.add("/pages/clue.jsp");
        permissionList.add("/pages/customer.jsp");
        permissionList.add("/pages/contacts.jsp");
        permissionList.add("/pages/tran.jsp");
        permissionList.add("/pages/user.jsp");
        permissionList.add("/pages/role.jsp");
        permissionList.add("/pages/permission.jsp");
        if(user!=null&&permissionList.contains(path)){
            Set<String> permissions = user.getPermissions();
            if(!"1".equals(user.getIsAdmin())&&!permissions.contains(path)){
                response.sendRedirect(request.getContextPath()+"/pages/error.jsp");
                return;
            }
        }
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
package com.crsbg.filter;
        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);
    }

}
package com.crsbg.controller;

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)){

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值