点餐画面后台接口更新

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; package com.example.demo.controller;
import com.example.demo.Constants; import com.example.demo.Constants;
import com.example.demo.model.Diancan; import com.example.demo.model.*;
import com.example.demo.model.DiancanForm; import com.example.demo.repository.DiancanDetailRespository;
import com.example.demo.model.Menu;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -14,8 +13,12 @@ import org.springframework.web.bind.annotation.*;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@Controller @Controller
@ -28,6 +31,9 @@ public class WebController {
@Autowired @Autowired
private DiancanRespository diancanRespository; private DiancanRespository diancanRespository;
@Autowired
private DiancanDetailRespository diancanDetailRespository;
@RequestMapping("/index") @RequestMapping("/index")
public String index(Model model,Diancan diancan){ public String index(Model model,Diancan diancan){
List<Diancan> diancans= diancanRespository.findAll((root,query,cb)->{ List<Diancan> diancans= diancanRespository.findAll((root,query,cb)->{
@ -55,8 +61,10 @@ public class WebController {
} }
@RequestMapping("/order/del/{id}") @RequestMapping("/order/del/{id}")
@Transactional
public void del(Model model, @PathVariable String id, HttpServletResponse response) throws IOException { public void del(Model model, @PathVariable String id, HttpServletResponse response) throws IOException {
diancanRespository.deleteById(id); diancanRespository.deleteById(id);
diancanDetailRespository.deleteByZhuohao(id);
response.sendRedirect("/api/index"); response.sendRedirect("/api/index");
} }
@ -68,7 +76,27 @@ public class WebController {
} }
@PostMapping("/order") @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"); response.sendRedirect("/api/index");
} }

@ -17,19 +17,12 @@ public class Diancan {
@Column(nullable = false) @Column(nullable = false)
private Boolean yuding; private Boolean yuding;
@Column(nullable = false)
private Date birthday; private Date birthday;
private Integer renshu; private Integer renshu;
private String tel; private String tel;
private String caipin;
private String zhushi;
private String jiushui;
private Integer jine; private Integer jine;
private String beizhu; private String beizhu;
@ -82,30 +75,6 @@ public class Diancan {
this.tel = tel; 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() { public Integer getJine() {
return jine; 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> </tr>
</thead> </thead>
<tbody th:switch="${query.yuding}"> <tbody>
<tr th:case="true" th:each="item:${list}"> <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}}">${item.zhuohao}</a></th> <th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}" th:text="${item.zhuohao}"></a></th>
<td class="p-3">${item.xingming}</td> <td class="p-3" th:text="${item.xingming}"></td>
<td class="p-3"> <td class="p-3">
<img th:src="@{${item.yuding?'/icon/radioactive.svg':'/icon/radioactive.svg'}}" class="icon"/> <img th:src="@{${item.yuding?'/icon/radioactive.svg':'/icon/radioactive.svg'}}" class="icon"/>
</td> </td>
<td class="p-3">${item.tel}</td> <td class="p-3" th:text="${item.tel}"></td>
<td class="p-3">${item.birthday}</td> <td class="p-3" th:text="${#dates.format(item.birthday, 'yyyyMMdd HHmm')}"></td>
<td class="p-3">${item.renshu}</td> <td class="p-3" th:text="${item.renshu}"></td>
<td> <td>
<a th:href="@{'/api/order/'+${item.zhuohao}}" class="btn btn-secondary">修改</a> <a th:href="@{'/api/order/'+${item.zhuohao}}" class="btn btn-secondary">修改</a>
</td> </td>
@ -94,9 +94,9 @@
<a th:href="@{'/api/order/del/'+${item.zhuohao}}" class="btn btn-secondary">删除</a> <a th:href="@{'/api/order/del/'+${item.zhuohao}}" class="btn btn-secondary">删除</a>
</td> </td>
</tr> </tr>
<tr th:case="false" th:each="item:${list}"> <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}}">${item.zhuohao}</a></th> <th scope="row" class="p-3"><a th:href="@{'/api/order/detail/'+${item.zhuohao}}" th:text="${item.zhuohao}"></a></th>
<td class="p-3">${item.renshu}</td> <td class="p-3" th:text="${item.renshu}"></td>
<td> <td>
<a href="/api/order" class="btn btn-secondary">点餐</a> <a href="/api/order" class="btn btn-secondary">点餐</a>
</td> </td>

@ -43,7 +43,7 @@
<option selected value="">请选择材料</option> <option selected value="">请选择材料</option>
</select> </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) { function plus(s) {
@ -127,8 +127,9 @@
function hasYuding(zhuohao) { function hasYuding(zhuohao) {
fetch(new Request(`/api/hasYuding?zhuohao=${zhuohao.value}`)).then(res=>res.json()).then(res=>{ fetch(new Request(`/api/hasYuding?zhuohao=${zhuohao.value}`)).then(res=>res.json()).then(res=>{
if(res){ if(res){
alert(`桌号${zhuohao.value}已预定!`) zhuohao.classList.add("is-invalid")
zhuohao.value='' }else{
zhuohao.classList.remove("is-invalid")
} }
}) })
} }
@ -156,6 +157,8 @@
<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" 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"> <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>

Loading…
Cancel
Save