fix: stu create order
This commit is contained in:
parent
8954d66842
commit
73a5918f49
@ -1,58 +1,114 @@
|
||||
|
||||
|
||||
package cn.edu.cqwu.repair.controller.stu;
|
||||
|
||||
import cn.edu.cqwu.repair.dao.DeviceDao;
|
||||
import cn.edu.cqwu.repair.dao.OrderDao;
|
||||
import cn.edu.cqwu.repair.dao.StuDao;
|
||||
import cn.edu.cqwu.repair.entity.Device;
|
||||
import cn.edu.cqwu.repair.entity.Order;
|
||||
import cn.edu.cqwu.repair.entity.OrderStatus;
|
||||
import cn.edu.cqwu.repair.entity.Stu;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.Mapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Controller
|
||||
public class StuUploadController {
|
||||
|
||||
StuDao stuDao;
|
||||
DeviceDao deviceDao;
|
||||
DeviceDao deviceDao;
|
||||
OrderDao orderDao;
|
||||
|
||||
@Autowired
|
||||
public StuUploadController(StuDao stuDao,OrderDao orderDao,DeviceDao deviceDao) {
|
||||
public StuUploadController(StuDao stuDao, OrderDao orderDao, DeviceDao deviceDao) {
|
||||
this.stuDao = stuDao;
|
||||
this.orderDao = orderDao;
|
||||
this.deviceDao = deviceDao;
|
||||
}
|
||||
|
||||
// @RequestMapping("/stu/upload")
|
||||
// public String consult(HttpServletRequest request) {
|
||||
// request.setAttribute("devices", deviceDao.findAllDevice());
|
||||
//
|
||||
// return "/stu/upload";
|
||||
//
|
||||
// }
|
||||
|
||||
@PostMapping("/upload.do")
|
||||
public String upload(Order order, @SessionAttribute Stu stu, HttpServletRequest request){
|
||||
order.setStudentId(stu.getUserid());
|
||||
order.setStudentId(0);
|
||||
|
||||
int is = orderDao.add(order);
|
||||
if(is==1){
|
||||
request.setAttribute("stuUploadMess","上传成功");
|
||||
}else{
|
||||
request.setAttribute("stuUploadMess","上传失败");
|
||||
|
||||
@RequestMapping("/stu/upload.do")
|
||||
public String upload(int deviceTypeId, int deviceAddressId, HttpServletRequest request) {
|
||||
ArrayList<Device> deviceList = deviceDao.findAllDevice(deviceTypeId, deviceAddressId, 0);
|
||||
if (deviceList.isEmpty()) {
|
||||
request.setAttribute("stuUploadMess", "没有查询到设备信息");
|
||||
} else {
|
||||
request.setAttribute("deviceTypeId", deviceTypeId);
|
||||
request.setAttribute("deviceAddressId", deviceAddressId);
|
||||
}
|
||||
return "/stu/success";
|
||||
return "/stu/upload";
|
||||
}
|
||||
|
||||
@RequestMapping("/stu/upload1.do")
|
||||
public String upload1(
|
||||
@SessionAttribute Stu stu,
|
||||
int deviceId,
|
||||
String address,
|
||||
String faultDesc,
|
||||
String contact,
|
||||
String phone,
|
||||
MultipartFile[] myfile,
|
||||
HttpServletRequest req) {
|
||||
Order order = new Order();
|
||||
order.setDeviceId(deviceId);
|
||||
order.setStudentId(stu.getUserid());
|
||||
order.setAddress(address);
|
||||
order.setFaultDesc(faultDesc);
|
||||
order.setContact(contact);
|
||||
order.setPhone(phone);
|
||||
order.setOrderStatus(OrderStatus.UNASSIGNED.value);
|
||||
|
||||
String path2 = "/upload/" + stu.getUserNo() + "/";
|
||||
String path = req.getServletContext().getRealPath(path2);
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
ArrayList<String> filepaths = new ArrayList<>();
|
||||
if (myfile != null) {
|
||||
for (int i = 0; i < myfile.length; i++) {
|
||||
String filepath = saveFile(myfile[i], path, path2, time + "", i);
|
||||
if (filepath.equals("图片格式不正确")) {
|
||||
req.setAttribute("stuUploadMess", "图片格式不正确");
|
||||
return "/stu/upload";
|
||||
} else {
|
||||
filepaths.add(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
order.setFaultImgArray(filepaths);
|
||||
int result = orderDao.add(order);
|
||||
if (result > 0) {
|
||||
req.setAttribute("stuUploadMess", "创建维修单成功");
|
||||
} else {
|
||||
req.setAttribute("stuUploadMess", "创建维修单失败");
|
||||
}
|
||||
return "/stu/upload";
|
||||
}
|
||||
|
||||
|
||||
public String saveFile(MultipartFile myfile, String path, String path2, String time, int i) {
|
||||
String filename = myfile.getOriginalFilename();
|
||||
String filePath = path + time + "_" + i;
|
||||
String filePath2 = path2 + time + "_" + i;
|
||||
if (filename != null && (filename.endsWith(".jpg") || filename.endsWith(".JPG"))) {
|
||||
filePath += ".jpg";
|
||||
filePath2 += ".jpg";
|
||||
} else if (filename != null && (filename.endsWith(".png") || filename.endsWith(".PNG"))) {
|
||||
filePath += ".png";
|
||||
filePath2 += ".png";
|
||||
} else {
|
||||
return "图片格式不正确";
|
||||
}
|
||||
try {
|
||||
myfile.transferTo(new File(filePath));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return filePath2;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author xtaod
|
||||
@ -115,6 +116,27 @@ public class Order {
|
||||
this.faultImg = faultImg;
|
||||
}
|
||||
|
||||
public ArrayList<String> getFaultImgArray() {
|
||||
String imgs = getFaultImg();
|
||||
// 使用 , 分割图片地址
|
||||
String[] imgArray = imgs.split(",");
|
||||
ArrayList<String> imgList = new ArrayList<>();
|
||||
for (String img : imgArray) {
|
||||
if (!img.isEmpty()) {
|
||||
imgList.add(img);
|
||||
}
|
||||
}
|
||||
return imgList;
|
||||
}
|
||||
|
||||
public void setFaultImgArray(ArrayList<String> imgList) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String img : imgList) {
|
||||
sb.append(img).append(",");
|
||||
}
|
||||
setFaultImg(sb.toString());
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
25
src/main/webapp/js/upload.js
Normal file
25
src/main/webapp/js/upload.js
Normal file
@ -0,0 +1,25 @@
|
||||
function addFile() {
|
||||
const fileDiv = document.querySelector("#fileDiv");
|
||||
|
||||
const inputDiv = document.createElement("input");
|
||||
inputDiv.setAttribute("class", "form-control form-control-lg");
|
||||
inputDiv.type = "file";
|
||||
inputDiv.name = "myfile";
|
||||
inputDiv.required = true;
|
||||
inputDiv.id = "file" + fileDiv.children.length;
|
||||
|
||||
const br = document.createElement("br");
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.appendChild(inputDiv);
|
||||
div.appendChild(br);
|
||||
|
||||
fileDiv.appendChild(div);
|
||||
}
|
||||
|
||||
function delFile() {
|
||||
const fileDiv = document.querySelector("#fileDiv");
|
||||
if (fileDiv.children.length > 0) {
|
||||
fileDiv.removeChild(fileDiv.lastChild);
|
||||
}
|
||||
}
|
@ -5,74 +5,134 @@
|
||||
<%@ 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="title" value="上传表单"/>
|
||||
<c:set var="title" value="新建报修单"/>
|
||||
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css">
|
||||
|
||||
|
||||
|
||||
<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="${webroot}/js/upload.js"></script>
|
||||
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous"></head>
|
||||
<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">
|
||||
<form action="${webroot}/upload.do" method="post" >
|
||||
<main class="form-signin w-100 m-auto" style="min-width: 600px">
|
||||
<c:if test="${empty requestScope.deviceTypeId}">
|
||||
<form action="${webroot}/stu/upload.do" method="post" >
|
||||
</c:if>
|
||||
<c:if test="${not empty requestScope.deviceTypeId}">
|
||||
<form action="${webroot}/stu/upload1.do" method="post" enctype="multipart/form-data" id="form">
|
||||
</c:if>
|
||||
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
|
||||
<h1 class="h3 mb-3 fw-normal">上传维修单</h1>
|
||||
<h1 class="h3 mb-3 fw-normal">${title}</h1>
|
||||
|
||||
<c:if test="${not empty requestScope.stuUploadMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.stuUploadMess}
|
||||
</div>
|
||||
</c:if>
|
||||
<div class="form-floating">
|
||||
|
||||
<select id="deviceId" name="deviceId">
|
||||
|
||||
|
||||
<%-- 使用 JSP 语法获取 application 中的设备数组 --%>
|
||||
<% ArrayList<Device> devices = (ArrayList<Device>) application.getAttribute("device"); %>
|
||||
|
||||
<%-- 循环遍历设备数组,并将每个设备作为下拉框的选项 --%>
|
||||
<% for (Device device : devices) { %>
|
||||
<option value="<%= device.getDeviceName() %>"><%= device.getDeviceName() %></option>
|
||||
<% } %>
|
||||
<c:if test="${empty requestScope.deviceTypeId}">
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">报修类型</span>
|
||||
<select class="form-select" name="deviceTypeId" id="deviceTypeId" required>
|
||||
<c:forEach items="${applicationScope.faults}" var="fault">
|
||||
<option value="${fault.faultId}">${fault.faultName}</option>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" name="contact" id="contact" required>
|
||||
<label for="contact">联系人名称</label>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">报修区域</span>
|
||||
<select class="form-select" name="deviceAddressId" id="deviceAddressId" required>
|
||||
<c:forEach items="${applicationScope.addresses1}" var="address" varStatus="rows">
|
||||
<c:forEach items="${applicationScope.addresses0}" var="address0" varStatus="rows0">
|
||||
<c:if test="${address0.parentId == address.addressId}">
|
||||
<option value="${address0.addressId}">${address.addressName} - ${address0.addressName}</option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" name="phone" id="phone" required>
|
||||
<label for="phone">联系人电话</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" name="address" id="address" required>
|
||||
<label for="address">详细地点</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" name="faultDesc" id="faultDesc" required>
|
||||
<label for="faultDesc">故障描述</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="text" class="form-control" name="faultImg" id="faultImg" required>
|
||||
<label for="faultImg">故障图片</label>
|
||||
</div>
|
||||
</c:if>
|
||||
<c:if test="${not empty requestScope.deviceTypeId}">
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">报修类型</span>
|
||||
<select class="form-select" name="deviceTypeId" id="1" required>
|
||||
<c:forEach items="${applicationScope.faults}" var="fault">
|
||||
<c:if test="${fault.faultId == requestScope.deviceTypeId}">
|
||||
<option value="${fault.faultId}" selected>${fault.faultName}</option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">报修区域</span>
|
||||
<select class="form-select" name="deviceAddressId" id="2" required>
|
||||
<c:forEach items="${applicationScope.addresses0}" var="address0" varStatus="rows0">
|
||||
<c:if test="${address0.addressId == requestScope.deviceAddressId}">
|
||||
<option value="${address0.addressId}" selected>${address.addressName} - ${address0.addressName}</option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">报修设备</span>
|
||||
<select class="form-select" name="deviceId" id="deviceId" required>
|
||||
<c:forEach items="${applicationScope.device}" var="device" varStatus="rows">
|
||||
<c:if test="${device.deviceTypeId == requestScope.deviceTypeId}">
|
||||
<c:if test="${device.deviceAddressId == requestScope.deviceAddressId}">
|
||||
<c:if test="${device.deviceStatus == 0}">
|
||||
<option value="${device.deviceId}">${device.deviceName}</option>
|
||||
</c:if>
|
||||
</c:if>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">详细地点</span>
|
||||
<input type="text" class="form-control" name="address" id="address" value="${requestScope.reginfo.sname}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">问题描述</span>
|
||||
<input type="text" class="form-control" name="faultDesc" id="faultDesc" value="${requestScope.reginfo.sname}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">联系人姓名</span>
|
||||
<input type="text" class="form-control" name="contact" id="contact" value="${requestScope.reginfo.sname}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">联系人电话</span>
|
||||
<input type="text" class="form-control" name="phone" id="phone" value="${requestScope.reginfo.sname}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div id="fileDiv">
|
||||
</div>
|
||||
|
||||
<input type="button" class="btn btn-primary w-100 py-2" onclick="addFile()" value="添加图片">
|
||||
<br/><br/>
|
||||
<input type="button" class="btn btn-primary w-100 py-2" onclick="delFile()" value="删除图片">
|
||||
<br/><br/>
|
||||
</c:if>
|
||||
|
||||
<button class="btn btn-primary w-100 py-2" type="submit" id="submit">提交</button>
|
||||
<br/><br/>
|
||||
@ -81,15 +141,5 @@
|
||||
</main>
|
||||
|
||||
</main>
|
||||
<script src="${webroot}/js/pass.js" type="javascript"></script>
|
||||
<script>
|
||||
const toastLiveExample = document.getElementById('liveToast')
|
||||
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
|
||||
toastBootstrap.show()
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user