|
@@ -0,0 +1,628 @@
|
|
|
+package spider;
|
|
|
+
|
|
|
+import cn.hutool.db.DbUtil;
|
|
|
+import cn.hutool.db.Entity;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.mingxue.spider.helper.StringUtils;
|
|
|
+import com.mingxue.spider.utils.HttpUtils;
|
|
|
+import com.mingxue.spider.utils.UsignUtils;
|
|
|
+import org.junit.Test;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 优志愿
|
|
|
+ * 1、获取职业列表数据;
|
|
|
+ * https://www.youzy.cn/tzy/search/vocationalLibrary/homepage
|
|
|
+ * 2、详情数据(职业概况、就业岗位);
|
|
|
+ */
|
|
|
+public class YouZy {
|
|
|
+ private static Logger log = LoggerFactory.getLogger(YouZy.class);
|
|
|
+
|
|
|
+ private static final String host = "https://uwf7de983aad7a717eb.youzy.cn";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test() throws Exception {
|
|
|
+// processVocationalHotAndLack();
|
|
|
+// getVocationalList();
|
|
|
+// getCareerProspects("010101","c29e43498afdfe626ea17818b86fec4b");
|
|
|
+
|
|
|
+
|
|
|
+ //eduLevel:"ben","zhuan"
|
|
|
+// List<String> majorList = getMajor(3, "ben,zhuan");
|
|
|
+// System.out.println(JSONObject.toJSONString(majorList));
|
|
|
+ List<String> majorList = getMajor(3, "ben,zhuan");
|
|
|
+ System.out.println(majorList.size());
|
|
|
+
|
|
|
+// majorList = getMajor(3, "zhuan");
|
|
|
+// System.out.println(majorList.size());
|
|
|
+
|
|
|
+ for (String majorCode : majorList) {
|
|
|
+// if(majorCode.compareTo("130503")<=-1){
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+
|
|
|
+ getCareerProspects(majorCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param majorLevel =1 2 3级专业
|
|
|
+ * @param eduLevels(教育水平):"ben","zhuan"
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getMajor(Integer majorLevel, String eduLevels) {
|
|
|
+ List<String> majorList = new LinkedList<>();
|
|
|
+ for (String eduLevel : eduLevels.split(",")) {
|
|
|
+ String path = "/youzy.dms.basiclib.api.major.tree.query";
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("eduLevel", eduLevel);
|
|
|
+
|
|
|
+ String result = getResult(path, map);
|
|
|
+ if (StringUtils.isEmpty(result)) {
|
|
|
+ return majorList;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray resultArray = JSONObject.parseArray(result);
|
|
|
+ resultArray.stream().forEach(major1 -> {
|
|
|
+ JSONObject major1Obj = (JSONObject) major1;
|
|
|
+ String code1 = major1Obj.getString("code");
|
|
|
+ String name1 = major1Obj.getString("name");
|
|
|
+ if (majorLevel == 1) {
|
|
|
+ majorList.add(code1);
|
|
|
+ } else {
|
|
|
+ JSONArray major2Array = major1Obj.getJSONArray("majors");
|
|
|
+ major2Array.stream().forEach(major2 -> {
|
|
|
+ JSONObject major2Obj = (JSONObject) major2;
|
|
|
+ String code2 = major2Obj.getString("code");
|
|
|
+ String name2 = major2Obj.getString("name");
|
|
|
+ if (majorLevel == 2) {
|
|
|
+ majorList.add(code2);
|
|
|
+ } else if (majorLevel == 3) {
|
|
|
+ JSONArray major3Array = major2Obj.getJSONArray("majors");
|
|
|
+ major3Array.stream().forEach(major3 -> {
|
|
|
+ JSONObject major3Obj = (JSONObject) major3;
|
|
|
+ String code3 = major3Obj.getString("code");
|
|
|
+ String name3 = major3Obj.getString("name");
|
|
|
+ majorList.add(code3);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return majorList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 就业前景 sy_major_career_prospects
|
|
|
+ * https://www.youzy.cn/majors/small?code=010101
|
|
|
+ *
|
|
|
+ * @param code
|
|
|
+ */
|
|
|
+ public void getCareerProspects(String code) {
|
|
|
+ log.info("start code {}",code);
|
|
|
+ //就业方向
|
|
|
+ String path = "/youzy.dms.basiclib.api.major.bycode.get";
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code", code);
|
|
|
+
|
|
|
+ String res = getRes(path, map);
|
|
|
+
|
|
|
+ String jobDirection = StringUtils.EMPTY;
|
|
|
+ String major=StringUtils.EMPTY;
|
|
|
+ String majorName = StringUtils.EMPTY;
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("res is empty");
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ JSONObject resultJsonobject = JSONObject.parseObject(res);
|
|
|
+ if (resultJsonobject.getBoolean("isSuccess")) {
|
|
|
+ JSONObject resultJsonObject = resultJsonobject.getJSONObject("result");
|
|
|
+ String bigName = resultJsonObject.getString("bigName");
|
|
|
+ jobDirection = resultJsonObject.getJSONObject("major").getString("jobDirection");
|
|
|
+
|
|
|
+ majorName = resultJsonObject.getJSONObject("major").getString("name");
|
|
|
+ major = bigName+"-"+majorName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(jobDirection)) {
|
|
|
+ log.error("jobDirection is empty,code is {},major is {},resultJsonobject is {}",code,major
|
|
|
+ ,JSONObject.parseObject(res));
|
|
|
+
|
|
|
+// return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ path = "/youzy.dms.basiclib.api.major.jobfuture.bycode.query";
|
|
|
+ String result = getResult(path, map);
|
|
|
+ if (StringUtils.isEmpty(result)) {
|
|
|
+ log.error("result is empty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray resultJsonArray = JSONObject.parseArray(result);
|
|
|
+
|
|
|
+ JSONObject insertObj4 = new JSONObject();
|
|
|
+ insertObj4.put("job_direction", jobDirection);
|
|
|
+ insertObj4.put("code", code);
|
|
|
+ insertObj4.put("name", majorName);
|
|
|
+
|
|
|
+ List<Entity> dbInsertList = new LinkedList<>();
|
|
|
+
|
|
|
+ resultJsonArray.stream().forEach(jsonobejct00 -> {
|
|
|
+ JSONObject jsonobejct0 = (JSONObject) jsonobejct00;
|
|
|
+ String type = jsonobejct0.getString("type");
|
|
|
+ switch (type) {
|
|
|
+ case "ZhiYeFX"://主要职业分布
|
|
|
+ String vocational_distribution = jsonobejct0.getString("futures");
|
|
|
+ insertObj4.put("vocational_distribution", vocational_distribution);
|
|
|
+ String description = jsonobejct0.getString("description");
|
|
|
+ if (StringUtils.isNotEmpty(description)) {
|
|
|
+ insertObj4.put("description", description);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "HangYeFB"://主要行业分布
|
|
|
+ String industry_distribution = jsonobejct0.getString("futures");
|
|
|
+ insertObj4.put("industry_distribution", industry_distribution);
|
|
|
+ description = jsonobejct0.getString("description");
|
|
|
+ if (StringUtils.isNotEmpty(description)) {
|
|
|
+ insertObj4.put("description", description);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "ChengShiFB"://主要就业地区分布
|
|
|
+ String job_region_distribution = jsonobejct0.getString("futures");
|
|
|
+ insertObj4.put("job_region_distribution", job_region_distribution);
|
|
|
+ description = jsonobejct0.getString("description");
|
|
|
+ if (StringUtils.isNotEmpty(description)) {
|
|
|
+ insertObj4.put("description", description);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "XinZiPJ"://近10年平均薪资
|
|
|
+ String average_salary = jsonobejct0.getString("futures");
|
|
|
+ insertObj4.put("average_salary", average_salary);
|
|
|
+ description = jsonobejct0.getString("description");
|
|
|
+ if (StringUtils.isNotEmpty(description)) {
|
|
|
+ insertObj4.put("description", description);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ //插入表sy_vocational_post
|
|
|
+ Entity subjectTable4 = Entity.create("sy_major_career_prospects");
|
|
|
+ subjectTable4.putAll(insertObj4);
|
|
|
+// dbInsertList.add(subjectTable4);
|
|
|
+
|
|
|
+ try {
|
|
|
+ DbUtil.use().insertOrUpdate(subjectTable4, "code");
|
|
|
+ log.info("finished code {}",code);
|
|
|
+// DbUtil.use().insert(dbInsertList);
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void processVocationalHotAndLack() throws SQLException {
|
|
|
+ List<Entity> dbInsertList = new LinkedList<>();
|
|
|
+ JSONArray hitsArray = getVocationalHits();
|
|
|
+ hitsArray.stream().forEach(hitsObj -> {
|
|
|
+ JSONObject insertObj5 = (JSONObject) hitsObj;
|
|
|
+ insertObj5.put("code", insertObj5.getString("code"));
|
|
|
+ insertObj5.put("hits", insertObj5.getString("hits"));
|
|
|
+ insertObj5.put("level", insertObj5.getInteger("level"));
|
|
|
+ insertObj5.put("levels", insertObj5.getString("levels"));
|
|
|
+ insertObj5.put("name", insertObj5.getString("name"));
|
|
|
+ insertObj5.put("summary", insertObj5.getString("summary"));
|
|
|
+ insertObj5.put("type", 1);
|
|
|
+
|
|
|
+ Entity subjectTable5 = Entity.create("sy_vocational_hits_lack");
|
|
|
+ subjectTable5.putAll(insertObj5);
|
|
|
+ dbInsertList.add(subjectTable5);
|
|
|
+ });
|
|
|
+
|
|
|
+ JSONArray lackArray = getVocationalLack();
|
|
|
+ lackArray.stream().forEach(hitsObj -> {
|
|
|
+ JSONObject insertObj5 = (JSONObject) hitsObj;
|
|
|
+ insertObj5.put("code", insertObj5.getString("code"));
|
|
|
+ insertObj5.put("hits", insertObj5.getString("hits"));
|
|
|
+ insertObj5.put("level", insertObj5.getInteger("level"));
|
|
|
+ insertObj5.put("levels", insertObj5.getString("levels"));
|
|
|
+ insertObj5.put("name", insertObj5.getString("name"));
|
|
|
+ insertObj5.put("summary", insertObj5.getString("summary"));
|
|
|
+ insertObj5.put("type", 2);
|
|
|
+
|
|
|
+ Entity subjectTable5 = Entity.create("sy_vocational_hits_lack");
|
|
|
+ subjectTable5.putAll(insertObj5);
|
|
|
+ dbInsertList.add(subjectTable5);
|
|
|
+ });
|
|
|
+
|
|
|
+ DbUtil.use().insert(dbInsertList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 热门职业
|
|
|
+ */
|
|
|
+ public JSONArray getVocationalHits() {
|
|
|
+ String url = host + "/youzy.dms.basiclib.api.career.jobs.hot.get?count=" + 10;
|
|
|
+ String uSign = "d4ed2f64f1fb31fb92b9ea621f43d1d8";
|
|
|
+ String res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ JSONArray resultJsonArray = new JSONArray();
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("res is empty");
|
|
|
+ } else {
|
|
|
+ JSONObject resultJsonobject = JSONObject.parseObject(res);
|
|
|
+ if (resultJsonobject.getBoolean("isSuccess")) {
|
|
|
+ resultJsonArray = resultJsonobject.getJSONArray("result");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultJsonArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 稀缺职业
|
|
|
+ */
|
|
|
+ public JSONArray getVocationalLack() {
|
|
|
+ String url = host + "/youzy.dms.basiclib.api.career.jobs.lack.get?count=" + 20;
|
|
|
+ String uSign = "9ae912cae8aa4513d3fe5b25620018c3";
|
|
|
+ String res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ JSONArray resultJsonArray = new JSONArray();
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("res is empty");
|
|
|
+ } else {
|
|
|
+ JSONObject resultJsonobject = JSONObject.parseObject(res);
|
|
|
+ if (resultJsonobject.getBoolean("isSuccess")) {
|
|
|
+ resultJsonArray = resultJsonobject.getJSONArray("result");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultJsonArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getVocationalList() throws Exception {
|
|
|
+ String url = host + "/youzy.dms.basiclib.api.career.jobs.tree.get";
|
|
|
+ String uSign = "c08ac01cdae3d836849cc3ee3721332b";
|
|
|
+ String res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("res is empty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject resultJsonobject = JSONObject.parseObject(res);
|
|
|
+
|
|
|
+ List<Entity> dbInsertList = new LinkedList<>();
|
|
|
+ List<JSONObject> dataSet = new LinkedList<>();
|
|
|
+ final int[] dataSize = {0};
|
|
|
+
|
|
|
+ if (resultJsonobject.getBoolean("isSuccess")) {
|
|
|
+ JSONArray resultJsonArray = resultJsonobject.getJSONArray("result");
|
|
|
+// log.info("resultJsonArray size is {}",resultJsonArray.size());
|
|
|
+ dataSize[0] += resultJsonArray.size();
|
|
|
+ resultJsonArray.stream().forEach(jsonobejct00 -> {
|
|
|
+ JSONObject jsonobejct0 = (JSONObject) jsonobejct00;
|
|
|
+ String code1 = jsonobejct0.getString("code");
|
|
|
+ String name1 = jsonobejct0.getString("name");
|
|
|
+ Integer level1 = 1;
|
|
|
+ String parentCode1 = "0";
|
|
|
+
|
|
|
+ JSONObject insertObj1 = new JSONObject();
|
|
|
+ insertObj1.put("code", code1);
|
|
|
+ insertObj1.put("name", name1);
|
|
|
+ insertObj1.put("level", level1);
|
|
|
+ insertObj1.put("parent_code", parentCode1);
|
|
|
+ insertObj1.put("ancestors", parentCode1);
|
|
|
+
|
|
|
+ Entity subjectTable = Entity.create("sy_vocational");
|
|
|
+ subjectTable.putAll(insertObj1);
|
|
|
+
|
|
|
+// try {
|
|
|
+// DbUtil.use().insertOrUpdate(subjectTable,"code");
|
|
|
+// } catch (SQLException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+ dbInsertList.add(subjectTable);
|
|
|
+ dataSet.add(insertObj1);
|
|
|
+
|
|
|
+ JSONArray childrenArray1 = jsonobejct0.getJSONArray("children");
|
|
|
+// log.info("childrenArray1 size is {}",childrenArray1.size());
|
|
|
+ dataSize[0] += childrenArray1.size();
|
|
|
+
|
|
|
+ childrenArray1.stream().forEach(jsonobejct1 -> {
|
|
|
+ JSONObject ca1 = (JSONObject) jsonobejct1;
|
|
|
+
|
|
|
+ String code2 = ca1.getString("code");
|
|
|
+ String name2 = ca1.getString("name");
|
|
|
+ Integer level2 = 2;
|
|
|
+ String parentCode2 = code1;
|
|
|
+ JSONObject insertObj2 = new JSONObject();
|
|
|
+ insertObj2.put("code", code2);
|
|
|
+ insertObj2.put("name", name2);
|
|
|
+ insertObj2.put("level", level2);
|
|
|
+ insertObj2.put("parent_code", parentCode2);
|
|
|
+ insertObj2.put("ancestors", parentCode1 + "," + parentCode2);
|
|
|
+ dataSet.add(insertObj2);
|
|
|
+
|
|
|
+ Entity subjectTable2 = Entity.create("sy_vocational");
|
|
|
+ subjectTable2.putAll(insertObj2);
|
|
|
+ dbInsertList.add(subjectTable2);
|
|
|
+
|
|
|
+// try {
|
|
|
+// DbUtil.use().insertOrUpdate(subjectTable2,"code");
|
|
|
+// } catch (SQLException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+ JSONArray jobsArray2 = ca1.getJSONArray("jobs");
|
|
|
+// log.info("jobsArray2 size is {}",jobsArray2.size());
|
|
|
+ dataSize[0] += jobsArray2.size();
|
|
|
+
|
|
|
+ jobsArray2.stream().forEach(jsonobejct2 -> {
|
|
|
+ JSONObject ca2 = (JSONObject) jsonobejct2;
|
|
|
+ String code3 = ca2.getString("code");
|
|
|
+ String name3 = ca2.getString("name");
|
|
|
+ Integer level3 = 3;
|
|
|
+ String parentCode3 = code2;
|
|
|
+
|
|
|
+ JSONObject insertObj3 = new JSONObject();
|
|
|
+ insertObj3.put("code", code3);
|
|
|
+ insertObj3.put("name", name3);
|
|
|
+ insertObj3.put("level", level3);
|
|
|
+ insertObj3.put("parent_code", parentCode3);
|
|
|
+ insertObj3.put("ancestors", parentCode1 + "," + parentCode2 + "," + parentCode3);
|
|
|
+
|
|
|
+
|
|
|
+ Entity subjectTable3 = Entity.create("sy_vocational");
|
|
|
+ subjectTable3.putAll(insertObj3);
|
|
|
+ dbInsertList.add(subjectTable3);
|
|
|
+ dataSet.add(insertObj3);
|
|
|
+
|
|
|
+// try {
|
|
|
+// DbUtil.use().insertOrUpdate(subjectTable3,"code");
|
|
|
+// } catch (SQLException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+ //code3概述与就业岗位
|
|
|
+ try {
|
|
|
+ processVocationalOverviewAndPost(code3);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ log.info("code3 is {}, name3 is {}", code3, name3);
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ DbUtil.use().insert(dbInsertList);
|
|
|
+ dbInsertList.clear();
|
|
|
+
|
|
|
+ log.info("dataSize[0] is {}", dataSize[0]);
|
|
|
+ log.info(res);
|
|
|
+ log.info(JSONObject.toJSONString(res));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processVocationalOverviewAndPost(String vocationalCode) throws Exception {
|
|
|
+ //1-1概述
|
|
|
+ String url = host + "/youzy.dms.basiclib.api.career.job.bycode.get?code=" + vocationalCode;
|
|
|
+ String body = "code=" + vocationalCode;
|
|
|
+ String uSign = "28b6defebdf24aab9d6b6f0b68d58c4f";
|
|
|
+ String res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("1-1概述:res is empty,the code is {}", vocationalCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject resObject = JSONObject.parseObject(res);
|
|
|
+
|
|
|
+ JSONObject insertObj3 = new JSONObject();
|
|
|
+ if (resObject.getBoolean("isSuccess")) {
|
|
|
+ JSONObject resultObj = resObject.getJSONObject("result");
|
|
|
+ String code = resultObj.getString("code");
|
|
|
+ String description = resultObj.getString("description");
|
|
|
+ Integer hits = resultObj.getInteger("hits");
|
|
|
+// JSONArray jobs = resultObj.getJSONArray("jobs");
|
|
|
+ String jobs = resultObj.getString("jobs");
|
|
|
+
|
|
|
+ Integer level = resultObj.getInteger("level");
|
|
|
+ String levelName = resultObj.getString("levelName");
|
|
|
+// JSONArray levels=resultObj.getJSONArray("levels");
|
|
|
+ String levels = resultObj.getString("levels");
|
|
|
+
|
|
|
+ String name = resultObj.getString("name");
|
|
|
+// JSONArray postJobs=resultObj.getJSONArray("postJobs");
|
|
|
+ String postJobs = resultObj.getString("postJobs");
|
|
|
+
|
|
|
+ Integer status = resultObj.getInteger("status");
|
|
|
+ String summary = resultObj.getString("summary");
|
|
|
+// JSONArray tags=resultObj.getJSONArray("tags");
|
|
|
+ String tags = resultObj.getString("tags");
|
|
|
+
|
|
|
+ insertObj3.put("code", code);
|
|
|
+ insertObj3.put("description", description);
|
|
|
+ insertObj3.put("hits", hits);
|
|
|
+ insertObj3.put("jobs", jobs);
|
|
|
+
|
|
|
+ insertObj3.put("level", level);
|
|
|
+ insertObj3.put("level_name", levelName);
|
|
|
+ insertObj3.put("levels", levels);
|
|
|
+ insertObj3.put("name", name);
|
|
|
+ insertObj3.put("post_jobs", postJobs);
|
|
|
+ insertObj3.put("status", status);
|
|
|
+ insertObj3.put("status", status);
|
|
|
+ insertObj3.put("summary", summary);
|
|
|
+ insertObj3.put("tags", tags);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //1-2、概述-相关专业
|
|
|
+ url = host + "/youzy.dms.basiclib.api.jobmajors.relevant.query?jobCode=" + vocationalCode;
|
|
|
+ ;
|
|
|
+// body = "jobCode="+vocationalCode;
|
|
|
+ uSign = "6907cd5128cd30d61afb3774e90771a8";
|
|
|
+ res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("概述-相关专业:res is emptythe code is {}", vocationalCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject postMajorsJsonobject = JSONObject.parseObject(res);
|
|
|
+
|
|
|
+ if (postMajorsJsonobject.getBoolean("isSuccess")) {
|
|
|
+ String postMajors = postMajorsJsonobject.getString("result");
|
|
|
+ insertObj3.put("post_majors", postMajors);
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入表 sy_vocational_overview
|
|
|
+// Entity subjectTable3 = Entity.create("sy_vocational_overview");
|
|
|
+// subjectTable3.putAll(insertObj3);
|
|
|
+// DbUtil.use().insertOrUpdate(subjectTable3,"code");
|
|
|
+
|
|
|
+
|
|
|
+ //2、就业岗位
|
|
|
+ url = host + "/youzy.dms.basiclib.api.career.post.tabs.get?code=" + vocationalCode;
|
|
|
+ ;
|
|
|
+// body = "jobCode="+vocationalCode;
|
|
|
+ uSign = "28b6defebdf24aab9d6b6f0b68d58c4f";
|
|
|
+ res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("2-1、就业岗位:res is emptythe code is {}", vocationalCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject postJsonobject = JSONObject.parseObject(res);
|
|
|
+
|
|
|
+ JSONObject insertObj4 = new JSONObject();
|
|
|
+ if (postJsonobject.getBoolean("isSuccess")) {
|
|
|
+ JSONArray postArray = postJsonobject.getJSONArray("result");
|
|
|
+ postArray.stream().forEach(jsonobejct -> {
|
|
|
+ JSONObject ca2 = (JSONObject) jsonobejct;
|
|
|
+ String name = ca2.getString("name");
|
|
|
+ Integer salaryMax = ca2.getInteger("salaryMax");
|
|
|
+ Integer salaryMin = ca2.getInteger("salaryMin");
|
|
|
+
|
|
|
+ insertObj4.put("code", vocationalCode);
|
|
|
+ insertObj4.put("name", name);
|
|
|
+ insertObj4.put("salary_max", salaryMax);
|
|
|
+ insertObj4.put("salary_min", salaryMin);
|
|
|
+
|
|
|
+ //插入表sy_vocational_post
|
|
|
+ Entity subjectTable4 = Entity.create("sy_vocational_post");
|
|
|
+ subjectTable4.putAll(insertObj4);
|
|
|
+ try {
|
|
|
+ DbUtil.use().insertOrUpdate(subjectTable4, "name");
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //岗位详情
|
|
|
+ try {
|
|
|
+ processPostDetails(name);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processPostDetails(String postName) throws Exception {
|
|
|
+ //2-2、岗位详情
|
|
|
+ String url = host + "/youzy.dms.basiclib.api.career.post.byname.get?name=" + postName;
|
|
|
+ ;
|
|
|
+// body = "jobCode="+vocationalCode;
|
|
|
+ String uSign = "e4b60f1264f61582957a67c1f23cede3";
|
|
|
+ String res = HttpUtils.postBody(url, "", uSign);
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("2-2、岗位详情:res is emptythe name is {}", postName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject postDetailJsonobject = JSONObject.parseObject(res);
|
|
|
+
|
|
|
+ JSONObject insertObj5 = new JSONObject();
|
|
|
+
|
|
|
+ if (postDetailJsonobject.getBoolean("isSuccess")) {
|
|
|
+ JSONObject postDetailObj = postDetailJsonobject.getJSONObject("result");
|
|
|
+
|
|
|
+ String citySalary = postDetailObj.getString("citySalary");
|
|
|
+ String demand = postDetailObj.getString("demand");
|
|
|
+ String edu = postDetailObj.getString("edu");
|
|
|
+ String exp = postDetailObj.getString("exp");
|
|
|
+ String experience = postDetailObj.getString("experience");
|
|
|
+ String industrySalary = postDetailObj.getString("industrySalary");
|
|
|
+ String name = postDetailObj.getString("name");
|
|
|
+ String salary = postDetailObj.getString("salary");
|
|
|
+ Integer salaryAvg = postDetailObj.getInteger("salaryAvg");
|
|
|
+ String sampleDesc = postDetailObj.getString("sampleDesc");
|
|
|
+ //职业数据来源
|
|
|
+ String vocationalSource = "职业数据来自《中华人民共和国国家职业分类大典》";
|
|
|
+ //薪资数据来源
|
|
|
+ String salarySource = "薪资数据来自于职友集" + postDetailObj.getString("sampleDesc");
|
|
|
+
|
|
|
+ insertObj5.put("city_salary", citySalary);
|
|
|
+ insertObj5.put("demand", demand);
|
|
|
+ insertObj5.put("edu", edu);
|
|
|
+ insertObj5.put("exp", exp);
|
|
|
+ insertObj5.put("experience", experience);
|
|
|
+ insertObj5.put("industry_salary", industrySalary);
|
|
|
+ insertObj5.put("name", name);
|
|
|
+ insertObj5.put("salary", salary);
|
|
|
+ insertObj5.put("salary_avg", salaryAvg);
|
|
|
+ insertObj5.put("sample_desc", sampleDesc);
|
|
|
+ insertObj5.put("vocational_source", vocationalSource);
|
|
|
+ insertObj5.put("salary_source", salarySource);
|
|
|
+
|
|
|
+ //插入表sy_vocational_post_detail
|
|
|
+ Entity subjectTable5 = Entity.create("sy_vocational_post_detail");
|
|
|
+ subjectTable5.putAll(insertObj5);
|
|
|
+ DbUtil.use().insertOrUpdate(subjectTable5, "name");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取请求的result
|
|
|
+ *
|
|
|
+ * @param path /youzy.dms.basiclib.api.major.tree.query
|
|
|
+ * @param map 参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getResult(String path, Map<String, Object> map) {
|
|
|
+ String res = getRes(path, map);
|
|
|
+ String resultString = StringUtils.EMPTY;
|
|
|
+ if (StringUtils.isEmpty(res)) {
|
|
|
+ log.error("res is empty");
|
|
|
+ } else {
|
|
|
+ JSONObject resultJsonobject = JSONObject.parseObject(res);
|
|
|
+ if (resultJsonobject.getBoolean("isSuccess")) {
|
|
|
+ resultString = resultJsonobject.getString("result");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultString;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getRes(String path, Map<String, Object> map) {
|
|
|
+ String requestPath = UsignUtils.getRequestPathAndParam(path, map);
|
|
|
+ String usign = UsignUtils.getUsign(requestPath);
|
|
|
+
|
|
|
+ String url = host + requestPath;
|
|
|
+ String res = HttpUtils.postBody(url, "", usign);
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|