add worker evalueReport

This commit is contained in:
sobear 2024-06-07 00:02:35 +08:00
parent 5f63b16145
commit 37e539727d
7 changed files with 242 additions and 0 deletions

View File

@ -0,0 +1,70 @@
package cn.edu.cqwu.repair.controller.worker;
import cn.edu.cqwu.repair.dao.OrderDao;
import cn.edu.cqwu.repair.dao.WorkerDao;
import cn.edu.cqwu.repair.entity.Order;
import cn.edu.cqwu.repair.entity.ScoreDates;
import cn.edu.cqwu.repair.entity.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
* @author sobear
*/
@Controller
public class WorkerEvalueReportController extends HttpServlet{
private final OrderDao orderDao;
private final WorkerDao workerDao;
@Autowired
public WorkerEvalueReportController(OrderDao orderDao,WorkerDao workerDao){
this.orderDao = orderDao;
this.workerDao = workerDao;
}
@RequestMapping ("/worker/EvalueReport.do")
public String getScore(Model model, HttpSession session,
HttpServletRequest request){
// 获取Session对象
session = request.getSession();
// 从Session中获取ID数据
Worker workerUser = (Worker) session.getAttribute("workerUser");
// 调用DAO的方法来获取数据库中的该员工的历史订单数据
List<Order> orders = (List<Order>) orderDao.findByWorkerNoStatus(workerUser.getUserid());
int num12 = 0; // 记录score为1~2之间的数量
int num3 = 0; // 记录score为3之间的数量
int num45 = 0; // 记录score为4~5之间的数量
int numTotal = orders.size(); // 记录总数
int totalScore = 0; // 记录总分数
for (Order order : orders) {
int score = order.getScore();
totalScore += score;
if (score >= 1 && score <= 2) {
num12++;
} else if (score == 3) {
num3++;
} else if (score >= 4 && score <= 5) {
num45++;
}
}
double numAverage = (double) totalScore / numTotal; // 平均数
ScoreDates scDatas = new ScoreDates(num12,num3,num45,numTotal,totalScore,numAverage);
model.addAttribute("scDatas",scDatas);
return "/worker/worker_evalue_report";
}
}

View File

@ -15,6 +15,8 @@ public interface OrderDao {
ArrayList<Order> findByWorkerId(int workerId); ArrayList<Order> findByWorkerId(int workerId);
ArrayList<Order> findByStatus(int status); ArrayList<Order> findByStatus(int status);
ArrayList<Order> findByWorkerNoStatus(int status);
public int statusModify(int orderId); public int statusModify(int orderId);
public Order findByOrderId(int orderId); public Order findByOrderId(int orderId);

View File

@ -71,6 +71,13 @@ public class OrderDaoImpl implements OrderDao {
return (ArrayList<Order>) mapper.selectListByQuery(qw); return (ArrayList<Order>) mapper.selectListByQuery(qw);
} }
@Override
public ArrayList<Order> findByWorkerNoStatus(int workerId){
QueryWrapper qw = new QueryWrapper();
qw.select(ORDER.ALL_COLUMNS).where(ORDER.WORKER_ID.eq(workerId));
return (ArrayList<Order>) mapper.selectListByQuery(qw);
}
@Override @Override
public ArrayList<Order> findByStatus(int status) { public ArrayList<Order> findByStatus(int status) {
QueryWrapper qw = new QueryWrapper(); QueryWrapper qw = new QueryWrapper();

View File

@ -89,4 +89,6 @@ public class WorkerDaoImpl implements WorkerDao {
qw.where(WORKER.ORDER_STATUS.eq(WorkerStatus.FREE.value)).where(WORKER.TYPE_ID.eq(typeId)); qw.where(WORKER.ORDER_STATUS.eq(WorkerStatus.FREE.value)).where(WORKER.TYPE_ID.eq(typeId));
return MAPPER.selectOneByQuery(qw); return MAPPER.selectOneByQuery(qw);
} }
} }

View File

@ -0,0 +1,74 @@
package cn.edu.cqwu.repair.entity;
public class ScoreDates {
private int num12; // 记录score为1~2之间的数量
private int num3; // 记录score为3之间的数量
private int num45; // 记录score为4~5之间的数量
private int numTotal; // 记录总数
private int totalScore; // 记录总分数
private double numAverage;//记录平均数
// 构造函数
public ScoreDates(int num12, int num3, int num45, int numTotal, int totalScore,double numAverage) {
this.num12 = num12;
this.num3 = num3;
this.num45 = num45;
this.numTotal = numTotal;
this.totalScore = totalScore;
this.numAverage = numAverage;
}
// Getter Setter 方法
public double getnumAverage() {
return numAverage;
}
public void setnumAverage(double numAverage) {
this.numAverage = numAverage;
}
public int getNum12() {
return num12;
}
public void setNum12(int num12) {
this.num12 = num12;
}
public int getNum3() {
return num3;
}
public void setNum3(int num3) {
this.num3 = num3;
}
public int getNum45() {
return num45;
}
public void setNum45(int num45) {
this.num45 = num45;
}
public int getNumTotal() {
return numTotal;
}
public void setNumTotal(int numTotal) {
this.numTotal = numTotal;
}
public int getTotalScore() {
return totalScore;
}
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
@Override
public String toString() {
return "{num12: "+num12 + ",num3:" + num3 + ",num45:" + num45 + ",numAverage: " + numAverage + ",}";
}
}

View File

@ -100,6 +100,9 @@
<a href="${webroot}/worker/FixList.do" class="nav-link link-body-emphasis" aria-current="page"> <a href="${webroot}/worker/FixList.do" class="nav-link link-body-emphasis" aria-current="page">
>> 维修列表 >> 维修列表
</a> </a>
<a href="${webroot}/worker/EvalueReport.do" class="nav-link link-body-emphasis" aria-current="page">
>> 订单满意度
</a>
<a href="${webroot}/worker/HistoryList.do" class="nav-link link-body-emphasis" aria-current="page"> <a href="${webroot}/worker/HistoryList.do" class="nav-link link-body-emphasis" aria-current="page">
>> 历史维修记录 >> 历史维修记录
</a> </a>

View File

@ -0,0 +1,84 @@
<%--
Created by IntelliJ IDEA.
User: sobear
Date: 2024/6/6
Time: 21:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<c:set var="title" value="用户中心"/>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>${title}</title>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
</head>
<body>
<main class="d-flex flex-nowrap">
<%@ include file="../includes/header.jsp" %>
<main class="form-signin w-100 m-auto">
<canvas id="pieChart" width="400" height="400"></canvas>
<div class="alert alert-primary square-alert" role="alert">
你的客户满意度评价为:${scDatas.getnumAverage()};
</div>
</main>
</main>
<script>
// 获取 Java 对象中的数据
var scDatas = ${scDatas};
// 在 JavaScript 中使用 Java 对象中的数据
var num12 = scDatas.num12;
var num3 = scDatas.num3;
var num45 = scDatas.num45;
// 绘制饼图
var ctx = document.getElementById('pieChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'pie',
data: {
labels: ['不满意', '一般', '满意'],
datasets: [{
label: 'Scores',
data: [num12, num3, num45],
backgroundColor: [
'rgba(255, 99, 132, 0.5)',
'rgba(54, 162, 235, 0.5)',
'rgba(255, 206, 86, 0.5)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: true,
text: 'Scores Distribution'
}
}
});
</script>
</body>
</html>