GarOrderServiceImpl.java
12.9 KB
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
package com.trash.garbage.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.trash.common.utils.StringUtils;
import com.trash.enterprise.domain.TransportationEnterprise;
import com.trash.enterprise.service.ITransportationEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trash.common.utils.SecurityUtils;
import com.trash.common.utils.bean.BeanUtils;
import com.trash.driver.domain.vo.DriverVo;
import com.trash.driver.service.IDriverService;
import com.trash.garbage.global.GlobalStatus;
import com.trash.garbage.mapper.GarOrderMapper;
import com.trash.garbage.pojo.domain.GarOrder;
import com.trash.garbage.pojo.domain.GarOrderEvaluate;
import com.trash.garbage.pojo.domain.GarOrderImage;
import com.trash.garbage.pojo.domain.GarUser;
import com.trash.garbage.pojo.dto.EvaluateDto;
import com.trash.garbage.pojo.dto.OrderDto;
import com.trash.garbage.pojo.dto.OrderUpdateDto;
import com.trash.garbage.pojo.dto.UploadDto;
import com.trash.garbage.pojo.vo.OrderDetailVo;
import com.trash.garbage.service.GarOrderEvaluateService;
import com.trash.garbage.service.GarOrderImageService;
import com.trash.garbage.service.GarOrderService;
import com.trash.garbage.service.GarUserService;
import cn.hutool.core.collection.CollectionUtil;
/**
* @author 20412
* @description 针对表【gar_order(建筑垃圾—订单表)】的数据库操作Service实现
* @createDate 2023-11-24 16:26:19
*/
@Service
public class GarOrderServiceImpl extends ServiceImpl<GarOrderMapper, GarOrder>
implements GarOrderService {
@Autowired
private GarOrderImageService garOrderImageService;
@Autowired
private GarOrderEvaluateService garOrderEvaluateService;
@Autowired
private GarUserService garUserService;
@Autowired
private IDriverService driverService;
@Autowired
private ITransportationEnterpriseService enterpriseService;
@Override
@Transactional(rollbackFor = Exception.class)
public String saveOrder(OrderDto dto) {
String userId = SecurityUtils.getLoginUser().getUser().getUserId();
GarOrder order = new GarOrder();
BeanUtils.copyBeanProp(order, dto);
order.setGarOrderUserId(userId);
order.setGarOrderHandlerStatus(GlobalStatus.GarOrderStatus.NEW_ORDER.getValue());
order.setGarCancelFlag(GlobalStatus.GarOrderStatus.CANCEL_FLAG_NO.getValue());
save(order);
// 保存图片url
List<String> imageUrls = dto.getImageUrls();
List<GarOrderImage> images = new ArrayList<>(imageUrls.size());
for (String imageUrl : imageUrls) {
GarOrderImage image = new GarOrderImage();
image.setGarOrderId(order.getGarOrderId());
image.setGarOrderImageUrl(imageUrl);
image.setGarOrderImageType(GlobalStatus.GarOrderStatus.IMAGE_TYPE_CURRENT.getValue());
images.add(image);
}
garOrderImageService.saveBatch(images);
return order.getGarOrderId();
}
@Override
public OrderDetailVo queryOrderDetail(String id) {
GarOrder order = this.getById(id);
String tel = SecurityUtils.getLoginUser().getUser().getPhonenumber();
LambdaQueryWrapper<GarOrderImage> qwi = new LambdaQueryWrapper<>();
qwi.eq(GarOrderImage::getGarOrderId, id);
OrderDetailVo vo = new OrderDetailVo();
BeanUtils.copyBeanProp(vo, order);
DriverVo driverVo = new DriverVo();
driverVo.setPhoneNo(tel);
List<DriverVo> driverVos = driverService.selectDriverList(driverVo);
if (CollectionUtil.isNotEmpty(driverVos)) {
vo.setHandleFlag(true);
vo.setGarHandleEvaluateFlag(false);
}
List<GarOrderImage> imageList = garOrderImageService.list(qwi);
for (GarOrderImage image : imageList) {
if (GlobalStatus.GarOrderStatus.CANCEL_FLAG_NO.getValue().equals(image.getGarOrderImageType())) {
vo.getCurrentImages().add(image.getGarOrderImageUrl());
}
if (GlobalStatus.GarOrderStatus.IMAGE_TYPE_PUT_ON.getValue().equals(image.getGarOrderImageType())) {
vo.getPutOnImages().add(image.getGarOrderImageUrl());
}
if (GlobalStatus.GarOrderStatus.IMAGE_TYPE_PUT_DOWN.getValue().equals(image.getGarOrderImageType())) {
vo.getPutDownImages().add(image.getGarOrderImageUrl());
}
}
if (StringUtils.isNotEmpty(vo.getGarOrderHandlerId())) {
if (vo.getHandleFlag()) {
vo.setGarOrderHandleName(driverVos.get(0).getName());
vo.setGarOrderHandleTel(driverVo.getPhoneNo());
}
}
return vo;
}
@Override
public PageInfo queryOrderList(Integer type, Integer pageNo, Integer pageSize) {
String userId = SecurityUtils.getLoginUser().getUser().getUserId();
GarUser user = garUserService.getById(userId);
LambdaQueryWrapper<GarOrder> qw = new LambdaQueryWrapper<>();
qw.orderByAsc(GarOrder::getGarEvaluateFlag, GarOrder::getGarOrderHandlerStatus);
// 居民用户
if (user.getGarUserType().equals(GlobalStatus.UserStatusEnum.NORMAL_USER.getDescription())) {
PageHelper.startPage(pageNo, pageSize);
// 待清运 || 清运中 || 已完成 || 待支付
if (GlobalStatus.GarOrderStatus.NEW_ORDER.getValue().equals(type)
|| GlobalStatus.GarOrderStatus.ACTIVE_ORDER.getValue().equals(type)
|| GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue().equals(type)) {
qw.eq(GarOrder::getGarOrderUserId, userId)
.eq(GarOrder::getGarCancelFlag, GlobalStatus.GarOrderStatus.CANCEL_FLAG_NO.getValue())
.eq(GarOrder::getGarOrderHandlerStatus, type);
List<GarOrder> orderList = list(qw);
PageInfo<GarOrder> pageInfo = new PageInfo<GarOrder>(orderList, pageSize);
return pageInfo;
}
// 全部
if (GlobalStatus.GarOrderStatus.ALL_ORDER.getValue().equals(type)) {
qw.eq(GarOrder::getGarOrderUserId, userId);
List<GarOrder> orderList = list(qw);
PageInfo<GarOrder> pageInfo = new PageInfo<GarOrder>(orderList, pageSize);
return pageInfo;
}
} else {
DriverVo driver = new DriverVo();
driver.setPhoneNo(user.getGarUserTel());
List<DriverVo> driverList = driverService.selectDriverList(driver);
// 负责人不存在
if (CollectionUtil.isEmpty(driverList)) {
return new PageInfo<GarOrder>(Collections.emptyList(), pageSize);
}
DriverVo driverVo = driverList.get(0);
TransportationEnterprise enterprise = enterpriseService.selectTransportationEnterpriseById(driverVo.getCompanyId());
PageHelper.startPage(pageNo, pageSize);
if (GlobalStatus.GarOrderStatus.NEW_ORDER.getValue().equals(type)) {
qw.eq(GarOrder::getGarOrderCompanyId, enterprise.getParentId())
.eq(GarOrder::getGarCancelFlag, GlobalStatus.GarOrderStatus.CANCEL_FLAG_NO.getValue())
.eq(GarOrder::getGarOrderHandlerStatus, GlobalStatus.GarOrderStatus.NEW_ORDER.getValue());
List<GarOrder> orderList = list(qw);
PageInfo<GarOrder> pageInfo = new PageInfo<GarOrder>(orderList, pageSize);
return pageInfo;
}
if (GlobalStatus.GarOrderStatus.ACTIVE_ORDER.getValue().equals(type)
|| GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue().equals(type)) {
qw.eq(GarOrder::getGarOrderCompanyId, enterprise.getParentId())
.eq(GarOrder::getGarOrderHandlerId, user.getGarUserId())
.eq(GarOrder::getGarCancelFlag, GlobalStatus.GarOrderStatus.CANCEL_FLAG_NO.getValue())
.eq(GarOrder::getGarOrderHandlerStatus, type);
List<GarOrder> orderList = list(qw);
PageInfo<GarOrder> pageInfo = new PageInfo<GarOrder>(orderList, pageSize);
return pageInfo;
}
// 全部
if (GlobalStatus.GarOrderStatus.ALL_ORDER.getValue().equals(type)) {
qw.eq(GarOrder::getGarOrderHandlerId, userId);
List<GarOrder> orderList = list(qw);
PageInfo<GarOrder> pageInfo = new PageInfo<GarOrder>(orderList, pageSize);
return pageInfo;
}
}
return null;
}
@Override
public String uploadOrder(OrderUpdateDto dto) {
GarOrder order = getById(dto.getGarOrderId());
String userId = SecurityUtils.getLoginUser().getUser().getUserId();
GarUser user = garUserService.getById(userId);
// 取消订单
if (GlobalStatus.GarOrderStatus.CANCEL_FLAG_YES.getValue().equals(dto.getGarCancelFlag())) {
LambdaUpdateWrapper<GarOrder> uw = new LambdaUpdateWrapper<>();
uw.set(GarOrder::getGarCancelFlag, dto.getGarCancelFlag())
.set(GarOrder::getGarReason, dto.getGarReason())
.eq(GarOrder::getGarOrderId, dto.getGarOrderId());
update(uw);
return "订单取消成功";
}
// 运输员操作 TODO 公司所属 待清运- 》 清运中
if (GlobalStatus.UserStatusEnum.DRIVER_USER.getDescription().equals(user.getGarUserType())) {
if (order.getGarOrderHandlerStatus().equals(GlobalStatus.GarOrderStatus.NEW_ORDER.getValue())
|| GlobalStatus.GarOrderStatus.NEW_ORDER.getValue().equals(dto.getHandleType())) {
LambdaUpdateWrapper<GarOrder> uw = new LambdaUpdateWrapper<>();
uw.eq(GarOrder::getGarOrderId, dto.getGarOrderId())
.set(GarOrder::getGarOrderHandlerStatus, GlobalStatus.GarOrderStatus.ACTIVE_ORDER.getValue())
.set(GarOrder::getGarOrderHandlerId, userId);
update(uw);
return "已接受派单";
}
// 运输员操作 清运中 ==》已完成
if (GlobalStatus.GarOrderStatus.ACTIVE_ORDER.getValue().equals(order.getGarOrderHandlerStatus())
&& GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue().equals(dto.getHandleType())) {
LambdaUpdateWrapper<GarOrder> uw = new LambdaUpdateWrapper<>();
uw.eq(GarOrder::getGarOrderId, dto.getGarOrderId())
.set(GarOrder::getGarOrderHandlerStatus, GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue())
.set(GarOrder::getGarEvaluateFlag, GlobalStatus.GarOrderStatus.EVALUATE_ORDER_NO.getValue());
update(uw);
}
return "派单已完成";
}
return "什么都没发生";
}
@Override
public String uploadImageUrlByType(UploadDto dto) {
List<GarOrderImage> garOrderImages = new ArrayList<>(dto.getImageUrls().size());
for (String imageUrl : dto.getImageUrls()) {
GarOrderImage orderImage = new GarOrderImage();
orderImage.setGarOrderId(dto.getGarOrderId());
orderImage.setGarOrderImageUrl(imageUrl);
orderImage.setGarOrderImageType(dto.getType());
garOrderImages.add(orderImage);
}
garOrderImageService.saveBatch(garOrderImages);
return "上传成功!";
}
@Override
public String evaluateOrder(EvaluateDto dto) {
String userId = SecurityUtils.getLoginUser().getUser().getUserId();
GarUser user = garUserService.getById(userId);
GarOrder order = getById(dto.getOrderId());
// TODO 用户评价
if (GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue().equals(order.getGarOrderHandlerStatus())) {
evaluate(dto, order);
}
return "已评价";
}
private void evaluate(EvaluateDto dto, GarOrder order) {
GarOrderEvaluate evaluate = new GarOrderEvaluate();
evaluate.setGarOrderId(order.getGarOrderId());
evaluate.setGarEvaluateContent(dto.getContent());
evaluate.setGarEvaluateScore(dto.getScore());
garOrderEvaluateService.save(evaluate);
// 修改订单评价状态
LambdaUpdateWrapper<GarOrder> uw = new LambdaUpdateWrapper<>();
uw.eq(GarOrder::getGarOrderId, order.getGarOrderId())
.set(GarOrder::getGarEvaluateFlag, GlobalStatus.GarOrderStatus.EVALUATE_ORDER_YES.getValue());
update(uw);
}
}