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
package org.jeecg.modules.arj.g.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.modules.arj.config.AjaxResult;
import org.jeecg.modules.arj.entity.Head;
import org.jeecg.modules.arj.g.entity.G18ChanTotal;
import org.jeecg.modules.arj.g.entity.G18Chanliangtongji;
import org.jeecg.modules.arj.g.service.G18ChanTotalService;
import org.jeecg.modules.arj.g.service.G18ChanliangtongjiService;
import org.jeecg.modules.arj.g.vo.G18ChanVo;
import org.jeecg.modules.arj.service.HeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 * 盖线产量统计 前端控制器
 * </p>
 *
 * @author hyy
 * @since 2023-05-12
 */
@Api(tags = "g18-盖线产量统计")
@RestController
@RequestMapping("/g/g18-chanliangtongji")
public class G18ChanliangtongjiController {
 
    @Autowired
    HeadService headService;
    @Autowired
    G18ChanliangtongjiService g18ChanliangtongjiService;
    @Autowired
    G18ChanTotalService g18ChanTotalService;
 
 
    //新增和修改接口
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public AjaxResult save(@RequestBody G18ChanVo g18ChanVo) {
        //新增或者更新
        Head head = headService.insert(g18ChanVo.getHead());
        if (g18ChanVo.getG18ChanliangtongjiList() != null) {
            g18ChanVo.getG18ChanliangtongjiList().stream().forEach(item -> item.setHeadId(head.getId()));
            g18ChanliangtongjiService.saveBatch(g18ChanVo.getG18ChanliangtongjiList());
        }
        if (g18ChanVo.getG18ChanTotal() != null) {
            g18ChanVo.getG18ChanTotal().setHeadId(head.getId());
            g18ChanTotalService.save(g18ChanVo.getG18ChanTotal());
        }
        return AjaxResult.success(head.getId());
    }
 
 
    //查询所有内容接口
    @ApiOperation("获取最新数据")
    @GetMapping("/list")
    public AjaxResult findAll() {
        Head head = headService.queryLast("g18");
        G18ChanVo g18ChanVo = new G18ChanVo();
        g18ChanVo.setHead(head);
        g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(head.getId()));
 
            g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(head.getId()));
        return AjaxResult.success(g18ChanVo);   //返回查询到的所有数据
    }
 
    //根据id查询
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/id")
    public AjaxResult findOne(String id) {
        Head head = headService.queryById(id);
 
        if (head == null) return AjaxResult.error("访问无数据");
 
        G18ChanVo g18ChanVo = new G18ChanVo();
        g18ChanVo.setHead(head);
 
        g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(id));
        g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(id));
        return AjaxResult.success(g18ChanVo);   //返回查询到指定id的数据
    }
 
    //分页查询
    @GetMapping("/page")
    public IPage<G18Chanliangtongji> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        //此处没有写查询条件逻辑,因为太活了,所有不在模板中写了
        IPage<G18Chanliangtongji> page = new Page<>(pageNum, pageSize);  //新建一个page
        QueryWrapper<G18Chanliangtongji> queryWrapper = new QueryWrapper<>();  //新建一个queryWrapper
 
        queryWrapper.orderByDesc("id");   //通过id倒序显示
        return g18ChanliangtongjiService.page(page, queryWrapper);  //返回分页
    }
 
    //查询所有内容接口
    @ApiOperation("获取最新数据")
    @GetMapping("/last")
    public AjaxResult find(String leixing) {
        Head head = headService.queryLast("g18");
        G18ChanVo g18ChanVo = new G18ChanVo();
        g18ChanVo.setHead(head);
        g18ChanVo.setG18ChanliangtongjiList(g18ChanliangtongjiService.queryByHeadId(head.getId()));
 
        g18ChanVo.setG18ChanTotal(g18ChanTotalService.queryByHeadId(head.getId()));
        return AjaxResult.success(g18ChanVo);   //返回查询到的所有数据
    }
}