| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | |
| | | /**新增*/ |
| | |
| | | |
| | | userUnionHis.setUserId(userId); |
| | | |
| | | |
| | | //---先获取全部 |
| | | List<UserUnionHis> userUnionHisList = userUnionHisMapper.getUserUnionHisList(userUnionHis.getFromCode(),userUnionHis.getOpenId()); |
| | | |
| | | |
| | | //查看是否存在 |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | |
| | | 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())){ |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |
| | | /**新增*/ |