SelfTakeController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.modules.groupon.controller;
  18. import cn.hutool.core.util.NumberUtil;
  19. import cn.hutool.core.util.StrUtil;
  20. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  21. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  22. import com.baomidou.mybatisplus.core.metadata.IPage;
  23. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import io.swagger.annotations.ApiParam;
  27. import lombok.AllArgsConstructor;
  28. import org.springblade.core.boot.ctrl.BladeController;
  29. import org.springblade.core.mp.support.Condition;
  30. import org.springblade.core.mp.support.Query;
  31. import org.springblade.core.tool.api.R;
  32. import org.springblade.core.tool.utils.Func;
  33. import org.springblade.modules.groupon.entity.SelfTake;
  34. import org.springblade.modules.groupon.entity.UserSelfTake;
  35. import org.springblade.modules.groupon.param.AddUserSelfTakeParam;
  36. import org.springblade.modules.groupon.service.ISelfTakeService;
  37. import org.springblade.modules.groupon.service.IUserSelfTakeService;
  38. import org.springblade.modules.groupon.vo.SelfTakeVO;
  39. import org.springblade.modules.groupon.wrapper.SelfTakeWrapper;
  40. import org.springframework.web.bind.annotation.*;
  41. import javax.annotation.Resource;
  42. import javax.validation.Valid;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.stream.Collectors;
  46. /**
  47. * 自提点表 控制器
  48. *
  49. * @author BladeX
  50. * @since 2023-06-02
  51. */
  52. @RestController
  53. @AllArgsConstructor
  54. @RequestMapping("groupon/selftake")
  55. @Api(value = "自提点表", tags = "自提点表接口")
  56. public class SelfTakeController extends BladeController {
  57. private final ISelfTakeService selfTakeService;
  58. @Resource
  59. private IUserSelfTakeService userSelfTakeService;
  60. /**
  61. * 查询自己的自提点
  62. */
  63. @PostMapping("/listByUserId")
  64. @ApiOperationSupport(order = 1)
  65. @ApiOperation(value = "查询团长自提点", notes = "userId")
  66. public R listByUserId(@RequestParam Long userId) {
  67. List<UserSelfTake> list = userSelfTakeService.lambdaQuery()
  68. .eq(UserSelfTake::getUserId, userId)
  69. .list();
  70. if (list.size() <= 0) {
  71. return R.success("没有查询到自提点");
  72. }
  73. List<Long> collect = list.stream().map(UserSelfTake::getSelfTakeId).collect(Collectors.toList());
  74. LambdaQueryWrapper<SelfTake> q = new LambdaQueryWrapper<>();
  75. q.in(SelfTake::getId, collect);
  76. q.eq(SelfTake::getStatus, 1);
  77. q.eq(SelfTake::getIsDelete, 0);
  78. q.orderByDesc(SelfTake::getIsDefault);
  79. q.orderByDesc(SelfTake::getCreateTime);
  80. List<SelfTake> list1 = selfTakeService.list(q);
  81. return R.data(list1);
  82. }
  83. /**
  84. * 详情
  85. */
  86. @GetMapping("/detail")
  87. @ApiOperationSupport(order = 1)
  88. @ApiOperation(value = "详情", notes = "传入selfTake")
  89. public R<SelfTakeVO> detail(SelfTake selfTake) {
  90. SelfTake detail = selfTakeService.getOne(Condition.getQueryWrapper(selfTake));
  91. return R.data(SelfTakeWrapper.build().entityVO(detail));
  92. }
  93. /**
  94. * 分页 自提点表
  95. */
  96. @GetMapping("/list")
  97. @ApiOperationSupport(order = 2)
  98. @ApiOperation(value = "分页", notes = "传入selfTake")
  99. public R<IPage<SelfTakeVO>> list(SelfTake selfTake, Query query, String isAdmin) {
  100. String name = "";
  101. if (StrUtil.isNotBlank(selfTake.getName())) {
  102. name = selfTake.getName();
  103. selfTake.setName(null);
  104. }
  105. QueryWrapper<SelfTake> queryWrapper = Condition.getQueryWrapper(selfTake);
  106. if (StrUtil.isNotBlank(name)) {
  107. queryWrapper.like("name", name);
  108. }
  109. if (StrUtil.isBlank(isAdmin)) {
  110. queryWrapper.isNotNull("contact_number").ne("contact_number", "");
  111. }
  112. IPage<SelfTake> pages = selfTakeService.page(Condition.getPage(query), queryWrapper);
  113. return R.data(SelfTakeWrapper.build().pageVO(pages));
  114. }
  115. /**
  116. * 自定义分页 自提点表
  117. */
  118. @GetMapping("/page")
  119. @ApiOperationSupport(order = 3)
  120. @ApiOperation(value = "分页", notes = "传入selfTake")
  121. public R<IPage<SelfTakeVO>> page(SelfTakeVO selfTake, Query query) {
  122. // 处理前端下拉多选时的bug
  123. if (NumberUtil.isNumber(selfTake.getName()) && selfTake.getName().length() == 19) {
  124. selfTake.setName("");
  125. }
  126. IPage<SelfTakeVO> pages = selfTakeService.selectSelfTakePage(Condition.getPage(query), selfTake);
  127. return R.data(pages);
  128. }
  129. /**
  130. * 新增 自提点表
  131. */
  132. @PostMapping("/save")
  133. @ApiOperationSupport(order = 4)
  134. @ApiOperation(value = "新增", notes = "传入selfTake")
  135. public R save(@Valid @RequestBody SelfTake selfTake) {
  136. return R.status(selfTakeService.save(selfTake));
  137. }
  138. /**
  139. * 修改 自提点表
  140. */
  141. @PostMapping("/update")
  142. @ApiOperationSupport(order = 5)
  143. @ApiOperation(value = "修改", notes = "传入selfTake")
  144. public R update(@Valid @RequestBody SelfTake selfTake) {
  145. return R.status(selfTakeService.updateById(selfTake));
  146. }
  147. /**
  148. * 新增或修改 自提点表
  149. */
  150. @PostMapping("/submit")
  151. @ApiOperationSupport(order = 6)
  152. @ApiOperation(value = "新增或修改", notes = "传入selfTake")
  153. public R submit(@Valid @RequestBody SelfTake selfTake) {
  154. return R.status(selfTakeService.saveOrUpdate(selfTake));
  155. }
  156. /**
  157. * 删除 自提点表
  158. */
  159. @PostMapping("/remove")
  160. @ApiOperationSupport(order = 7)
  161. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  162. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  163. return R.status(selfTakeService.removeByIds(Func.toLongList(ids)));
  164. }
  165. /**
  166. * 给团长添加自提点
  167. */
  168. @PostMapping("/addUserSelfTake")
  169. @ApiOperationSupport(order = 7)
  170. @ApiOperation(value = "给团长添加自提点", notes = "传入ids")
  171. public R addUserSelfTake(@RequestBody AddUserSelfTakeParam param) {
  172. userSelfTakeService.lambdaUpdate()
  173. .eq(UserSelfTake::getUserId, param.getUserId())
  174. .remove();
  175. List<UserSelfTake> list = new ArrayList<>();
  176. for (Long selfTakeId : param.getSelfTakeList()) {
  177. UserSelfTake userSelfTake = new UserSelfTake();
  178. userSelfTake.setUserId(param.getUserId());
  179. userSelfTake.setSelfTakeId(selfTakeId);
  180. list.add(userSelfTake);
  181. }
  182. userSelfTakeService.saveBatch(list);
  183. return R.success("操作成功");
  184. }
  185. }