修改画面更新

master
pan 5 years ago
parent 438bf4cf48
commit 41adbc4071
  1. 110
      db/db2.sql
  2. 1
      src/main/java/com/example/demo/Constants.java
  3. 8
      src/main/java/com/example/demo/controller/WebController.java
  4. 1
      src/main/java/com/example/demo/model/CaiDan.java
  5. 1
      src/main/java/com/example/demo/model/Diancan.java
  6. 12
      src/main/java/com/example/demo/model/DiancanDetail.java
  7. 4
      src/main/java/com/example/demo/repository/DiancanDetailRespository.java
  8. 2
      src/main/resources/application.yaml
  9. 93
      src/main/resources/templates/order.html
  10. 5
      src/test/java/com/example/demo/DemoApplicationTests.java

@ -0,0 +1,110 @@
-- MySQL dump 10.13 Distrib 8.0.20, for Linux (x86_64)
--
-- Host: localhost Database: dmmdb
-- ------------------------------------------------------
-- Server version 8.0.20
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `diancan_detail`
--
DROP TABLE IF EXISTS `diancan_detail`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `diancan_detail` (
`id` int NOT NULL AUTO_INCREMENT,
`zhuohao` char(11) NOT NULL,
`menu_id` char(3) NOT NULL,
`sum` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `diancan_detail`
--
LOCK TABLES `diancan_detail` WRITE;
/*!40000 ALTER TABLE `diancan_detail` DISABLE KEYS */;
INSERT INTO `diancan_detail` VALUES (7,'12','001',''),(8,'12','009','10');
/*!40000 ALTER TABLE `diancan_detail` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `m_menu`
--
DROP TABLE IF EXISTS `m_menu`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `m_menu` (
`ID` char(3) NOT NULL,
`FENLEI` varchar(20) NOT NULL,
`PINMU` varchar(20) NOT NULL,
`CAILIAO` varchar(20) NOT NULL,
`JIAGE` int NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `m_menu`
--
LOCK TABLES `m_menu` WRITE;
/*!40000 ALTER TABLE `m_menu` DISABLE KEYS */;
INSERT INTO `m_menu` VALUES ('001','正菜','肉类','牛肉',50),('002','正菜','肉类','猪肉',30),('003','正菜','肉类','鸡肉',20),('004','正菜','蔬菜','白菜',10),('005','正菜','蔬菜','黄瓜',10),('006','正菜','海鲜','大虾',40),('007','正菜','海鲜','黄鱼',40),('008','主食','米饭','白饭',3),('009','主食','米饭','炒饭',10),('010','主食','面条','凉拌',12),('011','主食','面条','打卤',15),('012','主食','水饺','素馅',15),('013','主食','水饺','肉馅',20),('014','酒水','白酒','茅台',1000),('015','酒水','白酒','郎酒',500),('016','酒水','啤酒','雪花',5),('017','酒水','啤酒','哈啤',6),('018','酒水','饮料','可乐',3),('019','酒水','饮料','雪碧',3);
/*!40000 ALTER TABLE `m_menu` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tbl_diancan`
--
DROP TABLE IF EXISTS `tbl_diancan`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_diancan` (
`ZHUOHAO` char(11) NOT NULL,
`XINGMING` varchar(15) NOT NULL,
`YUDING` tinyint(1) NOT NULL,
`BIRTHDAY` datetime DEFAULT NULL,
`RENSHU` int DEFAULT NULL,
`TEL` varchar(20) DEFAULT NULL,
`JINE` int DEFAULT NULL,
`BEIZHU` varchar(200) DEFAULT NULL,
PRIMARY KEY (`ZHUOHAO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `tbl_diancan`
--
LOCK TABLES `tbl_diancan` WRITE;
/*!40000 ALTER TABLE `tbl_diancan` DISABLE KEYS */;
INSERT INTO `tbl_diancan` VALUES ('12','12',1,NULL,1,'15920722180',150,'');
/*!40000 ALTER TABLE `tbl_diancan` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2020-07-15 7:38:54

@ -5,4 +5,5 @@ public class Constants {
public static final String LIST = "list"; public static final String LIST = "list";
public static final String QUERY = "query"; public static final String QUERY = "query";
public static final String FENLEI = "fenlei"; public static final String FENLEI = "fenlei";
public static final String QUERYDETAIL = "querydetail";
} }

@ -72,6 +72,9 @@ public class WebController {
public String getOrder(Model model){ public String getOrder(Model model){
model.addAttribute(Constants.SPAN_NAME,"点餐画面"); model.addAttribute(Constants.SPAN_NAME,"点餐画面");
model.addAttribute(Constants.FENLEI,menuRepository.getFenlei()); model.addAttribute(Constants.FENLEI,menuRepository.getFenlei());
Diancan diancan= new Diancan();
diancan.setRenshu(1);
model.addAttribute(Constants.QUERY,diancan);
return "order"; return "order";
} }
@ -103,6 +106,11 @@ public class WebController {
@GetMapping("/order/{id}") @GetMapping("/order/{id}")
public String getEditOrder(Model model,@PathVariable String id){ public String getEditOrder(Model model,@PathVariable String id){
model.addAttribute(Constants.SPAN_NAME,"修改画面"); model.addAttribute(Constants.SPAN_NAME,"修改画面");
Diancan diancan=diancanRespository.getOne(id);
model.addAttribute(Constants.QUERY,diancan);
List<DiancanDetail> diancanDetails=diancanDetailRespository.findByZhuohao(diancan.getZhuohao());
model.addAttribute(Constants.QUERYDETAIL,diancanDetails);
model.addAttribute(Constants.FENLEI,menuRepository.getFenlei());
return "order"; return "order";
} }

@ -1,6 +1,7 @@
package com.example.demo.model; package com.example.demo.model;
public class CaiDan { public class CaiDan {
private String cailiao; private String cailiao;
private String sum; private String sum;

@ -9,6 +9,7 @@ import java.util.Date;
public class Diancan { public class Diancan {
@Id @Id
@Column(name = "zhuohao")
private String zhuohao; private String zhuohao;
@Column(nullable = false) @Column(nullable = false)

@ -47,4 +47,16 @@ public class DiancanDetail {
public void setZhuohao(String zhuohao) { public void setZhuohao(String zhuohao) {
this.zhuohao = zhuohao; this.zhuohao = zhuohao;
} }
@OneToOne
@JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false)
private Menu menu;
public Menu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
} }

@ -3,6 +3,10 @@ package com.example.demo.repository;
import com.example.demo.model.DiancanDetail; import com.example.demo.model.DiancanDetail;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface DiancanDetailRespository extends JpaRepository<DiancanDetail,Long> { public interface DiancanDetailRespository extends JpaRepository<DiancanDetail,Long> {
int deleteByZhuohao(String zhuohao); int deleteByZhuohao(String zhuohao);
List<DiancanDetail> findByZhuohao(String zhuohao);
} }

@ -4,7 +4,7 @@ spring:
cache: false cache: false
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/dmmdb url: jdbc:mysql://localhost:33060/dmmdb
username: sukura username: sukura
password: 123456 password: 123456
jpa: jpa:

@ -17,9 +17,33 @@
</style> </style>
<script th:inline="javascript"> <script th:inline="javascript">
onload = function () { onload = function () {
let item = document.getElementsByClassName('fff') let detailList=[[${querydetail}]]
for (let i in item) { if(detailList){
item[i].innerHTML += getSelect() console.info(detailList)
for(let index in detailList) {
let fff
if(index==="0") {
fff = document.querySelector('div[class="input-group mt-3 order-frame fff"]')
fff.innerHTML += getSelect()
}else{
plus()
fff = document.querySelector('div[class="input-group mt-3 order-frame fff"]:last-child')
}
let fenlei = fff.querySelector('select[name$=fenlei]')
fenlei.value = detailList[index].menu.fenlei
let pinmu = fenlei.parentElement.querySelector('select[name$=pinmu]')
let cailiao = fenlei.parentElement.querySelector('select[name$=cailiao]')
let zuofa = fenlei.parentElement.querySelector('input[name$=sum]')
changeFenLei(fenlei, pinmu, cailiao, detailList[index])
zuofa.value = detailList[index].sum
changePinmu(fenlei, pinmu, cailiao, detailList[index])
jine.value = [[${query.jine}]]
}
}else {
let item = document.getElementsByClassName('fff')
for (let i in item) {
item[i].innerHTML += getSelect()
}
} }
} }
@ -31,26 +55,26 @@
} }
let count=document.querySelectorAll('select[name$=cailiao]').length let count=document.querySelectorAll('select[name$=cailiao]').length
return `<select class="custom-select" name="diancans[${count}].fenlei" onchange="changeFenLei(this,this.parentElement.querySelector('select[name$=pinmu]'),this.parentElement.querySelector('select[name$=cailiao]'))"> return `<select class="custom-select" name="diancans[${count}].fenlei" onchange="changeFenLei(this,this.parentElement.querySelector('select[name$=pinmu]'),this.parentElement.querySelector('select[name$=cailiao]'))">
<option selected>请选择分类</option> <option value="">请选择分类</option>
${fenleistr} ${fenleistr}
</select> </select>
<select class="custom-select" name="diancans[${count}].pinmu" onchange="changePinmu(this.parentElement.querySelector('select[name$=fenlei]'),this,this.parentElement.querySelector('select[name$=cailiao]'))"> <select class="custom-select" name="diancans[${count}].pinmu" onchange="changePinmu(this.parentElement.querySelector('select[name$=fenlei]'),this,this.parentElement.querySelector('select[name$=cailiao]'))">
<option selected>请选择品目</option> <option value="">请选择品目</option>
</select> </select>
<select class="custom-select" name="diancans[${count}].cailiao" required oninvalid="setCustomValidity('请选择材料')" onchange="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))"> <select class="custom-select" name="diancans[${count}].cailiao" required oninvalid="setCustomValidity('请选择材料')" onchange="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))">
<option selected value="">请选择材料</option> <option value="">请选择材料</option>
</select> </select>
<input type="text" class="form-control" name="diancans[${count}].sum" placeholder="做法或数量" onchange="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))" oninput="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))">` <input type="text" class="form-control" name="diancans[${count}].sum" placeholder="做法或数量" onchange="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))" oninput="changeCailiao(document.querySelectorAll('select[name$=cailiao]'))">`
} }
function plus(s) { function plus() {
let div = document.createElement('div') let div = document.createElement('div')
div.classList.add('input-group', 'mt-3', 'order-frame') div.classList.add('input-group', 'mt-3', 'order-frame','fff')
div.innerHTML = `<div class="col-3 text-right mt-auto mb-auto"> div.innerHTML = `<div class="col-3 text-right mt-auto mb-auto">
<img src="/icon/plus.svg" class="icon action" onclick="plus(this)"/> <img src="/icon/plus.svg" class="icon action" onclick="plus()"/>
<img src="/icon/minus.svg" class="icon action" onclick="minus(this)"/> <img src="/icon/minus.svg" class="icon action" onclick="minus(this)"/>
</div> </div>
${getSelect()} ${getSelect()}
@ -70,12 +94,16 @@
changeCailiao(document.querySelectorAll('select[name$=cailiao]')) changeCailiao(document.querySelectorAll('select[name$=cailiao]'))
} }
function changeFenLei(fenlei, pinmu, cailiao) { function changeFenLei(fenlei, pinmu, cailiao,item) {
pinmu.innerHTML = '<option selected>请选择品目</option>' pinmu.innerHTML = '<option value="">请选择品目</option>'
cailiao.innerHTML = '<option selected>请选择材料</option>' cailiao.innerHTML = '<option value="">请选择材料</option>'
fetch(new Request('/api/getPinMu?fenlei=' + fenlei.value)).then(res => res.json()).then(res => { fetch(new Request('/api/getPinMu?fenlei=' + fenlei.value)).then(res => res.json()).then(res => {
for (let index in res) { for (let index in res) {
pinmu.innerHTML += `<option>${res[index]}</option>` if(item&&res[index]===item.menu.pinmu) {
pinmu.innerHTML += `<option selected value="${res[index]}">${res[index]}</option>`
} else {
pinmu.innerHTML += `<option value="${res[index]}">${res[index]}</option>`
}
} }
}) })
let sum=fenlei.parentElement.querySelector('input[name$=sum]') let sum=fenlei.parentElement.querySelector('input[name$=sum]')
@ -89,11 +117,16 @@
changeCailiao(document.querySelectorAll('select[name$=cailiao]')) changeCailiao(document.querySelectorAll('select[name$=cailiao]'))
} }
function changePinmu(fenlei, pinmu, cailiao) { function changePinmu(fenlei, pinmu, cailiao,item) {
cailiao.innerHTML = '<option selected>请选择材料</option>' cailiao.innerHTML = '<option value="">请选择材料</option>'
fetch(new Request(`/api/getMenu?fenlei=${fenlei.value}&pinmu=${pinmu.value}`)).then(res => res.json()).then(res => { let pinmuval=item?item.menu.pinmu:pinmu.value
fetch(new Request(`/api/getMenu?fenlei=${fenlei.value}&pinmu=${pinmuval}`)).then(res => res.json()).then(res => {
for (let index in res) { for (let index in res) {
cailiao.innerHTML += `<option value="${res[index].id}" jine="${res[index].jiage}">${res[index].cailiao}</option>` if(item&&res[index].id===item.menu.id) {
cailiao.innerHTML += `<option selected value="${res[index].id}" jine="${res[index].jiage}">${res[index].cailiao}</option>`
}else{
cailiao.innerHTML += `<option value="${res[index].id}" jine="${res[index].jiage}">${res[index].cailiao}</option>`
}
} }
}) })
@ -151,18 +184,18 @@
<div class="container"> <div class="container">
<div class="frame"> <div class="frame">
<span th:text="${span_name}"></span> <span th:text="${span_name}"></span>
<form method="post" action="/api/order"> <form method="post" action="/api/order" th:object="${query}">
<div class="input-group mt-3"> <div class="input-group mt-3">
<div class="input-group-prepend col-3 pr-2 justify-content-end"> <div class="input-group-prepend col-3 pr-2 justify-content-end">
<span class="input-group-text">桌号</span> <span class="input-group-text">桌号</span>
</div> </div>
<input type="text" name="zhuohao" class="form-control col-4" required oninvalid="setCustomValidity('桌号不能为空')" oninput="setCustomValidity('');hasYuding(this)"> <input type="text" th:field="*{zhuohao}" th:readonly="*{zhuohao ne null}" class="form-control col-4" required oninvalid="setCustomValidity('桌号不能为空')" oninput="setCustomValidity('');hasYuding(this)">
<div class="invalid-feedback mt-3 mb-3 text-center font-weight-bold">桌号已预定</div> <div class="invalid-feedback mt-3 mb-3 text-center font-weight-bold">桌号已预定</div>
<div class="input-group-prepend col-3 pr-2 justify-content-end"> <div class="input-group-prepend col-3 pr-2 justify-content-end">
<span class="input-group-text">客人姓名</span> <span class="input-group-text">客人姓名</span>
</div> </div>
<input type="text" name="xingming" class="form-control col-4" oninvalid="setCustomValidity('姓名不能为空')" oninput="setCustomValidity('');" required maxlength="15"> <input type="text" th:field="*{xingming}" class="form-control col-4" oninvalid="setCustomValidity('姓名不能为空')" oninput="setCustomValidity('');" required maxlength="15">
</div> </div>
<div class="input-group mt-3"> <div class="input-group mt-3">
@ -170,16 +203,16 @@
<span class="input-group-text">用餐时间</span> <span class="input-group-text">用餐时间</span>
</div> </div>
<div class="custom-control custom-radio custom-control-inline mt-auto mb-auto"> <div class="custom-control custom-radio custom-control-inline mt-auto mb-auto">
<input type="radio" id="customRadioInline1" name="birthday" checked <input type="radio" id="customRadioInline1" name="birthday"
class="custom-control-input" value="1" onclick="birthdayValid(this.parentElement.parentElement.querySelector('input[name=shijian]'))"> class="custom-control-input" value="1" th:checked="*{birthday eq null}" onclick="birthdayValid(this.parentElement.parentElement.querySelector('input[name=shijian]'))">
<label class="custom-control-label" for="customRadioInline1">及时单</label> <label class="custom-control-label" for="customRadioInline1">及时单</label>
</div> </div>
<div class="custom-control custom-radio custom-control-inline mt-auto mb-auto"> <div class="custom-control custom-radio custom-control-inline mt-auto mb-auto">
<input type="radio" id="customRadioInline2" value="2" name="birthday" class="custom-control-input" onclick="changeBirthday(this.parentElement.parentElement.querySelector('input[name=shijian]'))"> <input type="radio" id="customRadioInline2" value="2" th:checked="*{birthday ne null}" name="birthday" class="custom-control-input" onclick="changeBirthday(this.parentElement.parentElement.querySelector('input[name=shijian]'))">
<label class="custom-control-label" for="customRadioInline2">指定</label> <label class="custom-control-label" for="customRadioInline2">指定</label>
</div> </div>
<input type="text" name="shijian" oninput="setCustomValidity('')" oninvalid="setCustomValidity('时间不能为空')" class="form-control col-4"> <input type="text" th:value="${#dates.format(query.birthday, 'yyyyMMdd HHmm')}" name="shijian" oninput="setCustomValidity('')" oninvalid="setCustomValidity('时间不能为空')" class="form-control col-4">
</div> </div>
<div class="input-group mt-3"> <div class="input-group mt-3">
@ -187,7 +220,7 @@
<span class="input-group-text">用餐人数</span> <span class="input-group-text">用餐人数</span>
</div> </div>
<input type="number" value="1" name="renshu" class="form-control col-4"> <input type="number" th:field="*{renshu}" class="form-control col-4">
</div> </div>
<div class="input-group mt-3"> <div class="input-group mt-3">
@ -195,7 +228,7 @@
<span class="input-group-text">联系方式(手机)</span> <span class="input-group-text">联系方式(手机)</span>
</div> </div>
<input type="text" name="tel" oninput="checkMobie()" class="form-control col-4"> <input type="text" th:field="*{tel}" oninput="checkMobie()" class="form-control col-4">
</div> </div>
<div class="input-group mt-3 order-frame fff"> <div class="input-group mt-3 order-frame fff">
@ -207,12 +240,12 @@
<div id="list"> <div id="list">
<div class="input-group mt-3 order-frame d-none" id="add"> <div class="input-group mt-3 order-frame d-none" id="add">
<div class="col-3 text-right mt-auto mb-auto"> <div class="col-3 text-right mt-auto mb-auto">
<img src="/icon/plus.svg" class="icon action" onclick="plus(this)"/> <img src="/icon/plus.svg" class="icon action" onclick="plus()"/>
</div> </div>
</div> </div>
<div class="input-group mt-3 order-frame fff"> <div class="input-group mt-3 order-frame fff" th:if="${querydetail} eq null">
<div class="col-3 text-right mt-auto mb-auto"> <div class="col-3 text-right mt-auto mb-auto">
<img src="/icon/plus.svg" class="icon action" onclick="plus(this)"/> <img src="/icon/plus.svg" class="icon action" onclick="plus()"/>
<img src="/icon/minus.svg" class="icon action" onclick="minus(this)"/> <img src="/icon/minus.svg" class="icon action" onclick="minus(this)"/>
</div> </div>
</div> </div>
@ -229,7 +262,7 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<span class="input-group-text">备注</span> <span class="input-group-text">备注</span>
</div> </div>
<textarea class="form-control" name="beizhu" aria-label="With textarea"></textarea> <textarea class="form-control" th:field="*{beizhu}" aria-label="With textarea"></textarea>
</div> </div>
<div class="mt-3 text-right"> <div class="mt-3 text-right">
<button class="btn btn-secondary col-3">提交</button> <button class="btn btn-secondary col-3">提交</button>

@ -1,5 +1,6 @@
package com.example.demo; package com.example.demo;
import com.example.demo.model.Diancan;
import com.example.demo.repository.DiancanRespository; import com.example.demo.repository.DiancanRespository;
import com.example.demo.repository.MenuRepository; import com.example.demo.repository.MenuRepository;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -33,4 +34,8 @@ class DemoApplicationTests {
int a=diancanRespository.countByZhuohao("2"); int a=diancanRespository.countByZhuohao("2");
} }
@Test
void testGet(){
Diancan diancan=diancanRespository.getOne("12");
}
} }

Loading…
Cancel
Save