wuxw лет назад: 7
Родитель
Сommit
82436cd676

+ 235 - 0
Api/src/main/java/com/java110/api/listener/users/ModifyStaffServiceListener.java

@@ -0,0 +1,235 @@
+package com.java110.api.listener.users;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiDataFlowListener;
+import com.java110.common.cache.MappingCache;
+import com.java110.common.constant.*;
+import com.java110.common.exception.ListenerExecuteException;
+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.DataFlowFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.entity.center.AppService;
+import com.java110.event.service.api.ServiceDataFlowEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.*;
+
+/**
+ * 修改员工 2018年12月6日
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("modifyStaffServiceListener")
+public class ModifyStaffServiceListener extends AbstractServiceApiDataFlowListener{
+
+    private final static Logger logger = LoggerFactory.getLogger(ModifyStaffServiceListener.class);
+
+
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_USER_STAFF_MODIFY;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.POST;
+    }
+
+
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+
+
+    /**
+     * 添加员工信息
+     *
+     *
+     *
+     * @param event
+     */
+    @Override
+    public void soService(ServiceDataFlowEvent event) {
+        //获取数据上下文对象
+        DataFlowContext dataFlowContext = event.getDataFlowContext();
+        AppService service = event.getAppService();
+        String paramIn = dataFlowContext.getReqData();
+        Assert.isJsonObject(paramIn,"添加员工时请求参数有误,不是有效的json格式 "+paramIn);
+        JSONObject paramInJson = JSONObject.parseObject(paramIn);
+        Assert.jsonObjectHaveKey(paramInJson,"userId","请求参数中未包含userId 节点,请确认");
+        JSONArray businesses = new JSONArray();
+        //判断请求报文中包含 userId 并且 不为-1时 将已有用户添加为员工,反之,则添加用户再将用户添加为员工
+        JSONObject staffBusiness = modifyStaff(paramInJson,dataFlowContext);
+        businesses.add(staffBusiness);
+
+        HttpHeaders header = new HttpHeaders();
+        dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_USER_ID,paramInJson.getString("userId"));
+        dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD,"D");
+
+        String paramInObj = super.restToCenterProtocol(businesses,dataFlowContext.getRequestCurrentHeaders()).toJSONString();
+
+        //将 rest header 信息传递到下层服务中去
+        super.freshHttpHeader(header,dataFlowContext.getRequestCurrentHeaders());
+
+        HttpEntity<String> httpEntity = new HttpEntity<String>(paramInObj, header);
+        //http://user-service/test/sayHello
+        super.doRequest(dataFlowContext, service, httpEntity);
+
+        super.doResponse(dataFlowContext);
+
+        //如果不成功直接返回
+        if(dataFlowContext.getResponseEntity().getStatusCode() != HttpStatus.OK){
+            return ;
+        }
+
+        //赋权
+        privilegeUserDefault(dataFlowContext,paramInJson);
+    }
+
+    /**
+     * 添加员工
+     * @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);
+        JSONArray businessStoreUsers = new JSONArray();
+        JSONObject businessStoreUser = new JSONObject();
+        businessStoreUser.put("storeId",paramInJson.getString("storeId"));
+        businessStoreUser.put("storeUserId","-1");
+        businessStoreUser.put("userId",paramInJson.getString("userId"));
+        businessStoreUser.put("relCd",paramInJson.getString("relCd"));
+        businessStoreUsers.add(businessStoreUser);
+        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessStoreUser",businessStoreUsers);
+
+        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;
+    }
+
+    private JSONObject modifyStaff(JSONObject paramObj,DataFlowContext dataFlowContext){
+        //校验json 格式中是否包含 name,email,levelCd,tel
+        Assert.jsonObjectHaveKey(paramObj,"name","请求参数中未包含name 节点,请确认");
+        Assert.jsonObjectHaveKey(paramObj,"tel","请求参数中未包含tel 节点,请确认");
+
+
+        JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
+        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_MODIFY_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",builderStaffInfo(paramObj,dataFlowContext));
+
+        return business;
+    }
+
+    /**
+     *  构建员工信息
+     * @param paramObj
+     * @param dataFlowContext
+     * @return
+     */
+    private JSONObject builderStaffInfo(JSONObject paramObj, DataFlowContext dataFlowContext) {
+
+        //首先根据员工ID查询员工信息,根据员工信息修改相应的数据
+        ResponseEntity responseEntity= null;
+        AppService appService = DataFlowFactory.getService(dataFlowContext.getAppId(), ServiceCodeConstant.SERVICE_CODE_QUERY_USER_USERINFO);
+        if(appService == null){
+            throw new ListenerExecuteException(1999,"当前没有权限访问"+ServiceCodeConstant.SERVICE_CODE_QUERY_USER_USERINFO);
+
+        }
+        String requestUrl = appService.getUrl() + "?userId="+paramObj.getString("userId");
+        HttpHeaders header = new HttpHeaders();
+        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(),ServiceCodeConstant.SERVICE_CODE_QUERY_USER_USERINFO);
+        dataFlowContext.getRequestHeaders().put("REQUEST_URL",requestUrl);
+        HttpEntity<String> httpEntity = new HttpEntity<String>("", header);
+        doRequest(dataFlowContext,appService,httpEntity);
+        responseEntity = dataFlowContext.getResponseEntity();
+
+        if(responseEntity.getStatusCode() != HttpStatus.OK){
+            dataFlowContext.setResponseEntity(responseEntity);
+        }
+
+        JSONObject userInfo = JSONObject.parseObject(responseEntity.getBody().toString());
+        userInfo.putAll(paramObj);
+
+        return userInfo;
+    }
+
+    /**
+     * 对请求报文处理
+     * @param paramObj
+     * @return
+     */
+    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);
+        Assert.hasLength(staffDefaultPassword,"映射表中未设置员工默认密码,请检查"+MappingConstant.KEY_STAFF_DEFAULT_PASSWORD);
+        staffDefaultPassword = AuthenticationFactory.passwdMd5(staffDefaultPassword);
+        paramObj.put("password",staffDefaultPassword);
+        return paramObj;
+    }
+
+
+    /**
+     * 用户赋权
+     * @return
+     */
+    private void privilegeUserDefault(DataFlowContext dataFlowContext,JSONObject paramObj){
+        ResponseEntity responseEntity= null;
+        AppService appService = DataFlowFactory.getService(dataFlowContext.getAppId(), ServiceCodeConstant.SERVICE_CODE_SAVE_USER_DEFAULT_PRIVILEGE);
+        if(appService == null){
+            responseEntity = new ResponseEntity<String>("当前没有权限访问"+ServiceCodeConstant.SERVICE_CODE_SAVE_USER_DEFAULT_PRIVILEGE,HttpStatus.UNAUTHORIZED);
+            dataFlowContext.setResponseEntity(responseEntity);
+            return ;
+        }
+        String requestUrl = appService.getUrl();
+        HttpHeaders header = new HttpHeaders();
+        header.add(CommonConstant.HTTP_SERVICE.toLowerCase(),ServiceCodeConstant.SERVICE_CODE_SAVE_USER_DEFAULT_PRIVILEGE);
+        super.freshHttpHeader(header,dataFlowContext.getRequestCurrentHeaders());
+        JSONObject paramInObj = new JSONObject();
+        paramInObj.put("userId",paramObj.getString("userId"));
+        paramInObj.put("storeTypeCd",paramObj.getString("storeTypeCd"));
+        paramInObj.put("userFlag","staff");
+        HttpEntity<String> httpEntity = new HttpEntity<String>(paramInObj.toJSONString(), header);
+        doRequest(dataFlowContext,appService,httpEntity);
+        responseEntity = dataFlowContext.getResponseEntity();
+
+        if(responseEntity.getStatusCode() != HttpStatus.OK){
+            dataFlowContext.setResponseEntity(responseEntity);
+        }
+    }
+
+
+}

