123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package com.ylx.massage.service.impl;
- import cn.hutool.json.JSONObject;
- import com.alibaba.fastjson.JSONArray;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.google.common.collect.Lists;
- import com.ylx.common.constant.MassageConstants;
- import com.ylx.common.exception.ServiceException;
- import com.ylx.common.utils.StringUtils;
- import com.ylx.massage.domain.TJs;
- import com.ylx.massage.domain.TXiangmu;
- import com.ylx.massage.domain.vo.TJsVo;
- import com.ylx.massage.enums.JsStatusEnum;
- import com.ylx.massage.mapper.TJsMapper;
- import com.ylx.massage.service.TJsService;
- import com.ylx.massage.service.TXiangmuService;
- import com.ylx.massage.utils.LocationUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 技师表 服务实现类
- */
- @Service
- @Slf4j
- public class TJsServiceImpl extends ServiceImpl<TJsMapper, TJs> implements TJsService {
- @Resource
- private TJsMapper mapper;
- @Resource
- private LocationUtil locationUtil;
- @Resource
- private TXiangmuService xiangmuService;
- @Override
- public Page<TJs> getAll(Page<TJs> page, TJsVo param) {
- return mapper.getAll(page, param);
- }
- @Override
- public boolean addJs(TJs js) {
- LambdaQueryWrapper<TJs> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
- TJs cjs = this.getOne(queryWrapper);
- if (cjs != null) {
- throw new ServiceException("请勿重复申请");
- }
- cacheAddress(js);
- initialization(js);
- return this.save(js);
- }
- private void cacheAddress(TJs js) {
- if (StringUtils.isBlank(js.getcPhone())) {
- throw new ServiceException("手机号不能为空");
- }
- if (StringUtils.isBlank(js.getcAddress())) {
- throw new ServiceException("地址不能为空");
- }
- log.info("js:{}", js);
- JSONObject jsonObject = new JSONObject(js.getcAddress());
- Object latitude = jsonObject.get("latitude");
- Object longitude = jsonObject.get("longitude");
- locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(longitude.toString()), Double.parseDouble(latitude.toString()));
- }
- @Override
- public boolean wxUpdateJs(TJs js) {
- cacheAddress(js);
- return this.updateById(js);
- }
- @Override
- public TJs getByJsId(String jsId) {
- if (jsId == null || jsId.trim().isEmpty()) {
- // 处理空或空白的jsId
- throw new ServiceException("Id为空");
- }
- TJs js = this.getById(jsId);
- if (js == null) {
- // 处理getById返回null的情况
- return null; // 或者返回一个新的TJs实例,具体看业务需求
- }
- if (StringUtils.isBlank(js.getcBhList())) {
- // 处理js.getcBhList()返回null或空列表的情况
- js.setProjects(new ArrayList<>()); // 设置空列表,避免后续调用空指针
- return js;
- }
- List<String> projectIds = Arrays.stream(js.getcBhList().split(",")).collect(Collectors.toList());
- LambdaQueryWrapper<TXiangmu> xiangmuLambdaQueryWrapper = new LambdaQueryWrapper<>();
- xiangmuLambdaQueryWrapper.in(TXiangmu::getcId, projectIds);
- List<TXiangmu> projects = xiangmuService.list(xiangmuLambdaQueryWrapper);
- js.setProjects(projects);
- return js;
- }
- private static void initialization(TJs js) {
- // 评分默认最高
- js.setnStar(MassageConstants.INTEGER_FIVE);
- // 已服务数量 0
- js.setnNum(MassageConstants.INTEGER_ZERO);
- // 佣金比例 10
- js.setnBili(MassageConstants.INTEGER_TEN);
- // 服务状态
- js.setnStatus(JsStatusEnum.JS_SERVICEABLE.getCode());
- // 上岗状态
- js.setnStatus2(JsStatusEnum.POST_NOT_ON_DUTY.getCode());
- // 审核状态
- js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
- js.setnB1(MassageConstants.INTEGER_ZERO);
- js.setnB2(MassageConstants.INTEGER_ZERO);
- js.setnB3(MassageConstants.INTEGER_ZERO);
- js.setDtCreateTime(LocalDateTime.now());
- }
- }
|