Forráskód Böngészése

添加员工测试中

wuxw 7 éve%!(EXTRA string=óta)
szülő
commit
9dd26651d8

+ 14 - 0
Api/src/main/java/com/java110/api/listener/AbstractServiceApiDataFlowListener.java

@@ -1,5 +1,6 @@
 package com.java110.api.listener;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.common.constant.CommonConstant;
 import com.java110.common.constant.ResponseConstant;
@@ -170,6 +171,19 @@ public abstract class AbstractServiceApiDataFlowListener implements ServiceDataF
         return centerProtocol;
     }
 
+    /**
+     * 将rest 协议转为 订单协议
+     * @param businesses 多个业务
+     * @return
+     */
+    protected JSONObject restToCenterProtocol(JSONArray businesses, Map<String,String> headers){
+
+        JSONObject centerProtocol = JSONObject.parseObject("{\"orders\":{},\"business\":[]}");
+        freshOrderProtocol(centerProtocol.getJSONObject("orders"),headers);
+        centerProtocol.put("business",businesses);
+        return centerProtocol;
+    }
+
     /**
      * 刷入order信息
      * @param orders 订单信息

+ 75 - 21
Api/src/main/java/com/java110/api/listener/users/AddStaffServiceListener.java

@@ -1,5 +1,7 @@
 package com.java110.api.listener.users;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.api.listener.AbstractServiceApiDataFlowListener;
 import com.java110.common.cache.MappingCache;
@@ -8,6 +10,7 @@ import com.java110.common.util.Assert;
 import com.java110.core.annotation.Java110Listener;
 import com.java110.core.context.DataFlowContext;
 import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.entity.center.AppService;
 import com.java110.event.service.api.ServiceDataFlowEvent;
 import org.slf4j.Logger;
@@ -56,23 +59,34 @@ public class AddStaffServiceListener extends AbstractServiceApiDataFlowListener{
         AppService service = event.getAppService();
         String paramIn = dataFlowContext.getReqData();
         Assert.isJsonObject(paramIn,"添加员工时请求参数有误,不是有效的json格式 "+paramIn);
+        JSONObject paramInJson = JSONObject.parseObject(paramIn);
+        Assert.jsonObjectHaveKey(paramInJson,"storeId","请求参数中未包含storeId 节点,请确认");
+        JSONArray businesses = new JSONArray();
+        //判断请求报文中包含 userId 并且 不为-1时 将已有用户添加为员工,反之,则添加用户再将用户添加为员工
+        String userId = "";
+        String oldUserId = "";
+
+        if(!paramInJson.containsKey("userId") || "-1".equals(paramInJson.getString("userId"))){
+            //将userId 强制写成-1
+            oldUserId = "-1";
+            userId = GenerateCodeFactory.getUserId();
+            paramInJson.put("userId",userId);
+            //添加用户
+            JSONObject business = addUser(paramInJson,dataFlowContext);
+            businesses.add(business);
+        }
+
+        paramInJson.put("userId",userId);
+        paramInJson.put("relCd","-1".equals(oldUserId)?StoreUserRelConstant.REL_COMMON:StoreUserRelConstant.REL_ADMIN);
+
+        JSONObject staffBusiness = addStaff(paramInJson);
+        businesses.add(staffBusiness);
 
-        //校验json 格式中是否包含 name,email,levelCd,tel
-        Assert.jsonObjectHaveKey(paramIn,"name","请求参数中未包含name 节点,请确认");
-        Assert.jsonObjectHaveKey(paramIn,"email","请求参数中未包含email 节点,请确认");
-        Assert.jsonObjectHaveKey(paramIn,"tel","请求参数中未包含tel 节点,请确认");
-
-
-        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
-        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_USER_INFO);
-        business.put(CommonConstant.HTTP_SEQ,1);
-        business.put(CommonConstant.HTTP_INVOKE_MODEL,CommonConstant.HTTP_INVOKE_MODEL_S);
-
-        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessUser",refreshParamIn(paramIn));
         HttpHeaders header = new HttpHeaders();
-        dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_USER_ID,"-1");
+        dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_USER_ID,userId);
         dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD,"D");
-        String paramInObj = super.restToCenterProtocol(business,dataFlowContext.getRequestCurrentHeaders()).toJSONString();
+
+        String paramInObj = super.restToCenterProtocol(businesses,dataFlowContext.getRequestCurrentHeaders()).toJSONString();
 
         //将 rest header 信息传递到下层服务中去
         super.freshHttpHeader(header,dataFlowContext.getRequestCurrentHeaders());
@@ -84,14 +98,57 @@ public class AddStaffServiceListener extends AbstractServiceApiDataFlowListener{
         super.doResponse(dataFlowContext);
     }
 
+    /**
+     * 添加员工
+     * @param paramInJson
+     * @return
+     */
+    private JSONObject addStaff(JSONObject paramInJson){
+
+        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
+        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_STORE_USER);
+        business.put(CommonConstant.HTTP_SEQ,1);
+        business.put(CommonConstant.HTTP_INVOKE_MODEL,CommonConstant.HTTP_INVOKE_MODEL_S);
+
+        JSONObject businessStoreUser = new JSONObject();
+        businessStoreUser.put("storeId",paramInJson.getString("storeId"));
+        businessStoreUser.put("userId",paramInJson.getString("userId"));
+        businessStoreUser.put("relCd",paramInJson.getString("relCd"));
+
+        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessStoreUser",businessStoreUser);
+
+        return business;
+    }
+
+    /**
+     * 添加用户
+     * @param paramObj
+     */
+    private JSONObject addUser(JSONObject paramObj,DataFlowContext dataFlowContext){
+
+        //校验json 格式中是否包含 name,email,levelCd,tel
+        Assert.jsonObjectHaveKey(paramObj,"name","请求参数中未包含name 节点,请确认");
+        Assert.jsonObjectHaveKey(paramObj,"email","请求参数中未包含email 节点,请确认");
+        Assert.jsonObjectHaveKey(paramObj,"tel","请求参数中未包含tel 节点,请确认");
+
+
+        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
+        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_USER_INFO);
+        business.put(CommonConstant.HTTP_SEQ,1);
+        business.put(CommonConstant.HTTP_INVOKE_MODEL,CommonConstant.HTTP_INVOKE_MODEL_S);
+
+        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessUser",refreshParamIn(paramObj));
+
+        return business;
+    }
+
     /**
      * 对请求报文处理
-     * @param paramIn
+     * @param paramObj
      * @return
      */
-    private JSONObject refreshParamIn(String paramIn){
-        JSONObject paramObj = JSONObject.parseObject(paramIn);
-        paramObj.put("userId","-1");
+    private JSONObject refreshParamIn(JSONObject paramObj){
+        //paramObj.put("userId","-1");
         paramObj.put("levelCd", UserLevelConstant.USER_LEVEL_STAFF);
         //设置默认密码
         String staffDefaultPassword = MappingCache.getValue(MappingConstant.KEY_STAFF_DEFAULT_PASSWORD);
@@ -102,7 +159,4 @@ public class AddStaffServiceListener extends AbstractServiceApiDataFlowListener{
     }
 
 
-
-
-
 }

+ 3 - 3
StoreService/doc/addStaff.json

@@ -13,14 +13,14 @@
     }]
   },
   "business": [{
-    "serviceCode": "save.store.info",
-    "serviceName": "保存商户信息",
+    "serviceCode": "user.staff.add",
+    "serviceName": "添加员工",
     "remark": "备注",
     "datas": {
       "businessStoreUser": {
         "storeId": "-1",
         "userId": "用户ID",
-        "relCd": "齐天超时(王府井店)",
+        "relCd": "齐天超时(王府井店)"
       }
     },
     "attrs": [{

+ 14 - 0
java110-common/src/main/java/com/java110/common/constant/StoreUserRelConstant.java

@@ -0,0 +1,14 @@
+package com.java110.common.constant;
+
+/**
+ * 员工角色
+ * Created by Administrator on 2019/3/30.
+ */
+public class StoreUserRelConstant {
+
+    //管理员
+    public final static String REL_ADMIN = "600311000001";
+
+    //普通员工
+    public final static String REL_COMMON = "600311000002";
+}