TJsServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.config.WechatAccountConfig;
  9. import com.ylx.common.constant.MassageConstants;
  10. import com.ylx.common.exception.ServiceException;
  11. import com.ylx.common.utils.StringUtils;
  12. import com.ylx.massage.domain.*;
  13. import com.ylx.massage.domain.vo.TJsVo;
  14. import com.ylx.massage.enums.JsStatusEnum;
  15. import com.ylx.massage.enums.OrderStatusEnum;
  16. import com.ylx.massage.mapper.TJsMapper;
  17. import com.ylx.massage.service.*;
  18. import com.ylx.massage.utils.DateTimeUtils;
  19. import com.ylx.massage.utils.LocationUtil;
  20. import com.ylx.massage.utils.WeChatUtil;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import javax.annotation.Resource;
  25. import java.time.LocalDateTime;
  26. import java.util.*;
  27. import java.util.stream.Collectors;
  28. /**
  29. * 技师表 服务实现类
  30. */
  31. @Service
  32. @Slf4j
  33. public class TJsServiceImpl extends ServiceImpl<TJsMapper, TJs> implements TJsService {
  34. @Resource
  35. private TJsMapper mapper;
  36. @Resource
  37. private WechatAccountConfig wxPayProperties;
  38. @Resource
  39. private LocationUtil locationUtil;
  40. @Resource
  41. private TCollectService collectService;
  42. @Resource
  43. private TXiangmuService xiangmuService;
  44. @Resource
  45. private TCommentService commentService;
  46. @Resource
  47. private TWxUserService wxUserService;
  48. @Resource
  49. private WeChatUtil weChatUtil;
  50. @Resource
  51. private TOrderService orderService;
  52. @Override
  53. public Page<TJs> getAll(Page<TJs> page, TJsVo param) {
  54. return mapper.getAll(page, param);
  55. }
  56. @Override
  57. public boolean addJs(TJs js) {
  58. LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
  59. queryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  60. TJs cjs = this.getOne(queryWrapper);
  61. if (cjs != null) {
  62. throw new ServiceException("请勿重复申请");
  63. }
  64. cacheAddress(js);
  65. initialization(js);
  66. return this.save(js);
  67. }
  68. private void cacheAddress(TJs js) {
  69. if (StringUtils.isBlank(js.getcPhone())) {
  70. throw new ServiceException("手机号不能为空");
  71. }
  72. if (StringUtils.isBlank(js.getName())) {
  73. throw new ServiceException("地址不能为空");
  74. }
  75. if (StringUtils.isNotBlank(js.getId())) {
  76. TJs oldJs = this.getById(js.getId());
  77. if (oldJs.getnTong().equals(JsStatusEnum.JS_RETURN.getCode())) {
  78. js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
  79. }
  80. }
  81. // log.info("js:{}", js);
  82. // JSONObject jsonObject = new JSONObject(js.getcAddress());
  83. // Object latitude = jsonObject.get("latitude");
  84. // Object longitude = jsonObject.get("longitude");
  85. locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(js.getLongitude().toString()), Double.parseDouble(js.getLatitude().toString()));
  86. }
  87. @Override
  88. public boolean wxUpdateJs(TJs js) {
  89. cacheAddress(js);
  90. return this.updateById(js);
  91. }
  92. @Override
  93. @Transactional(rollbackFor = Exception.class)
  94. public boolean auditing(TJs js) {
  95. TJs js1 = this.getById(js.getId());
  96. LambdaQueryWrapper<TJs> jsLambdaQueryWrapper = new LambdaQueryWrapper<>();
  97. jsLambdaQueryWrapper.eq(TJs::getId, js.getId()).eq(TJs::getnTong, JsStatusEnum.JS_NOT_PASS.getCode());
  98. js.setnTong(JsStatusEnum.JS_PASS.getCode());
  99. LambdaQueryWrapper<TWxUser> wxLambdaQueryWrapper = new LambdaQueryWrapper<>();
  100. wxLambdaQueryWrapper.eq(TWxUser::getcOpenid, js1.getcOpenId());
  101. TWxUser tWxUser = new TWxUser();
  102. tWxUser.setRole(1);
  103. wxUserService.update(tWxUser, wxLambdaQueryWrapper);
  104. boolean update = this.update(js, jsLambdaQueryWrapper);
  105. js.setcOpenId(js1.getcOpenId());
  106. this.jsNotification(js);
  107. return update;
  108. }
  109. @Override
  110. public void jsNotification(TJs js) {
  111. cn.hutool.json.JSONObject param = JSONUtil.createObj();
  112. //是否审核通过
  113. if(JsStatusEnum.JS_PASS.getCode().equals(js.getnTong())){
  114. param.set("const1", JSONUtil.createObj().set("value", "审核通过可以接单"));
  115. }else{
  116. param.set("const1", JSONUtil.createObj().set("value", "审核驳回请重新提交"));
  117. }
  118. //审核时间
  119. param.set("time2", JSONUtil.createObj().set("value", DateTimeUtils.formatDate(new Date(), DateTimeUtils.DATE_NUMBER_YEAR_MONTH_FORMAT)));
  120. //账号
  121. param.set("character_string3", JSONUtil.createObj().set("value", js.getcOpenId()));
  122. weChatUtil.notification(js.getcOpenId(), wxPayProperties.getTemplateId2(), param);
  123. }
  124. @Override
  125. public boolean updateLocation(TJs js) {
  126. if (StringUtils.isBlank(js.getcOpenId())) {
  127. throw new ServiceException("技师OpenID不能为空");
  128. }
  129. if (StringUtils.isBlank(js.getName())) {
  130. throw new ServiceException("地址不能为空");
  131. }
  132. // JSONObject jsonObject = new JSONObject(js.getcAddress());
  133. // Object latitude = jsonObject.get("latitude");
  134. // Object longitude = jsonObject.get("longitude");
  135. locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(js.getLongitude().toString()), Double.parseDouble(js.getLatitude().toString()));
  136. LambdaQueryWrapper<TJs> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  137. objectLambdaQueryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  138. return this.update(js, objectLambdaQueryWrapper);
  139. }
  140. @Override
  141. public void newOrderNotification(String openId) {
  142. // 订单号 23010000010101
  143. // 用户电话 15055556666
  144. // 用户名称 李四
  145. // 时间 2022年11月11日22:22
  146. // 服务地址 湖南长沙岳麓
  147. cn.hutool.json.JSONObject param = JSONUtil.createObj();
  148. //订单号
  149. param.set("character_string9", JSONUtil.createObj().set("value", "23010000010101"));
  150. //点话
  151. param.set("phone_number14",JSONUtil.createObj().set("value", "18360233903"));
  152. param.set("thing18",JSONUtil.createObj().set("value", "李四"));
  153. param.set("time6",JSONUtil.createObj().set("value", "2022年11月11日 22:22"));
  154. param.set("thing27",JSONUtil.createObj().set("value", "湖南长沙岳麓"));
  155. // weChatUtil.notification(openId, param);
  156. }
  157. @Override
  158. public boolean upPost(TJs js) {
  159. if (StringUtils.isBlank(js.getId())) {
  160. throw new ServiceException("技师ID不能为空");
  161. }
  162. if (js.getnStatus2() == null) {
  163. throw new ServiceException("岗位状态不能为空");
  164. }
  165. //上岗
  166. if (Objects.equals(js.getnStatus2(), JsStatusEnum.POST_ON_DUTY.getCode())) {
  167. //岗位状态为1时,设置nStatus为1
  168. js.setnStatus(JsStatusEnum.JS_SERVICEABLE.getCode());
  169. }
  170. if (Objects.equals(js.getnStatus2(), JsStatusEnum.POST_NOT_ON_DUTY.getCode())) {
  171. //判断该技师是否有服务中的订单
  172. List<TOrder> list = orderService.list(new LambdaQueryWrapper<TOrder>().eq(TOrder::getnStatus, OrderStatusEnum.SERVICE).eq(TOrder::getcJsId, js.getId()));
  173. if (!list.isEmpty()) {
  174. throw new ServiceException("您有服务中的订单,不能下岗");
  175. }
  176. js.setnStatus(JsStatusEnum.JS_NO_SERVICE.getCode());
  177. }
  178. return this.updateById(js);
  179. }
  180. @Override
  181. public TJs getByJsId(String jsId, String openId) {
  182. if (jsId == null || jsId.trim().isEmpty()) {
  183. // 处理空或空白的jsId
  184. throw new ServiceException("Id为空");
  185. }
  186. TJs js = this.getById(jsId);
  187. if (js == null) {
  188. // 处理getById返回null的情况
  189. return null; // 或者返回一个新的TJs实例,具体看业务需求
  190. }
  191. if (StringUtils.isBlank(js.getcBhList())) {
  192. // 处理js.getcBhList()返回null或空列表的情况
  193. js.setProjects(new ArrayList<>()); // 设置空列表,避免后续调用空指针
  194. return js;
  195. }
  196. //项目
  197. List<String> projectIds = Arrays.stream(js.getcBhList().split(",")).collect(Collectors.toList());
  198. LambdaQueryWrapper<TXiangmu> xiangmuLambdaQueryWrapper = new LambdaQueryWrapper<>();
  199. xiangmuLambdaQueryWrapper.in(TXiangmu::getcId, projectIds);
  200. List<TXiangmu> projects = xiangmuService.list(xiangmuLambdaQueryWrapper);
  201. js.setProjects(projects);
  202. //评论
  203. LambdaQueryWrapper<TComment> commentLambdaQueryWrapper = new LambdaQueryWrapper<>();
  204. commentLambdaQueryWrapper.eq(TComment::getcJsid, jsId);
  205. List<TComment> list = commentService.list(commentLambdaQueryWrapper);
  206. if (CollectionUtil.isNotEmpty(list)) {
  207. js.setComments(list);
  208. }
  209. //是否收藏
  210. LambdaQueryWrapper<TCollect> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
  211. objectLambdaQueryWrapper.eq(TCollect::getcJsId, jsId).eq(TCollect::getcWxOpenId, openId);
  212. TCollect collect = collectService.getOne(objectLambdaQueryWrapper);
  213. if (collect != null) {
  214. js.setIsCollection(true);
  215. } else {
  216. js.setIsCollection(false);
  217. }
  218. return js;
  219. }
  220. private static void initialization(TJs js) {
  221. // 评分默认最高
  222. js.setnStar(MassageConstants.INTEGER_FIVE);
  223. // 已服务数量 0
  224. js.setnNum(MassageConstants.INTEGER_ZERO);
  225. // 佣金比例 10
  226. js.setnBili(MassageConstants.INTEGER_TEN);
  227. // 服务状态
  228. js.setnStatus(JsStatusEnum.JS_NO_SERVICE.getCode());
  229. // 上岗状态
  230. js.setnStatus2(JsStatusEnum.POST_NOT_ON_DUTY.getCode());
  231. // 审核状态
  232. js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
  233. js.setnB1(MassageConstants.INTEGER_ZERO);
  234. js.setnB2(MassageConstants.INTEGER_ONE);
  235. js.setnB3(MassageConstants.INTEGER_ZERO);
  236. js.setDtCreateTime(LocalDateTime.now());
  237. }
  238. }