chenjiahe
2024-08-09 facff53d9e3f608a43af80cae7173d81d5f64047
用户的公众号时间和crm时间BUG修复,流程重新梳理
3个文件已修改
147 ■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/entity/user/UserUnionDto.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/controller/user/UserController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/impl/UserUnionHisServiceImpl.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/entity/user/UserUnionDto.java
@@ -26,6 +26,10 @@
    /**平台的用户标识*/
    private String merId;
    //---------------------额外想法参数字段--------------------------------
    /**平台编码*/
    private String appIdCode;
    public String getId() {
        return id;
    }
@@ -89,4 +93,12 @@
    public void setCorpUserId(String corpUserId) {
        this.corpUserId = corpUserId;
    }
    public String getAppIdCode() {
        return appIdCode;
    }
    public void setAppIdCode(String appIdCode) {
        this.appIdCode = appIdCode;
    }
}
phi_platform_user/src/main/java/com/hx/phip/controller/user/UserController.java
@@ -547,6 +547,11 @@
        // 获取签名 appId
        String appId = request.getHeader("appId");
        if(userDto.getUserUnion() != null){
            userDto.getUserUnion().setAppIdCode(thirtApplication.getAppIdCode());
        }
        // 返回新增加的用户id
        String userId = userService.insertInfo(userDto,appId);
@@ -1021,7 +1026,18 @@
     * 根据HisId更新unionId/opneId
     */
    @RequestMapping("/unionId/edit")
    public Result unionIdEdit(@RequestBody(required = false)  UserUnionDto userUnionDto){
    public Result unionIdEdit(HttpServletRequest request,@RequestBody  UserUnionDto userUnionDto){
        // 获取用户信息
        ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if (thirtApplication == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "验签失败,请重新验签!");
        }
        if (StringUtils.isEmpty(thirtApplication.getAppIdCode())) {
            throw new PlatTipsException(PlatformCode.ERROR_TIPS, "AppIdCode不能为空!");
        }
        if(userUnionDto == null){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据格式错误");
        }
@@ -1041,6 +1057,8 @@
            throw new PlatTipsException(PlatformCode.ERROR_TIPS, "hisId错误!");
        }
        userUnionDto.setAppIdCode(thirtApplication.getAppIdCode());
        userUnionHisService.insert(users.getId(),userUnionDto);
        return Result.success();
    }
phi_platform_user/src/main/java/com/hx/phip/service/impl/UserUnionHisServiceImpl.java
@@ -2,11 +2,13 @@
import com.hx.common.service.CommonService;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.PlatformConstants;
import com.hx.phiappt.dao.mapper.*;
import com.hx.phiappt.model.BaseEntity;
import com.hx.phiappt.model.Employee;
import com.hx.phiappt.model.User;
import com.hx.phiappt.model.UserUnionHis;
import com.hx.phiappt.model.wechat.gzh.GzhFocusRecord;
import com.hx.phip.common.wx.corp.WeiXinCorpMpUtil;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.entity.user.UserUnionDto;
@@ -95,15 +97,10 @@
        Map<String, Object> sqlValues = new HashMap<>();
        sqlValues.put("unionId", unionId);
        sqlValues.put("isDel", BaseEntity.NO);
        String sql = " unionid=#{m.unionId} AND (sysUserId IS NULL OR LENGTH(sysUserId) <= 0) AND isDel=#{m.isDel}";
        sqlValues.put("userId", userId);
        String sql = " sysUserId=#{m.userId},editTime=NOW() WHERE unionid=#{m.unionId} AND isDel=#{m.isDel}";
        sqlSentence.sqlSentence(sql, sqlValues);
        int count = commonService.selectCount(ContactExternalMapper.class, sqlSentence);
        if (count > 0) {
            sqlValues.put("userId", userId);
            sql = " sysUserId=#{m.userId},editTime=NOW() WHERE unionid=#{m.unionId} AND (sysUserId IS NULL OR LENGTH(sysUserId) <= 0) AND isDel=#{m.isDel}";
            sqlSentence.sqlSentence(sql, sqlValues);
            commonService.updateWhere(ContactExternalMapper.class, sqlSentence);
        }
        commonService.updateWhere(ContactExternalMapper.class, sqlSentence);
    }
    /**新增*/
@@ -131,6 +128,11 @@
        userUnionHis.setUserId(userId);
        //---先获取全部
        List<UserUnionHis> userUnionHisList = userUnionHisMapper.getUserUnionHisList(userUnionHis.getFromCode(),userUnionHis.getOpenId());
        //查看是否存在
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
@@ -146,17 +148,48 @@
        values.put("fromId",userUnionHis.getFromId());
        values.put("editTime",new Date());
        sqlSentence.sqlUpdate("userId = #{m.userId},fromName = #{m.fromName},fromAppId = #{m.fromAppId},unionId = #{m.unionId},openId = #{m.openId},hisId = #{m.hisId},fromId = #{m.fromId},editTime = #{m.editTime} " +
                " WHERE fromCode = #{m.fromCode} AND openId = #{m.openId}",values);
                " WHERE fromCode = #{m.fromCode} AND openId = #{m.openId} AND isDel = 0",values);
        //更新匹配记录的信息
        userUnionHisMapper.updateWhere(sqlSentence);
        int updateNum = userUnionHisMapper.updateWhere(sqlSentence);
        if(updateNum == 0){
            userUnionHisMapper.insert(userUnionHis);
        }else if(updateNum > 1){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"更新用户信息失败");
        //更新被替换的记录用户
        values.clear();
        values.put("bindCRMTime",null);
        sqlSentence.sqlUpdate("bindCRMTime = #{m.bindCRMTime} WHERE id = #{m.id}",values);
        for(UserUnionHis userUnionHis1:userUnionHisList){
            values.put("id",userUnionHis1.getUserId());
            userMapper.updateWhere(sqlSentence);
        }
        // 公众号记录
        sqlSentence.sqlUpdate("userId = #{m.userId},editTime=NOW() WHERE unionId=#{m.unionId} AND userId IS NULL AND isDel=0", values);
        gzhFocusRecordMapper.updateWhere(sqlSentence);
        //没有数据就新增
        if(userUnionHisList.size() == 0){
            userUnionHisMapper.insert(userUnionHis);
        }
        //查找公众关注信息
        List<GzhFocusRecord> gzhFocusRecordList = gzhFocusRecordMapper.getGzhFocusRecordList(GzhFocusRecord.YES,null,null,userUnionHis.getUnionId());
        Date bindGZHTime = null;
        if(gzhFocusRecordList.size() > 0){
            bindGZHTime = gzhFocusRecordList.get(0).getBindTime();
            // 更新公众号记录
            sqlSentence.sqlUpdate("userId = #{m.userId},editTime=NOW() WHERE unionId=#{m.unionId} AND status = 1 AND isDel=0", values);
            gzhFocusRecordMapper.updateWhere(sqlSentence);
        }
        //更新用户信息,生成两个独立的对象
        StringBuilder updateUserSql = new StringBuilder();
        Map<String,Object> userValueMap = new HashMap<>();
        //crm
        if(PlatformConstants.TYPE_PLATFORM_CRM.equals(userUnionDto.getAppIdCode())){
            userValueMap.put("bindCRMTime", new Date());
            updateUserSql.append("bindCRMTime = #{m.bindCRMTime},");
        }
        if(bindGZHTime != null){
            userValueMap.put("bindGZHTime",bindGZHTime);
            updateUserSql.append("bindGZHTime = #{m.bindGZHTime},");
        }
        // 员工处理
        if(StringUtils.noNull(userUnionDto.getCorpUserId())){
@@ -168,32 +201,38 @@
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpUserId错误");
            }
            values.clear();
            values.put("cUserId",userUnionDto.getCorpUserId());
            values.put("bindCRMTime", new Date());
            values.put("id",userId);
            userValueMap.put("cUserId",userUnionDto.getCorpUserId());
            updateUserSql.append("cUserId = #{m.cUserId},");
            //获取用户信息
            User user = userMapper.selectOneByKey(userId);
            if (user == null) {
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户不存在");
            }
            sqlSentence.sqlUpdate("cUserId = #{m.cUserId},bindCRMTime = #{m.bindCRMTime} WHERE id = #{m.id}",values);
            if(userMapper.updateWhere(sqlSentence) != 1){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpUserId更新失败!");
            }
            if (StringUtils.isEmpty(user.getcUserId()) || !user.getcUserId().equals(userUnionDto.getCorpUserId())) {
                try {
                    // 企业微信员工标识有更新时推送企业微信消息
                    // 获取token
                    SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,customParameter.getCorpAppId(), customParameter.getCorpSecret());
                    if (sysParameter != null) {
                        String content = userUnionDto.getFromName() + "用户关联您的员工账号成功";
                        sendMsgTools.sendMsg(userUnionDto.getCorpUserId(), customParameter.getCorpAgentId(), content, sysParameter.getParamValue());
            if(user != null){
                if (StringUtils.isEmpty(user.getcUserId()) || !user.getcUserId().equals(userUnionDto.getCorpUserId())) {
                    try {
                        // 企业微信员工标识有更新时推送企业微信消息
                        // 获取token
                        SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,customParameter.getCorpAppId(), customParameter.getCorpSecret());
                        if (sysParameter != null) {
                            String content = userUnionDto.getFromName() + "用户关联您的员工账号成功";
                            sendMsgTools.sendMsg(userUnionDto.getCorpUserId(), customParameter.getCorpAgentId(), content, sysParameter.getParamValue());
                        }
                    } catch (Exception e) {
                        logger.error("用户更新员工标识时推送企业微信消息失败:" + e.getMessage());
                    }
                } catch (Exception e) {
                    logger.error("用户更新员工标识时推送企业微信消息失败:" + e.getMessage());
                }
            }
        }
        if(updateUserSql.length() > 0){
            //去除最后一个逗号
            updateUserSql.delete(updateUserSql.length() - 1, updateUserSql.length());
            //更新用户信息
            updateUserSql.append(" WHERE id = #{m.id}");
            userValueMap.put("id",userId);
            sqlSentence.sqlSentence(updateUserSql.toString(),userValueMap);
            userMapper.updateWhere(sqlSentence);
        }
    }
    /**新增*/