修改画面后台接口更新

master
pan 4 years ago
parent 41adbc4071
commit 3bc468d2b3
  1. 1
      src/main/java/com/example/demo/Constants.java
  2. 28
      src/main/java/com/example/demo/controller/WebController.java
  3. 2
      src/main/resources/templates/order.html

@ -6,4 +6,5 @@ public class Constants {
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"; public static final String QUERYDETAIL = "querydetail";
public static final String ACTION_NAME = "action_name";
} }

@ -71,14 +71,17 @@ public class WebController {
@GetMapping("/order") @GetMapping("/order")
public String getOrder(Model model){ public String getOrder(Model model){
model.addAttribute(Constants.SPAN_NAME,"点餐画面"); model.addAttribute(Constants.SPAN_NAME,"点餐画面");
model.addAttribute(Constants.ACTION_NAME,"/api/order");
model.addAttribute(Constants.FENLEI,menuRepository.getFenlei()); model.addAttribute(Constants.FENLEI,menuRepository.getFenlei());
Diancan diancan= new Diancan(); Diancan diancan= new Diancan();
diancan.setRenshu(1); diancan.setRenshu(1);
model.addAttribute(Constants.QUERY,diancan); model.addAttribute(Constants.QUERY,diancan);
return "order"; return "order";
} }
@PostMapping("/order") @PostMapping("/order")
@Transactional
public void postOrder(Model model, HttpServletResponse response, DiancanForm diancanForm) throws IOException, ParseException { public void postOrder(Model model, HttpServletResponse response, DiancanForm diancanForm) throws IOException, ParseException {
Diancan diancan=new Diancan(); Diancan diancan=new Diancan();
diancan.setZhuohao(diancanForm.getZhuohao()); diancan.setZhuohao(diancanForm.getZhuohao());
@ -106,6 +109,7 @@ 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,"修改画面");
model.addAttribute(Constants.ACTION_NAME,"/api/order/"+id);
Diancan diancan=diancanRespository.getOne(id); Diancan diancan=diancanRespository.getOne(id);
model.addAttribute(Constants.QUERY,diancan); model.addAttribute(Constants.QUERY,diancan);
List<DiancanDetail> diancanDetails=diancanDetailRespository.findByZhuohao(diancan.getZhuohao()); List<DiancanDetail> diancanDetails=diancanDetailRespository.findByZhuohao(diancan.getZhuohao());
@ -115,7 +119,29 @@ public class WebController {
} }
@PostMapping("/order/{id}") @PostMapping("/order/{id}")
public void postEditOrder(Model model,@PathVariable String id,HttpServletResponse response) throws IOException { @Transactional
public void postEditOrder(Model model,@PathVariable String id,HttpServletResponse response, DiancanForm diancanForm) throws IOException, ParseException {
Diancan diancan=diancanRespository.getOne(diancanForm.getZhuohao());
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);
diancanDetailRespository.deleteByZhuohao(diancan.getZhuohao());
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");
} }

@ -184,7 +184,7 @@
<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" th:object="${query}"> <form method="post" th:action="${action_name}" 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>

Loading…
Cancel
Save