OrderController.java
8.88 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
package com.sl.ms.oms.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sl.ms.oms.dto.*;
import com.sl.ms.oms.entity.OrderEntity;
import com.sl.ms.oms.entity.OrderLocationEntity;
import com.sl.ms.oms.service.CrudOrderService;
import com.sl.ms.oms.service.OrderCargoService;
import com.sl.ms.oms.service.OrderLocationService;
import com.sl.ms.oms.service.OrderService;
import com.sl.transport.common.util.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 订单 前端控制器
*/
@Slf4j
@Api(tags = "订单管理")
@RestController
@RequestMapping("order")
public class OrderController {
@Resource
private OrderService orderService;
@Resource
private OrderLocationService orderLocationService;
@Resource
private CrudOrderService crudOrderService;
@Resource
private OrderCargoService orderCargoService;
/**
* 下单
*
* @param mailingSaveDTO 订单信息
* @return 订单信息
*/
@ApiOperation(value = "下单")
@PostMapping
public OrderDTO mailingSave(@RequestBody MailingSaveDTO mailingSaveDTO) throws Exception {
log.info("保存订单信息:{}", JSONUtil.toJsonStr(mailingSaveDTO));
return orderService.mailingSave(mailingSaveDTO);
}
/**
* 预估总价
*
* @param mailingSaveDTO 订单信息
* @return 预估信息
*/
@ApiOperation("预估总价")
@PostMapping("totalPrice")
public OrderCarriageDTO totalPrice(@RequestBody MailingSaveDTO mailingSaveDTO) {
return orderService.totalPrice(mailingSaveDTO);
}
@GetMapping("count")
@ApiOperation(value = "统计", notes = "统计各个状态的数量")
public List<OrderStatusCountDTO> count(@RequestParam("memberId") Long memberId) {
return crudOrderService.groupByStatus(memberId);
}
/**
* 修改订单信息
*
* @param id 订单id
* @param orderDTO 订单信息
* @return 订单信息
*/
@PutMapping("/{id}")
public OrderDTO updateById(@PathVariable(name = "id") Long id, @RequestBody OrderDTO orderDTO) {
orderDTO.setId(id);
OrderEntity order = BeanUtil.toBean(orderDTO, OrderEntity.class);
orderService.updateById(order);
return orderDTO;
}
/**
* 获取订单分页数据
*
* @param orderDTO 查询条件
* @return 订单分页数据
*/
@PostMapping("/page")
public PageResponse<OrderDTO> findByPage(@RequestBody OrderDTO orderDTO) {
IPage<OrderEntity> orderIPage = crudOrderService.findByPage(orderDTO.getPage(), orderDTO.getPageSize(), orderDTO);
List<OrderDTO> dtoList = new ArrayList<>();
orderIPage.getRecords().forEach(order -> dtoList.add(BeanUtil.toBean(order, OrderDTO.class)));
return PageResponse.<OrderDTO>builder()
.items(dtoList)
.pageSize(orderDTO.getPageSize())
.page(orderDTO.getPage())
.counts(orderIPage.getTotal())
.pages(orderIPage.getPages()).build();
}
/**
* 根据id获取订单详情
*
* @param id 订单Id
* @return 订单详情
*/
@GetMapping("/{id}")
public OrderDTO findById(@PathVariable(name = "id") Long id) {
OrderEntity orderEntity = orderService.getById(id);
if (ObjectUtil.isNotEmpty(orderEntity)) {
return BeanUtil.toBean(orderEntity, OrderDTO.class);
}
return null;
}
/**
* 根据id获取订单详情
*
* @param id 订单Id
* @return 订单详情
*/
@GetMapping("detail/{id}")
public OrderDetailDTO findDetailByOrderId(@PathVariable(name = "id") Long id) {
OrderDetailDTO orderDetailDTO = new OrderDetailDTO();
OrderEntity orderEntity = orderService.getById(id);
if (ObjectUtil.isEmpty(orderEntity)) {
return null;
}
OrderDTO orderDTO = BeanUtil.toBean(orderEntity, OrderDTO.class);
orderDetailDTO.setOrderDTO(orderDTO);
OrderLocationDTO orderLocationByOrderId = orderLocationService.findOrderLocationByOrderId(id);
orderDetailDTO.setOrderLocationDTO(orderLocationByOrderId);
OrderCargoDTO orderCargoDTO = orderCargoService.findByOrderId(id);
orderDetailDTO.getOrderDTO().setOrderCargoDto(orderCargoDTO);
return orderDetailDTO;
}
/**
* 根据ids获取集合
*
* @param ids 订单Ids
* @return 订单详情
*/
@GetMapping("ids")
public List<OrderDTO> findByIds(@RequestParam(name = "ids") List<Long> ids) {
List<OrderEntity> orders = orderService.listByIds(ids);
return orders.stream().map(item -> BeanUtil.toBean(item, OrderDTO.class))
.collect(Collectors.toList());
}
/**
* 列表查询
* @param orderSearchDTO 条件
* @return 订单列表
*/
@ResponseBody
@PostMapping("list")
public List<OrderDTO> list(@RequestBody OrderSearchDTO orderSearchDTO) {
LambdaQueryWrapper<OrderEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ObjectUtil.isNotEmpty(orderSearchDTO.getStatus()), OrderEntity::getStatus, orderSearchDTO.getStatus());
wrapper.in(CollUtil.isNotEmpty(orderSearchDTO.getReceiverCountyIds()), OrderEntity::getReceiverCountyId, orderSearchDTO.getReceiverCountyIds());
wrapper.in(CollUtil.isNotEmpty(orderSearchDTO.getSenderCountyIds()), OrderEntity::getSenderCountyId, orderSearchDTO.getSenderCountyIds());
wrapper.eq(ObjectUtil.isNotEmpty(orderSearchDTO.getCurrentAgencyId()), OrderEntity::getCurrentAgencyId, orderSearchDTO.getCurrentAgencyId());
//快递员端进行条件查询取派件任务时,会传入关键词,作为订单id或姓名或手机号查询条件
if (StringUtils.isNotBlank(orderSearchDTO.getKeyword())) {
wrapper.like(ObjectUtil.isNotEmpty(orderSearchDTO.getOrderId()), OrderEntity::getId, orderSearchDTO.getKeyword())
.or().like(ObjectUtil.isNotEmpty(orderSearchDTO.getSenderName()), OrderEntity::getSenderName, orderSearchDTO.getSenderName())
.or().like(ObjectUtil.isNotEmpty(orderSearchDTO.getSenderPhone()), OrderEntity::getSenderPhone, orderSearchDTO.getSenderPhone())
.or().like(ObjectUtil.isNotEmpty(orderSearchDTO.getReceiverName()), OrderEntity::getReceiverName, orderSearchDTO.getReceiverName())
.or().like(ObjectUtil.isNotEmpty(orderSearchDTO.getReceiverPhone()), OrderEntity::getReceiverPhone, orderSearchDTO.getReceiverPhone());
}
return orderService.list(wrapper).stream().map(order -> BeanUtil.toBean(order, OrderDTO.class)).collect(Collectors.toList());
}
/**
* 查询订单位置
* @param orderId 订单ID
* @return 位置
*/
@GetMapping("location/{orderId}")
public OrderLocationDTO findOrderLocationByOrderId(@PathVariable(name = "orderId") Long orderId) {
return orderLocationService.findOrderLocationByOrderId(orderId);
}
/**
* 根据orderId列表查询订单的location信息
*
* @param orderIds 订单id列表
* @return 位置
*/
@GetMapping("locations")
public List<OrderLocationDTO> findOrderLocationByOrderIds(@RequestParam("orderIds") List<Long> orderIds) {
QueryWrapper<OrderLocationEntity> queryWrapper = new QueryWrapper<OrderLocationEntity>()
.in("order_id", orderIds);
List<OrderLocationEntity> locationList = orderLocationService.list(queryWrapper);
if (CollUtil.isNotEmpty(locationList)) {
return locationList.stream().map(location -> {
OrderLocationDTO locationDTO = new OrderLocationDTO();
BeanUtil.copyProperties(location, locationDTO);
return locationDTO;
}).collect(Collectors.toList());
}
return new ArrayList<>();
}
/**
* 取件更新
* @param orderPickupDTO 取件更新信息
*/
@PutMapping("orderPickup")
void orderPickup(@RequestBody OrderPickupDTO orderPickupDTO) {
crudOrderService.orderPickup(orderPickupDTO);
}
/**
* 状态更新
* @param orderId 订单ID
* @param code 状态码
*/
@PutMapping("updateStatus")
void updateStatus(@RequestParam("orderId") List<Long> orderId, @RequestParam("code") Integer code) {
crudOrderService.updateStatus(orderId, code);
}
}