+ 44 - 0
WebService/src/main/java/com/java110/web/components/EditStaffComponent.java

@@ -0,0 +1,44 @@
+package com.java110.web.components;
+
+import com.java110.core.context.IPageData;
+import com.java110.web.smo.IStaffServiceSMO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+
+/**
+ * 编辑员工信息
+ * Created by Administrator on 2019/4/3.
+ */
+@Component("editStaff")
+public class EditStaffComponent {
+
+    @Autowired
+    IStaffServiceSMO staffServiceSMOImpl;
+    /**
+     * 修改员工信息
+     * @param pd
+     * @return
+     */
+    public ResponseEntity<String> modifyStaff(IPageData pd){
+
+        ResponseEntity<String> responseEntity = null;
+        try{
+            responseEntity =  staffServiceSMOImpl.modifyStaff(pd);
+        }catch (Exception e){
+            responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+        }finally {
+            return responseEntity;
+        }
+    }
+
+
+    public IStaffServiceSMO getStaffServiceSMOImpl() {
+        return staffServiceSMOImpl;
+    }
+
+    public void setStaffServiceSMOImpl(IStaffServiceSMO staffServiceSMOImpl) {
+        this.staffServiceSMOImpl = staffServiceSMOImpl;
+    }
+}

+ 8 - 0
WebService/src/main/java/com/java110/web/smo/IStaffServiceSMO.java

