智慧农业后台管理
guoshilong
2022-10-26 7de9fef9839d5411f28d7021515563766a3ee503
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.stock.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
 
import javax.validation.Valid;
 
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.stock.vo.StocksVO;
import org.springblade.modules.stockrecord.entity.Stockrecord;
import org.springblade.modules.stockrecord.service.IStockrecordService;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDictBizService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.stock.entity.Stock;
import org.springblade.modules.stock.vo.StockVO;
import org.springblade.modules.stock.service.IStockService;
import org.springblade.core.boot.ctrl.BladeController;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 农资库存表 控制器
 *
 * @author BladeX
 * @since 2022-05-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/stock/stock")
@Api(value = "农资库存表", tags = "农资库存表接口")
public class StockController extends BladeController {
 
    private final IStockService stockService;
    private final IStockrecordService stockrecordService;
 
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入stock")
    public R<Stock> detail(Stock stock) {
        Stock detail = stockService.getOne(Condition.getQueryWrapper(stock));
        return R.data(detail);
    }
 
    /**
     * 分页 农资库存表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入stock")
    public R<IPage<Stock>> list(Stock stock, Query query) {
        IPage<Stock> pages = stockService.page(Condition.getPage(query), Condition.getQueryWrapper(stock));
        return R.data(pages);
    }
 
    /**
     * 自定义分页 农资库存表
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入stock")
    public R<IPage<StockVO>> page(StockVO stock, Query query) {
        IPage<StockVO> pages = stockService.selectLists(Condition.getPage(query), stock);
        for (int i = 0; i < pages.getRecords().size(); i++) {
            String specs = pages.getRecords().get(i).getSpecs();
            Integer amount = pages.getRecords().get(i).getAmount();
            Integer num = Integer.parseInt(specs);
            String dic1 = pages.getRecords().get(i).getDic1();
            String dic2 = pages.getRecords().get(i).getDic2();
            String s = specs + dic1 + "/" + dic2;
            pages.getRecords().get(i).setSpn(s);
            pages.getRecords().get(i).setCnum(num * amount);
 
        }
        return R.data(pages);
    }
 
    /**
     * 自定义分页 农资库存表
     */
    @GetMapping("/pages")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入stock")
    public R<List<StockVO>> pages(StockVO stock) {
        List<StockVO> pages = stockService.selectListss(stock);
        for (int i = 0; i < pages.size(); i++) {
            String specs = pages.get(i).getSpecs();
            Integer amount = pages.get(i).getAmount();
            Integer num = Integer.parseInt(specs);
            String dic1 = pages.get(i).getDic1();
            String dic2 = pages.get(i).getDic2();
            String s = specs + dic1 + "/" + dic2;
            pages.get(i).setSpn(s);
            pages.get(i).setCnum(num * amount);
 
        }
        return R.data(pages);
    }
 
