| | |
| | | } |
| | | long talentId = number(talent.get("id")); |
| | | List<Map<String, Object>> binding = rows(""" |
| | | select t.id, |
| | | exists(select 1 from talent_card c where c.talent_id = t.id and c.deleted = 0 and c.card_type = 'PERSONAL') has_talent_card |
| | | select t.id |
| | | from talent_user t |
| | | where t.openid = ? and t.deleted = 0 |
| | | limit 1 for update |
| | | """, openId); |
| | | if (!binding.isEmpty() && number(binding.get(0).get("id")) != talentId) { |
| | | if (number(binding.get(0).get("hasTalentCard")) != 0) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "当前微信已绑定其他人才账号,请联系管理员"); |
| | | } |
| | | jdbc.update("update talent_user set openid = null where id = ?", number(binding.get(0).get("id"))); |
| | | long previousTalentId = number(binding.get(0).get("id")); |
| | | jdbc.update("update talent_session set revoked_at = coalesce(revoked_at, now()) where talent_id = ? and revoked_at is null", previousTalentId); |
| | | } |
| | | // uk_openid 是唯一索引:已软删/停用的历史账号照样占着这个 openid,不先摘掉就会撞唯一键(接口报「服务器内部错误」)。 |
| | | releaseOpenId(openId, talentId); |
| | | jdbc.update("update talent_user set openid = ? where id = ?", openId, talentId); |
| | | return issueSession(talentId); |
| | | } |
| | | |
| | | /** 把 openid 从除 keepTalentId 之外的所有行上摘掉(含软删、停用的历史账号)。 */ |
| | | private void releaseOpenId(String openId, long keepTalentId) { |
| | | jdbc.update("update talent_user set openid = null where openid = ? and id <> ?", openId, keepTalentId); |
| | | } |
| | | |
| | | private long registerVisitor(String openId, String mobile) { |
| | |
| | | jdbc.update("update talent_user set mobile = ? where id = ?", mobile, talentId); |
| | | return talentId; |
| | | } |
| | | // 没有可用的绑定时要把历史占用清掉,否则下面这条 insert 会撞 uk_openid。 |
| | | jdbc.update("update talent_user set openid = null where openid = ?", openId); |
| | | jdbc.update(""" |
| | | insert into talent_user(openid, name, mobile, talent_level, source_area_type, status) |
| | | values (?, '普通游客', ?, '普通游客', 'LOCAL', 1) |