Jelajahi Sumber

1.企微外部联系人同步小程序用户手机号 2.修改我的企微客户绑定手机号业务

wjj 1 hari lalu
induk
melakukan
bded9b764b

+ 10 - 0
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -2383,6 +2383,16 @@ public class Task {
 //        }
 //        }
     }
     }
 
 
+    public void syncFsUserPhone(){
+        logger.info("=============同步小程序会员手机号==========");
+        try {
+            int syncedFsUserPhone = qwExternalContactService.syncFsUserPhone();
+            logger.info("同步小程序会员手机号完成,共同步{}条数据", syncedFsUserPhone);
+        } catch (Exception e) {
+            logger.info("同步小程序会员手机号失败,错误信息:{}",e.getMessage());
+        }
+    }
+
     /**
     /**
      * "跟进会员"提醒时间任务
      * "跟进会员"提醒时间任务
      * */
      * */

+ 3 - 0
fs-service/src/main/java/com/fs/his/domain/FsUser.java

@@ -177,6 +177,9 @@ public class FsUser extends BaseEntity
 
 
     private String appleKey; // 苹果key登陆验证
     private String appleKey; // 苹果key登陆验证
 
 
+    @TableField(exist = false)
+    private Long exId;//外部联系人id
+
     public void setNickName(String nickname)
     public void setNickName(String nickname)
     {
     {
         if(StringUtils.isNotEmpty(nickname)){
         if(StringUtils.isNotEmpty(nickname)){

+ 32 - 7
fs-service/src/main/java/com/fs/his/service/impl/FsUserServiceImpl.java

@@ -68,7 +68,9 @@ import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
 import com.fs.hisStore.service.IFsUserBillScrmService;
 import com.fs.hisStore.service.IFsUserBillScrmService;
 import com.fs.hisStore.vo.FsCompanyUserListQueryVO;
 import com.fs.hisStore.vo.FsCompanyUserListQueryVO;
 import com.fs.qw.cache.IQwExternalContactCacheService;
 import com.fs.qw.cache.IQwExternalContactCacheService;
+import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.dto.FsUserTransferParamDTO;
 import com.fs.qw.dto.FsUserTransferParamDTO;
+import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.param.QwFsUserParam;
 import com.fs.qw.param.QwFsUserParam;
 import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.vo.QwFsUserVO;
 import com.fs.qw.vo.QwFsUserVO;
@@ -183,6 +185,9 @@ public class FsUserServiceImpl implements IFsUserService {
     @Autowired
     @Autowired
     private IQwExternalContactService qwExternalContactService;
     private IQwExternalContactService qwExternalContactService;
 
 
+    @Autowired
+    private QwExternalContactMapper qwExternalContactMapper;
+
 
 
     /**
     /**
      * 查询用户
      * 查询用户
@@ -1611,6 +1616,9 @@ public class FsUserServiceImpl implements IFsUserService {
         if (user.getUserId() == null) {
         if (user.getUserId() == null) {
             return R.error("会员参数错误,绑定手机号失败");
             return R.error("会员参数错误,绑定手机号失败");
         }
         }
+        if (user.getExId() == null) {
+            return R.error("参数错误");
+        }
         if (StringUtils.isEmpty(user.getPhone())) {
         if (StringUtils.isEmpty(user.getPhone())) {
             return R.error("手机号不能为空!");
             return R.error("手机号不能为空!");
         }
         }
@@ -1629,14 +1637,31 @@ public class FsUserServiceImpl implements IFsUserService {
         if (userById == null) {
         if (userById == null) {
             return R.error("未找到用户信息");
             return R.error("未找到用户信息");
         }
         }
-        if (StringUtils.isNotEmpty(userById.getPhone())) {
-            return R.error("该用户已绑定手机号");
+        QwExternalContact queryExt = qwExternalContactMapper.selectQwExternalContactById(user.getExId());
+        if (queryExt == null) {
+            return R.error("外部联系人为空");
+        }
+        String binPhone;
+        if (StringUtils.isEmpty(userById.getPhone())) {
+            binPhone = user.getPhone();
+            FsUser mapUser = new FsUser();
+            mapUser.setUserId(user.getUserId());
+            mapUser.setPhone(user.getPhone());
+            fsUserMapper.updateFsUser(mapUser);
+        } else {
+            binPhone = userById.getPhone();
+        }
+        //更新外部联系人小程序用户手机号信息信息
+        QwExternalContact qwExternalContact = new QwExternalContact();
+        qwExternalContact.setId(user.getExId());
+        if (isLikelyEncryptedByEntropy(binPhone)) {
+            qwExternalContact.setFsUserPhone(decryptPhone(binPhone));
+        } else {
+            qwExternalContact.setFsUserPhone(binPhone);
         }
         }
-        FsUser mapUser = new FsUser();
-        mapUser.setUserId(user.getUserId());
-        mapUser.setPhone(user.getPhone());
-        if (fsUserMapper.updateFsUser(mapUser) > 0) {
-            return R.ok();
+        int i = qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
+        if (i > 0) {
+            return R.ok("绑定手机号成功");
         }
         }
         return R.error("绑定手机号失败");
         return R.error("绑定手机号失败");
     }
     }

+ 3 - 0
fs-service/src/main/java/com/fs/qw/domain/QwExternalContact.java

@@ -157,4 +157,7 @@ public class QwExternalContact extends BaseEntity
     //是否已推送给医生 0否 1是
     //是否已推送给医生 0否 1是
     private Integer isPush;
     private Integer isPush;
 
 
+    //小程序用户手机号
+    private String fsUserPhone;
+
 }
 }

+ 8 - 0
fs-service/src/main/java/com/fs/qw/mapper/QwExternalContactMapper.java

@@ -256,6 +256,8 @@ public interface QwExternalContactMapper extends BaseMapper<QwExternalContact> {
             "left join company_user cu on ec.company_user_id=cu.user_id " +
             "left join company_user cu on ec.company_user_id=cu.user_id " +
             "<where>  \n" +
             "<where>  \n" +
             "            <if test=\"userId != null  and userId != ''\"> and ec.user_id   like concat( #{userId}, '%') </if>\n" +
             "            <if test=\"userId != null  and userId != ''\"> and ec.user_id   like concat( #{userId}, '%') </if>\n" +
+            "            <if test=\"bindStatus != null  and bindStatus == 0\"> and ec.fs_user_phone IS NULL </if>\n" +
+            "            <if test=\"bindStatus != null  and bindStatus == 1\"> and ec.fs_user_phone IS NOT NULL AND ec.fs_user_phone != '' </if>\n" +
             "            <if test=\"qwUserName != null  and qwUserName != ''\"> and qu.qw_user_name   like concat( #{qwUserName}, '%') </if>\n" +
             "            <if test=\"qwUserName != null  and qwUserName != ''\"> and qu.qw_user_name   like concat( #{qwUserName}, '%') </if>\n" +
             "            <if test=\"externalUserId != null  and externalUserId != ''\"> and ec.external_user_id = #{externalUserId}</if>\n" +
             "            <if test=\"externalUserId != null  and externalUserId != ''\"> and ec.external_user_id = #{externalUserId}</if>\n" +
             "            <if test=\"name != null  and name != ''\"> and ec.name like concat( #{name}, '%')</if>\n" +
             "            <if test=\"name != null  and name != ''\"> and ec.name like concat( #{name}, '%')</if>\n" +
@@ -554,4 +556,10 @@ public interface QwExternalContactMapper extends BaseMapper<QwExternalContact> {
 
 
     @Select("SELECT count(*) FROM `qw_external_contact` WHERE unionid = #{unionId} ")
     @Select("SELECT count(*) FROM `qw_external_contact` WHERE unionid = #{unionId} ")
     Long selectCountByUnionId(String unionId);
     Long selectCountByUnionId(String unionId);
+
+    @Select("select q.id,q.fs_user_id,u.phone fs_user_phone FROM qw_external_contact q LEFT JOIN fs_user u ON q.fs_user_id = u.user_id WHERE q.fs_user_id IS NOT NULL AND q.fs_user_phone IS NULL AND u.phone IS NOT NULL AND u.phone != '' ORDER BY q.id ASC LIMIT 1000 ")
+    List<QwExternalContact> selectSyncFsUserPhoneList();
+
+
+    int batchUpdateFsUserPhoneById(@Param("list") List<QwExternalContact> list);
 }
 }

+ 3 - 0
fs-service/src/main/java/com/fs/qw/param/QwExternalContactParam.java

@@ -132,6 +132,9 @@ public class QwExternalContactParam {
 
 
     private Long wayId;
     private Long wayId;
 
 
+    //是否绑定小程序用户手机号 0未绑定 1绑定
+    private Integer bindStatus;
+
     @ApiModelProperty(value = "页码,默认为1")
     @ApiModelProperty(value = "页码,默认为1")
     private Integer pageNum =1;
     private Integer pageNum =1;
     @ApiModelProperty(value = "页大小,默认为10")
     @ApiModelProperty(value = "页大小,默认为10")

+ 5 - 0
fs-service/src/main/java/com/fs/qw/service/IQwExternalContactService.java

@@ -256,4 +256,9 @@ public interface IQwExternalContactService extends IService<QwExternalContact> {
     void buyProductAddTag(Long fsUserId,Long packageId);
     void buyProductAddTag(Long fsUserId,Long packageId);
 
 
     List<String> selectTagsByFsUserId(Long fsUserId);
     List<String> selectTagsByFsUserId(Long fsUserId);
+
+    /**
+     * 同步企微客户手机号
+     */
+    int syncFsUserPhone();
 }
 }

+ 23 - 0
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactServiceImpl.java

@@ -6105,6 +6105,29 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
         return Collections.emptyList();
         return Collections.emptyList();
     }
     }
 
 
+    @Override
+    public int syncFsUserPhone() {
+        int totalCount = 0;
+        while (true) {
+            List<QwExternalContact> contacts = qwExternalContactMapper.selectSyncFsUserPhoneList();
+            if (CollectionUtils.isEmpty(contacts)) {
+                break;
+            }
+            contacts.forEach(qwExternalContact -> {
+                if (PhoneUtil.isLikelyEncryptedByEntropy(qwExternalContact.getFsUserPhone())) {
+                    qwExternalContact.setFsUserPhone(PhoneUtil.decryptPhone(qwExternalContact.getFsUserPhone()));
+                }
+            });
+            //更新
+            int updateCount = qwExternalContactMapper.batchUpdateFsUserPhoneById(contacts);
+            totalCount += updateCount;
+            if (updateCount < 1000) {
+                break;
+            }
+        }
+        return totalCount;
+    }
+
 
 
     public Boolean getSopAiChatByRedis(String qwUserId,String corpId,String externalUserId){
     public Boolean getSopAiChatByRedis(String qwUserId,String corpId,String externalUserId){
 
 

+ 17 - 1
fs-service/src/main/resources/mapper/qw/QwExternalContactMapper.xml

@@ -45,10 +45,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="registerTime"    column="register_time"    />
         <result property="registerTime"    column="register_time"    />
         <result property="isReply"    column="is_reply"    />
         <result property="isReply"    column="is_reply"    />
         <result property="isPush"    column="is_push"    />
         <result property="isPush"    column="is_push"    />
+        <result property="fsUserPhone"    column="fs_user_phone"    />
     </resultMap>
     </resultMap>
 
 
     <sql id="selectQwExternalContactVo">
     <sql id="selectQwExternalContactVo">
-        select id,qw_user_id,register_time,state,way_id,stage_status,first_time,open_id,is_interact,level, unionid, user_id,transfer_time,loss_time,del_time,transfer_num, external_user_id,transfer_status,status,create_time, name, avatar, type, gender, remark, description, tag_ids, remark_mobiles, remark_corp_name, add_way, oper_userid, corp_id, company_id, company_user_id, customer_id, fs_user_id,is_reply,is_push from qw_external_contact
+        select id,qw_user_id,register_time,state,way_id,stage_status,first_time,open_id,is_interact,level, unionid, user_id,transfer_time,loss_time,del_time,transfer_num, external_user_id,transfer_status,status,create_time, name, avatar, type, gender, remark, description, tag_ids, remark_mobiles, remark_corp_name, add_way, oper_userid, corp_id, company_id, company_user_id, customer_id, fs_user_id,is_reply,is_push,fs_user_phone from qw_external_contact
     </sql>
     </sql>
 
 
     <select id="selectQwExternalContactList" parameterType="QwExternalContact" resultMap="QwExternalContactResult">
     <select id="selectQwExternalContactList" parameterType="QwExternalContact" resultMap="QwExternalContactResult">
@@ -352,6 +353,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isProductBuy != null">is_product_buy = #{isProductBuy},</if>
             <if test="isProductBuy != null">is_product_buy = #{isProductBuy},</if>
             <if test="isUpsellProductBuy != null">is_upsell_product_buy = #{isUpsellProductBuy},</if>
             <if test="isUpsellProductBuy != null">is_upsell_product_buy = #{isUpsellProductBuy},</if>
             <if test="isPush != null">is_push = #{isPush},</if>
             <if test="isPush != null">is_push = #{isPush},</if>
+            <if test="fsUserPhone != null">fs_user_phone = #{fsUserPhone},</if>
         </trim>
         </trim>
         where id = #{id}
         where id = #{id}
     </update>
     </update>
@@ -784,5 +786,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             order by ec.create_time desc, ec.id desc
             order by ec.create_time desc, ec.id desc
     </select>
     </select>
 
 
+    <update id="batchUpdateFsUserPhoneById" parameterType="java.util.List">
+        UPDATE qw_external_contact
+        SET fs_user_phone = CASE id
+        <foreach collection="list" item="item">
+            WHEN #{item.id} THEN #{item.fsUserPhone}
+        </foreach>
+        ELSE fs_user_phone
+        END
+        WHERE id IN
+        <foreach collection="list" item="item" open="(" separator="," close=")">
+            #{item.id}
+        </foreach>
+    </update>
+
 
 
 </mapper>
 </mapper>