diff --git a/client-api/src/main/java/org/jiayunet/service/JobIntentionService.java b/client-api/src/main/java/org/jiayunet/service/JobIntentionService.java index 71e5a00..78f0728 100644 --- a/client-api/src/main/java/org/jiayunet/service/JobIntentionService.java +++ b/client-api/src/main/java/org/jiayunet/service/JobIntentionService.java @@ -10,11 +10,13 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.Instant; + /** * 求职意向服务 - * 主要功能:用户求职意向的查询和保存 - * 依赖服务:无 - * 使用的表:bg_user_job_intention + *

主要功能:用户求职意向的查询和保存

+ *

依赖服务:无

+ *

使用的表:bg_user_job_intention

* * @author zk */ @@ -25,7 +27,7 @@ public class JobIntentionService { /** * 查询当前用户的求职意向 - * 逻辑:根据userId查询,不存在返回null + *

根据userId查询,不存在返回null

*/ public JobIntentionDto getJobIntention() { Long userId = UserSecurityTool.getUserId(); @@ -40,18 +42,28 @@ public class JobIntentionService { /** * 保存/更新求职意向 - * 逻辑:先查询是否存在,存在则更新,不存在则新增 + *

先查询是否存在,存在则更新,不存在则新增

*/ public void saveJobIntention(JobIntentionParam param) { Long userId = UserSecurityTool.getUserId(); UserJobIntention po = intentionMapper.selectOne(new LambdaQueryWrapper().eq(UserJobIntention::getUserId, userId)); + if (po == null) { po = new UserJobIntention(); po.setUserId(userId); - BeanUtils.copyProperties(param, po); + po.setCategoryIds(param.getCategoryIds() != null ? param.getCategoryIds() : java.util.Collections.emptyList()); + po.setRegionCodes(param.getRegionCodes() != null ? param.getRegionCodes() : java.util.Collections.emptyList()); + po.setIndustryIds(param.getIndustryIds() != null ? param.getIndustryIds() : java.util.Collections.emptyList()); + po.setEmploymentType(param.getEmploymentType()); + po.setCreateTime(Instant.now()); + po.setUpdateTime(Instant.now()); intentionMapper.insert(po); } else { - BeanUtils.copyProperties(param, po); + po.setCategoryIds(param.getCategoryIds() != null ? param.getCategoryIds() : java.util.Collections.emptyList()); + po.setRegionCodes(param.getRegionCodes() != null ? param.getRegionCodes() : java.util.Collections.emptyList()); + po.setIndustryIds(param.getIndustryIds() != null ? param.getIndustryIds() : java.util.Collections.emptyList()); + po.setEmploymentType(param.getEmploymentType()); + po.setUpdateTime(Instant.now()); intentionMapper.updateById(po); } } diff --git a/common/src/main/java/org/jiayunet/config/JacksonConfig.java b/common/src/main/java/org/jiayunet/config/JacksonConfig.java index ae26be7..679e571 100644 --- a/common/src/main/java/org/jiayunet/config/JacksonConfig.java +++ b/common/src/main/java/org/jiayunet/config/JacksonConfig.java @@ -24,7 +24,24 @@ public class JacksonConfig { private static final JsonSerializer LONG_SERIALIZER = new JsonSerializer() { @Override public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeString(value.toString()); + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(value.toString()); + } + } + }; + + private static final JsonSerializer NUMBER_TO_STRING_SERIALIZER = new JsonSerializer() { + @Override + public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + if (value == null) { + gen.writeNull(); + } else if (value instanceof Number) { + gen.writeString(String.valueOf(((Number) value).longValue())); + } else { + gen.writeString(value.toString()); + } } }; @@ -38,11 +55,16 @@ public class JacksonConfig { @Bean public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { - return builder - .serializerByType(Long.class, LONG_SERIALIZER) - .serializerByType(long.class, LONG_SERIALIZER) + ObjectMapper mapper = builder .deserializerByType(Long.class, LONG_DESERIALIZER) .deserializerByType(long.class, LONG_DESERIALIZER) .build(); + + // 使用兼容 Number 类型的序列化器 + mapper.registerModule(new com.fasterxml.jackson.databind.module.SimpleModule() + .addSerializer(Long.class, NUMBER_TO_STRING_SERIALIZER) + .addSerializer(long.class, NUMBER_TO_STRING_SERIALIZER)); + + return mapper; } } diff --git a/manager/src/main/java/org/jiayunet/pojo/po/UserJobIntention.java b/manager/src/main/java/org/jiayunet/pojo/po/UserJobIntention.java index 1bb36e7..058a161 100644 --- a/manager/src/main/java/org/jiayunet/pojo/po/UserJobIntention.java +++ b/manager/src/main/java/org/jiayunet/pojo/po/UserJobIntention.java @@ -1,11 +1,14 @@ package org.jiayunet.pojo.po; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import java.time.Instant; +import java.util.List; /** * 用户求职意向表(bg_user_job_intention) @@ -13,7 +16,7 @@ import java.time.Instant; * @author zk */ @Data -@TableName(value = "bg_user_job_intention") +@TableName(value = "bg_user_job_intention", autoResultMap = true) public class UserJobIntention { @TableId(type = IdType.ASSIGN_ID) @@ -22,14 +25,17 @@ public class UserJobIntention { /** 用户ID */ private Long userId; - /** 意向岗位类型ID列表(JSON数组),节点可能为任意级别 */ - private String categoryIds; + /** 意向岗位类型ID列表,节点可能为任意级别 */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List categoryIds; - /** 意向城市编码列表(JSON数组),节点可能为任意级别 */ - private String regionCodes; + /** 意向城市编码列表,节点可能为任意级别 */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List regionCodes; - /** 意向行业ID列表(JSON数组),节点可能为任意级别 */ - private String industryIds; + /** 意向行业ID列表,节点可能为任意级别 */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List industryIds; /** 工作类型 0=全职 1=实习 */ private Integer employmentType;