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.CBaseService; import org.jeecg.modules.arj.g.service.CSpService; import org.jeecg.modules.arj.g.service.CTieqkService; import org.jeecg.modules.arj.g.service.CWgService; import org.jeecg.modules.arj.g.vo.ChongVo; 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.*; import javax.annotation.Resource; @Api(tags = "g01-底盖冲床工序生产质量记录") @RestController @RequestMapping("/g/chongVoController") public class ChongVoController { @Resource private CTieqkService cTieqkService; @Resource private CBaseService cBaseService; @Resource private CSpService cSpService; @Resource private CWgService cWgService; @Autowired private HeadService headService; //新增和修改接口 @PostMapping("/add") public AjaxResult add(@RequestBody ChongVo bianxkVo) { //新增或者更新 Head h = headService.insert(bianxkVo.getHead()); if( bianxkVo.getCTieqk() != null){ bianxkVo.getCTieqk().setHeadId(h.getId()); cTieqkService.save(bianxkVo.getCTieqk()); } if (bianxkVo.getCSpList() != null) { bianxkVo.getCSpList().stream().forEach(item -> item.setHeadId(h.getId())); cSpService.saveBatch(bianxkVo.getCSpList()); } if (bianxkVo.getCBaseList() != null) { bianxkVo.getCBaseList().stream().forEach(item -> item.setHeadId(h.getId())); cBaseService.saveBatch(bianxkVo.getCBaseList()); } if (bianxkVo.getCWgList() != null) { bianxkVo.getCWgList().stream().forEach(item -> item.setHeadId(h.getId())); cWgService.saveBatch(bianxkVo.getCWgList()); } return AjaxResult.success(h.getId()); } @PostMapping("/edit") public AjaxResult edit(@RequestBody ChongVo bianxkVo) { //新增或者更新 Head h2 = bianxkVo.getHead(); h2.setId(""); Head h = headService.insert(h2); if( bianxkVo.getCTieqk() != null){ bianxkVo.getCTieqk().setHeadId(h.getId()); cTieqkService.saveOrUpdate(bianxkVo.getCTieqk()); } if (bianxkVo.getCSpList() != null) { bianxkVo.getCSpList().stream().forEach(item -> item.setHeadId(h.getId())); cSpService.saveOrUpdateBatch(bianxkVo.getCSpList()); } if (bianxkVo.getCBaseList() != null) { bianxkVo.getCBaseList().stream().forEach(item -> item.setHeadId(h.getId())); cBaseService.saveOrUpdateBatch(bianxkVo.getCBaseList()); } if (bianxkVo.getCWgList() != null) { bianxkVo.getCWgList().stream().forEach(item -> item.setHeadId(h.getId())); cWgService.saveOrUpdateBatch(bianxkVo.getCWgList()); } return AjaxResult.success(h.getId()); } @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { ChongVo chongVo = new ChongVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); chongVo.setHead(head); chongVo.setCTieqk(cTieqkService.queryByHeadId(head.getId())); chongVo.setCSpList(cSpService.queryByHeadId(head.getId())); chongVo.setCBaseList(cBaseService.queryByHeadId(head.getId())); chongVo.setCWgList(cWgService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(String leixing) { Head head = headService.queryLast(leixing==null?"g01":leixing); if (head == null) return AjaxResult.error("访问无数据"); ChongVo chongVo = new ChongVo(); chongVo.setHead(head); chongVo.setCTieqk(cTieqkService.queryByHeadId(head.getId())); chongVo.setCSpList(cSpService.queryByHeadId(head.getId())); chongVo.setCBaseList(cBaseService.queryByHeadId(head.getId())); chongVo.setCWgList(cWgService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } }