Browse Source

1、新增写字楼爬虫模块2、新增mls系统爬虫模块

liutielin 3 years ago
parent
commit
f038568834

+ 28 - 0
src/main/java/com/up/sell/controller/Api58sy.java

@@ -0,0 +1,28 @@
+package com.up.sell.controller;
+
+import javax.servlet.http.HttpServletRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.up.sell.service.IProjectService;
+
+@RestController
+@RequestMapping("Api58czNew")
+public class Api58sy {
+	
+	@Autowired
+	 IProjectService projectService;
+	
+	 @PostMapping("/webhook")
+	 public String Webhook(HttpServletRequest request) {
+		 System.out.println("webhook run...");
+		// 爬取的数据
+	      String data = request.getParameter("data");
+	      String data_key = request.getParameter("data_key");
+		 projectService.crawlerProject(data);
+		 return data_key;
+	 }
+
+}

+ 117 - 0
src/main/java/com/up/sell/service/IProjectService.java

@@ -0,0 +1,117 @@
+package com.up.sell.service;
+
+import java.text.ParseException;
+
+import com.up.sell.vo.Project;
+
+
+/**
+ * 
+ * 项目服务
+ * 
+ * @author j.x.j
+ *
+ */
+public interface IProjectService {
+
+	void crawlerProject(String data);
+	/**
+	 * 编辑项目
+	 * 
+	 * @param project
+	 * @return
+	 * @throws ParseException
+	 */
+	int edit(Project project);
+	
+	/**
+	 * 删除项目
+	 * 
+	 * @param projectId
+	 *            项目标识
+	 * @return
+	 */
+//	int deleteById(Long projectId);
+
+	/**
+	 * 删除多个项目
+	 * 
+	 * @param projectIds
+	 * @return
+	 */
+//	int deleteByIds(String projectIds);
+
+	/**
+	 * 条件查询项目列表
+	 * 
+	 * @param project
+	 *            查询项目条件对象
+	 * @return
+	 */
+//	List<Project> selectListByProject(Project project);
+
+	
+
+	/**
+	 * 获得项目信息
+	 * 
+	 * @param id
+	 *            项目标识
+	 * @return
+	 */
+	Project getPorject(Long id);
+
+	/**
+	 * 
+	 * @param projectId
+	 * @return
+	 */
+//	List<ProjectTag> getProjectTags(Long projectId);
+
+	/**
+	 * 
+	 * @param projectId
+	 * @return
+	 */
+	//List<ProjectAcreage> getProjectAcreages(Long projectId);
+
+	/**
+	 * 
+	 * @param projectId
+	 * @return
+	 */
+	//List<ProjectBusiness> getProjectBusiness(Long projectId);
+
+	/**
+	 * 
+	 * @param ProjectId
+	 * @return
+	 */
+	//List<ProjectPicture> getProjectPictures(Long ProjectId);
+
+	/**
+	 * 项目经理人添加项目
+	 * 
+	 * @return
+	 */
+//	List<Project> selectProject();
+//
+//	int updateSetLeader(Integer id, Long[] sum);
+
+	/**
+	 * 查找项目经理人项目
+	 * 
+	 * @param id
+	 * @return
+	 */
+//	List<Project> selectByProject(Integer id);
+
+	//未分配的招商项目
+//	List<Project> selectAttractProject(Long userId);
+	
+	//未分配的销售项目
+//	List<Project> selectSaleProject(Long userId);
+
+//	Project selectProjectId(String projectId);
+
+}

+ 158 - 0
src/main/java/com/up/sell/service/impl/ProjectServiceForMlsImpl.java

@@ -0,0 +1,158 @@
+package com.up.sell.service.impl;
+
+import java.util.Date;
+import java.util.Objects;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.up.sell.mapper.AreasMapper;
+import com.up.sell.mapper.ProjectBusinessMapper;
+import com.up.sell.mapper.ProjectMapper;
+import com.up.sell.mapper.ProjectPictureMapper;
+import com.up.sell.mapper.ProjectTagMapper;
+import com.up.sell.service.IProjectService;
+import com.up.sell.vo.Project;
+import com.up.sell.vo.ProjectPicture;
+
+
+@Service("ProjectServiceForMlsImpl")
+public class ProjectServiceForMlsImpl implements IProjectService {
+
+	@Autowired
+	ProjectMapper projectMapper;
+	@Autowired
+	AreasMapper areasMapper;
+	@Autowired
+	ProjectTagMapper projectTagMapper;
+	@Autowired
+	ProjectPictureMapper projectPictureMapper;
+	@Autowired
+	ProjectBusinessMapper projectBusinessMapper;
+
+	public void crawlerProject(String json) {
+		JSONObject jsonObject = JSON.parseObject(json);
+		Project project = new Project();
+		
+		project.setProjectName(jsonObject.getString("project_name"));
+		project.setPrice(jsonObject.getString("shop_rent_price"));
+		if(isInteger(jsonObject.getString("shop_rent_price"))) {
+			project.setPriceType("1"); //数字
+		}else {
+			project.setPriceType("2"); //文本
+		}
+		String zx = jsonObject.getString("decoration");
+		System.out.println("zx : "+zx);
+		if(zx != null) {
+			int pzx = 1;
+			if(zx.contains("毛坯")) {
+				pzx = 1;
+			}else if(zx.contains("简装")) {
+				pzx = 2;
+			}else if(zx.contains("中等")) {
+				pzx = 3;
+			}else if(zx.contains("精装")) {
+				pzx = 4;
+			}else if(zx.contains("豪华")) {
+				pzx = 5;
+			}
+			project.setDecoration(pzx);
+		}
+//		else {
+//			project.setDecoration(1);
+//		}
+		
+		project.setAcreage(Double.valueOf(jsonObject.getString("acreage")));
+		//区域
+		String areas = jsonObject.getString("project_district_id");
+		String destrictId = "411302";
+		if("宛城区".equals(areas)) {
+			destrictId = "411302";
+		}else if("卧龙区".equals(areas)){
+			destrictId = "411303";
+		}else if("南召县".equals(areas)){
+			destrictId = "411321";
+		}else if("方城县".equals(areas)){
+			destrictId = "411322";
+		}else if("西陕县".equals(areas)){
+			destrictId = "411323";
+		}else {
+			destrictId = "411323";
+		}
+		project.setProjectDistrictId(destrictId);
+		
+		project.setProjectAddress(jsonObject.getString("project_address"));
+		if(jsonObject.get("shop_image_list") != null) {
+			//String[] bannerImgs = jsonObject.get("shop_image_list").toString().split(",");
+			String[] imgArray = jsonObject.getJSONArray("shop_image_list").toArray(new String[]{});
+            System.out.println("imgArray : "+imgArray);
+			//String bannerImgs = Stream.of(imgArray).collect(Collectors.joining(","));
+			project.setBannerImgs(imgArray);
+		}
+		project.setDescription(jsonObject.getString("shop_introduce"));
+		project.setProvinceId("410000");
+		project.setProjectProvinceId("410000");
+		project.setCityId("411300");
+		project.setProjectCityId("411300");
+		
+		
+		project.setProjectStatus(1); //下架
+		project.setProjectType(Integer.valueOf(jsonObject.getString("project_type"))); //招商
+		project.setHouseType(Integer.valueOf(jsonObject.getString("house_type")));
+		project.setFavoriteCount(100);
+		project.setViewCount(0);
+		project.setBusinessType(1);
+		project.setCreateTime(new Date());
+		project.setUpdateTime(new Date());
+		//保存项目
+		edit(project);
+	}
+
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public int edit(Project project) {
+
+		project.setCreateUser(1);
+		project.setCreateTime(new Date());
+		project.setProvinceId("410000");
+		projectMapper.insertSelective(project);
+		
+		Long projectId = project.getId();
+		if (Objects.nonNull(project.getBannerImgs())) {
+			Stream.of(project.getBannerImgs()).forEach(img -> {
+				img = img.replace("http://up-sell.oss-cn-beijing.aliyuncs.com", "");
+				projectPictureMapper.insertSelective(ProjectPicture.ofBanner(projectId, img, 1));
+			});
+		}
+		return 1;
+	}
+
+	@Override
+	public Project getPorject(Long id) {
+		return projectMapper.selectByPrimaryKey(id);
+	}
+	
+	public static boolean isInteger(String str) {
+		String reg = "^[0-9]+(.[0-9]+)?$";
+        Pattern pattern = Pattern.compile(reg);  
+        return pattern.matcher(str).matches();  
+	}
+
+	public static void main(String[] args) {
+		 String str = "";
+			//"^[-\\+]?[\\d]*$"
+		 String reg = "^[0-9]+(.[0-9]+)?$";
+		 Pattern pattern = Pattern.compile(reg);  
+	     System.out.println(pattern.matcher(str).matches());  
+	        
+	        
+		
+	}
+
+}

+ 161 - 0
src/main/java/com/up/sell/service/impl/ProjectServiceImpl.java

@@ -0,0 +1,161 @@
+package com.up.sell.service.impl;
+
+import java.util.Date;
+import java.util.Objects;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.up.sell.mapper.AreasMapper;
+import com.up.sell.mapper.ProjectBusinessMapper;
+import com.up.sell.mapper.ProjectMapper;
+import com.up.sell.mapper.ProjectPictureMapper;
+import com.up.sell.mapper.ProjectTagMapper;
+import com.up.sell.service.IProjectService;
+import com.up.sell.vo.Project;
+import com.up.sell.vo.ProjectPicture;
+
+
+@Service("ProjectServiceImpl")
+@Primary
+public class ProjectServiceImpl implements IProjectService {
+
+	@Autowired
+	ProjectMapper projectMapper;
+	@Autowired
+	AreasMapper areasMapper;
+	@Autowired
+	ProjectTagMapper projectTagMapper;
+	@Autowired
+	ProjectPictureMapper projectPictureMapper;
+	@Autowired
+	ProjectBusinessMapper projectBusinessMapper;
+
+	public void crawlerProject(String json) {
+		JSONObject jsonObject = JSON.parseObject(json);
+		Project project = new Project();
+		
+		project.setProjectName(jsonObject.getString("project_name"));
+		project.setPrice(jsonObject.getString("shop_rent_price"));
+		if(isInteger(jsonObject.getString("shop_rent_price"))) {
+			project.setPriceType("1"); //数字
+		}else {
+			project.setPriceType("2"); //文本
+		}
+		String zx = jsonObject.getString("decoration");
+		System.out.println("zx : "+zx);
+		if(zx != null) {
+			int pzx = 1;
+			if(zx.contains("毛坯")) {
+				pzx = 1;
+			}else if(zx.contains("简装")) {
+				pzx = 2;
+			}else if(zx.contains("中等")) {
+				pzx = 3;
+			}else if(zx.contains("精装")) {
+				pzx = 4;
+			}else if(zx.contains("豪华")) {
+				pzx = 5;
+			}
+			project.setDecoration(pzx);
+		}
+//		else {
+//			project.setDecoration(1);
+//		}
+		
+		project.setAcreage(Double.valueOf(jsonObject.getString("acreage")));
+		//区域
+		String areas = jsonObject.getString("project_district_id");
+		String destrictId = "411302";
+		if("宛城区".equals(areas)) {
+			destrictId = "411302";
+		}else if("卧龙区".equals(areas)){
+			destrictId = "411303";
+		}else if("南召县".equals(areas)){
+			destrictId = "411321";
+		}else if("方城县".equals(areas)){
+			destrictId = "411322";
+		}else if("西陕县".equals(areas)){
+			destrictId = "411323";
+		}else {
+			destrictId = "411323";
+		}
+		project.setProjectDistrictId(destrictId);
+		
+		project.setProjectAddress(jsonObject.getString("project_address"));
+		if(jsonObject.get("shop_image_list") != null) {
+			//String[] bannerImgs = jsonObject.get("shop_image_list").toString().split(",");
+			String[] imgArray = jsonObject.getJSONArray("shop_image_list").toArray(new String[]{});
+            System.out.println("imgArray : "+imgArray);
+			//String bannerImgs = Stream.of(imgArray).collect(Collectors.joining(","));
+			project.setBannerImgs(imgArray);
+		}
+		project.setDescription(jsonObject.getString("shop_introduce"));
+		project.setProvinceId("410000");
+		project.setProjectProvinceId("410000");
+		project.setCityId("411300");
+		project.setProjectCityId("411300");
+		
+		
+		project.setProjectStatus(1); //下架
+		project.setProjectType(Integer.valueOf(jsonObject.getString("project_type"))); //招商
+		project.setHouseType(Integer.valueOf(jsonObject.getString("house_type")));
+		project.setFavoriteCount(100);
+		project.setViewCount(0);
+		project.setBusinessType(1);
+		project.setCreateTime(new Date());
+		project.setUpdateTime(new Date());
+		//保存项目
+		edit(project);
+	}
+
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public int edit(Project project) {
+
+		project.setCreateUser(1);
+		project.setCreateTime(new Date());
+		project.setProvinceId("410000");
+		projectMapper.insertSelective(project);
+		
+		Long projectId = project.getId();
+		if (Objects.nonNull(project.getBannerImgs())) {
+			Stream.of(project.getBannerImgs()).forEach(img -> {
+				img = img.replace("http://up-sell.oss-cn-beijing.aliyuncs.com", "");
+				projectPictureMapper.insertSelective(ProjectPicture.ofBanner(projectId, img, 1));
+			});
+		}
+		return 1;
+	}
+
+	@Override
+	public Project getPorject(Long id) {
+		return projectMapper.selectByPrimaryKey(id);
+	}
+	
+	public static boolean isInteger(String str) {
+		String reg = "^[0-9]+(.[0-9]+)?$";
+        Pattern pattern = Pattern.compile(reg);  
+        return pattern.matcher(str).matches();  
+	}
+
+	public static void main(String[] args) {
+		 String str = "";
+			//"^[-\\+]?[\\d]*$"
+		 String reg = "^[0-9]+(.[0-9]+)?$";
+		 Pattern pattern = Pattern.compile(reg);  
+	     System.out.println(pattern.matcher(str).matches());  
+	        
+	        
+		
+	}
+
+}

