ProjectServiceImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.up.sell.service.impl;
  2. import java.util.Date;
  3. import java.util.Objects;
  4. import java.util.regex.Pattern;
  5. import java.util.stream.Collectors;
  6. import java.util.stream.Stream;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Primary;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.up.sell.mapper.AreasMapper;
  14. import com.up.sell.mapper.ProjectBusinessMapper;
  15. import com.up.sell.mapper.ProjectMapper;
  16. import com.up.sell.mapper.ProjectPictureMapper;
  17. import com.up.sell.mapper.ProjectTagMapper;
  18. import com.up.sell.service.IProjectService;
  19. import com.up.sell.vo.Project;
  20. import com.up.sell.vo.ProjectPicture;
  21. @Service("ProjectServiceImpl")
  22. @Primary
  23. public class ProjectServiceImpl implements IProjectService {
  24. @Autowired
  25. ProjectMapper projectMapper;
  26. @Autowired
  27. AreasMapper areasMapper;
  28. @Autowired
  29. ProjectTagMapper projectTagMapper;
  30. @Autowired
  31. ProjectPictureMapper projectPictureMapper;
  32. @Autowired
  33. ProjectBusinessMapper projectBusinessMapper;
  34. public void crawlerProject(String json) {
  35. JSONObject jsonObject = JSON.parseObject(json);
  36. Project project = new Project();
  37. project.setProjectName(jsonObject.getString("project_name"));
  38. project.setPrice(jsonObject.getString("shop_rent_price"));
  39. if(isInteger(jsonObject.getString("shop_rent_price"))) {
  40. project.setPriceType("1"); //数字
  41. }else {
  42. project.setPriceType("2"); //文本
  43. }
  44. String zx = jsonObject.getString("decoration");
  45. System.out.println("zx : "+zx);
  46. if(zx != null) {
  47. int pzx = 1;
  48. if(zx.contains("毛坯")) {
  49. pzx = 1;
  50. }else if(zx.contains("简装")) {
  51. pzx = 2;
  52. }else if(zx.contains("中等")) {
  53. pzx = 3;
  54. }else if(zx.contains("精装")) {
  55. pzx = 4;
  56. }else if(zx.contains("豪华")) {
  57. pzx = 5;
  58. }
  59. project.setDecoration(pzx);
  60. }
  61. project.setAcreage(Double.valueOf(jsonObject.getString("acreage")));
  62. //区域
  63. String areas = jsonObject.getString("project_district_id");
  64. String destrictId = "411302";
  65. if("宛城区".equals(areas)) {
  66. destrictId = "411302";
  67. }else if("卧龙区".equals(areas)){
  68. destrictId = "411303";
  69. }else if("南召县".equals(areas)){
  70. destrictId = "411321";
  71. }else if("方城县".equals(areas)){
  72. destrictId = "411322";
  73. }else if("西陕县".equals(areas)){
  74. destrictId = "411323";
  75. }else {
  76. destrictId = "411323";
  77. }
  78. project.setProjectDistrictId(destrictId);
  79. project.setProjectAddress(jsonObject.getString("project_address"));
  80. if(jsonObject.get("shop_image_list") != null) {
  81. //String[] bannerImgs = jsonObject.get("shop_image_list").toString().split(",");
  82. String[] imgArray = jsonObject.getJSONArray("shop_image_list").toArray(new String[]{});
  83. System.out.println("imgArray : "+imgArray);
  84. //String bannerImgs = Stream.of(imgArray).collect(Collectors.joining(","));
  85. project.setBannerImgs(imgArray);
  86. }
  87. project.setDescription(jsonObject.getString("shop_introduce"));
  88. project.setProvinceId("410000");
  89. project.setProjectProvinceId("410000");
  90. project.setCityId("411300");
  91. project.setProjectCityId("411300");
  92. project.setProjectStatus(1); //下架
  93. project.setProjectType(Integer.valueOf(jsonObject.getString("project_type"))); //招商
  94. project.setHouseType(Integer.valueOf(jsonObject.getString("house_type")));
  95. project.setFavoriteCount(100);
  96. project.setViewCount(0);
  97. project.setBusinessType(1);
  98. project.setCreateTime(new Date());
  99. project.setUpdateTime(new Date());
  100. //保存项目
  101. edit(project);
  102. }
  103. @Override
  104. @Transactional(rollbackFor = Exception.class)
  105. public int edit(Project project) {
  106. project.setCreateUser(1);
  107. project.setCreateTime(new Date());
  108. project.setProvinceId("410000");
  109. projectMapper.insertSelective(project);
  110. Long projectId = project.getId();
  111. if (Objects.nonNull(project.getBannerImgs())) {
  112. Stream.of(project.getBannerImgs()).forEach(img -> {
  113. img = img.replace("http://up-sell.oss-cn-beijing.aliyuncs.com", "");
  114. projectPictureMapper.insertSelective(ProjectPicture.ofBanner(projectId, img, 1));
  115. });
  116. }
  117. return 1;
  118. }
  119. @Override
  120. public Project getPorject(Long id) {
  121. return projectMapper.selectByPrimaryKey(id);
  122. }
  123. public static boolean isInteger(String str) {
  124. String reg = "^[0-9]+(.[0-9]+)?$";
  125. Pattern pattern = Pattern.compile(reg);
  126. return pattern.matcher(str).matches();
  127. }
  128. public static void main(String[] args) {
  129. String str = "";
  130. //"^[-\\+]?[\\d]*$"
  131. String reg = "^[0-9]+(.[0-9]+)?$";
  132. Pattern pattern = Pattern.compile(reg);
  133. System.out.println(pattern.matcher(str).matches());
  134. }
  135. }