|
@@ -0,0 +1,121 @@
|
|
|
|
|
+package com.ruoyi.app.order;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 订单商家操作
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.ruoyi.app.order.dto.OrderPushBodyDto;
|
|
|
|
|
+import com.ruoyi.app.utils.PayPush;
|
|
|
|
|
+import com.ruoyi.app.utils.event.PushEventService;
|
|
|
|
|
+import com.ruoyi.common.annotation.Anonymous;
|
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
+import com.ruoyi.framework.manager.AsyncManager;
|
|
|
|
|
+import com.ruoyi.system.domain.InfoUser;
|
|
|
|
|
+import com.ruoyi.system.domain.PosOrder;
|
|
|
|
|
+import com.ruoyi.system.service.IInfoUserService;
|
|
|
|
|
+import com.ruoyi.system.service.IPosOrderService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * posorderController
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author ruoyi
|
|
|
|
|
+ * @date 2023-05-23
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/system/orderShOprate")
|
|
|
|
|
+public class PosOrderShOprateController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IPosOrderService posOrderService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IInfoUserService infoUserService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PushEventService pushEventService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商家出餐
|
|
|
|
|
+ * @param token
|
|
|
|
|
+ * @param ddId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Anonymous
|
|
|
|
|
+ @GetMapping("/dispatchOrder")
|
|
|
|
|
+ public AjaxResult dispatchOrder(@RequestHeader String token, @RequestParam Long ddId){
|
|
|
|
|
+ PosOrder order=posOrderService.getOne(new LambdaQueryWrapper<PosOrder>().eq(PosOrder::getDdId,ddId));
|
|
|
|
|
+ PosOrder update=new PosOrder();
|
|
|
|
|
+ update.setId(order.getId());
|
|
|
|
|
+ update.setDiningStatus(1L);
|
|
|
|
|
+ if(1L==order.getType()) {
|
|
|
|
|
+ update.setState(12L);
|
|
|
|
|
+ }
|
|
|
|
|
+ posOrderService.saveOrUpdate(update);
|
|
|
|
|
+ if(0L==order.getType()){
|
|
|
|
|
+ chuCan(order,update);
|
|
|
|
|
+ }
|
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商家出餐推送:给用户和骑手推送通知
|
|
|
|
|
+ */
|
|
|
|
|
+ public void chuCan(PosOrder oldOrder, PosOrder posOrder) {
|
|
|
|
|
+ if (oldOrder.getDiningStatus() != null && oldOrder.getDiningStatus() == 0
|
|
|
|
|
+ && posOrder.getDiningStatus() != null && posOrder.getDiningStatus().equals(1L)) {
|
|
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
|
|
+ ids.add(oldOrder.getUserId());
|
|
|
|
|
+ if (oldOrder.getQsId() != null) {
|
|
|
|
|
+ ids.add(oldOrder.getQsId());
|
|
|
|
|
+ }
|
|
|
|
|
+ List<InfoUser> users = infoUserService.list(new LambdaQueryWrapper<InfoUser>().in(InfoUser::getUserId, ids));
|
|
|
|
|
+ Optional<InfoUser> user = users.stream().filter(x -> "0".equals(x.getUserType())).findFirst();
|
|
|
|
|
+ Optional<InfoUser> qsUser = users.stream().filter(x -> "2".equals(x.getUserType())).findFirst();
|
|
|
|
|
+
|
|
|
|
|
+ String title = "no.message.push.message";
|
|
|
|
|
+ String content = "no.message.push.merchant.ready.content";
|
|
|
|
|
+ Long stateVal = posOrder.getState() != null ? posOrder.getState() : oldOrder.getState();
|
|
|
|
|
+ String stateStr = stateVal != null ? String.valueOf(stateVal) : "2";
|
|
|
|
|
+ String body = OrderPushBodyDto.getJson(String.valueOf(oldOrder.getDdId()), stateStr);
|
|
|
|
|
+ String ddId = String.valueOf(oldOrder.getDdId());
|
|
|
|
|
+
|
|
|
|
|
+ // 给用户推送
|
|
|
|
|
+ if (user.isPresent()) {
|
|
|
|
|
+ InfoUser u = user.get();
|
|
|
|
|
+ PayPush push = new PayPush();
|
|
|
|
|
+ Long uUserId = u.getUserId();
|
|
|
|
|
+ String uCid = u.getCid();
|
|
|
|
|
+ AsyncManager.me().execute(new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ PayPush.userPushHandleLocal(push, pushEventService, uUserId, uCid, title, content, body, "", ddId);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ // 给骑手推送
|
|
|
|
|
+ if (qsUser.isPresent()) {
|
|
|
|
|
+ InfoUser qs = qsUser.get();
|
|
|
|
|
+ if (!StringUtils.isEmpty(qs.getCid())) {
|
|
|
|
|
+ PayPush push = new PayPush();
|
|
|
|
|
+ Long qsUserId = qs.getUserId();
|
|
|
|
|
+ String qsCid = qs.getCid();
|
|
|
|
|
+ AsyncManager.me().execute(new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ PayPush.qsPushHandleLocal(push, pushEventService, qsUserId, qsCid, title, content, body, "", ddId);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|