Преглед на файлове

用户委托经纪人代理服务

by su преди 4 години
родител
ревизия
36da43aaf6

+ 3 - 1
house-biz/src/main/java/com/ljq/house/biz/dao/TmUserDao.java

@@ -27,6 +27,8 @@ public interface TmUserDao extends BaseMapper<TmUser> {
 
     public long selectTmUserCount();
 
-    List<TmUser> setectUserlist(@Param("user") TmUser user);
+    public int updateUser(@Param("tmUser") TmUser tmUser);
+
+
 
 }

+ 49 - 0
house-biz/src/main/java/com/ljq/house/biz/vo/request/DelegationVo.java

@@ -0,0 +1,49 @@
+package com.ljq.house.biz.vo.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author abnerhou
+ * @date 2020/7/31 19:18
+ * @desciption
+ */
+@Data
+@ApiModel(value = "委托请求实体" , description = "委托请求实体")
+public class DelegationVo {
+
+    //微信首次登录的code
+    @ApiModelProperty(value="微信首次登录的code",name="wx_code",example="dfsdfsfx")
+    @JsonProperty("wx_code")
+    private String wxCode;
+
+    @ApiModelProperty(value="经过微信加密的手机号",name="phone_num",example="dfsdfsfxxfdsfddfasdaffa")
+    @JsonProperty("phone_num")
+    private String phoneNum;
+
+    //微信登录数据解密的初始变量
+    @ApiModelProperty(value="微信登录数据解密的初始变量",name="iv",example="dfsdfsfxxfdsfddfasdaffa")
+    private String iv;
+
+    //微信加密的敏感数据
+    @ApiModelProperty(value="微信加密的敏感数据",name="encryptedData",example="dfsdfsfxxfdsfddfasdaffa")
+    private String encryptedData;
+
+    //不包括敏感信息的原始数据字符串,用于计算签名
+    @ApiModelProperty(value="不包括敏感信息的原始数据字符串,用于计算签名",name="rawData",example="dfsdfsfxxfdsfddfasdaffa")
+    private String rawData;
+
+    //使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息
+    @ApiModelProperty(value="使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息",name="signature",example="dfsdfsfxxfdsfddfasdaffa")
+    private String signature;
+
+    @ApiModelProperty(value="用户Id",name="user_id",example="dfsdfsfxxfdsfddfasdaffa")
+    @JsonProperty("user_id")
+    private String userId;
+
+    @ApiModelProperty(value="经纪人Id",name="agency_user_id",example="dfsdfsfxxfdsfddfasdaffa")
+    @JsonProperty("agency_user_id")
+    private String agencyUserId;
+}

+ 2 - 0
house-biz/src/main/resources/mapper/TmHouseMapper.xml

@@ -140,6 +140,8 @@
             <if test="tmHouse.introduceVideoDesc != null and tmHouse.introduceVideoDesc.trim() != ''">introduce_video_desc=#{tmHouse.introduceVideoDesc},</if>
             <if test="tmHouse.additionsImages != null and tmHouse.additionsImages.trim() != ''">additions_images=#{tmHouse.additionsImages},</if>
             <if test="tmHouse.coverAdditionsImages != null and tmHouse.coverAdditionsImages.trim() != ''">cover_additions_images=#{tmHouse.coverAdditionsImages},</if>
+            <if test="tmHouse.constructionYear != null and tmHouse.constructionYear.trim() != ''">construction_year=#{tmHouse.constructionYear},</if>
+
             last_modify_datetime = now()
         </set>
         where `house_id` = #{tmHouse.houseId}

+ 51 - 27
house-biz/src/main/resources/mapper/TmUserMapper.xml

@@ -60,40 +60,34 @@
         limit 1
     </select>
 
-    <select id="setectUserlist" resultType="com.ljq.house.biz.model.TmUser">
-        select * from tm_user
-        <where>
-            ENABLE = 1
-            <if test="user !=null and user.userId">
-                and user_id = #{user.userId}
+    <update id="updateUser">
+        update tm_user
+        <set>
+            <if test="tmUser.wxOpenId !=null and tmUser.wxOpenId != '' ">
+                wx_open_id = #{tmUser.wxOpenId},
             </if>
-
-            <if test="user !=null and user.wxOpenId">
-                and wx_open_id = #{user.wxOpenId}
+            <if test="tmUser.name !=null and tmUser.name != '' ">
+                name = #{tmUser.name},
             </if>
-
-            <if test="user !=null and user.name">
-                and name = #{user.name}
+            <if test="tmUser.phone !=null and tmUser.phone != '' ">
+                phone = #{tmUser.phone},
             </if>
-
-            <if test="user !=null and user.phone">
-                and phone = #{user.phone}
+            <if test="tmUser.email !=null and tmUser.email != '' ">
+                email = #{tmUser.email},
             </if>
-
-            <if test="user !=null and user.email">
-                and email = #{user.email}
+            <if test="tmUser.passwd !=null and tmUser.passwd != '' ">
+                passwd = #{tmUser.passwd},
             </if>
-            <if test="user !=null and user.passwd">
-                and passwd = #{user.passwd}
+            <if test="tmUser.avatar !=null and tmUser.avatar != '' ">
+                avatar = #{tmUser.avatar},
             </if>
-
-            <if test="user !=null and user.enable">
-                and enable = #{user.enable}
+            <if test="tmUser.enable !=null ">
+                enable = #{tmUser.enable},
             </if>
-
-        </where>
-        order by CREATE_TIME desc
-    </select>
+            last_modify_datetime = now(),
+        </set>
+        where user_id = #{tmUser.userId}
+    </update>
 
 
 
@@ -162,4 +156,34 @@
         from tm_user
         where ENABLE = 1
     </select>
+
+
+    <update id="updateUser">
+        update tm_user
+        <set>
+            <if test="tmUser.wxOpenId !=null and tmUser.wxOpenId != '' ">
+                wx_open_id = #{tmUser.wxOpenId},
+            </if>
+            <if test="tmUser.name !=null and tmUser.name != '' ">
+                name = #{tmUser.name},
+            </if>
+            <if test="tmUser.phone !=null and tmUser.phone != '' ">
+                phone = #{tmUser.phone},
+            </if>
+            <if test="tmUser.email !=null and tmUser.email != '' ">
+                email = #{tmUser.email},
+            </if>
+            <if test="tmUser.passwd !=null and tmUser.passwd != '' ">
+                passwd = #{tmUser.passwd},
+            </if>
+            <if test="tmUser.avatar !=null and tmUser.avatar != '' ">
+                avatar = #{tmUser.avatar},
+            </if>
+            <if test="tmUser.enable !=null ">
+                enable = #{tmUser.enable},
+            </if>
+            last_modify_datetime = now(),
+        </set>
+        where user_id = #{tmUser.userId}
+    </update>
 </mapper>

+ 48 - 45
house-web/src/main/java/com/ljq/house/app/controller/AppTmUserController.java

@@ -7,6 +7,7 @@ import com.ljq.house.auth.utils.aes.WXCore;
 import com.ljq.house.biz.dao.*;
 import com.ljq.house.biz.model.*;
 import com.ljq.house.biz.model.dto.WxUserInfoDto;
+import com.ljq.house.biz.vo.request.DelegationVo;
 import com.ljq.house.common.constants.CommonConstants;
 import com.ljq.house.common.enums.HouseFocusStatusEnum;
 import com.ljq.house.common.enums.IdStarterEnum;
@@ -26,6 +27,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -160,44 +162,6 @@ public class AppTmUserController {
         return Result.success(jsonObject);
     }
 
-    @ApiOperation(value = "获取手机号")
-    @RequestMapping(value = "/getPhoneNum", method = RequestMethod.POST)
-    @ResponseBody
-    public Result getPhone(@RequestBody @ApiParam(name="登录请求实体",value="传入json格式",required=true) LoginVo loginVo) {
-
-        if (!StringUtils.isNoneBlank(loginVo.getWxCode(), loginVo.getIv(), loginVo.getPhoneNum(),loginVo.getUserId())) {
-            throw new CommonBaseException(ResultCodeEnum.D017);
-        }
-        Map<String, Object> wxResult =  WxOpUtils.tryLoginWx(loginVo.getWxCode(), userWxAppId, userWxAppSecret);
-        String wxSessionKey = (String) wxResult.get(WxOpUtils.SESSION_KEY);
-        String wxOpenId = (String) wxResult.get(WxOpUtils.WX_OPEN_ID_KEY);
-        String decryptPhoneNum = null;
-        try {
-            JSONObject resultJson = WXCore.decrypt(wxOpenId, loginVo.getPhoneNum(), wxSessionKey, loginVo.getIv());
-            decryptPhoneNum = null != resultJson ? resultJson.getString(CommonConstants.WxConstant.WX_PHONE_NUMBER) : "";
-            log.info("用户解密出来的手机号码为:{}", decryptPhoneNum);
-        }catch (Exception e) {
-            log.error("解密手机号出现异常:{}", e);
-            throw new CommonBaseException(ResultCodeEnum.D039);
-        }
-
-        //先通过wxOpenId获取用户表,查看用户是否已经存在
-        //先通过手机号获取用户表,查看用户是否已经存在
-        TmUser dbUser = tmUserDao.selectTmUsers(loginVo.getUserId());
-        if (null == dbUser) {
-            throw new CommonBaseException(ResultCodeEnum.D046);
-        }else{
-            dbUser.setPhone(decryptPhoneNum);
-            tmUserDao.update(dbUser);
-        }
-
-        //返回用户信息和token给前端
-        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
-
-        jsonObject.put("user", dbUser);
-
-        return Result.success(jsonObject);
-    }
 
     @ApiOperation(value = "修改用户")
     @PostMapping("/update")
@@ -380,17 +344,56 @@ public class AppTmUserController {
      * @return
      */
 
-    @RequestMapping(value = "/delegation", method = RequestMethod.GET)
+    @PostMapping(value = "/delegation")
     @ResponseBody
-    public Result addAgencyCustomer(@RequestParam(name =  "user_id") String userId ,
-                                    @RequestParam(name = "agency_user_id") String agencyUserId) {
+    @Transactional(rollbackFor = Exception.class)
+    public Result addAgencyCustomer(@RequestBody @ApiParam(name="委托请求实体",value="传入json格式",required=true) DelegationVo delegationVo) {
 
-        TmUser tmUser = tmUserDao.selectTmUsers(userId);
-        TmAgency tmAgency = tmAgencyDao.selectTmAgencyById(agencyUserId);
+        if(null == delegationVo){
+            throw new CommonBaseException(ResultCodeEnum.D017);
+        }
+        if(!StringUtils.isNoneBlank( delegationVo.getIv() , delegationVo.getEncryptedData() , delegationVo.getWxCode())){
+            throw new CommonBaseException(ResultCodeEnum.D017);
+        }
+
+        Map<String, Object> wxResult =  WxOpUtils.tryLoginWx(delegationVo.getWxCode() , userWxAppId, userWxAppSecret);
+        String wxSessionKey = (String) wxResult.get(WxOpUtils.SESSION_KEY);
+        String wxOpenId = (String) wxResult.get(WxOpUtils.WX_OPEN_ID_KEY);
+        String decryptPhoneNum = null;
+        try {
+            JSONObject resultJson = WXCore.decrypt(wxOpenId, delegationVo.getEncryptedData(), wxSessionKey, delegationVo.getIv());
+            decryptPhoneNum = null != resultJson ? resultJson.getString(CommonConstants.WxConstant.WX_PHONE_NUMBER) : "";
+            log.info("解密出来的手机号码为:{}", decryptPhoneNum);
+        } catch (Exception e) {
+            log.error("解密手机号出现异常:{}", e);
+            throw new CommonBaseException(ResultCodeEnum.D039);
+        }
+        if(StringUtils.isBlank(decryptPhoneNum)){
+            throw new CommonBaseException(ResultCodeEnum.D039);
+        }
+        log.info("上送的userId={}" , delegationVo.getUserId());
+        //TODO这里获取的地方要改
+        TmUser tmUser = tmUserDao.selectTmUsers(delegationVo.getUserId());
+        TmAgency tmAgency = tmAgencyDao.selectTmAgencyById(delegationVo.getAgencyUserId());
         if(null == tmUser || null == tmAgency){
-            Result.failure("用户或者经纪人数据缺失");
+            throw new CommonBaseException(ResultCodeEnum.D101 , "用户或者经纪人数据缺失");
         }
-        if(userService.checkHadDelegated(userId , agencyUserId)){
+        if(StringUtils.isNotBlank(tmUser.getWxOpenId()) && !StringUtils.equals(tmUser.getWxOpenId() , wxOpenId)){
+            log.info("上送的wxOpenId={}, 数据库中的是openId={}" , wxOpenId , tmUser.getWxOpenId());
+            throw new CommonBaseException(ResultCodeEnum.D101 , "上送的openId和数据中的不一致");
+        }
+
+        if(StringUtils.isBlank(tmUser.getWxOpenId())){
+            tmUser.setWxOpenId(wxOpenId);
+        }
+        tmUser.setPhone(decryptPhoneNum);
+        int updateUser = tmUserDao.updateUser(tmUser);
+        if(updateUser != 1){
+            throw new CommonBaseException(ResultCodeEnum.D101 , "更新用户的手机号码失败");
+        }
+
+
+        if(userService.checkHadDelegated(delegationVo.getUserId() , delegationVo.getAgencyUserId())){
             return Result.success("此用户已经委托过,无需重复委托", tmUser.getPhone());
         }