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

加入管理员免密登录物业账号功能

java110 лет назад: 5
Родитель
Сommit
2b7cc5a8e0

+ 15 - 8
java110-db/src/main/resources/mapper/store/StoreServiceDaoImplMapper.xml

@@ -563,15 +563,22 @@
 
     <!--查询员工和商户信息-->
     <select id="getStoreUserInfo" parameterType="Map" resultType="Map">
-        select s.store_id,s.b_id,s.user_id,s.name,s.address,s.tel,s.store_type_cd,
+        select s.store_id,s.store_id storeId,s.b_id,s.user_id,s.user_id userId,s.name,s.address,s.tel,s.store_type_cd,s.store_type_cd storeTypeCd,
         s.nearby_landmarks,s.map_x,s.map_y,s.create_time,su.store_user_id,su.rel_cd
-        from s_store s left join s_store_user su on s.store_id=su.store_id
-        <where>
-            s.status_cd = "0" and su.status_cd = "0"
-            <if test="userId != null and userId != ''">
-                and su.user_id = #{userId}
-            </if>
-        </where>
+        from s_store s
+        left join s_store_user su on s.store_id=su.store_id and su.status_cd = '0'
+        where
+        s.status_cd = '0'
+        <if test="userId != null and userId != ''">
+            and su.user_id = #{userId}
+        </if>
+        <if test="storeTypeCd != null and storeTypeCd != ''">
+            and s.store_type_cd = #{storeTypeCd}
+        </if>
+        <if test="storeId != null and storeId != ''">
+            and s.store_id = #{storeId}
+        </if>
+
     </select>
 
 

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

@@ -259,6 +259,11 @@ public class ServiceCodeConstant {
      */
     public static final String SERVICE_CODE_USER_SERVICE_LOGIN = "user.service.login";
 
+    /**
+     * 管理员免密登录
+     */
+    public static final String SERVICE_CODE_ADMIN_LOGIN_PROPERTY = "login.adminLoginProperty";
+
     /**
      * 用户登录服务处理
      */

+ 165 - 0
service-api/src/main/java/com/java110/api/listener/login/AdminLoginPropertyServiceListener.java

@@ -0,0 +1,165 @@
+/*
+ * Copyright 2017-2021 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.api.listener.login;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiDataFlowListener;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.event.service.api.ServiceDataFlowEvent;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.store.StoreUserDto;
+import com.java110.dto.user.UserDto;
+import com.java110.dto.userLogin.UserLoginDto;
+import com.java110.intf.store.IStoreInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
+import com.java110.intf.user.IUserLoginInnerServiceSMO;
+import com.java110.po.userLogin.UserLoginPo;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.exception.SMOException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.DateUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 用户注册 侦听
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("adminLoginPropertyServiceListener")
+public class AdminLoginPropertyServiceListener extends AbstractServiceApiDataFlowListener {
+
+    private final static Logger logger = LoggerFactory.getLogger(AdminLoginPropertyServiceListener.class);
+
+
+    @Autowired
+    private IUserLoginInnerServiceSMO userLoginInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMOImpl;
+
+    @Autowired
+    private IStoreInnerServiceSMO storeInnerServiceSMOImpl;
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_ADMIN_LOGIN_PROPERTY;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.POST;
+    }
+
+
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+
+    private void validate(JSONObject reqJson) {
+        Assert.hasKeyAndValue(reqJson, "username", "未包含需要登录的用户名");
+        Assert.hasKeyAndValue(reqJson, "userId", "未包含需要登录的用户ID");
+        Assert.hasKeyAndValue(reqJson, "curPasswd", "未包含当前用户的密码");
+        Assert.hasKeyAndValue(reqJson, "curUserName", "未包含当前用户的用户名");
+    }
+
+
+    /**
+     * @param event
+     */
+    @Override
+    public void soService(ServiceDataFlowEvent event) {
+        //获取数据上下文对象
+        DataFlowContext dataFlowContext = event.getDataFlowContext();
+        ResponseEntity<String> responseEntity = null;
+        JSONObject paramIn = JSONObject.parseObject(dataFlowContext.getReqData());
+        validate(paramIn);
+
+        UserDto userDto = new UserDto();
+        userDto.setUserName(paramIn.getString("curUserName"));
+        userDto.setPassword(paramIn.getString("curPasswd"));
+        List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+
+        if (userDtos == null || userDtos.size() < 1) {
+            responseEntity = new ResponseEntity<String>("用户或密码错误", HttpStatus.UNAUTHORIZED);
+            dataFlowContext.setResponseEntity(responseEntity);
+            return;
+        }
+
+        //校验当前账户商户是不是 管理员商户
+        StoreUserDto storeUserDto = new StoreUserDto();
+        storeUserDto.setStoreTypeCd("800900000001");
+        storeUserDto.setUserId(userDtos.get(0).getUserId());
+        List<StoreUserDto> storeUserDtos = storeInnerServiceSMOImpl.getStoreUserInfo(storeUserDto);
+
+        Assert.listOnlyOne(storeUserDtos, "当前用户不是运营团队 不能免登录");
+
+
+        // 校验 需要登录的物业账号是否存在
+        userDto = new UserDto();
+        userDto.setUserId(paramIn.getString("userId"));
+        userDto.setUserName(paramIn.getString("username"));
+        userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+        Assert.listOnlyOne(userDtos, "需要登录的物业账号不存在");
+
+        //校验当前账户商户是不是 管理员商户
+        storeUserDto = new StoreUserDto();
+        storeUserDto.setStoreTypeCd("800900000003"); //物业账号
+        storeUserDto.setUserId(userDtos.get(0).getUserId());
+        storeUserDtos = storeInnerServiceSMOImpl.getStoreUserInfo(storeUserDto);
+
+        Assert.listOnlyOne(storeUserDtos, "需要免密登录的账号不是物业账号");
+
+        userDto = userDtos.get(0);
+        JSONObject userInfo = JSONObject.parseObject(JSONObject.toJSONString(userDto));
+        try {
+            Map userMap = new HashMap();
+            userMap.put(CommonConstant.LOGIN_USER_ID, userDto.getUserId());
+            userMap.put(CommonConstant.LOGIN_USER_NAME, userDto.getUserName());
+            String token = AuthenticationFactory.createAndSaveToken(userMap);
+            userInfo.remove("password");
+            userInfo.put("token", token);
+            //记录登录日志
+            UserLoginPo userLoginPo = new UserLoginPo();
+            userLoginPo.setLoginId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_loginId));
+            userLoginPo.setLoginTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+            userLoginPo.setPassword(userDto.getPassword());
+            userLoginPo.setSource(UserLoginDto.SOURCE_WEB);
+            userLoginPo.setToken(token);
+            userLoginPo.setUserId(userInfo.getString("userId"));
+            userLoginPo.setUserName(userInfo.getString("userName"));
+            userLoginInnerServiceSMOImpl.saveUserLogin(userLoginPo);
+            responseEntity = new ResponseEntity<String>(userInfo.toJSONString(), HttpStatus.OK);
+            dataFlowContext.setResponseEntity(responseEntity);
+        } catch (Exception e) {
+            logger.error("登录异常:", e);
+            throw new SMOException(ResponseConstant.RESULT_CODE_INNER_ERROR, "系统内部错误,请联系管理员");
+        }
+    }
+
+}

+ 2 - 1
service-api/src/main/java/com/java110/api/listener/UserLoginServiceListener.java

@@ -1,6 +1,7 @@
-package com.java110.api.listener;
+package com.java110.api.listener.login;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.api.listener.AbstractServiceApiDataFlowListener;
 import com.java110.core.annotation.Java110Listener;
 import com.java110.core.context.DataFlowContext;
 import com.java110.core.event.service.api.ServiceDataFlowEvent;

