Przeglądaj źródła

更新 content 的 geo 模块

reghao 1 rok temu
rodzic
commit
4d4a9c1930

+ 1 - 12
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/MapController.java

@@ -2,14 +2,12 @@ package cn.reghao.tnb.content.app.geo;
 
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.db.SelectOption;
-import cn.reghao.tnb.content.api.dto.geo.JobLoc;
 import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
 import cn.reghao.tnb.content.api.dto.geo.MallReplyPhotoDto;
 import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
 import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
 import cn.reghao.tnb.content.app.geo.model.vo.MarkerInfo;
 import cn.reghao.tnb.content.app.geo.service.EarthService;
-import cn.reghao.tnb.content.app.geo.service.JobLocationService;
 import cn.reghao.tnb.content.app.geo.service.MapService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -29,19 +27,10 @@ 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, JobLocationService jobLocationService) {
+    public MapController(MapService mapService, EarthService earthService) {
         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")

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

@@ -1,17 +0,0 @@
-package cn.reghao.tnb.content.app.geo.db.mapper;
-
-import cn.reghao.jutil.jdk.db.BaseMapper;
-import cn.reghao.tnb.content.app.geo.model.po.JobLocation;
-import cn.reghao.tnb.content.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();
-}

+ 2 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/db/mapper/MallReplyMapper.java

@@ -12,6 +12,8 @@ import java.util.List;
  */
 @Mapper
 public interface MallReplyMapper extends BaseMapper<MallReply> {
+    void updateSetCup(String replyId, String cup);
+
     List<MallReply> findByItemType(int itemType);
     List<MallReply> findByItemId(String itemId);
     MallReply findByReplyId(String replyId);

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

@@ -1,39 +0,0 @@
-package cn.reghao.tnb.content.app.geo.model.po;
-
-import cn.reghao.jutil.jdk.db.BaseObject;
-import cn.reghao.tnb.content.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());
-    }
-}

+ 3 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/model/po/MallReply.java

@@ -5,6 +5,7 @@ import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
+import lombok.Setter;
 
 /**
  * @author reghao
@@ -12,6 +13,7 @@ import lombok.NoArgsConstructor;
  */
 @NoArgsConstructor
 @AllArgsConstructor
+@Setter
 @Getter
 public class MallReply extends BaseObject<Integer> {
     private Integer itemType;
@@ -20,6 +22,7 @@ public class MallReply extends BaseObject<Integer> {
     private String replyContent;
     private String appendContent;
     private String extra;
+    private String cup;
     private String username;
     private String avatarUrl;
 

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

@@ -1,40 +0,0 @@
-package cn.reghao.tnb.content.app.geo.service;
-
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.tnb.content.api.dto.geo.JobLoc;
-import cn.reghao.tnb.content.app.geo.db.mapper.JobLocationMapper;
-import cn.reghao.tnb.content.app.geo.model.po.JobLocation;
-import cn.reghao.tnb.content.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();
-    }
-}

+ 4 - 51
content/content-service/src/main/java/cn/reghao/tnb/content/app/geo/service/MapService.java

@@ -2,7 +2,6 @@ package cn.reghao.tnb.content.app.geo.service;
 
 import cn.reghao.file.api.iface.OssService;
 import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.tnb.common.db.SelectOption;
 import cn.reghao.tnb.content.api.dto.geo.MallReplyDto;
 import cn.reghao.tnb.content.api.dto.geo.MallReplyPhotoDto;
@@ -14,7 +13,6 @@ import cn.reghao.tnb.content.app.geo.model.po.MallReplyPhoto;
 import cn.reghao.tnb.content.app.geo.model.vo.MapMarker;
 import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
 import cn.reghao.tnb.content.app.geo.model.vo.MarkerInfo;
