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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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<Zj5Mfj> 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);
 
    }
}