| | |
| | | return detail(id); |
| | | } |
| | | |
| | | /** |
| | | * 游客(还没有人才卡)补录认证信息并升级为持卡人:建一张 PERSONAL 卡,同时把等级、卡号写回 talent_user。 |
| | | * |
| | | * <p>已经有有效主卡的持卡人不能走这条路——改等级有单独的「修改人才等级」入口,避免这里重复发卡。 |
| | | */ |
| | | @Transactional |
| | | public Map<String, Object> upgrade(Long id, TalentUpgradeRequest request) { |
| | | Integer existingCards = jdbcTemplate.queryForObject(""" |
| | | select count(*) from talent_card |
| | | where deleted = 0 and talent_id = ? and card_type = 'PERSONAL' |
| | | """, Integer.class, id); |
| | | if (existingCards != null && existingCards > 0) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "该持卡人已有有效人才卡,请改用「修改人才等级」"); |
| | | } |
| | | String cardNo = request.talentCardNo().trim().toUpperCase(); |
| | | Integer cardCount = jdbcTemplate.queryForObject("select count(*) from talent_card where card_no = ?", Integer.class, cardNo); |
| | | if (cardCount != null && cardCount > 0) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "人才卡号已存在"); |
| | | } |
| | | int updated = jdbcTemplate.update(""" |
| | | update talent_user |
| | | set name = ?, id_card_no = ?, gender = ?, work_unit = ?, talent_level = ?, |
| | | source_area_type = ?, work_address = ?, contact_address = ?, talent_card_no = ? |
| | | where id = ? and deleted = 0 |
| | | """, |
| | | request.name(), |
| | | blankToNull(request.idCardNo()), |
| | | request.gender(), |
| | | blankToNull(request.workUnit()), |
| | | request.talentLevel(), |
| | | defaultValue(request.sourceAreaType(), "LOCAL"), |
| | | blankToNull(request.workAddress()), |
| | | blankToNull(request.contactAddress()), |
| | | cardNo, |
| | | id); |
| | | if (updated == 0) { |
| | | throw new BusinessException(ErrorCode.NOT_FOUND, "持卡人不存在"); |
| | | } |
| | | jdbcTemplate.update(""" |
| | | insert into talent_card(talent_id, card_no, card_type, card_level, valid_start, valid_end, issue_time, status) |
| | | values (?, ?, 'PERSONAL', ?, curdate(), date_add(curdate(), interval 1 year), now(), 1) |
| | | """, id, cardNo, request.talentLevel()); |
| | | return detail(id); |
| | | } |
| | | |
| | | @Transactional |
| | | public Map<String, Object> updateCardLevel(Long id, String talentLevel) { |
| | | Integer cardCount = jdbcTemplate.queryForObject(""" |