Browse Source

添加 JobLocation 模型, 记录 51job 上爬取的数据

reghao 1 year ago
parent
commit
cd83bd0b70

+ 22 - 0
mall/mall-api/src/main/java/cn/reghao/tnb/mall/api/dto/geo/JobLoc.java

@@ -0,0 +1,22 @@
+package cn.reghao.tnb.mall.api.dto.geo;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author reghao
+ * @date 2024-11-24 14:12:00
+ */
+@AllArgsConstructor
+@Getter
+public class JobLoc {
+    private String companyName;
+    private String issueDate;
+    private String jobHref;
+    private String jobDescribe;
+    private long salaryMin;
+    private long salaryMax;
+    private String salaryStr;
+    private double lat;
+    private double lng;
+}

+ 15 - 2
mall/mall-service/src/main/java/cn/reghao/tnb/mall/app/geo/controller/MapController.java

@@ -2,12 +2,14 @@ package cn.reghao.tnb.mall.app.geo.controller;
 
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.db.SelectOption;
+import cn.reghao.tnb.mall.api.dto.geo.JobLoc;
 import cn.reghao.tnb.mall.api.dto.geo.MallReplyDto;
 import cn.reghao.tnb.mall.api.dto.geo.MallReplyPhotoDto;
 import cn.reghao.tnb.mall.app.geo.model.vo.MapPoint;
 import cn.reghao.tnb.mall.app.geo.model.vo.MapMarker;
 import cn.reghao.tnb.mall.app.geo.model.vo.MarkerInfo;
 import cn.reghao.tnb.mall.app.geo.service.EarthService;
