GroupRelationController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.cyksj.web.controller.group;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.cyksj.common.constant.Constant;
  4. import com.cyksj.common.exception.BusinessRuntimeException;
  5. import com.cyksj.dto.Result;
  6. import com.cyksj.enums.GatewayResponse;
  7. import com.cyksj.mapper.GroupsRelationMapper;
  8. import com.cyksj.model.entity.GroupsRelation;
  9. import com.cyksj.model.entity.OrderDon;
  10. import com.cyksj.model.request.OrderPayRequest;
  11. import com.cyksj.model.views.RenewalView;
  12. import com.cyksj.service.corp.CorpService;
  13. import com.cyksj.service.order.OrderDonService;
  14. import com.cyksj.service.relation.GroupRelationFrontService;
  15. import com.cyksj.web.util.StpUserUtil;
  16. import com.ejlchina.searcher.BeanSearcher;
  17. import lombok.RequiredArgsConstructor;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.List;
  21. /**
  22. * @author chan
  23. * @date 2022/9/27 11:48 AM
  24. */
  25. @Slf4j
  26. @RequiredArgsConstructor
  27. @RestController
  28. @RequestMapping("/applets/group/relation")
  29. public class GroupRelationController {
  30. private final BeanSearcher beanSearcher;
  31. private final OrderDonService orderDonService;
  32. private final GroupsRelationMapper relationMapper;
  33. private final GroupRelationFrontService groupRelationFrontService;
  34. private final CorpService corpService;
  35. @RequestMapping("/get/renewal")
  36. public Result<List<RenewalView>> get(Boolean isLoginPopularize) {
  37. long userId = StpUserUtil.getLoginIdAsLong();
  38. List<RenewalView> list = groupRelationFrontService.getMyTicket(userId, isLoginPopularize);
  39. list.forEach(data->{
  40. if (data.getGoodsId() == 1) {
  41. OrderDon last = orderDonService.getOne(Wrappers.lambdaQuery(OrderDon.class)
  42. .eq(OrderDon::getGoodsId, 1)
  43. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  44. .orderByAsc(OrderDon::getId)
  45. .select(OrderDon::getCreatedTime)
  46. .last("limit 1"));
  47. if (last != null) {
  48. data.setLastTime(last.getCreatedTime());
  49. }
  50. }
  51. });
  52. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  53. }
  54. @PostMapping("/post/renewal")
  55. public Result<OrderDon> renewal(@RequestBody OrderPayRequest request) throws Exception {
  56. long userId = StpUserUtil.getLoginIdAsLong();
  57. request.setUserId(userId);
  58. OrderDon orderDon = orderDonService.renewal(request);
  59. return GatewayResponse.SUCCESS.newBuilder().toResult(orderDon);
  60. }
  61. @PutMapping("/update/set/account")
  62. public Result<String> setAccount(@RequestBody GroupsRelation relation) {
  63. long userId = StpUserUtil.getLoginIdAsLong();
  64. GroupsRelation re = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, relation.getId()).eq(GroupsRelation::getUserId, userId).last(" limit 1"));
  65. if (re == null) {
  66. throw new BusinessRuntimeException("该车票不存在,请联系客服.");
  67. }
  68. relationMapper.update(relation, Wrappers.lambdaUpdate(GroupsRelation.class).set(GroupsRelation::getAccount, relation.getAccount()).eq(GroupsRelation::getId, relation.getId()));
  69. return GatewayResponse.SUCCESS.newBuilder().toResult();
  70. }
  71. /**
  72. * 查询是否加入了企业微信
  73. */
  74. @GetMapping("/check/joinCorpWx")
  75. public Result<Boolean> isJoinCorpWx() {
  76. long userId = StpUserUtil.getLoginIdAsLong();
  77. Boolean flag = corpService.isJoinCorpWx(userId, false);
  78. return GatewayResponse.SUCCESS.newBuilder().toResult(flag);
  79. }
  80. }