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.C13CtsyService; import org.jeecg.modules.arj.g.vo.C13CtsyVo; 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 = "g13-整张冲铁使用登记表") @RestController @RequestMapping("/g/c13CtsyVoController") public class C13CtsyVoController { @Autowired private HeadService headService; @Autowired private C13CtsyService c13CtsyService ; //新增和修改接口 @PostMapping("/add") public AjaxResult add(@RequestBody C13CtsyVo bianxkVo) { //新增或者更新 bianxkVo.getHead().setShengcx("一线"); Head h = headService.insert(bianxkVo.getHead()); if (bianxkVo.getC13CtsyList() != null) { bianxkVo.getC13CtsyList().stream().forEach(item -> item.setHeadId(h.getId())); c13CtsyService.saveBatch(bianxkVo.getC13CtsyList()); } return AjaxResult.success(h.getId()); } @PostMapping("/edit") public AjaxResult edit(@RequestBody C13CtsyVo bianxkVo) { //新增或者更新 Head h2 = bianxkVo.getHead(); h2.setId(""); Head h = headService.insert(h2); if (bianxkVo.getC13CtsyList() != null) { bianxkVo.getC13CtsyList().stream().forEach(item -> item.setHeadId(h.getId())); c13CtsyService.saveOrUpdateBatch(bianxkVo.getC13CtsyList()); } return AjaxResult.success(h.getId()); } @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { C13CtsyVo chongVo = new C13CtsyVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); chongVo.setHead(head); chongVo.setC13CtsyList(c13CtsyService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(String leixing) { Head head = headService.queryLast(leixing==null?"g13":leixing); if (head == null) return AjaxResult.error("访问无数据"); C13CtsyVo chongVo = new C13CtsyVo(); chongVo.setHead(head); chongVo.setC13CtsyList(c13CtsyService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } }