浏览代码

1.PC新增商户配送员接口
2.APP新增配送员完成配送接口

FengChaoYu 3 周之前
父节点
当前提交
c667369f53

+ 31 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/order/OrderDeliverController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.miniapp.bean.order.OrderDeliverBean;
 import com.gree.mall.miniapp.bean.order.OrderDetailBean;
 import com.gree.mall.miniapp.bean.workorder.CountOrderStatusBean;
+import com.gree.mall.miniapp.constant.Constant;
 import com.gree.mall.miniapp.helper.ResponseHelper;
 import com.gree.mall.miniapp.logic.order.OrderDeliverLogic;
 import com.gree.mall.miniapp.plus.entity.OrderInfo;
@@ -11,9 +12,14 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.text.ParseException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -23,6 +29,8 @@ public class OrderDeliverController {
 
     @Resource
     OrderDeliverLogic orderDeliverLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
     @PostMapping("/list")
     @ApiOperation("配送订单")
@@ -37,8 +45,30 @@ public class OrderDeliverController {
 
     @PostMapping("/status/count")
     @ApiOperation(value = "工单状态统计")
-    public ResponseHelper<CountOrderStatusBean> countStatus() throws Exception{
+    public ResponseHelper<CountOrderStatusBean> countStatus() throws Exception {
         CountOrderStatusBean countOrderStatusBean = orderDeliverLogic.countOrderStatus();
         return ResponseHelper.success(countOrderStatusBean);
     }
+
+    @PostMapping("/finish")
+    @ApiOperation("完成配送")
+    public ResponseHelper submitAll(
+            @ApiParam(required = true, value = "订单id") @RequestParam String orderId,
+            @ApiParam(required = true, value = "完成配送图片url") @RequestParam(required = false) String url,
+            @ApiParam(value = "备注") @RequestParam(required = false) String finishRemark,
+            @ApiParam(value = "经度") @RequestParam(required = false) String lng,
+            @ApiParam(value = "纬度") @RequestParam(required = false) String lat,
+            HttpServletRequest request
+    ) throws Exception {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER + orderId);
+        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+            return ResponseHelper.error("系统繁忙,请稍后再试");
+        }
+        try {
+            orderDeliverLogic.finish(orderId, url, finishRemark, lng, lat);
+            return ResponseHelper.success();
+        }finally {
+            obtain.unlock();
+        }
+    }
 }

+ 18 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/order/OrderDeliverLogic.java

@@ -7,6 +7,8 @@ import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
 import com.gree.mall.miniapp.bean.workorder.CountOrderStatusBean;
 import com.gree.mall.miniapp.commonmapper.CommonMapper;
 import com.gree.mall.miniapp.commonmapper.workorder.OrderBaseCMapper;
+import com.gree.mall.miniapp.enums.OrderStatusEnum;
+import com.gree.mall.miniapp.exception.RemoteServiceException;
 import com.gree.mall.miniapp.logic.common.CommonLogic;
 import com.gree.mall.miniapp.plus.entity.OrderInfo;
 import com.gree.mall.miniapp.plus.service.OrderInfoService;
@@ -40,4 +42,20 @@ public class OrderDeliverLogic {
 
         return countOrderStatusBean3;
     }
+
+    public void finish(String orderId, String url, String finishRemark, String lng, String lat) {
+        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
+        // TODO 完成配送逻辑
+        final OrderInfo orderInfo = orderInfoService.getById(orderId);
+        if (!orderInfo.getOrderStatus().equals(OrderStatusEnum.PSZ.toString())) {
+            throw new RemoteServiceException("订单状态非“配送中”,不能操作完成配送");
+        }
+
+        orderInfoService.lambdaUpdate()
+                .set(OrderInfo::getOrderStatus, OrderStatusEnum.OVER.toString())
+                .set(OrderInfo::getLastOrderStatus, OrderStatusEnum.PSZ.toString())
+                .eq(OrderInfo::getOrderId, orderId)
+                .eq(OrderInfo::getDeliveryUserId, currentCompanyWechat.getUserId())
+                .update();
+    }
 }