    /**
     * 新增 农资库存表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入stock")
    public R save(@Valid @RequestBody Stock stock) {
        stock.setState("0");
        stock.setSp1("stockSpecs1");
        stock.setSp2("stockSpecs2");
        boolean save = stockService.save(stock);
        //农资记录表
        Stockrecord stockrecord = new Stockrecord();
        //农资ID
        stockrecord.setSid(stock.getId());
        stockrecord.setStockId1(stock.getStockId());
        stockrecord.setAmount1(stock.getAmount());
        stockrecord.setTime1(stock.getTime());
        stockrecord.setType1(stock.getType());
        stockrecord.setStockType1(1);
        stockrecord.setPicture1(stock.getPicture());
        stockrecord.setRemarks1(stock.getRemarks());
        stockrecord.setSpecs1(stock.getSpecs());
        stockrecord.setSpecsVal1(stock.getSpecsValue1());
        stockrecord.setSpecsVal2(stock.getSpecsValue2());
        stockrecord.setDeptId(stock.getDeptId());
        stockrecord.setSp1("stockSpecs1");
        stockrecord.setSp2("stockSpecs2");
        //统计公斤
        Integer amount = stock.getAmount();
        String specs = stock.getSpecs();
        int i = Integer.parseInt(specs);
        Integer specsValue1 = stock.getSpecsValue1();
        double v = 0;
        //克
        if (specsValue1 == 0) {
            v = amount * i * 0.001;
        }
        //斤
        if (specsValue1 == 1) {
            v = amount * i * 0.5;
        }
        //公斤
        if (specsValue1 == 2) {
            v = amount * i;
        }
        //吨
        if (specsValue1 == 3) {
            v = amount * i * 1000;
        }
        //毫升
        if (specsValue1 == 4) {
            //毫升换成升
            double s = amount * i * 0.001;
            //升换成公斤
            v = s;
        }
        //升
        if (specsValue1 == 5) {
            v = amount * i;
        }
        stockrecord.setCensus(v);
        stockrecordService.save(stockrecord);
        return R.status(save);
    }
 
    /**
     * 修改 农资库存表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入stock")
    public R update(@Valid @RequestBody Stock stock) {
        return R.status(stockService.updateById(stock));
    }
 
    /**
     * 新增或修改 农资库存表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入stock")
    public R submit(@Valid @RequestBody Stock stock) {
        return R.status(stockService.saveOrUpdate(stock));
    }
 
 
    /**
     * 删除 农资库存表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(stockService.deleteLogic(Func.toLongList(ids)));
    }
 
    /**
     * 数据统计
     *
     * @param stock
     * @param query
     * @return
     */
    @PostMapping("/pagenum")
    public R<IPage<StocksVO>> pagenum(StocksVO stock, Query query) {
        IPage<StocksVO> pages = stockService.slectNum(Condition.getPage(query), stock);
        for (int i = 0; i < pages.getRecords().size(); i++) {
            Double cgnum = pages.getRecords().get(i).getCgnum();
            Double dbrknum = pages.getRecords().get(i).getDbrknum();
            double v = cgnum + dbrknum;
            pages.getRecords().get(i).setRknum(v);
            Double lycknum = pages.getRecords().get(i).getLycknum();
            Double dbcknum = pages.getRecords().get(i).getDbcknum();
            Double bfcknum = pages.getRecords().get(i).getBfcknum();
            double v1 = lycknum + dbcknum + bfcknum;
            pages.getRecords().get(i).setCknum(v1);
        }
        return R.data(pages);
    }
 
 
    /**
     * 首页农资入库数量统计
     *
     * @return
     */
    @GetMapping("/StockCount")
    public R StockCount(String deptId) {
        List<Map<String, Object>> maps = stockService.StockCount(deptId);
        //化肥0
        double hf = 0;
        //有机肥1
        double yjf = 0;
        //杀虫剂2
        double scj = 0;
        //杀菌剂3
        double sjj = 0;
        //饲料4
        double sl = 0;
        for (int i = 0; i < maps.size(); i++) {
            //规格
            String specs = maps.get(i).get("specs").toString();
            Integer specs1 = Integer.parseInt(specs);
            //数量
            String amount = maps.get(i).get("amount").toString();
            Integer amount1 = Integer.parseInt(amount);
            //规格类型
            String spe = maps.get(i).get("spe").toString();
            //类型
            String type = maps.get(i).get("type").toString();
            if (type.equals("0")) {
                //克
                if (spe.equals("0")) {
                    hf += amount1 * specs1 * 0.001;
                }
                //斤
                if (spe.equals("1")) {
                    hf += amount1 * specs1 * 0.5;
                }
                //公斤
                if (spe.equals("2")) {
                    hf += amount1 * specs1;
                }
                //吨
                if (spe.equals("3")) {
                    hf += amount1 * specs1 * 1000;
                }
                //毫升
                if (spe.equals("4")) {
                    //毫升换成升
                    double s = amount1 * specs1 * 0.001;
                    //升换成公斤
                    hf += s;
                }
                //升
                if (spe.equals("5")) {
                    hf += amount1 * specs1;
                }
            }
            if (type.equals("1")) {
                //克
                if (spe.equals("0")) {
                    yjf += amount1 * specs1 * 0.001;
                }
                //斤
                if (spe.equals("1")) {
                    yjf += amount1 * specs1 * 0.5;
                }
                //公斤
                if (spe.equals("2")) {
                    yjf += amount1 * specs1;
                }
                //吨
                if (spe.equals("3")) {
                    yjf += amount1 * specs1 * 1000;
                }
                //毫升
                if (spe.equals("4")) {
                    //毫升换成升
                    double s = amount1 * specs1 * 0.001;
                    //升换成公斤
                    yjf += s;
                }
                //升
                if (spe.equals("5")) {
                    yjf += amount1 * specs1;
                }
            }
            if (type.equals("2")) {
                //克
                if (spe.equals("0")) {
                    scj += amount1 * specs1 * 0.001;
                }
                //斤
                if (spe.equals("1")) {
                    scj += amount1 * specs1 * 0.5;
                }
                //公斤
                if (spe.equals("2")) {
                    scj += amount1 * specs1;
                }
                //吨
                if (spe.equals("3")) {
                    scj += amount1 * specs1 * 1000;
                }
                //毫升
                if (spe.equals("4")) {
                    //毫升换成升
                    double s = amount1 * specs1 * 0.001;
                    //升换成公斤
                    scj += s;
                }
                //升
                if (spe.equals("5")) {
                    scj += amount1 * specs1;
                }
            }
            if (type.equals("3")) {
                //克
                if (spe.equals("0")) {
                    sjj += amount1 * specs1 * 0.001;
                }
                //斤
                if (spe.equals("1")) {
                    sjj += amount1 * specs1 * 0.5;
                }
                //公斤
                if (spe.equals("2")) {
                    sjj += amount1 * specs1;
                }
                //吨
                if (spe.equals("3")) {
                    sjj += amount1 * specs1 * 1000;
                }
                //毫升
                if (spe.equals("4")) {
                    //毫升换成升
                    double s = amount1 * specs1 * 0.001;
                    //升换成公斤
                    sjj += s;
                }
                //升
                if (spe.equals("5")) {
                    sjj += amount1 * specs1;
                }
            }
            if (type.equals("4")) {
                //克
                if (spe.equals("0")) {
                    sl += amount1 * specs1 * 0.001;
                }
                //斤
                if (spe.equals("1")) {
                    sl += amount1 * specs1 * 0.5;
                }
                //公斤
                if (spe.equals("2")) {
                    sl += amount1 * specs1;
                }
                //吨
                if (spe.equals("3")) {
                    sl += amount1 * specs1 * 1000;
                }
                //毫升
                if (spe.equals("4")) {
                    //毫升换成升
                    double s = amount1 * specs1 * 0.001;
                    //升换成公斤
                    sl += s;
                }
                //升
                if (spe.equals("5")) {
                    sl += amount1 * specs1;
                }
            }
        }
        Map map = new HashMap();
        map.put("name", "化肥");
        map.put("val", new BigDecimal(hf).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        Map map1 = new HashMap();
        map1.put("name", "有机肥");
        map1.put("val", new BigDecimal(String.valueOf(yjf)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        Map map2 = new HashMap();
        map2.put("name", "杀虫剂");
        map2.put("val", new BigDecimal(String.valueOf(scj)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        Map map3 = new HashMap();
        map3.put("name", "杀菌剂");
        map3.put("val", new BigDecimal(String.valueOf(sjj)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        Map map4 = new HashMap();
        map4.put("name", "饲料");
        map4.put("val", new BigDecimal(String.valueOf(sl)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        List list = new ArrayList();
        list.add(map);
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        return R.data(list);
    }
 
 
    /**
     * 小程序数据统计
     *
     * @return
     */
    @GetMapping("/pagenumx")
    public R pagenumx(String deptId, String startTime, String endTime) {
        Double rknu = 0.0;
        Double cknu = 0.0;
        List<StocksVO> pages = stockService.slectNumx(deptId, startTime, endTime);
        for (int i = 0; i < pages.size(); i++) {
            Double cgnum = pages.get(i).getCgnum();
            Double dbrknum = pages.get(i).getDbrknum();
            double v = cgnum + dbrknum;
            pages.get(i).setRknum(v);
            Double lycknum = pages.get(i).getLycknum();
            Double dbcknum = pages.get(i).getDbcknum();
            Double bfcknum = pages.get(i).getBfcknum();
            double v1 = lycknum + dbcknum + bfcknum;
            pages.get(i).setCknum(v1);
        }
        for (int j = 0; j < pages.size(); j++) {
            Double rknum = pages.get(j).getRknum();
            Double cknum = pages.get(j).getCknum();
            rknu += rknum;
            cknu += cknum;
        }
        Map map = new HashMap();
        DecimalFormat df = new DecimalFormat("#0.000");
        String format = df.format(rknu);
        Double a = Double.parseDouble(format);
        String format1 = df.format(cknu);
        double b = Double.parseDouble(format1);
        map.put("rknum", a);
        map.put("cknum", b);
        return R.data(map);
    }
 
    /**
     * 小程序农资数据统计详情
     *
     * @param stock
     * @param query
     * @return
     */
    @GetMapping("/pagenums")
    public R pagenums(StocksVO stock, Query query) {
        Double rknu = 0.0;
        Double cknu = 0.0;
        IPage<StocksVO> pages = stockService.slectNum(Condition.getPage(query), stock);
        for (int i = 0; i < pages.getRecords().size(); i++) {
            Double cgnum = pages.getRecords().get(i).getCgnum();
            Double dbrknum = pages.getRecords().get(i).getDbrknum();
            double v = cgnum + dbrknum;
            pages.getRecords().get(i).setRknum(v);
            Double lycknum = pages.getRecords().get(i).getLycknum();
            Double dbcknum = pages.getRecords().get(i).getDbcknum();
            Double bfcknum = pages.getRecords().get(i).getBfcknum();
            double v1 = lycknum + dbcknum + bfcknum;
            pages.getRecords().get(i).setCknum(v1);
        }
        for (int j = 0; j < pages.getRecords().size(); j++) {
            Double rknum = pages.getRecords().get(j).getRknum();
            Double cknum = pages.getRecords().get(j).getCknum();
            rknu += rknum;
            cknu += cknum;
        }
        Map map = new HashMap();
        DecimalFormat df = new DecimalFormat("#0.000");
        String format = df.format(rknu);
        Double a = Double.parseDouble(format);
        String format1 = df.format(cknu);
        double b = Double.parseDouble(format1);
        map.put("rknum", a);
        map.put("cknum", b);
        List list = new ArrayList();
        list.add(map);
        list.add(pages);
        return R.data(list);
    }
 
 
}