Просмотр исходного кода

优化员工邮箱不需要必填问题

wuxw лет назад: 6
Родитель
Сommit
b08ff35fe5

+ 8 - 1
Api/src/main/java/com/java110/api/listener/user/AddStaffServiceListener.java

@@ -13,6 +13,7 @@ import com.java110.core.factory.DataFlowFactory;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.entity.center.AppService;
 import com.java110.event.service.api.ServiceDataFlowEvent;
+import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.*;
@@ -160,13 +161,19 @@ public class AddStaffServiceListener extends AbstractServiceApiDataFlowListener{
 
         //校验json 格式中是否包含 name,email,levelCd,tel
         Assert.jsonObjectHaveKey(paramObj,"name","请求参数中未包含name 节点,请确认");
-        Assert.jsonObjectHaveKey(paramObj,"email","请求参数中未包含email 节点,请确认");
+        //Assert.jsonObjectHaveKey(paramObj,"email","请求参数中未包含email 节点,请确认");
         Assert.jsonObjectHaveKey(paramObj,"tel","请求参数中未包含tel 节点,请确认");
         Assert.jsonObjectHaveKey(paramObj,"orgId", "请求报文格式错误或未包含部门信息");
         Assert.jsonObjectHaveKey(paramObj,"address", "请求报文格式错误或未包含地址信息");
         Assert.jsonObjectHaveKey(paramObj,"sex", "请求报文格式错误或未包含性别信息");
         Assert.jsonObjectHaveKey(paramObj,"relCd", "请求报文格式错误或未包含员工角色");
 
+
+        if (paramObj.containsKey("email") && !StringUtil.isEmpty(paramObj.getString("email"))) {
+            Assert.isEmail(paramObj, "email", "不是有效的邮箱格式");
+        }
+
+
         JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
         business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_USER_INFO);
         business.put(CommonConstant.HTTP_SEQ,1);

+ 19 - 8
WebService/src/main/java/com/java110/web/smo/impl/StaffServiceSMOImpl.java

@@ -1,10 +1,12 @@
 package com.java110.web.smo.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.entity.component.ComponentValidateResult;
 import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.util.Assert;
 import com.java110.core.context.IPageData;
 import com.java110.core.component.BaseComponentSMO;
+import com.java110.utils.util.StringUtil;
 import com.java110.web.smo.IStaffServiceSMO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,13 +39,17 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
         logger.debug("保存员工信息入参:{}", pd.toString());
         JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
         Assert.hasKeyAndValue(reqJson, "username", "请求报文格式错误或未包含用户名信息");
-        Assert.hasKeyAndValue(reqJson, "email", "请求报文格式错误或未包含邮箱信息");
+        //Assert.hasKeyAndValue(reqJson, "email", "请求报文格式错误或未包含邮箱信息");
         Assert.hasKeyAndValue(reqJson, "tel", "请求报文格式错误或未包含手机信息");
         Assert.hasKeyAndValue(reqJson, "sex", "请求报文格式错误或未包含性别信息");
         Assert.hasKeyAndValue(reqJson, "address", "请求报文格式错误或未包含地址信息");
         Assert.hasKeyAndValue(reqJson, "orgId", "请求报文格式错误或未包含部门信息");
         Assert.hasKeyAndValue(reqJson, "relCd", "请求报文格式错误或未包含员工角色");
 
+        if (reqJson.containsKey("email") && !StringUtil.isEmpty(reqJson.getString("email"))) {
+            Assert.isEmail(reqJson, "email", "不是有效的邮箱格式");
+        }
+
 
         ResponseEntity responseEntity = super.getStoreInfo(pd, restTemplate);
 
@@ -54,7 +60,7 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
 
         String storeId = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeId");
         String storeTypeCd = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeTypeCd");
-       // JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
+        // JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
         reqJson.put("name", reqJson.getString("username"));
         reqJson.put("storeId", storeId);
         reqJson.put("storeTypeCd", storeTypeCd);
@@ -84,7 +90,7 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
         if (rows > 50) {
             return new ResponseEntity<String>("rows 数量不能大于50", HttpStatus.BAD_REQUEST);
         }
-       // page = (page - 1) * rows;
+        // page = (page - 1) * rows;
         ResponseEntity responseEntity = super.getStoreInfo(pd, restTemplate);
         if (responseEntity.getStatusCode() != HttpStatus.OK) {
             return responseEntity;
@@ -95,8 +101,8 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
         //paramIn.put("page", page);
         paramIn.put("storeId", storeId);
         //if (StringUtil.isEmpty(staffName)) {
-            responseEntity = this.callCenterService(restTemplate, pd, "",
-                    ServiceConstant.SERVICE_API_URL + "/api/query.staff.infos" + super.mapToUrlParam(paramIn), HttpMethod.GET);
+        responseEntity = this.callCenterService(restTemplate, pd, "",
+                ServiceConstant.SERVICE_API_URL + "/api/query.staff.infos" + super.mapToUrlParam(paramIn), HttpMethod.GET);
        /* } else {
             responseEntity = this.callCenterService(restTemplate, pd, "",
                     ServiceConstant.SERVICE_API_URL + "/api/query.staff.byName?rows=" + rows + "&page=" + page + "&storeId=" + storeId + "&name=" + staffName, HttpMethod.GET);
@@ -141,11 +147,12 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
     public ResponseEntity<String> delete(IPageData pd) {
         ResponseEntity<String> responseEntity = null;
         Assert.jsonObjectHaveKey(pd.getReqData(), "userId", "请求报文格式错误或未包含用户ID信息");
-        Assert.jsonObjectHaveKey(pd.getReqData(), "storeId", "请求报文格式错误或未包含商户ID信息");
+        //Assert.jsonObjectHaveKey(pd.getReqData(), "storeId", "请求报文格式错误或未包含商户ID信息");
+        ComponentValidateResult result = super.validateStoreStaffCommunityRelationship(pd, restTemplate);
         JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
         JSONObject newParam = new JSONObject();
         newParam.put("userId", paramIn.getString("userId"));
-        newParam.put("storeId", paramIn.getString("storeId"));
+        newParam.put("storeId", result.getStoreId());
         //修改用户信息
         responseEntity = this.callCenterService(restTemplate, pd, newParam.toJSONString(),
                 ServiceConstant.SERVICE_API_URL + "/api/user.staff.delete", HttpMethod.POST);
@@ -283,10 +290,14 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
     private void modifyStaffValidate(IPageData pd) {
         Assert.jsonObjectHaveKey(pd.getReqData(), "userId", "请求报文格式错误或未包含用户ID信息");
         Assert.jsonObjectHaveKey(pd.getReqData(), "username", "请求报文格式错误或未包含用户名信息");
-        Assert.jsonObjectHaveKey(pd.getReqData(), "email", "请求报文格式错误或未包含邮箱信息");
+        //Assert.jsonObjectHaveKey(pd.getReqData(), "email", "请求报文格式错误或未包含邮箱信息");
         Assert.jsonObjectHaveKey(pd.getReqData(), "tel", "请求报文格式错误或未包含手机信息");
         Assert.jsonObjectHaveKey(pd.getReqData(), "sex", "请求报文格式错误或未包含性别信息");
         Assert.jsonObjectHaveKey(pd.getReqData(), "address", "请求报文格式错误或未包含地址信息");
+        JSONObject reqJson = JSONObject.parseObject(pd.getReqData());
+        if (reqJson.containsKey("email") && !StringUtil.isEmpty(reqJson.getString("email"))) {
+            Assert.isEmail(reqJson, "email", "不是有效的邮箱格式");
+        }
     }
 
 

+ 1 - 1
WebService/src/main/resources/components/staffPackage/addStaffView/addStaffView.html

@@ -38,7 +38,7 @@
                 <div class="form-group row">
                     <label class="col-sm-2 col-form-label">员工邮箱</label>
                     <div class="col-sm-10">
-                        <input v-model="addStaffViewInfo.email" type="text" placeholder="必填,请填写员工邮箱"
+                        <input v-model="addStaffViewInfo.email" type="text" placeholder="可选,请填写员工邮箱"
                                class="form-control">
                     </div>
                 </div>

+ 70 - 84
WebService/src/main/resources/components/staffPackage/addStaffView/addStaffView.js

@@ -1,116 +1,102 @@
-(function(vc){
+(function(vc) {
 
     vc.extends({
         propTypes: {
-           callBackListener:vc.propTypes.string, //父组件名称
-           callBackFunction:vc.propTypes.string //父组件监听方法
+            callBackListener: vc.propTypes.string,
+            //父组件名称
+            callBackFunction: vc.propTypes.string //父组件监听方法
         },
-        data:{
-            addStaffViewInfo:{
-                flowComponent:'addStaffView',
-                username:'',
-                sex:'',
-                email:'',
-                tel:'',
-                address:'',
-                relCd:'',
+        data: {
+            addStaffViewInfo: {
+                flowComponent: 'addStaffView',
+                username: '',
+                sex: '',
+                email: '',
+                tel: '',
+                address: '',
+                relCd: '',
             }
         },
-        watch:{
-            addStaffViewInfo:{
+        watch: {
+            addStaffViewInfo: {
                 deep: true,
-                handler:function(){
+                handler: function() {
                     vc.component.saveAddStaffInfo();
                 }
-             }
+            }
         },
-         _initMethod:function(){
+        _initMethod: function() {
 
-         },
-         _initEvent:function(){
+},
+        _initEvent: function() {
 
-            vc.on('addStaffViewInfo', 'onIndex', function(_index){
+            vc.on('addStaffViewInfo', 'onIndex',
+            function(_index) {
                 vc.component.addStaffViewInfo.index = _index;
             });
         },
-        methods:{
-            addStaffValidate(){
+        methods: {
+            addStaffValidate() {
                 return vc.validate.validate({
-                    addStaffViewInfo:vc.component.addStaffViewInfo
-                },{
-                    'addStaffViewInfo.username':[
-{
-                            limit:"required",
-                            param:"",
-                            errInfo:"员工名称不能为空"
-                        },
- {
-                            limit:"maxin",
-                            param:"2,10",
-                            errInfo:"员工名称长度必须在2位至10位"
-                        },
-                    ],
-'addStaffViewInfo.sex':[
-{
-                            limit:"required",
-                            param:"",
-                            errInfo:"员工性别不能为空"
-                        },
-                    ],
-                    'addStaffViewInfo.relCd':[
+                    addStaffViewInfo: vc.component.addStaffViewInfo
+                },
+                {
+                    'addStaffViewInfo.username': [{
+                        limit: "required",
+                        param: "",
+                        errInfo: "员工名称不能为空"
+                    },
                     {
-                        limit:"required",
-                        param:"",
-                        errInfo:"员工岗位不能为空"
+                        limit: "maxin",
+                        param: "2,10",
+                        errInfo: "员工名称长度必须在2位至10位"
                     },
-                     {
-                        limit:"num",
-                        param:"",
-                        errInfo:"员工岗位错误"
+                    ],
+                    'addStaffViewInfo.sex': [{
+                        limit: "required",
+                        param: "",
+                        errInfo: "员工性别不能为空"
                     },
                     ],
-'addStaffViewInfo.email':[
-{
-                            limit:"required",
-                            param:"",
-                            errInfo:"员工邮箱不能为空"
-                        },
- {
-                            limit:"email",
-                            param:"",
-                            errInfo:"员工邮箱不是有效邮箱"
-                        },
+                    'addStaffViewInfo.relCd': [{
+                        limit: "required",
+                        param: "",
+                        errInfo: "员工岗位不能为空"
+                    },
+                    {
+                        limit: "num",
+                        param: "",
+                        errInfo: "员工岗位错误"
+                    },
                     ],
-'addStaffViewInfo.tel':[
- {
-                            limit:"photo",
-                            param:"",
-                            errInfo:"联系方式不是有效手机"
-                        },
+                    'addStaffViewInfo.tel': [{
+                        limit: "photo",
+                        param: "",
+                        errInfo: "联系方式不是有效手机"
+                    },
                     ],
-'addStaffViewInfo.address':[
-{
-                            limit:"required",
-                            param:"",
-                            errInfo:"家庭住址不能为空"
-                        },
- {
-                            limit:"maxLength",
-                            param:"200",
-                            errInfo:"家庭住址不能超过200位"
-                        },
+                    'addStaffViewInfo.address': [{
+                        limit: "required",
+                        param: "",
+                        errInfo: "家庭住址不能为空"
+                    },
+                    {
+                        limit: "maxLength",
+                        param: "200",
+                        errInfo: "家庭住址不能超过200位"
+                    },
                     ],
 
                 });
             },
-            saveAddStaffInfo:function(){
-                if(vc.component.addStaffValidate()){
+            saveAddStaffInfo: function() {
+                if (vc.component.addStaffValidate()) {
                     //侦听回传
-                    vc.emit($props.callBackListener,$props.callBackFunction, vc.component.addStaffViewInfo);
-                    return ;
+                    vc.emit($props.callBackListener, $props.callBackFunction, vc.component.addStaffViewInfo);
+                    return;
                 }
             }
         }
     });
 
-})(window.vc);
+})(window.vc);

+ 1 - 1
WebService/src/main/resources/components/staffPackage/edit-staff/editStaff.html

@@ -13,7 +13,7 @@
                             </div>
                             <div class="form-group row">
                                 <label class="col-sm-2 col-form-label">员工邮箱</label>
-                                <div class="col-sm-10"><input v-model="editStaffInfo.email" type="email" placeholder="必填,请填写员工名称" class="form-control"></div>
+                                <div class="col-sm-10"><input v-model="editStaffInfo.email" type="email" placeholder="可选,请填写员工名称" class="form-control"></div>
                             </div>
                             <div class="form-group row">
                                 <label class="col-sm-2 col-form-label">手机号码</label>

+ 0 - 12
WebService/src/main/resources/components/staffPackage/edit-staff/editStaff.js

@@ -47,18 +47,6 @@
                             errInfo:"用户名长度必须在2位至10位"
                         },
                     ],
-                    'editStaffInfo.email':[
-                        {
-                            limit:"required",
-                            param:"",
-                            errInfo:"密码不能为空"
-                        },
-                        {
-                            limit:"email",
-                            param:"",
-                            errInfo:"不是有效的邮箱"
-                        },
-                    ],
                     'editStaffInfo.tel':[
                         {
                             limit:"required",

+ 18 - 3
java110-utils/src/main/java/com/java110/utils/util/Assert.java

@@ -249,16 +249,17 @@ public class Assert extends org.springframework.util.Assert {
 
     /**
      * 检验是否在 infos 中存在 flowComponent 对应组件的key
+     *
      * @param infos
      * @param flowComponent
      * @param key
      * @param message
      */
-    public static void hasKeyByFlowData(JSONArray infos, String flowComponent, String key, String message){
+    public static void hasKeyByFlowData(JSONArray infos, String flowComponent, String key, String message) {
 
-        for(int infoIndex = 0 ; infoIndex < infos.size() ; infoIndex ++){
+        for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
             JSONObject _info = infos.getJSONObject(infoIndex);
-            if(_info.containsKey(flowComponent) && _info.getString("flowComponent").equals(flowComponent)){
+            if (_info.containsKey(flowComponent) && _info.getString("flowComponent").equals(flowComponent)) {
                 hasKeyAndValue(_info, key, message);
                 break;
             }
@@ -307,4 +308,18 @@ public class Assert extends org.springframework.util.Assert {
     }
 
 
+    /**
+     * 检验是否在 infos 中存在 flowComponent 对应组件的key
+     *
+     * @param key
+     * @param message
+     */
+    public static void isEmail(JSONObject info, String key, String message) {
+        hasKeyAndValue(info, key, message);
+        if (!ValidatorUtil.isEmail(info.getString(key))) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+
 }