好好编程-物流项目18【客户管理-查询客户】

简介: 好好编程-物流项目18【客户管理-查询客户】

客户管理

查询客户

 客户操作规则

image.png

 业务员只能查看属于自己的客户,操作员和管理员可以查看所有的客户。

image.png

1.常量

image.png

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创建

image.png

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

image.png

<%@ 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.访问测试

业务员访问

管理员访问

image.png

image.png

完成~~


相关文章
|
9月前
|
安全
什么是互助预约排单系统开发丨dapp预约排单互助项目系统开发详细流程/规则方案/案例设计/逻辑功能/源码开发
Allow users to register accounts and perform identity verification to ensure the authenticity and credibility of user information.
|
1月前
|
新零售 小程序
认养农业互助模式系统开发|详情逻辑|案例设计
新零售是线上与线下结合,组合的价值主要是线下为线上引流
|
9月前
|
安全
dapp互助预约排单抢单项目系统开发规则玩法/逻辑说明/案例介绍/方案设计/源码程序
The development of DApp appointment and scheduling mutual assistance system refers to the development of a mutual assistance system based on blockchain technology and decentralized application programs (DApp). This system is usually designed as a mutual aid or sharing economy model, aimed at providi
|
8月前
|
安全 搜索推荐 程序员
身为产品经理该如何向客户推广API商品数据接口,该如何跟进项目和程序员对接?
API是Application Programming Interface的缩写,即应用程序编程接口。API商品数据接口是一种允许不同应用程序或系统之间进行数据交互的方式。通过API商品数据接口,不同的应用程序或系统可以相互调用和共享数据,而不必直接相互通信或共享数据。
|
11月前
|
安全 区块链 数据库
互助拍卖竞拍抢单模式系统开发项目方案丨DAPP拍卖竞拍抢拍互助系统开发(案例开发)/开发逻辑/源码运营版
    dapp的开发和运行基于智能合约,智能合约是一种运行在区块链上的自动执行合约,它可以实现自动化的交易和管理逻辑,And automatically supervise and execute according to the set rules.Dapp achieves decentralized data storage,business logic,and value exchange through smart contracts.
|
SQL JSON 前端开发
校园外卖点餐系统——Day02【员工管理业务开发】
校园外卖点餐系统——Day02【员工管理业务开发】
131 0
校园外卖点餐系统——Day02【员工管理业务开发】
|
JSON 前端开发 Java
校园外卖点餐系统——Day04【菜品管理业务开发】
校园外卖点餐系统——Day04【菜品管理业务开发】
144 0
校园外卖点餐系统——Day04【菜品管理业务开发】
【氚云】在代码中,如何实现对人员和部门的调用?
在代码中,如何实现对人员和部门的调用?
240 0
好好编程-物流项目19【客户管理-更新客户】
好好编程-物流项目19【客户管理-更新客户】
好好编程-物流项目19【客户管理-更新客户】
好好编程-物流项目20【客户管理-删除客户】
好好编程-物流项目20【客户管理-删除客户】
好好编程-物流项目20【客户管理-删除客户】