| | |
| | | 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.Keyword; |
| | | import com.linghu.model.entity.Orders; |
| | | import com.linghu.model.dto.KeywordDto; |
| | | import com.linghu.model.dto.OrderDto; |
| | | import com.linghu.model.page.CustomPage; |
| | | import com.linghu.service.KeywordService; |
| | | import com.linghu.service.OrderService; |
| | | |
| | | import io.swagger.annotations.Api; |
| | |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | |
| | | @Autowired |
| | | private KeywordService keywordService; |
| | | |
| | | /** |
| | | * 新增订单 |
| | |
| | | if (!saveOrderWithKeywords) { |
| | | return ResponseResult.error("添加关键词失败"); |
| | | } |
| | | //更新关键词数量 |
| | | LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper = new LambdaQueryWrapper<>(); |
| | | queryKeywordsQueryWrapper.eq(Keyword::getOrder_id, order.getOrder_id()); |
| | | int count1 = keywordService.count(queryKeywordsQueryWrapper); |
| | | order.setKeyword_num(count1); |
| | | order.setUpdate_time(LocalDateTime.now()); |
| | | orderService.updateById(order); |
| | | |
| | | if (save) { |
| | | return ResponseResult.success(order); |
| | |
| | | */ |
| | | @PutMapping |
| | | @ApiOperation(value = "更新订单") |
| | | public ResponseResult<Void> update(@RequestBody Orders order) { |
| | | if (order.getOrder_id() == null) { |
| | | public ResponseResult<Void> update(@RequestBody OrderDto orderDto) { |
| | | if (orderDto.getOrder_id() == null) { |
| | | return ResponseResult.error("订单ID不能为空"); |
| | | } |
| | | if (order.getClient_name() == null || order.getClient_name().trim().isEmpty()) { |
| | | if (orderDto.getClient_name() == null || orderDto.getClient_name().trim().isEmpty()) { |
| | | return ResponseResult.error("客户名称不能为空"); |
| | | } |
| | | |
| | | Orders existingOrder = orderService.getById(order.getOrder_id()); |
| | | Orders existingOrder = orderService.getById(orderDto.getOrder_id()); |
| | | if (existingOrder == null) { |
| | | return ResponseResult.error("订单不存在"); |
| | | } |
| | | |
| | | order.setUpdate_time(LocalDateTime.now()); |
| | | orderDto.setUpdate_time(LocalDateTime.now()); |
| | | if (orderDto.getKeywords()!= null&&orderDto.getKeywords().trim().length() > 0){ |
| | | // 保存关键词 |
| | | boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto, orderDto.getOrder_id()); |
| | | if (!saveOrderWithKeywords) { |
| | | return ResponseResult.error("添加关键词失败"); |
| | | } |
| | | } |
| | | //更新关键词数量 |
| | | LambdaQueryWrapper<Keyword> queryKeywordsQueryWrapper = new LambdaQueryWrapper<>(); |
| | | queryKeywordsQueryWrapper.eq(Keyword::getOrder_id, orderDto.getOrder_id()); |
| | | int count1 = keywordService.count(queryKeywordsQueryWrapper); |
| | | orderDto.setKeyword_num(count1); |
| | | |
| | | if (orderService.updateById(order)) { |
| | | |
| | | |
| | | if (orderService.updateById(orderDto)) { |
| | | return ResponseResult.success(); |
| | | } |
| | | return ResponseResult.error("更新订单失败"); |
| | |
| | | */ |
| | | @GetMapping |
| | | @ApiOperation("查询订单列表") |
| | | public ResponseResult<Page<Orders>> list( |
| | | @RequestParam(required = false,defaultValue = "1") Integer pageNum , |
| | | @RequestParam(required = false,defaultValue = "10") Integer pageSize , |
| | | public ResponseResult<CustomPage<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) String createTime) { |
| | | |
| | | LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Orders::getDel_flag, 0); // 只查询未删除的订单 |
| | | queryWrapper.eq(Orders::getDel_flag, 0); |
| | | |
| | | // 添加查询条件 |
| | | if (clientName != null && !clientName.trim().isEmpty()) { |
| | |
| | | } |
| | | |
| | | // 分页查询 |
| | | if (pageNum != null && pageSize != null) { |
| | | Page<Orders> pageInfo = new Page<>(pageNum, pageSize); |
| | | Page<Orders> result = orderService.page(pageInfo, queryWrapper); |
| | | return ResponseResult.success(result); |
| | | return ResponseResult.success(new CustomPage<>(result)); |
| | | } |
| | | |
| | | // 不分页查询:手动创建 CustomPage |
| | | List<Orders> list = orderService.list(queryWrapper); |
| | | CustomPage<Orders> page = new CustomPage<>(new Page<>()); |
| | | page.setRecords(list); |
| | | page.setTotal(list.size()); |
| | | |
| | | return ResponseResult.success(page); |
| | | } |
| | | |
| | | @GetMapping("/{orderId}/keywordList") |