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.Zj7WeekService; import org.jeecg.modules.arj.g.vo.ZhujiaoWeekVo; 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 = "g07-注胶机周润滑记录") @RestController @RequestMapping("/g/zhujiaoWeekVoController") public class ZhujiaoWeekVoController { @Autowired private HeadService headService; @Autowired private Zj7WeekService zj7WeekService ; //新增和修改接口 @PostMapping("/add") public AjaxResult add(@RequestBody ZhujiaoWeekVo bianxkVo) { //新增或者更新 Head h = headService.insert(bianxkVo.getHead()); if (bianxkVo.getZj7WeekList() != null) { bianxkVo.getZj7WeekList().stream().forEach(item -> item.setHeadId(h.getId())); zj7WeekService.saveBatch(bianxkVo.getZj7WeekList()); } return AjaxResult.success(h.getId()); } @PostMapping("/edit") public AjaxResult edit(@RequestBody ZhujiaoWeekVo bianxkVo) { //新增或者更新 Head h2 = bianxkVo.getHead(); h2.setId(""); Head h = headService.insert(h2); if (bianxkVo.getZj7WeekList() != null) { bianxkVo.getZj7WeekList().stream().forEach(item -> item.setHeadId(h.getId())); zj7WeekService.saveOrUpdateBatch(bianxkVo.getZj7WeekList()); } return AjaxResult.success(h.getId()); } @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { ZhujiaoWeekVo chongVo = new ZhujiaoWeekVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); chongVo.setHead(head); chongVo.setZj7WeekList(zj7WeekService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(String leixing) { Head head = headService.queryLast(leixing==null?"g07":leixing); if (head == null) return AjaxResult.error("访问无数据"); ZhujiaoWeekVo chongVo = new ZhujiaoWeekVo(); chongVo.setHead(head); chongVo.setZj7WeekList(zj7WeekService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } }