| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.fasterxml.jackson.databind.util.BeanUtil; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.entity.Order; |
| | | import com.linghu.model.entity.Orders; |
| | | import com.linghu.model.dto.OrderDto; |
| | | import com.linghu.service.OrderService; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | * 订单管理接口 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/order") |
| | | @RequestMapping("/orders") |
| | | @Api(value = "订单管理接口", tags = "订单管理") |
| | | public class OrderController { |
| | | |
| | | @Autowired |
| | |
| | | * 新增订单 |
| | | */ |
| | | @PostMapping |
| | | public ResponseResult<Order> add(@RequestBody OrderDto orderDto) { |
| | | //将dto转entity |
| | | Order order = new Order(); |
| | | @ApiOperation(value = "新增订单") |
| | | public ResponseResult<Orders> add(@RequestBody OrderDto orderDto) { |
| | | // 将dto转entity |
| | | Orders order = new Orders(); |
| | | BeanUtils.copyProperties(orderDto, order); |
| | | |
| | | if (order.getClient_name() == null || order.getClient_name().trim().isEmpty()) { |
| | |
| | | String dateStr = dateFormat.format(new Date()); |
| | | |
| | | // 查询当天订单数量 |
| | | LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.likeRight(Order::getOrder_id, dateStr); |
| | | LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.likeRight(Orders::getOrder_id, dateStr); |
| | | long count = orderService.count(queryWrapper); |
| | | |
| | | // 生成订单ID |
| | |
| | | // 设置初始状态 |
| | | order.setStatus(1); // 待处理 |
| | | order.setDel_flag(0); // 未删除 |
| | | order.setCreate_time(new Date()); |
| | | //保存关键词 |
| | | boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto); |
| | | |
| | | order.setCreate_time(LocalDateTime.now()); |
| | | boolean save = orderService.save(order); |
| | | // 保存关键词 |
| | | boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto,order.getOrder_id()); |
| | | if (!saveOrderWithKeywords) { |
| | | return ResponseResult.error("添加关键词失败"); |
| | | } |
| | | |
| | | if (orderService.save(order)) { |
| | | if (save) { |
| | | return ResponseResult.success(order); |
| | | } |
| | | return ResponseResult.error("添加订单失败"); |
| | |
| | | * 删除订单(逻辑删除) |
| | | */ |
| | | @DeleteMapping("/{orderId}") |
| | | @ApiOperation(value = "删除订单") |
| | | public ResponseResult<Void> delete(@PathVariable String orderId) { |
| | | Order order = orderService.getById(orderId); |
| | | Orders order = orderService.getById(orderId); |
| | | if (order == null) { |
| | | return ResponseResult.error("订单不存在"); |
| | | } |
| | | |
| | | order.setDel_flag(1); |
| | | order.setUpdate_time(new Date()); |
| | | order.setUpdate_time(LocalDateTime.now()); |
| | | boolean success = orderService.updateById(order); |
| | | |
| | | if (orderService.updateById(order)) { |
| | | return ResponseResult.success(); |
| | | } |
| | | return ResponseResult.error("删除订单失败"); |
| | | return success ? ResponseResult.success() : ResponseResult.error("删除订单失败"); |
| | | } |
| | | |
| | | /** |
| | | * 更新订单 |
| | | */ |
| | | @PutMapping |
| | | public ResponseResult<Void> update(@RequestBody Order order) { |
| | | @ApiOperation(value = "更新订单") |
| | | public ResponseResult<Void> update(@RequestBody Orders order) { |
| | | if (order.getOrder_id() == null) { |
| | | return ResponseResult.error("订单ID不能为空"); |
| | | } |
| | |
| | | return ResponseResult.error("客户名称不能为空"); |
| | | } |
| | | |
| | | Order existingOrder = orderService.getById(order.getOrder_id()); |
| | | Orders existingOrder = orderService.getById(order.getOrder_id()); |
| | | if (existingOrder == null) { |
| | | return ResponseResult.error("订单不存在"); |
| | | } |
| | | |
| | | order.setUpdate_time(new Date()); |
| | | order.setUpdate_time(LocalDateTime.now()); |
| | | |
| | | if (orderService.updateById(order)) { |
| | | return ResponseResult.success(); |
| | |
| | | * 根据ID查询订单 |
| | | */ |
| | | @GetMapping("/{orderId}") |
| | | public ResponseResult<Order> getById(@PathVariable String orderId) { |
| | | Order order = orderService.getById(orderId); |
| | | @ApiOperation("根据ID查询订单") |
| | | public ResponseResult<Orders> getById(@PathVariable String orderId) { |
| | | Orders order = orderService.getById(orderId); |
| | | if (order == null || order.getDel_flag() == 1) { |
| | | return ResponseResult.error("订单不存在"); |
| | | } |
| | |
| | | * 查询订单列表 |
| | | */ |
| | | @GetMapping |
| | | public ResponseResult<List<Order>> list( |
| | | @ApiOperation("查询订单列表") |
| | | public ResponseResult<List<Orders>> list( |
| | | @RequestParam(required = false) Integer pageNum, |
| | | @RequestParam(required = false) Integer pageSize, |
| | | @RequestParam(required = false) String clientName, |
| | | @RequestParam(required = false) Integer status) { |
| | | @RequestParam(required = false) Integer status, |
| | | @RequestParam(required = false) String createTime) { |
| | | |
| | | LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Order::getDel_flag, 0); // 只查询未删除的订单 |
| | | LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Orders::getDel_flag, 0); // 只查询未删除的订单 |
| | | |
| | | // 添加查询条件 |
| | | if (clientName != null && !clientName.trim().isEmpty()) { |
| | | queryWrapper.like(Order::getClient_name, clientName); |
| | | queryWrapper.like(Orders::getClient_name, clientName); |
| | | } |
| | | if (status != null) { |
| | | queryWrapper.eq(Order::getStatus, status); |
| | | queryWrapper.eq(Orders::getStatus, status); |
| | | } |
| | | if (createTime != null) { |
| | | queryWrapper.like(Orders::getCreate_time, createTime); |
| | | } |
| | | |
| | | // 分页查询 |
| | | if (pageNum != null && pageSize != null) { |
| | | Page<Order> pageInfo = new Page<>(pageNum, pageSize); |
| | | Page<Order> result = orderService.page(pageInfo, queryWrapper); |
| | | Page<Orders> pageInfo = new Page<>(pageNum, pageSize); |
| | | Page<Orders> result = orderService.page(pageInfo, queryWrapper); |
| | | return ResponseResult.success(result.getRecords()); |
| | | } |
| | | |
| | | // 不分页 |
| | | List<Order> list = orderService.list(queryWrapper); |
| | | List<Orders> list = orderService.list(queryWrapper); |
| | | return ResponseResult.success(list); |
| | | } |
| | | } |