PageRenderTime 18ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/lagou/Position.java

https://gitlab.com/scottqq/LagouClawer
Java | 272 lines | 248 code | 24 blank | 0 comment | 3 complexity | 98abcc94b8f21976420d31493b88ae38 MD5 | raw file
  1. package com.lagou;
  2. import org.apache.commons.lang.builder.ToStringBuilder;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONObject;
  8. public class Position
  9. {
  10. private static final Logger LOGGER = LoggerFactory.getLogger(Position.class);
  11. public static final String INSERT_SQL_HEADER = "INSERT INTO `position_data`(`position_id`,`position_name`,`company_id`,`company_short_name`,`position_first_type`,`industry_field`,`education`,`work_year`,`city`,`position_advantage`,`create_time`,`salary`,`salary_min`,`salary_max`,`leader_name`,`company_name`,`company_size`,`finance_stage`,`job_nature`,`position_type`,`company_label_list`,`created_ts`,`updated_ts`) VALUES ";
  12. private String positionId;
  13. private String positionName;
  14. private String companyId;
  15. private String companyShortName;
  16. private String positionFirstType;
  17. private String industryField;
  18. private String education;
  19. private String workYear;
  20. private String city;
  21. private String positionAdvantage;
  22. private String createTime;
  23. private String salary;
  24. private double salaryMin;
  25. private double salaryMax;
  26. private String leaderName;
  27. private String companyName;
  28. private String companySize;
  29. private String financeStage;
  30. private String jobNature;
  31. private String positionType;
  32. private String companyLabelList;
  33. public String toInsertSQL()
  34. {
  35. StringBuilder buf = new StringBuilder(INSERT_SQL_HEADER);
  36. buf.append(this.toInsertSQLValue());
  37. return buf.toString();
  38. }
  39. public String toInsertSQLHeader()
  40. {
  41. return INSERT_SQL_HEADER;
  42. }
  43. public String toInsertSQLValue()
  44. {
  45. StringBuilder buf = new StringBuilder();
  46. buf.append("('").append(this.positionId).append("','").append(this.positionName).append("','").append(this.companyId).append("','");
  47. buf.append(this.companyShortName).append("','").append(this.positionFirstType).append("','").append(this.industryField).append("','");
  48. buf.append(this.education).append("','").append(this.workYear).append("','").append(this.city).append("','").append(this.positionAdvantage).append("','");
  49. buf.append(this.createTime).append("','").append(this.salary).append("','").append(this.salaryMin).append("','").append(this.salaryMax).append("','").append(this.leaderName).append("','").append(this.companyName).append("','");
  50. buf.append(this.companySize).append("','").append(this.financeStage).append("','").append(this.jobNature).append("','").append(this.positionType).append("','");
  51. buf.append(this.companyLabelList).append("',now(),now())");
  52. return buf.toString();
  53. }
  54. @Override
  55. public String toString()
  56. {
  57. return ToStringBuilder.reflectionToString(this).toString();
  58. }
  59. public static Position create(String json)
  60. {
  61. Position position = new Position();
  62. JSONObject obj = JSON.parseObject(json);
  63. position.setPositionId(obj.getString("positionId"));
  64. position.setPositionName(obj.getString("positionName"));
  65. position.setCompanyId(obj.getString("companyId"));
  66. position.setCompanyShortName(obj.getString("companyShortName"));
  67. position.setPositionFirstType(obj.getString("positionFirstType"));
  68. position.setIndustryField(obj.getString("industryField"));
  69. position.setEducation(obj.getString("education"));
  70. position.setWorkYear(obj.getString("workYear"));
  71. position.setCity(obj.getString("city"));
  72. String strPositionAdvantage = obj.getString("positionAdvantage");
  73. strPositionAdvantage = strPositionAdvantage.replaceAll("\'", "''");
  74. position.setPositionAdvantage(strPositionAdvantage);
  75. position.setCreateTime(obj.getString("createTime"));
  76. String strSalary = obj.getString("salary");
  77. position.setSalary(strSalary);
  78. if(StringUtils.contains(strSalary, "以上"))
  79. {
  80. String strSalaryMin = StringUtils.replaceChars(strSalary, "以上", "");
  81. strSalaryMin = StringUtils.replaceChars(strSalaryMin, "k", "000");
  82. Double salaryMin = 0.0;
  83. try{ salaryMin = Double.parseDouble(strSalaryMin);} catch(Exception e) { LOGGER.error("error",e);}
  84. position.setSalaryMin(salaryMin);
  85. position.setSalaryMax(Double.MAX_VALUE);
  86. }
  87. if(StringUtils.contains(strSalary, "以下"))
  88. {
  89. String strSalaryMax = StringUtils.replaceChars(strSalary, "以下", "");
  90. strSalaryMax = StringUtils.replaceChars(strSalaryMax, "k", "000");
  91. Double salaryMax = Double.MAX_VALUE;
  92. try{ salaryMax = Double.parseDouble(strSalaryMax);} catch(Exception e) { LOGGER.error("error",e);}
  93. position.setSalaryMin(0.0);
  94. position.setSalaryMax(salaryMax);
  95. }
  96. if(StringUtils.contains(strSalary, "-"))
  97. {
  98. String[] array = StringUtils.split(strSalary, "-");
  99. String strSalaryMin = StringUtils.replace(array[0], "k", "000");;
  100. String strSalaryMax = StringUtils.replace(array[1], "k", "000");;
  101. Double salaryMin = 0.0;
  102. Double salaryMax = Double.MAX_VALUE;
  103. try{ salaryMin = Double.parseDouble(strSalaryMin);} catch(Exception e) { LOGGER.error("error",e);}
  104. try{ salaryMax = Double.parseDouble(strSalaryMax);} catch(Exception e) { LOGGER.error("error",e);}
  105. position.setSalaryMin(salaryMin);
  106. position.setSalaryMax(salaryMax);
  107. }
  108. position.setLeaderName(obj.getString("leaderName"));
  109. position.setCompanyName(obj.getString("companyName"));
  110. position.setCompanySize(obj.getString("companySize"));
  111. position.setFinanceStage(obj.getString("financeStage"));
  112. position.setJobNature(obj.getString("jobNature"));
  113. position.setPositionType(obj.getString("positionType"));
  114. String strCompanyLabelList = obj.getString("companyLabelList");
  115. strCompanyLabelList = strCompanyLabelList.replaceAll("\\[", "");
  116. strCompanyLabelList = strCompanyLabelList.replaceAll("\\]", "");
  117. strCompanyLabelList = strCompanyLabelList.replaceAll("\"", "");
  118. strCompanyLabelList = strCompanyLabelList.replaceAll(",", "|");
  119. position.setCompanyLabelList(strCompanyLabelList);
  120. return position;
  121. }
  122. public String getPositionId() {
  123. return positionId;
  124. }
  125. public void setPositionId(String positionId) {
  126. this.positionId = positionId;
  127. }
  128. public String getPositionName() {
  129. return positionName;
  130. }
  131. public void setPositionName(String positionName) {
  132. this.positionName = positionName;
  133. }
  134. public String getCompanyId() {
  135. return companyId;
  136. }
  137. public void setCompanyId(String companyId) {
  138. this.companyId = companyId;
  139. }
  140. public String getCompanyShortName() {
  141. return companyShortName;
  142. }
  143. public void setCompanyShortName(String companyShortName) {
  144. this.companyShortName = companyShortName;
  145. }
  146. public String getPositionFirstType() {
  147. return positionFirstType;
  148. }
  149. public void setPositionFirstType(String positionFirstType) {
  150. this.positionFirstType = positionFirstType;
  151. }
  152. public String getIndustryField() {
  153. return industryField;
  154. }
  155. public void setIndustryField(String industryField) {
  156. this.industryField = industryField;
  157. }
  158. public String getEducation() {
  159. return education;
  160. }
  161. public void setEducation(String education) {
  162. this.education = education;
  163. }
  164. public String getWorkYear() {
  165. return workYear;
  166. }
  167. public void setWorkYear(String workYear) {
  168. this.workYear = workYear;
  169. }
  170. public String getCity() {
  171. return city;
  172. }
  173. public void setCity(String city) {
  174. this.city = city;
  175. }
  176. public String getPositionAdvantage() {
  177. return positionAdvantage;
  178. }
  179. public void setPositionAdvantage(String positionAdvantage) {
  180. this.positionAdvantage = positionAdvantage;
  181. }
  182. public String getCreateTime() {
  183. return createTime;
  184. }
  185. public void setCreateTime(String createTime) {
  186. this.createTime = createTime;
  187. }
  188. public String getSalary() {
  189. return salary;
  190. }
  191. public void setSalary(String salary) {
  192. this.salary = salary;
  193. }
  194. public String getLeaderName() {
  195. return leaderName;
  196. }
  197. public void setLeaderName(String leaderName) {
  198. this.leaderName = leaderName;
  199. }
  200. public String getCompanyName() {
  201. return companyName;
  202. }
  203. public void setCompanyName(String companyName) {
  204. this.companyName = companyName;
  205. }
  206. public String getCompanySize() {
  207. return companySize;
  208. }
  209. public void setCompanySize(String companySize) {
  210. this.companySize = companySize;
  211. }
  212. public String getFinanceStage() {
  213. return financeStage;
  214. }
  215. public void setFinanceStage(String financeStage) {
  216. this.financeStage = financeStage;
  217. }
  218. public String getJobNature() {
  219. return jobNature;
  220. }
  221. public void setJobNature(String jobNature) {
  222. this.jobNature = jobNature;
  223. }
  224. public String getPositionType() {
  225. return positionType;
  226. }
  227. public void setPositionType(String positionType) {
  228. this.positionType = positionType;
  229. }
  230. public String getCompanyLabelList() {
  231. return companyLabelList;
  232. }
  233. public void setCompanyLabelList(String companyLabelList) {
  234. this.companyLabelList = companyLabelList;
  235. }
  236. public double getSalaryMin() {
  237. return salaryMin;
  238. }
  239. public void setSalaryMin(double salaryMin) {
  240. this.salaryMin = salaryMin;
  241. }
  242. public double getSalaryMax() {
  243. return salaryMax;
  244. }
  245. public void setSalaryMax(double salaryMax) {
  246. this.salaryMax = salaryMax;
  247. }
  248. }