|  |  | 
 |  |  | import com.matrix.system.common.tools.ResponseHeadUtil; | 
 |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
 |  |  | import com.matrix.system.hive.bean.AchieveNew; | 
 |  |  | import com.matrix.system.hive.bean.SysOrder; | 
 |  |  | import com.matrix.system.hive.bean.SysOrderItem; | 
 |  |  | import com.matrix.system.hive.service.AchieveNewService; | 
 |  |  | import com.matrix.system.hive.service.SysOrderItemService; | 
 |  |  | import com.matrix.system.hive.service.SysOrderService; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Controller; | 
 |  |  | import org.springframework.ui.ModelMap; | 
 |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
 |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
 |  |  | import org.springframework.web.bind.annotation.ResponseBody; | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Resource | 
 |  |  |     private AchieveNewService achieveNewService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SysOrderService sysOrderService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SysOrderItemService sysOrderItemService; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 门店每日单据明细表 | 
 |  |  | 
 |  |  |         com.matrix.core.tools.excl.ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/del") | 
 |  |  |     @ResponseBody | 
 |  |  |     public AjaxResult del(Long id) { | 
 |  |  |         int i = achieveNewService.removeById(id); | 
 |  |  |         if (i > 0) { | 
 |  |  |             return AjaxResult.buildSuccessInstance("删除成功"); | 
 |  |  |         } | 
 |  |  |         return AjaxResult.buildFailInstance("删除失败"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/add") | 
 |  |  |     @ResponseBody | 
 |  |  |     public AjaxResult add(@RequestBody List<AchieveNew> list) { | 
 |  |  |         SysOrder order = sysOrderService.findById(list.get(0).getOrderId()); | 
 |  |  |         List<SysOrderItem> orderItems = sysOrderItemService.findByOrderId(order.getId()); | 
 |  |  |         orderItems.forEach(item -> { | 
 |  |  |             List<AchieveNew> achieveNewList = new ArrayList<>(); | 
 |  |  |             for(AchieveNew achieveNew : list) { | 
 |  |  |                 achieveNewService.removeById(achieveNew.getId()); | 
 |  |  |                 achieveNew.setId(null); | 
 |  |  |                 achieveNew.setConsume(null); | 
 |  |  |                 achieveNew.setCardCash(null); | 
 |  |  |  | 
 |  |  |                 if (achieveNew.getOrderItemId().equals(item.getId())) { | 
 |  |  |                     achieveNewList.add(achieveNew); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             item.setAchaeveList(achieveNewList); | 
 |  |  |         }); | 
 |  |  |         order.setItems(orderItems); | 
 |  |  |         achieveNewService.addAchaeveByOrder(order); | 
 |  |  |         return AjaxResult.buildSuccessInstance("保存成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  |  |