123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- package com.ylx.massage.service.impl;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.json.JSONObject;
- import cn.hutool.json.JSONUtil;
- 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.ylx.common.config.WechatAccountConfig;
- import com.ylx.common.constant.MassageConstants;
- import com.ylx.common.exception.ServiceException;
- import com.ylx.common.utils.StringUtils;
- import com.ylx.massage.domain.*;
- import com.ylx.massage.domain.vo.TJsVo;
- import com.ylx.massage.enums.JsStatusEnum;
- import com.ylx.massage.enums.OrderStatusEnum;
- import com.ylx.massage.mapper.TJsMapper;
- import com.ylx.massage.service.*;
- import com.ylx.massage.utils.DateTimeUtils;
- import com.ylx.massage.utils.LocationUtil;
- import com.ylx.massage.utils.WeChatUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.time.LocalDateTime;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 技师表 服务实现类
- */
- @Service
- @Slf4j
- public class TJsServiceImpl extends ServiceImpl<TJsMapper, TJs> implements TJsService {
- @Resource
- private TJsMapper mapper;
- @Resource
- private WechatAccountConfig wxPayProperties;
- @Resource
- private LocationUtil locationUtil;
- @Resource
- private TCollectService collectService;
- @Resource
- private TXiangmuService xiangmuService;
- @Resource
- private TCommentService commentService;
- @Resource
- private TWxUserService wxUserService;
- @Resource
- private WeChatUtil weChatUtil;
- @Resource
- private TOrderService orderService;
- @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.getName())) {
- throw new ServiceException("地址不能为空");
- }
- if (StringUtils.isNotBlank(js.getId())) {
- TJs oldJs = this.getById(js.getId());
- if (oldJs.getnTong().equals(JsStatusEnum.JS_RETURN.getCode())) {
- js.setnTong(JsStatusEnum.JS_NOT_PASS.getCode());
- }
- }
- // 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(js.getLongitude().toString()), Double.parseDouble(js.getLatitude().toString()));
- }
- @Override
- public boolean wxUpdateJs(TJs js) {
- cacheAddress(js);
- return this.updateById(js);
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public boolean auditing(TJs js) {
- TJs js1 = this.getById(js.getId());
- LambdaQueryWrapper<TJs> jsLambdaQueryWrapper = new LambdaQueryWrapper<>();
- jsLambdaQueryWrapper.eq(TJs::getId, js.getId()).eq(TJs::getnTong, JsStatusEnum.JS_NOT_PASS.getCode());
- js.setnTong(JsStatusEnum.JS_PASS.getCode());
- LambdaQueryWrapper<TWxUser> wxLambdaQueryWrapper = new LambdaQueryWrapper<>();
- wxLambdaQueryWrapper.eq(TWxUser::getcOpenid, js1.getcOpenId());
- TWxUser tWxUser = new TWxUser();
- tWxUser.setRole(1);
- wxUserService.update(tWxUser, wxLambdaQueryWrapper);
- boolean update = this.update(js, jsLambdaQueryWrapper);
- js.setcOpenId(js1.getcOpenId());
- this.jsNotification(js);
- return update;
- }
- @Override
- public void jsNotification(TJs js) {
- cn.hutool.json.JSONObject param = JSONUtil.createObj();
- //是否审核通过
- if(JsStatusEnum.JS_PASS.getCode().equals(js.getnTong())){
- param.set("const1", JSONUtil.createObj().set("value", "审核通过可以接单"));
- }else{
- param.set("const1", JSONUtil.createObj().set("value", "审核驳回请重新提交"));
- }
- //审核时间
- param.set("time2", JSONUtil.createObj().set("value", DateTimeUtils.formatDate(new Date(), DateTimeUtils.DATE_NUMBER_YEAR_MONTH_FORMAT)));
- //账号
- param.set("character_string3", JSONUtil.createObj().set("value", js.getcOpenId()));
- weChatUtil.notification(js.getcOpenId(), wxPayProperties.getTemplateId2(), param);
- }
- @Override
- public boolean updateLocation(TJs js) {
- if (StringUtils.isBlank(js.getcOpenId())) {
- throw new ServiceException("技师OpenID不能为空");
- }
- if (StringUtils.isBlank(js.getName())) {
- throw new ServiceException("地址不能为空");
- }
- // JSONObject jsonObject = new JSONObject(js.getcAddress());
- // Object latitude = jsonObject.get("latitude");
- // Object longitude = jsonObject.get("longitude");
- locationUtil.geoAdd(js.getcOpenId(), Double.parseDouble(js.getLongitude().toString()), Double.parseDouble(js.getLatitude().toString()));
- LambdaQueryWrapper<TJs> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
- objectLambdaQueryWrapper.eq(TJs::getcOpenId, js.getcOpenId());
- return this.update(js, objectLambdaQueryWrapper);
- }
- @Override
- public void newOrderNotification(String openId) {
- // 订单号 23010000010101
- // 用户电话 15055556666
- // 用户名称 李四
- // 时间 2022年11月11日22:22
- // 服务地址 湖南长沙岳麓
- cn.hutool.json.JSONObject param = JSONUtil.createObj();
- //订单号
- param.set("character_string9", JSONUtil.createObj().set("value", "23010000010101"));
- //点话
- param.set("phone_number14",JSONUtil.createObj().set("value", "18360233903"));
- param.set("thing18",JSONUtil.createObj().set("value", "李四"));
- param.set("time6",JSONUtil.createObj().set("value", "2022年11月11日 22:22"));
- param.set("thing27",JSONUtil.createObj().set("value", "湖南长沙岳麓"));
- // weChatUtil.notification(openId, param);
- }
- @Override
- public boolean upPost(TJs js) {
- if (StringUtils.isBlank(js.getId())) {
- throw new ServiceException("技师ID不能为空");
- }
- if (js.getnStatus2() == null) {
- throw new ServiceException("岗位状态不能为空");
- }
- //上岗
- if (Objects.equals(js.getnStatus2(), JsStatusEnum.POST_ON_DUTY.getCode())) {
- //岗位状态为1时,设置nStatus为1
- js.setnStatus(JsStatusEnum.JS_SERVICEABLE.getCode());
- }
- if (Objects.equals(js.getnStatus2(), JsStatusEnum.POST_NOT_ON_DUTY.getCode())) {
- //判断该技师是否有服务中的订单
- List<TOrder> list = orderService.list(new LambdaQueryWrapper<TOrder>().eq(TOrder::getnStatus, OrderStatusEnum.SERVICE).eq(TOrder::getcJsId, js.getId()));
- if (!list.isEmpty()) {
- throw new ServiceException("您有服务中的订单,不能下岗");
- }
- js.setnStatus(JsStatusEnum.JS_NO_SERVICE.getCode());
- }
- return this.updateById(js);
- }
- @Override
- public TJs getByJsId(String jsId, String openId) {
- 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);
- //评论
- LambdaQueryWrapper<TComment> commentLambdaQueryWrapper = new LambdaQueryWrapper<>();
- commentLambdaQueryWrapper.eq(TComment::getcJsid, jsId);
- List<TComment> list = commentService.list(commentLambdaQueryWrapper);
- if (CollectionUtil.isNotEmpty(list)) {
- js.setComments(list);
- }
- //是否收藏
- LambdaQueryWrapper<TCollect> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
- objectLambdaQueryWrapper.eq(TCollect::getcJsId, jsId).eq(TCollect::getcWxOpenId, openId);
- TCollect collect = collectService.getOne(objectLambdaQueryWrapper);
- if (collect != null) {
- js.setIsCollection(true);
- } else {
- js.setIsCollection(false);
- }
- 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_NO_SERVICE.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_ONE);
- js.setnB3(MassageConstants.INTEGER_ZERO);
- js.setDtCreateTime(LocalDateTime.now());
- }
- }
|