TJsServiceImpl.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.ylx.massage.service.impl;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import cn.hutool.json.JSONObject;
  4. import cn.hutool.json.JSONUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.ylx.common.constant.MassageConstants;
  9. import com.ylx.common.exception.ServiceException;
  10. import com.ylx.common.utils.StringUtils;
  11. import com.ylx.massage.domain.*;
  12. import com.ylx.massage.domain.vo.TJsVo;
  13. import com.ylx.massage.enums.JsStatusEnum;
  14. import com.ylx.massage.mapper.TJsMapper;
  15. import com.ylx.massage.service.*;
  16. import com.ylx.massage.utils.LocationUtil;
  17. import com.ylx.massage.utils.WeChatUtil;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import javax.annotation.Resource;
  22. import java.time.LocalDateTime;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 技师表 服务实现类
  29. */
  30. @Service
  31. @Slf4j
  32. public class TJsServiceImpl extends ServiceImpl<TJsMapper, TJs> implements TJsService {
  33. @Resource
  34. private TJsMapper mapper;
  35. @Resource
  36. private LocationUtil locationUtil;
  37. @Resource
  38. private TCollectService collectService;
  39. @Resource
  40. private TXiangmuService xiangmuService;
  41. @Resource
  42. private TCommentService commentService;
  43. @Resource
  44. private TWxUserService wxUserService;
  45. @Resource
  46. private WeChatUtil weChatUtil;
  47. @Override
  48. public Page<TJs> getAll(Page<TJs> page, TJsVo param) {
  49. return mapper.getAll(page, param);
  50. }
  51. @Override
  52. public boolean addJs(TJs js) {
  53. LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
  54. queryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  55. TJs cjs = this.getOne(queryWrapper);
  56. if (cjs != null) {
  57. throw new ServiceException("请勿重复申请");
  58. }
  59. cacheAddress(js);
  60. initialization(js);
  61. return this.save(js);
  62. }
  63. private void cacheAddress(TJs js) {
  64. if (StringUtils.isBlank(js.getcPhone())) {
  65. throw new ServiceException("手机号不能为空");
  66. }
  67. if (StringUtils.isBlank(js.getcAddress())) {
  68. throw new ServiceException("地址不能为空");
  69. }
  70. log.info("js:{}", js);
  71. JSONObject jsonObject = new JSONObject(js.getcAddress());
  72. Object latitude = jsonObject.get("latitude");
  73. Object longitude = jsonObject.get("longitude");
  74. locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(longitude.toString()), Double.parseDouble(latitude.toString()));
  75. }
  76. @Override
  77. public boolean wxUpdateJs(TJs js) {
  78. cacheAddress(js);
  79. return this.updateById(js);
  80. }
  81. @Override
  82. @Transactional(rollbackFor = Exception.class)
  83. public boolean auditing(TJs js) {
  84. TJs js1 = this.getById(js.getId());
  85. LambdaQueryWrapper<TJs> jsLambdaQueryWrapper = new LambdaQueryWrapper<>();
  86. jsLambdaQueryWrapper.eq(TJs::getId, js.getId()).eq(TJs::getnTong, JsStatusEnum.JS_NOT_PASS.getCode());
  87. js.setnTong(JsStatusEnum.JS_PASS.getCode());
  88. LambdaQueryWrapper<TWxUser> wxLambdaQueryWrapper = new LambdaQueryWrapper<>();
  89. wxLambdaQueryWrapper.eq(TWxUser::getcOpenid, js1.getcOpenId());
  90. TWxUser tWxUser = new TWxUser();
  91. tWxUser.setRole(1);
  92. wxUserService.update(tWxUser, wxLambdaQueryWrapper);
  93. return this.update(js, jsLambdaQueryWrapper);
  94. }
  95. @Override
  96. public boolean updateLocation(TJs js) {
  97. if (StringUtils.isBlank(js.getcOpenId())) {
  98. throw new ServiceException("技师OpenID不能为空");
  99. }
  100. if (StringUtils.isBlank(js.getcAddress())) {
  101. throw new ServiceException("地址不能为空");
  102. }
  103. JSONObject jsonObject = new JSONObject(js.getcAddress());
  104. Object latitude = jsonObject.get("latitude");
  105. Object longitude = jsonObject.get("longitude");
  106. locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(longitude.toString()), Double.parseDouble(latitude.toString()));
  107. LambdaQueryWrapper<TJs> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  108. objectLambdaQueryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  109. return this.update(js, objectLambdaQueryWrapper);
  110. }
  111. @Override
  112. public void newOrderNotification(String openId) {
  113. // 订单号 23010000010101
  114. // 用户电话 15055556666
  115. // 用户名称 李四
  116. // 时间 2022年11月11日22:22
  117. // 服务地址 湖南长沙岳麓
  118. cn.hutool.json.JSONObject param = JSONUtil.createObj();
  119. //订单号
  120. param.set("keyword1", "23010000010101");
  121. //点话
  122. param.set("keyword2","18360233903");
  123. param.set("keyword3","李四");
  124. param.set("keyword4","2022年11月11日22:22");
  125. param.set("keyword5","湖南长沙岳麓");
  126. weChatUtil.notification(openId, param.toString());
  127. }
  128. @Override
  129. public TJs getByJsId(String jsId, String openId) {
  130. if (jsId == null || jsId.trim().isEmpty()) {
  131. // 处理空或空白的jsId
  132. throw new ServiceException("Id为空");
  133. }
  134. TJs js = this.getById(jsId);
  135. if (js == null) {
  136. // 处理getById返回null的情况
  137. return null; // 或者返回一个新的TJs实例,具体看业务需求
  138. }
  139. if (StringUtils.isBlank(js.getcBhList())) {
  140. // 处理js.getcBhList()返回null或空列表的情况
  141. js.setProjects(new ArrayList<>()); // 设置空列表,避免后续调用空指针
  142. return js;
  143. }
  144. //项目
  145. List<String> projectIds = Arrays.stream(js.getcBhList().split(",")).collect(Collectors.toList());
  146. LambdaQueryWrapper<TXiangmu> xiangmuLambdaQueryWrapper = new LambdaQueryWrapper<>();
  147. xiangmuLambdaQueryWrapper.in(TXiangmu::getcId, projectIds);
  148. List<TXiangmu> projects = xiangmuService.list(xiangmuLambdaQueryWrapper);
  149. js.setProjects(projects);
  150. //评论
  151. LambdaQueryWrapper<TComment> commentLambdaQueryWrapper = new LambdaQueryWrapper<>();
  152. commentLambdaQueryWrapper.eq(TComment::getcJsid, jsId);
  153. List<TComment> list = commentService.list(commentLambdaQueryWrapper);
  154. if (CollectionUtil.isNotEmpty(list)) {
  155. js.setComments(list);
  156. }
  157. //是否收藏
  158. LambdaQueryWrapper<TCollect> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  159. objectLambdaQueryWrapper.eq(TCollect::getcJsId, jsId).eq(TCollect::getcWxOpenId, openId);
  160. TCollect collect = collectService.getOne(objectLambdaQueryWrapper);
  161. if (collect != null) {
  162. js.setIsCollection(true);
  163. } else {
  164. js.setIsCollection(false);
  165. }
  166. return js;
  167. }
  168. private static void initialization(TJs js) {
  169. // 评分默认最高
  170. js.setnStar(MassageConstants.INTEGER_FIVE);
  171. // 已服务数量 0
  172. js.setnNum(MassageConstants.INTEGER_ZERO);
  173. // 佣金比例 10
  174. js.setnBili(MassageConstants.INTEGER_TEN);
  175. // 服务状态
  176. js.setnStatus(JsStatusEnum.JS_SERVICEABLE.getCode());
  177. // 上岗状态
  178. js.setnStatus2(JsStatusEnum.POST_NOT_ON_DUTY.getCode());
  179. // 审核状态
  180. js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
  181. js.setnB1(MassageConstants.INTEGER_ZERO);
  182. js.setnB2(MassageConstants.INTEGER_ZERO);
  183. js.setnB3(MassageConstants.INTEGER_ZERO);
  184. js.setDtCreateTime(LocalDateTime.now());
  185. }
  186. }