+ 41 - 5
src/main/java/com/up/sell/vo/Project.java

@@ -27,6 +27,8 @@ public class Project {
      * 累计关注数量;商业、办公产业、办公产业、住宅
      */
     private Integer favoriteCount;
+    
+    private Integer viewCount;
 
     /**
      * 佣金:销售/招商佣金;商业、办公产业、住宅
@@ -91,7 +93,7 @@ public class Project {
     /**
      * 价格、单位:元/㎡ or 元/天/㎡;商业、办公产业、住宅
      */
-    private Double price;
+    private String price;
 
     /**
      * 建筑面积,单位㎡;商业、办公产业、住宅
@@ -272,8 +274,40 @@ public class Project {
      * 最后更新时间
      */
     private Date updateTime;
-
-    /**
+    
+    private String priceType;
+    
+    
+    
+    public String getPriceType() {
+		return priceType;
+	}
+
+	public void setPriceType(String priceType) {
+		this.priceType = priceType;
+	}
+
+	/** 图片banner **/
+	private String[] bannerImgs;
+
+    public String[] getBannerImgs() {
+		return bannerImgs;
+	}
+
+	public void setBannerImgs(String[] bannerImgs) {
+		this.bannerImgs = bannerImgs;
+	}
+
+	
+	public Integer getViewCount() {
+		return viewCount;
+	}
+
+	public void setViewCount(Integer viewCount) {
+		this.viewCount = viewCount;
+	}
+
+	/**
      * 
      * @return id 
      */
@@ -549,7 +583,7 @@ public class Project {
      * 价格、单位:元/㎡ or 元/天/㎡;商业、办公产业、住宅
      * @return price 价格、单位:元/㎡ or 元/天/㎡;商业、办公产业、住宅
      */
-    public Double getPrice() {
+    public String getPrice() {
         return price;
     }
 
@@ -557,7 +591,7 @@ public class Project {
      * 价格、单位:元/㎡ or 元/天/㎡;商业、办公产业、住宅
      * @param price 价格、单位:元/㎡ or 元/天/㎡;商业、办公产业、住宅
      */
-    public void setPrice(Double price) {
+    public void setPrice(String price) {
         this.price = price;
     }
 
@@ -1136,4 +1170,6 @@ public class Project {
     public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
+    
+    
 }

+ 53 - 4
src/main/java/com/up/sell/vo/ProjectPicture.java

@@ -2,6 +2,7 @@ package com.up.sell.vo;
 
 import java.util.Date;
 
+
 public class ProjectPicture {
     /**
      * 
@@ -11,7 +12,12 @@ public class ProjectPicture {
     /**
      * 项目ID
      */
-    private Integer projectId;
+    private Long projectId;
+    
+    /**
+	 * 图片类型:字典表112
+	 */
+	private Integer picType;
 
     /**
      * 图片排序,同一个业务多张图片可以排序
@@ -52,8 +58,19 @@ public class ProjectPicture {
      * 最后更新时间
      */
     private Date updateTime;
+    
+    private String defaultPic;
+    
 
-    /**
+    public String getDefaultPic() {
+		return defaultPic;
+	}
+
+	public void setDefaultPic(String defaultPic) {
+		this.defaultPic = defaultPic;
+	}
+
+	/**
      * 
      * @return id 
      */
@@ -73,7 +90,7 @@ public class ProjectPicture {
      * 项目ID
      * @return project_id 项目ID
      */
-    public Integer getProjectId() {
+    public Long getProjectId() {
         return projectId;
     }
 
@@ -81,7 +98,7 @@ public class ProjectPicture {
      * 项目ID
      * @param projectId 项目ID
      */
-    public void setProjectId(Integer projectId) {
+    public void setProjectId(Long projectId) {
         this.projectId = projectId;
     }
 
@@ -212,4 +229,36 @@ public class ProjectPicture {
     public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
+    
+    public Integer getPicType() {
+		return picType;
+	}
+
+	public void setPicType(Integer picType) {
+		this.picType = picType;
+	}
+
+	/**
+	 * 展示图片
+	 * 
+	 * @param projectId
+	 * @param picType
+	 * @param picPath
+	 * @param description
+	 * @param sort
+	 * @return
+	 */
+	public static ProjectPicture ofBanner(Long projectId, String picPath, int sort) {
+		ProjectPicture projectPicture = new ProjectPicture();
+		projectPicture.setCreateUser(1);
+		projectPicture.setCreateTime(new Date());
+		projectPicture.setUpdateUser(1);
+		projectPicture.setUpdateTime(new Date());
+		projectPicture.setProjectId(projectId);
+		projectPicture.setPicType(1);
+		projectPicture.setPicPath(picPath);
+		projectPicture.setSort(sort);
+		projectPicture.setDefaultPic("0");
+		return projectPicture;
+	}
 }

+ 8 - 1
src/main/resources/configs/mybatis/xml/ProjectMapper.xml

@@ -116,7 +116,8 @@
       #{households,jdbcType=INTEGER}, #{createUser,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
       #{updateUser,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP})
   </insert>
-  <insert id="insertSelective" parameterType="com.up.sell.vo.Project">
+  <insert id="insertSelective" parameterType="com.up.sell.vo.Project"
+  	useGeneratedKeys="true" keyProperty="id">
     insert into project
     <trim prefix="(" suffix=")" suffixOverrides=",">
       <if test="id != null">
@@ -170,6 +171,9 @@
       <if test="lat != null">
         lat,
       </if>
+      <if test="priceType != null">
+        price_type,
+      </if>
       <if test="price != null">
         price,
       </if>
@@ -334,6 +338,9 @@
       <if test="lat != null">
         #{lat,jdbcType=DOUBLE},
       </if>
+      <if test="priceType != null">
+        #{priceType,jdbcType=VARCHAR},
+      </if>
       <if test="price != null">
         #{price,jdbcType=DOUBLE},
       </if>

+ 15 - 16
src/main/resources/configs/mybatis/xml/ProjectPictureMapper.xml

@@ -28,14 +28,12 @@
     where id = #{id,jdbcType=INTEGER}
   </delete>
   <insert id="insert" parameterType="com.up.sell.vo.ProjectPicture">
-    insert into project_picture (id, project_id, sort, 
+    insert into project_picture (id, pic_type, project_id, sort, 
       pic_path, description, price, 
-      create_user, create_time, update_user, 
-      update_time)
-    values (#{id,jdbcType=INTEGER}, #{projectId,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, 
+      create_user, create_time, default_pic)
+    values (#{id,jdbcType=INTEGER},#{picType,jdbcType=INTEGER}, #{projectId,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, 
       #{picPath,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{price,jdbcType=DOUBLE}, 
-      #{createUser,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=INTEGER}, 
-      #{updateTime,jdbcType=TIMESTAMP})
+      #{createUser,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{defaultPic,jdbcType=VARCHAR})
   </insert>
   <insert id="insertSelective" parameterType="com.up.sell.vo.ProjectPicture">
     insert into project_picture
@@ -43,6 +41,9 @@
       <if test="id != null">
         id,
       </if>
+      <if test="picType != null">
+        pic_type,
+      </if>
       <if test="projectId != null">
         project_id,
       </if>
@@ -64,17 +65,17 @@
       <if test="createTime != null">
         create_time,
       </if>
-      <if test="updateUser != null">
-        update_user,
-      </if>
-      <if test="updateTime != null">
-        update_time,
+      <if test="defaultPic != null">
+        default_pic,
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="id != null">
         #{id,jdbcType=INTEGER},
       </if>
+      <if test="picType != null">
+        #{picType,jdbcType=INTEGER},
+      </if>
       <if test="projectId != null">
         #{projectId,jdbcType=INTEGER},
       </if>
@@ -96,12 +97,10 @@
       <if test="createTime != null">
         #{createTime,jdbcType=TIMESTAMP},
       </if>
-      <if test="updateUser != null">
-        #{updateUser,jdbcType=INTEGER},
-      </if>
-      <if test="updateTime != null">
-        #{updateTime,jdbcType=TIMESTAMP},
+       <if test="defaultPic != null">
+        #{defaultPic,jdbcType=VARCHAR},
       </if>
+      
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.up.sell.vo.ProjectPicture">