TJsController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package com.ylx.web.controller.massage;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.ylx.common.annotation.Log;
  5. import com.ylx.common.core.controller.BaseController;
  6. import com.ylx.common.core.domain.R;
  7. import com.ylx.common.core.domain.model.WxLoginUser;
  8. import com.ylx.common.enums.BusinessType;
  9. import com.ylx.common.exception.ServiceException;
  10. import com.ylx.common.utils.ListUtils;
  11. import com.ylx.massage.domain.Location;
  12. import com.ylx.massage.domain.TJs;
  13. import com.ylx.massage.domain.vo.TJsVo;
  14. import com.ylx.massage.service.TJsService;
  15. import com.ylx.massage.utils.LocationUtil;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.web.bind.annotation.RequestBody;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RequestMethod;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import javax.annotation.Resource;
  25. import java.math.BigDecimal;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.stream.Collectors;
  29. /**
  30. * 技师Controller
  31. *
  32. * @author ylx
  33. * @date 2024-03-22
  34. */
  35. @RestController
  36. @RequestMapping("api/js/v1")
  37. @Api(tags = {"技师管理"})
  38. @Slf4j
  39. public class TJsController extends BaseController {
  40. @Resource
  41. private TJsService jsService;
  42. @Resource
  43. private LocationUtil locationUtil;
  44. /**
  45. * 添加技师申请
  46. *
  47. * @param js
  48. * @return
  49. */
  50. @Log(title = "技师管理", businessType = BusinessType.INSERT)
  51. @RequestMapping(value = "wx/add", method = RequestMethod.POST)
  52. @ApiOperation("添加技师申请")
  53. public R add(@RequestBody TJs js) {
  54. try {
  55. WxLoginUser wxLoginUser = getWxLoginUser();
  56. js.setcOpenId(wxLoginUser.getCOpenid());
  57. return R.ok(jsService.addJs(js));
  58. } catch (ServiceException s) {
  59. log.error(s.toString());
  60. return R.fail(s.getMessage());
  61. } catch (Exception e) {
  62. log.error(e.toString());
  63. return R.fail("系统异常");
  64. }
  65. }
  66. /**
  67. * 更新技师信息
  68. *
  69. * @param js
  70. * @return
  71. */
  72. @Log(title = "技师管理", businessType = BusinessType.UPDATE)
  73. @RequestMapping(value = "wx/update", method = RequestMethod.POST)
  74. @ApiOperation("更新技师信息")
  75. public R wxUpdate(@RequestBody TJs js) {
  76. try {
  77. return R.ok(jsService.wxUpdateJs(js));
  78. } catch (ServiceException s) {
  79. log.error(s.toString());
  80. return R.fail(s.getMessage());
  81. } catch (Exception e) {
  82. log.error(e.toString());
  83. return R.fail("系统异常");
  84. }
  85. }
  86. /**
  87. * 微信查询
  88. *
  89. * @param
  90. * @return
  91. */
  92. @RequestMapping(value = "wx/select", method = RequestMethod.GET)
  93. @ApiOperation("微信查询")
  94. public R wxSelect(Page<TJs> page, TJsVo js) {
  95. try {
  96. if (js.getLatitude() != null && js.getLongitude() != null) {
  97. // 检查经纬度是否在合理范围内
  98. Location location = new Location();
  99. location.setLatitude(js.getLatitude().doubleValue());
  100. location.setLongitude(js.getLongitude().doubleValue());
  101. location.setLimit(100L); // 考虑将此值作为参数或配置项
  102. location.setRadius(1000.00);
  103. List<TJs> nearbyTechnicians = locationUtil.dis(location);
  104. if (nearbyTechnicians != null) {
  105. Map<String, BigDecimal> collect = nearbyTechnicians.stream().collect(Collectors.toMap(TJs::getcOpenId, TJs::getDistance));
  106. js.setIds(nearbyTechnicians.stream().map(TJs::getcOpenId).collect(Collectors.toList()));
  107. int size = (int) page.getSize();
  108. int pageNum = (int) page.getCurrent();
  109. page.setSize(nearbyTechnicians.size());
  110. page.setCurrent(1);
  111. Page<TJs> all = jsService.getAll(page, js);
  112. all.getRecords().forEach(item -> {
  113. item.setDistance(collect.get(item.getcOpenId()));
  114. });
  115. List<TJs> objects = (List<TJs>) ListUtils.subList(all.getRecords(), size, pageNum);
  116. page.setRecords(objects);
  117. page.setSize(size);
  118. }
  119. }
  120. return R.ok(jsService.getAll(page, js));
  121. } catch (Exception e) {
  122. // 异常处理
  123. e.printStackTrace();
  124. return R.fail("操作失败");
  125. }
  126. }
  127. /**
  128. * 分页查询数据
  129. */
  130. @RequestMapping(value = "/select", method = RequestMethod.GET)
  131. @ApiOperation("分页查询数据")
  132. public Page<TJs> selectSp(Page<TJs> page, TJs js) {
  133. LambdaQueryWrapper<TJs> mhCompanyLambdaQueryWrapper = new LambdaQueryWrapper<>();
  134. mhCompanyLambdaQueryWrapper.eq(null != js.getnTong(), TJs::getnTong, js.getnTong()).
  135. like(StringUtils.isNotBlank(js.getcName()), TJs::getcName, js.getcName()).
  136. orderByDesc(TJs::getDtCreateTime);
  137. return jsService.page(page, mhCompanyLambdaQueryWrapper);
  138. }
  139. /**
  140. * 删除
  141. */
  142. @Log(title = "技师管理", businessType = BusinessType.DELETE)
  143. @RequestMapping(value = "/del", method = RequestMethod.POST)
  144. @ApiOperation("删除")
  145. public Boolean del(@RequestBody TJs js) {
  146. return jsService.removeById(js);
  147. }
  148. @ApiOperation("根据id查询技师")
  149. @RequestMapping(value = "/wx/getByid", method = RequestMethod.POST)
  150. public R getById(@RequestBody TJs js) {
  151. try {
  152. return R.ok(jsService.getByJsId(js.getId()));
  153. } catch (ServiceException s) {
  154. log.error(s.getMessage());
  155. return R.fail(s.getMessage());
  156. } catch (Exception e) {
  157. log.error(e.getMessage());
  158. return R.fail("系统异常");
  159. }
  160. }
  161. @ApiOperation("根据OpenId查询技师")
  162. @RequestMapping(value = "/wx/getByOpenId", method = RequestMethod.POST)
  163. public R getByOpenId(@RequestBody TJs js) {
  164. try {
  165. LambdaQueryWrapper<TJs> mhCompanyLambdaQueryWrapper = new LambdaQueryWrapper<>();
  166. mhCompanyLambdaQueryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  167. return R.ok(jsService.getOne(mhCompanyLambdaQueryWrapper));
  168. } catch (ServiceException s) {
  169. log.error(s.getMessage());
  170. return R.fail(s.getMessage());
  171. } catch (Exception e) {
  172. log.error(e.getMessage());
  173. return R.fail("系统异常");
  174. }
  175. }
  176. }