TAddressController.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package com.ylx.web.controller.massage;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.ylx.common.core.controller.BaseController;
  7. import com.ylx.common.core.domain.R;
  8. import com.ylx.common.utils.StringUtils;
  9. import com.ylx.massage.domain.TAddress;
  10. import com.ylx.massage.domain.vo.UserAddressListVO;
  11. import com.ylx.massage.service.TAddressService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.annotation.Resource;
  17. import java.util.List;
  18. /**
  19. * 轮播图(TAddress)表控制层
  20. *
  21. * @author makejava
  22. * @since 2024-04-11 17:18:52
  23. */
  24. @RestController
  25. @Api(tags = {"地址管理"})
  26. @RequestMapping("tAddress")
  27. @Slf4j
  28. public class TAddressController extends BaseController {
  29. /**
  30. * 服务对象
  31. */
  32. @Resource
  33. private TAddressService tAddressService;
  34. /**
  35. * 分页查询所有地址数据
  36. *
  37. * @param page 分页对象
  38. * @param tAddress 查询实体
  39. * @return R 所有数据
  40. */
  41. @GetMapping
  42. public R selectAll(Page<TAddress> page, TAddress tAddress) {
  43. return R.ok(this.tAddressService.page(page, new QueryWrapper<>(tAddress)));
  44. }
  45. /**
  46. * 根据姓名查询通讯地址列表
  47. *
  48. * @param page
  49. * @param tAddress
  50. * @return R
  51. */
  52. @GetMapping("pc/getAddressList")
  53. @ApiOperation("通讯地址列表")
  54. public R getAddressList(Page<TAddress> page, TAddress tAddress) {
  55. Page<TAddress> page1 = tAddressService.page(page, new LambdaQueryWrapper<TAddress>()
  56. .like(TAddress::getUserName, tAddress.getUserName())
  57. .orderByDesc(TAddress::getCreateTime));
  58. return R.ok(page1);
  59. }
  60. /**
  61. * 根据OpenId查询用户地址
  62. *
  63. * @param openId
  64. * @return R<List < TAddress>> 单条数据
  65. */
  66. @ApiOperation("根据OpenId查询用户地址")
  67. @GetMapping("getByOpenId")
  68. public R<List<TAddress>> selectOne(@RequestParam String openId) {
  69. LambdaQueryWrapper<TAddress> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  70. objectLambdaQueryWrapper.eq(TAddress::getOpenid, openId);
  71. return R.ok(this.tAddressService.list(objectLambdaQueryWrapper));
  72. }
  73. /**
  74. * PC端根据openId查询用户地址
  75. *
  76. * @param openId 用户openId
  77. * @return R<List<UserAddressListVO>> 用户地址列表
  78. */
  79. @ApiOperation("PC端根据openId查询用户地址")
  80. @GetMapping("pc/getUserAddressList")
  81. public R<List<UserAddressListVO>> getUserAddressList(@RequestParam String openId) {
  82. try {
  83. if (StringUtils.isBlank(openId)) {
  84. return R.fail("openId不能为空");
  85. }
  86. return R.ok(this.tAddressService.getPcUserAddressList(openId));
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. throw new RuntimeException(e);
  90. }
  91. }
  92. @ApiOperation("根据Id查询地址")
  93. @GetMapping("getById")
  94. public R<TAddress> getById(@RequestParam String id) {
  95. return R.ok(this.tAddressService.getById(id));
  96. }
  97. /**
  98. * 根据手机号码查询技师的虚拟地址(PC端)
  99. *
  100. * @param phone
  101. * @return R<List<TAddress>>
  102. */
  103. @ApiOperation("根据手机号码查询技师的虚拟地址")
  104. @GetMapping("getVirtualAddressByPhone")
  105. public R<List<TAddress>> getVirtualAddressByPhone(@RequestParam String phone) {
  106. try {
  107. LambdaQueryWrapper<TAddress> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  108. objectLambdaQueryWrapper.eq(TAddress::getPhone, phone).eq(TAddress::getType, 2).eq(TAddress::getUserType,2);
  109. return R.ok(this.tAddressService.list(objectLambdaQueryWrapper));
  110. } catch (Exception e) {
  111. e.printStackTrace();
  112. throw new RuntimeException(e);
  113. }
  114. }
  115. /**
  116. * 根据手机号码查询技师的虚拟地址(用户端)
  117. *
  118. * @param phone
  119. * @return R<List<TAddress>>
  120. */
  121. @ApiOperation("根据手机号码查询技师的虚拟地址")
  122. @GetMapping("/wx/getVirtualAddressByPhone")
  123. public R<List<TAddress>> getWXVirtualAddressByPhone(@RequestParam String phone) {
  124. try {
  125. LambdaQueryWrapper<TAddress> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  126. objectLambdaQueryWrapper.eq(TAddress::getPhone, phone).eq(TAddress::getType, 2).eq(TAddress::getUserType,2);
  127. return R.ok(this.tAddressService.list(objectLambdaQueryWrapper));
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. throw new RuntimeException(e);
  131. }
  132. }
  133. /**
  134. * 新增地址(用户端)
  135. *
  136. * @param tAddress 实体对象
  137. * @return R 新增结果
  138. */
  139. @PostMapping("save")
  140. @ApiOperation("新增地址")
  141. public R insert(@RequestBody TAddress tAddress) {
  142. try {
  143. return R.ok(this.tAddressService.insertAddress(tAddress));
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. throw new RuntimeException(e);
  147. }
  148. }
  149. /**
  150. * 新增虚拟地址(商户端)
  151. *
  152. * @param tAddress 实体对象
  153. * @return R 新增结果
  154. */
  155. @PostMapping("saveVirtualAddress")
  156. @ApiOperation("新增虚拟地址")
  157. public R saveVirtualAddress(@RequestBody TAddress tAddress) {
  158. try {
  159. log.info("tAddress参数的值:{}", JSON.toJSONString(tAddress));
  160. return R.ok(this.tAddressService.insertVirtualAddress(tAddress));
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. throw new RuntimeException(e);
  164. }
  165. }
  166. /**
  167. * 修改数据
  168. *
  169. * @param tAddress 实体对象
  170. * @return 修改结果
  171. */
  172. @PostMapping("/update")
  173. @ApiOperation("修改地址")
  174. public R update(@RequestBody TAddress tAddress) {
  175. return R.ok(this.tAddressService.updateAddress(tAddress));
  176. }
  177. /**
  178. * 删除数据
  179. *
  180. * @param idList 主键结合
  181. * @return 删除结果
  182. */
  183. @DeleteMapping("/delete")
  184. @ApiOperation("删除地址")
  185. public R delete(@RequestParam("idList") List<Long> idList) {
  186. return R.ok(this.tAddressService.removeByIds(idList));
  187. }
  188. /**
  189. * 删除技师的虚拟地址
  190. *
  191. * @param id
  192. * @return R
  193. */
  194. @DeleteMapping("/deleteVirtualAddress")
  195. @ApiOperation("删除地址")
  196. public R deleteVirtualAddress(@RequestParam("id") String id) {
  197. try {
  198. return R.ok(this.tAddressService.removeById(id));
  199. } catch (Exception e) {
  200. e.printStackTrace();
  201. throw new RuntimeException(e);
  202. }
  203. }
  204. /**
  205. * 设置默认地址
  206. * @param tAddress
  207. * @return R
  208. */
  209. @PostMapping("/defaultAddress")
  210. @ApiOperation("设置默认地址")
  211. public R defaultAddress(@RequestBody TAddress tAddress) {
  212. return R.ok(this.tAddressService.defaultAddress(tAddress));
  213. }
  214. }