wangxy 1 неделя назад
Родитель
Сommit
6cefb34dee

+ 1 - 2
fs-admin/src/main/java/com/fs/xiaoshouyi/controller/XiaoShouYiController.java

@@ -72,8 +72,7 @@ public class XiaoShouYiController {
 
             GenerateLinkResponse response = materialService.generateMaterialTrackLink(
                                                                     companyUserId,
-                                                                    request.getMaterialIds(),
-                                                                    request.getSendUserId());
+                                                                    request.getMaterialIds());
 
             return response.isSuccess()
                     ? AjaxResult.success(response)

+ 1 - 2
fs-company/src/main/java/com/fs/xiaoshouyi/controller/XiaoShouYiController.java

@@ -72,8 +72,7 @@ public class XiaoShouYiController {
 
             GenerateLinkResponse response = materialService.generateMaterialTrackLink(
                                                                     companyUserId,
-                                                                    request.getMaterialIds(),
-                                                                    request.getSendUserId());
+                                                                    request.getMaterialIds());
 
             return response.isSuccess()
                     ? AjaxResult.success(response)

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsUserMapper.java

@@ -487,4 +487,6 @@ public interface FsUserMapper
      * @param userIds
      * **/
     List<FsUser> selectUserListByUserIds(@Param("userIds") List<Long> userIds);
+
+    int updateMpOpenIdByUserId(@Param("userId") Long userId, @Param("openId") String openId);
 }

+ 4 - 0
fs-service/src/main/java/com/fs/his/mapper/FsUserWxMapper.java

@@ -3,6 +3,7 @@ package com.fs.his.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.his.domain.FsUserWx;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 public interface FsUserWxMapper extends BaseMapper<FsUserWx> {
 
@@ -13,4 +14,7 @@ public interface FsUserWxMapper extends BaseMapper<FsUserWx> {
     void insertOrUpdateByUniqueKey(FsUserWx wx);
 
     FsUserWx getFsUserWcByUserIdAndAppId(@Param("fsUserId") Long userId,@Param("appId") String appId );
+
+    @Select("select * from fs_user_wx where app_id=#{appid} and fs_user_id=#{userId} limit 1")
+    FsUserWx selectByAppidAndUserId(@Param("appid") String appid, @Param("userId") Long userId);
 }

+ 1 - 1
fs-service/src/main/java/com/fs/sop/service/impl/SopUserLogsInfoServiceImpl.java

@@ -2132,7 +2132,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                                     materialIdList.add(materialWithUpload.getMaterialId());
 
                                     GenerateLinkResponse response =
-                                            xiaoShouYiMaterialService.generateMaterialTrackLink(Long.valueOf(companyUserId),materialIdList, 4256378833539950L);
+                                            xiaoShouYiMaterialService.generateMaterialTrackLink(Long.valueOf(companyUserId),materialIdList);
 
                                     if (response == null) {
                                         throw new RuntimeException("generateMaterialTrackLink返回为空");

+ 5 - 0
fs-service/src/main/java/com/fs/xiaoshouyi/domain/XsyAccount.java

@@ -73,4 +73,9 @@ public class XsyAccount {
 
     private Date createTime;
     private Date updateTime;
+
+    /**
+     * 销售易发送人id
+     */
+    private String sendUserId;
 }

+ 10 - 3
fs-service/src/main/java/com/fs/xiaoshouyi/service/XiaoShouYiMaterialService.java

@@ -1,10 +1,12 @@
 package com.fs.xiaoshouyi.service;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.fs.xiaoshouyi.client.XiaoShouYiHttpClient;
 import com.fs.xiaoshouyi.config.XiaoShouYiProperties;
+import com.fs.xiaoshouyi.domain.XsyAccount;
 import com.fs.xiaoshouyi.dto.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -42,19 +44,24 @@ public class XiaoShouYiMaterialService {
     private final XiaoShouYiHttpClient httpClient;
     private final XiaoShouYiProperties properties;
     private final XsyAccountResolver xsyAccountResolver;
+    private final XsyAccountService xsyAccountService;
 
 
     /**
      * 自动选账号:生成素材追踪链接
      */
     public GenerateLinkResponse generateMaterialTrackLink(Long companyUserId,
-                                                              List<Long> materialIdList,
-                                                              Long sendUserId) {
+                                                              List<Long> materialIdList) {
         Long accountId = resolveAccountId(companyUserId);
+        XsyAccount xsyAccount = xsyAccountService.selectById(accountId);
+        if (ObjectUtil.isEmpty(xsyAccount)){
+            throw new RuntimeException("销售易账号不存在,accountId=" + accountId);
+        }
+
 
         Map<String, Object> body = new HashMap<String, Object>();
         body.put("materialIdList", materialIdList);
-        body.put("sendUserId", sendUserId);
+        body.put("sendUserId", xsyAccount.getSendUserId());
 
         return executeWithRetry(
                 accountId,

+ 6 - 0
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -2539,5 +2539,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{userId}
         </foreach>
     </select>
+    <update id="updateMpOpenIdByUserId">
+        update fs_user
+        set mp_open_id = #{openId},
+            update_time = now()
+        where user_id = #{userId}
+    </update>
 
 </mapper>

+ 4 - 2
fs-service/src/main/resources/mapper/xiaoshouyi/XsyAccountMapper.xml

@@ -93,7 +93,8 @@
             client_secret,
             redirect_uri,
             status,
-            create_time
+            create_time,
+            send_user_id
         ) values (
              #{id},
              #{accountName},
@@ -101,7 +102,8 @@
              #{clientSecret},
              #{redirectUri},
              #{status},
-             now()
+             now(),
+             #{sendUserId}
                  )
     </insert>
 

+ 42 - 0
fs-user-app/src/main/java/com/fs/app/controller/AppLoginController.java

@@ -3,6 +3,7 @@ package com.fs.app.controller;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fs.app.annotation.Login;
 import com.fs.app.param.*;
@@ -20,7 +21,9 @@ import com.fs.core.config.WxOpenProperties;
 import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserNewTask;
+import com.fs.his.domain.FsUserWx;
 import com.fs.his.mapper.FsUserMapper;
+import com.fs.his.mapper.FsUserWxMapper;
 import com.fs.his.service.IFsUserCouponService;
 import com.fs.his.service.IFsUserNewTaskService;
 import com.fs.his.service.IFsUserService;
@@ -72,6 +75,9 @@ public class AppLoginController extends AppBaseController{
 
     @Autowired
     private ISmsService smsService;
+
+    @Autowired
+    private FsUserWxMapper fsUserWxMapper;
     @ApiOperation("注册app用户")
     @PostMapping("/register")
     @RepeatSubmit
@@ -987,4 +993,40 @@ public class AppLoginController extends AppBaseController{
         // 不存在,追加到末尾
         return currentAppIds + "," + newAppId;
     }
+    @PostMapping("/loginByUnionId")
+    public R loginByUnionId(@RequestBody FsUserUnionIdLoginParam param){
+        if (StringUtils.isEmpty(param.getUnionId()) || StringUtils.isEmpty(param.getOpenId())) {
+            return R.error("unionId或openId不能为空");
+        }
+        FsUser fsUser = userMapper.selectFsUserByUnionid(param.getUnionId());
+        if (ObjectUtil.isEmpty(fsUser)){
+            return R.error("账号不存在");
+        }
+
+        if (!StringUtils.equals(fsUser.getMpOpenId(), param.getOpenId())) {
+            int rows = userMapper.updateMpOpenIdByUserId(fsUser.getUserId(), param.getOpenId());
+            if (rows <= 0) {
+                return R.error("绑定openId失败");
+            }
+        }
+        String appid = "wx6f25bbf90d1b13ce";
+        FsUserWx userWx = fsUserWxMapper.selectByAppidAndUserId(appid, fsUser.getUserId());
+        if(userWx == null){
+            FsUserWx userWx1 = new FsUserWx();
+            userWx1.setFsUserId(fsUser.getUserId());
+            userWx1.setAppId(appid);
+            userWx1.setUnionId(param.getUnionId());
+            userWx1.setOpenId(param.getOpenId());
+            userWx1.setType(2);
+            userWx1.setCreateTime(new Date());
+            userWx1.setUpdateTime(new Date());
+            fsUserWxMapper.insert(userWx1);
+        }
+        String token = jwtUtils.generateToken(fsUser.getUserId());
+        redisCache.setCacheObject("userToken:" + fsUser.getUserId(), token, 604800, TimeUnit.SECONDS);
+        Map<String, Object> map = new HashMap<>();
+        map.put("token", token);
+        map.put("user", fsUser);
+        return R.ok(map);
+    }
 }

+ 13 - 0
fs-user-app/src/main/java/com/fs/app/param/FsUserUnionIdLoginParam.java

@@ -0,0 +1,13 @@
+package com.fs.app.param;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class FsUserUnionIdLoginParam implements Serializable {
+
+    private String openId;
+
+    private String unionId;
+}