xuhy
2025-04-21 a1dd09b905842ae0e58537457861550c57454327
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
package com.ruoyi.admin.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.RecoveryClassify;
import com.ruoyi.admin.entity.RecoveryServe;
import com.ruoyi.admin.entity.RecoveryServePrice;
import com.ruoyi.admin.request.RecoveryServePriceRequest;
import com.ruoyi.admin.request.RecoveryServeRequest;
import com.ruoyi.admin.service.RecoveryClassifyService;
import com.ruoyi.admin.service.RecoveryServePriceService;
import com.ruoyi.admin.service.RecoveryServeService;
import com.ruoyi.admin.vo.RecoveryServeResultVO;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/recoveryServe")
@Api(tags = {"后台-回收管理-回收服务管理"})
public class RecoveryServeController {
 
    @Resource
    private RecoveryServeService recoveryServeService;
    @Resource
    private RecoveryClassifyService recoveryClassifyService;
    @Resource
    private RecoveryServePriceService recoveryServePriceService;
 
    /**
     * 回收服务分页列表
     *
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     */
    @RequiresPermissions("serve_recycling_list")
    @ApiOperation(value = "回收服务分页查询列表", tags = {"后台-回收管理-回收服务管理"})
    @GetMapping(value = "/page")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务名称", name = "serveName", dataType = "String"),
            @ApiImplicitParam(value = "回收价格起点", name = "startPrice", dataType = "String"),
            @ApiImplicitParam(value = "回收价格终点", name = "endPrice", dataType = "String"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<RecoveryServe>> queryPageList(String serveName, String startPrice, String endPrice,
                                                 @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryChainWrapper<RecoveryServe> wrapper = recoveryServeService.lambdaQuery();
        // 服务名称模糊匹配
        wrapper = StringUtils.isNotBlank(serveName) ? wrapper.like(RecoveryServe::getServeName, serveName) : wrapper;
        // 回收价格区间匹配
        wrapper = null != startPrice ? wrapper.ge(RecoveryServe::getDefaultPrice, startPrice) : wrapper;
        wrapper = null != endPrice ? wrapper.le(RecoveryServe::getDefaultPrice, endPrice) : wrapper;
        return R.ok(wrapper.eq(RecoveryServe::getIsDelete, 0)
                .orderByDesc(RecoveryServe::getCreateTime).page(Page.of(pageNum, pageSize)));
    }
    @ApiOperation(value = "服务名称下拉列表", tags = {"后台-订单管理-服务名称下拉列表"})
    @GetMapping(value = "/pageList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务名称", name = "serveName", dataType = "String"),
            @ApiImplicitParam(value = "回收价格起点", name = "startPrice", dataType = "String"),
            @ApiImplicitParam(value = "回收价格终点", name = "endPrice", dataType = "String"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<RecoveryServe>> pageList(String serveName, String startPrice, String endPrice,
                                                 @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryChainWrapper<RecoveryServe> wrapper = recoveryServeService.lambdaQuery();
        wrapper.orderByDesc(RecoveryServe::getSort);
        // 服务名称模糊匹配
        wrapper = StringUtils.isNotBlank(serveName) ? wrapper.like(RecoveryServe::getServeName, serveName) : wrapper;
        // 回收价格区间匹配
        wrapper = null != startPrice ? wrapper.ge(RecoveryServe::getDefaultPrice, startPrice) : wrapper;
        wrapper = null != endPrice ? wrapper.le(RecoveryServe::getDefaultPrice, endPrice) : wrapper;
        return R.ok(wrapper.eq(RecoveryServe::getIsDelete, 0)
                .page(Page.of(pageNum, pageSize)));
    }
 
    /**
     * 回收服务列表
     */
    @RequiresPermissions("serve_recycling_list")
    @ApiOperation(value = "回收服务列表", tags = {"后台-回收管理-回收服务管理"})
    @GetMapping(value = "/list")
    public R<List<RecoveryServe>> queryPageList() {
        return R.ok(recoveryServeService.lambdaQuery().eq(RecoveryServe::getIsDelete, 0)
                .orderByDesc(RecoveryServe::getCreateTime).list());
    }
 
    /**
     * 所属分类列表
     */
    @RequiresPermissions("serve_recycling_list")
    @ApiOperation(value = "所属分类列表", tags = {"后台-回收管理-回收服务管理"})
    @GetMapping(value = "/typeList")
    public R<List<RecoveryClassify>> typeList() {
        return R.ok(recoveryClassifyService.lambdaQuery()
                .eq(RecoveryClassify::getIsDelete, 0)
                .orderByDesc(RecoveryClassify::getCreateTime)
                .list());
    }
 
    /**
     * 回收服务详情
     *
     * @param id 回收服务id
     */
    @RequiresPermissions("serve_detail")
    @ApiOperation(value = "回收服务详情", tags = {"后台-回收管理-回收服务管理"})
    @GetMapping(value = "/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "回收服务id", name = "id", dataType = "Integer", required = true)
    })
    public R<RecoveryServeResultVO> detail(@RequestParam Integer id) {
        RecoveryServe recoveryServe = recoveryServeService.getById(id);
        List<RecoveryServePrice> priceList = recoveryServePriceService.lambdaQuery()
                .eq(RecoveryServePrice::getRecoveryServeId, id)
                .eq(RecoveryServePrice::getIsDelete, 0).list();
        return R.ok(new RecoveryServeResultVO(recoveryServe, priceList));
    }
 
    /**
     * 新增回收服务
     *
     * @param recoveryServeRequest 回收服务信息
     */
    @RequiresPermissions("serve_save")
    @ApiOperation(value = "新增回收服务", tags = {"后台-回收管理-回收服务管理"})
    @PostMapping(value = "/save")
    public R<String> save(@RequestBody RecoveryServeRequest recoveryServeRequest) {
        RecoveryServe serve = recoveryServeRequest.getServe();
        boolean save = recoveryServeService.save(serve);
        // 城市及对饮回收价
        if (null != recoveryServeRequest.getPriceList()) {
            for (RecoveryServePriceRequest data : recoveryServeRequest.getPriceList()) {
                BigDecimal recoveryPrice = data.getRecoveryPrice();
                String city = data.getCity();
                // 信息封装
                RecoveryServePrice price = new RecoveryServePrice();
                price.setRecoveryServeId(serve.getId());
                price.setRecoveryPrice(recoveryPrice);
                price.setCity(city);
                price.setCityCode(data.getCityCode());
                save = save && recoveryServePriceService.save(price);
            }
        }
        return save ? R.ok() : R.fail();
    }
 
    /**
     * 修改回收服务
     *
     * @param recoveryServeRequest 回收服务信息
     */
    @RequiresPermissions("serve_update")
    @ApiOperation(value = "修改回收服务", tags = {"后台-回收管理-回收服务管理"})
    @PostMapping(value = "/update")
    public R<String> update(@RequestBody RecoveryServeRequest recoveryServeRequest) {
        RecoveryServe serve = recoveryServeRequest.getServe();
        serve.setId(recoveryServeRequest.getId());
        boolean update = recoveryServeService.updateById(serve);
        // 城市及对应回收价
        List<RecoveryServePrice> priceList = recoveryServePriceService.lambdaQuery()
                .eq(RecoveryServePrice::getRecoveryServeId, recoveryServeRequest.getId())
                .eq(RecoveryServePrice::getIsDelete, 0).list();
        if (!priceList.isEmpty()) {
            for (RecoveryServePrice price : priceList) {
                price.setIsDelete(Constants.ONE);
            }
            update = update && recoveryServePriceService.updateBatchById(priceList);
        }
        // 新增省市及回收价
        if (null != recoveryServeRequest.getPriceList()) {
            for (RecoveryServePriceRequest data : recoveryServeRequest.getPriceList()) {
                BigDecimal recoveryPrice = data.getRecoveryPrice();
                String city = data.getCity();
                // 信息封装
                RecoveryServePrice price = new RecoveryServePrice();
                price.setRecoveryServeId(serve.getId());
                price.setRecoveryPrice(recoveryPrice);
                price.setCity(city);
                price.setCityCode(data.getCityCode());
                update = update && recoveryServePriceService.save(price);
            }
        }
        return update ? R.ok() : R.fail();
    }
 
    /**
     * 根据id批量删除回收服务
     *
     * @param ids 回收服务多条id拼接
     */
    @RequiresPermissions("serve_delete")
    @ApiOperation(value = "批量删除回收服务", tags = {"后台-回收管理-回收服务管理"})
    @GetMapping(value = "/batchDelete")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "多个id ',' 拼接", name = "ids", dataType = "String", required = true)
    })
    public R<String> batchDelete(@RequestParam String ids) {
        List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        List<RecoveryServe> list = recoveryServeService.lambdaQuery().in(RecoveryServe::getId, idList).list();
        list.forEach(data -> data.setIsDelete(1));
        recoveryServePriceService.lambdaUpdate()
                .set(RecoveryServePrice::getIsDelete, Constants.ONE)
                .in(RecoveryServePrice::getRecoveryServeId, idList).update();
        return recoveryServeService.updateBatchById(list) ? R.ok() : R.fail();
    }
 
}