ソースを参照

unionId修改调整

jk-GitHub-coder 4 年 前
コミット
1c8cccb8c7

+ 28 - 21
YijiaRestful/src/main/java/com/platform/yijia/controller/AppUserInfoController.java

@@ -20,6 +20,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -129,12 +130,14 @@ public class AppUserInfoController {
      */
     @RequestMapping(value = "/addAppUserInfo", method = RequestMethod.POST)
     @ResponseBody
+    @Transactional
     public String addAppUserInfo(@RequestBody AppUserInfoRequest request){
         Gson gson =new Gson();
         ResultData resultData=null;
         try{
+            logger.info("前端传入参数:" +request.toString());
             AppUserInfo appUserInfo =new AppUserInfo();
-            //CustomerPoints customerPoints =  new CustomerPoints();
+            CustomerPoints customerPoints =  new CustomerPoints();
             String openId = "";     //此参数用于查询该用户是否已注册过
             if(request.getUserType()!=null){
                 //1-微信公众号
@@ -143,63 +146,67 @@ public class AppUserInfoController {
                     appUserInfo.setBlogToken(request.getBlogToken());
                     openId = request.getBlogOpenid();
                     appUserInfo.setBlogOpenid(openId);
-                    //customerPoints.setBlogOpenId(openId);
+                    customerPoints.setBlogOpenId(openId);
                  //2-微信小程序
                 }else if(request.getUserType().equals("2") &&StringUtils.isNotBlank(request.getMinaOpenid())){
                     appUserInfo.setUserType(request.getUserType());
                     appUserInfo.setMinaToken(request.getMinaToken());
                     openId = request.getMinaOpenid();
                     appUserInfo.setMinaOpenid(openId);
-                    //customerPoints.setMinaOpenId(openId);
+                    customerPoints.setMinaOpenId(openId);
                 }
             }
             if(StringUtils.isNotBlank(request.getBlogNickName())){
                 appUserInfo.setBlogNickName(request.getBlogNickName());
-                //customerPoints.setCustomerName(request.getBlogNickName());
+                customerPoints.setCustomerName(request.getBlogNickName());
             }
             if(StringUtils.isNotBlank(request.getMobilePhone())){
                 appUserInfo.setMobilePhone(request.getMobilePhone());
-                //customerPoints.setMobilePhone(request.getMobilePhone());
+                customerPoints.setMobilePhone(request.getMobilePhone());
             }
             if(StringUtils.isNotBlank(request.getBlogProfilePhoto())){
                 appUserInfo.setBlogProfilePhoto(request.getBlogProfilePhoto());
             }
             if(StringUtils.isNotBlank(request.getUnionId())){
                 appUserInfo.setUnionId(request.getUnionId());
-                //customerPoints.setUnionId(request.getUnionId());
+                customerPoints.setUnionId(request.getUnionId());
             }
 
             appUserInfo.setRegisteDate(new Date());
             appUserInfo.setUpdateDate(new Date());
 
-            //customerPoints.setCreateTime(new Date());
-//            customerPoints.setUnionId(request.getUnionId());
-//            customerPoints.setPoints(0);
-//            customerPoints.setConsumptionPoints(0);
-//            customerPoints.setAccumulatePoints(0);
-//            customerPoints.setInvalidPoints(0);
+            customerPoints.setCreateTime(new Date());
+            customerPoints.setUnionId(request.getUnionId());
+            customerPoints.setPoints(0);
+            customerPoints.setConsumptionPoints(0);
+            customerPoints.setAccumulatePoints(0);
+            customerPoints.setInvalidPoints(0);
+            customerPoints.setStationId(request.getStationId());
+            customerPoints.setStationName(request.getStationName());
 
             if(StringUtils.isNotBlank(request.getSexFlag())){
                 appUserInfo.setSexFlag(request.getSexFlag());
             }
-
+            logger.info("插入数据库用户信息参数:"+appUserInfo.toString());
             Map<String, Object> params = new HashMap<>();
             params.put("openId", openId);                   //注册用户openId
             params.put("userType", request.getUserType());  //用户类型
             //判断该用户是否已存在
             int count = appUserInfoService.isExistAppUser(params);
             if(count > 0){
-//                boolean boo = customerPointsService.isExistCustomerPointsInfo(customerPoints);
-//                if(!boo){
-//                    customerPointsService.insertCustomerPointsInfo(customerPoints);
-//                }
-//                if(appUserInfoService.getUserUnionId(appUserInfo)==null){
-//                    appUserInfoService.updateUnionId(appUserInfo);
-//                }
+                boolean boo = customerPointsService.isExistCustomerPointsInfo(customerPoints);
+                if(!boo){
+                    customerPointsService.insertCustomerPointsInfo(customerPoints);
+                }
+                String userUnionId = appUserInfoService.getUserUnionId(appUserInfo);
+
+                if(!StringUtils.isNotBlank(userUnionId)){
+                    appUserInfoService.updateUnionId(appUserInfo);
+                }
                 resultData = ResultData.error(CodeMsg.USER_EXSIST);
             }else {
                 appUserInfoService.AddAppUserInfo(appUserInfo);
-//                customerPointsService.insertCustomerPointsInfo(customerPoints);
+                customerPointsService.insertCustomerPointsInfo(customerPoints);
                 resultData = ResultData.success(CodeMsg.SUCCESS);
             }
         }catch (Exception e){

+ 3 - 0
YijiaRestful/src/main/java/com/platform/yijia/param/request/AppUserInfoRequest.java

@@ -22,4 +22,7 @@ public class AppUserInfoRequest {
     private String blogProfilePhoto;    //用户头像
     private String updateDate;          //更新时间
     private String unionId;          //微信用户unionId
+    private Integer stationId;          //油站Id
+    private String stationName;          //油站名称
+
 }

+ 5 - 1
YijiaRestful/src/main/java/com/platform/yijia/utils/weixinapp/WeiXinUserUtil.java

@@ -70,11 +70,15 @@ public class WeiXinUserUtil {
         //发起GET请求
         JSONObject jsonObject = HttpRequestUtil.getHttpsRequestData(requestUrl, "GET", null);
         logger.info("用户openid和session_key:" + jsonObject.toString());
-        //System.out.println("用户openid和session_key:  "+jsonObject);
         if(jsonObject != null && jsonObject.containsKey("openid")){
             resultMap.put("openid", jsonObject.getString("openid"));
+        }
+        if(jsonObject != null && jsonObject.containsKey("session_key")){
             resultMap.put("session_key", jsonObject.getString("session_key"));
         }
+        if(jsonObject != null && jsonObject.containsKey("unionid")){
+            resultMap.put("unionid", jsonObject.getString("unionid"));
+        }
         return resultMap;
     }
 

+ 10 - 10
YijiaRestful/src/main/resources/mapper/AppUserInfoMapper.xml

@@ -392,7 +392,7 @@
         update_date = #{updateDate,jdbcType=TIMESTAMP},
       </if>
       <if test="unionId != null">
-        union_id = #{updateDate,jdbcType=VARCHAR},
+        union_id = #{unionId,jdbcType=VARCHAR},
       </if>
     </set>
     where user_id = #{userId,jdbcType=INTEGER}
@@ -422,17 +422,17 @@
   <!--查询客户unionId-->
   <select id="getUserUnionId" parameterType="com.platform.yijia.pojo.AppUserInfo" resultType="String">
     SELECT
-        unionId
+        union_id AS unionId
     from app_user_info
     <where>
       <if test="userType !=null and userType !=''">
         user_type = #{userType}
       </if>
-      <if test="userType !=null and userType ==1 ">
-        AND blog_openid = #{openId}
+      <if test="blogOpenid !=null and blogOpenid !=''">
+        AND blog_openid = #{blogOpenid}
       </if>
-      <if test="userType !=null and userType ==2 ">
-        AND mina_openid = #{openId}
+      <if test="minaOpenid !=null and minaOpenid !=''">
+        AND mina_openid = #{minaOpenid}
       </if>
     </where>
   </select>
@@ -449,11 +449,11 @@
       <if test="userType !=null and userType !=''">
         user_type = #{userType}
       </if>
-      <if test="userType !=null and userType ==1 ">
-        AND blog_openid = #{openId}
+      <if test="blogOpenid !=null and blogOpenid !=''">
+        AND blog_openid = #{blogOpenid}
       </if>
-      <if test="userType !=null and userType ==2 ">
-        AND mina_openid = #{openId}
+      <if test="minaOpenid !=null and minaOpenid !=''">
+        AND mina_openid = #{minaOpenid}
       </if>
     </where>
   </update>

+ 2 - 2
YijiaRestful/src/main/resources/mapper/CustomerPointsMapper.xml

@@ -182,11 +182,11 @@
   <!--判断是否存在-->
   <select id="isExistCustomerPointsInfo" resultType="int" parameterType="com.platform.yijia.pojo.CustomerPoints">
     SELECT
-        COUNT (id)
+        COUNT(union_id)
     FROM
         customer_points
     <where>
-      <if test="unionId !=null">
+      <if test="unionId !=null and unionId !=''">
         union_id = #{unionId}
       </if>
     </where>