AdaKing88
2023-08-23 ae35159387a55199e8ab150ebb97d89d68a235bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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.C17FzjtService;
import org.jeecg.modules.arj.g.vo.C17FzjtVo;
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 = "g17-防撞胶条点检表")
@RestController
@RequestMapping("/g/c17FzjtVoController")
public class C17FzjtVoController {
    @Autowired
    private HeadService headService;
 
    @Autowired
    private C17FzjtService c17FzjtService ;
    //新增和修改接口
    @PostMapping("/add")
    public AjaxResult add(@RequestBody C17FzjtVo bianxkVo) {
        //新增或者更新
        Head h = headService.insert(bianxkVo.getHead());
 
 
        if (bianxkVo.getC17FzjtList() != null) {
            bianxkVo.getC17FzjtList().stream().forEach(item -> item.setHeadId(h.getId()));
            c17FzjtService.saveBatch(bianxkVo.getC17FzjtList());
        }
 
        return AjaxResult.success(h.getId());
 
    }
 
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody C17FzjtVo bianxkVo) {
        //新增或者更新
 
        Head h2 = bianxkVo.getHead();
        h2.setId("");
        Head h = headService.insert(h2);
 
        if (bianxkVo.getC17FzjtList() != null) {
            bianxkVo.getC17FzjtList().stream().forEach(item -> item.setHeadId(h.getId()));
            c17FzjtService.saveOrUpdateBatch(bianxkVo.getC17FzjtList());
        }
 
 
        return AjaxResult.success(h.getId());
 
    }
 
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/id")
    public AjaxResult queryById(String id) {
        C17FzjtVo chongVo = new C17FzjtVo();
        Head head = headService.queryById(id);
 
        if (head == null) return AjaxResult.error("访问无数据");
        chongVo.setHead(head);
 
 
        chongVo.setC17FzjtList(c17FzjtService.queryByHeadId(head.getId()));
        return AjaxResult.success(chongVo);
    }
 
 
 
 
 
    /**
     * 获取最新数据
     *
     * @return 实例对象
     */
    @ApiOperation("获取最新数据")
    @PostMapping("/last")
    public AjaxResult getlastRecord(String leixing) {
        Head head = headService.queryLast(leixing==null?"g17":leixing);
        if (head == null) return AjaxResult.error("访问无数据");
        C17FzjtVo chongVo = new C17FzjtVo();
        chongVo.setHead(head);
 
 
        chongVo.setC17FzjtList(c17FzjtService.queryByHeadId(head.getId()));
 
 
        return AjaxResult.success(chongVo);
    }
}