@@ -23,4 +23,12 @@ public interface IStaffServiceSMO {
      * @return
      */
     public ResponseEntity<String> loadData(IPageData pd);
+
+
+    /**
+     * 修改员工信息
+     * @param pd
+     * @return
+     */
+    public ResponseEntity<String> modifyStaff(IPageData pd);
 }

+ 30 - 0
WebService/src/main/java/com/java110/web/smo/impl/StaffServiceSMOImpl.java

@@ -95,6 +95,36 @@ public class StaffServiceSMOImpl extends BaseComponentSMO implements IStaffServi
         return responseEntity;
     }
 
+    /**
+     * 修改员工信息
+     * @param pd
+     * @return
+     */
+    @Override
+    public ResponseEntity<String> modifyStaff(IPageData pd) {
+
+        ResponseEntity<String> responseEntity = null;
+        //校验 前台数据
+        modifyStaffValidate(pd);
+        //修改用户信息
+        responseEntity = this.callCenterService(restTemplate,pd,"",
+                ServiceConstant.SERVICE_API_URL+"/api/user.staff.modify", HttpMethod.POST);
+        return responseEntity;
+    }
+
+    /**
+     * 修改员工 数据校验
+     * @param pd
+     */
+    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(),"tel","请求报文格式错误或未包含手机信息");
+        Assert.jsonObjectHaveKey(pd.getReqData(),"sex","请求报文格式错误或未包含性别信息");
+        Assert.jsonObjectHaveKey(pd.getReqData(),"address","请求报文格式错误或未包含地址信息");
+    }
+
 
     public RestTemplate getRestTemplate() {
         return restTemplate;

+ 46 - 0
WebService/src/main/resources/components/edit-staff/editStaff.html

@@ -0,0 +1,46 @@
+<div id = "editStaffModel" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" >
+    <div class="modal-dialog modal-lg">
+        <div class="modal-content">
+            <div class="modal-body">
+                <h3 class="m-t-none m-b ">修改员工</h3>
+                <div class="ibox-content">
+                    <div>
+                        <p style="color:red;">{{editStaffInfo.errorInfo}}</p>
+                        <div>
+                            <div class="form-group row">
+                                <label class="col-sm-2 col-form-label">员工名称</label>
+                                <div class="col-sm-10"><input v-model="editStaffInfo.username" type="text" placeholder="必填,请填写员工名称" class="form-control"></div>
+                            </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>
+                            <div class="form-group row">
+                                <label class="col-sm-2 col-form-label">手机号码</label>
+                                <div class="col-sm-10"><input v-model="editStaffInfo.tel" type="tel" placeholder="必填,请填写手机号码" class="form-control"></div>
+                            </div>
+                            <div class="form-group row">
+                                <label class="col-sm-2 col-form-label">员工性别</label>
+                                <div class="col-sm-10">
+                                    <select class="custom-select" v-model="editStaffInfo.sex">
+                                        <option selected value="">必填,请选择员工性别</option>
+                                        <option value="0">男</option>
+                                        <option value="1">女</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="form-group row">
+                                <label class="col-sm-2 col-form-label">家庭住址</label>
+                                <div class="col-sm-10"><input v-model="editStaffInfo.address" type="text" placeholder="请填写家庭住址" class="form-control"></div>
+                            </div>
+                            <div class="ibox-content">
+                                <button class="btn btn-primary float-right" type="button" v-on:click="editStaffInfo()" ><i class="fa fa-check"></i>&nbsp;修改</button>
+                                <button type="button" class="btn btn-warning float-right" style="margin-right:20px;" data-dismiss="modal">取消</button>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>

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

@@ -0,0 +1,128 @@
+/**
+    编辑员工
+**/
+(function(vc){
+    vc.extends({
+        data:{
+            editStaffInfo:{
+                userId:'',
+                username:'',
+                email:'',
+                tel:'',
+                sex:'',
+                address:'',
+                errorInfo:'',
+            }
+        },
+        _initMethod:function(){
+        },
+        _initEvent:function(){
+             vc.component.$on('edit_staff_event',function(_staffInfo){
+                    vc.component.refreshEditStaffInfo(_staffInfo);
+                    $('#editStaffModel').modal('show');
+                });
+        },
+        methods:{
+            refreshEditStaffInfo(_staffInfo){
+                vc.component.editStaffInfo.userId = _staffInfo.userId;
+                vc.component.editStaffInfo.username = _staffInfo.name;
+                vc.component.editStaffInfo.email = _staffInfo.email;
+                vc.component.editStaffInfo.tel = _staffInfo.tel;
+                vc.component.editStaffInfo.sex = _staffInfo.sex;
+                vc.component.editStaffInfo.address = _staffInfo.address;
+            },
+            editStaffValidate(){
+                            return vc.validate.validate({
+                                editStaffInfo:vc.component.editStaffInfo
+                            },{
+                                'editStaffInfo.username':[
+                                    {
+                                        limit:"required",
+                                        param:"",
+                                        errInfo:"用户名不能为空"
+                                    },
+                                    {
+                                        limit:"maxin",
+                                        param:"2,10",
+                                        errInfo:"用户名长度必须在2位至10位"
+                                    },
+                                ],
+                                'editStaffInfo.email':[
+                                    {
+                                        limit:"required",
+                                        param:"",
+                                        errInfo:"密码不能为空"
+                                    },
+                                    {
+                                        limit:"email",
+                                        param:"",
+                                        errInfo:"不是有效的邮箱"
+                                    },
+                                ],
+                                'editStaffInfo.tel':[
+                                    {
+                                        limit:"required",
+                                        param:"",
+                                        errInfo:"手机号不能为空"
+                                    },
+                                    {
+                                        limit:"phone",
+                                        param:"",
+                                        errInfo:"不是有效的手机号"
+                                    }
+                                ],
+                                'editStaffInfo.sex':[
+                                    {
+                                        limit:"required",
+                                        param:"",
+                                        errInfo:"性别不能为空"
+                                    }
+                                ],
+                                'editStaffInfo.address':[
+                                    {
+                                        limit:"required",
+                                        param:"",
+                                        errInfo:"地址不能为空"
+                                    },
+                                    {
+                                        limit:"maxLength",
+                                        param:"200",
+                                        errInfo:"地址长度不能超过200位"
+                                    },
+                                ]
+
+                            });
+                        },
+            editStaffInfo:function(){
+                 if(!vc.component.editStaffValidate()){
+                    vc.component.editStaffInfo.errorInfo = vc.validate.errInfo;
+                    return ;
+                }
+
+                vc.component.editStaffInfo.errorInfo = "";
+                vc.http.post(
+                    'editStaff',
+                    'modifyStaff',
+                    JSON.stringify(vc.component.editStaffInfo),
+                    {
+                        emulateJSON:true
+                     },
+                     function(json,res){
+                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
+                        if(res.status == 200){
+                            //关闭model
+                            $('#editStaffModel').modal('hide');
+                            vc.component.$emit('editStaff_reload_event',{});
+                            return ;
+                        }
+                        vc.component.editStaffInfo.errorInfo = json;
+                     },
+                     function(errInfo,error){
+                        console.log('请求失败处理');
+
+                        vc.component.editStaffInfo.errorInfo = errInfo;
+                     });
+            }
+        },
+    });
+})(window.vc);

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

@@ -34,7 +34,7 @@
                                 <td>{{staff.statusCd}}</td>
                                 <td>{{staff.createTime}}</td>
                                 <td>
-                                    <i class="glyphicon glyphicon-edit" style="color: #17a2b8;"></i>
+                                    <i class="glyphicon glyphicon-edit" style="color: #17a2b8;" v-on:click="openEditStaff(staff)"></i>
                                     <i v-if="staff.relCd != 600311000001" class="glyphicon glyphicon-remove-sign" style="color: #dc3545;margin-left:5px"></i>
                                 </td>
                             </tr>

+ 8 - 46
WebService/src/main/resources/components/staff/staff.js

@@ -14,6 +14,11 @@
                  vc.component.$on('addStaff_reload_event',function(){
                      vc.component.loadData();
                  });
+                 vc.component.$on('editStaff_reload_event',function(){
+                      vc.component.loadData();
+                  });
+
+
             },
             methods:{
                 loadData:function(){
@@ -45,53 +50,10 @@
                 currentPage:function(_currentPage){
 
                 },
-                addStaff:function(){
-                    var param = {
-                        params:{
-                            page:1,
-                            rows:10
-                        }
-                    };
-                      //发送get请求
-                   vc.http.post('nav',
-                                'logout',
-                                JSON.stringify(param),
-                               {
-                                   emulateJSON:true
-                                },
-                                 function(json,res){
-                                   if(res.status == 200){
-                                       vc.jumpToPage("/flow/login");
-                                       return ;
-                                   }
-                                 },function(){
-                                    console.log('请求失败处理');
-                                 }
-                               );
-                },
-                enableStaff:function(){
-                    //获取用户名
-                    var param = {
-                                        msg:'123',
-                    };
-
-                    //发送get请求
-                   vc.http.get('nav',
-                                'getUserInfo',
-                                 param,
-                                 function(json,res){
-                                    if(res.status == 200){
-                                        var tmpUserInfo = JSON.parse(json);
-                                       vc.component.userName = tmpUserInfo.name;
-                                   }
-                                 },function(){
-                                    console.log('请求失败处理');
-                                 }
-                               );
-                },
-                disableStaff:function(){
-
+                openEditStaff:function(_staffInfo){
+                     vc.component.$emit('edit_staff_event',_staffInfo);
                 }
+
             }
 
 

+ 1 - 0
WebService/src/main/resources/views/staff.html

@@ -21,6 +21,7 @@
         <div id="component" class="wrapper wrapper-content animated fadeInRight">
             <vc:create name="staff"></vc:create>
             <vc:create name="addStaff"></vc:create>
+            <vc:create name="editStaff"></vc:create>
         </div>
 
 

+ 5 - 0
java110-common/src/main/java/com/java110/common/constant/ServiceCodeConstant.java

@@ -242,6 +242,11 @@ public class ServiceCodeConstant {
      */
     public static final String SERVICE_CODE_USER_STAFF_ADD = "user.staff.add";
 
+    /**
+     * 添加员工 服务
+     */
+    public static final String SERVICE_CODE_USER_STAFF_MODIFY = "user.staff.modify";
+
     /**
      * 停用员工服务
      */