tjx
2025-11-26 7f46bc0760299c943c0373215f75986ee8062821
新增企业微信的接口
已修改6个文件
133 ■■■■■ 文件已修改
src/main/java/com/gs/xky/entity/QwStaff.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gs/xky/service/Impl/QwStaffServiceImpl.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gs/xky/service/QwStaffService.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gs/xky/service/WorkWXService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QwStaffMapper.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/gs/xky/XkyApplicationTests.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    /**
     *
     * 企微的userid
     */
    private String account;
    /**
     *
     *
     */
    private String position;
    /**
     *
     *
     */
    private String dept;
    /**
     *
     *
     */
    private String sex;
    /**
     *
     *
     */
    private String phone;
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}
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 针对表【QW_STAFF】的数据库操作Service实现
* @createDate 2025-11-26 10:51:47
*/
 * @author Administrator
 * @description 针对表【QW_STAFF】的数据库操作Service实现
 * @createDate 2025-11-26 10:51:47
 */
@Service
public class QwStaffServiceImpl extends ServiceImpl<QwStaffMapper, QwStaff>
    implements QwStaffService{
        implements QwStaffService {
}
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 针对表【QW_STAFF】的数据库操作Service
* @createDate 2025-11-26 10:51:47
*/
 * @author Administrator
 * @description 针对表【QW_STAFF】的数据库操作Service
 * @createDate 2025-11-26 10:51:47
 */
public interface QwStaffService extends IService<QwStaff> {
}
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表中没有有效的account数据");
            return new ArrayList<>();
        }
        log.info("从QW_STAFF表获取到 {} 个用户account", 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);
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>
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("=== 测试结束 ===");
    }
}