客户管理
查询客户
客户操作规则
业务员只能查看属于自己的客户,操作员和管理员可以查看所有的客户。
1.常量
2.创建V_Customer视图
SELECT t1.customer_id ,t1.customer_name ,t1.address ,t1.c_sex ,t1.email ,t1.base_id ,t1.id_card ,t1.mobile_phone ,t1.order_id ,t1.remark ,t1.user_id ,t2.user_name ,t2.real_name ,t3.base_name from t_customer t1 left join t_user t2 on t1.user_id = t2.user_id left join t_basicdata t3 on t1.base_id = t3.base_id
通过视图将对应的业务员姓名和常用区间信息查询了出来,便于展示数据
3.CustomerDto创建
package com.bobo.dto; import com.bobo.pojo.Customer; /** * 客户的数据传输对象 * * @author 波波烤鸭 * * dengpbs@163.com */ public class CustomerDto extends BasePage{ private Customer customer; // 业务员 private String salesMan; // 常用区间 private String interval; public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public String getSalesMan() { return salesMan; } public void setSalesMan(String salesMan) { this.salesMan = salesMan; } public String getInterval() { return interval; } public void setInterval(String interval) { this.interval = interval; } }
4.CustomerMapper.xml
<resultMap type="com.bobo.dto.CustomerDto" id="baseCustomerDto"> <id column="customer_id" jdbcType="INTEGER" property="customer.customerId" /> <result column="order_id" jdbcType="INTEGER" property="customer.orderId" /> <result column="base_id" jdbcType="INTEGER" property="customer.baseId" /> <result column="user_id" jdbcType="INTEGER" property="customer.userId" /> <result column="customer_name" jdbcType="VARCHAR" property="customer.customerName" /> <result column="mobile_phone" jdbcType="BIGINT" property="customer.mobilePhone" /> <result column="email" jdbcType="VARCHAR" property="customer.email" /> <result column="address" jdbcType="VARCHAR" property="customer.address" /> <result column="id_card" jdbcType="VARCHAR" property="customer.idCard" /> <result column="c_sex" jdbcType="BIT" property="customer.cSex" /> <result column="remark" jdbcType="VARCHAR" property="customer.remark" /> <result column="real_name" jdbcType="VARCHAR" property="salesMan" /> <result column="base_name" jdbcType="VARCHAR" property="interval" /> </resultMap> <select id="queryView" resultMap="baseCustomerDto" parameterType="com.bobo.pojo.Customer" > select t1.customer_id ,t1.customer_name ,t1.address ,t1.c_sex ,t1.email ,t1.base_id ,t1.id_card ,t1.mobile_phone ,t1.order_id ,t1.remark ,t1.user_id ,t1.user_name ,t1.real_name ,t1.base_name from v_customer t1 <where> <if test="userId !=null and userId > 0"> user_id = #{userId} </if> </where> </select>
5.CustomerMapper.java
List<CustomerDto> queryView(Customer record);
6.service层
接口
/** * 分页查询 * @param dto * @return */ public PageInfo<CustomerDto> queryPage(CustomerDto dto,User user);
实现
/** * 当前用户如果是 业务员 只能查看所属的客户 * 如果是 操作员 或者 管理员 能查看所有的客户 */ @Override public PageInfo<CustomerDto> queryPage(CustomerDto dto,User user) { PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); // 获取角色信息 List<Role> list = userService.queryRoleByUserId(user.getUserId()); boolean flag = false; if(list != null && list.size() > 0){ for (Role role : list) { if(Constant.ROLE_ADMIN.equals(role.getRoleName()) || Constant.ROLE_OPERATOR.equals(role.getRoleName())){ // 拥有操作员或者管理员的身份,查询所有的客户信息 flag = true; break; } } } // 业务员 限制查询 Customer customer = new Customer(); if(flag == false){ customer.setUserId(user.getUserId()); } List<CustomerDto> customers = customerMapper.queryView(customer); return new PageInfo<>(customers); }
7.控制器
@RequestMapping("/query") public String query(CustomerDto dto,Model model){ // 获取登录用户信息 User user = (User) SecurityUtils.getSubject().getPrincipal(); System.out.println("--->"+user.getUserId()); PageInfo<CustomerDto> list = customerService.queryPage(dto,user); model.addAttribute(Constant.PAGE_MODEL, list); return "customer/customer"; }
8.Customer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <link href="/css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".click").click(function() { $(".tip").fadeIn(200); }); $(".tiptop a").click(function() { $(".tip").fadeOut(200); }); $(".sure").click(function() { $(".tip").fadeOut(100); }); $(".cancel").click(function() { $(".tip").fadeOut(100); }); }); </script> </head> <body> <div class="place"> <span>位置:</span> <ul class="placeul"> <li><a href="#">首页</a></li> <li><a href="#">数据表</a></li> <li><a href="#">基本内容</a></li> </ul> </div> <div class="rightinfo"> <div class="tools"> <ul class="toolbar"> <li class="click"> <a href="userUpdate"> <span> <img src="/images/t01.png" /> </span> 添加 </a> </li> <li class="click"><span><img src="/images/t02.png" /></span>修改</li> <li><span><img src="/images/t03.png" /></span>删除</li> <li><span><img src="/images/t04.png" /></span>统计</li> </ul> <ul class="toolbar1"> <li><span><img src="/images/t05.png" /></span>设置</li> </ul> </div> <table class="tablelist"> <thead> <tr> <th><input name="" type="checkbox" value="" checked="checked" /></th> <th>编号<i class="sort"><img src="/images/px.gif" /></i></th> <th>客户姓名</th> <th>客户电话</th> <th>邮箱</th> <th>性别</th> <th>业务员</th> <th>常用区间</th> <th>身份证号</th> <th>通讯地址</th> <th>操作</th> </tr> </thead> <tbody> <c:forEach items="${pageModel.list }" var="dto"> <tr> <td><input name="" type="checkbox" value="" /></td> <td>${dto.customer.customerId }</td> <td>${dto.customer.customerName }</td> <td>${dto.customer.mobilePhone }</td> <td>${dto.customer.email }</td> <td>${dto.customer.cSex eq true?"男":"女" }</td> <td>${dto.salesMan }</td> <td>${dto.interval }</td> <td>${dto.customer.idCard}</td> <td>${dto.customer.address }</td> <td> <a href="/user/userUpdate?id=${dto.customer.customerId }" class="tablelink">修改</a> <a href="javascript:void(0)" onclick="deleteUser(${dto.customer.customerId})" class="tablelink"> 删除</a></td> </tr> </c:forEach> </tbody> </table> <div class="inline pull-right page" style="margin-top: 20px;"> <form action="/user/queryPage" id="pager"> <input type="hidden" name="pageSize" id="pageSize" value="${pageModel.pageSize }"> <input type="hidden" name="pageNum" id="pageNum" value="${pageModel.pageNum }"> </form> <jsp:include page="/pageBar.jsp"></jsp:include> </div> </div> <script type="text/javascript"> $('.tablelist tbody tr:odd').addClass('odd'); function deleteUser(userId){ if(window.confirm("确定要删除该用户吗?")){ location.href="/user/delete?id="+userId; } } </script> </body> </html>
9.访问测试
业务员访问
管理员访问
完成~~