123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- 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);
- }
-
- 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());
-
-
-
- }
- }
|