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.entity.Zj5Mfj; import org.jeecg.modules.arj.g.service.Zj5BaseService; import org.jeecg.modules.arj.g.service.Zj5MfjService; import org.jeecg.modules.arj.g.service.Zj5SpService; import org.jeecg.modules.arj.g.service.Zj5WgService; import org.jeecg.modules.arj.g.vo.ZhujiaoVo; 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 java.util.List; @Api(tags = "g05-底盖注胶工序生产质量记录") @RestController @RequestMapping("/g/zhujiaoVoController") public class ZhujiaoVoController { @Autowired private HeadService headService; @Autowired private Zj5BaseService zj5BaseService; @Autowired private Zj5SpService zj5SpService; @Autowired private Zj5MfjService zj5MfjService; @Autowired private Zj5WgService zj5WgService; //新增和修改接口 @PostMapping("/add") public AjaxResult add(@RequestBody ZhujiaoVo bianxkVo) { //新增或者更新 Head h = headService.insert(bianxkVo.getHead()); if( bianxkVo.getZj5Mfj() != null){ bianxkVo.getZj5Mfj().setHeadId(h.getId()); zj5MfjService.save(bianxkVo.getZj5Mfj()); } if (bianxkVo.getZj5BaseList() != null) { bianxkVo.getZj5BaseList().stream().forEach(item -> item.setHeadId(h.getId())); zj5BaseService.saveBatch(bianxkVo.getZj5BaseList()); } if (bianxkVo.getZj5SpList() != null) { bianxkVo.getZj5SpList().stream().forEach(item -> item.setHeadId(h.getId())); zj5SpService.saveBatch(bianxkVo.getZj5SpList()); } if (bianxkVo.getZj5WgList() != null) { bianxkVo.getZj5WgList().stream().forEach(item -> item.setHeadId(h.getId())); zj5WgService.saveBatch(bianxkVo.getZj5WgList()); } return AjaxResult.success(h.getId()); } @PostMapping("/edit") public AjaxResult edit(@RequestBody ZhujiaoVo bianxkVo) { //新增或者更新 Head h2 = bianxkVo.getHead(); h2.setId(""); Head h = headService.insert(h2); if( bianxkVo.getZj5Mfj() != null){ bianxkVo.getZj5Mfj().setHeadId(h.getId()); zj5MfjService.saveOrUpdate(bianxkVo.getZj5Mfj()); } if (bianxkVo.getZj5BaseList() != null) { bianxkVo.getZj5BaseList().stream().forEach(item -> item.setHeadId(h.getId())); zj5BaseService.saveOrUpdateBatch(bianxkVo.getZj5BaseList()); } if (bianxkVo.getZj5SpList() != null) { bianxkVo.getZj5SpList().stream().forEach(item -> item.setHeadId(h.getId())); zj5SpService.saveOrUpdateBatch(bianxkVo.getZj5SpList()); } if (bianxkVo.getZj5WgList() != null) { bianxkVo.getZj5WgList().stream().forEach(item -> item.setHeadId(h.getId())); zj5WgService.saveOrUpdateBatch(bianxkVo.getZj5WgList()); } return AjaxResult.success(h.getId()); } @ApiOperation("通过ID查询单条数据") @GetMapping("/id") public AjaxResult queryById(String id) { ZhujiaoVo chongVo = new ZhujiaoVo(); Head head = headService.queryById(id); if (head == null) return AjaxResult.error("访问无数据"); chongVo.setHead(head); List list = zj5MfjService.queryByHeadId(head.getId()); if( list.size() > 0) chongVo.setZj5Mfj( list.get(0)); chongVo.setZj5BaseList(zj5BaseService.queryByHeadId(head.getId())); chongVo.setZj5SpList(zj5SpService.queryByHeadId(head.getId())); chongVo.setZj5WgList(zj5WgService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } /** * 获取最新数据 * * @return 实例对象 */ @ApiOperation("获取最新数据") @PostMapping("/last") public AjaxResult getlastRecord(String leixing) { Head head = headService.queryLast(leixing==null?"g05":leixing); if (head == null) return AjaxResult.error("访问无数据"); ZhujiaoVo chongVo = new ZhujiaoVo(); chongVo.setHead(head); chongVo.setZj5Mfj(zj5MfjService.queryByHeadId(head.getId()).size()>0 ?zj5MfjService.queryByHeadId(head.getId()).get(0):null); chongVo.setZj5BaseList(zj5BaseService.queryByHeadId(head.getId())); chongVo.setZj5SpList(zj5SpService.queryByHeadId(head.getId())); chongVo.setZj5WgList(zj5WgService.queryByHeadId(head.getId())); return AjaxResult.success(chongVo); } }