TJsServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.ylx.massage.service.impl;
  2. import cn.hutool.json.JSONObject;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.google.common.collect.Lists;
  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.TJs;
  12. import com.ylx.massage.domain.TXiangmu;
  13. import com.ylx.massage.domain.vo.TJsVo;
  14. import com.ylx.massage.enums.JsStatusEnum;
  15. import com.ylx.massage.mapper.TJsMapper;
  16. import com.ylx.massage.service.TJsService;
  17. import com.ylx.massage.service.TXiangmuService;
  18. import com.ylx.massage.utils.LocationUtil;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.stereotype.Service;
  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 TXiangmuService xiangmuService;
  39. @Override
  40. public Page<TJs> getAll(Page<TJs> page, TJsVo param) {
  41. return mapper.getAll(page, param);
  42. }
  43. @Override
  44. public boolean addJs(TJs js) {
  45. LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
  46. queryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
  47. TJs cjs = this.getOne(queryWrapper);
  48. if (cjs != null) {
  49. throw new ServiceException("请勿重复申请");
  50. }
  51. cacheAddress(js);
  52. initialization(js);
  53. return this.save(js);
  54. }
  55. private void cacheAddress(TJs js) {
  56. if (StringUtils.isBlank(js.getcPhone())) {
  57. throw new ServiceException("手机号不能为空");
  58. }
  59. if (StringUtils.isBlank(js.getcAddress())) {
  60. throw new ServiceException("地址不能为空");
  61. }
  62. log.info("js:{}", js);
  63. JSONObject jsonObject = new JSONObject(js.getcAddress());
  64. Object latitude = jsonObject.get("latitude");
  65. Object longitude = jsonObject.get("longitude");
  66. locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(longitude.toString()), Double.parseDouble(latitude.toString()));
  67. }
  68. @Override
  69. public boolean wxUpdateJs(TJs js) {
  70. cacheAddress(js);
  71. return this.updateById(js);
  72. }
  73. @Override
  74. public TJs getByJsId(String jsId) {
  75. if (jsId == null || jsId.trim().isEmpty()) {
  76. // 处理空或空白的jsId
  77. throw new ServiceException("Id为空");
  78. }
  79. TJs js = this.getById(jsId);
  80. if (js == null) {
  81. // 处理getById返回null的情况
  82. return null; // 或者返回一个新的TJs实例,具体看业务需求
  83. }
  84. if (StringUtils.isBlank(js.getcBhList())) {
  85. // 处理js.getcBhList()返回null或空列表的情况
  86. js.setProjects(new ArrayList<>()); // 设置空列表,避免后续调用空指针
  87. return js;
  88. }
  89. List<String> projectIds = Arrays.stream(js.getcBhList().split(",")).collect(Collectors.toList());
  90. LambdaQueryWrapper<TXiangmu> xiangmuLambdaQueryWrapper = new LambdaQueryWrapper<>();
  91. xiangmuLambdaQueryWrapper.in(TXiangmu::getcId, projectIds);
  92. List<TXiangmu> projects = xiangmuService.list(xiangmuLambdaQueryWrapper);
  93. js.setProjects(projects);
  94. return js;
  95. }
  96. private static void initialization(TJs js) {
  97. // 评分默认最高
  98. js.setnStar(MassageConstants.INTEGER_FIVE);
  99. // 已服务数量 0
  100. js.setnNum(MassageConstants.INTEGER_ZERO);
  101. // 佣金比例 10
  102. js.setnBili(MassageConstants.INTEGER_TEN);
  103. // 服务状态
  104. js.setnStatus(JsStatusEnum.JS_SERVICEABLE.getCode());
  105. // 上岗状态
  106. js.setnStatus2(JsStatusEnum.POST_NOT_ON_DUTY.getCode());
  107. // 审核状态
  108. js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
  109. js.setnB1(MassageConstants.INTEGER_ZERO);
  110. js.setnB2(MassageConstants.INTEGER_ZERO);
  111. js.setnB3(MassageConstants.INTEGER_ZERO);
  112. js.setDtCreateTime(LocalDateTime.now());
  113. }
  114. }