+import cn.reghao.tnb.mall.app.geo.service.JobLocationService;
 import cn.reghao.tnb.mall.app.geo.service.MapService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -27,10 +29,19 @@ import java.util.List;
 public class MapController {
     private final MapService mapService;
     private final EarthService earthService;
+    private final JobLocationService jobLocationService;
 
-    public MapController(MapService mapService, EarthService earthService) {
+    public MapController(MapService mapService, EarthService earthService, JobLocationService jobLocationService) {
         this.mapService = mapService;
         this.earthService = earthService;
+        this.jobLocationService = jobLocationService;
+    }
+
+    @ApiOperation(value = "添加工作位置", notes = "N")
+    @PostMapping(value = "/job", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addJobLocation(@RequestBody JobLoc jobLoc) {
+        jobLocationService.addJobLocation(jobLoc);
+        return WebResult.success();
     }
 
     @ApiOperation(value = "检查淘宝商品评论是否存在", notes = "N")
@@ -57,7 +68,9 @@ public class MapController {
     @ApiOperation(value = "获取地图中标记的点", notes = "N")
     @GetMapping(value = "/markers", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getMapMarkers(@RequestParam("type") Integer type) {
-        List<MapMarker> list = mapService.getMapMarkers(type);
+        //List<MapMarker> list = mapService.getMapMarkers(type);
+        List<MapMarker> list = jobLocationService.getMapMarks();
+
         return WebResult.success(list);
     }
 

+ 17 - 0
mall/mall-service/src/main/java/cn/reghao/tnb/mall/app/geo/db/mapper/JobLocationMapper.java

@@ -0,0 +1,17 @@
+package cn.reghao.tnb.mall.app.geo.db.mapper;
+
+import cn.reghao.jutil.jdk.db.BaseMapper;
+import cn.reghao.tnb.mall.app.geo.model.po.JobLocation;
+import cn.reghao.tnb.mall.app.geo.model.vo.MapMarker;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-11-24 14:18:23
+ */
+@Mapper
+public interface JobLocationMapper extends BaseMapper<JobLocation> {
+    List<MapMarker> findMapMarker();
+}

+ 39 - 0
mall/mall-service/src/main/java/cn/reghao/tnb/mall/app/geo/model/po/JobLocation.java

@@ -0,0 +1,39 @@
+package cn.reghao.tnb.mall.app.geo.model.po;
+
+import cn.reghao.jutil.jdk.db.BaseObject;
+import cn.reghao.tnb.mall.api.dto.geo.JobLoc;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @author reghao
+ * @date 2024-11-24 14:08:53
+ */
+@NoArgsConstructor
+@Getter
+public class JobLocation extends BaseObject<Integer> {
+    private String companyName;
+    private LocalDateTime issueDate;
+    private String jobHref;
+    private String jobDescribe;
+    private long salaryMin;
+    private long salaryMax;
+    private String salaryStr;
+    private BigDecimal longitude;
+    private BigDecimal latitude;
+
+    public JobLocation(JobLoc jobLoc, LocalDateTime issueDate) {
+        this.companyName = jobLoc.getCompanyName();
+        this.issueDate = issueDate;
+        this.jobHref = jobLoc.getJobHref();
+        this.jobDescribe = jobLoc.getJobDescribe();
+        this.salaryMin = jobLoc.getSalaryMin();
+        this.salaryMax = jobLoc.getSalaryMax();
+        this.salaryStr = jobLoc.getSalaryStr();
+        this.longitude = BigDecimal.valueOf(jobLoc.getLng());
+        this.latitude = BigDecimal.valueOf(jobLoc.getLat());
+    }
+}

+ 40 - 0
mall/mall-service/src/main/java/cn/reghao/tnb/mall/app/geo/service/JobLocationService.java

@@ -0,0 +1,40 @@
+package cn.reghao.tnb.mall.app.geo.service;
+
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
+import cn.reghao.tnb.mall.api.dto.geo.JobLoc;
+import cn.reghao.tnb.mall.app.geo.db.mapper.JobLocationMapper;
+import cn.reghao.tnb.mall.app.geo.model.po.JobLocation;
+import cn.reghao.tnb.mall.app.geo.model.vo.MapMarker;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-11-24 14:17:52
+ */
+@Service
+public class JobLocationService {
+    private final JobLocationMapper jobLocationMapper;
+
+    public JobLocationService(JobLocationMapper jobLocationMapper) {
+        this.jobLocationMapper = jobLocationMapper;
+    }
+
+    public void addJobLocation(JobLoc jobLoc) {
+        LocalDateTime issueDate = LocalDateTime.MIN;
+        try {
+            issueDate = DateTimeConverter.localDateTime2(jobLoc.getIssueDate());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        JobLocation jobLocation = new JobLocation(jobLoc, issueDate);
+        jobLocationMapper.save(jobLocation);
+    }
+
+    public List<MapMarker> getMapMarks() {
+        return jobLocationMapper.findMapMarker();
+    }
+}

+ 55 - 0
mall/mall-service/src/main/resources/mapper/geo/JobLocationMapper.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="cn.reghao.tnb.mall.app.geo.db.mapper.JobLocationMapper">
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        insert into geo_job_location
+        (`company_name`,`issue_date`,`job_href`,`job_describe`,`salary_min`,`salary_max`,`salary_str`,`geo`)
+        values
+        (#{companyName},#{issueDate},#{jobHref},#{jobDescribe},#{salaryMin},#{salaryMax},#{salaryStr},point(#{longitude},#{latitude}))
+    </insert>
+    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
+        insert ignore into geo_job_location
+        (`company_name`,`issue_date`,`job_href`,`job_describe`,`salary_min`,`salary_max`,`salary_str`,`geo`)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.companyName},#{item.issueDate},#{item.jobHref},#{item.jobDescribe},#{item.salaryMin},#{item.salaryMax},#{item.salaryStr},point(#{item.longitude},#{item.latitude}))
+        </foreach>
+    </insert>
+
+    <resultMap id="photoGeo" type="cn.reghao.tnb.mall.app.geo.model.po.MallReplyPhoto">
+        <result property="id" column="id"/>
+        <result property="replyId" column="reply_id"/>
+        <result property="photoUrl" column="photo_url"/>
+        <association property="geoPoint" javaType="cn.reghao.tnb.mall.app.geo.model.vo.MapPoint">
+            <result property="lng" column="lng"/>
+            <result property="lat" column="lat"/>
+        </association>
+    </resultMap>
+    <select id="findAll" resultMap="photoGeo">
+        select id,reply_id,photo_url,x(geo) as lng,y(geo) as lat
+        from geo_job_location
+    </select>
+    <select id="findMarkerInfoById" resultType="cn.reghao.tnb.mall.app.geo.model.vo.MarkerInfo">
+        select reply.item_id,reply.reply_id,reply.extra as sku,reply.reply_content,reply.append_content,
+        photo.upload_id,photo.channel_id,photo.photo_url
+        from geo_job_location photo
+        inner join geo_mall_reply reply
+        on photo.reply_id=reply.reply_id and photo.id=#{id}
+    </select>
+
+    <resultMap id="mapMarker" type="cn.reghao.tnb.mall.app.geo.model.vo.MapMarker">
+        <result property="id" column="id"/>
+        <result property="title" column="company_name"/>
+        <association property="position" javaType="cn.reghao.tnb.mall.app.geo.model.vo.MapPoint">
+            <result property="lng" column="lng"/>
+            <result property="lat" column="lat"/>
+        </association>
+    </resultMap>
+    <select id="findMapMarker" resultMap="mapMarker">
+        select id,company_name,x(geo) as lng,y(geo) as lat
+        from geo_job_location photo
+        order by issue_date desc
+        limit 1000
+    </select>
+</mapper>