RepairController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package com.ym.mec.student.controller;
  2. import com.ym.mec.auth.api.client.SysUserFeignService;
  3. import com.ym.mec.auth.api.entity.SysUser;
  4. import com.ym.mec.biz.dal.entity.StudentGoodsSell;
  5. import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
  6. import com.ym.mec.biz.dal.entity.StudentRepair;
  7. import com.ym.mec.biz.dal.enums.DealStatusEnum;
  8. import com.ym.mec.biz.dal.enums.GroupType;
  9. import com.ym.mec.biz.dal.enums.OrderTypeEnum;
  10. import com.ym.mec.biz.dal.enums.PayStatus;
  11. import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
  12. import com.ym.mec.biz.dal.page.GoodsQueryInfo;
  13. import com.ym.mec.biz.dal.page.GoodsSellQueryInfo;
  14. import com.ym.mec.biz.dal.page.RepairStudentQueryInfo;
  15. import com.ym.mec.biz.service.*;
  16. import com.ym.mec.common.controller.BaseController;
  17. import com.ym.mec.common.entity.HttpResponseResult;
  18. import com.ym.mec.common.exception.BizException;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.http.HttpStatus;
  23. import org.springframework.web.bind.annotation.*;
  24. import java.util.List;
  25. import java.util.Map;
  26. @RequestMapping("repair")
  27. @Api(tags = "学生维修服务")
  28. @RestController
  29. public class RepairController extends BaseController {
  30. @Autowired
  31. private SysUserFeignService sysUserFeignService;
  32. @Autowired
  33. private StudentRepairService studentRepairService;
  34. @Autowired
  35. private StudentPaymentOrderService studentPaymentOrderService;
  36. @Autowired
  37. private GoodsService goodsService;
  38. @Autowired
  39. private GoodsCategoryService goodsCategoryService;
  40. @Autowired
  41. private StudentGoodsSellService studentGoodsSellService;
  42. @ApiOperation("添加商品销售订单")
  43. @PostMapping(value = "/addGoodsSellOrder")
  44. public HttpResponseResult addGoodsSellOrder(@RequestBody StudentGoodsSell studentGoodsSell) throws Exception {
  45. if(studentGoodsSell.getUserId() == null){
  46. SysUser sysUser = sysUserFeignService.queryUserInfo();
  47. if (sysUser == null) {
  48. throw new BizException("请登录");
  49. }
  50. studentGoodsSell.setUserId(sysUser.getId());
  51. }
  52. if (studentGoodsSell.getIsRepeatPay() == false) {
  53. List<StudentPaymentOrder> list = studentPaymentOrderService.queryByCondition(GroupType.GOODS_SELL, null, studentGoodsSell.getUserId(), DealStatusEnum.ING,
  54. OrderTypeEnum.GOODS_SELL);
  55. if (list.size() > 0) {
  56. StudentPaymentOrder applyOrder = list.get(list.size() - 1);
  57. // 查询订单状态
  58. PayStatus payStatus = studentPaymentOrderService.queryPayStatus(applyOrder.getPaymentChannel(), applyOrder.getOrderNo(), applyOrder.getTransNo());
  59. if(payStatus == PayStatus.SUCCESSED){
  60. throw new BizException("订单已支付成功,请勿重复支付");
  61. }else if(payStatus == PayStatus.PAYING){
  62. throw new BizException("订单还在交易中,请稍后重试");
  63. }
  64. return failed(HttpStatus.CONTINUE, "您有待支付的订单");
  65. }
  66. }
  67. studentGoodsSell.setAuthorUser(studentGoodsSell.getUserId());
  68. Map map = studentRepairService.addGoodsSellOrder(studentGoodsSell);
  69. if(map.containsKey("tradeState")){
  70. return failed(HttpStatus.CREATED, map,"恭喜您,购买成功!");
  71. }
  72. return succeed(map);
  73. }
  74. @ApiOperation("学员扫码支付")
  75. @PostMapping(value = "/studentPaymentGoodsOrder")
  76. public HttpResponseResult studentPaymentGoodsOrder(Integer goodsSellId) throws Exception {
  77. Map map = studentRepairService.studentPaymentGoodsOrder(goodsSellId);
  78. if(map.containsKey("tradeState")){
  79. return failed(HttpStatus.CREATED, map,"恭喜您,购买成功!");
  80. }
  81. return succeed(map);
  82. }
  83. @ApiOperation("获取维修记录")
  84. @GetMapping(value = "/getStudentRepairList")
  85. public HttpResponseResult getStudentRepairList(RepairStudentQueryInfo queryInfo) {
  86. SysUser sysUser = sysUserFeignService.queryUserInfo();
  87. if (sysUser == null) {
  88. return failed("用户信息获取失败");
  89. }
  90. queryInfo.setStudentId(sysUser.getId());
  91. queryInfo.setPayStatus(2);
  92. return succeed(studentRepairService.queryPage(queryInfo));
  93. }
  94. @ApiOperation("获取维修记录详情")
  95. @GetMapping(value = "/getRepairInfo")
  96. public HttpResponseResult getRepairInfo(Integer id,Integer studentId) {
  97. SysUser sysUser = sysUserFeignService.queryUserInfo();
  98. if ((sysUser == null || sysUser.getId() ==null) && studentId == null) {
  99. return failed("用户信息获取失败");
  100. }
  101. if(sysUser.getId() != null){
  102. studentId = sysUser.getId();
  103. }
  104. StudentRepair repairInfo = studentRepairService.getRepairInfo(id);
  105. if (!repairInfo.getStudentId().equals(studentId)) {
  106. return failed("您的维修记录不存在");
  107. }
  108. return succeed(repairInfo);
  109. }
  110. @ApiOperation("支付维修单")
  111. @PostMapping(value = "/payRepair")
  112. public HttpResponseResult payRepair(StudentRepair repairInfo) throws Exception {
  113. SysUser sysUser = sysUserFeignService.queryUserInfo();
  114. if (sysUser == null) {
  115. return failed(HttpStatus.FORBIDDEN, "请登录");
  116. }
  117. return succeed(studentRepairService.payRepair(repairInfo));
  118. }
  119. @ApiOperation("获取维修技师信息")
  120. @PostMapping(value = "/getRepairer")
  121. public HttpResponseResult getRepairer() {
  122. SysUser sysUser = sysUserFeignService.queryUserInfo();
  123. if (sysUser == null) {
  124. return failed(HttpStatus.FORBIDDEN, "请登录");
  125. }
  126. return succeed(studentRepairService.getStudentRepairer(sysUser.getId(),sysUser.getOrganId()));
  127. }
  128. @ApiOperation(value = "分页查询商品(教材、辅件)列表")
  129. @GetMapping("/queryGoodsPage")
  130. public Object queryPage(GoodsQueryInfo queryInfo){
  131. SysUser sysUser = sysUserFeignService.queryUserInfo();
  132. if(sysUser == null){
  133. throw new BizException("请先登录");
  134. }
  135. queryInfo.setStudentShowOrganId(sysUser.getOrganId().toString());
  136. return succeed(goodsService.queryPage(queryInfo));
  137. }
  138. @ApiOperation(value = "分页查询商品分类列表")
  139. @GetMapping("/queryGoodsCategoryPage")
  140. public Object queryGoodsCategoryPage(GoodsCategoryQueryInfo queryInfo) {
  141. return succeed(goodsCategoryService.queryPage(queryInfo));
  142. }
  143. @ApiOperation(value = "分页查询学员商品订单")
  144. @GetMapping("/queryStudentGoodsOrders")
  145. public Object queryStudentGoodsOrders(GoodsSellQueryInfo queryInfo) {
  146. SysUser sysUser = sysUserFeignService.queryUserInfo();
  147. if (sysUser == null) {
  148. return failed(HttpStatus.FORBIDDEN, "请登录");
  149. }
  150. queryInfo.setStudentId(sysUser.getId());
  151. return succeed(studentGoodsSellService.queryStudentGoodsOrders(queryInfo));
  152. }
  153. @ApiOperation(value = "获取学员商品订单")
  154. @GetMapping("/getStudentGoodsOrder")
  155. public Object getStudentGoodsOrder(Integer goodsSellId) {
  156. return succeed(studentGoodsSellService.getStudentGoodsOrder(goodsSellId));
  157. }
  158. @ApiOperation(value = "确认收货")
  159. @PostMapping("/affirmReceive")
  160. public Object affirmReceive(String orderNo) {
  161. studentGoodsSellService.affirmReceive(orderNo);
  162. return succeed();
  163. }
  164. }