招聘修复+企微对接

This commit is contained in:
zhangming 2025-06-24 09:52:28 +08:00
parent 071da92e60
commit 00b817587c
13 changed files with 2036 additions and 7 deletions

View File

@ -69,4 +69,23 @@ OCR_URL=https://open.easst.cn/openapi/rest/resume
#appid
APP_ID=84th31r9
#appSecret
APP_SECRET=b43c83ea6f2169f2fd20e691bcdfa6f6
APP_SECRET=b43c83ea6f2169f2fd20e691bcdfa6f6
INTERVIEW_REGISTRATION_MOBILE_URL=http://ip:port/mobilemode/mobile/view.html?appid=19&mTokenFrom=anonymous&mToken=6C760B28E1BE2BAFDA69017CBE6A0A47
#企微corpid
QW_CORPID=wwd68018f07e163b3a
#企微打卡corpsecret
QW_CORPSECRET=qIWrZYOeg2m8StghIl-eQ6Bu2r2AYLpe2E94EvdOQns
#企微消息corpsecret
QW_MES_CORPSECRET=vttHT0qWVuQ9iSRo4hhi192VyoyjNM7BzZo6XxXykvA
#企微消息推送URL
QW_MES_PUSH_URL=https://qyapi.weixin.qq.com/cgi-bin/message/send
#企微消息应用ID
QW_MES_AGENTID=1
#企微获取token的url
QW_TOKEN_URL=https://qyapi.weixin.qq.com/cgi-bin/gettoken
#企微获取设备打卡数据url
QW_CHECKIN_DATA_URL=https://qyapi.weixin.qq.com/cgi-bin/hardware/get_hardware_checkin_data
#同步间隔(分钟)
SYNC_INTERVAL_MIN=10

View File

@ -35,7 +35,16 @@ public class RecruitConstant {
public static final String COLLECT_MESSAGE_LINK;
public static final String MOBILE_APPID_OFFER;
public static final String OFFER_MOBILE_URL;
public static final String INTERVIEW_REGISTRATION_MOBILE_URL;
public static final String APPLICANTS_RESUMES_CATEGORY;
public static final String QW_CORPID;
public static final String QW_CORPSECRET;
public static final String QW_MES_CORPSECRET;
public static final String QW_TOKEN_URL;
public static final String QW_CHECKIN_DATA_URL;
public static final String QW_MES_PUSH_URL;
public static final String SYNC_INTERVAL_MIN;
public static final String QW_MES_AGENTID;
public static final String INTERVIEW_FEEDBACK_URL;
public static final String REMIND_SEARCH_LINK;
public static final String OCR_TYPE;
@ -60,8 +69,19 @@ public class RecruitConstant {
MOBILE_APPID_OFFER = getRecruitPropValue("MOBILE_APPID_OFFER");
// offer反馈移动建模地址
OFFER_MOBILE_URL = getCompleteUrl(getRecruitPropValue("OFFER_MOBILE_URL"));
INTERVIEW_REGISTRATION_MOBILE_URL = getCompleteUrl(getRecruitPropValue("INTERVIEW_REGISTRATION_MOBILE_URL"));
APPLICANTS_RESUMES_CATEGORY = getRecruitPropValue("APPLICANTS_RESUMES_CATEGORY");
// 企微相关
QW_CORPID = getRecruitPropValue("QW_CORPID");
QW_CORPSECRET = getRecruitPropValue("QW_CORPSECRET");
QW_MES_CORPSECRET = getRecruitPropValue("QW_MES_CORPSECRET");
QW_TOKEN_URL = getRecruitPropValue("QW_TOKEN_URL");
QW_CHECKIN_DATA_URL = getRecruitPropValue("QW_CHECKIN_DATA_URL");
SYNC_INTERVAL_MIN = getRecruitPropValue("SYNC_INTERVAL_MIN");
QW_MES_PUSH_URL = getRecruitPropValue("QW_MES_PUSH_URL");
QW_MES_AGENTID = getRecruitPropValue("QW_MES_AGENTID");
// 简历订阅相关
REMIND_SEARCH_LINK = getCompleteUrl(getRecruitPropValue("REMIND_SEARCH_LINK"));
// OCR相关

View File

@ -44,4 +44,31 @@ public class WrittenResultsController {
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::importExcel, params);
}
@POST
@Path("/remindExaminer")
@Produces(MediaType.APPLICATION_JSON)
public String remindExaminer(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::remindExaminer, params);
}
@POST
@Path("/countOption")
@Produces(MediaType.APPLICATION_JSON)
public String countOption(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::countOption, params);
}
@POST
@Path("/getQwCardData")
@Produces(MediaType.APPLICATION_JSON)
public String getQwCardData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::getQwCardData, params);
}
}

View File

@ -53,7 +53,7 @@ public class RecruitTabPo {
rs.executeQuery("select count(id) as num from uf_jcl_yppc where formmodeid is not null and xm=? and sjhm =?", rs.getString("xm"), rs.getString("sjhm"));
}
} else {
rs.executeQuery("select count(1) as num from " + tableName + " where ypz = ? ", Convert.toInt(billId, -1));
rs.execute("select count(1) as num from " + tableName + " where CAST(ypz AS varchar(max)) = '" + Convert.toInt(billId, -1) + "'");
}
if (rs.next()) {
tabCount = rs.getString("num");

View File

@ -23,4 +23,28 @@ public interface WrittenResultsService {
* @return
*/
Map<String, Object> importExcel(Map<String, Object> params);
/**
* 笔试附件回传后提醒笔试官
*
* @param params
* @return
*/
Map<String, Object> remindExaminer(Map<String, Object> params);
/**
* 性格测评选项统计计算
*
* @param params
* @return
*/
Map<String, Object> countOption(Map<String, Object> params);
/**
* 获取企微门禁数据
*
* @param params
* @return
*/
Map<String, Object> getQwCardData(Map<String, Object> params);
}

View File

@ -40,9 +40,11 @@ public class RecruitInterviewServiceImpl extends Service implements RecruitInter
Map<String, Object> mainDataMap = RecruitRecordSet.getSingleRecordMap(rs);
String sfcj = "";
String id = "";
String sjhm = "";
if (!mainDataMap.isEmpty()) {
sfcj = Util.null2String(mainDataMap.get("sfcj"));
id = Util.null2String(mainDataMap.get("id"));
sjhm = Util.null2String(mainDataMap.get("sjhm"));
} else {
returnMap.put("description", "反馈失败面试信息有误请联系相应HR确认");
return returnMap;
@ -63,7 +65,18 @@ public class RecruitInterviewServiceImpl extends Service implements RecruitInter
if ("0".equals(status)) {
returnMap.put("type", "success");
returnMap.put("message", "已确认参加面试");
returnMap.put("description", "您已接受面试感谢您的应聘请按期准备面试如有问题可以联系相应HR");
// returnMap.put("description", "您已接受面试感谢您的应聘请按期准备面试如有问题可以联系相应HR");
String href = RecruitConstant.INTERVIEW_REGISTRATION_MOBILE_URL;
if (StringUtils.isNotEmpty(sjhm)) {
rs.executeQuery("select id from uf_jcl_yppc where sjhm = ? ", sjhm);
if (rs.next()) {
String ypId = rs.getString("id");
href = href + "&ypId=" + ypId;
}
}
String description = "<p>&nbsp; &nbsp; &nbsp; &nbsp;您已接受面试感谢您的应聘请在面试前点击下方链接填写面试登记表信息如有问题可以联系相应HR<br />\n" +
"&nbsp; &nbsp; &nbsp; &nbsp;面试登记表链接:<b><a href= '" + href + "' target='_blank'>面试登记表链接</a></b></p>";
returnMap.put("description", description);
rs.executeUpdate("update uf_jcl_ms set sfcj = ? , zt = 0 where modeuuid = ? ", 0, uuid);

View File

@ -0,0 +1,79 @@
package com.engine.recruit.util;
import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;
import java.util.Base64;
import java.util.Random;
/**
* @version 1.0
* @Title ecology-9
* @Company 泛微软件
* @CreateDate 2025/5/7
* @Description 加解密工具类
* @Author AdminZm
*/
public class EncryptAndDecryptUtil {
BaseBean baseBean = new BaseBean();
final static Base64.Encoder encoder = Base64.getEncoder();
final static Base64.Decoder decoder = Base64.getDecoder();
public String encrypt(String s) {
if (StringUtils.isEmpty(s)) {
return "";
}
String str = "";
try {
String encode = encoder.encodeToString(s.getBytes("UTF-8"));
String s1 = new StringBuffer(encode).reverse().toString();
str = s1 + generate5CharRandom();
} catch (Exception e) {
baseBean.writeLog("encrypt error:" + e.getMessage());
}
return str;
}
public String decrypt(String s) {
if (StringUtils.isEmpty(s)) {
return "";
}
if (s.length() <= 5) {
return "加密存在问题";
}
String str = "";
try {
String reverse = s.substring(0, s.length() - 5);
String s1 = new StringBuffer(reverse).reverse().toString();
str = new String(decoder.decode(s1), "UTF-8");
} catch (Exception e) {
baseBean.writeLog("decrypt error:" + e.getMessage());
}
return str;
}
public String generate5CharRandom() {
//随机生成5位字符
String str1 = "qwertyuiopasdfghjklzxcvbnm" + "QWERTYUIUOPASDFGHJKLZXCVBNM" ;
String str2 = "1234567890" ;
char[] arr1 = str1.toCharArray();
char[] arr2 = str2.toCharArray();
char[] arr = new char[5];
Random r = new Random();
for (int i = 0; i < 4; i++) {
int n = r.nextInt(arr1.length);
arr[i] = arr1[n];
}
int n2 = r.nextInt(arr2.length);
arr[arr.length-1] = arr2[n2];
//打乱顺序
int n = r.nextInt(5);
char temp = arr[n];
arr[n] = arr[arr.length-1];
arr[arr.length-1] = temp;
return new String(arr);
}
}

View File

@ -25,4 +25,15 @@ public class WrittenResultsWrapper extends Service {
public Map<String, Object> importExcel(Map<String, Object> params) {
return getWrittenResultsService(user).importExcel(params);
}
public Map<String, Object> remindExaminer(Map<String, Object> params) {
return getWrittenResultsService(user).remindExaminer(params);
}
public Map<String, Object> countOption(Map<String, Object> params) {
return getWrittenResultsService(user).countOption(params);
}
public Map<String, Object> getQwCardData(Map<String, Object> params) {
return getWrittenResultsService(user).getQwCardData(params);
}
}

View File

@ -5,6 +5,7 @@ import com.engine.recruit.conn.RecruitRecordSet;
import com.engine.recruit.util.RecruitMessageUtils;
import com.weaver.formmodel.data.model.Formfield;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
@ -71,6 +72,7 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN
String tzypz = Util.null2String(mainDataMap.get("tzypz"));
String yjnr = Util.null2String(mainDataMap.get("yjnr"));
String yjtzmb = Util.null2String(mainDataMap.get("yjtzmb"));
String bsfj = Util.null2String(mainDataMap.get("bsfj"));
List<String> sendTypeList = Arrays.asList(tzypz.split(","));
boolean sendEmail = sendTypeList.contains("0");
boolean sendSms = sendTypeList.contains("1");
@ -83,7 +85,7 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN
List<List<Object>> paramList = new ArrayList<>();
buildParamList(detailDataMap, paramList);
if (CollectionUtils.isNotEmpty(paramList)) {
String insertSql = "insert into " + MODE_TABLE_NAME + " (modeuuid, modedatacreatertype, formmodeid, modedatacreater, modedatacreatedate, modedatacreatetime, modedatamodifier, modedatamodifydatetime, pcid, ypz, ypzw, bsmc, bssj, bssm, tdsj, bsapid, sjh, yx, bsdd ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String insertSql = "insert into " + MODE_TABLE_NAME + " (modeuuid, modedatacreatertype, formmodeid, modedatacreater, modedatacreatedate, modedatacreatetime, modedatamodifier, modedatamodifydatetime, pcid, ypz, ypzw, bsmc, bssj, bssm, tdsj, bsapid, sjh, yx, bsdd, bsg ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
for (List<Object> objects : paramList) {
String uuid = UUID.randomUUID().toString();
objects.add(0, uuid);
@ -95,7 +97,13 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN
String yx = Util.null2String(detailDataMap.get("yx"));
String sjh = Util.null2String(detailDataMap.get("sjh"));
if (sendEmail) {
RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
// RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
if (StringUtils.isNotEmpty(bsfj)) {
String offerAttach = RecruitModeUtil.getImageFileIdsByDocIds(bsfj);
RecruitMessageUtils.sendEmailWithFile(yx, emailTitle, msgContent, offerAttach);
} else {
RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
}
}
if (sendSms) {
@ -148,6 +156,7 @@ public class BatchAddWrittenResultModeExpand extends AbstractModeExpandJavaCodeN
param.add(map.get("sjh"));
param.add(map.get("yx"));
param.add(map.get("bsdd"));
param.add(map.get("bsg"));
paramList.add(param);
}

View File

@ -2,6 +2,7 @@ package weaver.formmode.recruit.modeexpand.written;
import com.engine.recruit.util.RecruitMessageUtils;
import com.weaver.formmodel.data.model.Formfield;
import org.apache.commons.lang3.StringUtils;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.formmode.recruit.modeexpand.util.RecruitModeUtil;
import weaver.general.BaseBean;
@ -60,8 +61,14 @@ public class CreateWrittenModeExpand extends AbstractModeExpandJavaCodeNew {
String yx = Util.null2String(mainDataMap.get("yx"));
String sjh = Util.null2String(mainDataMap.get("sjh"));
if (sendEmail) {
RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
// RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
String bstmfj = Util.null2String(mainDataMap.get("bstm"));
if (StringUtils.isNotEmpty(bstmfj)) {
String offerAttach = RecruitModeUtil.getImageFileIdsByDocIds(bstmfj);
RecruitMessageUtils.sendEmailWithFile(yx, emailTitle, msgContent, offerAttach);
} else {
RecruitMessageUtils.sendEmail(yx, emailTitle, msgContent);
}
}
if (sendSms) {
RecruitMessageUtils.sendSMS(sjh, msgContent);

View File

@ -0,0 +1,34 @@
package weaver.interfaces.recruit.cronjob;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.YearMonth;
/**
* @version 1.0
* @Title ecology-9
* @Company 泛微软件
* @CreateDate 2025/5/21
* @Description 删除消息推送数据
* @Author AdminZm
*/
public class DeleteXxtssjJob extends BaseCronJob {
BaseBean baseBean = new BaseBean();
@Override
public void execute() {
baseBean.writeLog("DeleteXxtssjJob start.");
try {
RecordSet rs = new RecordSet();
YearMonth yearMonth = YearMonth.now().minusMonths(2);
String date = yearMonth + "-01";
rs.execute("DELETE FROM uf_xxtsjlglb WHERE modedatacreatedate < '" + date + "'");
} catch (Exception e) {
baseBean.writeLog("DeleteXxtssjJob error:" + e);
}
baseBean.writeLog("DeleteXxtssjJob end.");
}
}

View File

@ -0,0 +1,652 @@
package weaver.interfaces.recruit.cronjob;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.engine.kq.biz.KQFormatBiz;
import com.engine.kq.wfset.util.SplitActionUtil;
import com.engine.recruit.constant.RecruitConstant;
import com.engine.recruit.util.EncryptAndDecryptUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;
import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* @version 1.0
* @Title ecology-9
* @Company 泛微软件
* @CreateDate 2025/5/6
* @Description 获取企微门禁数据
* @Author AdminZm
*/
public class SyncQwCardDataCron extends BaseCronJob {
BaseBean baseBean = new BaseBean();
@Override
public void execute() {
baseBean.writeLog("SyncQwCardDataCron start.");
RecordSet rs = new RecordSet();
try {
LocalDate currentDate = LocalDate.now();
// 获取前一天的日期
LocalDate previousDate = currentDate.minusDays(1);
DateTimeFormatter formatterRq = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String previousDateStr = previousDate.format(formatterRq);
String currentDateStr = currentDate.format(formatterRq);
// 定义格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 获取人员企微userid映射
Map<String, String> qwIdMap = new HashMap<>();
rs.execute("SELECT xm, qwuserid FROM uf_zsjgxysb");
while (rs.next()) {
String xm = rs.getString("xm");
String qwuserid = rs.getString("qwuserid");
if (StringUtils.isEmpty(xm) || StringUtils.isEmpty(qwuserid)) {
continue;
}
qwIdMap.put(xm, qwuserid);
}
// 获取工号与id对应
List<String> ghList = new ArrayList<>();
Map<String, String> ghAndIdMap = new HashMap<>();
Map<String, String> ghAndNameMap = new HashMap<>();
Map<String, String> ghAndOaGhMap = new HashMap<>();
rs.execute("SELECT id, workcode, lastname FROM hrmresource ");
while (rs.next()) {
String id = rs.getString("id");
String workcode = rs.getString("workcode");
String lastname = rs.getString("lastname");
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(lastname)) {
continue;
}
String oaGh = workcode;
if ((!CollectionUtils.isEmpty(qwIdMap)) && qwIdMap.containsKey(id)) {
workcode = qwIdMap.get(id);
}
if (StringUtils.isEmpty(workcode)) {
continue;
}
ghList.add(workcode);
ghAndIdMap.put(workcode, id);
ghAndNameMap.put(workcode, lastname);
ghAndOaGhMap.put(workcode, oaGh);
}
if (CollectionUtils.isEmpty(ghAndIdMap) || CollectionUtils.isEmpty(ghList)) {
baseBean.writeLog("SyncQwCardDataCron ghAndIdMap or ghList is null.");
return;
}
String sql = "select * from HrmScheduleSign where belongdate = ? OR belongdate = ? ";
rs.executeQuery(sql, previousDateStr, currentDateStr);
Set<String> signSet = new HashSet<>();
while (rs.next()) {
String userId = rs.getString("userId");
String signDate = rs.getString("signDate");
String signTime = rs.getString("signTime");
String signFrom = rs.getString("signFrom");
if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(signDate) || StringUtils.isEmpty(signTime) ||StringUtils.isEmpty(signFrom)) {
continue;
}
signSet.add(userId + "_" + signDate + "_" + signTime);
}
// 获取中间表打卡数据
// getMiddleTableData(previousDateStr, currentDateStr, ghAndIdMap, signSet);
Gson gson = new Gson();
Type type = new TypeToken<Map<String, Object>>() {}.getType();
// 获取token先考虑从缓存表中取
String jmhmw = null;
String sxsj = null;
rs.execute("SELECT TOP 1 * FROM uf_hcjlb ORDER BY id DESC");
if (rs.next()) {
jmhmw = rs.getString("jmhmw");
sxsj = rs.getString("sxsj");
}
EncryptAndDecryptUtil encryptAndDecryptUtil = new EncryptAndDecryptUtil();
ZonedDateTime zonedDateTimeNow = LocalDateTime.now().atZone(ZoneId.of("Asia/Shanghai"));
long timestampNow = zonedDateTimeNow.toInstant().toEpochMilli() / 1000;
String accessToken = null;
if (StringUtils.isEmpty(jmhmw) || StringUtils.isEmpty(sxsj)) {
String tokenUrl = RecruitConstant.QW_TOKEN_URL + "?corpid=" + RecruitConstant.QW_CORPID + "&corpsecret=" + RecruitConstant.QW_CORPSECRET;
HttpGet httpGet = new HttpGet(tokenUrl);
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);
String tokenRes = getString(response);
if (StringUtils.isEmpty(tokenRes)) {
baseBean.writeLog("SyncQwCardDataCron tokenRes is null.");
return;
}
Map<String, Object> tokenMap = gson.fromJson(tokenRes, type);
if (CollectionUtils.isEmpty(tokenMap)) {
baseBean.writeLog("SyncQwCardDataCron tokenMap is null.");
return;
}
Object errcode = tokenMap.get("errcode");
if (errcode == null || errcode == "" || new BigDecimal(errcode.toString()).compareTo(BigDecimal.ZERO) != 0) {
baseBean.writeLog("SyncQwCardDataCron get token failed:" + tokenMap);
return;
}
Object accessTokenObj = tokenMap.get("access_token");
if (accessTokenObj == null || accessTokenObj == "") {
baseBean.writeLog("SyncQwCardDataCron accessTokenObj is null.");
return;
}
Object expiresIn = tokenMap.get("expires_in");
int expiresInStr = 0;
if (expiresIn != null && expiresIn != "") {
expiresInStr = ((Double)expiresIn).intValue();
}
accessToken = accessTokenObj.toString();
long sxsjLong = timestampNow + Long.parseLong(String.valueOf(expiresInStr));
rs.executeUpdate("INSERT INTO uf_hcjlb (jmhmw,sxsj) VALUES (?,?)", encryptAndDecryptUtil.encrypt(accessToken), sxsjLong);
} else {
if (new BigDecimal(String.valueOf(timestampNow)).compareTo(new BigDecimal(sxsj)) > 0) {
rs.execute("DELETE FROM uf_hcjlb");
String tokenUrl = RecruitConstant.QW_TOKEN_URL + "?corpid=" + RecruitConstant.QW_CORPID + "&corpsecret=" + RecruitConstant.QW_CORPSECRET;
HttpGet httpGet = new HttpGet(tokenUrl);
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);
String tokenRes = getString(response);
if (StringUtils.isEmpty(tokenRes)) {
baseBean.writeLog("SyncQwCardDataCron tokenRes is null.");
return;
}
Map<String, Object> tokenMap = gson.fromJson(tokenRes, type);
if (CollectionUtils.isEmpty(tokenMap)) {
baseBean.writeLog("SyncQwCardDataCron tokenMap is null.");
return;
}
Object errcode = tokenMap.get("errcode");
if (errcode == null || errcode == "" || new BigDecimal(errcode.toString()).compareTo(BigDecimal.ZERO) != 0) {
baseBean.writeLog("SyncQwCardDataCron get token failed:" + tokenMap);
return;
}
Object accessTokenObj = tokenMap.get("access_token");
if (accessTokenObj == null || accessTokenObj == "") {
baseBean.writeLog("SyncQwCardDataCron accessTokenObj is null.");
return;
}
Object expiresIn = tokenMap.get("expires_in");
int expiresInStr = 0;
if (expiresIn != null && expiresIn != "") {
expiresInStr = ((Double)expiresIn).intValue();
}
accessToken = accessTokenObj.toString();
long sxsjLong = timestampNow + Long.parseLong(String.valueOf(expiresInStr));
rs.executeUpdate("INSERT INTO uf_hcjlb (jmhmw,sxsj) VALUES (?,?)", encryptAndDecryptUtil.encrypt(accessToken), sxsjLong);
} else {
accessToken = encryptAndDecryptUtil.decrypt(jmhmw);
}
}
ZonedDateTime nowEnd = LocalDateTime.now().atZone(ZoneId.of("Asia/Shanghai"));
long timestampEnd = nowEnd.toInstant().toEpochMilli() / 1000 + 90;
long timestampStart = nowEnd.toInstant().toEpochMilli() / 1000 - 1800;
// String start = previousDateStr + " 00:00:01";
// String end = currentDateStr + " 23:59:59";
//
// // 解析字符串为本地时间
// LocalDateTime localDateTimeStart = LocalDateTime.parse(start, formatter);
// LocalDateTime localDateTimeEnd = LocalDateTime.parse(end, formatter);
//
// // 指定时区例如上海时区
// ZonedDateTime zonedDateTimeStart = localDateTimeStart.atZone(ZoneId.of("Asia/Shanghai"));
// ZonedDateTime zonedDateTimeEnd = localDateTimeEnd.atZone(ZoneId.of("Asia/Shanghai"));
// 获取Unix时间戳
// long timestampStart = zonedDateTimeStart.toInstant().toEpochMilli() / 1000;
// long timestampEnd = zonedDateTimeEnd.toInstant().toEpochMilli() / 1000;
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("filter_type", 1);
paramMap.put("starttime", timestampStart);
paramMap.put("endtime", timestampEnd);
baseBean.writeLog("SyncQwCardDataCron ghList size is:" + ghList.size());
// int batchSize = 100; // 每个小集合的大小
// int size = ghList.size(); // 原始集合的大小
// int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
// List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合
//
// for (int i = 0; i < numberOfBatches; i++) {
// int fromIndex = i * batchSize;
// int toIndex = Math.min((i + 1) * batchSize, size);
// List<String> batch = ghList.subList(fromIndex, toIndex);
// dividedLists.add(batch);
// }
// 获取设备地址
Map<String, String> sbdzMap = new HashMap<>();
rs.execute("SELECT * FROM uf_kqjtz");
while (rs.next()) {
String sbsn = rs.getString("sbsn");
String dybm = rs.getString("dybm");
if (StringUtils.isEmpty(sbsn) || StringUtils.isEmpty(dybm)) {
continue;
}
sbdzMap.put(sbsn, dybm);
}
Set<String> needFormatSet = new HashSet<>();
List<List> insertList = new ArrayList<>();
Map<String, String> mesMap = new HashMap<>();
String url = RecruitConstant.QW_CHECKIN_DATA_URL + "?access_token=" + accessToken;
int batchSize = 100; // 每个小集合的大小
int size = ghList.size(); // 原始集合的大小
int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合
for (int i = 0; i < numberOfBatches; i++) {
int fromIndex = i * batchSize;
int toIndex = Math.min((i + 1) * batchSize, size);
List<String> batch = ghList.subList(fromIndex, toIndex);
dividedLists.add(batch);
}
for (List<String> batch : dividedLists) {
try {
paramMap.put("useridlist", batch);
baseBean.writeLog("SyncQwCardDataCron paramMap is:" + JSONObject.toJSONString(paramMap));
String result = doPost(url, paramMap, new HashMap<>());
// String result = HttpRequest.post(url)
// .header(Header.CONTENT_TYPE, "application/json")
// .body(JSONObject.toJSONString(paramMap))
// .timeout(20000)
// .execute().body();
baseBean.writeLog("getQwCardData result is:" + result);
if (StringUtils.isEmpty(result)) {
baseBean.writeLog("SyncQwCardDataCron result is null.");
continue;
}
Map<String, Object> resultMap = gson.fromJson(result, type);
if (CollectionUtils.isEmpty(resultMap)) {
baseBean.writeLog("SyncQwCardDataCron resultMap is null.");
continue;
}
Object errcodeMj = resultMap.get("errcode");
if (errcodeMj == null || errcodeMj == "" || new BigDecimal(errcodeMj.toString()).compareTo(BigDecimal.ZERO) != 0) {
baseBean.writeLog("SyncQwCardDataCron get mj failed:" + resultMap);
continue;
}
Object checkindataObj = resultMap.get("checkindata");
if (checkindataObj == null || checkindataObj == "") {
baseBean.writeLog("SyncQwCardDataCron checkindataObj null.");
continue;
}
List<Map<String, Object>> checkinDataMapLIst = (List<Map<String, Object>>)checkindataObj;
for (Map<String, Object> checkinDataMap : checkinDataMapLIst) {
Object userId = checkinDataMap.get("userid");
Object checkinTime = checkinDataMap.get("checkin_time");
Object deviceSn = checkinDataMap.get("device_sn");
if (userId == null || userId == "" || checkinTime == null || checkinTime == "") {
continue;
}
String yg = ghAndIdMap.get(userId.toString());
String ygName = ghAndNameMap.get(userId.toString());
if (StringUtils.isEmpty(yg) || StringUtils.isEmpty(ygName)) {
continue;
}
String fromType = "qw";
if (deviceSn != null && deviceSn != "") {
fromType = deviceSn.toString();
}
String addr = "qw";
if (deviceSn != null && deviceSn != "") {
if ((!CollectionUtils.isEmpty(sbdzMap)) && sbdzMap.containsKey(deviceSn.toString())) {
addr = sbdzMap.get(deviceSn.toString());
} else {
addr = deviceSn.toString();
}
}
Instant instant = Instant.ofEpochSecond(Long.parseLong(String.valueOf(((Double)checkinTime).intValue())));
// 2. 指定时区例如上海时区
ZonedDateTime zonedDateTimeA = instant.atZone(ZoneId.of("Asia/Shanghai"));
// 4. 转为字符串
String dateStrA = zonedDateTimeA.format(formatter);
String[] dt = dateStrA.split(" ");
String rq = dt[0];
String sj = dt[1];
String keyTemp = yg + "_" + rq + "_" + sj;
if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
continue;
}
List list = new ArrayList();
list.add(yg);
list.add("1");
list.add(rq);
list.add(sj);
list.add("1");
list.add(fromType);
list.add(addr);
list.add(rq);
insertList.add(list);
needFormatSet.add(yg + "_" + rq);
if ((!CollectionUtils.isEmpty(sbdzMap)) && deviceSn != null && deviceSn != "" && sbdzMap.containsKey(deviceSn.toString())) {
mesMap.put(userId + "#" + rq + "#" + sj + "#" + ygName, addr);
}
}
} catch (Exception e) {
baseBean.writeLog("SyncQwCardDataCron url error:" + e);
}
}
if (!CollectionUtils.isEmpty(insertList)) {
String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
"signFrom, addr, belongdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
rs.executeBatchSql(insertSql, insertList);
}
if (!CollectionUtils.isEmpty(mesMap)) {
// 消息推送
pushMesToQw(mesMap, ghAndOaGhMap);
}
if (!CollectionUtils.isEmpty(needFormatSet)) {
for (String key : needFormatSet) {
String yg = key.split("_")[0];
String rq = key.split("_")[1];
new KQFormatBiz().formatDate(yg, rq);
SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + yg);
}
}
} catch (Exception e) {
rs.execute("DELETE FROM uf_hcjlb");
baseBean.writeLog("SyncQwCardDataCron error:" + e);
}
baseBean.writeLog("SyncQwCardDataCron end.");
}
public void getMiddleTableData(String ksrq, String jsrq, Map<String, String> ghAndIdMap, Set<String> signSet) {
baseBean.writeLog("getMiddleTableData start:" + ksrq + "" + jsrq);
RecordSet rs = new RecordSet();
try {
Set<String> needFormatSet = new HashSet<>();
List<List> insertList = new ArrayList<>();
Map<String, String> mesMap = new HashMap<>();
rs.executeSqlWithDataSource("SELECT * FROM timer_card WHERE card_date >= '" + ksrq + "' AND card_date <= '" + jsrq + "'", "\n" +
"nw_timer");
while (rs.next()) {
String cardWork = rs.getString("card_work");
String cardTime = rs.getString("card_time");
String cardAddr = rs.getString("card_addr");
String cardName = rs.getString("card_name");
if (StringUtils.isEmpty(cardWork) || StringUtils.isEmpty(cardTime) || StringUtils.isEmpty(cardAddr) || StringUtils.isEmpty(cardName)) {
continue;
}
String yg = ghAndIdMap.get(cardWork);
if (StringUtils.isEmpty(yg)) {
continue;
}
String[] s = cardTime.split(" ");
String rq = s[0];
String sj = s[1];
String keyTemp = yg + "_" + rq + "_" + sj;
if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
continue;
}
List list = new ArrayList();
list.add(yg);
list.add("1");
list.add(rq);
list.add(sj);
list.add("1");
list.add(cardAddr);
list.add(rq);
insertList.add(list);
needFormatSet.add(yg + "_" + rq);
mesMap.put(cardWork + "_" + rq + "_" + sj + "_" + cardName, cardAddr);
}
if (!CollectionUtils.isEmpty(insertList)) {
String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
"signFrom, belongdate) VALUES (?, ?, ?, ?, ?, ?, ?)";
rs.executeBatchSql(insertSql, insertList);
}
if (!CollectionUtils.isEmpty(mesMap)) {
// 消息推送
// pushMesToQw(mesMap);
}
if (!CollectionUtils.isEmpty(needFormatSet)) {
for (String key : needFormatSet) {
String yg = key.split("_")[0];
String rq = key.split("_")[1];
new KQFormatBiz().formatDate(yg, rq);
SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + yg);
}
}
} catch (Exception e) {
baseBean.writeLog("getMiddleTableData error:" + e);
}
baseBean.writeLog("getMiddleTableData end.");
}
public void pushMesToQw(Map<String, String> mesMap, Map<String, String> ghAndOaGhMap) {
baseBean.writeLog("pushMesToQw start.");
RecordSet rs = new RecordSet();
String dataId = null;
try {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
String uuid = UUID.randomUUID().toString();
rs.executeUpdate("INSERT INTO uf_xxtsjlglb (cs, MODEUUID, modedatacreatedate, modedatacreatetime) VALUES (?, ?, ?, ?)",
JSONObject.toJSONString(mesMap), uuid, sdfDate.format(new Date()), sdfTime.format(new Date()));
rs.executeQuery("SELECT id FROM uf_xxtsjlglb WHERE MODEUUID = ?", uuid);
if (rs.next()) {
dataId = rs.getString("id");
}
if (StringUtils.isEmpty(dataId)) {
baseBean.writeLog("pushMesToQw get data id error:" + JSONObject.toJSONString(mesMap));
return;
}
Gson gson = new Gson();
Type type = new TypeToken<Map<String, Object>>() {}.getType();
String tokenUrl = RecruitConstant.QW_TOKEN_URL + "?corpid=" + RecruitConstant.QW_CORPID + "&corpsecret=" + RecruitConstant.QW_MES_CORPSECRET;
HttpGet httpGet = new HttpGet(tokenUrl);
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);
String tokenRes = getString(response);
if (StringUtils.isEmpty(tokenRes)) {
baseBean.writeLog("pushMesToQw tokenRes is null.");
return;
}
Map<String, Object> tokenMap = gson.fromJson(tokenRes, type);
if (CollectionUtils.isEmpty(tokenMap)) {
baseBean.writeLog("pushMesToQw tokenMap is null.");
return;
}
Object errcode = tokenMap.get("errcode");
if (errcode == null || errcode == "" || new BigDecimal(errcode.toString()).compareTo(BigDecimal.ZERO) != 0) {
baseBean.writeLog("pushMesToQw get token failed:" + tokenMap);
return;
}
Object accessTokenObj = tokenMap.get("access_token");
if (accessTokenObj == null || accessTokenObj == "") {
baseBean.writeLog("pushMesToQw accessTokenObj is null.");
return;
}
// Object expiresIn = tokenMap.get("expires_in");
// int expiresInStr = 0;
// if (expiresIn != null && expiresIn != "") {
// expiresInStr = ((Double)expiresIn).intValue();
// }
String accessToken = accessTokenObj.toString();
String url = RecruitConstant.QW_MES_PUSH_URL + "?access_token=" + accessToken;
for (Map.Entry<String, String> entry : mesMap.entrySet()) {
String dtId = null;
try {
String key = entry.getKey();
String value = entry.getValue();
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
continue;
}
String[] keyArr = key.split("#");
String gh = keyArr[0];
String rq = keyArr[1];
String sj = keyArr[2];
String name = keyArr[3];
if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(rq) || StringUtils.isEmpty(sj) || StringUtils.isEmpty(name)) {
continue;
}
String oaGh = ghAndOaGhMap.get(gh);
if (StringUtils.isEmpty(oaGh)) {
oaGh = "";
}
StringBuffer sb = new StringBuffer();
sb.append("路维人脸识别自动打卡设备,温馨提醒您:\n")
.append("**考勤人脸打卡信息 **\n")
.append("日期: <font color = \"info\">").append(rq).append("</font>\n")
.append("工号: <font color = \"warning\">").append(oaGh).append("</font>\n")
.append("姓名: <font color = \"warning\">").append(name).append("</font>\n")
.append("打卡时间: <font color = \"warning\">").append(rq).append(" ").append(sj).append("</font>\n")
.append("打卡地址: <font color = \"info\">").append(value).append("</font>\n");
Map<String, Object> paramMap = new HashMap<>();
JSONObject markdown = new JSONObject();
markdown.put("content", sb.toString());
paramMap.put("touser", gh);
paramMap.put("msgtype", "markdown");
paramMap.put("agentid", RecruitConstant.QW_MES_AGENTID);
paramMap.put("markdown", markdown);
String uuidDt = UUID.randomUUID() + gh;
rs.executeUpdate("INSERT INTO uf_xxtsjlglb (cs, MODEUUID, szid, modedatacreatedate, modedatacreatetime) VALUES (?, ?, ?, ?, ?)",
JSONObject.toJSONString(paramMap), uuidDt, dataId, sdfDate.format(new Date()), sdfTime.format(new Date()));
rs.executeQuery("SELECT id FROM uf_xxtsjlglb WHERE MODEUUID = ?", uuidDt);
if (rs.next()) {
dtId = rs.getString("id");
}
if (StringUtils.isEmpty(dtId)) {
baseBean.writeLog("pushMesToQw get dt id error.");
continue;
}
String result = doPost(url, paramMap, new HashMap<>());
rs.executeUpdate("UPDATE uf_xxtsjlglb SET xy = ? WHERE id = ?", result, dtId);
if (StringUtils.isEmpty(result)) {
baseBean.writeLog("pushMesToQw result is null.");
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 1 WHERE id = ?", dtId);
continue;
}
Map<String, Object> resultMap = gson.fromJson(result, type);
if (CollectionUtils.isEmpty(resultMap)) {
baseBean.writeLog("pushMesToQw resultMap is null.");
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 1 WHERE id = ?", dtId);
continue;
}
Object errcodeMj = resultMap.get("errcode");
if (errcodeMj == null || errcodeMj == "" || new BigDecimal(errcodeMj.toString()).compareTo(BigDecimal.ZERO) != 0) {
baseBean.writeLog("pushMesToQw failed:" + resultMap);
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 1 WHERE id = ?", dtId);
continue;
}
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 0 WHERE id = ?", dtId);
} catch (Exception e) {
baseBean.writeLog("pushMesToQw dt error:" + e);
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 1, yc = ? WHERE id = ?", e.getMessage(), dtId);
}
}
} catch (Exception e) {
baseBean.writeLog("pushMesToQw error:" + e);
rs.executeUpdate("UPDATE uf_xxtsjlglb SET jg = 1, yc = ? WHERE id = ?", e.getMessage(), dataId);
}
baseBean.writeLog("pushMesToQw end.");
}
public String doPost(String url, Map<String, Object> paramMap, Map<String, String> headers) {
Assert.hasText(url, "Url is empty!");
CloseableHttpClient httpClient = null;
try {
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
NoopHostnameVerifier.INSTANCE);
httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build();
HttpPost httpPost = new HttpPost(url);
Gson gson = new Gson();
if (MapUtils.isNotEmpty(paramMap)) {
StringEntity entity = new StringEntity(gson.toJson(paramMap), "UTF-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
}
if (MapUtils.isNotEmpty(headers)) {
for (String key : headers.keySet()) {
httpPost.addHeader(key, headers.get(key));
}
}
HttpResponse response = httpClient.execute(httpPost);
String result;
result = getString(response);
return result;
} catch (Exception e) {
throw new RuntimeException("Exception occurred when send post request[url:" + url + "]!" + e.getMessage());
} finally {
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
throw new RuntimeException("Exception occurred when httpClient:" + e.getMessage());
}
}
}
}
public String getString(HttpResponse response) throws IOException {
String result = null;
if (response != null) {
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
result = EntityUtils.toString(resEntity, "utf-8");
}
}
return result;
}
}