OrderInfoController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.izouma.tcg.web.orderInfo;
  2. import com.izouma.tcg.domain.card.CardBox;
  3. import com.izouma.tcg.dto.OrderInfoDTO;
  4. import com.izouma.tcg.enums.OrderStatus;
  5. import com.izouma.tcg.repo.card.CardBoxRepo;
  6. import com.izouma.tcg.utils.LogisticsQueryResponse;
  7. import com.izouma.tcg.web.BaseController;
  8. import com.izouma.tcg.domain.orderInfo.OrderInfo;
  9. import com.izouma.tcg.service.orderInfo.OrderInfoService;
  10. import com.izouma.tcg.dto.PageQuery;
  11. import com.izouma.tcg.exception.BusinessException;
  12. import com.izouma.tcg.repo.orderInfo.OrderInfoRepo;
  13. import com.izouma.tcg.utils.ObjUtils;
  14. import com.izouma.tcg.utils.excel.ExcelUtils;
  15. import io.swagger.annotations.ApiModel;
  16. import io.swagger.annotations.ApiOperation;
  17. import lombok.AllArgsConstructor;
  18. import org.apache.commons.beanutils.ConvertUtils;
  19. import org.springframework.data.domain.Page;
  20. import org.springframework.security.access.prepost.PreAuthorize;
  21. import org.springframework.web.bind.annotation.*;
  22. import javax.print.DocFlavor;
  23. import javax.servlet.http.HttpServletResponse;
  24. import javax.transaction.Transaction;
  25. import java.io.IOException;
  26. import java.util.Arrays;
  27. import java.util.List;
  28. import java.util.Map;
  29. @RestController
  30. @RequestMapping("/orderInfo")
  31. @AllArgsConstructor
  32. public class OrderInfoController extends BaseController {
  33. private OrderInfoService orderInfoService;
  34. private OrderInfoRepo orderInfoRepo;
  35. private CardBoxRepo cardBoxRepo;
  36. //@PreAuthorize("hasRole('ADMIN')")
  37. @PostMapping("/save")
  38. public OrderInfo save(@RequestBody OrderInfo record) {
  39. if (record.getId() != null) {
  40. OrderInfo orig = orderInfoRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  41. ObjUtils.merge(orig, record);
  42. return orderInfoRepo.save(orig);
  43. }
  44. return orderInfoRepo.save(record);
  45. }
  46. //@PreAuthorize("hasRole('ADMIN')")
  47. @PostMapping("/all")
  48. public Page<OrderInfo> all(@RequestBody PageQuery pageQuery) {
  49. return orderInfoService.all(pageQuery);
  50. }
  51. @GetMapping("/get/{id}")
  52. public OrderInfo get(@PathVariable Long id) {
  53. OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  54. if (orderInfo.getCardBoxList().size() < 1 & orderInfo.getCardBoxStr() != null) {
  55. List<Long> boxIds = Arrays
  56. .asList((Long[]) ConvertUtils.convert(orderInfo.getCardBoxStr().split(","), Long.class));
  57. List<CardBox> cardBoxList = cardBoxRepo.findAllByIdIn(boxIds);
  58. orderInfo.setCardBoxList(cardBoxList);
  59. }
  60. return orderInfo;
  61. }
  62. @PostMapping("/del/{id}")
  63. public void del(@PathVariable Long id) {
  64. orderInfoRepo.softDelete(id);
  65. }
  66. @GetMapping("/excel")
  67. @ResponseBody
  68. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  69. List<OrderInfo> data = all(pageQuery).getContent();
  70. ExcelUtils.export(response, data);
  71. }
  72. @PostMapping("/createOrderInfo")
  73. @ApiOperation("创建订单")
  74. public OrderInfo create(String boxIds, Long caseId, String remark, Long userAddressId) {
  75. return orderInfoService.create(boxIds, caseId, remark, userAddressId);
  76. }
  77. @GetMapping("/showPreview")
  78. @ApiOperation(("展示订单预览"))
  79. public Map<String, Object> showPreview(String boxIds, Long caseId) {
  80. return orderInfoService.showPreview(boxIds, caseId);
  81. }
  82. @GetMapping("/checkBox")
  83. @ApiOperation(("展示订单预览"))
  84. public boolean checkBox(String boxIds, Long caseId) {
  85. return orderInfoService.checkBox(boxIds, caseId);
  86. }
  87. @PostMapping("/pay")
  88. @ApiOperation("完成支付")
  89. public void pay(Long orderInfoId, String transactionId) {
  90. orderInfoService.pay(orderInfoId, transactionId);
  91. }
  92. @PostMapping("/cancel")
  93. @ApiOperation("/取消订单")
  94. public void cancel(Long orderInfoId) {
  95. orderInfoService.cancel(orderInfoId);
  96. }
  97. @PostMapping("/finish")
  98. @ApiOperation("/完成订单")
  99. public void finish(Long orderInfoId, @RequestParam(required = false) String finish) {
  100. orderInfoService.confirm(orderInfoId, finish);
  101. }
  102. @PostMapping("/send")
  103. @ApiOperation("/订单送货")
  104. public void send(Long orderInfoId, String logisticNo, String type, String remark) {
  105. orderInfoService.send(orderInfoId, logisticNo, type, remark);
  106. }
  107. @GetMapping("/checkLogistic")
  108. @ApiOperation("/查询物流")
  109. public Map<String, Object> checkLogistic(Long orderInfoId) {
  110. return orderInfoService.checkLogistics(orderInfoId);
  111. }
  112. @GetMapping("/showMyOrderInfos")
  113. @ApiOperation("/展示订单列表")
  114. public List<OrderInfoDTO> showMyOrderInfos(Long userId, OrderStatus orderStatus, @RequestParam(required = false) Long orderInfoId, @RequestParam(required = false) Long storeId) {
  115. return orderInfoService.showMyOrderInfos(userId, orderStatus, orderInfoId);
  116. }
  117. @PostMapping("/refund")
  118. @ApiOperation("/展示订单列表")
  119. public void refund(Long orderInfoId, String remark) {
  120. orderInfoService.refund(orderInfoId, remark);
  121. }
  122. @PostMapping("/afterSale")
  123. @ApiOperation("/展示订单列表")
  124. public void afterSale(Long orderInfoId, String remark, List<String> images) {
  125. orderInfoService.newAfterSale(orderInfoId, remark, images);
  126. }
  127. @PostMapping("/remindMy")
  128. @ApiOperation("/展示订单列表")
  129. public void remindMy(Long orderInfoId, String remark) {
  130. }
  131. @PostMapping("/delete")
  132. @ApiOperation("/删除完成订单")
  133. public void delete(Long orderInfoId) {
  134. orderInfoService.delete(orderInfoId);
  135. }
  136. @PostMapping("/saveLogistic")
  137. @ApiOperation("/发货")
  138. public void delete(Long id, String logisticNo, @RequestParam(required = false) String logisticType) {
  139. orderInfoService.saveLogistic(id, logisticNo, logisticType);
  140. }
  141. }