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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package org.jeecg.modules.arj.controller;
 
 
import com.alibaba.fastjson.JSONObject;
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.mapper.HeadMapper;
import org.jeecg.modules.arj.service.*;
import org.jeecg.modules.arj.vo.JiguanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
@Api(tags = "A5集罐机接口")
@RestController
@RequestMapping("/jiguanVo")
public class JiguanVoController {
 
    @Autowired
    private HeadService headService;
 
    @Autowired
    private HeadMapper headMapper;
 
    @Autowired
    private FeipinYintieService feipinYintieService;
    @Autowired
    private FeipinJiguanService feipinJiguanService;
 
    @Autowired
    private JiguanRd2Service jiguanRd2Service ;
    @Autowired
    private JiguanRdService jiguanRdService ;
    @Autowired
    private JiguanFuliaoRdService jiguanFuliaoRdService ;
    @Autowired
    private JiguanZhiliangRdService jiguanZhiliangRdService ;
 
 
 
 
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/id")
    public AjaxResult queryById(String id) {
        JiguanVo jianbjVo = new JiguanVo();
        Head head = headService.queryById(id);
        jianbjVo.setHead(head);
        jianbjVo.setFeipinYintieList(feipinYintieService.queryByHeadList(head.getId()));
        jianbjVo.setFeipinJiguanList(feipinJiguanService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanFuliaoRdList(jiguanFuliaoRdService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanRd2List(jiguanRd2Service.queryByHeadId(head.getId()));
        jianbjVo.setJiguanRd(jiguanRdService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanZhiliangRdList(jiguanZhiliangRdService.queryByHeadId(head.getId()));
        return AjaxResult.success(jianbjVo);
    }
 
    /**
     * 获取最新数据
     *
     * @return 实例对象
     */
    @ApiOperation("获取最新数据")
    @PostMapping("/last")
    public AjaxResult getlastRecord(@RequestBody String leixing) {
 
       // Head head = headService.queryLast(leixing==null?"A5":leixing);
        JSONObject j = JSONObject.parseObject(leixing);
        HashMap<String, String > myMap  = new HashMap<String, String>(){{
            put("0","一");
            put("2","二");
            put("3","三");
            put("4","四");
            put("5","五");
            put("6","六");
            put("7","七");
            put("8","八");
            put("9","九");
        }};
 
        Head head =  headService.queryLeixingChanxian("A5",myMap.get(j.getString("leixing")));
        JiguanVo jianbjVo = new JiguanVo();
 
        if (head == null) return AjaxResult.error("访问无数据");
 
        jianbjVo.setHead(head);
        jianbjVo.setFeipinYintieList(feipinYintieService.queryByHeadList(head.getId()));
        jianbjVo.setFeipinJiguanList(feipinJiguanService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanFuliaoRdList(jiguanFuliaoRdService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanRd2List(jiguanRd2Service.queryByHeadId(head.getId()));
        jianbjVo.setJiguanRd(jiguanRdService.queryByHeadId(head.getId()));
        jianbjVo.setJiguanZhiliangRdList(jiguanZhiliangRdService.queryByHeadId(head.getId()));
 
        return AjaxResult.success(jianbjVo);
    }
    @PostMapping("/page")
    public AjaxResult findPage( @RequestParam(defaultValue = "1") Integer pageNum ,  @RequestParam(defaultValue = "10") Integer pageSize) {
 
 
        List<Head> headList = headMapper.queryPage2((pageNum - 1) * pageSize, pageSize);
        IPage iPage = new Page();
        List<JiguanVo> records = new ArrayList<>();
        for (Head h : headList) {
 
            JiguanVo jiguanVo = new JiguanVo();
            Head head = headService.queryById(h.getId());
            if (head == null) return AjaxResult.error("访问无数据");
 
            jiguanVo.setHead(head);
            jiguanVo.setFeipinYintieList(feipinYintieService.queryByHeadList(head.getId()));
            jiguanVo.setFeipinJiguanList(feipinJiguanService.queryByHeadId(head.getId()));
            jiguanVo.setJiguanFuliaoRdList(jiguanFuliaoRdService.queryByHeadId(head.getId()));
            jiguanVo.setJiguanRd2List(jiguanRd2Service.queryByHeadId(head.getId()));
            jiguanVo.setJiguanRd(jiguanRdService.queryByHeadId(head.getId()));
            jiguanVo.setJiguanZhiliangRdList(jiguanZhiliangRdService.queryByHeadId(head.getId()));
 
            records.add(jiguanVo);
        }
        int n = headMapper.queryCount();
        iPage.setPages(n % pageSize == 0 ? n / pageSize : n / pageSize + 1);
        iPage.setRecords(records);
        iPage.setTotal(headMapper.queryCount());
        iPage.setSize(pageSize);
        iPage.setCurrent(pageNum);
 
        return AjaxResult.success(iPage);
    }
    /**
     * 分页查询
     *
     * @param head        筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @ApiOperation("分页查询")
    @GetMapping
    public AjaxResult paginQuery(Head head, PageRequest pageRequest) {
        //1.分页参数
        long current = pageRequest.getPageNumber();
        long size = pageRequest.getPageSize();
        //2.分页查询
        /*把Mybatis的分页对象做封装转换,MP的分页对象上有一些SQL敏感信息,还是通过spring的分页模型来封装数据吧*/
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<Head> pageResult = headService.paginQuery(head, current, size);
        //3. 分页结果组装
        List<Head> dataList = pageResult.getRecords();
        long total = pageResult.getTotal();
        PageImpl<Head> retPage = new PageImpl<Head>(dataList, pageRequest, total);
        return AjaxResult.success(retPage);
    }
 
    /**
     * 新增数据
     *
     * @param jianguanVo 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping
    public AjaxResult add(@RequestBody JiguanVo jianguanVo) {
 
        Head h = headService.insert(jianguanVo.getHead());
 
        if (jianguanVo.getFeipinJiguanList() != null) {
            jianguanVo.getFeipinJiguanList().stream().forEach(item -> item.setHeadId(h.getId()));
            feipinJiguanService.saveOrUpdateBatch(jianguanVo.getFeipinJiguanList());
        }
        if (jianguanVo.getFeipinYintieList() != null) {
            jianguanVo.getFeipinYintieList().stream().forEach(item -> item.setHeadId(h.getId()));
            feipinYintieService.saveOrUpdateBatch(jianguanVo.getFeipinYintieList());
        }
 
        if (jianguanVo.getJiguanRd() != null) {
            jianguanVo.getJiguanRd().setHeadId(h.getId());
            jiguanRdService.saveOrUpdate(jianguanVo.getJiguanRd());
        }
 
        if (jianguanVo.getJiguanRd2List() != null) {
            jianguanVo.getJiguanRd2List().stream().forEach(item -> item.setHeadId(h.getId()));
            jiguanRd2Service.saveOrUpdateBatch(jianguanVo.getJiguanRd2List());
        }
        if (jianguanVo.getJiguanFuliaoRdList() != null) {
            jianguanVo.getJiguanFuliaoRdList().stream().forEach(item -> item.setHeadId(h.getId()));
            jiguanFuliaoRdService.saveOrUpdateBatch(jianguanVo.getJiguanFuliaoRdList());
        }
        if (jianguanVo.getJiguanZhiliangRdList() != null) {
            jianguanVo.getJiguanZhiliangRdList().stream().forEach(item -> item.setHeadId(h.getId()));
            jiguanZhiliangRdService.saveOrUpdateBatch(jianguanVo.getJiguanZhiliangRdList());
        }
 
 
 
        return AjaxResult.success(h.getId());
    }
 
    /**
     * 更新数据
     *
     * @param jiguanVo 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JiguanVo jiguanVo) {
        Head h2 = jiguanVo.getHead();
        h2.setId("");
        Head hh = headService.insert(h2);
 
 
        if (jiguanVo.getFeipinJiguanList() != null) {
            jiguanVo.getFeipinJiguanList().stream().forEach(item -> item.setHeadId(hh.getId()));
            feipinJiguanService.saveBatch(jiguanVo.getFeipinJiguanList());
        }
        if (jiguanVo.getFeipinYintieList() != null) {
            jiguanVo.getFeipinYintieList().stream().forEach(item -> item.setHeadId(hh.getId()));
            feipinYintieService.saveBatch(jiguanVo.getFeipinYintieList());
        }
 
        if (jiguanVo.getJiguanRd() != null) {
            jiguanVo.getJiguanRd().setHeadId(hh.getId());
            jiguanRdService.save(jiguanVo.getJiguanRd());
        }
 
        if (jiguanVo.getJiguanRd2List() != null) {
            jiguanVo.getJiguanRd2List().stream().forEach(item -> item.setHeadId(hh.getId()));
            jiguanRd2Service.saveBatch(jiguanVo.getJiguanRd2List());
        }
        if (jiguanVo.getJiguanFuliaoRdList() != null) {
            jiguanVo.getJiguanFuliaoRdList().stream().forEach(item -> item.setHeadId(hh.getId()));
            jiguanFuliaoRdService.saveBatch(jiguanVo.getJiguanFuliaoRdList());
        }
        if (jiguanVo.getJiguanZhiliangRdList() != null) {
            jiguanVo.getJiguanZhiliangRdList().stream().forEach(item -> item.setHeadId(hh.getId()));
            jiguanZhiliangRdService.saveBatch(jiguanVo.getJiguanZhiliangRdList());
        }
 
 
 
        return AjaxResult.success(hh.getId());
    }
 
    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping
    public AjaxResult deleteById(String id) {
        return AjaxResult.success(headService.deleteById(id));
    }
}