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.Jg9Cpzl;
|
import org.jeecg.modules.arj.g.entity.Jg9Scjl;
|
import org.jeecg.modules.arj.g.service.Jg9CpzlService;
|
import org.jeecg.modules.arj.g.service.Jg9ScjlService;
|
import org.jeecg.modules.arj.g.vo.JiGaiVo;
|
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;
|
import java.util.List;
|
|
@Api(tags = "g09-集盖工序生产质量记录")
|
@RestController
|
@RequestMapping("/g/jiGaiVoController")
|
public class JiGaiVoController {
|
|
@Resource
|
private Jg9ScjlService jg9ScjlService;
|
@Resource
|
private Jg9CpzlService jg9CpzlService;
|
|
|
@Autowired
|
private HeadService headService;
|
private Head head ;
|
private Jg9Scjl jg9Scjl ;
|
private List<Jg9Cpzl> jg9CpzlList ;
|
//新增和修改接口
|
@PostMapping("/add")
|
public AjaxResult add(@RequestBody JiGaiVo bianxkVo) {
|
//新增或者更新
|
Head h = headService.insert(bianxkVo.getHead());
|
|
if( bianxkVo.getJg9Scjl() != null){
|
bianxkVo.getJg9Scjl().setHeadId(h.getId());
|
jg9ScjlService.save(bianxkVo.getJg9Scjl());
|
}
|
if (bianxkVo.getJg9CpzlList() != null) {
|
bianxkVo.getJg9CpzlList().stream().forEach(item -> item.setHeadId(h.getId()));
|
jg9CpzlService.saveBatch(bianxkVo.getJg9CpzlList());
|
}
|
|
return AjaxResult.success(h.getId());
|
|
}
|
|
@PostMapping("/edit")
|
public AjaxResult edit(@RequestBody JiGaiVo bianxkVo) {
|
//新增或者更新
|
|
Head h2 = bianxkVo.getHead();
|
h2.setId("");
|
Head h = headService.insert(h2);
|
if( bianxkVo.getJg9Scjl() != null){
|
bianxkVo.getJg9Scjl().setHeadId(h.getId());
|
jg9ScjlService.saveOrUpdate(bianxkVo.getJg9Scjl());
|
}
|
if (bianxkVo.getJg9CpzlList() != null) {
|
bianxkVo.getJg9CpzlList().stream().forEach(item -> item.setHeadId(h.getId()));
|
jg9CpzlService.saveOrUpdateBatch(bianxkVo.getJg9CpzlList());
|
}
|
return AjaxResult.success(h.getId());
|
|
}
|
|
@ApiOperation("通过ID查询单条数据")
|
@GetMapping("/id")
|
public AjaxResult queryById(String id) {
|
JiGaiVo chongVo = new JiGaiVo();
|
Head head = headService.queryById(id);
|
|
if (head == null) return AjaxResult.error("访问无数据");
|
chongVo.setHead(head);
|
List<Jg9Scjl> list = jg9ScjlService.queryByHeadId(head.getId()) ;
|
if( list.size() > 0 )
|
chongVo.setJg9Scjl(list.get(0));
|
List<Jg9Cpzl> zlist = jg9CpzlService.queryByHeadId(head.getId());
|
if( zlist.size() > 0)
|
chongVo.setJg9CpzlList(zlist);
|
|
return AjaxResult.success(chongVo);
|
}
|
|
|
|
/**
|
* 获取最新数据
|
*
|
* @return 实例对象
|
*/
|
@ApiOperation("获取最新数据")
|
@PostMapping("/last")
|
public AjaxResult getlastRecord(String leixing) {
|
Head head = headService.queryLast(leixing==null?"g09":leixing);
|
if (head == null) return AjaxResult.error("访问无数据");
|
JiGaiVo chongVo = new JiGaiVo();
|
chongVo.setHead(head);
|
|
chongVo.setJg9Scjl( jg9ScjlService.queryByHeadId(head.getId()).size()>0 ?jg9ScjlService.queryByHeadId(head.getId()).get(0):null);
|
chongVo.setJg9CpzlList(jg9CpzlService.queryByHeadId(head.getId()));
|
|
|
return AjaxResult.success(chongVo);
|
}
|
}
|