概念
本文在供应商管理功能之后,继续讲解订单管理功能,该功能是由普通员工与供应商之间的订单进货,经理进行监管等等。
需求分析
订单管理:
1.如果系统管理员登录,操作订单管理没有权限
2.如果经理登录,允许查看所有员工所谈下来的所有订单,修改,删除
3.普通员工登录,员工添加订单,并只能查看自己谈下来的订单
功能实现
当用户登录系统后,点击订单管理功能时,进行判断当前用户的身份,根据不同用户发出不同的请求:
function ddgl() {
var input=document.getElementById("hidd");
var i=input.value;
switch (i) {
case "2":
//经理,只能查看所有订单,修改订单,删除订单,不能添加订单
location.href="GetBills.do";
break;
case "3":
//普通员工,添加订单和查询自己的订单
location.href="GetBillsByUserId.do";
break;
default:
//管理员身份不允许操作该功能
alert("当前登录的员工不具备该功能的操作权限");
break;
}
}
普通员工查询自身订单信息
当普通员工进入系统后,操作订单管理功能,则想控制器发出GetBillsByUserId.do请求,因此,我们需要在控制层中建立操作订单表的控制器BillController类,并定义方法接收该请求:
package com.smbms.controller;
import com.smbms.service.IBillService;
import com.smbms.service.IProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class BillController {
@Autowired
IBillService bService;
//定义方法,用于普通员工操作订单管理功能,查看自己的订单信息
@RequestMapping("/GetBillsByUserId.do")
public ModelAndView GetBillsByUserId(HttpSession session){
//根据普通员工的主键id作为条件查询该普通员工自己的订单信息
Map<String,Object> map= (Map<String, Object>) session.getAttribute("userInfo");
long userId= (long) map.get("id");
List<Map<String, Object>> billsById = bService.getBillsById(userId);
ModelAndView mav=new ModelAndView();
mav.addObject("bills",billsById);
mav.setViewName("billList");
return mav;
}
}
在控制器中,通过登录保存的用户的个人信息中获得给普通员工的id作为查询订单表的条件,并将给用户id发送给service层中的IBillService接口中的方法:
package com.smbms.service;
import java.util.List;
import java.util.Map;
public interface IBillService {
//根据普通员工的id作为条件查询订单表
List<Map<String,Object>> getBillsById(long userId);
}
该接口将接收到的用户id发送给service的实现类BillServiceImp中实现该方法:
package com.smbms.service;
import com.smbms.dao.IBillDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service(value = "bService")
public class BillServiceImp implements IBillService {
@Autowired
IBillDao dao;
@Override
public List<Map<String, Object>> getBillsById(long userId) {
return dao.getBillById(userId);
}
}
实现类将用户id发送给dao层的IBillDao接口完成根据用户id查询订单信息的功能:
public interface IBillDao {
//根据普通员工的id作为条件查询订单表,将该员工自己的订单信息查询出来
@Select("select smbms_bill.id,smbms_bill.billCode," +
"smbms_bill.productName,smbms_bill.productDesc," +
"smbms_bill.productCount,smbms_bill.productUnit," +
"smbms_bill.totalPrice,smbms_bill.isPayment," +
"smbms_provider.proName,smbms_bill.creationDate " +
"from smbms_provider,smbms_bill " +
"where smbms_bill.providerId=smbms_provider.id " +
"and smbms_bill.createdBy=#{userId}")
List<Map<String,Object>> getBillById(@Param("userId")long userId);
}
根据需求的功能要求进行订单表和用户表的多表联查获得需要展示在页面的数据信息,并将查询的数据封装后返回给控制器,控制器将数据发送给billList.jsp页面显示:
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>超市订单管理系统--订单列表</title>
<style type="text/css">
tr {
height: 40px;
}
</style>
</head>
<body>
<div style="width: 1800px;height: 1000px;margin: auto;">
<div style="width: 100%;height: 160px;background-color:skyblue;">
<div style="width: 100%;height: 20px;">
<div align="left" style="width: 20%;height: 100%;float: left;" >
<a href="home.do" style="text-decoration: none;">返回首页</a>
</div>
<div align="right" style="width: 80%;height: 100%;float: right;">
<a>欢迎,<span style="color: red;">${userInfo.userName}</span></a>
<a href="index.do" style="text-decoration: none;">注销</a>
</div>
</div>
<div align="center" style="width: 100%;height: 140px;line-height: 140px;"><h1>超市订单管理系统</h1></div>
</div>
<% List<Map<String,Object>> list=(List<Map<String,Object>>)request.getAttribute("bills"); %>
<div align="center" style="width: 100%;height: 840px;background-color: pink;overflow: scroll;">
<div align="left" style="height: 40px;" >
<a href="toAddBill.do" style="text-decoration: none;
text-align:center; width: 50px;
height: 20px;
color: white;font-weight: bold;
margin-top:20px;margin-left:10px;
border-radius: 5px;">添加订单</a>
</div>
<!-- 当前普通员工是否有谈下过订单信息,如果没有,显示暂无信息,如果有,展示该员工的所有订单 -->
<% if(list==null||list.size()==0){ %>
<div style="width: 98%;text-align: center;height: 800px;">
当前暂无订单信息
</div>
<%}else { %>
<table border="1" style="width: 98%;text-align: center;border-collapse: collapse;">
<tr>
<td>序号</td>
<td>账单编码</td>
<td>商品名称</td>
<td>商品描述</td>
<td>商品数量</td>
<td>商品单位</td>
<td>商品总额</td>
<td>是否支付</td>
<td>供应商名称</td>
<td>创建时间</td>
</tr>
<% for(int i=0;i<list.size();i++){ %>
<tr>
<td ><%=i+1 %></td>
<td><%=list.get(i).get("billCode") %></td>
<td><%=list.get(i).get("pr