|
@@ -1,11 +1,15 @@
|
|
|
package com.sqx.modules.errand.service.impl;
|
|
package com.sqx.modules.errand.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
|
|
+import com.sqx.common.sms.SmsSendResult;
|
|
|
import com.sqx.common.utils.DateUtils;
|
|
import com.sqx.common.utils.DateUtils;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.common.utils.Result;
|
|
import com.sqx.common.utils.Result;
|
|
@@ -20,17 +24,19 @@ import com.sqx.modules.common.entity.CommonInfo;
|
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
|
import com.sqx.modules.errand.dao.ErrandEvaluateDao;
|
|
import com.sqx.modules.errand.dao.ErrandEvaluateDao;
|
|
|
import com.sqx.modules.errand.dao.TbIndentDao;
|
|
import com.sqx.modules.errand.dao.TbIndentDao;
|
|
|
|
|
+import com.sqx.modules.errand.dto.RiderDeliveryDTO;
|
|
|
import com.sqx.modules.errand.entity.ErrandAddress;
|
|
import com.sqx.modules.errand.entity.ErrandAddress;
|
|
|
import com.sqx.modules.errand.entity.ErrandEvaluate;
|
|
import com.sqx.modules.errand.entity.ErrandEvaluate;
|
|
|
import com.sqx.modules.errand.entity.ErrandRedPacket;
|
|
import com.sqx.modules.errand.entity.ErrandRedPacket;
|
|
|
import com.sqx.modules.errand.entity.TbIndent;
|
|
import com.sqx.modules.errand.entity.TbIndent;
|
|
|
import com.sqx.modules.errand.service.TbIndentService;
|
|
import com.sqx.modules.errand.service.TbIndentService;
|
|
|
|
|
+import com.sqx.modules.errand.service.TbIndentSmsSendLogService;
|
|
|
|
|
+import com.sqx.modules.errand.service.TbIndentSmsTemplateService;
|
|
|
import com.sqx.modules.errand.util.LonLatUtil;
|
|
import com.sqx.modules.errand.util.LonLatUtil;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
|
import com.sqx.modules.goods.entity.GoodsShop;
|
|
import com.sqx.modules.goods.entity.GoodsShop;
|
|
|
import com.sqx.modules.goods.entity.GoodsShopRelevancy;
|
|
import com.sqx.modules.goods.entity.GoodsShopRelevancy;
|
|
|
-import com.sqx.modules.message.dao.MessageInfoDao;
|
|
|
|
|
import com.sqx.modules.message.entity.MessageInfo;
|
|
import com.sqx.modules.message.entity.MessageInfo;
|
|
|
import com.sqx.modules.message.service.MessageService;
|
|
import com.sqx.modules.message.service.MessageService;
|
|
|
import com.sqx.modules.order.dao.OrderGoodsDao;
|
|
import com.sqx.modules.order.dao.OrderGoodsDao;
|
|
@@ -52,9 +58,16 @@ import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Random;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -92,6 +105,12 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
private MessageService messageService;
|
|
private MessageService messageService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private GoodsShopRelevancyDao goodsShopRelevancyDao;
|
|
private GoodsShopRelevancyDao goodsShopRelevancyDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TbIndentSmsTemplateService smsTemplateService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TbIndentSmsSendLogService smsSendLogService;
|
|
|
|
|
+
|
|
|
private ReentrantReadWriteLock reentrantReadWriteLock=new ReentrantReadWriteLock(true);
|
|
private ReentrantReadWriteLock reentrantReadWriteLock=new ReentrantReadWriteLock(true);
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -803,17 +822,73 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Result riderDelivery(Long userId, String indentNumber, String itemCode) {
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Result riderDelivery(Long userId, RiderDeliveryDTO deliveryDTO) {
|
|
|
|
|
+ // 添加拍照发短信逻辑
|
|
|
|
|
+ // 因为原有的确认送达方法代码比较凌乱,且不好重新封装,所以这里就在原有确认收货方法之前添加拍照发短信逻辑
|
|
|
reentrantReadWriteLock.writeLock().lock();
|
|
reentrantReadWriteLock.writeLock().lock();
|
|
|
try{
|
|
try{
|
|
|
- return finshOrder(userId, indentNumber, itemCode);
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ String indentNumber = deliveryDTO.getIndentNumber();
|
|
|
|
|
+ TbIndent indentOrder = tbIndentDao.findIndentByNumber(indentNumber);
|
|
|
|
|
+ if (ObjectUtil.isNull(indentOrder)) {
|
|
|
|
|
+ throw new SqxException("无效的跑腿订单id");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果是外卖订单
|
|
|
|
|
+ if (ObjectUtil.equal(indentOrder.getIndentType(), "5")) {
|
|
|
|
|
+ handTakeoutOrder(indentOrder, userId, deliveryDTO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return finshOrder(userId, indentNumber, deliveryDTO.getItemCode());
|
|
|
|
|
+ } catch (Exception e){
|
|
|
log.error("完成订单异常:"+e.getMessage(),e);
|
|
log.error("完成订单异常:"+e.getMessage(),e);
|
|
|
- }finally {
|
|
|
|
|
|
|
+ throw new SqxException(e.getMessage());
|
|
|
|
|
+ } finally {
|
|
|
reentrantReadWriteLock.writeLock().unlock();
|
|
reentrantReadWriteLock.writeLock().unlock();
|
|
|
}
|
|
}
|
|
|
- return Result.error("系统繁忙,请稍后再试!");
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理外卖订单
|
|
|
|
|
+ * @param indentOrder 跑腿订单
|
|
|
|
|
+ * @param userId 当前用户id
|
|
|
|
|
+ * @param deliveryDTO 送达信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handTakeoutOrder(TbIndent indentOrder, Long userId, RiderDeliveryDTO deliveryDTO) {
|
|
|
|
|
+ // 6表示跑腿订单处于已完成状态
|
|
|
|
|
+ if("6".equals(indentOrder.getIndentState())){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long smsTemplateId = deliveryDTO.getSmsTemplateId();
|
|
|
|
|
+ String imgs = deliveryDTO.getImgs();
|
|
|
|
|
+ if (ObjectUtil.isNull(smsTemplateId) || StrUtil.isBlank(imgs)) {
|
|
|
|
|
+ throw new SqxException("短信模板id或图片不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 收货人手机
|
|
|
|
|
+ String userPhone = indentOrder.getUserPhone();
|
|
|
|
|
+ // 当前骑手
|
|
|
|
|
+ UserEntity riderUser = userService.getById(userId);
|
|
|
|
|
+
|
|
|
|
|
+ if (StrUtil.isBlank(userPhone)) {
|
|
|
|
|
+ log.error("外卖跑腿订单【{}】收货人手机号码为空...", deliveryDTO.getIndentNumber());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ObjectUtil.isNull(riderUser) || StrUtil.isBlank(riderUser.getPhone())) {
|
|
|
|
|
+ log.error("外卖跑腿订单【{}】当前骑手id【{}】骑手不存在,或当前骑手手机号码为空...", deliveryDTO.getIndentNumber(), userId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 订单新增送达图片
|
|
|
|
|
+ TbOrder tbOrder = appOrderService.getById(indentOrder.getOrderId());
|
|
|
|
|
+ tbOrder.setDeliveryImgs(imgs);
|
|
|
|
|
+ appOrderService.updateById(tbOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 发送短信并记录短信发送记录
|
|
|
|
|
+ SmsSendResult smsSendResult = smsTemplateService.sendSms(smsTemplateId, riderUser, userPhone);
|
|
|
|
|
+ smsSendLogService.saveLog(indentOrder.getIndentId(), smsSendResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|