点餐画面后台接口更新

master
pan 4 years ago
parent 836f6b3bf7
commit 438bf4cf48
  1. 36
      src/main/java/com/example/demo/controller/WebController.java
  2. 31
      src/main/java/com/example/demo/model/Diancan.java
  3. 50
      src/main/java/com/example/demo/model/DiancanDetail.java
  4. 8
      src/main/java/com/example/demo/repository/DiancanDetailRespository.java
  5. 20
      src/main/resources/templates/index.html
  6. 9
      src/main/resources/templates/order.html

@ -1,9 +1,8 @@
package com.example.demo.controller;
import com.example.demo.Constants;
import com.example.demo.model.Diancan;
import com.example.demo.model.DiancanForm;
import com.example.demo.model.Menu;
import com.example.demo.model.*;
import com.example.demo.repository.DiancanDetailRespository;
import com.example.demo.repository.DiancanRespository;
import com.example.demo.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,8 +13,12 @@ import org.springframework.web.bind.annotation.*;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@ -28,6 +31,9 @@ public class WebController {
@Autowired
private DiancanRespository diancanRespository;
@Autowired
private DiancanDetailRespository diancanDetailRespository;
@RequestMapping("/index")
public String index(Model model,Diancan diancan){
List<Diancan> diancans= diancanRespository.findAll((root,query,cb)->{
@ -55,8 +61,10 @@ public class WebController {
}
@RequestMapping("/order/del/{id}")
@Transactional
public void del(Model model, @PathVariable String id, HttpServletResponse response) throws IOException {
diancanRespository.deleteById(id);
diancanDetailRespository.deleteByZhuohao(id);
response.sendRedirect("/api/index");
}
@ -68,7 +76,27 @@ public class WebController {
}
@PostMapping("/order")
public void postOrder(Model model, HttpServletResponse response, DiancanForm diancanForm) throws IOException {
public void postOrder(Model model, HttpServletResponse response, DiancanForm diancanForm) throws IOException, ParseException {
Diancan diancan=new Diancan();
diancan.setZhuohao(diancanForm.getZhuohao());
diancan.setXingming(diancanForm.getXingming());
diancan.setYuding(true);
if("2".equals(diancanForm.getBirthday())&&!StringUtils.isEmpty(diancanForm.getShijian())) {
Date date= new SimpleDateFormat("yyyyMMdd HHmm").parse(diancanForm.getShijian());
diancan.setBirthday(date);
}
diancan.setRenshu(diancanForm.getRenshu());
diancan.setTel(diancanForm.getTel());
diancan.setJine(diancanForm.getJine());
diancan.setBeizhu(diancanForm.getBeizhu());
diancanRespository.save(diancan);
for (CaiDan caiDan:diancanForm.getDiancans()){
DiancanDetail diancanDetail=new DiancanDetail();
diancanDetail.setZhuohao(diancan.getZhuohao());
diancanDetail.setSum(caiDan.getSum());
diancanDetail.setMenuId(caiDan.getCailiao());
diancanDetailRespository.save(diancanDetail);
}
response.sendRedirect("/api/index");
}

@ -17,19 +17,12 @@ public class Diancan {
@Column(nullable = false)
private Boolean yuding;
@Column(nullable = false)
private Date birthday;
private Integer renshu;
private String tel;
private String caipin;
private String zhushi;
private String jiushui;
private Integer jine;
private String beizhu;
@ -82,30 +75,6 @@ public class Diancan {
this.tel = tel;
}
public String getCaipin() {
return caipin;
}
public void setCaipin(String caipin) {
this.caipin = caipin;
}
public String getZhushi() {
return zhushi;
}
public void setZhushi(String zhushi) {
this.zhushi = zhushi;
}
public String getJiushui() {
return jiushui;
}
public void setJiushui(String jiushui) {
this.jiushui = jiushui;
}
public Integer getJine() {
return jine;
}

@ -0,0 +1,50 @@
package com.example.demo.model;
import javax.persistence.*;
@Entity(name = "diancan_detail")
public class DiancanDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String zhuohao;
@Column(name = "menu_id")
private String menuId;
private String sum;
public String getMenuId() {
return menuId;
}
public void setMenuId(String menuId) {
this.menuId = menuId;
}
public String getSum() {
return sum;
}
public void setSum(String sum) {
this.sum = sum;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getZhuohao() {
return zhuohao;
}
public void setZhuohao(String zhuohao) {
this.zhuohao = zhuohao;
}
}

@ -0,0 +1,8 @@
package com.example.demo.repository;
import com.example.demo.model.DiancanDetail;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DiancanDetailRespository extends JpaRepository<DiancanDetail,Long> {
int deleteByZhuohao(String zhuohao);
}

@ -77,16 +77,16 @@
</tr>
</thead>
<tbody th:switch="${query.yuding}">
<tr th:case="true" th:each="item:${list}">
<th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}">${item.zhuohao}</a></th>
<td class="p-3">${item.xingming}</td>
<tbody>
<tr th:if="${query.yuding} eq true" th:each="item : ${list}">
<th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}" th:text="${item.zhuohao}"></a></th>
<td class="p-3" th:text="${item.xingming}"></td>
<td class="p-3">
<img th:src="@{${item.yuding?'/icon/radioactive.svg':'/icon/radioactive.svg'}}" class="icon"/>
</td>
<td class="p-3">${item.tel}</td>
<td class="p-3">${item.birthday}</td>
<td class="p-3">${item.renshu}</td>
<td class="p-3" th:text="${item.tel}"></td>
<td class="p-3" th:text="${#dates.format(item.birthday, 'yyyyMMdd HHmm')}"></td>
<td class="p-3" th:text="${item.renshu}"></td>
<td>
<a th:href="@{'/api/order/'+${item.zhuohao}}" class="btn btn-secondary">修改</a>
</td>
@ -94,9 +94,9 @@
<a th:href="@{'/api/order/del/'+${item.zhuohao}}" class="btn btn-secondary">删除</a>
</td>
</tr>
<tr th:case="false" th:each="item:${list}">
<th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}">${item.zhuohao}</a></th>
<td class="p-3">${item.renshu}</td>
<tr th:if="${query.yuding} eq false" th:each="item:${list}">
<th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}" th:text="${item.zhuohao}"></a></th>
<td class="p-3" th:text="${item.renshu}"></td>
<td>
<a href="/api/order" class="btn btn-secondary">点餐</a>
</td>

@ -43,7 +43,7 @@
<option selected value="">请选择材料</option>
</select>
<input type="text" class="form-control" name="diancans[${count}].sum" placeholder="做法或数量" onchange="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) {
@ -127,8 +127,9 @@
function hasYuding(zhuohao) {
fetch(new Request(`/api/hasYuding?zhuohao=${zhuohao.value}`)).then(res=>res.json()).then(res=>{
if(res){
alert(`桌号${zhuohao.value}已预定!`)
zhuohao.value=''
zhuohao.classList.add("is-invalid")
}else{
zhuohao.classList.remove("is-invalid")
}
})
}
@ -156,6 +157,8 @@
<span class="input-group-text">桌号</span>
</div>
<input type="text" name="zhuohao" 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="input-group-prepend col-3 pr-2 justify-content-end">
<span class="input-group-text">客人姓名</span>
</div>

Loading…
Cancel
Save