-import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.stereotype.Service;
@@ -40,23 +38,17 @@ public class MapService {
 
     private final MallReplyMapper mallReplyMapper;
     private final MallReplyPhotoMapper mallReplyPhotoMapper;
-    private final GeoScopeMapper geoScopeMapper;
     private final GeoItemMapper geoItemMapper;
     private final GeoPointMapper geoPointMapper;
     private final CameraPhotoMapper cameraPhotoMapper;
-    private JobLocationService jobLocationService;
 
     public MapService(MallReplyMapper mallReplyMapper, MallReplyPhotoMapper mallReplyPhotoMapper,
-                      GeoScopeMapper geoScopeMapper, GeoItemMapper geoItemMapper,
-                      GeoPointMapper geoPointMapper, CameraPhotoMapper cameraPhotoMapper,
-                      JobLocationService jobLocationService) {
+                      GeoItemMapper geoItemMapper, GeoPointMapper geoPointMapper, CameraPhotoMapper cameraPhotoMapper) {
         this.mallReplyMapper = mallReplyMapper;
         this.mallReplyPhotoMapper = mallReplyPhotoMapper;
-        this.geoScopeMapper = geoScopeMapper;
         this.geoItemMapper = geoItemMapper;
         this.geoPointMapper = geoPointMapper;
         this.cameraPhotoMapper = cameraPhotoMapper;
-        this.jobLocationService = jobLocationService;
     }
 
     public boolean checkReplyId(String replyId) {
@@ -120,7 +112,7 @@ public class MapService {
     }
 
     public List<MapMarker> getMapMarkers(int itemType) {
-        int pageSize = 1000;
+        int pageSize = 5000;
         if (itemType == 1) {
             List<MapMarker> list = mallReplyPhotoMapper.findAllByReplyIdGroup(pageSize);
             //List<MapMarker> list = mallReplyPhotoMapper.findAllByGeoScope(pageSize, geoScope.getId());
@@ -128,61 +120,22 @@ public class MapService {
         } else if (itemType == 2) {
             List<MapMarker> list = mallReplyPhotoMapper.findByWestChina(pageSize, itemType);
             //List<MapMarker> list = mallReplyPhotoMapper.findByGeoScope(pageSize, itemType, geoScope1);
-            setMarkTitle(list);
+            //setMarkTitle(list);
             return list;
         } else if (itemType == 3) {
-            List<MapMarker> list = mallReplyPhotoMapper.findByReplyIdGroup(pageSize, itemType);
-            return list;
-        } else if (itemType == 4) {
-            List<MapMarker> list = mallReplyPhotoMapper.findByReplyIdGroup(pageSize, itemType);
-            return list;
-        } else if (itemType == 5) {
             List<MapMarker> list = cameraPhotoMapper.findByWestGeoGroup(pageSize);
             return list;
-        } else if (itemType == 6) {
+        } else if (itemType == 4) {
             List<MapMarker> list = cameraPhotoMapper.findByAlbumId(pageSize, 0);
             list.forEach(mapMarker -> {
                 String objectId = mapMarker.getId();
             });
             return list;
-        } else if (itemType == 7) {
-            List<MapMarker> list = jobLocationService.getMapMarks();
-            return list;
         }
 
         return Collections.emptyList();
     }
 
-    private void setMarkTitle(List<MapMarker> list) {
-        list.forEach(mapMarker -> {
-            String title = mapMarker.getTitle();
-            if (title == null) {
-                mapMarker.setTitle("标记");
-                return;
-            }
-
-            mapMarker.setTitle(getFormattedTitle1(title));
-        });
-    }
-
-    private String getFormattedTitle1(String title) {
-        String extra1 = null;
-        if (title.startsWith("{")) {
-            JsonObject jsonObject = JsonConverter.jsonToJsonElement(title).getAsJsonObject();
-            extra1 = jsonObject.get("尺码").getAsString();
-        } else {
-            extra1 = title.split("尺码:")[1];
-            String[] arr = title.split("&nbsp;&nbsp");
-            for (String str : arr) {
-                if (str.startsWith("尺码")) {
-                    extra1 = str.split(":")[1];
-                    break;
-                }
-            }
-        }
-        return extra1;
-    }
-
     public MarkerInfo getMarkerInfo(String id) {
         MarkerInfo markerInfo;
         if (isInteger(id)) {

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

@@ -1,55 +0,0 @@
-<?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.content.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.content.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.content.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.content.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.content.app.geo.model.vo.MapMarker">
-        <result property="id" column="id"/>
-        <result property="title" column="company_name"/>
-        <association property="position" javaType="cn.reghao.tnb.content.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>

+ 6 - 1
content/content-service/src/main/resources/mapper/geo/MallReplyMapper.xml

@@ -9,10 +9,15 @@
         (#{id},#{deleted},#{createTime},#{updateTime},#{itemType},#{itemId},#{replyId},#{replyContent},#{appendContent},#{extra},#{username},#{avatarUrl})
     </insert>
 
+    <update id="updateSetCup">
+        update geo_mall_reply
+        set cup=#{cup}
+        where reply_id=#{replyId}
+    </update>
+
     <select id="findAll" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
         select *
         from geo_mall_reply
-        limit 1000
     </select>
     <select id="findByItemType" resultType="cn.reghao.tnb.content.app.geo.model.po.MallReply">
         select *

+ 5 - 5
content/content-service/src/main/resources/mapper/geo/MallReplyPhotoMapper.xml

@@ -40,14 +40,14 @@
 
     <resultMap id="mapMarker" type="cn.reghao.tnb.content.app.geo.model.vo.MapMarker">
         <result property="id" column="id"/>
-        <result property="title" column="extra"/>
+        <result property="title" column="cup"/>
         <association property="position" javaType="cn.reghao.tnb.content.app.geo.model.vo.MapPoint">
             <result property="lng" column="lng"/>
             <result property="lat" column="lat"/>
         </association>
     </resultMap>
     <select id="findAllByReplyIdGroup" resultMap="mapMarker">
-        select photo.id,photo.manufacturer as extra,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
+        select photo.id,photo.manufacturer as cup,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
         from geo_mall_reply_photo photo
         inner join geo_mall_reply reply
         on photo.reply_id=reply.reply_id
@@ -56,7 +56,7 @@
         limit #{pageSize}
     </select>
     <select id="findByReplyIdGroup" resultMap="mapMarker">
-        select photo.id,photo.manufacturer as extra,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
+        select photo.id,photo.manufacturer as cup,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
         from geo_mall_reply_photo photo
         inner join geo_mall_reply reply
         on photo.reply_id=reply.reply_id and x(photo.geo)>0.0000 and reply.item_type=#{itemType}
@@ -66,7 +66,7 @@
     </select>
     <!-- 根据中国东西南北位置返回 -->
     <select id="findByGeoScope" resultMap="mapMarker">
-        select photo.id,reply.username as extra,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
+        select photo.id,reply.username as cup,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
         from geo_mall_reply_photo photo
         inner join geo_mall_reply reply
         on photo.reply_id=reply.reply_id
@@ -79,7 +79,7 @@
     </select>
     <!-- 由西向东升序 -->
     <select id="findByWestChina" resultMap="mapMarker">
-        select photo.id,reply.extra,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
+        select photo.id,reply.cup,photo.photo_url,x(photo.geo) as lng,y(photo.geo) as lat
         from geo_mall_reply_photo photo
         inner join geo_mall_reply reply
         on photo.reply_id=reply.reply_id

+ 105 - 0
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/GeoTest.java

@@ -0,0 +1,105 @@
+package cn.reghao.tnb.content.app.vod.service;
+
+import cn.reghao.jutil.jdk.serializer.JsonConverter;
+import cn.reghao.tnb.content.app.ContentApplication;
+import cn.reghao.tnb.content.app.geo.db.mapper.MallReplyMapper;
+import cn.reghao.tnb.content.app.geo.model.po.MallReply;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2025-03-15 19:39:57
+ */
+@Slf4j
+@ActiveProfiles("dev")
+@SpringBootTest(classes = ContentApplication.class)
+@RunWith(SpringRunner.class)
+public class GeoTest {
+    @Autowired
+    MallReplyMapper mallReplyMapper;
+
+    @Test
+    public void test() {
+        List<MallReply> list = mallReplyMapper.findAll();
+        list.forEach(mallReply -> {
+            String extra = mallReply.getExtra();
+            String cup = getFormattedTitle1(extra);
+            if (cup != null) {
+                mallReply.setCup(cup);
+                mallReplyMapper.updateSetCup(mallReply.getReplyId(), cup);
+            }
+        });
+    }
+
+    String getFormattedTitle1(String title) {
+        String extra1 = null;
+        if (title.startsWith("{")) {
+            JsonObject jsonObject = JsonConverter.jsonToJsonElement(title).getAsJsonObject();
+            if (jsonObject.get("尺码") != null) {
+                extra1 = jsonObject.get("尺码").getAsString();
+                if (extra1.contains("码(建议")) {
+                    String[] arr = extra1.split(" ");
+                    extra1 = arr[arr.length-1].replace(")", "");
+                } else if (extra1.contains("[【")) {
+                    String[] arr = extra1.split("\\[【");
+                    if (arr.length == 1) {
+                        return null;
+                    }
+
+                    extra1 = arr[arr.length-1].replace("】]", "");
+                    System.out.println();
+                } else if (extra1.contains("(建议")) {
+                    String[] arr = extra1.split("斤 ");
+                    if (arr.length == 1) {
+                        arr = extra1.split("\\[\\(");
+                    }
+
+                    extra1 = arr[arr.length-1].replace(")", "");
+                } else if (extra1.contains("[(")) {
+                    String[] arr = extra1.split(" ");
+                    if (arr.length == 1) {
+                        arr = extra1.split("\\[\\(");
+                    }
+
+                    extra1 = arr[arr.length-1].replace(")]", "");
+                }
+            } else if (jsonObject.get("颜色分类") != null) {
+                extra1 = jsonObject.get("颜色分类").getAsString();
+                if (extra1.contains("2023新版-肤色")) {
+                    String[] arr = extra1.split(")");
+                    if (arr.length == 1) {
+                        return null;
+                    }
+
+                    extra1 = arr[arr.length-1];
+                } else if (extra1.contains("杯【")) {
+                    String[] arr = extra1.split("【");
+                    if (arr.length == 1) {
+                        arr = extra1.split("\\[\\(");
+                    }
+
+                    extra1 = arr[0].split(")")[1];
+                }
+            }
+        } else {
+            extra1 = title.split("尺码:")[1];
+            String[] arr = title.split("&nbsp;&nbsp");
+            for (String str : arr) {
+                if (str.startsWith("尺码")) {
+                    extra1 = str.split(":")[1];
+                    break;
+                }
+            }
+        }
+        return extra1;
+    }
+}