diff --git a/e10dev/src/main/java/com/weaver/sxjg/config/EbDbDataSourceConfig.java b/e10dev/src/main/java/com/weaver/sxjg/config/EbDbDataSourceConfig.java new file mode 100644 index 0000000..88ab4a6 --- /dev/null +++ b/e10dev/src/main/java/com/weaver/sxjg/config/EbDbDataSourceConfig.java @@ -0,0 +1,149 @@ +package com.weaver.sxjg.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +import javax.sql.DataSource; + + +@Configuration +@Component +public class EbDbDataSourceConfig { + private static final Logger log = LoggerFactory.getLogger(EbDbDataSourceConfig.class); + @Value("${spring.datasource.urlebdesign}") + private String url; + @Value("${spring.datasource.driver-class-name}") + private String driverClassName; + @Value("${spring.datasource.username}") + private String username; + @Value("${spring.datasource.password}") + private String password; + + public DataSource dbDataSource() { + log.error("database:::::::::url"+url); + log.error("database:::::::::driverClassName"+driverClassName); + log.error("database:::::::::username"+username); + log.error("database:::::::::password"+password); + return DataSourceBuilder.create().driverClassName(this.driverClassName).username(this.username).password(this.password).url(this.url).build(); + } + + public EbDbDataSourceConfig() { + } + + public String getUrl() { + return this.url; + } + + public String getDriverClassName() { + return this.driverClassName; + } + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + + public void setUrl(String url) { + this.url = url; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (!(o instanceof EbDbDataSourceConfig)) { + return false; + } else { + EbDbDataSourceConfig other = (EbDbDataSourceConfig)o; + if (!other.canEqual(this)) { + return false; + } else { + label59: { + Object this$url = this.getUrl(); + Object other$url = other.getUrl(); + if (this$url == null) { + if (other$url == null) { + break label59; + } + } else if (this$url.equals(other$url)) { + break label59; + } + + return false; + } + + Object this$driverClassName = this.getDriverClassName(); + Object other$driverClassName = other.getDriverClassName(); + if (this$driverClassName == null) { + if (other$driverClassName != null) { + return false; + } + } else if (!this$driverClassName.equals(other$driverClassName)) { + return false; + } + + Object this$username = this.getUsername(); + Object other$username = other.getUsername(); + if (this$username == null) { + if (other$username != null) { + return false; + } + } else if (!this$username.equals(other$username)) { + return false; + } + + Object this$password = this.getPassword(); + Object other$password = other.getPassword(); + if (this$password == null) { + if (other$password != null) { + return false; + } + } else if (!this$password.equals(other$password)) { + return false; + } + + return true; + } + } + } + + protected boolean canEqual(Object other) { + return other instanceof EbDbDataSourceConfig; + } + + public int hashCode() { + boolean PRIME = true; + int result = 1; + Object $url = this.getUrl(); + result = result * 59 + ($url == null ? 43 : $url.hashCode()); + Object $driverClassName = this.getDriverClassName(); + result = result * 59 + ($driverClassName == null ? 43 : $driverClassName.hashCode()); + Object $username = this.getUsername(); + result = result * 59 + ($username == null ? 43 : $username.hashCode()); + Object $password = this.getPassword(); + result = result * 59 + ($password == null ? 43 : $password.hashCode()); + return result; + } + + public String toString() { + return "EbDbDataSourceConfig(url=" + this.getUrl() + ", driverClassName=" + this.getDriverClassName() + ", username=" + this.getUsername() + ", password=" + this.getPassword() + ")"; + } +} diff --git a/e10dev/src/main/java/com/weaver/sxjg/esb/EsbRpcPositionZhilian.java b/e10dev/src/main/java/com/weaver/sxjg/esb/EsbRpcPositionZhilian.java new file mode 100644 index 0000000..99750f0 --- /dev/null +++ b/e10dev/src/main/java/com/weaver/sxjg/esb/EsbRpcPositionZhilian.java @@ -0,0 +1,552 @@ +package com.weaver.sxjg.esb; + +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.weaver.ebuilder.common.exception.BusinessException; +import com.weaver.esb.api.rpc.EsbRpcRemoteInterface; +import com.weaver.sxjg.config.EbDbDataSourceConfig; +import com.weaver.sxjg.util.SxjgUtil; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.PostMethod; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author liuhao + * @use: 职位-新增,修改,发布,下线 接口对接智联招聘 + * @date + */ +@Service("esbRpcPositionZhilian_sj") +public class EsbRpcPositionZhilian implements EsbRpcRemoteInterface { + + private static final Logger log = LoggerFactory.getLogger(EsbRpcPositionZhilian.class); + private String zlTokenUrl; + private String clientId; + private String clientSecret; + private String dicturl; + private String jobaddurl; + private String jobupdateurl; + private String jobpublishurl; + private String joboffline; + private String wslburl; + private String wslbxqurl; + @Autowired + public EbDbDataSourceConfig ebDbDataSourceConfig; + + public EsbRpcPositionZhilian() { + PropertiesConfiguration p = null; + try { + p = new PropertiesConfiguration(); + p.setEncoding("utf-8"); + p.setFileName("config/sxjg.properties"); + p.load(); + this.setClientId(p.getString("sxjg.client_id")); + this.setClientSecret(p.getString("sxjg.client_secret")); + this.setZlTokenUrl(p.getString("sxjg.refreshtokenurl")); + this.setDicturl(p.getString("sxjg.dicturl")); + this.setJobaddurl(p.getString("sxjg.jobadd")); + this.setJobupdateurl(p.getString("sxjg.jobupdate")); + this.setJobpublishurl(p.getString("sxjg.jobpublish")); + this.setJoboffline(p.getString("sxjg.joboffline")); + this.setWslburl(p.getString("sxjg.wslburl")); + this.setWslbxqurl(p.getString("sxjg.wslbxqurl")); + }catch (ConfigurationException e) { + throw new BusinessException("获取sxjg.properties配置文件失败,", e); + } + } + + @Override + public Map execute(Map params) { + String operate_flag = (String)params.get("operate_flag"); + //1更新字典 + if("1".equals(operate_flag)) { + log.error("定时更新字典启动:>>>>>>>>>>>>>>>>>>>>>>"); + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + updateRefreshDict(params,jdbcTemplate,"0000"); + return SxjgUtil.ok(); + } + //2 岗位新增,编辑,删除 + else if("2".equals(operate_flag)) { + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + try { + jobAdd(params,jdbcTemplate); + return SxjgUtil.ok(); + }catch (Exception e){ + e.printStackTrace(); + return SxjgUtil.err(e.getMessage()); + } + } + //3 简历获取 + else if("3".equals(operate_flag)) { + log.error("简历获取:>>>>>>>>>>>>>>>>>>>>>>"); + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + synchronJobTitle(jdbcTemplate); + return SxjgUtil.ok(); + } + //4 岗位发布 + else if("4".equals(operate_flag)) { + log.error("职位发布:>>>>>>>>>>>>>>>>>>>>>>"); + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + try{ + publishjob(params,jdbcTemplate); + return SxjgUtil.ok(); + }catch (Exception e){ + return SxjgUtil.err(e.getMessage()); + } + } + //refresh token 定时 + else if("5".equals(operate_flag)) { + log.error("定时刷新token启动:>>>>>>>>>>>>>>>>>>>>>>"); + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + refreshToken(jdbcTemplate,"0000"); + return SxjgUtil.ok(); + } + else if("6".equals(operate_flag)) {//职位下线 + JdbcTemplate jdbcTemplate = new JdbcTemplate(ebDbDataSourceConfig.dbDataSource()); + try{ + downjob(params,jdbcTemplate); + return SxjgUtil.ok(); + }catch (Exception e){ + return SxjgUtil.err(e.getMessage()); + } + } + else { + return SxjgUtil.err("配置不正确,请检查参数:operate_flag"); + } + } + + private void synchronJobTitle(JdbcTemplate jdbcTemplate){ + List> rs = SxjgUtil.getZlTblist(jdbcTemplate); + if(CollectionUtil.isNotEmpty(rs)) { + for(Map m : rs) { + BigDecimal id = (BigDecimal)m.get("id"); + String jobNumber = (String)m.get("zlzwid"); + String subcompany = (String)m.get("sub_company"); + String companyId = SxjgUtil.getZlbh(subcompany,jdbcTemplate); + String jobsyctime = (String)m.get("jobsyctime");//上一次更新时间 + Date preTimesql = SxjgUtil.getDateByTimestr(jobsyctime,"yyyy-MM-dd HH:mm:ss"); + String preTimejk = SxjgUtil.getTimeStrByDate(preTimesql,"yyyy/MM/dd HH:mm"); + Date now = new Date(); + String nowTimejk = SxjgUtil.getTimeStrByDate(now,"yyyy/MM/dd HH:mm"); + String nowTimeSql = SxjgUtil.getTimeStrByDate(now,"yyyy-MM-dd HH:mm:ss"); + try{ + getWsList(jobNumber,companyId,preTimejk,nowTimejk,jdbcTemplate);//一批量 有任何一次失败,则不更新时间 + //更新该岗位的最后获取时间 + SxjgUtil.updateLastTime(id,nowTimeSql,jdbcTemplate); + }catch (Exception e){ + log.error("根据jobNumber"+jobNumber+"获取网申列表失败,失败原因:"+e.getMessage()); + } + } + } + } + + private void downjob(Map params, JdbcTemplate jdbcTemplate) throws Exception{ + String id = (String)params.get("id"); + log.error("职位下线,职位id:>>>>>>>>>>>>>>>>>>>>>>"+id); + String jobNumber = SxjgUtil.getJobNumber(id,jdbcTemplate); + if(jobNumber.length()==0) { + log.error("当前职位id:"+id+" 并未找到jobNumber,请先新增职位!"); + throw new Exception("当前职位并未找到jobNumber!"); + } + String orgCode = (String)params.get("orgcode"); + String companyId = SxjgUtil.getZlbh(orgCode,jdbcTemplate); + long companyId1 = Long.parseLong(companyId); + if(companyId.length()==0){ + throw new Exception("当前岗位所属组织并未配置,请联系管理员!"); + } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("jobNumber",jobNumber); + jsonObject.put("companyId",companyId1); + String rs = SxjgUtil.doJsonPost(joboffline,this.getClientId(),jsonObject.toJSONString(),jdbcTemplate,"0000"); + if(SxjgUtil.isSuccess(rs)) { + JSONObject r1 =SxjgUtil.getInterfaceData(rs); + SxjgUtil.updateStatus(id,jdbcTemplate,"2"); + }else { + throw new Exception("职位下线失败:"+rs); + } + } + + + private void publishjob(Map params, JdbcTemplate jdbcTemplate) throws Exception{ + String id = (String)params.get("id"); + String jobNumber = SxjgUtil.getJobNumber(id,jdbcTemplate); + if(jobNumber.length()==0) { + log.error("当前职位id:"+id+" 并未找到jobNumber,请先新增职位!"); + throw new Exception("当前职位并未找到jobNumber!"); + } + String orgCode = (String)params.get("orgcode"); + String companyId = SxjgUtil.getZlbh(orgCode,jdbcTemplate); + long companyId1 = Long.parseLong(companyId); + if(companyId.length()==0){ + throw new Exception("当前岗位所属组织并未配置,请联系管理员!"); + } + String qudao = (String)params.get("qudao"); + if(!qudao.contains("智联招聘")) { + return; + } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("jobNumber",jobNumber); + jsonObject.put("intoReview",0); + jsonObject.put("companyId",companyId1); + String rs = SxjgUtil.doJsonPost(jobpublishurl,this.getClientId(),jsonObject.toJSONString(),jdbcTemplate,"0000"); + if(SxjgUtil.isSuccess(rs)) { + SxjgUtil.updateStatus(id,jdbcTemplate,"1"); + }else { + throw new Exception("职位发布失败:"+rs); + } + } + + /** + * isAdd 是新增 ,否更新 + */ + private void jobAdd(Map params, JdbcTemplate jdbcTemplate) throws Exception { + boolean isAdd = true; + Map res = new HashMap<>(); + String id = (String)params.get("id"); + String qudao = (String)params.get("qudao"); + if(!qudao.contains("智联招聘")){ + throw new Exception("没有勾选智联招聘,当前数据不走同步接口"); + } + String orgCode = (String)params.get("orgcode"); + log.error("职位id:"+id); + log.error("职位所属公司code:"+orgCode); + String companyId = SxjgUtil.getZlbh(orgCode,jdbcTemplate); + long companyId1 = Long.parseLong(companyId); + if(companyId.length()==0){ + throw new Exception("当前岗位所属组织并未配置,请联系管理员!"); + } + + String jobNumber = SxjgUtil.getJobNumber(id,jdbcTemplate); + if(jobNumber.length()>0) { + isAdd = false; + } + log.error("职位所属公司code对应智联code:"+companyId); + log.error("发布渠道:"+qudao); + String jobNature = (String)params.get("jobNature");//职位属性 + long jobType = SxjgUtil.getLastValuekey((String)params.get("jobType"),"/"); + String jobTitle = (String)params.get("jobTitle");//职位名称 + String city = (String)params.get("city");//工作城市 + if(city.contains("市")) { + city= city.split("市")[0]; + } + String jobAddress = (String)params.get("jobAddress");//工作地址 + BigDecimal maxSalary = new BigDecimal((String)params.get("maxSalary"));//最大月薪 + BigDecimal minSalary = new BigDecimal((String)params.get("minSalary"));//最小月薪 + String quantity1 = (String)params.get("quantity");//招聘人数 + int quantity = Double.valueOf(quantity1).intValue(); + String education = (String)params.get("education");//最低学历 + String workAge = (String)params.get("workAge");//工作年限 + String jobDescription = (String)params.get("jobDescription");//职位描述 + //转换智联 + int jobNature1 = "实习".equals(jobNature) ? 4 : 2; + long cityId = SxjgUtil.getCityId(jdbcTemplate,city); + long maxSalary1 =maxSalary.multiply(new BigDecimal(1000)).longValue(); + long minSalary1 =minSalary.multiply(new BigDecimal(1000)).longValue(); + if((minSalary1*2) < maxSalary1) { + log.error("智联岗位新增:最大薪资不能超过最小薪资的2倍"); + throw new Exception("智联岗位新增:最大薪资不能超过最小薪资的2倍"); + } + if(jobDescription.length()<10) { + throw new Exception("智联岗位新增:岗位描述不能小于十个字"); + } + if(minSalary1<1000l){ + log.error("智联岗位新增:最低薪资不能小于1000"); + throw new Exception("智联岗位新增:最低薪资不能小于1000"); + } + int education1 = SxjgUtil.getEducode(education); + int workAge1 = SxjgUtil.getWordExpCode(workAge); + JSONObject jsonObject = new JSONObject(); + if(!isAdd){ + jsonObject.put("jobNumber",jobNumber); + } + jsonObject.put("jobNature",jobNature1); + jsonObject.put("jobType",jobType); + jsonObject.put("jobTitle",jobTitle); + jsonObject.put("cityId",cityId); + jsonObject.put("jobAddress",jobAddress); + jsonObject.put("maxSalary",maxSalary1); + jsonObject.put("companyId",companyId1); + jsonObject.put("minSalary",minSalary1); + jsonObject.put("quantity",quantity); + jsonObject.put("education",education1); + jsonObject.put("workAge",workAge1); + jsonObject.put("jobDescription",jobDescription); + String url1 = isAdd ? this.getJobaddurl() : this.getJobupdateurl(); + String rs = SxjgUtil.doJsonPost(url1,this.getClientId(),jsonObject.toJSONString(),jdbcTemplate,"0000"); + if(SxjgUtil.isSuccess(rs)) { + if(isAdd) { + JSONObject r1 =SxjgUtil.getInterfaceData(rs); + SxjgUtil.updateZhilianId(id,r1.getString("jobNumber"),jdbcTemplate); + } + }else { + throw new Exception("职位新增接口异常!"); + } + } + + /** + * 更新token,并且更新字典 + */ + private Map updateRefreshDict(Map params,JdbcTemplate jdbcTemplate,String orgcode) { + Map res = new HashMap<>(); + res.put("result",false); + res.put("description",""); + JSONObject json1 = new JSONObject(); + json1.put("dicType","REGIONS"); + json1.put("page",1); + String s1 = SxjgUtil.doJsonPost(getDicturl(),getClientId(),json1.toJSONString(),jdbcTemplate,orgcode); + JSONObject rs1 = JSONObject.parseObject(s1); + JSONObject r11 = rs1.getJSONObject("data"); + int total = r11.getInteger("total"); + int yeshu = 0; + if(total%100 == 0) { + yeshu = total/100; + }else { + yeshu = total/100; + yeshu = yeshu+1; + } + for(int j = 1;j<=yeshu;j++) { + JSONObject json = new JSONObject(); + json.put("dicType","REGIONS"); + json.put("page",j); + String s = SxjgUtil.doJsonPost(getDicturl(),getClientId(),json.toJSONString(),jdbcTemplate,"0000"); + JSONObject rs = JSONObject.parseObject(s); + JSONObject r1 = rs.getJSONObject("data"); + JSONArray r2 = r1.getJSONArray("dataList"); + for(int i = 0; i rs0 = jdbcTemplate.queryForMap(querysql); + long v = (Long) rs0.get("sums"); + if(v==0l) { + String updateSql = "insert into zhilian_zidian(code,cnName,enName,parentCode,pyName," + + "attribute,type)values('"+code+"','"+cnName+"','"+enName+"','"+parentCode+"','"+pyName+"','"+attribute+"','"+"REGIONS"+"')"; + jdbcTemplate.execute(updateSql); + } + } + res.put("result",true); + } + return res; + } + + /** + * use:获取网申列表,自行分页,从第一页开始,每次获取100条 + */ + private void getWsList(String jobNumber,String companyId,String starttime,String endtime,JdbcTemplate jdbcTemplate) throws Exception{ + JSONObject json1 = new JSONObject(); + json1.put("page",1); + json1.put("pageSize",100); + json1.put("dateStart",starttime); + json1.put("dateEnd",endtime); + json1.put("jobNumber",jobNumber); + json1.put("companyId",companyId); + String s1 = SxjgUtil.doJsonPost(getWslburl(),getClientId(),json1.toJSONString(),jdbcTemplate,"0000"); + JSONArray jsonArray = new JSONArray(); + if(SxjgUtil.isSuccess(s1)) { + JSONObject data = SxjgUtil.getInterfaceData(s1); + int total = data.getInteger("total"); + if(total == 0){ + return; + } + int yeshu = 0; + if(total%100 == 0) { + yeshu = total/100; + }else { + yeshu = total/100; + yeshu = yeshu+1; + } + //进入分页 + for(int j = 1;j<=yeshu;j++) { + if(yeshu == 1) { + jsonArray = data.getJSONArray("dataList"); + dealJsonArrayGetDetail(jsonArray,companyId,jobNumber,jdbcTemplate); + continue; + } + json1 = new JSONObject(); + json1.put("page",j); + json1.put("pageSize",100); + json1.put("dateStart",starttime); + json1.put("dateEnd",endtime); + json1.put("jobNumber",jobNumber); + json1.put("companyId",companyId); + s1 = SxjgUtil.doJsonPost(getWslburl(),getClientId(),json1.toJSONString(),jdbcTemplate,"0000"); + if(SxjgUtil.isSuccess(s1)) { + data = SxjgUtil.getInterfaceData(s1); + jsonArray = data.getJSONArray("dataList"); + dealJsonArrayGetDetail(jsonArray,companyId,jobNumber,jdbcTemplate); + } + } + }else { + throw new Exception("获取网申列表详情失败,失败原因看日志!"); + } + } + + /** + * 获取到时间段内的简历 + */ + public void dealJsonArrayGetDetail(JSONArray jsonArray,String companyid,String jobNumber,JdbcTemplate jdbcTemplate) throws Exception{ + for(int i = 0; i < jsonArray.size();i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + String jobResumeId = jsonObject.getString("jobResumeId"); + JSONObject json1 = new JSONObject(); + json1.put("jobResumeId",jobResumeId); + json1.put("companyId",companyid); + String s1 = SxjgUtil.doJsonPost(getWslbxqurl(),getClientId(),json1.toJSONString(),jdbcTemplate,"0000"); + if(SxjgUtil.isSuccess(s1)) { + //处理批次 + if(!SxjgUtil.existPc(jobResumeId,jobNumber,jdbcTemplate)) { + //成功录入批次后 + // TODO: 2023/9/15 需要调用批次录用,成功后处理 + String pcid = ""; + //录入中间表,将已经成功同步的批次记录 记录批次编号,简历编号(智联) + SxjgUtil.insertSyn(jobResumeId,pcid,jobNumber,jdbcTemplate); + } + }else { + throw new Exception("获取简历详情失败!具体明细请看日志"); + } + } + } + + @Test +// public void test1(){ +// DataSource db = DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver").username("ecology").password("uxJhLJn4%NpWxujAYyKsTpxP").url("jdbc:mysql://10.70.11.12:3306/ec_ebuilder_designer?characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&allowMultiQueries=true").build(); +// JdbcTemplate jdbcTemplate = new JdbcTemplate(db); +// refreshToken(jdbcTemplate,"0000"); +// } + + private boolean refreshToken(JdbcTemplate jdbcTemplate,String orgcodes) { + boolean flag = false; + try { + String postURL; + PostMethod postMethod = null; + postMethod = new PostMethod(getZlTokenUrl()); + System.out.println(getZlTokenUrl()); + postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + NameValuePair[] data = { + new NameValuePair("client_id",getClientId()), + new NameValuePair("client_secret",getClientSecret()), + new NameValuePair("grant_type","refresh_token"), + new NameValuePair("refresh_token",SxjgUtil.getRt(jdbcTemplate,orgcodes)) + }; + + postMethod.setRequestBody(data); + + org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient(); + int response = httpClient.executeMethod(postMethod); // 执行POST方法 + String result = postMethod.getResponseBodyAsString() ; + System.out.println(result); +// log.error("调用智联刷新token接口,返回值:>>>>>>>>>>>>>>>>>>>>>>"+result); + Map rs1 = SxjgUtil.parseXmlToToken(result); + SxjgUtil.updateToken(rs1.get("at"),rs1.get("rt"),jdbcTemplate,orgcodes); + flag = true; + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e.getMessage()); + } + return flag; + } + + /** + * 获取字典并更新数据库 + */ + public boolean getDictUp() { + return true; + } + public void setZlTokenUrl(String zlTokenUrl) { + this.zlTokenUrl = zlTokenUrl; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + public String getZlTokenUrl() { + return zlTokenUrl; + } + + public String getDicturl() { + return dicturl; + } + + public void setDicturl(String dicturl) { + this.dicturl = dicturl; + } + + public String getJobaddurl() { + return jobaddurl; + } + + public void setJobaddurl(String jobaddurl) { + this.jobaddurl = jobaddurl; + } + public String getJobupdateurl() { + return jobupdateurl; + } + + public void setJobupdateurl(String jobupdateurl) { + this.jobupdateurl = jobupdateurl; + } + + public String getJobpublishurl() { + return jobpublishurl; + } + + public void setJobpublishurl(String jobpublishurl) { + this.jobpublishurl = jobpublishurl; + } + + public String getJoboffline() { + return joboffline; + } + + public void setJoboffline(String joboffline) { + this.joboffline = joboffline; + } + + public String getWslburl() { + return wslburl; + } + + public void setWslburl(String wslburl) { + this.wslburl = wslburl; + } + + public String getWslbxqurl() { + return wslbxqurl; + } + + public void setWslbxqurl(String wslbxqurl) { + this.wslbxqurl = wslbxqurl; + } +} diff --git a/e10dev/src/main/java/com/weaver/sxjg/util/SxjgUtil.java b/e10dev/src/main/java/com/weaver/sxjg/util/SxjgUtil.java new file mode 100644 index 0000000..b3d0799 --- /dev/null +++ b/e10dev/src/main/java/com/weaver/sxjg/util/SxjgUtil.java @@ -0,0 +1,334 @@ +package com.weaver.sxjg.util; + +import com.alibaba.fastjson.JSONObject; +import com.weaver.sxjg.config.EbDbDataSourceConfig; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.io.*; +import java.math.BigDecimal; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SxjgUtil { + private static final Logger log = LoggerFactory.getLogger(SxjgUtil.class); + + @Autowired + public static EbDbDataSourceConfig ebDbDataSourceConfig; + /** + * 解析xml获取返回值 + */ + public static Map parseXmlToToken(String xml) throws Exception { + Maprs = new HashMap<>(); + Document document = null; + try { + document = DocumentHelper.parseText(xml); + } catch (DocumentException e) { + e.printStackTrace(); + } + //获取根节点A的下一个子节点B + Element B_element = document.getRootElement().element("data"); + //可判断节点是否存在,存在再去获取节点内容 + if (B_element != null) { + //根据B节点再获取其子节点C + Element rt = B_element.element("rt"); + String rtstr = rt.getText(); + Element at = B_element.element("at"); + String atstr = at.getText(); + rs.put("rt",rtstr); + rs.put("at",atstr); + } else { + throw new Exception("获取失败!"); + } + return rs; + } + + public static String getToken(JdbcTemplate jdbcTemplate,String orgCodes){ + String sql = "select at from zhilian_token where orgcode = '"+orgCodes+"'"; + Map map = jdbcTemplate.queryForMap(sql); + String token = map.get("at").toString(); + return token; + } + + public static String getRt(JdbcTemplate jdbcTemplate,String orgCodes){ + String sql = "select rt from zhilian_token where orgcode = '"+orgCodes+"'"; + Map map = jdbcTemplate.queryForMap(sql); + String rt = map.get("rt").toString(); + return rt; + } + + public static long getCityId(JdbcTemplate jdbcTemplate,String name){ + String sql = "select count(id) as sums from zhilian_zidian where cnName like '%"+name+"%' and type='REGIONS' and attribute in ('CITY','DISTRICT')"; + Map map = jdbcTemplate.queryForMap(sql); + long sums = (long)map.get("sums"); + if(sums==0l) { + return 512l;//其他 + } + sql = "select code from zhilian_zidian where cnName like '%"+name+"%' and type = 'REGIONS' and attribute in ('CITY','DISTRICT') limit 1"; + map = jdbcTemplate.queryForMap(sql); + String code = (String)map.get("code"); + long code1 = Long.parseLong(code); + return code1; + } + + public static void updateToken(String at1,String rt1,JdbcTemplate jdbcTemplate,String orgCodes){ + String sql = "select id from zhilian_token where orgcode = '"+orgCodes+"' limit 1"; + Map map = jdbcTemplate.queryForMap(sql); + String id = map.get("id").toString(); + String updatesql = "update zhilian_token set rt='"+rt1+"',at = '"+at1+"' where id = "+id; + jdbcTemplate.execute(updatesql); + } + + public static String doJsonPost(String url,String clientid,String json,JdbcTemplate jdbcTemplate,String orgcode) { + log.error("智联接口"+url+",推送报文:>>>>>>>>>>>>>>>>>>>>>>"+json); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost post = new HttpPost(url); + post.setHeader("Content-Type", "application/json;charset=utf-8"); + post.setHeader("clientId", clientid); + post.setHeader("accessToken",SxjgUtil.getToken(jdbcTemplate,orgcode)); + String result=""; + try { + StringEntity s = new StringEntity(json,"UTF-8"); + s.setContentEncoding("utf-8"); + s.setContentType("application/json"); + post.setEntity(s); + // 发送请求 + HttpResponse httpResponse = client.execute(post); + // 获取响应输入流 + InputStream inStream = httpResponse.getEntity().getContent(); + BufferedReader reader = new BufferedReader(new InputStreamReader( + inStream,"utf-8")); + StringBuilder strber = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) + strber.append(line + "\n"); + inStream.close(); + result = strber.toString(); + log.error("智联接口"+url+",返回值:>>>>>>>>>>>>>>>>>>>>>>"+result); + } catch (Exception e) { + log.error("智联接口"+url+",返回值:>>>>>>>>>>>>>>>>>>>>>>"+e.getMessage()); + e.printStackTrace(); + } + return result; + } + + /** + * 智联字典 [{"attribute":"11","cnName":"博士","code":"1","enName":"Doctor","parentCode":"0","pyName":"boshi"},{"attribute":"8","cnName":"硕士","code":"3","enName":"Master","parentCode":"0","pyName":"shuoshi"},{"attribute":"7","cnName":"本科","code":"4","enName":"Bachelor","parentCode":"0","pyName":"benke"},{"attribute":"5","cnName":"大专","code":"5","enName":"Associate","parentCode":"0","pyName":"dazhuan"},{"attribute":"3","cnName":"高中","code":"7","enName":" Senior High","parentCode":"0","pyName":"gaozhong"},{"attribute":"1","cnName":"初中及以下","code":"9","enName":"junior high","parentCode":"0","pyName":"chuzhongjiyixia"},{"attribute":"9","cnName":"MBA/EMBA","code":"10","enName":"MBA/EMBA","parentCode":"0","pyName":"MBA/EMBA"},{"attribute":"4","cnName":"中专/中技","code":"12","enName":"Secondary Specialized/Skilled Workers Training","parentCode":"0","pyName":"zhongzhuan/zhongji"}] + */ + public static int getEducode(String name) { + if("不限".equals(name)) { + return 9;//初中及以下 + } + if("初中及以下".equals(name)) { + return 9; + } + if("中专/中技".equals(name)) { + return 12; + } + if("高中".equals(name)) { + return 7; + } + if("大专".equals(name)) { + return 5; + } + if("本科".equals(name)) { + return 4; + } + if("硕士".equals(name)) { + return 3; + } + if("博士".equals(name)) { + return 1; + } + if("MBA".equals(name)) { + return 10; + } + if("其他".equals(name)) { + return 9; + } + return 9; + } + + /** + * 智联字典:[{"cnName":"无经验","code":"0000","enName":"No experience","parentCode":"0","pyName":"wujingyan"},{"cnName":"1年以下","code":"0001","enName":"Below 1 Year","parentCode":"0","pyName":"nianyixia"},{"cnName":"1-3年","code":"0103","enName":"1-3 Year","parentCode":"0","pyName":"nian"},{"cnName":"3-5年","code":"0305","enName":"3-5 Year","parentCode":"0","pyName":"nian"},{"cnName":"5-10年","code":"0510","enName":"5-10 Year","parentCode":"0","pyName":"nian"},{"cnName":"10年以上","code":"1099","enName":"Above 10 Year","parentCode":"0","pyName":"nianyishang"}] + */ + public static int getWordExpCode(String name){ + if("不限".equals(name)) { + return 0000; + } + if("应届毕业生".equals(name)) { + return 0000; + } + if("一年以内".equals(name)) { + return 0001; + } + if("1~3年".equals(name)) { + return 0103; + } + if("3~5年".equals(name)) { + return 0305; + } + if("5~10年".equals(name)) { + return 0510; + } + if("10年以上".equals(name)) { + return 1099; + } + return 0000; + } + + public static Map ok() { + Map rs = new HashMap<>(); + rs.put("result",true); + rs.put("description",""); + return rs; + } + + public static Map err(String msg) { + Map rs = new HashMap<>(); + rs.put("result",false); + rs.put("description",msg); + return rs; + } + + public static JSONObject getInterfaceData(String s) { + JSONObject r1 = JSONObject.parseObject(s); + return r1.getJSONObject("data"); + } + public static boolean isSuccess(String s) { + if(s.length()==0)return false; + JSONObject r1 = JSONObject.parseObject(s); + return "成功".equals(r1.getString("message")) ? true : false; + } + + public static void updateZhilianId(String id1,String zwid1,JdbcTemplate jdbcTemplate) { + String sql = "update uf_rcrt_position set zlzwid = '"+zwid1+"' where id = "+id1; + jdbcTemplate.execute(sql); + } + + public static long getLastValuekey(String str,String spe) { + String[] res = str.split(spe); + String rs = res[res.length-1]; + return Long.parseLong(rs); + } + + public static String getJobNumber(String id1, JdbcTemplate jdbcTemplate) { + String sql = "select zlzwid from uf_rcrt_position where id = "+id1; + try { + Map rs = jdbcTemplate.queryForMap(sql); + if(rs.get("zlzwid")==null) { + return ""; + } + String jobNumber = (String)rs.get("zlzwid"); + return jobNumber; + }catch (Exception e){ + return ""; + } + } + + public static String getZlbh(String orgcode,JdbcTemplate jdbcTemplate) { + String sql = "select zlbh from uf_rcrt_zhilianzh where ssfb = '"+orgcode+"' and IS_DELETE = 0 and qyzt = '1' limit 1"; + try { + Map rs = jdbcTemplate.queryForMap(sql); + String zlbh = (String)rs.get("zlbh"); + return zlbh; + }catch (Exception e){ + return ""; + } + } + + public static String decrypt(String secretKey, String content) { + byte[] code = Base64.getDecoder().decode(content); + try { + SecretKey decryptKey = new SecretKeySpec(Base64.getDecoder().decode(secretKey), "aes"); + Cipher aesCipher = Cipher.getInstance("aes"); + aesCipher.init(Cipher.DECRYPT_MODE, decryptKey); + byte[] result = aesCipher.doFinal(code); + return new String(result, "UTF-8"); + } catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | + UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) { + throw new RuntimeException(); + } + } + + //1已发布 2已下架 + public static void updateStatus(String id, JdbcTemplate jdbcTemplate,String status) { + String sql = ""; + if("1".equals(status)) {//更新发布时间和状态 + String nowTime = getTimeStrByDate(new Date(),"yyyy-MM-dd HH:mm:ss"); + sql = "update uf_rcrt_position set jobsyctime = '"+nowTime+"',sfyfbzl = '"+status+"' where id = "+id; + }else { + sql = "update uf_rcrt_position set sfyfbzl = '"+status+"' where id = "+id; + } + jdbcTemplate.execute(sql); + } + + public static List> getZlTblist(JdbcTemplate jdbcTemplate) { + String sql = "select id,zlzwid,sub_company,jobsyctime from uf_rcrt_position where zlzwid is not null and sfyfbzl = '1'"; + List> rs = jdbcTemplate.queryForList(sql); + return rs; + } + +// public static void main(String[] args) { +// DataSource db = DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver").username("ecology").password("uxJhLJn4%NpWxujAYyKsTpxP").url("jdbc:mysql://10.70.11.12:3306/ec_ebuilder_designer?characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&allowMultiQueries=true").build(); +// JdbcTemplate jdbcTemplate = new JdbcTemplate(db); +// List> rs = getZlTblist(jdbcTemplate); +// for(Map a1 : rs) { +// BigDecimal id = (BigDecimal)a1.get("id"); +// String jobNumber = (String)a1.get("zlzwid"); +// String company = (String)a1.get("sub_company"); +// System.out.println(id); +// System.out.println(jobNumber); +// System.out.println(company); +// } +// } + + public static Date getDateByTimestr(String datatime,String format) { + SimpleDateFormat sdf2 = new SimpleDateFormat(format); + Date myDate2 = null; + try { + myDate2 = sdf2.parse(datatime); + return myDate2; + }catch (Exception e){ + return null; + } + } + + public static String getTimeStrByDate(Date date,String formate) { + SimpleDateFormat sdf2 = new SimpleDateFormat(formate); + String strDate2 = sdf2.format(date); + return strDate2; + } + + public static void updateLastTime(BigDecimal id, String nowTimeSql,JdbcTemplate jdbcTemplate) { + String sql = "update uf_rcrt_position set jobsyctime = '"+nowTimeSql+"' where id = "+id; + jdbcTemplate.execute(sql); + } + + public static void insertSyn(String jobResumeId1, String pcid1, String jobNumber1,JdbcTemplate jdbcTemplate) { + String sql = "INSERT INTO zhilian_jianlisyn(jobResumeId,pcid,jobNumber) VALUES ('"+jobResumeId1+"', '"+pcid1+"', '"+jobNumber1+"')"; + jdbcTemplate.execute(sql); + } + + public static boolean existPc(String jobResumeId,String jobNumber,JdbcTemplate jdbcTemplate) { + String sql = "select count(id) as nums from zhilian_jianlisyn where jobResumeId = '"+jobResumeId+"' and jobNumber = '"+jobNumber+"'"; + Map rs = jdbcTemplate.queryForMap(sql); + long sums = (long)rs.get("nums"); + return sums>0l; + } +}