From 7f46bc0760299c943c0373215f75986ee8062821 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期三, 26 十一月 2025 13:21:13 +0800
Subject: [PATCH] 新增企业微信的接口
---
src/main/java/com/gs/xky/entity/QwStaff.java | 32 ++++------
src/main/java/com/gs/xky/service/QwStaffService.java | 10 +-
src/main/resources/mapper/QwStaffMapper.xml | 14 ----
src/main/java/com/gs/xky/service/WorkWXService.java | 28 +++++++++
src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java | 14 ++--
src/test/java/com/gs/xky/XkyApplicationTests.java | 35 +++++++++++
6 files changed, 88 insertions(+), 45 deletions(-)
diff --git a/src/main/java/com/gs/xky/entity/QwStaff.java b/src/main/java/com/gs/xky/entity/QwStaff.java
index c3d6817..cd7ca22 100644
--- a/src/main/java/com/gs/xky/entity/QwStaff.java
+++ b/src/main/java/com/gs/xky/entity/QwStaff.java
@@ -3,52 +3,46 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
import lombok.Data;
+import java.io.Serializable;
+
/**
- *
+ *
* @TableName QW_STAFF
*/
-@TableName(value ="QW_STAFF")
+@TableName(value = "QW_STAFF")
@Data
public class QwStaff implements Serializable {
+ @TableField(exist = false)
+ private static final long serialVersionUID = 1L;
/**
- *
+ *
*/
@TableId
private Long id;
-
/**
- *
+ *
*/
private String name;
-
/**
- *
+ * 浼佸井鐨剈serid
*/
private String account;
-
/**
- *
+ *
*/
private String position;
-
/**
- *
+ *
*/
private String dept;
-
/**
- *
+ *
*/
private String sex;
-
/**
- *
+ *
*/
private String phone;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
}
\ No newline at end of file
diff --git a/src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java b/src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java
index f58f4f9..b6d298a 100644
--- a/src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java
+++ b/src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java
@@ -1,19 +1,19 @@
package com.gs.xky.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import generator.domain.QwStaff;
-import com.gs.xky.service.QwStaffService;
+import com.gs.xky.entity.QwStaff;
import com.gs.xky.mapper.QwStaffMapper;
+import com.gs.xky.service.QwStaffService;
import org.springframework.stereotype.Service;
/**
-* @author Administrator
-* @description 閽堝琛ㄣ�怮W_STAFF銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
-* @createDate 2025-11-26 10:51:47
-*/
+ * @author Administrator
+ * @description 閽堝琛ㄣ�怮W_STAFF銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+ * @createDate 2025-11-26 10:51:47
+ */
@Service
public class QwStaffServiceImpl extends ServiceImpl<QwStaffMapper, QwStaff>
- implements QwStaffService{
+ implements QwStaffService {
}
diff --git a/src/main/java/com/gs/xky/service/QwStaffService.java b/src/main/java/com/gs/xky/service/QwStaffService.java
index e22bac0..4dc1324 100644
--- a/src/main/java/com/gs/xky/service/QwStaffService.java
+++ b/src/main/java/com/gs/xky/service/QwStaffService.java
@@ -1,13 +1,13 @@
package com.gs.xky.service;
-import generator.domain.QwStaff;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.gs.xky.entity.QwStaff;
/**
-* @author Administrator
-* @description 閽堝琛ㄣ�怮W_STAFF銆戠殑鏁版嵁搴撴搷浣淪ervice
-* @createDate 2025-11-26 10:51:47
-*/
+ * @author Administrator
+ * @description 閽堝琛ㄣ�怮W_STAFF銆戠殑鏁版嵁搴撴搷浣淪ervice
+ * @createDate 2025-11-26 10:51:47
+ */
public interface QwStaffService extends IService<QwStaff> {
}
diff --git a/src/main/java/com/gs/xky/service/WorkWXService.java b/src/main/java/com/gs/xky/service/WorkWXService.java
index 14753bf..70b63fc 100644
--- a/src/main/java/com/gs/xky/service/WorkWXService.java
+++ b/src/main/java/com/gs/xky/service/WorkWXService.java
@@ -1,8 +1,11 @@
package com.gs.xky.service;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gs.xky.config.DataAcquisitionConfiguration;
+import com.gs.xky.entity.QwStaff;
+import com.gs.xky.mapper.QwStaffMapper;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import okhttp3.*;
@@ -16,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@@ -29,6 +33,8 @@
.build();
private final ObjectMapper objectMapper = new ObjectMapper();
+
+ private final QwStaffMapper qwStaffMapper;
public String getAccessToken() throws IOException {
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s",
@@ -164,6 +170,28 @@
}
}
+ public List<CheckinData> getCheckinDataByQwStaff(long startTime, long endTime) throws IOException {
+ List<QwStaff> qwStaffList = qwStaffMapper.selectList(new LambdaQueryWrapper<QwStaff>());
+
+ if (qwStaffList == null || qwStaffList.isEmpty()) {
+ log.warn("QW_STAFF琛ㄤ腑娌℃湁鏁版嵁");
+ return new ArrayList<>();
+ }
+
+ List<String> useridList = qwStaffList.stream()
+ .map(QwStaff::getAccount)
+ .filter(account -> account != null && !account.isEmpty())
+ .collect(Collectors.toList());
+
+ if (useridList.isEmpty()) {
+ log.warn("QW_STAFF琛ㄤ腑娌℃湁鏈夋晥鐨刟ccount鏁版嵁");
+ return new ArrayList<>();
+ }
+
+ log.info("浠嶲W_STAFF琛ㄨ幏鍙栧埌 {} 涓敤鎴穉ccount", useridList.size());
+ return getCheckinData(startTime, endTime, useridList);
+ }
+
public List<CheckinData> getCheckinData(long startTime, long endTime, List<String> useridList) throws IOException {
String accessToken = getAccessToken();
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s", accessToken);
diff --git a/src/main/resources/mapper/QwStaffMapper.xml b/src/main/resources/mapper/QwStaffMapper.xml
index e08f8fb..990a83a 100644
--- a/src/main/resources/mapper/QwStaffMapper.xml
+++ b/src/main/resources/mapper/QwStaffMapper.xml
@@ -4,18 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gs.xky.mapper.QwStaffMapper">
- <resultMap id="BaseResultMap" type="com.gs.xky.entity.QwStaff">
- <id property="id" column="ID" />
- <result property="name" column="NAME" />
- <result property="account" column="ACCOUNT" />
- <result property="position" column="POSITION" />
- <result property="dept" column="DEPT" />
- <result property="sex" column="SEX" />
- <result property="phone" column="PHONE" />
- </resultMap>
-
- <sql id="Base_Column_List">
- ID,NAME,ACCOUNT,POSITION,DEPT,SEX,
- PHONE
- </sql>
</mapper>
diff --git a/src/test/java/com/gs/xky/XkyApplicationTests.java b/src/test/java/com/gs/xky/XkyApplicationTests.java
index 46b1b93..4e485e0 100644
--- a/src/test/java/com/gs/xky/XkyApplicationTests.java
+++ b/src/test/java/com/gs/xky/XkyApplicationTests.java
@@ -179,4 +179,39 @@
System.out.println("=== 娴嬭瘯缁撴潫 ===");
}
+
+ @Test
+ void testGetCheckinDataByQwStaff() {
+ System.out.println("=== 寮�濮嬫祴璇曢�氳繃QW_STAFF琛ㄨ幏鍙栨墦鍗℃暟鎹� ===");
+
+ try {
+ long endTime = System.currentTimeMillis() / 1000;
+ long startTime = endTime - 86400;
+
+ System.out.println(" - 寮�濮嬫椂闂�: " + new java.util.Date(startTime * 1000));
+ System.out.println(" - 缁撴潫鏃堕棿: " + new java.util.Date(endTime * 1000));
+
+ List<WorkWXService.CheckinData> checkinDataList = workWXService.getCheckinDataByQwStaff(startTime, endTime);
+
+ if (checkinDataList != null && !checkinDataList.isEmpty()) {
+ System.out.println("鉁� 鎴愬姛鑾峰彇鎵撳崱鏁版嵁");
+ System.out.println(" - 鎵撳崱璁板綍鎬绘暟: " + checkinDataList.size());
+ System.out.println(" - 鍓�5鏉℃暟鎹�:");
+ checkinDataList.stream().limit(5).forEach(data -> {
+ System.out.println(" * userid: " + data.getUserid() +
+ ", 鎵撳崱鏃堕棿: " + new java.util.Date(data.getCheckinTime() * 1000) +
+ ", 鎵撳崱绫诲瀷: " + data.getCheckinType() +
+ ", 寮傚父绫诲瀷: " + data.getExceptionType() +
+ ", 鍦扮偣: " + data.getLocationDetail());
+ });
+ } else {
+ System.out.println("鉁� 鑾峰彇鐨勬墦鍗℃暟鎹负绌猴紙鍙兘QW_STAFF琛ㄦ棤鏁版嵁鎴栨椂闂磋寖鍥村唴鏃犳墦鍗¤褰曪級");
+ }
+ } catch (IOException e) {
+ System.out.println("鉁� 鑾峰彇鎵撳崱鏁版嵁澶辫触: " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ System.out.println("=== 娴嬭瘯缁撴潫 ===");
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3