智慧农业后台管理
guoshilong
2022-08-01 60c9b50a2f883e8a5f22a4bc21618c509e2bb76b
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
/*
 *      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.soldr.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.soldr.vo.SoldrVOs;
import org.springblade.modules.soldrecord.service.ISoldrecordService;
import org.springblade.modules.stock.entity.Stock;
import org.springblade.modules.stock.service.IStockService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.soldr.entity.Soldr;
import org.springblade.modules.soldr.vo.SoldrVO;
import org.springblade.modules.soldr.service.ISoldrService;
import org.springblade.core.boot.ctrl.BladeController;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 已出库存数量记录表 控制器
 *
 * @author BladeX
 * @since 2022-05-27
 */
@RestController
@AllArgsConstructor
@RequestMapping("/soldr/soldr")
@Api(value = "已出库存数量记录表", tags = "已出库存数量记录表接口")
public class SoldrController extends BladeController {
 
    private final ISoldrService soldrService;
    private final ISoldrecordService soldrecordService;
    private final IStockService stockService;
 
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入soldr")
    public R<Soldr> detail(Soldr soldr) {
        Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
        return R.data(detail);
    }
 
    /**
     * 分页 已出库存数量记录表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入soldr")
    public R<IPage<Soldr>> list(Soldr soldr, Query query) {
        IPage<Soldr> pages = soldrService.page(Condition.getPage(query), Condition.getQueryWrapper(soldr));
        return R.data(pages);
    }
 
    /**
     * 自定义分页 已出库存数量记录表
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入soldr")
    public R<IPage<SoldrVO>> page(SoldrVO soldr, Query query) {
        IPage<SoldrVO> pages = soldrService.selectLists(Condition.getPage(query), soldr);
        for (int i = 0; i < pages.getRecords().size(); i++) {
            String specs = pages.getRecords().get(i).getSpecs1();
            Integer amount = pages.getRecords().get(i).getAmount1();
            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);
    }
 
    /**
     * 新增 已出库存数量记录表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入soldr")
    public R save(@Valid @RequestBody Soldr soldr) {
        return R.status(soldrService.save(soldr));
    }
 
    /**
     * 修改 已出库存数量记录表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入soldr")
    public R update(@Valid @RequestBody Soldr soldr) {
        return R.status(soldrService.updateById(soldr));
    }
 
    /**
     * 新增或修改 已出库存数量记录表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入soldr")
    public R submit(@Valid @RequestBody Soldr soldr) {
        return R.status(soldrService.saveOrUpdate(soldr));
    }
 
 
    /**
     * 删除 已出库存数量记录表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(soldrService.deleteLogic(Func.toLongList(ids)));
    }
 
 
    /**
     * 退回
     * @param num 数量
     * @param id 农资id
     * @param type
     * @return
     */
    @PostMapping("/out")
    public R out(Integer num, Long id, Integer type) {
        //如果等于就修改并删除
        if (type == 0) {
            Stock stock = new Stock();
            stock.setId(id);
            Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
            Integer amount = detail1.getAmount();
            stock.setAmount(amount + num);
            stockService.Updaet(stock);
            //删除
            soldrService.del(id);
        }
        //如果小于就修改
        else {
            Soldr soldr = new Soldr();
            soldr.setSid(id);
            //通过农资库存id找到已出库农资表中对应的农资
            Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
            Integer amount1 = detail.getAmount1();
            Double census = detail.getCensus();
            //统计公斤
            Integer specsValue1 = detail.getSpecsVal1();
            double v = 0;
            //克
            if (specsValue1 == 0) {
                v = num * 0.001;
            }
            //斤
            else if (specsValue1 == 1) {
                v = num * 0.5;
            }
            //公斤
            else if (specsValue1 == 2) {
                v = num;
            }
            //吨
            else if (specsValue1 == 3) {
                v = num * 1000;
            }
            //毫升
            else if (specsValue1 == 4) {
                //毫升换成升
                double s = num * 0.001;
                //升换成公斤
                v = s;
            }
            //升
            else{
                v = num;
            }
            //更新已出库农资的数据
            soldrecordService.updateSold(amount1 - num, id,census-v);
            Stock stock = new Stock();
            stock.setId(id);
            //根据传过来的sid获取对应的库存表数据
            Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
            Integer amount = detail1.getAmount();
            stock.setAmount(amount + num);
            //更新库存表
            stockService.Updaet(stock);
        }
        return R.success("退回成功");
    }
 
 
    @GetMapping("/outs")
    public R outs(SoldrVOs soldrVOs) {
        //如果等于就修改并删除
        if (soldrVOs.getType().equals("0")) {
            Stock stock = new Stock();
            stock.setId(soldrVOs.getId());
            Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
            Integer amount = detail1.getAmount();
            stock.setAmount(amount + soldrVOs.getNum());
            stockService.Updaet(stock);
            //删除
            soldrService.del(soldrVOs.getId());
        }
        //如果小于就修改
        else {
            Soldr soldr = new Soldr();
            soldr.setSid(soldrVOs.getId());
            Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
            Integer amount1 = detail.getAmount1();
            Double census = detail.getCensus();
            //统计公斤
            Integer specsValue1 = detail.getSpecsVal1();
            double v = 0;
            //克
            if (specsValue1 == 0) {
                v = soldrVOs.getNum() * 0.001;
            }
            //斤
            if (specsValue1 == 1) {
                v = soldrVOs.getNum() * 0.5;
            }
            //公斤
            if (specsValue1 == 2) {
                v = soldrVOs.getNum();
            }
            //吨
            if (specsValue1 == 3) {
                v = soldrVOs.getNum() * 1000;
            }
            //毫升
            if (specsValue1 == 4) {
                //毫升换成升
                double s = soldrVOs.getNum() * 0.001;
                //升换成公斤
                v = s;
            }
            //升
            if (specsValue1 == 5) {
                v = soldrVOs.getNum();
            }
            soldrecordService.updateSold(amount1 - soldrVOs.getNum(), soldrVOs.getId(),census-v);
            Stock stock = new Stock();
            stock.setId(soldrVOs.getId());
            Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
            Integer amount = detail1.getAmount();
            stock.setAmount(amount + soldrVOs.getNum());
            stockService.Updaet(stock);
        }
        return R.success("退回成功");
    }
 
    /**
     * 已出农资列表
     *
     * @return
     */
    @GetMapping("/selectSol")
    public R selectSol() {
        List<SoldrVO> soldrVOS = soldrService.selectSol();
        for (int i = 0; i < soldrVOS.size(); i++) {
            String specs1 = soldrVOS.get(i).getSpecs1();
            String dic1 = soldrVOS.get(i).getDic1();
            String dic2 = soldrVOS.get(i).getDic2();
            String agrname = soldrVOS.get(i).getAgrname();
            String s = agrname + specs1 + dic1 + "/" + dic2;
            soldrVOS.get(i).setSpn(s);
        }
 
        return R.data(soldrVOS);
    }
 
}