+ 2 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/user/UserLogic.java

@@ -746,12 +746,14 @@ public class UserLogic {
                 .one();
         UserWait userWait = null;
         if (Objects.isNull(user)) {
+            // 师傅信息没有就查找初始化师傅表
             userWait = userWaitService.lambdaQuery()
                     .eq(UserWait::getMobile, mobile)
                     .eq(UserWait::getUserType, UserTypeEnum.WORKER.getKey())
                     .last("limit 1")
                     .one();
 
+            // 没有师傅信息抛出错误
             if (Objects.isNull(userWait)) {
                 throw new RemoteServiceException("无师傅信息");
             }

+ 1 - 67
mall-server-api/src/main/java/com/gree/mall/manager/constant/Constant.java

@@ -49,26 +49,9 @@ public class Constant {
 
     public class RedisPrefix {
         public final static String LOCK_LOGIN = "zfire:overseas:login:";
-        public final static String WORK_MINI_ACCESS_TOKEN = "zfire:overseas:work:mini:access:token";
-        public final static String TOKEN_WX = "zfire:overseas:token:wx";
-        public final static String TOKEN_MP_WX = "mp:token:wx";
-        public final static String TOKEN_TAX = "zfire:overseas:token:tax";
-        public final static String TOKEN_GONGDAN = "zfire:overseas:token:gongdan";
         public final static String LOCK_ORDER = "zfire:overseas:lock:order";
-        public final static String LOCK_ORDER_STOCK = "zfire:overseas:lock:stock";
-        public final static String LOCK_WX_SYNC = "zfire:overseas:lock:wx:sync";
-        public final static String LOCK_SOP_SYNC = "zfire:overseas:lock:sop";
-        public final static String CHAT_MESSAGE_SEQ_KEY = "CHAT_MESSAGE_SEQ";
-        public final static String LOCK_EXCHANGE_CODE = "zfire:overseas:lock:exchangecode";
-        public final static String PARTS_BASE_MANAGE = "zfire:overseas:lock:parts:base:manage:";
-        public final static String MATERIAL_CATEGORY = "zfire:overseas:lock:material:category:";
-        public final static String MATERIAL_PURCHASE = "zfire:overseas:lock:material:purchase:";
-        public final static String MATERIAL_STOCK_LOCK = "zfire:overseas:lock:material:stock:";
-        public final static String MATERIAL_SALES = "zfire:overseas:lock:material:sales:";
         public final static String GOODS_MATERIAL_PURCHASE = "zfire:overseas:lock:goods:material:purchase:";
         public final static String GOODS_MATERIAL_PURCHASE_RET = "zfire:overseas:lock:goods:material:purchase:ret:";
-        public final static String MATERIAL_WORKER_INCR = "zfire:overseas:lock:material:worker:incr";
-        public final static String TRADE_RECORD_LOCK = "zfire:overseas:lock:trade:record:";
         public final static String LOCK_ORDER_OFFLINE = "zfire:overseas:lock:order:offline:";
         //订单号每日流水
         public final static String ORDER_NUM = "zfire:overseas:orderNo:";
@@ -77,59 +60,10 @@ public class Constant {
 
         public final static String LOCK_GOODS_MATERIAL = "zfire:overseas:goods:material:";
 
-        public final static String ORDER_ENGIN_BASE =  "zfire:overseas:lock:order:engin:base:";
-
-        // 接口令牌
-        public final static String INF_TOKEN = "zfire:overseas:token:inf";
-
-        //维修日结汇总
-        public final static String LOCK_DAILY_BANKACCOUNT = "zfire:overseas:SETTLE:LOCK:BANKACCOUNT:";
-        public final static String LOCK_DAILY_SUMMARY = "zfire:overseas:SETTLE:LOCK:DAILY:SUMMARY";
-        public final static String BALANCE_SEL_MOBILE_SMS = "zfire:overseas:SETTLE:BALANCE:SMS";
-        public final static String ISSUE_SAL_MOBILE_SMS = "zfire:overseas:SETTLE:ISSUE:SMS";
-        public final static String LOCK_SUMMARY_ISSUE = "zfire:overseas:SETTLE:lock:issue:summary";
-        public static final String LOCK_MATERIAL_PURCHASE = "zfire:overseas:material:purchase:";
-
-        public final static String NEW_IN = "zfire:overseas:parts:new:in:";
-        public static final String OLD_OUT = "zfire:overseas:parts:old:out:";
-        public static final String NEW_REFUND = "zfire:overseas:parts:new:refund:";
-        public static final String PARTS_SALES = "zfire:overseas:lock:parts:sales:";
-        public static final String WRITE_SALES_ITEM = "zfire:overseas:parts:write:sales:item:";
-        public static final String NEW_CHANGE = "zfire:overseas:parts:change:sales:";
-        public static final String PARTS_REFUND = "zfire:overseas:lock:parts:refund";
-    }
-    public class ChatMessage {
-        public final static String MSG_TYPE_DOC = "docmsg";
-        public final static String MSG_TYPE_EXTERNAL_RED_PACKET = "external_redpacket";
-        /**
-         * 语音聊消息
-         */
-        public final static String MSG_TYPE_VOICE = "voice";
-
-        public final static String MSG_TYPE_VIDEO = "video";
-        /**
-         * 图片消息类型
-         */
-        public final static String MSG_TYPE_IMAGE = "image";
-
-        /**
-         * 音频存档消息
-         */
-        public final static String MSG_TYPE_MEETING_VOICE_CALL = "meeting_voice_call";
-        /**
-         * 表情消息
-         */
-        public final static  String MSG_TYPE_EMOTION = "emotion";
+        public final static String LOCK_COMMON =  "zfire:overseas:lock:common:";
 
     }
 
 
-    public class SharePercent {
-        public final static String SHARE_LIMIT_PERCENT = "0.2";
-    }
-
-    public class WXUrl {
-        public final static String WX_PUSH_MSG_URL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=";
-    }
 
 }

+ 30 - 3
mall-server-api/src/main/java/com/gree/mall/manager/controller/member/MemberController.java

@@ -13,6 +13,7 @@ import com.gree.mall.manager.bean.member.UserCompanyAttrBean;
 import com.gree.mall.manager.bean.member.UserCompanyDeliveryBean;
 import com.gree.mall.manager.bean.user.UserApplyWorkerBean;
 import com.gree.mall.manager.bean.user.UserWxBean;
+import com.gree.mall.manager.constant.Constant;
 import com.gree.mall.manager.enums.ExamineStatusEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.helper.ResponseHelper;
@@ -29,13 +30,17 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -47,6 +52,8 @@ public class MemberController {
     UserLogic userLogic;
     @Autowired
     GoodsLogic goodsLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
     @ZfireList
     @PostMapping("/list/customer")
@@ -331,15 +338,35 @@ public class MemberController {
     }
 
     @PostMapping("/company/delivery/import")
-    @ApiOperation(value = "配送员师傅-导入(模板名称:配送员师傅导入.xlsx)")
+    @ApiOperation(value = "作废 配送员师傅-导入(模板名称:配送员师傅导入.xlsx)")
     public ResponseHelper companyDeliveryImport(
             @RequestParam MultipartFile file
     ) throws RemoteServiceException, IOException {
-        List<Object> objects = ExcelUtils.importExcel(file);
-        userLogic.companyDeliveryImport(objects);
+//        List<Object> objects = ExcelUtils.importExcel(file);
+//        userLogic.companyDeliveryImport(objects);
+
         return ResponseHelper.success();
     }
 
+    @PostMapping("/company/delivery/add")
+    @ApiOperation(value = "商户配送员添加")
+    public ResponseHelper companyDeliveryAdd(
+            @ApiParam(value = "用户id", required = true) @RequestParam String mobile,
+            @ApiParam(value = "昵称", required = true) @RequestParam String nickName,
+            @ApiParam(value = "仓储id", required = true) @RequestParam String storageId
+    ) throws Exception {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_COMMON + mobile);
+        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+            return ResponseHelper.error("系统繁忙,请稍后再试");
+        }
+        try {
+            userLogic.companyDeliveryAdd(mobile, nickName, storageId);
+            return ResponseHelper.success();
+        }finally {
+            obtain.unlock();
+        }
+    }
+
     @PostMapping("/company/delivery/del")
     @ApiOperation(value = "商户配送员删除")
     public ResponseHelper companyDeliveryDel(

+ 40 - 7
mall-server-api/src/main/java/com/gree/mall/manager/logic/user/UserLogic.java

@@ -78,6 +78,7 @@ public class UserLogic {
     private final PgOrderWorkerService pgOrderWorkerService;
     private final UserCompanyDeliveryService userCompanyDeliveryService;
     private final UserCompanyAttrService userCompanyAttrService;
+    private final StorageService storageService;
 
     /**
      * 客户列表-v2
@@ -192,10 +193,7 @@ public class UserLogic {
     @Transactional
     public void importData(List<Object> datas) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
-        List<AdminWebsit> list = adminWebsitService.lambdaQuery()
-                .eq(AdminWebsit::getCompanyWechatId, adminUser.getCompanyWechatId())
-                .eq(AdminWebsit::getType, AdminWebsitTypeEnum.C.getKey())
-                .list();
+
         int index = 0;
         //先删除
         userWaitService.lambdaUpdate()
@@ -215,9 +213,7 @@ public class UserLogic {
             if (StringUtils.isAnyBlank(name, mobile)) {
                 throw new RemoteServiceException(errPrefix + "黄色区域为必填项");
             }
-            if (mobile.length() != 11) {
-                throw new RemoteServiceException(errPrefix + "手机号格式不正确");
-            }
+
             UserWait userWait = new UserWait();
             userWait.setUserType(UserTypeEnum.WORKER.getKey());
             userWait.setMobile(mobile);
@@ -520,6 +516,42 @@ public class UserLogic {
         userCompanyDeliveryService.saveBatch(userCompanyDeliveryList);
     }
 
+    @Transactional
+    public void companyDeliveryAdd(String mobile, String nickName, String storageId) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        UserCompanyDelivery delivery = new UserCompanyDelivery();
+
+        final Storage storage = storageService.getById(storageId);
+
+        if (Objects.isNull(storage)) {
+            throw new RemoteServiceException("仓储信息错误");
+        }
+
+        User user = userService.lambdaQuery()
+                .eq(User::getMobile, mobile)
+                .one();
+
+        if (Objects.isNull(user)) {
+            final String userId = IdWorker.getIdStr();
+            user = new User()
+                    .setUserId(userId)
+                    .setMobile(mobile)
+                    .setNickName(nickName)
+                    .setWorkerNumber(userId)
+                    .setOpenId(userId)
+                    .setType(UserTypeEnum.WORKER.getKey());
+
+            user.insert();
+        }
+
+        delivery.setCompanyWechatId(adminUser.getCompanyWechatId())
+                .setUserId(user.getUserId())
+                .setId(IdWorker.getIdStr())
+                .setCreateTime(DateUtil.date())
+                .setStorageId(storageId)
+                .insert();
+    }
+
     public void companyDeliveryDel(String userId) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
 
@@ -642,4 +674,5 @@ public class UserLogic {
 //                .eq(UserCompanyDelivery::getCompanyWechatId, adminUser.getCompanyWechatId())
 //                .remove();
     }
+
 }