+ 1 - 1
service-front/src/main/java/com/java110/front/components/carInout/CarInManageComponent.java

@@ -2,7 +2,7 @@ package com.java110.front.components.carInout;
 
 
 import com.java110.core.context.IPageData;
-import com.java110.front.smo.carInout.IListCarInoutsSMO;
+import com.java110.front.smo.carBlackWhite.IListCarInoutsSMO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;

+ 1 - 1
service-front/src/main/java/com/java110/front/components/carInout/CarInoutManageComponent.java

@@ -2,7 +2,7 @@ package com.java110.front.components.carInout;
 
 
 import com.java110.core.context.IPageData;
-import com.java110.front.smo.carInout.IListCarInoutsSMO;
+import com.java110.front.smo.carBlackWhite.IListCarInoutsSMO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;

+ 17 - 4
service-front/src/main/java/com/java110/front/controller/AdminLoginPropertyAccountController.java

@@ -15,8 +15,12 @@
  */
 package com.java110.front.controller;
 
+import com.java110.core.context.IPageData;
+import com.java110.core.context.PageData;
+import com.java110.front.smo.login.IAdminLoginPropertyAccountServiceSMO;
+import com.java110.utils.constant.CommonConstant;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -34,14 +38,23 @@ import javax.servlet.http.HttpServletRequest;
 @RequestMapping(path = "/app")
 public class AdminLoginPropertyAccountController {
 
+    @Autowired
+    private IAdminLoginPropertyAccountServiceSMO adminLoginPropertyAccountServiceSMOImpl;
+
     /**
      * 管理员免密登录至 执行的物业账户下
      *
-     * @param postInfo
      * @param request
      */
     @RequestMapping(path = "/adminLoginPropertyAccount", method = RequestMethod.POST)
-    public ResponseEntity<String> adminLoginPropertyAccount(@RequestBody String postInfo, HttpServletRequest request) {
-        return null;
+    public ResponseEntity<String> adminLoginPropertyAccount(HttpServletRequest request) {
+        IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+
+        IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), pd.getReqData(),
+                "login", "", "", pd.getSessionId(),
+                pd.getAppId());
+        ResponseEntity<String> responseEntity = adminLoginPropertyAccountServiceSMOImpl.doLogin(newPd);
+        request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, newPd);
+        return responseEntity;
     }
 }

+ 1 - 1
service-front/src/main/java/com/java110/front/smo/carInout/IListCarInoutsSMO.java

@@ -1,4 +1,4 @@
-package com.java110.front.smo.carInout;
+package com.java110.front.smo.carBlackWhite;
 
 import com.java110.utils.exception.SMOException;
 import com.java110.core.context.IPageData;

+ 2 - 2
service-front/src/main/java/com/java110/front/smo/carInout/impl/ListCarInoutsSMOImpl.java

@@ -1,4 +1,4 @@
-package com.java110.front.smo.carInout.impl;
+package com.java110.front.smo.carBlackWhite.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.component.AbstractComponentSMO;
@@ -8,7 +8,7 @@ import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.exception.SMOException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
-import com.java110.front.smo.carInout.IListCarInoutsSMO;
+import com.java110.front.smo.carBlackWhite.IListCarInoutsSMO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;

+ 37 - 0
service-front/src/main/java/com/java110/front/smo/login/IAdminLoginPropertyAccountServiceSMO.java

@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.front.smo.login;
+
+import com.java110.core.context.IPageData;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * 管理员免密登录物业账号 接口类
+ * Created by wuxw on 2019/3/20.
+ */
+public interface IAdminLoginPropertyAccountServiceSMO {
+
+    /**
+     * 登录接口
+     * @param pd 页面请求对象
+     * @return
+     */
+    public ResponseEntity<String> doLogin(IPageData pd);
+
+
+
+
+}

+ 100 - 0
service-front/src/main/java/com/java110/front/smo/login/impl/AdminLoginPropertyAccountServiceSMOImpl.java

@@ -0,0 +1,100 @@
+package com.java110.front.smo.login.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.cache.Java110RedisConfig;
+import com.java110.core.component.BaseComponentSMO;
+import com.java110.core.context.IPageData;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.front.smo.login.IAdminLoginPropertyAccountServiceSMO;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.constant.ServiceConstant;
+import com.java110.utils.util.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+import org.thymeleaf.util.StringUtils;
+
+/**
+ * 登录信息实现类
+ * Created by wuxw on 2019/3/20.
+ */
+
+@Service("adminLoginPropertyAccountServiceSMOImpl")
+public class AdminLoginPropertyAccountServiceSMOImpl extends BaseComponentSMO implements IAdminLoginPropertyAccountServiceSMO {
+    private final static Logger logger = LoggerFactory.getLogger(AdminLoginPropertyAccountServiceSMOImpl.class);
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+
+    /**
+     * 登录处理
+     *
+     * @param pd 页面请求对象
+     * @return
+     */
+    @Override
+    public ResponseEntity<String> doLogin(IPageData pd) {
+
+        ResponseEntity<String> responseEntity = null;
+        JSONObject loginInfo = JSONObject.parseObject(pd.getReqData());
+        validate(loginInfo);
+        loginInfo.put("curPasswd", AuthenticationFactory.passwdMd5(loginInfo.getString("curPasswd")));
+        responseEntity = this.callCenterService(restTemplate, pd, loginInfo.toJSONString(), ServiceConstant.SERVICE_API_URL + "/api/login.adminLoginProperty", HttpMethod.POST);
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            JSONObject userInfo = JSONObject.parseObject(responseEntity.getBody());
+            pd.setToken(userInfo.getString("token"));
+            clearUserCache(userInfo);
+        }
+        return responseEntity;
+    }
+
+    /**
+     * 校验验证码
+     *
+     * @param reqJson 页面请求对象
+     * @return
+     */
+    public void validate(JSONObject reqJson) {
+
+        Assert.hasKeyAndValue(reqJson, "username", "未包含需要登录的用户名");
+        Assert.hasKeyAndValue(reqJson, "userId", "未包含需要登录的用户ID");
+        Assert.hasKeyAndValue(reqJson, "curPasswd", "未包含当前用户的密码");
+        Assert.hasKeyAndValue(reqJson, "curUserName", "未包含当前用户的用户名");
+
+    }
+
+    /**
+     * 清理用户缓存
+     *
+     * @param userInfo
+     */
+    private void clearUserCache(JSONObject userInfo) {
+        //员工商户缓存 getStoreInfo
+        String storeId = "";
+
+        String storeInfo = CommonCache.getValue("getStoreInfo" + Java110RedisConfig.GET_STORE_INFO_EXPIRE_TIME_KEY + "::" + userInfo.getString("userId"));
+        if (!StringUtils.isEmpty(storeInfo)) {
+            CommonCache.removeValue("getStoreInfo" + Java110RedisConfig.GET_STORE_INFO_EXPIRE_TIME_KEY + "::" + userInfo.getString("userId"));
+            JSONObject storeObj = JSONObject.parseObject(storeInfo);
+            storeId = storeObj.getJSONObject("msg").getString("storeId");
+            CommonCache.removeValue("getStoreEnterCommunitys" + Java110RedisConfig.GET_STORE_ENTER_COMMUNITYS_EXPIRE_TIME_KEY + "::" + storeId);
+        }
+        //员工权限
+        CommonCache.removeValue("getUserPrivileges" + Java110RedisConfig.DEFAULT_EXPIRE_TIME_KEY + "::" + userInfo.getString("userId"));
+    }
+
+
+    public RestTemplate getRestTemplate() {
+        return restTemplate;
+    }
+
+    public void setRestTemplate(RestTemplate restTemplate) {
+        this.restTemplate = restTemplate;
+    }
+}