package org.jeecg.modules.arj.g.controller; import org.jeecg.modules.arj.config.AjaxResult; import org.jeecg.modules.arj.entity.Head; import org.jeecg.modules.arj.g.service.Jg11QjService; import org.jeecg.modules.arj.g.vo.Jg11QjVo; import org.jeecg.modules.arj.service.HeadService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @Api(tags = "g11-502集盖机清洁记录") @RestController @RequestMapping("/g/jg11QjVoController") public class Jg11QjVoController { @Autowired private HeadService headService; @Autowired private Jg11QjService jg11QjService ; //新增和修改接口 @PostMapping("/add") public AjaxResult add(@RequestBody Jg11QjVo bianxkVo) { //新增或者更新 Head h = headService.insert(bianxkVo.getHead()); if (bianxkVo.getJg11QjList() != null) { bianxkVo.getJg11QjList().stream().forEach(item -> item.setHeadId(h.getId())); jg11QjService.saveBatch(bianxkVo.getJg11QjList()); } return AjaxResult.success(h.getId()); } @PostMapping("/edit") public AjaxResult edit(@RequestBody Jg11QjVo bianxkVo) { //新增或者更新 Head h2 = bianxkVo.getHead(); h2.setId(""); Head h = headService.insert(h2); if (bianxkVo.getJg11QjList() != null) { bianxkVo.getJg11QjList().stream().forEach(item -> item.setHeadId(h.getId())); jg11QjService.saveOrUpdateBatch(bianxkVo.getJg11QjList()); } return AjaxResult.success(h.getId()); } @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { Jg11QjVo chongVo = new Jg11QjVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); chongVo.setHead(head); chongVo.setJg11QjList(jg11QjService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(String leixing) { Head head = headService.queryLast(leixing==null?"g11":leixing); if (head == null) return AjaxResult.error("访问无数据"); Jg11QjVo chongVo = new Jg11QjVo(); chongVo.setHead(head); chongVo.setJg11QjList(jg11QjService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } }