处理 long类型值为小于int.max 数据格式错误问题
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
package org.jiayunet.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.apache.ibatis.type.BaseTypeHandler;
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
|
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||||
|
import org.apache.ibatis.type.MappedTypes;
|
||||||
|
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List<Long> 类型的 JSON TypeHandler
|
||||||
|
* <p>解决 JacksonTypeHandler 反序列化 JSON 数组时将小数字解析为 Integer 的问题</p>
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@MappedTypes(List.class)
|
||||||
|
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||||
|
public class LongListTypeHandler extends BaseTypeHandler<List<Long>> {
|
||||||
|
|
||||||
|
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||||
|
private static final TypeReference<List<Long>> TYPE_REF = new TypeReference<>() {};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNonNullParameter(PreparedStatement ps, int i, List<Long> parameter, JdbcType jdbcType) throws SQLException {
|
||||||
|
try {
|
||||||
|
ps.setString(i, MAPPER.writeValueAsString(parameter));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SQLException("序列化 List<Long> 失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||||
|
return parse(rs.getString(columnName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
|
return parse(rs.getString(columnIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||||
|
return parse(cs.getString(columnIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Long> parse(String json) throws SQLException {
|
||||||
|
if (json == null || json.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return MAPPER.readValue(json, TYPE_REF);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SQLException("反序列化 List<Long> 失败: " + json, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.jiayunet.config.LongListTypeHandler;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,7 +65,7 @@ public class Job {
|
|||||||
private Long requiredIndustryId;
|
private Long requiredIndustryId;
|
||||||
|
|
||||||
/** 要求专业ID数组,关联bg_major_category */
|
/** 要求专业ID数组,关联bg_major_category */
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = LongListTypeHandler.class)
|
||||||
private List<Long> requiredMajorIds;
|
private List<Long> requiredMajorIds;
|
||||||
|
|
||||||
/** 专业敏感度 0=不限 1=优先 2=强制 */
|
/** 专业敏感度 0=不限 1=优先 2=强制 */
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.jiayunet.config.LongListTypeHandler;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,7 +27,7 @@ public class UserJobIntention {
|
|||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/** 意向岗位类型ID列表,节点可能为任意级别 */
|
/** 意向岗位类型ID列表,节点可能为任意级别 */
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = LongListTypeHandler.class)
|
||||||
private List<Long> categoryIds;
|
private List<Long> categoryIds;
|
||||||
|
|
||||||
/** 意向城市编码列表,节点可能为任意级别 */
|
/** 意向城市编码列表,节点可能为任意级别 */
|
||||||
@@ -34,7 +35,7 @@ public class UserJobIntention {
|
|||||||
private List<String> regionCodes;
|
private List<String> regionCodes;
|
||||||
|
|
||||||
/** 意向行业ID列表,节点可能为任意级别 */
|
/** 意向行业ID列表,节点可能为任意级别 */
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = LongListTypeHandler.class)
|
||||||
private List<Long> industryIds;
|
private List<Long> industryIds;
|
||||||
|
|
||||||
/** 工作类型 0=全职 1=实习 */
|
/** 工作类型 0=全职 1=实习 */
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import org.jiayunet.config.LongListTypeHandler;
|
||||||
import org.jiayunet.pojo.vo.UserHonorsVo;
|
import org.jiayunet.pojo.vo.UserHonorsVo;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -49,7 +50,7 @@ public class UserProfile {
|
|||||||
private String portfolioUrl;
|
private String portfolioUrl;
|
||||||
|
|
||||||
/** 用户专业ID数组,关联bg_major_category(不展示,用于适配度计算) */
|
/** 用户专业ID数组,关联bg_major_category(不展示,用于适配度计算) */
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = LongListTypeHandler.class)
|
||||||
private List<Long> majorIds;
|
private List<Long> majorIds;
|
||||||
|
|
||||||
/** 学校等级 1=C9/985/QS前50 2=211/双一流/QS前200 3=普通一本/QS前500 4=其他(不展示,用于适配度计算) */
|
/** 学校等级 1=C9/985/QS前50 2=211/双一流/QS前200 3=普通一本/QS前500 4=其他(不展示,用于适配度计算) */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.jiayunet.pojo.vo;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.jiayunet.config.LongListTypeHandler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public class JobListItemVo {
|
|||||||
private Integer minExperience;
|
private Integer minExperience;
|
||||||
|
|
||||||
/** 要求专业ID数组(JSON) */
|
/** 要求专业ID数组(JSON) */
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = LongListTypeHandler.class)
|
||||||
private List<Long> requiredMajorIds;
|
private List<Long> requiredMajorIds;
|
||||||
|
|
||||||
/** 专业敏感度 0=不限 1=优先 2=强制 */
|
/** 专业敏感度 0=不限 1=优先 2=强制 */
|
||||||
|
|||||||
@@ -165,12 +165,13 @@ public class JobMatchService {
|
|||||||
|
|
||||||
int score = matchMajorPair(userMajor, jobMajor);
|
int score = matchMajorPair(userMajor, jobMajor);
|
||||||
maxScore = Math.max(maxScore, score);
|
maxScore = Math.max(maxScore, score);
|
||||||
if (maxScore == 100) return 100; // 已满分,提前退出
|
if (maxScore == 100) return 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return maxScore;
|
return maxScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 匹配一对专业的相关度
|
* 匹配一对专业的相关度
|
||||||
* <p>完全匹配→100,同二级→70,同一级→30,不相关→0</p>
|
* <p>完全匹配→100,同二级→70,同一级→30,不相关→0</p>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<result column="source_url" property="sourceUrl"/>
|
<result column="source_url" property="sourceUrl"/>
|
||||||
<result column="required_industry_id" property="requiredIndustryId"/>
|
<result column="required_industry_id" property="requiredIndustryId"/>
|
||||||
<result column="min_experience" property="minExperience"/>
|
<result column="min_experience" property="minExperience"/>
|
||||||
<result column="required_major_ids" property="requiredMajorIds" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
|
<result column="required_major_ids" property="requiredMajorIds" typeHandler="org.jiayunet.config.LongListTypeHandler"/>
|
||||||
<result column="major_sensitivity" property="majorSensitivity"/>
|
<result column="major_sensitivity" property="majorSensitivity"/>
|
||||||
<result column="status" property="status"/>
|
<result column="status" property="status"/>
|
||||||
<result column="company_id" property="companyId"/>
|
<result column="company_id" property="companyId"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user